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 | |
| 12 | #include "GrContext.h" |
| 13 | #include "GrRenderTarget.h" |
| 14 | |
| 15 | #include "SkBenchmark.h" |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 16 | #include "SkCanvas.h" |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 17 | #include "SkDeferredCanvas.h" |
reed@android.com | f523e25 | 2009-01-26 23:15:37 +0000 | [diff] [blame] | 18 | #include "SkColorPriv.h" |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 19 | #include "SkGpuDevice.h" |
reed@android.com | 3a859a0 | 2009-01-28 00:56:29 +0000 | [diff] [blame] | 20 | #include "SkGraphics.h" |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 21 | #include "SkImageEncoder.h" |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 22 | #if SK_ANGLE |
| 23 | #include "gl/SkANGLEGLContext.h" |
| 24 | #endif |
tomhudson@google.com | 6bf38b5 | 2012-02-14 15:11:59 +0000 | [diff] [blame] | 25 | #include "gl/SkNativeGLContext.h" |
| 26 | #include "gl/SkNullGLContext.h" |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 27 | #include "gl/SkDebugGLContext.h" |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 28 | #include "SkNWayCanvas.h" |
| 29 | #include "SkPicture.h" |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 30 | #include "SkString.h" |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 31 | |
djsollen@google.com | 56c6977 | 2011-11-08 19:00:26 +0000 | [diff] [blame] | 32 | #ifdef SK_BUILD_FOR_ANDROID |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 33 | static void log_error(const char msg[]) { SkDebugf("%s", msg); } |
| 34 | static void log_progress(const char msg[]) { SkDebugf("%s", msg); } |
| 35 | #else |
| 36 | static void log_error(const char msg[]) { fprintf(stderr, "%s", msg); } |
| 37 | static void log_progress(const char msg[]) { printf("%s", msg); } |
| 38 | #endif |
| 39 | |
| 40 | static void log_error(const SkString& str) { log_error(str.c_str()); } |
| 41 | static void log_progress(const SkString& str) { log_progress(str.c_str()); } |
| 42 | |
| 43 | /////////////////////////////////////////////////////////////////////////////// |
| 44 | |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 45 | static void erase(SkBitmap& bm) { |
| 46 | if (bm.config() == SkBitmap::kA8_Config) { |
| 47 | bm.eraseColor(0); |
| 48 | } else { |
| 49 | bm.eraseColor(SK_ColorWHITE); |
| 50 | } |
| 51 | } |
| 52 | |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 53 | #if 0 |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 54 | static bool equal(const SkBitmap& bm1, const SkBitmap& bm2) { |
| 55 | if (bm1.width() != bm2.width() || |
| 56 | bm1.height() != bm2.height() || |
| 57 | bm1.config() != bm2.config()) { |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | size_t pixelBytes = bm1.width() * bm1.bytesPerPixel(); |
| 62 | for (int y = 0; y < bm1.height(); y++) { |
| 63 | if (memcmp(bm1.getAddr(0, y), bm2.getAddr(0, y), pixelBytes)) { |
| 64 | return false; |
| 65 | } |
| 66 | } |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 67 | return true; |
| 68 | } |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 69 | #endif |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 70 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 71 | class Iter { |
| 72 | public: |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 73 | Iter(void* param) { |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 74 | fBench = BenchRegistry::Head(); |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 75 | fParam = param; |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | SkBenchmark* next() { |
| 79 | if (fBench) { |
| 80 | BenchRegistry::Factory f = fBench->factory(); |
| 81 | fBench = fBench->next(); |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 82 | return f(fParam); |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 83 | } |
| 84 | return NULL; |
| 85 | } |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 86 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 87 | private: |
| 88 | const BenchRegistry* fBench; |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 89 | void* fParam; |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | static void make_filename(const char name[], SkString* path) { |
| 93 | path->set(name); |
| 94 | for (int i = 0; name[i]; i++) { |
| 95 | switch (name[i]) { |
| 96 | case '/': |
| 97 | case '\\': |
| 98 | case ' ': |
| 99 | case ':': |
| 100 | path->writable_str()[i] = '-'; |
| 101 | break; |
| 102 | default: |
| 103 | break; |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 108 | static void saveFile(const char name[], const char config[], const char dir[], |
| 109 | const SkBitmap& bm) { |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 110 | SkBitmap copy; |
| 111 | if (!bm.copyTo(©, SkBitmap::kARGB_8888_Config)) { |
| 112 | return; |
| 113 | } |
reed@android.com | f523e25 | 2009-01-26 23:15:37 +0000 | [diff] [blame] | 114 | |
| 115 | if (bm.config() == SkBitmap::kA8_Config) { |
| 116 | // turn alpha into gray-scale |
| 117 | size_t size = copy.getSize() >> 2; |
| 118 | SkPMColor* p = copy.getAddr32(0, 0); |
| 119 | for (size_t i = 0; i < size; i++) { |
| 120 | int c = (*p >> SK_A32_SHIFT) & 0xFF; |
| 121 | c = 255 - c; |
| 122 | c |= (c << 24) | (c << 16) | (c << 8); |
| 123 | *p++ = c | (SK_A32_MASK << SK_A32_SHIFT); |
| 124 | } |
| 125 | } |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 126 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 127 | SkString str; |
| 128 | make_filename(name, &str); |
| 129 | str.appendf("_%s.png", config); |
| 130 | str.prepend(dir); |
| 131 | ::remove(str.c_str()); |
| 132 | SkImageEncoder::EncodeFile(str.c_str(), copy, SkImageEncoder::kPNG_Type, |
| 133 | 100); |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | static void performClip(SkCanvas* canvas, int w, int h) { |
| 137 | SkRect r; |
| 138 | |
| 139 | r.set(SkIntToScalar(10), SkIntToScalar(10), |
| 140 | SkIntToScalar(w*2/3), SkIntToScalar(h*2/3)); |
| 141 | canvas->clipRect(r, SkRegion::kIntersect_Op); |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 142 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 143 | r.set(SkIntToScalar(w/3), SkIntToScalar(h/3), |
| 144 | SkIntToScalar(w-10), SkIntToScalar(h-10)); |
| 145 | canvas->clipRect(r, SkRegion::kXOR_Op); |
| 146 | } |
| 147 | |
| 148 | static void performRotate(SkCanvas* canvas, int w, int h) { |
| 149 | const SkScalar x = SkIntToScalar(w) / 2; |
| 150 | const SkScalar y = SkIntToScalar(h) / 2; |
| 151 | |
| 152 | canvas->translate(x, y); |
| 153 | canvas->rotate(SkIntToScalar(35)); |
| 154 | canvas->translate(-x, -y); |
| 155 | } |
| 156 | |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 157 | static void performScale(SkCanvas* canvas, int w, int h) { |
| 158 | const SkScalar x = SkIntToScalar(w) / 2; |
| 159 | const SkScalar y = SkIntToScalar(h) / 2; |
| 160 | |
| 161 | canvas->translate(x, y); |
| 162 | // just enough so we can't take the sprite case |
| 163 | canvas->scale(SK_Scalar1 * 99/100, SK_Scalar1 * 99/100); |
| 164 | canvas->translate(-x, -y); |
| 165 | } |
| 166 | |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 167 | static bool parse_bool_arg(char * const* argv, char* const* stop, bool* var) { |
| 168 | if (argv < stop) { |
| 169 | *var = atoi(*argv) != 0; |
| 170 | return true; |
| 171 | } |
| 172 | return false; |
| 173 | } |
| 174 | |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 175 | enum Backend { |
| 176 | kRaster_Backend, |
| 177 | kGPU_Backend, |
| 178 | kPDF_Backend, |
| 179 | }; |
| 180 | |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 181 | class GLHelper { |
| 182 | public: |
| 183 | GLHelper() { |
| 184 | } |
| 185 | |
| 186 | bool init(SkGLContext* glCtx, int width, int height) { |
| 187 | GrContext* grCtx; |
| 188 | GrRenderTarget* rt; |
| 189 | if (glCtx->init(width, height)) { |
| 190 | GrPlatform3DContext ctx = |
| 191 | reinterpret_cast<GrPlatform3DContext>(glCtx->gl()); |
| 192 | grCtx = GrContext::Create(kOpenGL_Shaders_GrEngine, ctx); |
| 193 | if (NULL != grCtx) { |
| 194 | GrPlatformRenderTargetDesc desc; |
| 195 | desc.fConfig = kSkia8888_PM_GrPixelConfig; |
| 196 | desc.fWidth = width; |
| 197 | desc.fHeight = height; |
| 198 | desc.fStencilBits = 8; |
| 199 | desc.fRenderTargetHandle = glCtx->getFBOID(); |
| 200 | rt = grCtx->createPlatformRenderTarget(desc); |
| 201 | if (NULL == rt) { |
| 202 | grCtx->unref(); |
| 203 | return false; |
| 204 | } |
| 205 | } |
| 206 | } else { |
| 207 | return false; |
| 208 | } |
| 209 | glCtx->ref(); |
| 210 | fGLContext.reset(glCtx); |
| 211 | fGrContext.reset(grCtx); |
| 212 | fRenderTarget.reset(rt); |
| 213 | return true; |
| 214 | } |
| 215 | |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 216 | void cleanup() { |
| 217 | fGLContext.reset(NULL); |
| 218 | fGrContext.reset(NULL); |
| 219 | fRenderTarget.reset(NULL); |
| 220 | } |
| 221 | |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 222 | bool isValid() { |
| 223 | return NULL != fGLContext.get(); |
| 224 | } |
| 225 | |
| 226 | SkGLContext* glContext() { |
| 227 | return fGLContext.get(); |
| 228 | } |
| 229 | |
| 230 | GrRenderTarget* renderTarget() { |
| 231 | return fRenderTarget.get(); |
| 232 | } |
| 233 | |
| 234 | GrContext* grContext() { |
| 235 | return fGrContext.get(); |
| 236 | } |
| 237 | private: |
| 238 | SkAutoTUnref<SkGLContext> fGLContext; |
| 239 | SkAutoTUnref<GrContext> fGrContext; |
| 240 | SkAutoTUnref<GrRenderTarget> fRenderTarget; |
| 241 | }; |
| 242 | |
| 243 | static GLHelper gRealGLHelper; |
| 244 | static GLHelper gNullGLHelper; |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 245 | static GLHelper gDebugGLHelper; |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 246 | #if SK_ANGLE |
| 247 | static GLHelper gANGLEGLHelper; |
| 248 | #endif |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 249 | |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 250 | static SkDevice* make_device(SkBitmap::Config config, const SkIPoint& size, |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 251 | Backend backend, GLHelper* glHelper) { |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 252 | SkDevice* device = NULL; |
| 253 | SkBitmap bitmap; |
| 254 | bitmap.setConfig(config, size.fX, size.fY); |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 255 | |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 256 | switch (backend) { |
| 257 | case kRaster_Backend: |
| 258 | bitmap.allocPixels(); |
| 259 | erase(bitmap); |
reed@google.com | af951c9 | 2011-06-16 19:10:39 +0000 | [diff] [blame] | 260 | device = new SkDevice(bitmap); |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 261 | break; |
| 262 | case kGPU_Backend: |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 263 | device = new SkGpuDevice(glHelper->grContext(), |
| 264 | glHelper->renderTarget()); |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 265 | break; |
| 266 | case kPDF_Backend: |
| 267 | default: |
| 268 | SkASSERT(!"unsupported"); |
| 269 | } |
| 270 | return device; |
| 271 | } |
| 272 | |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 273 | static const struct { |
| 274 | SkBitmap::Config fConfig; |
| 275 | const char* fName; |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 276 | Backend fBackend; |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 277 | GLHelper* fGLHelper; |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 278 | } gConfigs[] = { |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 279 | { SkBitmap::kARGB_8888_Config, "8888", kRaster_Backend, NULL }, |
| 280 | { SkBitmap::kRGB_565_Config, "565", kRaster_Backend, NULL }, |
| 281 | { SkBitmap::kARGB_8888_Config, "GPU", kGPU_Backend, &gRealGLHelper }, |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 282 | #if SK_ANGLE |
| 283 | { SkBitmap::kARGB_8888_Config, "ANGLE", kGPU_Backend, &gANGLEGLHelper }, |
| 284 | #endif |
robertphillips@google.com | a0b63b8 | 2012-03-30 12:23:56 +0000 | [diff] [blame] | 285 | #ifdef SK_DEBUG |
| 286 | { SkBitmap::kARGB_8888_Config, "Debug", kGPU_Backend, &gDebugGLHelper }, |
| 287 | #endif |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 288 | { SkBitmap::kARGB_8888_Config, "NULLGPU", kGPU_Backend, &gNullGLHelper }, |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 289 | }; |
| 290 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 291 | static int findConfig(const char config[]) { |
| 292 | for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); i++) { |
| 293 | if (!strcmp(config, gConfigs[i].fName)) { |
| 294 | return i; |
| 295 | } |
| 296 | } |
| 297 | return -1; |
| 298 | } |
| 299 | |
tomhudson@google.com | 8382394 | 2011-10-28 14:59:07 +0000 | [diff] [blame] | 300 | static void determine_gpu_context_size(SkTDict<const char*>& defineDict, |
| 301 | int* contextWidth, |
| 302 | int* contextHeight) { |
| 303 | Iter iter(&defineDict); |
| 304 | SkBenchmark* bench; |
| 305 | while ((bench = iter.next()) != NULL) { |
| 306 | SkIPoint dim = bench->getSize(); |
| 307 | if (*contextWidth < dim.fX) { |
| 308 | *contextWidth = dim.fX; |
| 309 | } |
| 310 | if (*contextHeight < dim.fY) { |
| 311 | *contextHeight = dim.fY; |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
reed@google.com | 1a7eabc | 2011-10-31 16:33:52 +0000 | [diff] [blame] | 316 | static bool skip_name(const SkTDArray<const char*> array, const char name[]) { |
| 317 | if (0 == array.count()) { |
| 318 | // no names, so don't skip anything |
| 319 | return false; |
| 320 | } |
| 321 | for (int i = 0; i < array.count(); ++i) { |
| 322 | if (strstr(name, array[i])) { |
| 323 | // found the name, so don't skip |
| 324 | return false; |
| 325 | } |
| 326 | } |
| 327 | return true; |
| 328 | } |
| 329 | |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 330 | static void help() { |
| 331 | SkDebugf("Usage: bench [-o outDir] [-repeat nr] " |
| 332 | "[-timers [wcg]*] [-rotate]\n" |
| 333 | " [-scale] [-clip] [-forceAA 1|0] [-forceFilter 1|0]\n" |
| 334 | " [-forceDither 1|0] [-forceBlend 1|0] [-strokeWidth width]\n" |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 335 | " [-forceDeferred 1|0] [-match name]\n" |
| 336 | " [-config 8888|565|GPU|ANGLE|NULLGPU] [-Dfoo bar]\n" |
| 337 | " [-h|--help]"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 338 | SkDebugf("\n\n"); |
| 339 | SkDebugf(" -o outDir : Image of each bench will be put in outDir.\n"); |
| 340 | SkDebugf(" -repeat nr : Each bench repeats for nr times.\n"); |
| 341 | SkDebugf(" -timers [wcg]* : " |
| 342 | "Display wall time, cpu time or gpu time for each bench.\n"); |
| 343 | SkDebugf(" -rotate : Rotate before each bench runs.\n"); |
| 344 | SkDebugf(" -scale : Scale before each bench runs.\n"); |
| 345 | SkDebugf(" -clip : Clip before each bench runs.\n"); |
| 346 | SkDebugf(" -forceAA 1|0 : " |
| 347 | "Enable/disable anti-aliased, default is enabled.\n"); |
| 348 | SkDebugf(" -forceFilter 1|0 : " |
| 349 | "Enable/disable bitmap filtering, default is disabled.\n"); |
| 350 | SkDebugf(" -forceDither 1|0 : " |
| 351 | "Enable/disable dithering, default is disabled.\n"); |
| 352 | SkDebugf(" -forceBlend 1|0 : " |
| 353 | "Enable/disable dithering, default is disabled.\n"); |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 354 | SkDebugf(" -forceDeferred 1|0 : " |
| 355 | "Enable/disable deferred canvas, default is disabled.\n"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 356 | SkDebugf(" -strokeWidth width : The width for path stroke.\n"); |
| 357 | SkDebugf(" -match name : Only run bench whose name is matched.\n"); |
| 358 | SkDebugf(" -config 8888|565|GPU|ANGLE|NULLGPU : " |
| 359 | "Run bench in corresponding config mode.\n"); |
| 360 | SkDebugf(" -Dfoo bar : Add extra definition to bench.\n"); |
| 361 | SkDebugf(" -h|--help : Show this help message.\n"); |
| 362 | } |
| 363 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 364 | int main (int argc, char * const argv[]) { |
reed@android.com | 3a859a0 | 2009-01-28 00:56:29 +0000 | [diff] [blame] | 365 | SkAutoGraphics ag; |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 366 | |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 367 | SkTDict<const char*> defineDict(1024); |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 368 | int repeatDraw = 1; |
| 369 | int forceAlpha = 0xFF; |
| 370 | bool forceAA = true; |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 371 | bool forceFilter = false; |
reed@android.com | 4e635f9 | 2009-10-19 17:39:46 +0000 | [diff] [blame] | 372 | SkTriState::State forceDither = SkTriState::kDefault; |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 373 | bool forceDeferred = false; |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 374 | bool timerWall = false; |
| 375 | bool timerCpu = true; |
| 376 | bool timerGpu = true; |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 377 | bool doScale = false; |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 378 | bool doRotate = false; |
| 379 | bool doClip = false; |
agl@chromium.org | 652807b | 2010-04-27 15:47:34 +0000 | [diff] [blame] | 380 | bool hasStrokeWidth = false; |
| 381 | float strokeWidth; |
reed@google.com | 1a7eabc | 2011-10-31 16:33:52 +0000 | [diff] [blame] | 382 | SkTDArray<const char*> fMatches; |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 383 | |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 384 | SkString outDir; |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 385 | SkBitmap::Config outConfig = SkBitmap::kNo_Config; |
bsalomon@google.com | cadbcb8 | 2012-01-06 19:22:11 +0000 | [diff] [blame] | 386 | GLHelper* glHelper = NULL; |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 387 | const char* configName = ""; |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 388 | Backend backend = kRaster_Backend; // for warning |
tomhudson@google.com | 13eaaaa | 2012-04-16 18:00:40 +0000 | [diff] [blame] | 389 | SkTDArray<int> configs; |
| 390 | bool userConfig = false; |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 391 | |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 392 | char* const* stop = argv + argc; |
| 393 | for (++argv; argv < stop; ++argv) { |
| 394 | if (strcmp(*argv, "-o") == 0) { |
| 395 | argv++; |
| 396 | if (argv < stop && **argv) { |
| 397 | outDir.set(*argv); |
| 398 | if (outDir.c_str()[outDir.size() - 1] != '/') { |
| 399 | outDir.append("/"); |
| 400 | } |
| 401 | } |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 402 | } else if (strcmp(*argv, "-repeat") == 0) { |
| 403 | argv++; |
| 404 | if (argv < stop) { |
| 405 | repeatDraw = atoi(*argv); |
| 406 | if (repeatDraw < 1) { |
| 407 | repeatDraw = 1; |
| 408 | } |
| 409 | } else { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 410 | log_error("missing arg for -repeat\n"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 411 | help(); |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 412 | return -1; |
| 413 | } |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 414 | } else if (strcmp(*argv, "-timers") == 0) { |
| 415 | argv++; |
| 416 | if (argv < stop) { |
| 417 | timerWall = false; |
| 418 | timerCpu = false; |
| 419 | timerGpu = false; |
| 420 | for (char* t = *argv; *t; ++t) { |
| 421 | switch (*t) { |
| 422 | case 'w': timerWall = true; break; |
| 423 | case 'c': timerCpu = true; break; |
| 424 | case 'g': timerGpu = true; break; |
| 425 | } |
| 426 | } |
| 427 | } else { |
| 428 | log_error("missing arg for -timers\n"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 429 | help(); |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 430 | return -1; |
| 431 | } |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 432 | } else if (!strcmp(*argv, "-rotate")) { |
| 433 | doRotate = true; |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 434 | } else if (!strcmp(*argv, "-scale")) { |
| 435 | doScale = true; |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 436 | } else if (!strcmp(*argv, "-clip")) { |
| 437 | doClip = true; |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 438 | } else if (strcmp(*argv, "-forceAA") == 0) { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 439 | if (!parse_bool_arg(++argv, stop, &forceAA)) { |
| 440 | log_error("missing arg for -forceAA\n"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 441 | help(); |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 442 | return -1; |
| 443 | } |
| 444 | } else if (strcmp(*argv, "-forceFilter") == 0) { |
| 445 | if (!parse_bool_arg(++argv, stop, &forceFilter)) { |
| 446 | log_error("missing arg for -forceFilter\n"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 447 | help(); |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 448 | return -1; |
| 449 | } |
reed@android.com | 4e635f9 | 2009-10-19 17:39:46 +0000 | [diff] [blame] | 450 | } else if (strcmp(*argv, "-forceDither") == 0) { |
| 451 | bool tmp; |
| 452 | if (!parse_bool_arg(++argv, stop, &tmp)) { |
| 453 | log_error("missing arg for -forceDither\n"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 454 | help(); |
reed@android.com | 4e635f9 | 2009-10-19 17:39:46 +0000 | [diff] [blame] | 455 | return -1; |
| 456 | } |
| 457 | forceDither = tmp ? SkTriState::kTrue : SkTriState::kFalse; |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 458 | } else if (strcmp(*argv, "-forceBlend") == 0) { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 459 | bool wantAlpha = false; |
| 460 | if (!parse_bool_arg(++argv, stop, &wantAlpha)) { |
| 461 | log_error("missing arg for -forceBlend\n"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 462 | help(); |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 463 | return -1; |
| 464 | } |
| 465 | forceAlpha = wantAlpha ? 0x80 : 0xFF; |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 466 | } else if (strcmp(*argv, "-forceDeferred") == 0) { |
| 467 | if (!parse_bool_arg(++argv, stop, &forceDeferred)) { |
| 468 | log_error("missing arg for -forceDeferred\n"); |
| 469 | help(); |
| 470 | return -1; |
| 471 | } |
agl@chromium.org | 652807b | 2010-04-27 15:47:34 +0000 | [diff] [blame] | 472 | } else if (strcmp(*argv, "-strokeWidth") == 0) { |
| 473 | argv++; |
| 474 | if (argv < stop) { |
| 475 | const char *strokeWidthStr = *argv; |
| 476 | if (sscanf(strokeWidthStr, "%f", &strokeWidth) != 1) { |
| 477 | log_error("bad arg for -strokeWidth\n"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 478 | help(); |
agl@chromium.org | 652807b | 2010-04-27 15:47:34 +0000 | [diff] [blame] | 479 | return -1; |
| 480 | } |
| 481 | hasStrokeWidth = true; |
| 482 | } else { |
| 483 | log_error("missing arg for -strokeWidth\n"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 484 | help(); |
agl@chromium.org | 652807b | 2010-04-27 15:47:34 +0000 | [diff] [blame] | 485 | return -1; |
| 486 | } |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 487 | } else if (strcmp(*argv, "-match") == 0) { |
| 488 | argv++; |
| 489 | if (argv < stop) { |
reed@google.com | 1a7eabc | 2011-10-31 16:33:52 +0000 | [diff] [blame] | 490 | *fMatches.append() = *argv; |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 491 | } else { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 492 | log_error("missing arg for -match\n"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 493 | help(); |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 494 | return -1; |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 495 | } |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 496 | } else if (strcmp(*argv, "-config") == 0) { |
| 497 | argv++; |
| 498 | if (argv < stop) { |
| 499 | int index = findConfig(*argv); |
| 500 | if (index >= 0) { |
tomhudson@google.com | 13eaaaa | 2012-04-16 18:00:40 +0000 | [diff] [blame] | 501 | *configs.append() = index; |
| 502 | userConfig = true; |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 503 | } else { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 504 | SkString str; |
| 505 | str.printf("unrecognized config %s\n", *argv); |
| 506 | log_error(str); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 507 | help(); |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 508 | return -1; |
| 509 | } |
| 510 | } else { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 511 | log_error("missing arg for -config\n"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 512 | help(); |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 513 | return -1; |
| 514 | } |
reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 515 | } else if (strlen(*argv) > 2 && strncmp(*argv, "-D", 2) == 0) { |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 516 | argv++; |
reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 517 | if (argv < stop) { |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 518 | defineDict.set(argv[-1] + 2, *argv); |
| 519 | } else { |
| 520 | log_error("incomplete '-Dfoo bar' definition\n"); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 521 | help(); |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 522 | return -1; |
| 523 | } |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 524 | } else if (strcmp(*argv, "--help") == 0 || strcmp(*argv, "-h") == 0) { |
| 525 | help(); |
| 526 | return 0; |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 527 | } else { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 528 | SkString str; |
| 529 | str.printf("unrecognized arg %s\n", *argv); |
| 530 | log_error(str); |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 531 | help(); |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 532 | return -1; |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 533 | } |
| 534 | } |
tomhudson@google.com | 13eaaaa | 2012-04-16 18:00:40 +0000 | [diff] [blame] | 535 | if (!userConfig) { |
| 536 | // if no config is specified by user, we add them all. |
| 537 | for (unsigned int i = 0; i < SK_ARRAY_COUNT(gConfigs); ++i) { |
| 538 | *configs.append() = i; |
| 539 | } |
| 540 | } |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 541 | |
reed@google.com | 3b14dc1 | 2011-04-04 14:31:36 +0000 | [diff] [blame] | 542 | // report our current settings |
| 543 | { |
| 544 | SkString str; |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 545 | str.printf("skia bench: alpha=0x%02X antialias=%d filter=%d deferred=%d", |
| 546 | forceAlpha, forceAA, forceFilter, forceDeferred); |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 547 | str.appendf(" rotate=%d scale=%d clip=%d", |
| 548 | doRotate, doScale, doClip); |
| 549 | |
| 550 | const char * ditherName; |
| 551 | switch (forceDither) { |
| 552 | case SkTriState::kDefault: ditherName = "default"; break; |
| 553 | case SkTriState::kTrue: ditherName = "true"; break; |
| 554 | case SkTriState::kFalse: ditherName = "false"; break; |
| 555 | default: ditherName = "<invalid>"; break; |
| 556 | } |
| 557 | str.appendf(" dither=%s", ditherName); |
| 558 | |
| 559 | if (hasStrokeWidth) { |
| 560 | str.appendf(" strokeWidth=%f", strokeWidth); |
| 561 | } else { |
| 562 | str.append(" strokeWidth=none"); |
| 563 | } |
| 564 | |
| 565 | #if defined(SK_SCALAR_IS_FLOAT) |
| 566 | str.append(" scalar=float"); |
| 567 | #elif defined(SK_SCALAR_IS_FIXED) |
| 568 | str.append(" scalar=fixed"); |
| 569 | #endif |
| 570 | |
| 571 | #if defined(SK_BUILD_FOR_WIN32) |
| 572 | str.append(" system=WIN32"); |
| 573 | #elif defined(SK_BUILD_FOR_MAC) |
| 574 | str.append(" system=MAC"); |
| 575 | #elif defined(SK_BUILD_FOR_ANDROID) |
| 576 | str.append(" system=ANDROID"); |
| 577 | #elif defined(SK_BUILD_FOR_UNIX) |
| 578 | str.append(" system=UNIX"); |
| 579 | #else |
| 580 | str.append(" system=other"); |
| 581 | #endif |
| 582 | |
| 583 | #if defined(SK_DEBUG) |
| 584 | str.append(" DEBUG"); |
| 585 | #endif |
| 586 | str.append("\n"); |
reed@google.com | 3b14dc1 | 2011-04-04 14:31:36 +0000 | [diff] [blame] | 587 | log_progress(str); |
| 588 | } |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 589 | |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 590 | //Don't do GL when fixed. |
| 591 | #if !defined(SK_SCALAR_IS_FIXED) |
tomhudson@google.com | 8382394 | 2011-10-28 14:59:07 +0000 | [diff] [blame] | 592 | int contextWidth = 1024; |
| 593 | int contextHeight = 1024; |
| 594 | determine_gpu_context_size(defineDict, &contextWidth, &contextHeight); |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 595 | SkAutoTUnref<SkGLContext> realGLCtx(new SkNativeGLContext); |
| 596 | SkAutoTUnref<SkGLContext> nullGLCtx(new SkNullGLContext); |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 597 | SkAutoTUnref<SkGLContext> debugGLCtx(new SkDebugGLContext); |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 598 | #if SK_ANGLE |
| 599 | SkAutoTUnref<SkGLContext> angleGLCtx(new SkANGLEGLContext); |
| 600 | #endif |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 601 | gRealGLHelper.init(realGLCtx.get(), contextWidth, contextHeight); |
| 602 | gNullGLHelper.init(nullGLCtx.get(), contextWidth, contextHeight); |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 603 | gDebugGLHelper.init(debugGLCtx.get(), contextWidth, contextHeight); |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 604 | #if SK_ANGLE |
| 605 | gANGLEGLHelper.init(angleGLCtx.get(), contextWidth, contextHeight); |
| 606 | #endif |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 607 | #endif |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 608 | BenchTimer timer = BenchTimer(gRealGLHelper.glContext()); |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 609 | |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 610 | Iter iter(&defineDict); |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 611 | SkBenchmark* bench; |
| 612 | while ((bench = iter.next()) != NULL) { |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 613 | SkIPoint dim = bench->getSize(); |
| 614 | if (dim.fX <= 0 || dim.fY <= 0) { |
| 615 | continue; |
| 616 | } |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 617 | |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 618 | bench->setForceAlpha(forceAlpha); |
| 619 | bench->setForceAA(forceAA); |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 620 | bench->setForceFilter(forceFilter); |
reed@android.com | 4e635f9 | 2009-10-19 17:39:46 +0000 | [diff] [blame] | 621 | bench->setDither(forceDither); |
agl@chromium.org | 652807b | 2010-04-27 15:47:34 +0000 | [diff] [blame] | 622 | if (hasStrokeWidth) { |
| 623 | bench->setStrokeWidth(strokeWidth); |
| 624 | } |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 625 | |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 626 | // only run benchmarks if their name contains matchStr |
reed@google.com | 1a7eabc | 2011-10-31 16:33:52 +0000 | [diff] [blame] | 627 | if (skip_name(fMatches, bench->getName())) { |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 628 | continue; |
| 629 | } |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 630 | |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 631 | { |
| 632 | SkString str; |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 633 | str.printf("running bench [%d %d] %28s", dim.fX, dim.fY, |
reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 634 | bench->getName()); |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 635 | log_progress(str); |
| 636 | } |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 637 | |
tomhudson@google.com | 13eaaaa | 2012-04-16 18:00:40 +0000 | [diff] [blame] | 638 | for (int x = 0; x < configs.count(); ++x) { |
| 639 | int configIndex = configs[x]; |
| 640 | |
| 641 | outConfig = gConfigs[configIndex].fConfig; |
| 642 | configName = gConfigs[configIndex].fName; |
| 643 | backend = gConfigs[configIndex].fBackend; |
| 644 | glHelper = gConfigs[configIndex].fGLHelper; |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 645 | |
| 646 | if (kGPU_Backend == backend && |
| 647 | (NULL == glHelper || !glHelper->isValid())) { |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 648 | continue; |
| 649 | } |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 650 | |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 651 | SkDevice* device = make_device(outConfig, dim, backend, glHelper); |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 652 | SkCanvas* canvas; |
| 653 | if (forceDeferred) { |
| 654 | canvas = new SkDeferredCanvas(device); |
| 655 | } else { |
| 656 | canvas = new SkCanvas(device); |
| 657 | } |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 658 | device->unref(); |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 659 | SkAutoUnref canvasUnref(canvas); |
| 660 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 661 | if (doClip) { |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 662 | performClip(canvas, dim.fX, dim.fY); |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 663 | } |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 664 | if (doScale) { |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 665 | performScale(canvas, dim.fX, dim.fY); |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 666 | } |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 667 | if (doRotate) { |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 668 | performRotate(canvas, dim.fX, dim.fY); |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 669 | } |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 670 | |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 671 | //warm up caches if needed |
reed@android.com | eca4836 | 2010-12-20 18:34:17 +0000 | [diff] [blame] | 672 | if (repeatDraw > 1) { |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 673 | SkAutoCanvasRestore acr(canvas, true); |
| 674 | bench->draw(canvas); |
| 675 | canvas->flush(); |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 676 | if (glHelper) { |
| 677 | glHelper->grContext()->flush(); |
| 678 | SK_GL(*glHelper->glContext(), Finish()); |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 679 | } |
reed@android.com | eca4836 | 2010-12-20 18:34:17 +0000 | [diff] [blame] | 680 | } |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 681 | |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 682 | timer.start(); |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 683 | for (int i = 0; i < repeatDraw; i++) { |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 684 | SkAutoCanvasRestore acr(canvas, true); |
| 685 | bench->draw(canvas); |
| 686 | canvas->flush(); |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 687 | if (glHelper) { |
| 688 | glHelper->grContext()->flush(); |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 689 | } |
| 690 | } |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 691 | if (glHelper) { |
| 692 | SK_GL(*glHelper->glContext(), Finish()); |
bsalomon@google.com | 788e247 | 2011-10-19 20:56:30 +0000 | [diff] [blame] | 693 | } |
bsalomon@google.com | 788e247 | 2011-10-19 20:56:30 +0000 | [diff] [blame] | 694 | timer.end(); |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 695 | |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 696 | if (repeatDraw > 1) { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 697 | SkString str; |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 698 | str.printf(" %4s:", configName); |
| 699 | if (timerWall) { |
| 700 | str.appendf(" msecs = %6.2f", timer.fWall / repeatDraw); |
| 701 | } |
| 702 | if (timerCpu) { |
| 703 | str.appendf(" cmsecs = %6.2f", timer.fCpu / repeatDraw); |
| 704 | } |
bsalomon@google.com | 508824b | 2011-12-13 16:49:49 +0000 | [diff] [blame] | 705 | if (timerGpu && glHelper && timer.fGpu > 0) { |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 706 | str.appendf(" gmsecs = %6.2f", timer.fGpu / repeatDraw); |
| 707 | } |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 708 | log_progress(str); |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 709 | } |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 710 | if (outDir.size() > 0) { |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 711 | saveFile(bench->getName(), configName, outDir.c_str(), |
| 712 | device->accessBitmap(false)); |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 713 | } |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 714 | } |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 715 | log_progress("\n"); |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 716 | } |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 717 | |
robertphillips@google.com | 0da3719 | 2012-03-19 14:42:13 +0000 | [diff] [blame] | 718 | // need to clean up here rather than post-main to allow leak detection to work |
| 719 | gDebugGLHelper.cleanup(); |
| 720 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 721 | return 0; |
| 722 | } |