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