epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 8 | |
| 9 | |
| 10 | #include "BenchTimer.h" |
| 11 | |
| 12 | #include "GrContext.h" |
| 13 | #include "GrRenderTarget.h" |
| 14 | |
| 15 | #include "SkBenchmark.h" |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 16 | #include "SkCanvas.h" |
reed@android.com | f523e25 | 2009-01-26 23:15:37 +0000 | [diff] [blame] | 17 | #include "SkColorPriv.h" |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 18 | #include "SkGpuDevice.h" |
reed@android.com | 3a859a0 | 2009-01-28 00:56:29 +0000 | [diff] [blame] | 19 | #include "SkGraphics.h" |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 20 | #include "SkImageEncoder.h" |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 21 | #include "SkNativeGLContext.h" |
| 22 | #include "SkNullGLContext.h" |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 23 | #include "SkNWayCanvas.h" |
| 24 | #include "SkPicture.h" |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 25 | #include "SkString.h" |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 26 | |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 27 | #ifdef ANDROID |
| 28 | static void log_error(const char msg[]) { SkDebugf("%s", msg); } |
| 29 | static void log_progress(const char msg[]) { SkDebugf("%s", msg); } |
| 30 | #else |
| 31 | static void log_error(const char msg[]) { fprintf(stderr, "%s", msg); } |
| 32 | static void log_progress(const char msg[]) { printf("%s", msg); } |
| 33 | #endif |
| 34 | |
| 35 | static void log_error(const SkString& str) { log_error(str.c_str()); } |
| 36 | static void log_progress(const SkString& str) { log_progress(str.c_str()); } |
| 37 | |
| 38 | /////////////////////////////////////////////////////////////////////////////// |
| 39 | |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 40 | static void erase(SkBitmap& bm) { |
| 41 | if (bm.config() == SkBitmap::kA8_Config) { |
| 42 | bm.eraseColor(0); |
| 43 | } else { |
| 44 | bm.eraseColor(SK_ColorWHITE); |
| 45 | } |
| 46 | } |
| 47 | |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 48 | #if 0 |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 49 | static bool equal(const SkBitmap& bm1, const SkBitmap& bm2) { |
| 50 | if (bm1.width() != bm2.width() || |
| 51 | bm1.height() != bm2.height() || |
| 52 | bm1.config() != bm2.config()) { |
| 53 | return false; |
| 54 | } |
| 55 | |
| 56 | size_t pixelBytes = bm1.width() * bm1.bytesPerPixel(); |
| 57 | for (int y = 0; y < bm1.height(); y++) { |
| 58 | if (memcmp(bm1.getAddr(0, y), bm2.getAddr(0, y), pixelBytes)) { |
| 59 | return false; |
| 60 | } |
| 61 | } |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 62 | return true; |
| 63 | } |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 64 | #endif |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 65 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 66 | class Iter { |
| 67 | public: |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 68 | Iter(void* param) { |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 69 | fBench = BenchRegistry::Head(); |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 70 | fParam = param; |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | SkBenchmark* next() { |
| 74 | if (fBench) { |
| 75 | BenchRegistry::Factory f = fBench->factory(); |
| 76 | fBench = fBench->next(); |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 77 | return f(fParam); |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 78 | } |
| 79 | return NULL; |
| 80 | } |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 81 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 82 | private: |
| 83 | const BenchRegistry* fBench; |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 84 | void* fParam; |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | static void make_filename(const char name[], SkString* path) { |
| 88 | path->set(name); |
| 89 | for (int i = 0; name[i]; i++) { |
| 90 | switch (name[i]) { |
| 91 | case '/': |
| 92 | case '\\': |
| 93 | case ' ': |
| 94 | case ':': |
| 95 | path->writable_str()[i] = '-'; |
| 96 | break; |
| 97 | default: |
| 98 | break; |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 103 | static void saveFile(const char name[], const char config[], const char dir[], |
| 104 | const SkBitmap& bm) { |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 105 | SkBitmap copy; |
| 106 | if (!bm.copyTo(©, SkBitmap::kARGB_8888_Config)) { |
| 107 | return; |
| 108 | } |
reed@android.com | f523e25 | 2009-01-26 23:15:37 +0000 | [diff] [blame] | 109 | |
| 110 | if (bm.config() == SkBitmap::kA8_Config) { |
| 111 | // turn alpha into gray-scale |
| 112 | size_t size = copy.getSize() >> 2; |
| 113 | SkPMColor* p = copy.getAddr32(0, 0); |
| 114 | for (size_t i = 0; i < size; i++) { |
| 115 | int c = (*p >> SK_A32_SHIFT) & 0xFF; |
| 116 | c = 255 - c; |
| 117 | c |= (c << 24) | (c << 16) | (c << 8); |
| 118 | *p++ = c | (SK_A32_MASK << SK_A32_SHIFT); |
| 119 | } |
| 120 | } |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 121 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 122 | SkString str; |
| 123 | make_filename(name, &str); |
| 124 | str.appendf("_%s.png", config); |
| 125 | str.prepend(dir); |
| 126 | ::remove(str.c_str()); |
| 127 | SkImageEncoder::EncodeFile(str.c_str(), copy, SkImageEncoder::kPNG_Type, |
| 128 | 100); |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | static void performClip(SkCanvas* canvas, int w, int h) { |
| 132 | SkRect r; |
| 133 | |
| 134 | r.set(SkIntToScalar(10), SkIntToScalar(10), |
| 135 | SkIntToScalar(w*2/3), SkIntToScalar(h*2/3)); |
| 136 | canvas->clipRect(r, SkRegion::kIntersect_Op); |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 137 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 138 | r.set(SkIntToScalar(w/3), SkIntToScalar(h/3), |
| 139 | SkIntToScalar(w-10), SkIntToScalar(h-10)); |
| 140 | canvas->clipRect(r, SkRegion::kXOR_Op); |
| 141 | } |
| 142 | |
| 143 | static void performRotate(SkCanvas* canvas, int w, int h) { |
| 144 | const SkScalar x = SkIntToScalar(w) / 2; |
| 145 | const SkScalar y = SkIntToScalar(h) / 2; |
| 146 | |
| 147 | canvas->translate(x, y); |
| 148 | canvas->rotate(SkIntToScalar(35)); |
| 149 | canvas->translate(-x, -y); |
| 150 | } |
| 151 | |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 152 | static void performScale(SkCanvas* canvas, int w, int h) { |
| 153 | const SkScalar x = SkIntToScalar(w) / 2; |
| 154 | const SkScalar y = SkIntToScalar(h) / 2; |
| 155 | |
| 156 | canvas->translate(x, y); |
| 157 | // just enough so we can't take the sprite case |
| 158 | canvas->scale(SK_Scalar1 * 99/100, SK_Scalar1 * 99/100); |
| 159 | canvas->translate(-x, -y); |
| 160 | } |
| 161 | |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 162 | static bool parse_bool_arg(char * const* argv, char* const* stop, bool* var) { |
| 163 | if (argv < stop) { |
| 164 | *var = atoi(*argv) != 0; |
| 165 | return true; |
| 166 | } |
| 167 | return false; |
| 168 | } |
| 169 | |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 170 | enum Backend { |
| 171 | kRaster_Backend, |
| 172 | kGPU_Backend, |
| 173 | kPDF_Backend, |
| 174 | }; |
| 175 | |
| 176 | static SkDevice* make_device(SkBitmap::Config config, const SkIPoint& size, |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 177 | Backend backend, GrContext* context, |
| 178 | GrRenderTarget* rt) { |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 179 | SkDevice* device = NULL; |
| 180 | SkBitmap bitmap; |
| 181 | bitmap.setConfig(config, size.fX, size.fY); |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 182 | |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 183 | switch (backend) { |
| 184 | case kRaster_Backend: |
| 185 | bitmap.allocPixels(); |
| 186 | erase(bitmap); |
reed@google.com | af951c9 | 2011-06-16 19:10:39 +0000 | [diff] [blame] | 187 | device = new SkDevice(bitmap); |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 188 | break; |
| 189 | case kGPU_Backend: |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 190 | device = new SkGpuDevice(context, rt); |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 191 | // device->clear(0xFFFFFFFF); |
| 192 | break; |
| 193 | case kPDF_Backend: |
| 194 | default: |
| 195 | SkASSERT(!"unsupported"); |
| 196 | } |
| 197 | return device; |
| 198 | } |
| 199 | |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 200 | static const struct { |
| 201 | SkBitmap::Config fConfig; |
| 202 | const char* fName; |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 203 | Backend fBackend; |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 204 | } gConfigs[] = { |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 205 | { SkBitmap::kARGB_8888_Config, "8888", kRaster_Backend }, |
| 206 | { SkBitmap::kRGB_565_Config, "565", kRaster_Backend }, |
| 207 | { SkBitmap::kARGB_8888_Config, "GPU", kGPU_Backend }, |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 208 | }; |
| 209 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 210 | static int findConfig(const char config[]) { |
| 211 | for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); i++) { |
| 212 | if (!strcmp(config, gConfigs[i].fName)) { |
| 213 | return i; |
| 214 | } |
| 215 | } |
| 216 | return -1; |
| 217 | } |
| 218 | |
tomhudson@google.com | 8382394 | 2011-10-28 14:59:07 +0000 | [diff] [blame] | 219 | static void determine_gpu_context_size(SkTDict<const char*>& defineDict, |
| 220 | int* contextWidth, |
| 221 | int* contextHeight) { |
| 222 | Iter iter(&defineDict); |
| 223 | SkBenchmark* bench; |
| 224 | while ((bench = iter.next()) != NULL) { |
| 225 | SkIPoint dim = bench->getSize(); |
| 226 | if (*contextWidth < dim.fX) { |
| 227 | *contextWidth = dim.fX; |
| 228 | } |
| 229 | if (*contextHeight < dim.fY) { |
| 230 | *contextHeight = dim.fY; |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | |
reed@google.com | 1a7eabc | 2011-10-31 16:33:52 +0000 | [diff] [blame^] | 235 | static bool skip_name(const SkTDArray<const char*> array, const char name[]) { |
| 236 | if (0 == array.count()) { |
| 237 | // no names, so don't skip anything |
| 238 | return false; |
| 239 | } |
| 240 | for (int i = 0; i < array.count(); ++i) { |
| 241 | if (strstr(name, array[i])) { |
| 242 | // found the name, so don't skip |
| 243 | return false; |
| 244 | } |
| 245 | } |
| 246 | return true; |
| 247 | } |
| 248 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 249 | int main (int argc, char * const argv[]) { |
reed@android.com | 3a859a0 | 2009-01-28 00:56:29 +0000 | [diff] [blame] | 250 | SkAutoGraphics ag; |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 251 | |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 252 | SkTDict<const char*> defineDict(1024); |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 253 | int repeatDraw = 1; |
| 254 | int forceAlpha = 0xFF; |
| 255 | bool forceAA = true; |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 256 | bool forceFilter = false; |
reed@android.com | 4e635f9 | 2009-10-19 17:39:46 +0000 | [diff] [blame] | 257 | SkTriState::State forceDither = SkTriState::kDefault; |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 258 | bool timerWall = false; |
| 259 | bool timerCpu = true; |
| 260 | bool timerGpu = true; |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 261 | bool doScale = false; |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 262 | bool doRotate = false; |
| 263 | bool doClip = false; |
agl@chromium.org | 652807b | 2010-04-27 15:47:34 +0000 | [diff] [blame] | 264 | bool hasStrokeWidth = false; |
| 265 | float strokeWidth; |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 266 | bool useNullGL = false; |
reed@google.com | 1a7eabc | 2011-10-31 16:33:52 +0000 | [diff] [blame^] | 267 | SkTDArray<const char*> fMatches; |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 268 | |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 269 | SkString outDir; |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 270 | SkBitmap::Config outConfig = SkBitmap::kNo_Config; |
| 271 | const char* configName = ""; |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 272 | Backend backend = kRaster_Backend; // for warning |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 273 | int configCount = SK_ARRAY_COUNT(gConfigs); |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 274 | |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 275 | char* const* stop = argv + argc; |
| 276 | for (++argv; argv < stop; ++argv) { |
| 277 | if (strcmp(*argv, "-o") == 0) { |
| 278 | argv++; |
| 279 | if (argv < stop && **argv) { |
| 280 | outDir.set(*argv); |
| 281 | if (outDir.c_str()[outDir.size() - 1] != '/') { |
| 282 | outDir.append("/"); |
| 283 | } |
| 284 | } |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 285 | } else if (strcmp(*argv, "-repeat") == 0) { |
| 286 | argv++; |
| 287 | if (argv < stop) { |
| 288 | repeatDraw = atoi(*argv); |
| 289 | if (repeatDraw < 1) { |
| 290 | repeatDraw = 1; |
| 291 | } |
| 292 | } else { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 293 | log_error("missing arg for -repeat\n"); |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 294 | return -1; |
| 295 | } |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 296 | } else if (strcmp(*argv, "-timers") == 0) { |
| 297 | argv++; |
| 298 | if (argv < stop) { |
| 299 | timerWall = false; |
| 300 | timerCpu = false; |
| 301 | timerGpu = false; |
| 302 | for (char* t = *argv; *t; ++t) { |
| 303 | switch (*t) { |
| 304 | case 'w': timerWall = true; break; |
| 305 | case 'c': timerCpu = true; break; |
| 306 | case 'g': timerGpu = true; break; |
| 307 | } |
| 308 | } |
| 309 | } else { |
| 310 | log_error("missing arg for -timers\n"); |
| 311 | return -1; |
| 312 | } |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 313 | } else if (!strcmp(*argv, "-rotate")) { |
| 314 | doRotate = true; |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 315 | } else if (!strcmp(*argv, "-scale")) { |
| 316 | doScale = true; |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 317 | } else if (!strcmp(*argv, "-clip")) { |
| 318 | doClip = true; |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 319 | } else if (strcmp(*argv, "-forceAA") == 0) { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 320 | if (!parse_bool_arg(++argv, stop, &forceAA)) { |
| 321 | log_error("missing arg for -forceAA\n"); |
| 322 | return -1; |
| 323 | } |
| 324 | } else if (strcmp(*argv, "-forceFilter") == 0) { |
| 325 | if (!parse_bool_arg(++argv, stop, &forceFilter)) { |
| 326 | log_error("missing arg for -forceFilter\n"); |
| 327 | return -1; |
| 328 | } |
reed@android.com | 4e635f9 | 2009-10-19 17:39:46 +0000 | [diff] [blame] | 329 | } else if (strcmp(*argv, "-forceDither") == 0) { |
| 330 | bool tmp; |
| 331 | if (!parse_bool_arg(++argv, stop, &tmp)) { |
| 332 | log_error("missing arg for -forceDither\n"); |
| 333 | return -1; |
| 334 | } |
| 335 | forceDither = tmp ? SkTriState::kTrue : SkTriState::kFalse; |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 336 | } else if (strcmp(*argv, "-forceBlend") == 0) { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 337 | bool wantAlpha = false; |
| 338 | if (!parse_bool_arg(++argv, stop, &wantAlpha)) { |
| 339 | log_error("missing arg for -forceBlend\n"); |
| 340 | return -1; |
| 341 | } |
| 342 | forceAlpha = wantAlpha ? 0x80 : 0xFF; |
agl@chromium.org | 652807b | 2010-04-27 15:47:34 +0000 | [diff] [blame] | 343 | } else if (strcmp(*argv, "-strokeWidth") == 0) { |
| 344 | argv++; |
| 345 | if (argv < stop) { |
| 346 | const char *strokeWidthStr = *argv; |
| 347 | if (sscanf(strokeWidthStr, "%f", &strokeWidth) != 1) { |
| 348 | log_error("bad arg for -strokeWidth\n"); |
| 349 | return -1; |
| 350 | } |
| 351 | hasStrokeWidth = true; |
| 352 | } else { |
| 353 | log_error("missing arg for -strokeWidth\n"); |
| 354 | return -1; |
| 355 | } |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 356 | } else if (strcmp(*argv, "-match") == 0) { |
| 357 | argv++; |
| 358 | if (argv < stop) { |
reed@google.com | 1a7eabc | 2011-10-31 16:33:52 +0000 | [diff] [blame^] | 359 | *fMatches.append() = *argv; |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 360 | } else { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 361 | log_error("missing arg for -match\n"); |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 362 | return -1; |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 363 | } |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 364 | } else if (strcmp(*argv, "-config") == 0) { |
| 365 | argv++; |
| 366 | if (argv < stop) { |
| 367 | int index = findConfig(*argv); |
| 368 | if (index >= 0) { |
| 369 | outConfig = gConfigs[index].fConfig; |
| 370 | configName = gConfigs[index].fName; |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 371 | backend = gConfigs[index].fBackend; |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 372 | configCount = 1; |
| 373 | } else { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 374 | SkString str; |
| 375 | str.printf("unrecognized config %s\n", *argv); |
| 376 | log_error(str); |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 377 | return -1; |
| 378 | } |
| 379 | } else { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 380 | log_error("missing arg for -config\n"); |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 381 | return -1; |
| 382 | } |
reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 383 | } else if (strlen(*argv) > 2 && strncmp(*argv, "-D", 2) == 0) { |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 384 | argv++; |
reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 385 | if (argv < stop) { |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 386 | defineDict.set(argv[-1] + 2, *argv); |
| 387 | } else { |
| 388 | log_error("incomplete '-Dfoo bar' definition\n"); |
| 389 | return -1; |
| 390 | } |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 391 | } else if (strcmp(*argv, "-nullgl") == 0) { |
| 392 | useNullGL = true; |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 393 | } else { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 394 | SkString str; |
| 395 | str.printf("unrecognized arg %s\n", *argv); |
| 396 | log_error(str); |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 397 | return -1; |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 398 | } |
| 399 | } |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 400 | |
reed@google.com | 3b14dc1 | 2011-04-04 14:31:36 +0000 | [diff] [blame] | 401 | // report our current settings |
| 402 | { |
| 403 | SkString str; |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 404 | str.printf("skia bench: alpha=0x%02X antialias=%d filter=%d", |
reed@google.com | 3b14dc1 | 2011-04-04 14:31:36 +0000 | [diff] [blame] | 405 | forceAlpha, forceAA, forceFilter); |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 406 | str.appendf(" rotate=%d scale=%d clip=%d", |
| 407 | doRotate, doScale, doClip); |
| 408 | |
| 409 | const char * ditherName; |
| 410 | switch (forceDither) { |
| 411 | case SkTriState::kDefault: ditherName = "default"; break; |
| 412 | case SkTriState::kTrue: ditherName = "true"; break; |
| 413 | case SkTriState::kFalse: ditherName = "false"; break; |
| 414 | default: ditherName = "<invalid>"; break; |
| 415 | } |
| 416 | str.appendf(" dither=%s", ditherName); |
| 417 | |
| 418 | if (hasStrokeWidth) { |
| 419 | str.appendf(" strokeWidth=%f", strokeWidth); |
| 420 | } else { |
| 421 | str.append(" strokeWidth=none"); |
| 422 | } |
| 423 | |
| 424 | #if defined(SK_SCALAR_IS_FLOAT) |
| 425 | str.append(" scalar=float"); |
| 426 | #elif defined(SK_SCALAR_IS_FIXED) |
| 427 | str.append(" scalar=fixed"); |
| 428 | #endif |
| 429 | |
| 430 | #if defined(SK_BUILD_FOR_WIN32) |
| 431 | str.append(" system=WIN32"); |
| 432 | #elif defined(SK_BUILD_FOR_MAC) |
| 433 | str.append(" system=MAC"); |
| 434 | #elif defined(SK_BUILD_FOR_ANDROID) |
| 435 | str.append(" system=ANDROID"); |
| 436 | #elif defined(SK_BUILD_FOR_UNIX) |
| 437 | str.append(" system=UNIX"); |
| 438 | #else |
| 439 | str.append(" system=other"); |
| 440 | #endif |
| 441 | |
| 442 | #if defined(SK_DEBUG) |
| 443 | str.append(" DEBUG"); |
| 444 | #endif |
| 445 | str.append("\n"); |
reed@google.com | 3b14dc1 | 2011-04-04 14:31:36 +0000 | [diff] [blame] | 446 | log_progress(str); |
| 447 | } |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 448 | |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 449 | GrContext* context = NULL; |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 450 | GrRenderTarget* rt = NULL; |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 451 | //Don't do GL when fixed. |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 452 | SkAutoTUnref<SkGLContext> glctx; |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 453 | #if !defined(SK_SCALAR_IS_FIXED) |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 454 | if (useNullGL) { |
| 455 | glctx.reset(new SkNullGLContext); |
| 456 | } else { |
| 457 | glctx.reset(new SkNativeGLContext); |
| 458 | } |
tomhudson@google.com | 8382394 | 2011-10-28 14:59:07 +0000 | [diff] [blame] | 459 | int contextWidth = 1024; |
| 460 | int contextHeight = 1024; |
| 461 | determine_gpu_context_size(defineDict, &contextWidth, &contextHeight); |
| 462 | if (glctx.get()->init(contextWidth, contextHeight)) { |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 463 | GrPlatform3DContext ctx = |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 464 | reinterpret_cast<GrPlatform3DContext>(glctx.get()->gl()); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 465 | context = GrContext::Create(kOpenGL_Shaders_GrEngine, ctx); |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 466 | if (NULL != context) { |
| 467 | GrPlatformSurfaceDesc desc; |
| 468 | desc.reset(); |
| 469 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
tomhudson@google.com | 8382394 | 2011-10-28 14:59:07 +0000 | [diff] [blame] | 470 | desc.fWidth = contextWidth; |
| 471 | desc.fHeight = contextHeight; |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 472 | desc.fStencilBits = 8; |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 473 | desc.fPlatformRenderTarget = glctx.get()->getFBOID(); |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 474 | desc.fSurfaceType = kRenderTarget_GrPlatformSurfaceType; |
| 475 | rt = static_cast<GrRenderTarget*>(context->createPlatformSurface(desc)); |
| 476 | if (NULL == rt) { |
| 477 | context->unref(); |
| 478 | context = NULL; |
| 479 | } |
| 480 | } |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 481 | } |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 482 | #endif |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 483 | BenchTimer timer = BenchTimer(context ? glctx.get() : NULL); |
| 484 | |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 485 | Iter iter(&defineDict); |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 486 | SkBenchmark* bench; |
| 487 | while ((bench = iter.next()) != NULL) { |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 488 | SkIPoint dim = bench->getSize(); |
| 489 | if (dim.fX <= 0 || dim.fY <= 0) { |
| 490 | continue; |
| 491 | } |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 492 | |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 493 | bench->setForceAlpha(forceAlpha); |
| 494 | bench->setForceAA(forceAA); |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 495 | bench->setForceFilter(forceFilter); |
reed@android.com | 4e635f9 | 2009-10-19 17:39:46 +0000 | [diff] [blame] | 496 | bench->setDither(forceDither); |
agl@chromium.org | 652807b | 2010-04-27 15:47:34 +0000 | [diff] [blame] | 497 | if (hasStrokeWidth) { |
| 498 | bench->setStrokeWidth(strokeWidth); |
| 499 | } |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 500 | |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 501 | // only run benchmarks if their name contains matchStr |
reed@google.com | 1a7eabc | 2011-10-31 16:33:52 +0000 | [diff] [blame^] | 502 | if (skip_name(fMatches, bench->getName())) { |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 503 | continue; |
| 504 | } |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 505 | |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 506 | { |
| 507 | SkString str; |
reed@google.com | d34658a | 2011-04-11 13:12:51 +0000 | [diff] [blame] | 508 | str.printf("running bench [%d %d] %28s", dim.fX, dim.fY, |
reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 509 | bench->getName()); |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 510 | log_progress(str); |
| 511 | } |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 512 | |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 513 | for (int configIndex = 0; configIndex < configCount; configIndex++) { |
| 514 | if (configCount > 1) { |
| 515 | outConfig = gConfigs[configIndex].fConfig; |
| 516 | configName = gConfigs[configIndex].fName; |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 517 | backend = gConfigs[configIndex].fBackend; |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 518 | } |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 519 | |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 520 | if (kGPU_Backend == backend && NULL == context) { |
| 521 | continue; |
| 522 | } |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 523 | |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 524 | SkDevice* device = make_device(outConfig, dim, |
| 525 | backend, context, rt); |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 526 | SkCanvas canvas(device); |
| 527 | device->unref(); |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 528 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 529 | if (doClip) { |
| 530 | performClip(&canvas, dim.fX, dim.fY); |
| 531 | } |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 532 | if (doScale) { |
| 533 | performScale(&canvas, dim.fX, dim.fY); |
| 534 | } |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 535 | if (doRotate) { |
| 536 | performRotate(&canvas, dim.fX, dim.fY); |
| 537 | } |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 538 | |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 539 | bool gpu = kGPU_Backend == backend && context; |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 540 | //warm up caches if needed |
reed@android.com | eca4836 | 2010-12-20 18:34:17 +0000 | [diff] [blame] | 541 | if (repeatDraw > 1) { |
| 542 | SkAutoCanvasRestore acr(&canvas, true); |
| 543 | bench->draw(&canvas); |
bsalomon@google.com | 788e247 | 2011-10-19 20:56:30 +0000 | [diff] [blame] | 544 | #if !defined(SK_SCALAR_IS_FIXED) |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 545 | if (gpu) { |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 546 | context->flush(); |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 547 | SK_GL(*glctx.get(), Finish()); |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 548 | } |
bsalomon@google.com | 788e247 | 2011-10-19 20:56:30 +0000 | [diff] [blame] | 549 | #endif |
reed@android.com | eca4836 | 2010-12-20 18:34:17 +0000 | [diff] [blame] | 550 | } |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 551 | |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 552 | timer.start(); |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 553 | for (int i = 0; i < repeatDraw; i++) { |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 554 | SkAutoCanvasRestore acr(&canvas, true); |
| 555 | bench->draw(&canvas); |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 556 | if (gpu) { |
| 557 | context->flush(); |
| 558 | } |
| 559 | } |
bsalomon@google.com | 788e247 | 2011-10-19 20:56:30 +0000 | [diff] [blame] | 560 | #if !defined(SK_SCALAR_IS_FIXED) |
| 561 | if (gpu) { |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 562 | SK_GL(*glctx.get(), Finish()); |
bsalomon@google.com | 788e247 | 2011-10-19 20:56:30 +0000 | [diff] [blame] | 563 | } |
| 564 | #endif |
| 565 | timer.end(); |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 566 | |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 567 | if (repeatDraw > 1) { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 568 | SkString str; |
bungeman@google.com | be9ad4e | 2011-06-07 19:16:02 +0000 | [diff] [blame] | 569 | str.printf(" %4s:", configName); |
| 570 | if (timerWall) { |
| 571 | str.appendf(" msecs = %6.2f", timer.fWall / repeatDraw); |
| 572 | } |
| 573 | if (timerCpu) { |
| 574 | str.appendf(" cmsecs = %6.2f", timer.fCpu / repeatDraw); |
| 575 | } |
| 576 | if (timerGpu && gpu && timer.fGpu > 0) { |
| 577 | str.appendf(" gmsecs = %6.2f", timer.fGpu / repeatDraw); |
| 578 | } |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 579 | log_progress(str); |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 580 | } |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 581 | if (outDir.size() > 0) { |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 582 | saveFile(bench->getName(), configName, outDir.c_str(), |
| 583 | device->accessBitmap(false)); |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 584 | } |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 585 | } |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 586 | log_progress("\n"); |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 587 | } |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 588 | |
| 589 | SkSafeUnref(context); |
| 590 | SkSafeUnref(rt); |
| 591 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 592 | return 0; |
| 593 | } |