blob: 32aace36976f99a948259d0fd0a02a9bad1dc7dd [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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.com971d0c82011-08-19 17:22:05 +00008
9
10#include "BenchTimer.h"
11
12#include "GrContext.h"
13#include "GrRenderTarget.h"
14
15#include "SkBenchmark.h"
reed@android.combd700c32009-01-05 03:34:50 +000016#include "SkCanvas.h"
reed@android.comf523e252009-01-26 23:15:37 +000017#include "SkColorPriv.h"
bsalomon@google.com971d0c82011-08-19 17:22:05 +000018#include "SkGpuDevice.h"
reed@android.com3a859a02009-01-28 00:56:29 +000019#include "SkGraphics.h"
reed@android.comb398fe82009-01-07 11:47:57 +000020#include "SkImageEncoder.h"
tomhudson@google.com6bf38b52012-02-14 15:11:59 +000021#include "gl/SkNativeGLContext.h"
22#include "gl/SkNullGLContext.h"
robertphillips@google.com0da37192012-03-19 14:42:13 +000023#include "gl/SkDebugGLContext.h"
reed@android.com6c924ad2009-03-31 03:48:49 +000024#include "SkNWayCanvas.h"
25#include "SkPicture.h"
reed@android.combd700c32009-01-05 03:34:50 +000026#include "SkString.h"
reed@android.combd700c32009-01-05 03:34:50 +000027
djsollen@google.com56c69772011-11-08 19:00:26 +000028#ifdef SK_BUILD_FOR_ANDROID
reed@android.com29348cb2009-08-04 18:17:15 +000029static void log_error(const char msg[]) { SkDebugf("%s", msg); }
30static void log_progress(const char msg[]) { SkDebugf("%s", msg); }
31#else
32static void log_error(const char msg[]) { fprintf(stderr, "%s", msg); }
33static void log_progress(const char msg[]) { printf("%s", msg); }
34#endif
35
36static void log_error(const SkString& str) { log_error(str.c_str()); }
37static void log_progress(const SkString& str) { log_progress(str.c_str()); }
38
39///////////////////////////////////////////////////////////////////////////////
40
reed@android.com6c924ad2009-03-31 03:48:49 +000041static void erase(SkBitmap& bm) {
42 if (bm.config() == SkBitmap::kA8_Config) {
43 bm.eraseColor(0);
44 } else {
45 bm.eraseColor(SK_ColorWHITE);
46 }
47}
48
mike@reedtribe.orga9015f82011-05-17 02:25:05 +000049#if 0
reed@android.com6c924ad2009-03-31 03:48:49 +000050static bool equal(const SkBitmap& bm1, const SkBitmap& bm2) {
51 if (bm1.width() != bm2.width() ||
52 bm1.height() != bm2.height() ||
53 bm1.config() != bm2.config()) {
54 return false;
55 }
56
57 size_t pixelBytes = bm1.width() * bm1.bytesPerPixel();
58 for (int y = 0; y < bm1.height(); y++) {
59 if (memcmp(bm1.getAddr(0, y), bm2.getAddr(0, y), pixelBytes)) {
60 return false;
61 }
62 }
reed@android.com6c924ad2009-03-31 03:48:49 +000063 return true;
64}
mike@reedtribe.orga9015f82011-05-17 02:25:05 +000065#endif
reed@android.com6c924ad2009-03-31 03:48:49 +000066
reed@android.combd700c32009-01-05 03:34:50 +000067class Iter {
68public:
reed@android.come9d00602009-09-02 21:12:42 +000069 Iter(void* param) {
reed@android.combd700c32009-01-05 03:34:50 +000070 fBench = BenchRegistry::Head();
reed@android.come9d00602009-09-02 21:12:42 +000071 fParam = param;
reed@android.combd700c32009-01-05 03:34:50 +000072 }
73
74 SkBenchmark* next() {
75 if (fBench) {
76 BenchRegistry::Factory f = fBench->factory();
77 fBench = fBench->next();
reed@android.come9d00602009-09-02 21:12:42 +000078 return f(fParam);
reed@android.combd700c32009-01-05 03:34:50 +000079 }
80 return NULL;
81 }
bungeman@google.comd1a416a2011-05-18 18:37:07 +000082
reed@android.combd700c32009-01-05 03:34:50 +000083private:
84 const BenchRegistry* fBench;
reed@android.come9d00602009-09-02 21:12:42 +000085 void* fParam;
reed@android.combd700c32009-01-05 03:34:50 +000086};
87
88static void make_filename(const char name[], SkString* path) {
89 path->set(name);
90 for (int i = 0; name[i]; i++) {
91 switch (name[i]) {
92 case '/':
93 case '\\':
94 case ' ':
95 case ':':
96 path->writable_str()[i] = '-';
97 break;
98 default:
99 break;
100 }
101 }
102}
103
reed@android.com4c7d3d62009-01-21 03:15:13 +0000104static void saveFile(const char name[], const char config[], const char dir[],
105 const SkBitmap& bm) {
reed@android.com4c7d3d62009-01-21 03:15:13 +0000106 SkBitmap copy;
107 if (!bm.copyTo(&copy, SkBitmap::kARGB_8888_Config)) {
108 return;
109 }
reed@android.comf523e252009-01-26 23:15:37 +0000110
111 if (bm.config() == SkBitmap::kA8_Config) {
112 // turn alpha into gray-scale
113 size_t size = copy.getSize() >> 2;
114 SkPMColor* p = copy.getAddr32(0, 0);
115 for (size_t i = 0; i < size; i++) {
116 int c = (*p >> SK_A32_SHIFT) & 0xFF;
117 c = 255 - c;
118 c |= (c << 24) | (c << 16) | (c << 8);
119 *p++ = c | (SK_A32_MASK << SK_A32_SHIFT);
120 }
121 }
bungeman@google.comd1a416a2011-05-18 18:37:07 +0000122
reed@android.com4c7d3d62009-01-21 03:15:13 +0000123 SkString str;
124 make_filename(name, &str);
125 str.appendf("_%s.png", config);
126 str.prepend(dir);
127 ::remove(str.c_str());
128 SkImageEncoder::EncodeFile(str.c_str(), copy, SkImageEncoder::kPNG_Type,
129 100);
reed@android.com4c7d3d62009-01-21 03:15:13 +0000130}
131
132static void performClip(SkCanvas* canvas, int w, int h) {
133 SkRect r;
134
135 r.set(SkIntToScalar(10), SkIntToScalar(10),
136 SkIntToScalar(w*2/3), SkIntToScalar(h*2/3));
137 canvas->clipRect(r, SkRegion::kIntersect_Op);
bungeman@google.comd1a416a2011-05-18 18:37:07 +0000138
reed@android.com4c7d3d62009-01-21 03:15:13 +0000139 r.set(SkIntToScalar(w/3), SkIntToScalar(h/3),
140 SkIntToScalar(w-10), SkIntToScalar(h-10));
141 canvas->clipRect(r, SkRegion::kXOR_Op);
142}
143
144static void performRotate(SkCanvas* canvas, int w, int h) {
145 const SkScalar x = SkIntToScalar(w) / 2;
146 const SkScalar y = SkIntToScalar(h) / 2;
147
148 canvas->translate(x, y);
149 canvas->rotate(SkIntToScalar(35));
150 canvas->translate(-x, -y);
151}
152
reed@android.com387359e2009-08-04 01:51:09 +0000153static void performScale(SkCanvas* canvas, int w, int h) {
154 const SkScalar x = SkIntToScalar(w) / 2;
155 const SkScalar y = SkIntToScalar(h) / 2;
156
157 canvas->translate(x, y);
158 // just enough so we can't take the sprite case
159 canvas->scale(SK_Scalar1 * 99/100, SK_Scalar1 * 99/100);
160 canvas->translate(-x, -y);
161}
162
reed@android.com29348cb2009-08-04 18:17:15 +0000163static bool parse_bool_arg(char * const* argv, char* const* stop, bool* var) {
164 if (argv < stop) {
165 *var = atoi(*argv) != 0;
166 return true;
167 }
168 return false;
169}
170
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000171enum Backend {
172 kRaster_Backend,
173 kGPU_Backend,
174 kPDF_Backend,
175};
176
bsalomon@google.com508824b2011-12-13 16:49:49 +0000177class GLHelper {
178public:
179 GLHelper() {
180 }
181
182 bool init(SkGLContext* glCtx, int width, int height) {
183 GrContext* grCtx;
184 GrRenderTarget* rt;
185 if (glCtx->init(width, height)) {
186 GrPlatform3DContext ctx =
187 reinterpret_cast<GrPlatform3DContext>(glCtx->gl());
188 grCtx = GrContext::Create(kOpenGL_Shaders_GrEngine, ctx);
189 if (NULL != grCtx) {
190 GrPlatformRenderTargetDesc desc;
191 desc.fConfig = kSkia8888_PM_GrPixelConfig;
192 desc.fWidth = width;
193 desc.fHeight = height;
194 desc.fStencilBits = 8;
195 desc.fRenderTargetHandle = glCtx->getFBOID();
196 rt = grCtx->createPlatformRenderTarget(desc);
197 if (NULL == rt) {
198 grCtx->unref();
199 return false;
200 }
201 }
202 } else {
203 return false;
204 }
205 glCtx->ref();
206 fGLContext.reset(glCtx);
207 fGrContext.reset(grCtx);
208 fRenderTarget.reset(rt);
209 return true;
210 }
211
robertphillips@google.com0da37192012-03-19 14:42:13 +0000212 void cleanup() {
213 fGLContext.reset(NULL);
214 fGrContext.reset(NULL);
215 fRenderTarget.reset(NULL);
216 }
217
bsalomon@google.com508824b2011-12-13 16:49:49 +0000218 bool isValid() {
219 return NULL != fGLContext.get();
220 }
221
222 SkGLContext* glContext() {
223 return fGLContext.get();
224 }
225
226 GrRenderTarget* renderTarget() {
227 return fRenderTarget.get();
228 }
229
230 GrContext* grContext() {
231 return fGrContext.get();
232 }
233private:
234 SkAutoTUnref<SkGLContext> fGLContext;
235 SkAutoTUnref<GrContext> fGrContext;
236 SkAutoTUnref<GrRenderTarget> fRenderTarget;
237};
238
239static GLHelper gRealGLHelper;
240static GLHelper gNullGLHelper;
robertphillips@google.com0da37192012-03-19 14:42:13 +0000241static GLHelper gDebugGLHelper;
bsalomon@google.com508824b2011-12-13 16:49:49 +0000242
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000243static SkDevice* make_device(SkBitmap::Config config, const SkIPoint& size,
bsalomon@google.com508824b2011-12-13 16:49:49 +0000244 Backend backend, GLHelper* glHelper) {
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000245 SkDevice* device = NULL;
246 SkBitmap bitmap;
247 bitmap.setConfig(config, size.fX, size.fY);
bungeman@google.comd1a416a2011-05-18 18:37:07 +0000248
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000249 switch (backend) {
250 case kRaster_Backend:
251 bitmap.allocPixels();
252 erase(bitmap);
reed@google.comaf951c92011-06-16 19:10:39 +0000253 device = new SkDevice(bitmap);
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000254 break;
255 case kGPU_Backend:
bsalomon@google.com508824b2011-12-13 16:49:49 +0000256 device = new SkGpuDevice(glHelper->grContext(),
257 glHelper->renderTarget());
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000258 break;
259 case kPDF_Backend:
260 default:
261 SkASSERT(!"unsupported");
262 }
263 return device;
264}
265
reed@android.com4bc19832009-01-19 20:08:35 +0000266static const struct {
267 SkBitmap::Config fConfig;
268 const char* fName;
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000269 Backend fBackend;
bsalomon@google.com508824b2011-12-13 16:49:49 +0000270 GLHelper* fGLHelper;
reed@android.com4bc19832009-01-19 20:08:35 +0000271} gConfigs[] = {
bsalomon@google.com508824b2011-12-13 16:49:49 +0000272 { SkBitmap::kARGB_8888_Config, "8888", kRaster_Backend, NULL },
273 { SkBitmap::kRGB_565_Config, "565", kRaster_Backend, NULL },
274 { SkBitmap::kARGB_8888_Config, "GPU", kGPU_Backend, &gRealGLHelper },
275 { SkBitmap::kARGB_8888_Config, "NULLGPU", kGPU_Backend, &gNullGLHelper },
reed@android.com4bc19832009-01-19 20:08:35 +0000276};
277
reed@android.com4c7d3d62009-01-21 03:15:13 +0000278static int findConfig(const char config[]) {
279 for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); i++) {
280 if (!strcmp(config, gConfigs[i].fName)) {
281 return i;
282 }
283 }
284 return -1;
285}
286
tomhudson@google.com83823942011-10-28 14:59:07 +0000287static void determine_gpu_context_size(SkTDict<const char*>& defineDict,
288 int* contextWidth,
289 int* contextHeight) {
290 Iter iter(&defineDict);
291 SkBenchmark* bench;
292 while ((bench = iter.next()) != NULL) {
293 SkIPoint dim = bench->getSize();
294 if (*contextWidth < dim.fX) {
295 *contextWidth = dim.fX;
296 }
297 if (*contextHeight < dim.fY) {
298 *contextHeight = dim.fY;
299 }
300 }
301}
302
reed@google.com1a7eabc2011-10-31 16:33:52 +0000303static bool skip_name(const SkTDArray<const char*> array, const char name[]) {
304 if (0 == array.count()) {
305 // no names, so don't skip anything
306 return false;
307 }
308 for (int i = 0; i < array.count(); ++i) {
309 if (strstr(name, array[i])) {
310 // found the name, so don't skip
311 return false;
312 }
313 }
314 return true;
315}
316
reed@android.combd700c32009-01-05 03:34:50 +0000317int main (int argc, char * const argv[]) {
reed@android.com3a859a02009-01-28 00:56:29 +0000318 SkAutoGraphics ag;
bungeman@google.comd1a416a2011-05-18 18:37:07 +0000319
reed@android.come9d00602009-09-02 21:12:42 +0000320 SkTDict<const char*> defineDict(1024);
reed@android.com4bc19832009-01-19 20:08:35 +0000321 int repeatDraw = 1;
322 int forceAlpha = 0xFF;
323 bool forceAA = true;
reed@android.com29348cb2009-08-04 18:17:15 +0000324 bool forceFilter = false;
reed@android.com4e635f92009-10-19 17:39:46 +0000325 SkTriState::State forceDither = SkTriState::kDefault;
bungeman@google.combe9ad4e2011-06-07 19:16:02 +0000326 bool timerWall = false;
327 bool timerCpu = true;
328 bool timerGpu = true;
reed@android.com387359e2009-08-04 01:51:09 +0000329 bool doScale = false;
reed@android.com4c7d3d62009-01-21 03:15:13 +0000330 bool doRotate = false;
331 bool doClip = false;
agl@chromium.org652807b2010-04-27 15:47:34 +0000332 bool hasStrokeWidth = false;
333 float strokeWidth;
reed@google.com1a7eabc2011-10-31 16:33:52 +0000334 SkTDArray<const char*> fMatches;
bungeman@google.comd1a416a2011-05-18 18:37:07 +0000335
reed@android.comb398fe82009-01-07 11:47:57 +0000336 SkString outDir;
reed@android.com387359e2009-08-04 01:51:09 +0000337 SkBitmap::Config outConfig = SkBitmap::kNo_Config;
bsalomon@google.comcadbcb82012-01-06 19:22:11 +0000338 GLHelper* glHelper = NULL;
reed@android.com387359e2009-08-04 01:51:09 +0000339 const char* configName = "";
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000340 Backend backend = kRaster_Backend; // for warning
reed@android.com387359e2009-08-04 01:51:09 +0000341 int configCount = SK_ARRAY_COUNT(gConfigs);
bungeman@google.comd1a416a2011-05-18 18:37:07 +0000342
reed@android.comb398fe82009-01-07 11:47:57 +0000343 char* const* stop = argv + argc;
344 for (++argv; argv < stop; ++argv) {
345 if (strcmp(*argv, "-o") == 0) {
346 argv++;
347 if (argv < stop && **argv) {
348 outDir.set(*argv);
349 if (outDir.c_str()[outDir.size() - 1] != '/') {
350 outDir.append("/");
351 }
352 }
reed@android.com4bc19832009-01-19 20:08:35 +0000353 } else if (strcmp(*argv, "-repeat") == 0) {
354 argv++;
355 if (argv < stop) {
356 repeatDraw = atoi(*argv);
357 if (repeatDraw < 1) {
358 repeatDraw = 1;
359 }
360 } else {
reed@android.com29348cb2009-08-04 18:17:15 +0000361 log_error("missing arg for -repeat\n");
reed@android.com4bc19832009-01-19 20:08:35 +0000362 return -1;
363 }
bungeman@google.combe9ad4e2011-06-07 19:16:02 +0000364 } else if (strcmp(*argv, "-timers") == 0) {
365 argv++;
366 if (argv < stop) {
367 timerWall = false;
368 timerCpu = false;
369 timerGpu = false;
370 for (char* t = *argv; *t; ++t) {
371 switch (*t) {
372 case 'w': timerWall = true; break;
373 case 'c': timerCpu = true; break;
374 case 'g': timerGpu = true; break;
375 }
376 }
377 } else {
378 log_error("missing arg for -timers\n");
379 return -1;
380 }
reed@android.com4c7d3d62009-01-21 03:15:13 +0000381 } else if (!strcmp(*argv, "-rotate")) {
382 doRotate = true;
reed@android.com387359e2009-08-04 01:51:09 +0000383 } else if (!strcmp(*argv, "-scale")) {
384 doScale = true;
reed@android.com4c7d3d62009-01-21 03:15:13 +0000385 } else if (!strcmp(*argv, "-clip")) {
386 doClip = true;
reed@android.com4bc19832009-01-19 20:08:35 +0000387 } else if (strcmp(*argv, "-forceAA") == 0) {
reed@android.com29348cb2009-08-04 18:17:15 +0000388 if (!parse_bool_arg(++argv, stop, &forceAA)) {
389 log_error("missing arg for -forceAA\n");
390 return -1;
391 }
392 } else if (strcmp(*argv, "-forceFilter") == 0) {
393 if (!parse_bool_arg(++argv, stop, &forceFilter)) {
394 log_error("missing arg for -forceFilter\n");
395 return -1;
396 }
reed@android.com4e635f92009-10-19 17:39:46 +0000397 } else if (strcmp(*argv, "-forceDither") == 0) {
398 bool tmp;
399 if (!parse_bool_arg(++argv, stop, &tmp)) {
400 log_error("missing arg for -forceDither\n");
401 return -1;
402 }
403 forceDither = tmp ? SkTriState::kTrue : SkTriState::kFalse;
reed@android.com4bc19832009-01-19 20:08:35 +0000404 } else if (strcmp(*argv, "-forceBlend") == 0) {
reed@android.com29348cb2009-08-04 18:17:15 +0000405 bool wantAlpha = false;
406 if (!parse_bool_arg(++argv, stop, &wantAlpha)) {
407 log_error("missing arg for -forceBlend\n");
408 return -1;
409 }
410 forceAlpha = wantAlpha ? 0x80 : 0xFF;
agl@chromium.org652807b2010-04-27 15:47:34 +0000411 } else if (strcmp(*argv, "-strokeWidth") == 0) {
412 argv++;
413 if (argv < stop) {
414 const char *strokeWidthStr = *argv;
415 if (sscanf(strokeWidthStr, "%f", &strokeWidth) != 1) {
416 log_error("bad arg for -strokeWidth\n");
417 return -1;
418 }
419 hasStrokeWidth = true;
420 } else {
421 log_error("missing arg for -strokeWidth\n");
422 return -1;
423 }
reed@android.com387359e2009-08-04 01:51:09 +0000424 } else if (strcmp(*argv, "-match") == 0) {
425 argv++;
426 if (argv < stop) {
reed@google.com1a7eabc2011-10-31 16:33:52 +0000427 *fMatches.append() = *argv;
reed@android.com387359e2009-08-04 01:51:09 +0000428 } else {
reed@android.com29348cb2009-08-04 18:17:15 +0000429 log_error("missing arg for -match\n");
reed@android.com387359e2009-08-04 01:51:09 +0000430 return -1;
reed@android.com4c7d3d62009-01-21 03:15:13 +0000431 }
reed@android.com387359e2009-08-04 01:51:09 +0000432 } else if (strcmp(*argv, "-config") == 0) {
433 argv++;
434 if (argv < stop) {
435 int index = findConfig(*argv);
436 if (index >= 0) {
437 outConfig = gConfigs[index].fConfig;
438 configName = gConfigs[index].fName;
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000439 backend = gConfigs[index].fBackend;
bsalomon@google.com508824b2011-12-13 16:49:49 +0000440 glHelper = gConfigs[index].fGLHelper;
reed@android.com387359e2009-08-04 01:51:09 +0000441 configCount = 1;
442 } else {
reed@android.com29348cb2009-08-04 18:17:15 +0000443 SkString str;
444 str.printf("unrecognized config %s\n", *argv);
445 log_error(str);
reed@android.com387359e2009-08-04 01:51:09 +0000446 return -1;
447 }
448 } else {
reed@android.com29348cb2009-08-04 18:17:15 +0000449 log_error("missing arg for -config\n");
reed@android.com387359e2009-08-04 01:51:09 +0000450 return -1;
451 }
reed@android.com0c9da392010-02-22 19:50:13 +0000452 } else if (strlen(*argv) > 2 && strncmp(*argv, "-D", 2) == 0) {
reed@android.come9d00602009-09-02 21:12:42 +0000453 argv++;
reed@android.com0c9da392010-02-22 19:50:13 +0000454 if (argv < stop) {
reed@android.come9d00602009-09-02 21:12:42 +0000455 defineDict.set(argv[-1] + 2, *argv);
456 } else {
457 log_error("incomplete '-Dfoo bar' definition\n");
458 return -1;
459 }
reed@android.com387359e2009-08-04 01:51:09 +0000460 } else {
reed@android.com29348cb2009-08-04 18:17:15 +0000461 SkString str;
462 str.printf("unrecognized arg %s\n", *argv);
463 log_error(str);
reed@android.com387359e2009-08-04 01:51:09 +0000464 return -1;
reed@android.comb398fe82009-01-07 11:47:57 +0000465 }
466 }
bungeman@google.comd1a416a2011-05-18 18:37:07 +0000467
reed@google.com3b14dc12011-04-04 14:31:36 +0000468 // report our current settings
469 {
470 SkString str;
bungeman@google.coma5d48412011-06-15 17:25:46 +0000471 str.printf("skia bench: alpha=0x%02X antialias=%d filter=%d",
reed@google.com3b14dc12011-04-04 14:31:36 +0000472 forceAlpha, forceAA, forceFilter);
bungeman@google.coma5d48412011-06-15 17:25:46 +0000473 str.appendf(" rotate=%d scale=%d clip=%d",
474 doRotate, doScale, doClip);
475
476 const char * ditherName;
477 switch (forceDither) {
478 case SkTriState::kDefault: ditherName = "default"; break;
479 case SkTriState::kTrue: ditherName = "true"; break;
480 case SkTriState::kFalse: ditherName = "false"; break;
481 default: ditherName = "<invalid>"; break;
482 }
483 str.appendf(" dither=%s", ditherName);
484
485 if (hasStrokeWidth) {
486 str.appendf(" strokeWidth=%f", strokeWidth);
487 } else {
488 str.append(" strokeWidth=none");
489 }
490
491#if defined(SK_SCALAR_IS_FLOAT)
492 str.append(" scalar=float");
493#elif defined(SK_SCALAR_IS_FIXED)
494 str.append(" scalar=fixed");
495#endif
496
497#if defined(SK_BUILD_FOR_WIN32)
498 str.append(" system=WIN32");
499#elif defined(SK_BUILD_FOR_MAC)
500 str.append(" system=MAC");
501#elif defined(SK_BUILD_FOR_ANDROID)
502 str.append(" system=ANDROID");
503#elif defined(SK_BUILD_FOR_UNIX)
504 str.append(" system=UNIX");
505#else
506 str.append(" system=other");
507#endif
508
509#if defined(SK_DEBUG)
510 str.append(" DEBUG");
511#endif
512 str.append("\n");
reed@google.com3b14dc12011-04-04 14:31:36 +0000513 log_progress(str);
514 }
bsalomon@google.com508824b2011-12-13 16:49:49 +0000515
bungeman@google.coma5d48412011-06-15 17:25:46 +0000516 //Don't do GL when fixed.
517#if !defined(SK_SCALAR_IS_FIXED)
tomhudson@google.com83823942011-10-28 14:59:07 +0000518 int contextWidth = 1024;
519 int contextHeight = 1024;
520 determine_gpu_context_size(defineDict, &contextWidth, &contextHeight);
bsalomon@google.com508824b2011-12-13 16:49:49 +0000521 SkAutoTUnref<SkGLContext> realGLCtx(new SkNativeGLContext);
522 SkAutoTUnref<SkGLContext> nullGLCtx(new SkNullGLContext);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000523 SkAutoTUnref<SkGLContext> debugGLCtx(new SkDebugGLContext);
bsalomon@google.com508824b2011-12-13 16:49:49 +0000524 gRealGLHelper.init(realGLCtx.get(), contextWidth, contextHeight);
525 gNullGLHelper.init(nullGLCtx.get(), contextWidth, contextHeight);
robertphillips@google.com0da37192012-03-19 14:42:13 +0000526 gDebugGLHelper.init(debugGLCtx.get(), contextWidth, contextHeight);
bungeman@google.coma5d48412011-06-15 17:25:46 +0000527#endif
bsalomon@google.com508824b2011-12-13 16:49:49 +0000528 BenchTimer timer = BenchTimer(gRealGLHelper.glContext());
bsalomon@google.com74913722011-10-27 20:44:19 +0000529
reed@android.come9d00602009-09-02 21:12:42 +0000530 Iter iter(&defineDict);
reed@android.combd700c32009-01-05 03:34:50 +0000531 SkBenchmark* bench;
532 while ((bench = iter.next()) != NULL) {
reed@android.comb398fe82009-01-07 11:47:57 +0000533 SkIPoint dim = bench->getSize();
534 if (dim.fX <= 0 || dim.fY <= 0) {
535 continue;
536 }
reed@android.comb398fe82009-01-07 11:47:57 +0000537
reed@android.com4bc19832009-01-19 20:08:35 +0000538 bench->setForceAlpha(forceAlpha);
539 bench->setForceAA(forceAA);
reed@android.com29348cb2009-08-04 18:17:15 +0000540 bench->setForceFilter(forceFilter);
reed@android.com4e635f92009-10-19 17:39:46 +0000541 bench->setDither(forceDither);
agl@chromium.org652807b2010-04-27 15:47:34 +0000542 if (hasStrokeWidth) {
543 bench->setStrokeWidth(strokeWidth);
544 }
bungeman@google.comd1a416a2011-05-18 18:37:07 +0000545
reed@android.com387359e2009-08-04 01:51:09 +0000546 // only run benchmarks if their name contains matchStr
reed@google.com1a7eabc2011-10-31 16:33:52 +0000547 if (skip_name(fMatches, bench->getName())) {
reed@android.com387359e2009-08-04 01:51:09 +0000548 continue;
549 }
bungeman@google.comd1a416a2011-05-18 18:37:07 +0000550
reed@android.com29348cb2009-08-04 18:17:15 +0000551 {
552 SkString str;
reed@google.comd34658a2011-04-11 13:12:51 +0000553 str.printf("running bench [%d %d] %28s", dim.fX, dim.fY,
reed@android.com0c9da392010-02-22 19:50:13 +0000554 bench->getName());
reed@android.com29348cb2009-08-04 18:17:15 +0000555 log_progress(str);
556 }
bungeman@google.comd1a416a2011-05-18 18:37:07 +0000557
reed@android.com4bc19832009-01-19 20:08:35 +0000558 for (int configIndex = 0; configIndex < configCount; configIndex++) {
559 if (configCount > 1) {
560 outConfig = gConfigs[configIndex].fConfig;
561 configName = gConfigs[configIndex].fName;
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000562 backend = gConfigs[configIndex].fBackend;
bsalomon@google.com508824b2011-12-13 16:49:49 +0000563 glHelper = gConfigs[configIndex].fGLHelper;
reed@android.com4bc19832009-01-19 20:08:35 +0000564 }
bsalomon@google.com508824b2011-12-13 16:49:49 +0000565
566 if (kGPU_Backend == backend &&
567 (NULL == glHelper || !glHelper->isValid())) {
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000568 continue;
569 }
bungeman@google.comd1a416a2011-05-18 18:37:07 +0000570
bsalomon@google.com508824b2011-12-13 16:49:49 +0000571 SkDevice* device = make_device(outConfig, dim, backend, glHelper);
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000572 SkCanvas canvas(device);
573 device->unref();
bungeman@google.comd1a416a2011-05-18 18:37:07 +0000574
reed@android.com4c7d3d62009-01-21 03:15:13 +0000575 if (doClip) {
576 performClip(&canvas, dim.fX, dim.fY);
577 }
reed@android.com387359e2009-08-04 01:51:09 +0000578 if (doScale) {
579 performScale(&canvas, dim.fX, dim.fY);
580 }
reed@android.com4c7d3d62009-01-21 03:15:13 +0000581 if (doRotate) {
582 performRotate(&canvas, dim.fX, dim.fY);
583 }
bsalomon@google.com508824b2011-12-13 16:49:49 +0000584
bungeman@google.comd1a416a2011-05-18 18:37:07 +0000585 //warm up caches if needed
reed@android.comeca48362010-12-20 18:34:17 +0000586 if (repeatDraw > 1) {
587 SkAutoCanvasRestore acr(&canvas, true);
588 bench->draw(&canvas);
bsalomon@google.com508824b2011-12-13 16:49:49 +0000589 if (glHelper) {
590 glHelper->grContext()->flush();
591 SK_GL(*glHelper->glContext(), Finish());
bungeman@google.comd1a416a2011-05-18 18:37:07 +0000592 }
reed@android.comeca48362010-12-20 18:34:17 +0000593 }
bungeman@google.comd1a416a2011-05-18 18:37:07 +0000594
bungeman@google.combe9ad4e2011-06-07 19:16:02 +0000595 timer.start();
reed@android.com4bc19832009-01-19 20:08:35 +0000596 for (int i = 0; i < repeatDraw; i++) {
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000597 SkAutoCanvasRestore acr(&canvas, true);
598 bench->draw(&canvas);
bsalomon@google.com508824b2011-12-13 16:49:49 +0000599 if (glHelper) {
600 glHelper->grContext()->flush();
reed@google.com25df8882011-07-14 19:03:58 +0000601 }
602 }
bsalomon@google.com508824b2011-12-13 16:49:49 +0000603 if (glHelper) {
604 SK_GL(*glHelper->glContext(), Finish());
bsalomon@google.com788e2472011-10-19 20:56:30 +0000605 }
bsalomon@google.com788e2472011-10-19 20:56:30 +0000606 timer.end();
bungeman@google.comd1a416a2011-05-18 18:37:07 +0000607
reed@android.com4bc19832009-01-19 20:08:35 +0000608 if (repeatDraw > 1) {
reed@android.com29348cb2009-08-04 18:17:15 +0000609 SkString str;
bungeman@google.combe9ad4e2011-06-07 19:16:02 +0000610 str.printf(" %4s:", configName);
611 if (timerWall) {
612 str.appendf(" msecs = %6.2f", timer.fWall / repeatDraw);
613 }
614 if (timerCpu) {
615 str.appendf(" cmsecs = %6.2f", timer.fCpu / repeatDraw);
616 }
bsalomon@google.com508824b2011-12-13 16:49:49 +0000617 if (timerGpu && glHelper && timer.fGpu > 0) {
bungeman@google.combe9ad4e2011-06-07 19:16:02 +0000618 str.appendf(" gmsecs = %6.2f", timer.fGpu / repeatDraw);
619 }
reed@android.com29348cb2009-08-04 18:17:15 +0000620 log_progress(str);
reed@android.com4bc19832009-01-19 20:08:35 +0000621 }
reed@android.com4c7d3d62009-01-21 03:15:13 +0000622 if (outDir.size() > 0) {
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000623 saveFile(bench->getName(), configName, outDir.c_str(),
624 device->accessBitmap(false));
reed@android.com4c7d3d62009-01-21 03:15:13 +0000625 }
reed@android.com4bc19832009-01-19 20:08:35 +0000626 }
reed@android.com29348cb2009-08-04 18:17:15 +0000627 log_progress("\n");
reed@android.combd700c32009-01-05 03:34:50 +0000628 }
bsalomon@google.com971d0c82011-08-19 17:22:05 +0000629
robertphillips@google.com0da37192012-03-19 14:42:13 +0000630 // need to clean up here rather than post-main to allow leak detection to work
631 gDebugGLHelper.cleanup();
632
reed@android.combd700c32009-01-05 03:34:50 +0000633 return 0;
634}