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