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" |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 8 | #include "SkTime.h" |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 9 | |
| 10 | #include "SkBenchmark.h" |
| 11 | |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 12 | #ifdef ANDROID |
| 13 | static void log_error(const char msg[]) { SkDebugf("%s", msg); } |
| 14 | static void log_progress(const char msg[]) { SkDebugf("%s", msg); } |
| 15 | #else |
| 16 | static void log_error(const char msg[]) { fprintf(stderr, "%s", msg); } |
| 17 | static void log_progress(const char msg[]) { printf("%s", msg); } |
| 18 | #endif |
| 19 | |
| 20 | static void log_error(const SkString& str) { log_error(str.c_str()); } |
| 21 | static void log_progress(const SkString& str) { log_progress(str.c_str()); } |
| 22 | |
| 23 | /////////////////////////////////////////////////////////////////////////////// |
| 24 | |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 25 | static void erase(SkBitmap& bm) { |
| 26 | if (bm.config() == SkBitmap::kA8_Config) { |
| 27 | bm.eraseColor(0); |
| 28 | } else { |
| 29 | bm.eraseColor(SK_ColorWHITE); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | static bool equal(const SkBitmap& bm1, const SkBitmap& bm2) { |
| 34 | if (bm1.width() != bm2.width() || |
| 35 | bm1.height() != bm2.height() || |
| 36 | bm1.config() != bm2.config()) { |
| 37 | return false; |
| 38 | } |
| 39 | |
| 40 | size_t pixelBytes = bm1.width() * bm1.bytesPerPixel(); |
| 41 | for (int y = 0; y < bm1.height(); y++) { |
| 42 | if (memcmp(bm1.getAddr(0, y), bm2.getAddr(0, y), pixelBytes)) { |
| 43 | return false; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | return true; |
| 48 | } |
| 49 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 50 | class Iter { |
| 51 | public: |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 52 | Iter(void* param) { |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 53 | fBench = BenchRegistry::Head(); |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 54 | fParam = param; |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | SkBenchmark* next() { |
| 58 | if (fBench) { |
| 59 | BenchRegistry::Factory f = fBench->factory(); |
| 60 | fBench = fBench->next(); |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 61 | return f(fParam); |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 62 | } |
| 63 | return NULL; |
| 64 | } |
| 65 | |
| 66 | private: |
| 67 | const BenchRegistry* fBench; |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 68 | void* fParam; |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | static void make_filename(const char name[], SkString* path) { |
| 72 | path->set(name); |
| 73 | for (int i = 0; name[i]; i++) { |
| 74 | switch (name[i]) { |
| 75 | case '/': |
| 76 | case '\\': |
| 77 | case ' ': |
| 78 | case ':': |
| 79 | path->writable_str()[i] = '-'; |
| 80 | break; |
| 81 | default: |
| 82 | break; |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 87 | static void saveFile(const char name[], const char config[], const char dir[], |
| 88 | const SkBitmap& bm) { |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 89 | SkBitmap copy; |
| 90 | if (!bm.copyTo(©, SkBitmap::kARGB_8888_Config)) { |
| 91 | return; |
| 92 | } |
reed@android.com | f523e25 | 2009-01-26 23:15:37 +0000 | [diff] [blame] | 93 | |
| 94 | if (bm.config() == SkBitmap::kA8_Config) { |
| 95 | // turn alpha into gray-scale |
| 96 | size_t size = copy.getSize() >> 2; |
| 97 | SkPMColor* p = copy.getAddr32(0, 0); |
| 98 | for (size_t i = 0; i < size; i++) { |
| 99 | int c = (*p >> SK_A32_SHIFT) & 0xFF; |
| 100 | c = 255 - c; |
| 101 | c |= (c << 24) | (c << 16) | (c << 8); |
| 102 | *p++ = c | (SK_A32_MASK << SK_A32_SHIFT); |
| 103 | } |
| 104 | } |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 105 | |
| 106 | SkString str; |
| 107 | make_filename(name, &str); |
| 108 | str.appendf("_%s.png", config); |
| 109 | str.prepend(dir); |
| 110 | ::remove(str.c_str()); |
| 111 | SkImageEncoder::EncodeFile(str.c_str(), copy, SkImageEncoder::kPNG_Type, |
| 112 | 100); |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | static void performClip(SkCanvas* canvas, int w, int h) { |
| 116 | SkRect r; |
| 117 | |
| 118 | r.set(SkIntToScalar(10), SkIntToScalar(10), |
| 119 | SkIntToScalar(w*2/3), SkIntToScalar(h*2/3)); |
| 120 | canvas->clipRect(r, SkRegion::kIntersect_Op); |
| 121 | |
| 122 | r.set(SkIntToScalar(w/3), SkIntToScalar(h/3), |
| 123 | SkIntToScalar(w-10), SkIntToScalar(h-10)); |
| 124 | canvas->clipRect(r, SkRegion::kXOR_Op); |
| 125 | } |
| 126 | |
| 127 | static void performRotate(SkCanvas* canvas, int w, int h) { |
| 128 | const SkScalar x = SkIntToScalar(w) / 2; |
| 129 | const SkScalar y = SkIntToScalar(h) / 2; |
| 130 | |
| 131 | canvas->translate(x, y); |
| 132 | canvas->rotate(SkIntToScalar(35)); |
| 133 | canvas->translate(-x, -y); |
| 134 | } |
| 135 | |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 136 | static void performScale(SkCanvas* canvas, int w, int h) { |
| 137 | const SkScalar x = SkIntToScalar(w) / 2; |
| 138 | const SkScalar y = SkIntToScalar(h) / 2; |
| 139 | |
| 140 | canvas->translate(x, y); |
| 141 | // just enough so we can't take the sprite case |
| 142 | canvas->scale(SK_Scalar1 * 99/100, SK_Scalar1 * 99/100); |
| 143 | canvas->translate(-x, -y); |
| 144 | } |
| 145 | |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 146 | static void compare_pict_to_bitmap(SkPicture* pict, const SkBitmap& bm) { |
| 147 | SkBitmap bm2; |
| 148 | |
| 149 | bm2.setConfig(bm.config(), bm.width(), bm.height()); |
| 150 | bm2.allocPixels(); |
| 151 | erase(bm2); |
| 152 | |
| 153 | SkCanvas canvas(bm2); |
| 154 | canvas.drawPicture(*pict); |
| 155 | |
| 156 | if (!equal(bm, bm2)) { |
| 157 | SkDebugf("----- compare_pict_to_bitmap failed\n"); |
| 158 | } |
| 159 | } |
| 160 | |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 161 | static bool parse_bool_arg(char * const* argv, char* const* stop, bool* var) { |
| 162 | if (argv < stop) { |
| 163 | *var = atoi(*argv) != 0; |
| 164 | return true; |
| 165 | } |
| 166 | return false; |
| 167 | } |
| 168 | |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 169 | static const struct { |
| 170 | SkBitmap::Config fConfig; |
| 171 | const char* fName; |
| 172 | } gConfigs[] = { |
| 173 | { SkBitmap::kARGB_8888_Config, "8888" }, |
| 174 | { SkBitmap::kRGB_565_Config, "565", }, |
reed@android.com | 831f6c6 | 2010-02-22 22:03:06 +0000 | [diff] [blame] | 175 | #if 0 |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 176 | { SkBitmap::kARGB_4444_Config, "4444", }, |
| 177 | { SkBitmap::kA8_Config, "A8", } |
reed@android.com | 831f6c6 | 2010-02-22 22:03:06 +0000 | [diff] [blame] | 178 | #endif |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 179 | }; |
| 180 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 181 | static int findConfig(const char config[]) { |
| 182 | for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); i++) { |
| 183 | if (!strcmp(config, gConfigs[i].fName)) { |
| 184 | return i; |
| 185 | } |
| 186 | } |
| 187 | return -1; |
| 188 | } |
| 189 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 190 | int main (int argc, char * const argv[]) { |
reed@android.com | 3a859a0 | 2009-01-28 00:56:29 +0000 | [diff] [blame] | 191 | SkAutoGraphics ag; |
| 192 | |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 193 | SkTDict<const char*> defineDict(1024); |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 194 | int repeatDraw = 1; |
| 195 | int forceAlpha = 0xFF; |
| 196 | bool forceAA = true; |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 197 | bool forceFilter = false; |
reed@android.com | 4e635f9 | 2009-10-19 17:39:46 +0000 | [diff] [blame] | 198 | SkTriState::State forceDither = SkTriState::kDefault; |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 199 | bool doScale = false; |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 200 | bool doRotate = false; |
| 201 | bool doClip = false; |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 202 | bool doPict = false; |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 203 | const char* matchStr = NULL; |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 204 | |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 205 | SkString outDir; |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 206 | SkBitmap::Config outConfig = SkBitmap::kNo_Config; |
| 207 | const char* configName = ""; |
| 208 | int configCount = SK_ARRAY_COUNT(gConfigs); |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 209 | |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 210 | char* const* stop = argv + argc; |
| 211 | for (++argv; argv < stop; ++argv) { |
| 212 | if (strcmp(*argv, "-o") == 0) { |
| 213 | argv++; |
| 214 | if (argv < stop && **argv) { |
| 215 | outDir.set(*argv); |
| 216 | if (outDir.c_str()[outDir.size() - 1] != '/') { |
| 217 | outDir.append("/"); |
| 218 | } |
| 219 | } |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 220 | } else if (strcmp(*argv, "-pict") == 0) { |
| 221 | doPict = true; |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 222 | } else if (strcmp(*argv, "-repeat") == 0) { |
| 223 | argv++; |
| 224 | if (argv < stop) { |
| 225 | repeatDraw = atoi(*argv); |
| 226 | if (repeatDraw < 1) { |
| 227 | repeatDraw = 1; |
| 228 | } |
| 229 | } else { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 230 | log_error("missing arg for -repeat\n"); |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 231 | return -1; |
| 232 | } |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 233 | } else if (!strcmp(*argv, "-rotate")) { |
| 234 | doRotate = true; |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 235 | } else if (!strcmp(*argv, "-scale")) { |
| 236 | doScale = true; |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 237 | } else if (!strcmp(*argv, "-clip")) { |
| 238 | doClip = true; |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 239 | } else if (strcmp(*argv, "-forceAA") == 0) { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 240 | if (!parse_bool_arg(++argv, stop, &forceAA)) { |
| 241 | log_error("missing arg for -forceAA\n"); |
| 242 | return -1; |
| 243 | } |
| 244 | } else if (strcmp(*argv, "-forceFilter") == 0) { |
| 245 | if (!parse_bool_arg(++argv, stop, &forceFilter)) { |
| 246 | log_error("missing arg for -forceFilter\n"); |
| 247 | return -1; |
| 248 | } |
reed@android.com | 4e635f9 | 2009-10-19 17:39:46 +0000 | [diff] [blame] | 249 | } else if (strcmp(*argv, "-forceDither") == 0) { |
| 250 | bool tmp; |
| 251 | if (!parse_bool_arg(++argv, stop, &tmp)) { |
| 252 | log_error("missing arg for -forceDither\n"); |
| 253 | return -1; |
| 254 | } |
| 255 | forceDither = tmp ? SkTriState::kTrue : SkTriState::kFalse; |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 256 | } else if (strcmp(*argv, "-forceBlend") == 0) { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 257 | bool wantAlpha = false; |
| 258 | if (!parse_bool_arg(++argv, stop, &wantAlpha)) { |
| 259 | log_error("missing arg for -forceBlend\n"); |
| 260 | return -1; |
| 261 | } |
| 262 | forceAlpha = wantAlpha ? 0x80 : 0xFF; |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 263 | } else if (strcmp(*argv, "-match") == 0) { |
| 264 | argv++; |
| 265 | if (argv < stop) { |
| 266 | matchStr = *argv; |
| 267 | } else { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 268 | log_error("missing arg for -match\n"); |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 269 | return -1; |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 270 | } |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 271 | } else if (strcmp(*argv, "-config") == 0) { |
| 272 | argv++; |
| 273 | if (argv < stop) { |
| 274 | int index = findConfig(*argv); |
| 275 | if (index >= 0) { |
| 276 | outConfig = gConfigs[index].fConfig; |
| 277 | configName = gConfigs[index].fName; |
| 278 | configCount = 1; |
| 279 | } else { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 280 | SkString str; |
| 281 | str.printf("unrecognized config %s\n", *argv); |
| 282 | log_error(str); |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 283 | return -1; |
| 284 | } |
| 285 | } else { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 286 | log_error("missing arg for -config\n"); |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 287 | return -1; |
| 288 | } |
reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 289 | } else if (strlen(*argv) > 2 && strncmp(*argv, "-D", 2) == 0) { |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 290 | argv++; |
reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 291 | if (argv < stop) { |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 292 | defineDict.set(argv[-1] + 2, *argv); |
| 293 | } else { |
| 294 | log_error("incomplete '-Dfoo bar' definition\n"); |
| 295 | return -1; |
| 296 | } |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 297 | } else { |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 298 | SkString str; |
| 299 | str.printf("unrecognized arg %s\n", *argv); |
| 300 | log_error(str); |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 301 | return -1; |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 302 | } |
| 303 | } |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 304 | |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 305 | Iter iter(&defineDict); |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 306 | SkBenchmark* bench; |
| 307 | while ((bench = iter.next()) != NULL) { |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 308 | SkIPoint dim = bench->getSize(); |
| 309 | if (dim.fX <= 0 || dim.fY <= 0) { |
| 310 | continue; |
| 311 | } |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 312 | |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 313 | bench->setForceAlpha(forceAlpha); |
| 314 | bench->setForceAA(forceAA); |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 315 | bench->setForceFilter(forceFilter); |
reed@android.com | 4e635f9 | 2009-10-19 17:39:46 +0000 | [diff] [blame] | 316 | bench->setDither(forceDither); |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 317 | |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 318 | // only run benchmarks if their name contains matchStr |
| 319 | if (matchStr && strstr(bench->getName(), matchStr) == NULL) { |
| 320 | continue; |
| 321 | } |
| 322 | |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 323 | { |
| 324 | SkString str; |
reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 325 | str.printf("running bench [%d %d] %16s", dim.fX, dim.fY, |
| 326 | bench->getName()); |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 327 | log_progress(str); |
| 328 | } |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 329 | |
| 330 | for (int configIndex = 0; configIndex < configCount; configIndex++) { |
| 331 | if (configCount > 1) { |
| 332 | outConfig = gConfigs[configIndex].fConfig; |
| 333 | configName = gConfigs[configIndex].fName; |
| 334 | } |
| 335 | |
| 336 | SkBitmap bm; |
| 337 | bm.setConfig(outConfig, dim.fX, dim.fY); |
| 338 | bm.allocPixels(); |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 339 | erase(bm); |
reed@android.com | f523e25 | 2009-01-26 23:15:37 +0000 | [diff] [blame] | 340 | |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 341 | SkCanvas canvas(bm); |
reed@android.com | f523e25 | 2009-01-26 23:15:37 +0000 | [diff] [blame] | 342 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 343 | if (doClip) { |
| 344 | performClip(&canvas, dim.fX, dim.fY); |
| 345 | } |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 346 | if (doScale) { |
| 347 | performScale(&canvas, dim.fX, dim.fY); |
| 348 | } |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 349 | if (doRotate) { |
| 350 | performRotate(&canvas, dim.fX, dim.fY); |
| 351 | } |
| 352 | |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 353 | SkMSec now = SkTime::GetMSecs(); |
| 354 | for (int i = 0; i < repeatDraw; i++) { |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 355 | SkCanvas* c = &canvas; |
| 356 | |
| 357 | SkNWayCanvas nway; |
| 358 | SkPicture* pict = NULL; |
| 359 | if (doPict) { |
| 360 | pict = new SkPicture; |
| 361 | nway.addCanvas(pict->beginRecording(bm.width(), bm.height())); |
| 362 | nway.addCanvas(&canvas); |
| 363 | c = &nway; |
| 364 | } |
| 365 | |
| 366 | SkAutoCanvasRestore acr(c, true); |
| 367 | bench->draw(c); |
| 368 | |
| 369 | if (pict) { |
| 370 | compare_pict_to_bitmap(pict, bm); |
| 371 | pict->unref(); |
| 372 | } |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 373 | } |
| 374 | if (repeatDraw > 1) { |
reed@android.com | 831f6c6 | 2010-02-22 22:03:06 +0000 | [diff] [blame] | 375 | double duration = SkTime::GetMSecs() - now; |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 376 | SkString str; |
reed@android.com | 831f6c6 | 2010-02-22 22:03:06 +0000 | [diff] [blame] | 377 | str.printf(" %4s: msecs = %7.2f, fps = %7.2f", configName, |
| 378 | duration / repeatDraw, repeatDraw * 1000.0 / duration); |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 379 | log_progress(str); |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 380 | } |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 381 | if (outDir.size() > 0) { |
| 382 | saveFile(bench->getName(), configName, outDir.c_str(), bm); |
| 383 | } |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 384 | } |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 385 | log_progress("\n"); |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | return 0; |
| 389 | } |