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