epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 8 | |
| 9 | |
| 10 | #include "BenchTimer.h" |
| 11 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 12 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 13 | #include "GrContext.h" |
| 14 | #include "GrRenderTarget.h" |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 15 | #if SK_ANGLE |
| 16 | #include "gl/SkANGLEGLContext.h" |
| 17 | #endif // SK_ANGLE |
| 18 | #include "gl/SkNativeGLContext.h" |
| 19 | #include "gl/SkNullGLContext.h" |
| 20 | #include "gl/SkDebugGLContext.h" |
| 21 | #include "SkGpuDevice.h" |
| 22 | #endif // SK_SUPPORT_GPU |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 23 | |
| 24 | #include "SkBenchmark.h" |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 25 | #include "SkCanvas.h" |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 26 | #include "SkDeferredCanvas.h" |
junov@chromium.org | 44b67b2 | 2012-08-07 18:00:31 +0000 | [diff] [blame] | 27 | #include "SkDevice.h" |
reed@android.com | f523e25 | 2009-01-26 23:15:37 +0000 | [diff] [blame] | 28 | #include "SkColorPriv.h" |
reed@android.com | 3a859a0 | 2009-01-28 00:56:29 +0000 | [diff] [blame] | 29 | #include "SkGraphics.h" |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 30 | #include "SkImageEncoder.h" |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 31 | #include "SkNWayCanvas.h" |
| 32 | #include "SkPicture.h" |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 33 | #include "SkStream.h" |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 34 | #include "SkString.h" |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 35 | |
robertphillips@google.com | 2abed83 | 2012-08-23 17:50:06 +0000 | [diff] [blame] | 36 | template <typename T> const T& Min(const T& a, const T& b) { |
| 37 | return (a < b) ? a : b; |
| 38 | } |
| 39 | |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 40 | class SkBenchLogger { |
| 41 | public: |
| 42 | SkBenchLogger() : fFileStream(NULL) {} |
| 43 | ~SkBenchLogger() { |
| 44 | if (fFileStream) |
| 45 | SkDELETE(fFileStream); |
| 46 | } |
| 47 | |
| 48 | bool SetLogFile(const char file[]) { |
| 49 | fFileStream = SkNEW_ARGS(SkFILEWStream, (file)); |
| 50 | return fFileStream->isValid(); |
| 51 | } |
| 52 | |
| 53 | void logError(const char msg[]) { nativeLogError(msg); } |
| 54 | void logError(const SkString& str) { nativeLogError(str.c_str()); } |
| 55 | |
| 56 | void logProgress(const char msg[]) { |
| 57 | nativeLogProgress(msg); |
| 58 | fileWrite(msg, strlen(msg)); |
| 59 | } |
| 60 | void logProgress(const SkString& str) { |
| 61 | nativeLogProgress(str.c_str()); |
| 62 | fileWrite(str.c_str(), str.size()); |
| 63 | } |
| 64 | |
| 65 | private: |
djsollen@google.com | 56c6977 | 2011-11-08 19:00:26 +0000 | [diff] [blame] | 66 | #ifdef SK_BUILD_FOR_ANDROID |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 67 | void nativeLogError(const char msg[]) { SkDebugf("%s", msg); } |
| 68 | void nativeLogProgress(const char msg[]) { SkDebugf("%s", msg); } |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 69 | #else |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 70 | void nativeLogError(const char msg[]) { fprintf(stderr, "%s", msg); } |
| 71 | void nativeLogProgress(const char msg[]) { printf("%s", msg); } |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 72 | #endif |
| 73 | |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 74 | void fileWrite(const char msg[], size_t size) { |
| 75 | if (fFileStream && fFileStream->isValid()) |
| 76 | fFileStream->write(msg, size); |
| 77 | } |
| 78 | SkFILEWStream* fFileStream; |
| 79 | |
| 80 | } logger; |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 81 | |
| 82 | /////////////////////////////////////////////////////////////////////////////// |
| 83 | |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 84 | enum benchModes { |
| 85 | kNormal_benchModes, |
| 86 | kDeferred_benchModes, |
| 87 | kRecord_benchModes, |
| 88 | kPictureRecord_benchModes |
| 89 | }; |
| 90 | |
| 91 | /////////////////////////////////////////////////////////////////////////////// |
| 92 | |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 93 | static void erase(SkBitmap& bm) { |
| 94 | if (bm.config() == SkBitmap::kA8_Config) { |
| 95 | bm.eraseColor(0); |
| 96 | } else { |
| 97 | bm.eraseColor(SK_ColorWHITE); |
| 98 | } |
| 99 | } |
| 100 | |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 101 | #if 0 |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 102 | static bool equal(const SkBitmap& bm1, const SkBitmap& bm2) { |
| 103 | if (bm1.width() != bm2.width() || |
| 104 | bm1.height() != bm2.height() || |
| 105 | bm1.config() != bm2.config()) { |
| 106 | return false; |
| 107 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 108 | |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 109 | size_t pixelBytes = bm1.width() * bm1.bytesPerPixel(); |
| 110 | for (int y = 0; y < bm1.height(); y++) { |
| 111 | if (memcmp(bm1.getAddr(0, y), bm2.getAddr(0, y), pixelBytes)) { |
| 112 | return false; |
| 113 | } |
| 114 | } |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 115 | return true; |
| 116 | } |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 117 | #endif |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 118 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 119 | class Iter { |
| 120 | public: |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 121 | Iter(void* param) { |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 122 | fBench = BenchRegistry::Head(); |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 123 | fParam = param; |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 124 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 125 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 126 | SkBenchmark* next() { |
| 127 | if (fBench) { |
| 128 | BenchRegistry::Factory f = fBench->factory(); |
| 129 | fBench = fBench->next(); |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 130 | return f(fParam); |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 131 | } |
| 132 | return NULL; |
| 133 | } |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 134 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 135 | private: |
| 136 | const BenchRegistry* fBench; |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 137 | void* fParam; |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 138 | }; |
| 139 | |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 140 | class AutoPrePostDraw { |
| 141 | public: |
| 142 | AutoPrePostDraw(SkBenchmark* bench) : fBench(bench) { |
| 143 | fBench->preDraw(); |
| 144 | } |
| 145 | ~AutoPrePostDraw() { |
| 146 | fBench->postDraw(); |
| 147 | } |
| 148 | private: |
| 149 | SkBenchmark* fBench; |
| 150 | }; |
| 151 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 152 | static void make_filename(const char name[], SkString* path) { |
| 153 | path->set(name); |
| 154 | for (int i = 0; name[i]; i++) { |
| 155 | switch (name[i]) { |
| 156 | case '/': |
| 157 | case '\\': |
| 158 | case ' ': |
| 159 | case ':': |
| 160 | path->writable_str()[i] = '-'; |
| 161 | break; |
| 162 | default: |
| 163 | break; |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 168 | static void saveFile(const char name[], const char config[], const char dir[], |
| 169 | const SkBitmap& bm) { |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 170 | SkBitmap copy; |
| 171 | if (!bm.copyTo(©, SkBitmap::kARGB_8888_Config)) { |
| 172 | return; |
| 173 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 174 | |
reed@android.com | f523e25 | 2009-01-26 23:15:37 +0000 | [diff] [blame] | 175 | if (bm.config() == SkBitmap::kA8_Config) { |
| 176 | // turn alpha into gray-scale |
| 177 | size_t size = copy.getSize() >> 2; |
| 178 | SkPMColor* p = copy.getAddr32(0, 0); |
| 179 | for (size_t i = 0; i < size; i++) { |
| 180 | int c = (*p >> SK_A32_SHIFT) & 0xFF; |
| 181 | c = 255 - c; |
| 182 | c |= (c << 24) | (c << 16) | (c << 8); |
| 183 | *p++ = c | (SK_A32_MASK << SK_A32_SHIFT); |
| 184 | } |
| 185 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 186 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 187 | SkString str; |
| 188 | make_filename(name, &str); |
| 189 | str.appendf("_%s.png", config); |
| 190 | str.prepend(dir); |
| 191 | ::remove(str.c_str()); |
| 192 | SkImageEncoder::EncodeFile(str.c_str(), copy, SkImageEncoder::kPNG_Type, |
| 193 | 100); |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | static void performClip(SkCanvas* canvas, int w, int h) { |
| 197 | SkRect r; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 198 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 199 | r.set(SkIntToScalar(10), SkIntToScalar(10), |
| 200 | SkIntToScalar(w*2/3), SkIntToScalar(h*2/3)); |
| 201 | canvas->clipRect(r, SkRegion::kIntersect_Op); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 202 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 203 | r.set(SkIntToScalar(w/3), SkIntToScalar(h/3), |
| 204 | SkIntToScalar(w-10), SkIntToScalar(h-10)); |
| 205 | canvas->clipRect(r, SkRegion::kXOR_Op); |
| 206 | } |
| 207 | |
| 208 | static void performRotate(SkCanvas* canvas, int w, int h) { |
| 209 | const SkScalar x = SkIntToScalar(w) / 2; |
| 210 | const SkScalar y = SkIntToScalar(h) / 2; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 211 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 212 | canvas->translate(x, y); |
| 213 | canvas->rotate(SkIntToScalar(35)); |
| 214 | canvas->translate(-x, -y); |
| 215 | } |
| 216 | |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 217 | static void performScale(SkCanvas* canvas, int w, int h) { |
| 218 | const SkScalar x = SkIntToScalar(w) / 2; |
| 219 | const SkScalar y = SkIntToScalar(h) / 2; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 220 | |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 221 | canvas->translate(x, y); |
| 222 | // just enough so we can't take the sprite case |
| 223 | canvas->scale(SK_Scalar1 * 99/100, SK_Scalar1 * 99/100); |
| 224 | canvas->translate(-x, -y); |
| 225 | } |
| 226 | |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 227 | static bool parse_bool_arg(char * const* argv, char* const* stop, bool* var) { |
| 228 | if (argv < stop) { |
| 229 | *var = atoi(*argv) != 0; |
| 230 | return true; |
| 231 | } |
| 232 | return false; |
| 233 | } |
| 234 | |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 235 | enum Backend { |
| 236 | kRaster_Backend, |
| 237 | kGPU_Backend, |
| 238 | kPDF_Backend, |
| 239 | }; |
| 240 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 241 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 242 | class GLHelper { |
| 243 | public: |
| 244 | GLHelper() { |
| 245 | } |
| 246 | |
| 247 | bool init(SkGLContext* glCtx, int width, int height) { |
| 248 | GrContext* grCtx; |
tomhudson@google.com | 8afae61 | 2012-08-14 15:03:35 +0000 | [diff] [blame] | 249 | if (!glCtx->init(width, height)) { |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 250 | return false; |
| 251 | } |
tomhudson@google.com | 8afae61 | 2012-08-14 15:03:35 +0000 | [diff] [blame] | 252 | GrPlatform3DContext ctx = |
| 253 | reinterpret_cast<GrPlatform3DContext>(glCtx->gl()); |
| 254 | grCtx = GrContext::Create(kOpenGL_Shaders_GrEngine, ctx); |
| 255 | if (NULL != grCtx) { |
| 256 | GrPlatformRenderTargetDesc desc; |
| 257 | desc.fConfig = kSkia8888_PM_GrPixelConfig; |
| 258 | desc.fWidth = width; |
| 259 | desc.fHeight = height; |
| 260 | desc.fStencilBits = 8; |
| 261 | desc.fRenderTargetHandle = glCtx->getFBOID(); |
| 262 | GrRenderTarget* rt = grCtx->createPlatformRenderTarget(desc); |
| 263 | if (NULL == rt) { |
| 264 | grCtx->unref(); |
| 265 | return false; |
| 266 | } |
| 267 | glCtx->ref(); |
| 268 | fGLContext.reset(glCtx); |
| 269 | fGrContext.reset(grCtx); |
| 270 | fRenderTarget.reset(rt); |
| 271 | } |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 272 | return true; |
| 273 | } |
| 274 | |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 275 | void cleanup() { |
| 276 | fGLContext.reset(NULL); |
| 277 | fGrContext.reset(NULL); |
| 278 | fRenderTarget.reset(NULL); |
| 279 | } |
| 280 | |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 281 | bool isValid() { |
| 282 | return NULL != fGLContext.get(); |
| 283 | } |
| 284 | |
| 285 | SkGLContext* glContext() { |
| 286 | return fGLContext.get(); |
| 287 | } |
| 288 | |
| 289 | GrRenderTarget* renderTarget() { |
| 290 | return fRenderTarget.get(); |
| 291 | } |
| 292 | |
| 293 | GrContext* grContext() { |
| 294 | return fGrContext.get(); |
| 295 | } |
| 296 | private: |
| 297 | SkAutoTUnref<SkGLContext> fGLContext; |
| 298 | SkAutoTUnref<GrContext> fGrContext; |
| 299 | SkAutoTUnref<GrRenderTarget> fRenderTarget; |
| 300 | }; |
| 301 | |
| 302 | static GLHelper gRealGLHelper; |
| 303 | static GLHelper gNullGLHelper; |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 304 | static GLHelper gDebugGLHelper; |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 305 | #if SK_ANGLE |
| 306 | static GLHelper gANGLEGLHelper; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 307 | #endif // SK_ANGLE |
| 308 | #else // !SK_SUPPORT_GPU |
| 309 | class GLHelper; |
| 310 | class SkGLContext; |
| 311 | #endif // !SK_SUPPORT_GPU |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 312 | static SkDevice* make_device(SkBitmap::Config config, const SkIPoint& size, |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 313 | Backend backend, GLHelper* glHelper) { |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 314 | SkDevice* device = NULL; |
| 315 | SkBitmap bitmap; |
| 316 | bitmap.setConfig(config, size.fX, size.fY); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 317 | |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 318 | switch (backend) { |
| 319 | case kRaster_Backend: |
| 320 | bitmap.allocPixels(); |
| 321 | erase(bitmap); |
reed@google.com | af951c9 | 2011-06-16 19:10:39 +0000 | [diff] [blame] | 322 | device = new SkDevice(bitmap); |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 323 | break; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 324 | #if SK_SUPPORT_GPU |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 325 | case kGPU_Backend: |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 326 | device = new SkGpuDevice(glHelper->grContext(), |
| 327 | glHelper->renderTarget()); |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 328 | break; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 329 | #endif |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 330 | case kPDF_Backend: |
| 331 | default: |
| 332 | SkASSERT(!"unsupported"); |
| 333 | } |
| 334 | return device; |
| 335 | } |
| 336 | |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 337 | static const struct { |
| 338 | SkBitmap::Config fConfig; |
| 339 | const char* fName; |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 340 | Backend fBackend; |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 341 | GLHelper* fGLHelper; |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 342 | } gConfigs[] = { |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 343 | { SkBitmap::kARGB_8888_Config, "8888", kRaster_Backend, NULL }, |
| 344 | { SkBitmap::kRGB_565_Config, "565", kRaster_Backend, NULL }, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 345 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 346 | { SkBitmap::kARGB_8888_Config, "GPU", kGPU_Backend, &gRealGLHelper }, |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 347 | #if SK_ANGLE |
| 348 | { SkBitmap::kARGB_8888_Config, "ANGLE", kGPU_Backend, &gANGLEGLHelper }, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 349 | #endif // SK_ANGLE |
robertphillips@google.com | a0b63b8 | 2012-03-30 12:23:56 +0000 | [diff] [blame] | 350 | #ifdef SK_DEBUG |
| 351 | { SkBitmap::kARGB_8888_Config, "Debug", kGPU_Backend, &gDebugGLHelper }, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 352 | #endif // SK_DEBUG |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 353 | { SkBitmap::kARGB_8888_Config, "NULLGPU", kGPU_Backend, &gNullGLHelper }, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 354 | #endif // SK_SUPPORT_GPU |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 355 | }; |
| 356 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 357 | static int findConfig(const char config[]) { |
| 358 | for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); i++) { |
| 359 | if (!strcmp(config, gConfigs[i].fName)) { |
| 360 | return i; |
| 361 | } |
| 362 | } |
| 363 | return -1; |
| 364 | } |
| 365 | |
tomhudson@google.com | 8382394 | 2011-10-28 14:59:07 +0000 | [diff] [blame] | 366 | static void determine_gpu_context_size(SkTDict<const char*>& defineDict, |
| 367 | int* contextWidth, |
| 368 | int* contextHeight) { |
| 369 | Iter iter(&defineDict); |
| 370 | SkBenchmark* bench; |
| 371 | while ((bench = iter.next()) != NULL) { |
| 372 | SkIPoint dim = bench->getSize(); |
| 373 | if (*contextWidth < dim.fX) { |
| 374 | *contextWidth = dim.fX; |
| 375 | } |
| 376 | if (*contextHeight < dim.fY) { |
| 377 | *contextHeight = dim.fY; |
| 378 | } |
bsalomon@google.com | 7fbc604 | 2012-08-13 22:10:05 +0000 | [diff] [blame] | 379 | bench->unref(); |
tomhudson@google.com | 8382394 | 2011-10-28 14:59:07 +0000 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | |
reed@google.com | 1a7eabc | 2011-10-31 16:33:52 +0000 | [diff] [blame] | 383 | static bool skip_name(const SkTDArray<const char*> array, const char name[]) { |
| 384 | if (0 == array.count()) { |
| 385 | // no names, so don't skip anything |
| 386 | return false; |
| 387 | } |
| 388 | for (int i = 0; i < array.count(); ++i) { |
| 389 | if (strstr(name, array[i])) { |
| 390 | // found the name, so don't skip |
| 391 | return false; |
| 392 | } |
| 393 | } |
| 394 | return true; |
| 395 | } |
| 396 | |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 397 | static void help() { |
bensong@google.com | af3d79a | 2012-07-02 20:48:51 +0000 | [diff] [blame] | 398 | SkDebugf("Usage: bench [-o outDir] [-repeat nr] [-logPerIter 1|0] " |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 399 | "[-timers [wcgWC]*] [-rotate]\n" |
robertphillips@google.com | 2abed83 | 2012-08-23 17:50:06 +0000 | [diff] [blame] | 400 | " [-scale] [-clip] [-min] [-forceAA 1|0] [-forceFilter 1|0]\n" |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 401 | " [-forceDither 1|0] [-forceBlend 1|0] [-strokeWidth width]\n" |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 402 | " [-match name] [-mode normal|deferred|record|picturerecord]\n" |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 403 | " [-config 8888|565|GPU|ANGLE|NULLGPU] [-Dfoo bar]\n" |
| 404 | " [-h|--help]"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 405 | SkDebugf("\n\n"); |
| 406 | SkDebugf(" -o outDir : Image of each bench will be put in outDir.\n"); |
| 407 | SkDebugf(" -repeat nr : Each bench repeats for nr times.\n"); |
bensong@google.com | af3d79a | 2012-07-02 20:48:51 +0000 | [diff] [blame] | 408 | SkDebugf(" -logPerIter 1|0 : " |
| 409 | "Log each repeat timer instead of mean, default is disabled.\n"); |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 410 | SkDebugf(" -timers [wcgWC]* : " |
| 411 | "Display wall, cpu, gpu, truncated wall or truncated cpu time for each bench.\n"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 412 | SkDebugf(" -rotate : Rotate before each bench runs.\n"); |
| 413 | SkDebugf(" -scale : Scale before each bench runs.\n"); |
| 414 | SkDebugf(" -clip : Clip before each bench runs.\n"); |
robertphillips@google.com | 2abed83 | 2012-08-23 17:50:06 +0000 | [diff] [blame] | 415 | SkDebugf(" -min : Print the minimum times (instead of average).\n"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 416 | SkDebugf(" -forceAA 1|0 : " |
| 417 | "Enable/disable anti-aliased, default is enabled.\n"); |
| 418 | SkDebugf(" -forceFilter 1|0 : " |
| 419 | "Enable/disable bitmap filtering, default is disabled.\n"); |
| 420 | SkDebugf(" -forceDither 1|0 : " |
| 421 | "Enable/disable dithering, default is disabled.\n"); |
| 422 | SkDebugf(" -forceBlend 1|0 : " |
| 423 | "Enable/disable dithering, default is disabled.\n"); |
| 424 | SkDebugf(" -strokeWidth width : The width for path stroke.\n"); |
| 425 | SkDebugf(" -match name : Only run bench whose name is matched.\n"); |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 426 | SkDebugf(" -mode normal|deferred|record|picturerecord : Run in the corresponding mode\n" |
| 427 | " normal, Use a normal canvas to draw to;\n" |
| 428 | " deferred, Use a deferrred canvas when drawing;\n" |
| 429 | " record, Benchmark the time to record to an SkPicture;\n" |
| 430 | " picturerecord, Benchmark the time to do record from a \n" |
| 431 | " SkPicture to a SkPicture.\n"); |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 432 | SkDebugf(" -logFile : destination for writing log output, in addition to stdout.\n"); |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 433 | #if SK_SUPPORT_GPU |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 434 | SkDebugf(" -config 8888|565|GPU|ANGLE|NULLGPU : " |
| 435 | "Run bench in corresponding config mode.\n"); |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 436 | #else |
| 437 | SkDebugf(" -config 8888|565: " |
| 438 | "Run bench in corresponding config mode.\n"); |
| 439 | #endif |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 440 | SkDebugf(" -Dfoo bar : Add extra definition to bench.\n"); |
| 441 | SkDebugf(" -h|--help : Show this help message.\n"); |
| 442 | } |
| 443 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 444 | int main (int argc, char * const argv[]) { |
bsalomon@google.com | 65a87cc | 2012-08-14 13:15:44 +0000 | [diff] [blame] | 445 | #ifdef SK_ENABLE_INST_COUNT |
| 446 | gPrintInstCount = true; |
| 447 | #endif |
reed@android.com | 3a859a0 | 2009-01-28 00:56:29 +0000 | [diff] [blame] | 448 | SkAutoGraphics ag; |
bsalomon@google.com | 65a87cc | 2012-08-14 13:15:44 +0000 | [diff] [blame] | 449 | |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 450 | SkTDict<const char*> defineDict(1024); |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 451 | int repeatDraw = 1; |
bensong@google.com | af3d79a | 2012-07-02 20:48:51 +0000 | [diff] [blame] | 452 | bool logPerIter = false; |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 453 | int forceAlpha = 0xFF; |
| 454 | bool forceAA = true; |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 455 | bool forceFilter = false; |
reed@android.com | 4e635f9 | 2009-10-19 17:39:46 +0000 | [diff] [blame] | 456 | SkTriState::State forceDither = SkTriState::kDefault; |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 457 | bool timerWall = false; |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 458 | bool truncatedTimerWall = false; |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 459 | bool timerCpu = true; |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 460 | bool truncatedTimerCpu = false; |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 461 | bool timerGpu = true; |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 462 | bool doScale = false; |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 463 | bool doRotate = false; |
| 464 | bool doClip = false; |
robertphillips@google.com | 2abed83 | 2012-08-23 17:50:06 +0000 | [diff] [blame] | 465 | bool printMin = false; |
agl@chromium.org | 652807b | 2010-04-27 15:47:34 +0000 | [diff] [blame] | 466 | bool hasStrokeWidth = false; |
| 467 | float strokeWidth; |
reed@google.com | 1a7eabc | 2011-10-31 16:33:52 +0000 | [diff] [blame] | 468 | SkTDArray<const char*> fMatches; |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 469 | benchModes benchMode = kNormal_benchModes; |
| 470 | SkString perIterTimeformat("%.2f"); |
| 471 | SkString normalTimeFormat("%6.2f"); |
| 472 | |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 473 | SkString outDir; |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 474 | SkBitmap::Config outConfig = SkBitmap::kNo_Config; |
bsalomon@google.com | cadbcb8 | 2012-01-06 19:22:11 +0000 | [diff] [blame] | 475 | GLHelper* glHelper = NULL; |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 476 | const char* configName = ""; |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 477 | Backend backend = kRaster_Backend; // for warning |
tomhudson@google.com | 13eaaaa | 2012-04-16 18:00:40 +0000 | [diff] [blame] | 478 | SkTDArray<int> configs; |
| 479 | bool userConfig = false; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 480 | |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 481 | char* const* stop = argv + argc; |
| 482 | for (++argv; argv < stop; ++argv) { |
| 483 | if (strcmp(*argv, "-o") == 0) { |
| 484 | argv++; |
| 485 | if (argv < stop && **argv) { |
| 486 | outDir.set(*argv); |
| 487 | if (outDir.c_str()[outDir.size() - 1] != '/') { |
| 488 | outDir.append("/"); |
| 489 | } |
| 490 | } |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 491 | } else if (strcmp(*argv, "-repeat") == 0) { |
| 492 | argv++; |
| 493 | if (argv < stop) { |
| 494 | repeatDraw = atoi(*argv); |
| 495 | if (repeatDraw < 1) { |
| 496 | repeatDraw = 1; |
| 497 | } |
| 498 | } else { |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 499 | logger.logError("missing arg for -repeat\n"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 500 | help(); |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 501 | return -1; |
| 502 | } |
bensong@google.com | af3d79a | 2012-07-02 20:48:51 +0000 | [diff] [blame] | 503 | } else if (strcmp(*argv, "-logPerIter") == 0) { |
| 504 | if (!parse_bool_arg(++argv, stop, &logPerIter)) { |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 505 | logger.logError("missing arg for -logPerIter\n"); |
bensong@google.com | af3d79a | 2012-07-02 20:48:51 +0000 | [diff] [blame] | 506 | help(); |
| 507 | return -1; |
| 508 | } |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 509 | } else if (strcmp(*argv, "-timers") == 0) { |
| 510 | argv++; |
| 511 | if (argv < stop) { |
| 512 | timerWall = false; |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 513 | truncatedTimerWall = false; |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 514 | timerCpu = false; |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 515 | truncatedTimerCpu = false; |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 516 | timerGpu = false; |
| 517 | for (char* t = *argv; *t; ++t) { |
| 518 | switch (*t) { |
| 519 | case 'w': timerWall = true; break; |
| 520 | case 'c': timerCpu = true; break; |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 521 | case 'W': truncatedTimerWall = true; break; |
| 522 | case 'C': truncatedTimerCpu = true; break; |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 523 | case 'g': timerGpu = true; break; |
| 524 | } |
| 525 | } |
| 526 | } else { |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 527 | logger.logError("missing arg for -timers\n"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 528 | help(); |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 529 | return -1; |
| 530 | } |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 531 | } else if (!strcmp(*argv, "-rotate")) { |
| 532 | doRotate = true; |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 533 | } else if (!strcmp(*argv, "-scale")) { |
| 534 | doScale = true; |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 535 | } else if (!strcmp(*argv, "-clip")) { |
| 536 | doClip = true; |
robertphillips@google.com | 2abed83 | 2012-08-23 17:50:06 +0000 | [diff] [blame] | 537 | } else if (!strcmp(*argv, "-min")) { |
| 538 | printMin = true; |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 539 | } else if (strcmp(*argv, "-forceAA") == 0) { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 540 | if (!parse_bool_arg(++argv, stop, &forceAA)) { |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 541 | logger.logError("missing arg for -forceAA\n"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 542 | help(); |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 543 | return -1; |
| 544 | } |
| 545 | } else if (strcmp(*argv, "-forceFilter") == 0) { |
| 546 | if (!parse_bool_arg(++argv, stop, &forceFilter)) { |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 547 | logger.logError("missing arg for -forceFilter\n"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 548 | help(); |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 549 | return -1; |
| 550 | } |
reed@android.com | 4e635f9 | 2009-10-19 17:39:46 +0000 | [diff] [blame] | 551 | } else if (strcmp(*argv, "-forceDither") == 0) { |
| 552 | bool tmp; |
| 553 | if (!parse_bool_arg(++argv, stop, &tmp)) { |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 554 | logger.logError("missing arg for -forceDither\n"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 555 | help(); |
reed@android.com | 4e635f9 | 2009-10-19 17:39:46 +0000 | [diff] [blame] | 556 | return -1; |
| 557 | } |
| 558 | forceDither = tmp ? SkTriState::kTrue : SkTriState::kFalse; |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 559 | } else if (strcmp(*argv, "-forceBlend") == 0) { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 560 | bool wantAlpha = false; |
| 561 | if (!parse_bool_arg(++argv, stop, &wantAlpha)) { |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 562 | logger.logError("missing arg for -forceBlend\n"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 563 | help(); |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 564 | return -1; |
| 565 | } |
| 566 | forceAlpha = wantAlpha ? 0x80 : 0xFF; |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 567 | } else if (strcmp(*argv, "-mode") == 0) { |
| 568 | argv++; |
| 569 | if (argv < stop) { |
| 570 | if (strcmp(*argv, "normal") == 0) { |
| 571 | benchMode = kNormal_benchModes; |
| 572 | } else if (strcmp(*argv, "deferred") == 0) { |
| 573 | benchMode = kDeferred_benchModes; |
| 574 | } else if (strcmp(*argv, "record") == 0) { |
| 575 | benchMode = kRecord_benchModes; |
| 576 | } else if (strcmp(*argv, "picturerecord") == 0) { |
| 577 | benchMode = kPictureRecord_benchModes; |
| 578 | } else { |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 579 | logger.logError("bad arg for -mode\n"); |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 580 | help(); |
| 581 | return -1; |
| 582 | } |
| 583 | } else { |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 584 | logger.logError("missing arg for -mode\n"); |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 585 | help(); |
| 586 | return -1; |
| 587 | } |
agl@chromium.org | 652807b | 2010-04-27 15:47:34 +0000 | [diff] [blame] | 588 | } else if (strcmp(*argv, "-strokeWidth") == 0) { |
| 589 | argv++; |
| 590 | if (argv < stop) { |
| 591 | const char *strokeWidthStr = *argv; |
| 592 | if (sscanf(strokeWidthStr, "%f", &strokeWidth) != 1) { |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 593 | logger.logError("bad arg for -strokeWidth\n"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 594 | help(); |
agl@chromium.org | 652807b | 2010-04-27 15:47:34 +0000 | [diff] [blame] | 595 | return -1; |
| 596 | } |
| 597 | hasStrokeWidth = true; |
| 598 | } else { |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 599 | logger.logError("missing arg for -strokeWidth\n"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 600 | help(); |
agl@chromium.org | 652807b | 2010-04-27 15:47:34 +0000 | [diff] [blame] | 601 | return -1; |
| 602 | } |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 603 | } else if (strcmp(*argv, "-match") == 0) { |
| 604 | argv++; |
| 605 | if (argv < stop) { |
reed@google.com | 1a7eabc | 2011-10-31 16:33:52 +0000 | [diff] [blame] | 606 | *fMatches.append() = *argv; |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 607 | } else { |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 608 | logger.logError("missing arg for -match\n"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 609 | help(); |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 610 | return -1; |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 611 | } |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 612 | } else if (strcmp(*argv, "-config") == 0) { |
| 613 | argv++; |
| 614 | if (argv < stop) { |
| 615 | int index = findConfig(*argv); |
| 616 | if (index >= 0) { |
tomhudson@google.com | 13eaaaa | 2012-04-16 18:00:40 +0000 | [diff] [blame] | 617 | *configs.append() = index; |
| 618 | userConfig = true; |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 619 | } else { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 620 | SkString str; |
| 621 | str.printf("unrecognized config %s\n", *argv); |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 622 | logger.logError(str); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 623 | help(); |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 624 | return -1; |
| 625 | } |
| 626 | } else { |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 627 | logger.logError("missing arg for -config\n"); |
| 628 | help(); |
| 629 | return -1; |
| 630 | } |
| 631 | } else if (strcmp(*argv, "-logFile") == 0) { |
| 632 | argv++; |
| 633 | if (argv < stop) { |
| 634 | if (!logger.SetLogFile(*argv)) { |
| 635 | SkString str; |
| 636 | str.printf("Could not open %s for writing.", *argv); |
| 637 | return -1; |
| 638 | } |
| 639 | } else { |
| 640 | logger.logError("missing arg for -logFile\n"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 641 | help(); |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 642 | return -1; |
| 643 | } |
reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 644 | } else if (strlen(*argv) > 2 && strncmp(*argv, "-D", 2) == 0) { |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 645 | argv++; |
reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 646 | if (argv < stop) { |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 647 | defineDict.set(argv[-1] + 2, *argv); |
| 648 | } else { |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 649 | logger.logError("incomplete '-Dfoo bar' definition\n"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 650 | help(); |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 651 | return -1; |
| 652 | } |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 653 | } else if (strcmp(*argv, "--help") == 0 || strcmp(*argv, "-h") == 0) { |
| 654 | help(); |
| 655 | return 0; |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 656 | } else { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 657 | SkString str; |
| 658 | str.printf("unrecognized arg %s\n", *argv); |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 659 | logger.logError(str); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 660 | help(); |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 661 | return -1; |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 662 | } |
| 663 | } |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 664 | if ((benchMode == kRecord_benchModes || benchMode == kPictureRecord_benchModes) |
| 665 | && !outDir.isEmpty()) { |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 666 | logger.logError("'-mode record' and '-mode picturerecord' are not" |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 667 | " compatible with -o.\n"); |
| 668 | return -1; |
| 669 | } |
| 670 | if ((benchMode == kRecord_benchModes || benchMode == kPictureRecord_benchModes)) { |
| 671 | perIterTimeformat.set("%.4f"); |
| 672 | normalTimeFormat.set("%6.4f"); |
| 673 | } |
tomhudson@google.com | 13eaaaa | 2012-04-16 18:00:40 +0000 | [diff] [blame] | 674 | if (!userConfig) { |
| 675 | // if no config is specified by user, we add them all. |
| 676 | for (unsigned int i = 0; i < SK_ARRAY_COUNT(gConfigs); ++i) { |
| 677 | *configs.append() = i; |
| 678 | } |
| 679 | } |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 680 | |
reed@google.com | 3b14dc1 | 2011-04-04 14:31:36 +0000 | [diff] [blame] | 681 | // report our current settings |
| 682 | { |
| 683 | SkString str; |
bensong@google.com | af3d79a | 2012-07-02 20:48:51 +0000 | [diff] [blame] | 684 | str.printf("skia bench: alpha=0x%02X antialias=%d filter=%d " |
| 685 | "deferred=%d logperiter=%d", |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 686 | forceAlpha, forceAA, forceFilter, benchMode == kDeferred_benchModes, |
| 687 | logPerIter); |
robertphillips@google.com | 2abed83 | 2012-08-23 17:50:06 +0000 | [diff] [blame] | 688 | str.appendf(" rotate=%d scale=%d clip=%d min=%d", |
| 689 | doRotate, doScale, doClip, printMin); |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 690 | str.appendf(" record=%d picturerecord=%d", |
| 691 | benchMode == kRecord_benchModes, |
| 692 | benchMode == kPictureRecord_benchModes); |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 693 | const char * ditherName; |
| 694 | switch (forceDither) { |
| 695 | case SkTriState::kDefault: ditherName = "default"; break; |
| 696 | case SkTriState::kTrue: ditherName = "true"; break; |
| 697 | case SkTriState::kFalse: ditherName = "false"; break; |
| 698 | default: ditherName = "<invalid>"; break; |
| 699 | } |
| 700 | str.appendf(" dither=%s", ditherName); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 701 | |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 702 | if (hasStrokeWidth) { |
| 703 | str.appendf(" strokeWidth=%f", strokeWidth); |
| 704 | } else { |
| 705 | str.append(" strokeWidth=none"); |
| 706 | } |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 707 | |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 708 | #if defined(SK_SCALAR_IS_FLOAT) |
| 709 | str.append(" scalar=float"); |
| 710 | #elif defined(SK_SCALAR_IS_FIXED) |
| 711 | str.append(" scalar=fixed"); |
| 712 | #endif |
| 713 | |
| 714 | #if defined(SK_BUILD_FOR_WIN32) |
| 715 | str.append(" system=WIN32"); |
| 716 | #elif defined(SK_BUILD_FOR_MAC) |
| 717 | str.append(" system=MAC"); |
| 718 | #elif defined(SK_BUILD_FOR_ANDROID) |
| 719 | str.append(" system=ANDROID"); |
| 720 | #elif defined(SK_BUILD_FOR_UNIX) |
| 721 | str.append(" system=UNIX"); |
| 722 | #else |
| 723 | str.append(" system=other"); |
| 724 | #endif |
| 725 | |
| 726 | #if defined(SK_DEBUG) |
| 727 | str.append(" DEBUG"); |
| 728 | #endif |
| 729 | str.append("\n"); |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 730 | logger.logProgress(str); |
reed@google.com | 3b14dc1 | 2011-04-04 14:31:36 +0000 | [diff] [blame] | 731 | } |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 732 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 733 | SkGLContext* timerCtx = NULL; |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 734 | //Don't do GL when fixed. |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 735 | #if !defined(SK_SCALAR_IS_FIXED) && SK_SUPPORT_GPU |
tomhudson@google.com | 8382394 | 2011-10-28 14:59:07 +0000 | [diff] [blame] | 736 | int contextWidth = 1024; |
| 737 | int contextHeight = 1024; |
| 738 | determine_gpu_context_size(defineDict, &contextWidth, &contextHeight); |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 739 | SkAutoTUnref<SkGLContext> realGLCtx(new SkNativeGLContext); |
| 740 | SkAutoTUnref<SkGLContext> nullGLCtx(new SkNullGLContext); |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 741 | SkAutoTUnref<SkGLContext> debugGLCtx(new SkDebugGLContext); |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 742 | gRealGLHelper.init(realGLCtx.get(), contextWidth, contextHeight); |
| 743 | gNullGLHelper.init(nullGLCtx.get(), contextWidth, contextHeight); |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 744 | gDebugGLHelper.init(debugGLCtx.get(), contextWidth, contextHeight); |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 745 | #if SK_ANGLE |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 746 | SkAutoTUnref<SkGLContext> angleGLCtx(new SkANGLEGLContext); |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 747 | gANGLEGLHelper.init(angleGLCtx.get(), contextWidth, contextHeight); |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 748 | #endif // SK_ANGLE |
| 749 | timerCtx = gRealGLHelper.glContext(); |
| 750 | #endif // !defined(SK_SCALAR_IS_FIXED) && SK_SUPPORT_GPU |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 751 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 752 | BenchTimer timer = BenchTimer(timerCtx); |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 753 | Iter iter(&defineDict); |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 754 | SkBenchmark* bench; |
| 755 | while ((bench = iter.next()) != NULL) { |
bsalomon@google.com | 7fbc604 | 2012-08-13 22:10:05 +0000 | [diff] [blame] | 756 | SkAutoTUnref<SkBenchmark> benchUnref(bench); |
| 757 | |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 758 | SkIPoint dim = bench->getSize(); |
| 759 | if (dim.fX <= 0 || dim.fY <= 0) { |
| 760 | continue; |
| 761 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 762 | |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 763 | bench->setForceAlpha(forceAlpha); |
| 764 | bench->setForceAA(forceAA); |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 765 | bench->setForceFilter(forceFilter); |
reed@android.com | 4e635f9 | 2009-10-19 17:39:46 +0000 | [diff] [blame] | 766 | bench->setDither(forceDither); |
agl@chromium.org | 652807b | 2010-04-27 15:47:34 +0000 | [diff] [blame] | 767 | if (hasStrokeWidth) { |
| 768 | bench->setStrokeWidth(strokeWidth); |
| 769 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 770 | |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 771 | // only run benchmarks if their name contains matchStr |
reed@google.com | 1a7eabc | 2011-10-31 16:33:52 +0000 | [diff] [blame] | 772 | if (skip_name(fMatches, bench->getName())) { |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 773 | continue; |
| 774 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 775 | |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 776 | { |
| 777 | SkString str; |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 778 | str.printf("running bench [%d %d] %28s", dim.fX, dim.fY, |
reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 779 | bench->getName()); |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 780 | logger.logProgress(str); |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 781 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 782 | |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 783 | AutoPrePostDraw appd(bench); |
| 784 | |
tomhudson@google.com | 13eaaaa | 2012-04-16 18:00:40 +0000 | [diff] [blame] | 785 | for (int x = 0; x < configs.count(); ++x) { |
| 786 | int configIndex = configs[x]; |
| 787 | |
| 788 | outConfig = gConfigs[configIndex].fConfig; |
| 789 | configName = gConfigs[configIndex].fName; |
| 790 | backend = gConfigs[configIndex].fBackend; |
| 791 | glHelper = gConfigs[configIndex].fGLHelper; |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 792 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 793 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 794 | if (kGPU_Backend == backend && |
| 795 | (NULL == glHelper || !glHelper->isValid())) { |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 796 | continue; |
| 797 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 798 | #endif |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 799 | SkDevice* device = make_device(outConfig, dim, backend, glHelper); |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 800 | SkCanvas* canvas = NULL; |
| 801 | SkPicture pictureRecordFrom; |
| 802 | SkPicture pictureRecordTo; |
| 803 | switch(benchMode) { |
| 804 | case kDeferred_benchModes: |
| 805 | canvas = new SkDeferredCanvas(device); |
| 806 | break; |
| 807 | case kRecord_benchModes: |
| 808 | canvas = pictureRecordTo.beginRecording(dim.fX, dim.fY); |
| 809 | canvas->ref(); |
| 810 | break; |
| 811 | case kPictureRecord_benchModes: { |
| 812 | // This sets up picture-to-picture recording. |
| 813 | // The C++ drawing calls for the benchmark are recorded into |
| 814 | // pictureRecordFrom. As the benchmark, we will time how |
| 815 | // long it takes to playback pictureRecordFrom into |
| 816 | // pictureRecordTo. |
| 817 | SkCanvas* tempCanvas = pictureRecordFrom.beginRecording(dim.fX, dim.fY); |
| 818 | bench->draw(tempCanvas); |
| 819 | pictureRecordFrom.endRecording(); |
| 820 | canvas = pictureRecordTo.beginRecording(dim.fX, dim.fY); |
| 821 | canvas->ref(); |
| 822 | break; |
| 823 | } |
| 824 | case kNormal_benchModes: |
| 825 | canvas = new SkCanvas(device); |
| 826 | break; |
| 827 | default: |
| 828 | SkASSERT(0); |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 829 | } |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 830 | device->unref(); |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 831 | SkAutoUnref canvasUnref(canvas); |
| 832 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 833 | if (doClip) { |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 834 | performClip(canvas, dim.fX, dim.fY); |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 835 | } |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 836 | if (doScale) { |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 837 | performScale(canvas, dim.fX, dim.fY); |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 838 | } |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 839 | if (doRotate) { |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 840 | performRotate(canvas, dim.fX, dim.fY); |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 841 | } |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 842 | |
bensong@google.com | af3d79a | 2012-07-02 20:48:51 +0000 | [diff] [blame] | 843 | // warm up caches if needed |
reed@android.com | eca4836 | 2010-12-20 18:34:17 +0000 | [diff] [blame] | 844 | if (repeatDraw > 1) { |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 845 | #if SK_SUPPORT_GPU |
| 846 | if (glHelper) { |
| 847 | // purge the GPU resources to reduce variance |
| 848 | glHelper->grContext()->freeGpuResources(); |
| 849 | } |
| 850 | #endif |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 851 | SkAutoCanvasRestore acr(canvas, true); |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 852 | if (benchMode == kPictureRecord_benchModes) { |
| 853 | pictureRecordFrom.draw(canvas); |
| 854 | } else { |
| 855 | bench->draw(canvas); |
| 856 | } |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 857 | canvas->flush(); |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 858 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 859 | if (glHelper) { |
| 860 | glHelper->grContext()->flush(); |
| 861 | SK_GL(*glHelper->glContext(), Finish()); |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 862 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 863 | #endif |
reed@android.com | eca4836 | 2010-12-20 18:34:17 +0000 | [diff] [blame] | 864 | } |
bensong@google.com | af3d79a | 2012-07-02 20:48:51 +0000 | [diff] [blame] | 865 | |
| 866 | // record timer values for each repeat, and their sum |
| 867 | SkString fWallStr(" msecs = "); |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 868 | SkString fTruncatedWallStr(" Wmsecs = "); |
bensong@google.com | af3d79a | 2012-07-02 20:48:51 +0000 | [diff] [blame] | 869 | SkString fCpuStr(" cmsecs = "); |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 870 | SkString fTruncatedCpuStr(" Cmsecs = "); |
bensong@google.com | af3d79a | 2012-07-02 20:48:51 +0000 | [diff] [blame] | 871 | SkString fGpuStr(" gmsecs = "); |
robertphillips@google.com | 2abed83 | 2012-08-23 17:50:06 +0000 | [diff] [blame] | 872 | double fWallSum = 0.0, fWallMin; |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 873 | double fTruncatedWallSum = 0.0, fTruncatedWallMin; |
robertphillips@google.com | 2abed83 | 2012-08-23 17:50:06 +0000 | [diff] [blame] | 874 | double fCpuSum = 0.0, fCpuMin; |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 875 | double fTruncatedCpuSum = 0.0, fTruncatedCpuMin; |
robertphillips@google.com | 2abed83 | 2012-08-23 17:50:06 +0000 | [diff] [blame] | 876 | double fGpuSum = 0.0, fGpuMin; |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 877 | for (int i = 0; i < repeatDraw; i++) { |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 878 | if ((benchMode == kRecord_benchModes |
| 879 | || benchMode == kPictureRecord_benchModes)) { |
| 880 | // This will clear the recorded commands so that they do not |
| 881 | // acculmulate. |
| 882 | canvas = pictureRecordTo.beginRecording(dim.fX, dim.fY); |
| 883 | } |
| 884 | |
bensong@google.com | af3d79a | 2012-07-02 20:48:51 +0000 | [diff] [blame] | 885 | timer.start(); |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 886 | SkAutoCanvasRestore acr(canvas, true); |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 887 | if (benchMode == kPictureRecord_benchModes) { |
| 888 | pictureRecordFrom.draw(canvas); |
| 889 | } else { |
| 890 | bench->draw(canvas); |
| 891 | } |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 892 | canvas->flush(); |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 893 | |
| 894 | // stop the truncated timer after the last canvas call but |
| 895 | // don't wait for all the GL calls to complete |
| 896 | timer.truncatedEnd(); |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 897 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 898 | if (glHelper) { |
| 899 | glHelper->grContext()->flush(); |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 900 | SK_GL(*glHelper->glContext(), Finish()); |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 901 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 902 | #endif |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 903 | // stop the inclusive and gpu timers once all the GL calls |
| 904 | // have completed |
bensong@google.com | af3d79a | 2012-07-02 20:48:51 +0000 | [diff] [blame] | 905 | timer.end(); |
| 906 | |
| 907 | if (i == repeatDraw - 1) { |
| 908 | // no comma after the last value |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 909 | fWallStr.appendf(perIterTimeformat.c_str(), timer.fWall); |
| 910 | fCpuStr.appendf(perIterTimeformat.c_str(), timer.fCpu); |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 911 | fTruncatedWallStr.appendf(perIterTimeformat.c_str(), timer.fTruncatedWall); |
| 912 | fTruncatedCpuStr.appendf(perIterTimeformat.c_str(), timer.fTruncatedCpu); |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 913 | fGpuStr.appendf(perIterTimeformat.c_str(), timer.fGpu); |
bensong@google.com | af3d79a | 2012-07-02 20:48:51 +0000 | [diff] [blame] | 914 | } else { |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 915 | fWallStr.appendf(perIterTimeformat.c_str(), timer.fWall); |
| 916 | fWallStr.appendf(","); |
| 917 | fCpuStr.appendf(perIterTimeformat.c_str(), timer.fCpu); |
| 918 | fCpuStr.appendf(","); |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 919 | fTruncatedWallStr.appendf(perIterTimeformat.c_str(), timer.fTruncatedWall); |
| 920 | fTruncatedWallStr.appendf(","); |
| 921 | fTruncatedCpuStr.appendf(perIterTimeformat.c_str(), timer.fTruncatedCpu); |
| 922 | fTruncatedCpuStr.appendf(","); |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 923 | fGpuStr.appendf(perIterTimeformat.c_str(), timer.fGpu); |
| 924 | fGpuStr.appendf(","); |
bensong@google.com | af3d79a | 2012-07-02 20:48:51 +0000 | [diff] [blame] | 925 | } |
robertphillips@google.com | 2abed83 | 2012-08-23 17:50:06 +0000 | [diff] [blame] | 926 | |
| 927 | if (0 == i) { |
| 928 | fWallMin = timer.fWall; |
| 929 | fCpuMin = timer.fCpu; |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 930 | fTruncatedWallMin = timer.fTruncatedWall; |
| 931 | fTruncatedCpuMin = timer.fTruncatedCpu; |
robertphillips@google.com | 2abed83 | 2012-08-23 17:50:06 +0000 | [diff] [blame] | 932 | fGpuMin = timer.fGpu; |
| 933 | } else { |
| 934 | fWallMin = Min(fWallMin, timer.fWall); |
| 935 | fCpuMin = Min(fCpuMin, timer.fCpu); |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 936 | fTruncatedWallMin = Min(fTruncatedWallMin, timer.fTruncatedWall); |
| 937 | fTruncatedCpuMin = Min(fTruncatedCpuMin, timer.fTruncatedCpu); |
robertphillips@google.com | 2abed83 | 2012-08-23 17:50:06 +0000 | [diff] [blame] | 938 | fGpuMin = Min(fGpuMin, timer.fGpu); |
| 939 | } |
| 940 | |
bensong@google.com | af3d79a | 2012-07-02 20:48:51 +0000 | [diff] [blame] | 941 | fWallSum += timer.fWall; |
| 942 | fCpuSum += timer.fCpu; |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 943 | fTruncatedWallSum += timer.fTruncatedWall; |
| 944 | fTruncatedCpuSum += timer.fTruncatedCpu; |
bensong@google.com | af3d79a | 2012-07-02 20:48:51 +0000 | [diff] [blame] | 945 | fGpuSum += timer.fGpu; |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 946 | } |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 947 | if (repeatDraw > 1) { |
bensong@google.com | af3d79a | 2012-07-02 20:48:51 +0000 | [diff] [blame] | 948 | // output each repeat (no average) if logPerIter is set, |
| 949 | // otherwise output only the average |
| 950 | if (!logPerIter) { |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 951 | fWallStr.set(" msecs = "); |
robertphillips@google.com | 2abed83 | 2012-08-23 17:50:06 +0000 | [diff] [blame] | 952 | fWallStr.appendf(normalTimeFormat.c_str(), |
| 953 | printMin ? fWallMin : fWallSum / repeatDraw); |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 954 | fCpuStr.set(" cmsecs = "); |
robertphillips@google.com | 2abed83 | 2012-08-23 17:50:06 +0000 | [diff] [blame] | 955 | fCpuStr.appendf(normalTimeFormat.c_str(), |
| 956 | printMin ? fCpuMin : fCpuSum / repeatDraw); |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 957 | fTruncatedWallStr.set(" Wmsecs = "); |
| 958 | fTruncatedWallStr.appendf(normalTimeFormat.c_str(), |
| 959 | printMin ? fTruncatedWallMin : fTruncatedWallSum / repeatDraw); |
| 960 | fTruncatedCpuStr.set(" Cmsecs = "); |
| 961 | fTruncatedCpuStr.appendf(normalTimeFormat.c_str(), |
| 962 | printMin ? fTruncatedCpuMin : fTruncatedCpuSum / repeatDraw); |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 963 | fGpuStr.set(" gmsecs = "); |
robertphillips@google.com | 2abed83 | 2012-08-23 17:50:06 +0000 | [diff] [blame] | 964 | fGpuStr.appendf(normalTimeFormat.c_str(), |
| 965 | printMin ? fGpuMin : fGpuSum / repeatDraw); |
bensong@google.com | af3d79a | 2012-07-02 20:48:51 +0000 | [diff] [blame] | 966 | } |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 967 | SkString str; |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 968 | str.printf(" %4s:", configName); |
| 969 | if (timerWall) { |
bensong@google.com | af3d79a | 2012-07-02 20:48:51 +0000 | [diff] [blame] | 970 | str += fWallStr; |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 971 | } |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 972 | if (truncatedTimerWall) { |
| 973 | str += fTruncatedWallStr; |
| 974 | } |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 975 | if (timerCpu) { |
bensong@google.com | af3d79a | 2012-07-02 20:48:51 +0000 | [diff] [blame] | 976 | str += fCpuStr; |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 977 | } |
robertphillips@google.com | 91ee3a1 | 2012-08-28 12:18:40 +0000 | [diff] [blame] | 978 | if (truncatedTimerCpu) { |
| 979 | str += fTruncatedCpuStr; |
| 980 | } |
bensong@google.com | af3d79a | 2012-07-02 20:48:51 +0000 | [diff] [blame] | 981 | if (timerGpu && glHelper && fGpuSum > 0) { |
| 982 | str += fGpuStr; |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 983 | } |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 984 | logger.logProgress(str); |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 985 | } |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 986 | if (outDir.size() > 0) { |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 987 | saveFile(bench->getName(), configName, outDir.c_str(), |
| 988 | device->accessBitmap(false)); |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 989 | } |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 990 | } |
borenet@google.com | a2b32b8 | 2012-08-07 12:58:50 +0000 | [diff] [blame] | 991 | logger.logProgress(SkString("\n")); |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 992 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 993 | #if SK_SUPPORT_GPU |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 994 | // need to clean up here rather than post-main to allow leak detection to work |
| 995 | gDebugGLHelper.cleanup(); |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 996 | #endif |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 997 | return 0; |
| 998 | } |