blob: 757fa7036cd39f7514a47dbe86fc1f8e56ead676 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
bsalomon@google.com971d0c82011-08-19 17:22:05 +00007
epoger@google.com57f7abc2012-11-13 03:41:55 +00008/*
9 * Code for the "gm" (Golden Master) rendering comparison tool.
10 *
11 * If you make changes to this, re-run the self-tests at gm/tests/run.sh
12 * to make sure they still pass... you may need to change the expected
13 * results of the self-test.
14 */
15
bungeman@google.comb29c8832011-10-10 13:19:10 +000016#include "gm.h"
epoger@google.com7bc13a62012-02-14 14:53:59 +000017#include "system_preferences.h"
reed@android.comb9b9a182009-07-08 02:54:47 +000018#include "SkColorPriv.h"
reed@google.com8a85d0c2011-06-24 19:12:12 +000019#include "SkData.h"
junov@google.com4370aed2012-01-18 16:21:08 +000020#include "SkDeferredCanvas.h"
bsalomon@google.com971d0c82011-08-19 17:22:05 +000021#include "SkDevice.h"
epoger@google.comde961632012-10-26 18:56:36 +000022#include "SkDrawFilter.h"
scroggo@google.com5af9b202012-06-04 17:17:36 +000023#include "SkGPipe.h"
reed@android.com8015dd82009-06-21 00:49:18 +000024#include "SkGraphics.h"
25#include "SkImageDecoder.h"
26#include "SkImageEncoder.h"
epoger@google.come8ebeb12012-10-29 16:42:11 +000027#include "SkOSFile.h"
tomhudson@google.com9875dd12011-04-25 15:49:53 +000028#include "SkPicture.h"
robertphillips@google.com977b9c82012-06-05 19:35:09 +000029#include "SkRefCnt.h"
scroggo@google.com72c96722012-06-06 21:07:10 +000030#include "SkStream.h"
bsalomon@google.com2a48c3a2012-08-03 14:54:45 +000031#include "SkTArray.h"
scroggo@google.com72c96722012-06-06 21:07:10 +000032#include "SamplePipeControllers.h"
reed@google.com07700442010-12-20 19:46:07 +000033
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000034#if SK_SUPPORT_GPU
35#include "GrContextFactory.h"
36#include "GrRenderTarget.h"
37#include "SkGpuDevice.h"
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000038typedef GrContextFactory::GLContextType GLContextType;
39#else
40class GrContext;
41class GrRenderTarget;
42typedef int GLContextType;
43#endif
44
mike@reedtribe.org10afbef2011-12-30 16:02:53 +000045static bool gForceBWtext;
46
reed@google.com8923c6c2011-11-08 14:59:38 +000047extern bool gSkSuppressFontCachePurgeSpew;
48
reed@google.com07700442010-12-20 19:46:07 +000049#ifdef SK_SUPPORT_PDF
tomhudson@google.com9875dd12011-04-25 15:49:53 +000050 #include "SkPDFDevice.h"
51 #include "SkPDFDocument.h"
reed@google.com07700442010-12-20 19:46:07 +000052#endif
reed@android.com00dae862009-06-10 15:38:48 +000053
epoger@google.come3cc2eb2012-01-18 20:11:13 +000054// Until we resolve http://code.google.com/p/skia/issues/detail?id=455 ,
55// stop writing out XPS-format image baselines in gm.
56#undef SK_SUPPORT_XPS
bungeman@google.comb29c8832011-10-10 13:19:10 +000057#ifdef SK_SUPPORT_XPS
58 #include "SkXPSDevice.h"
59#endif
60
reed@google.com46cce912011-06-29 12:54:46 +000061#ifdef SK_BUILD_FOR_MAC
62 #include "SkCGUtils.h"
bsalomon@google.com0a09eef2011-06-29 19:42:58 +000063 #define CAN_IMAGE_PDF 1
reed@google.com46cce912011-06-29 12:54:46 +000064#else
bsalomon@google.com0a09eef2011-06-29 19:42:58 +000065 #define CAN_IMAGE_PDF 0
reed@google.com46cce912011-06-29 12:54:46 +000066#endif
67
epoger@google.comc7cf2b32011-12-28 19:31:01 +000068typedef int ErrorBitfield;
69const static ErrorBitfield ERROR_NONE = 0x00;
70const static ErrorBitfield ERROR_NO_GPU_CONTEXT = 0x01;
71const static ErrorBitfield ERROR_PIXEL_MISMATCH = 0x02;
72const static ErrorBitfield ERROR_DIMENSION_MISMATCH = 0x04;
73const static ErrorBitfield ERROR_READING_REFERENCE_IMAGE = 0x08;
74const static ErrorBitfield ERROR_WRITING_REFERENCE_IMAGE = 0x10;
75
reed@android.com00dae862009-06-10 15:38:48 +000076using namespace skiagm;
77
reed@google.comce7ffac2012-11-09 14:51:18 +000078/*
79 * Return the max of the difference (in absolute value) for any component.
80 * Returns 0 if they are equal.
81 */
82static int compute_PMColor_maxDiff(SkPMColor c0, SkPMColor c1) {
83 int da = SkAbs32(SkGetPackedA32(c0) - SkGetPackedA32(c1));
84 int dr = SkAbs32(SkGetPackedR32(c0) - SkGetPackedR32(c1));
85 int dg = SkAbs32(SkGetPackedG32(c0) - SkGetPackedG32(c1));
86 int db = SkAbs32(SkGetPackedB32(c0) - SkGetPackedB32(c1));
87 return SkMax32(da, SkMax32(dr, SkMax32(dg, db)));
88}
89
epoger@google.com57f7abc2012-11-13 03:41:55 +000090struct FailRec {
91 SkString fName;
92 int fMaxPixelError;
93
94 FailRec() : fMaxPixelError(0) {}
95 FailRec(const SkString& name) : fName(name), fMaxPixelError(0) {}
96};
97
reed@android.com00dae862009-06-10 15:38:48 +000098class Iter {
99public:
100 Iter() {
bsalomon@google.com39149582011-06-13 21:55:32 +0000101 this->reset();
102 }
103
104 void reset() {
reed@android.comdd0ac282009-06-20 02:38:16 +0000105 fReg = GMRegistry::Head();
reed@android.com00dae862009-06-10 15:38:48 +0000106 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000107
reed@android.comdd0ac282009-06-20 02:38:16 +0000108 GM* next() {
reed@android.com00dae862009-06-10 15:38:48 +0000109 if (fReg) {
reed@android.comdd0ac282009-06-20 02:38:16 +0000110 GMRegistry::Factory fact = fReg->factory();
reed@android.com00dae862009-06-10 15:38:48 +0000111 fReg = fReg->next();
reed@android.comdd0ac282009-06-20 02:38:16 +0000112 return fact(0);
reed@android.com00dae862009-06-10 15:38:48 +0000113 }
114 return NULL;
115 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000116
reed@android.com00dae862009-06-10 15:38:48 +0000117 static int Count() {
reed@android.comdd0ac282009-06-20 02:38:16 +0000118 const GMRegistry* reg = GMRegistry::Head();
reed@android.com00dae862009-06-10 15:38:48 +0000119 int count = 0;
120 while (reg) {
121 count += 1;
122 reg = reg->next();
123 }
124 return count;
125 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000126
reed@android.com00dae862009-06-10 15:38:48 +0000127private:
128 const GMRegistry* fReg;
129};
130
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000131enum Backend {
132 kRaster_Backend,
133 kGPU_Backend,
134 kPDF_Backend,
bungeman@google.comb29c8832011-10-10 13:19:10 +0000135 kXPS_Backend,
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000136};
137
bsalomon@google.com7361f542012-04-19 19:15:35 +0000138enum ConfigFlags {
139 kNone_ConfigFlag = 0x0,
140 /* Write GM images if a write path is provided. */
141 kWrite_ConfigFlag = 0x1,
epoger@google.comf28dd8a2012-10-25 16:27:34 +0000142 /* Read reference GM images if a read path is provided. */
bsalomon@google.com7361f542012-04-19 19:15:35 +0000143 kRead_ConfigFlag = 0x2,
144 kRW_ConfigFlag = (kWrite_ConfigFlag | kRead_ConfigFlag),
145};
146
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000147struct ConfigData {
bsalomon@google.com7361f542012-04-19 19:15:35 +0000148 SkBitmap::Config fConfig;
149 Backend fBackend;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000150 GLContextType fGLContextType; // GPU backend only
bsalomon@google.com7361f542012-04-19 19:15:35 +0000151 int fSampleCnt; // GPU backend only
152 ConfigFlags fFlags;
153 const char* fName;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000154};
155
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000156class BWTextDrawFilter : public SkDrawFilter {
157public:
reed@google.com971aca72012-11-26 20:26:54 +0000158 virtual bool filter(SkPaint*, Type) SK_OVERRIDE;
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000159};
reed@google.com971aca72012-11-26 20:26:54 +0000160bool BWTextDrawFilter::filter(SkPaint* p, Type t) {
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000161 if (kText_Type == t) {
162 p->setAntiAlias(false);
163 }
reed@google.com971aca72012-11-26 20:26:54 +0000164 return true;
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000165}
166
scroggo@google.com565254b2012-06-28 15:41:32 +0000167struct PipeFlagComboData {
168 const char* name;
169 uint32_t flags;
170};
171
172static PipeFlagComboData gPipeWritingFlagCombos[] = {
173 { "", 0 },
174 { " cross-process", SkGPipeWriter::kCrossProcess_Flag },
scroggob3c0f482012-07-02 19:07:57 +0000175 { " cross-process, shared address", SkGPipeWriter::kCrossProcess_Flag
scroggo@google.com15011ee2012-07-26 20:03:32 +0000176 | SkGPipeWriter::kSharedAddressSpace_Flag }
scroggo@google.com565254b2012-06-28 15:41:32 +0000177};
178
scroggo@google.com5af9b202012-06-04 17:17:36 +0000179
epoger@google.comde961632012-10-26 18:56:36 +0000180class GMMain {
181public:
epoger@google.come8ebeb12012-10-29 16:42:11 +0000182 GMMain() {
183 // Set default values of member variables, which tool_main()
184 // may override.
185 fNotifyMissingReadReference = true;
186 fUseFileHierarchy = false;
187 }
188
189 SkString make_name(const char shortName[], const char configName[]) {
190 SkString name;
epoger@google.com57f7abc2012-11-13 03:41:55 +0000191 if (0 == strlen(configName)) {
192 name.append(shortName);
193 } else if (fUseFileHierarchy) {
epoger@google.come8ebeb12012-10-29 16:42:11 +0000194 name.appendf("%s%c%s", configName, SkPATH_SEPARATOR, shortName);
195 } else {
196 name.appendf("%s_%s", shortName, configName);
197 }
epoger@google.comde961632012-10-26 18:56:36 +0000198 return name;
199 }
200
201 static SkString make_filename(const char path[],
202 const char pathSuffix[],
203 const SkString& name,
204 const char suffix[]) {
205 SkString filename(path);
epoger@google.come8ebeb12012-10-29 16:42:11 +0000206 if (filename.endsWith(SkPATH_SEPARATOR)) {
epoger@google.comde961632012-10-26 18:56:36 +0000207 filename.remove(filename.size() - 1, 1);
208 }
epoger@google.come8ebeb12012-10-29 16:42:11 +0000209 filename.appendf("%s%c%s.%s", pathSuffix, SkPATH_SEPARATOR,
210 name.c_str(), suffix);
epoger@google.comde961632012-10-26 18:56:36 +0000211 return filename;
212 }
213
214 /* since PNG insists on unpremultiplying our alpha, we take no
215 precision chances and force all pixels to be 100% opaque,
216 otherwise on compare we may not get a perfect match.
217 */
218 static void force_all_opaque(const SkBitmap& bitmap) {
219 SkAutoLockPixels lock(bitmap);
220 for (int y = 0; y < bitmap.height(); y++) {
221 for (int x = 0; x < bitmap.width(); x++) {
222 *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT);
223 }
scroggo@google.com565254b2012-06-28 15:41:32 +0000224 }
225 }
epoger@google.comde961632012-10-26 18:56:36 +0000226
227 static bool write_bitmap(const SkString& path, const SkBitmap& bitmap) {
228 SkBitmap copy;
229 bitmap.copyTo(&copy, SkBitmap::kARGB_8888_Config);
230 force_all_opaque(copy);
231 return SkImageEncoder::EncodeFile(path.c_str(), copy,
232 SkImageEncoder::kPNG_Type, 100);
233 }
234
235 static inline SkPMColor compute_diff_pmcolor(SkPMColor c0, SkPMColor c1) {
236 int dr = SkGetPackedR32(c0) - SkGetPackedR32(c1);
237 int dg = SkGetPackedG32(c0) - SkGetPackedG32(c1);
238 int db = SkGetPackedB32(c0) - SkGetPackedB32(c1);
239 return SkPackARGB32(0xFF, SkAbs32(dr), SkAbs32(dg), SkAbs32(db));
240 }
241
242 static void compute_diff(const SkBitmap& target, const SkBitmap& base,
243 SkBitmap* diff) {
244 SkAutoLockPixels alp(*diff);
245
246 const int w = target.width();
247 const int h = target.height();
248 for (int y = 0; y < h; y++) {
249 for (int x = 0; x < w; x++) {
250 SkPMColor c0 = *base.getAddr32(x, y);
251 SkPMColor c1 = *target.getAddr32(x, y);
252 SkPMColor d = 0;
253 if (c0 != c1) {
254 d = compute_diff_pmcolor(c0, c1);
255 }
256 *diff->getAddr32(x, y) = d;
257 }
258 }
259 }
260
epoger@google.com57f7abc2012-11-13 03:41:55 +0000261 // Records an error in fFailedTests, if we want to record errors
262 // of this type.
263 void RecordError(ErrorBitfield errorType, const SkString& name,
264 const char renderModeDescriptor [], int maxPixelError=0) {
265 switch (errorType) {
266 case ERROR_NONE:
267 break;
268 case ERROR_READING_REFERENCE_IMAGE:
269 break;
270 default:
271 FailRec& rec = fFailedTests.push_back(make_name(
272 name.c_str(), renderModeDescriptor));
273 rec.fMaxPixelError = maxPixelError;
274 break;
275 }
276 }
277
278 // List contents of fFailedTests via SkDebug.
279 void ListErrors() {
280 for (int i = 0; i < fFailedTests.count(); ++i) {
281 int pixErr = fFailedTests[i].fMaxPixelError;
282 SkString pixStr;
283 if (pixErr > 0) {
284 pixStr.printf(" pixel_error %d", pixErr);
285 }
286 SkDebugf("\t\t%s%s\n", fFailedTests[i].fName.c_str(),
287 pixStr.c_str());
288 }
289 }
290
epoger@google.comde961632012-10-26 18:56:36 +0000291 // Compares "target" and "base" bitmaps, returning the result
292 // (ERROR_NONE if the two bitmaps are identical).
293 //
294 // If a "diff" bitmap is passed in, pixel diffs (if any) will be written
295 // into it.
epoger@google.com57f7abc2012-11-13 03:41:55 +0000296 ErrorBitfield compare(const SkBitmap& target, const SkBitmap& base,
297 const SkString& name,
298 const char* renderModeDescriptor,
299 SkBitmap* diff) {
epoger@google.comde961632012-10-26 18:56:36 +0000300 SkBitmap copy;
301 const SkBitmap* bm = &target;
302 if (target.config() != SkBitmap::kARGB_8888_Config) {
303 target.copyTo(&copy, SkBitmap::kARGB_8888_Config);
304 bm = &copy;
305 }
306 SkBitmap baseCopy;
307 const SkBitmap* bp = &base;
308 if (base.config() != SkBitmap::kARGB_8888_Config) {
309 base.copyTo(&baseCopy, SkBitmap::kARGB_8888_Config);
310 bp = &baseCopy;
311 }
312
313 force_all_opaque(*bm);
314 force_all_opaque(*bp);
315
316 const int w = bm->width();
317 const int h = bm->height();
318 if (w != bp->width() || h != bp->height()) {
319 SkDebugf(
320 "---- %s dimensions mismatch for %s base [%d %d] current [%d %d]\n",
321 renderModeDescriptor, name.c_str(),
322 bp->width(), bp->height(), w, h);
epoger@google.com57f7abc2012-11-13 03:41:55 +0000323 RecordError(ERROR_DIMENSION_MISMATCH, name, renderModeDescriptor);
epoger@google.comde961632012-10-26 18:56:36 +0000324 return ERROR_DIMENSION_MISMATCH;
325 }
326
327 SkAutoLockPixels bmLock(*bm);
328 SkAutoLockPixels baseLock(*bp);
329
reed@google.comce7ffac2012-11-09 14:51:18 +0000330 int maxErr = 0;
epoger@google.comde961632012-10-26 18:56:36 +0000331 for (int y = 0; y < h; y++) {
332 for (int x = 0; x < w; x++) {
333 SkPMColor c0 = *bp->getAddr32(x, y);
334 SkPMColor c1 = *bm->getAddr32(x, y);
335 if (c0 != c1) {
reed@google.comce7ffac2012-11-09 14:51:18 +0000336 maxErr = SkMax32(maxErr, compute_PMColor_maxDiff(c0, c1));
epoger@google.comde961632012-10-26 18:56:36 +0000337 }
338 }
339 }
340
reed@google.comce7ffac2012-11-09 14:51:18 +0000341 if (maxErr > 0) {
342 SkDebugf(
343 "----- %s max pixel mismatch for %s is %d\n",
344 renderModeDescriptor, name.c_str(), maxErr);
reed@google.comce7ffac2012-11-09 14:51:18 +0000345 if (diff) {
346 diff->setConfig(SkBitmap::kARGB_8888_Config, w, h);
347 diff->allocPixels();
348 compute_diff(*bm, *bp, diff);
349 }
epoger@google.com57f7abc2012-11-13 03:41:55 +0000350 RecordError(ERROR_PIXEL_MISMATCH, name, renderModeDescriptor,
351 maxErr);
reed@google.comce7ffac2012-11-09 14:51:18 +0000352 return ERROR_PIXEL_MISMATCH;
353 }
epoger@google.comde961632012-10-26 18:56:36 +0000354 return ERROR_NONE;
355 }
356
357 static bool write_document(const SkString& path,
358 const SkDynamicMemoryWStream& document) {
359 SkFILEWStream stream(path.c_str());
360 SkAutoDataUnref data(document.copyToData());
361 return stream.writeData(data.get());
362 }
363
364 /// Returns true if processing should continue, false to skip the
365 /// remainder of this config for this GM.
366 //@todo thudson 22 April 2011 - could refactor this to take in
367 // a factory to generate the context, always call readPixels()
368 // (logically a noop for rasters, if wasted time), and thus collapse the
369 // GPU special case and also let this be used for SkPicture testing.
370 static void setup_bitmap(const ConfigData& gRec, SkISize& size,
371 SkBitmap* bitmap) {
372 bitmap->setConfig(gRec.fConfig, size.width(), size.height());
373 bitmap->allocPixels();
374 bitmap->eraseColor(0);
375 }
376
377 static void installFilter(SkCanvas* canvas) {
378 if (gForceBWtext) {
379 canvas->setDrawFilter(new BWTextDrawFilter)->unref();
380 }
381 }
382
reed@google.comaef73612012-11-16 13:41:45 +0000383 static void invokeGM(GM* gm, SkCanvas* canvas, bool isPDF, bool isDeferred) {
epoger@google.comde961632012-10-26 18:56:36 +0000384 SkAutoCanvasRestore acr(canvas, true);
385
386 if (!isPDF) {
387 canvas->concat(gm->getInitialTransform());
388 }
389 installFilter(canvas);
reed@google.comaef73612012-11-16 13:41:45 +0000390 gm->setCanvasIsDeferred(isDeferred);
epoger@google.comde961632012-10-26 18:56:36 +0000391 gm->draw(canvas);
392 canvas->setDrawFilter(NULL);
393 }
394
395 static ErrorBitfield generate_image(GM* gm, const ConfigData& gRec,
396 GrContext* context,
397 GrRenderTarget* rt,
398 SkBitmap* bitmap,
399 bool deferred) {
400 SkISize size (gm->getISize());
401 setup_bitmap(gRec, size, bitmap);
402
403 SkAutoTUnref<SkCanvas> canvas;
404
405 if (gRec.fBackend == kRaster_Backend) {
406 SkAutoTUnref<SkDevice> device(new SkDevice(*bitmap));
407 if (deferred) {
408 canvas.reset(new SkDeferredCanvas(device));
409 } else {
410 canvas.reset(new SkCanvas(device));
411 }
reed@google.comaef73612012-11-16 13:41:45 +0000412 invokeGM(gm, canvas, false, deferred);
epoger@google.comde961632012-10-26 18:56:36 +0000413 canvas->flush();
414 }
415#if SK_SUPPORT_GPU
416 else { // GPU
417 if (NULL == context) {
418 return ERROR_NO_GPU_CONTEXT;
419 }
420 SkAutoTUnref<SkDevice> device(new SkGpuDevice(context, rt));
421 if (deferred) {
422 canvas.reset(new SkDeferredCanvas(device));
423 } else {
424 canvas.reset(new SkCanvas(device));
425 }
reed@google.comaef73612012-11-16 13:41:45 +0000426 invokeGM(gm, canvas, false, deferred);
epoger@google.comde961632012-10-26 18:56:36 +0000427 // the device is as large as the current rendertarget, so
428 // we explicitly only readback the amount we expect (in
429 // size) overwrite our previous allocation
430 bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth,
431 size.fHeight);
432 canvas->readPixels(bitmap, 0, 0);
433 }
434#endif
435 return ERROR_NONE;
436 }
437
438 static void generate_image_from_picture(GM* gm, const ConfigData& gRec,
439 SkPicture* pict, SkBitmap* bitmap) {
440 SkISize size = gm->getISize();
441 setup_bitmap(gRec, size, bitmap);
442 SkCanvas canvas(*bitmap);
443 installFilter(&canvas);
444 canvas.drawPicture(*pict);
445 }
446
447 static void generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) {
448#ifdef SK_SUPPORT_PDF
449 SkMatrix initialTransform = gm->getInitialTransform();
450 SkISize pageSize = gm->getISize();
451 SkPDFDevice* dev = NULL;
452 if (initialTransform.isIdentity()) {
453 dev = new SkPDFDevice(pageSize, pageSize, initialTransform);
454 } else {
455 SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()),
456 SkIntToScalar(pageSize.height()));
457 initialTransform.mapRect(&content);
458 content.intersect(0, 0, SkIntToScalar(pageSize.width()),
459 SkIntToScalar(pageSize.height()));
460 SkISize contentSize =
461 SkISize::Make(SkScalarRoundToInt(content.width()),
462 SkScalarRoundToInt(content.height()));
463 dev = new SkPDFDevice(pageSize, contentSize, initialTransform);
464 }
465 SkAutoUnref aur(dev);
466
467 SkCanvas c(dev);
reed@google.comaef73612012-11-16 13:41:45 +0000468 invokeGM(gm, &c, true, false);
epoger@google.comde961632012-10-26 18:56:36 +0000469
470 SkPDFDocument doc;
471 doc.appendPage(dev);
472 doc.emitPDF(&pdf);
473#endif
474 }
475
476 static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) {
477#ifdef SK_SUPPORT_XPS
478 SkISize size = gm->getISize();
479
480 SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()),
481 SkIntToScalar(size.height()));
482 static const SkScalar inchesPerMeter = SkScalarDiv(10000, 254);
483 static const SkScalar upm = 72 * inchesPerMeter;
484 SkVector unitsPerMeter = SkPoint::Make(upm, upm);
485 static const SkScalar ppm = 200 * inchesPerMeter;
486 SkVector pixelsPerMeter = SkPoint::Make(ppm, ppm);
487
488 SkXPSDevice* dev = new SkXPSDevice();
489 SkAutoUnref aur(dev);
490
491 SkCanvas c(dev);
492 dev->beginPortfolio(&xps);
493 dev->beginSheet(unitsPerMeter, pixelsPerMeter, trimSize);
reed@google.comaef73612012-11-16 13:41:45 +0000494 invokeGM(gm, &c, false, false);
epoger@google.comde961632012-10-26 18:56:36 +0000495 dev->endSheet();
496 dev->endPortfolio();
497
498#endif
499 }
500
epoger@google.com57f7abc2012-11-13 03:41:55 +0000501 ErrorBitfield write_reference_image(
epoger@google.comde961632012-10-26 18:56:36 +0000502 const ConfigData& gRec, const char writePath [],
503 const char renderModeDescriptor [], const SkString& name,
504 SkBitmap& bitmap, SkDynamicMemoryWStream* document) {
505 SkString path;
506 bool success = false;
507 if (gRec.fBackend == kRaster_Backend ||
508 gRec.fBackend == kGPU_Backend ||
509 (gRec.fBackend == kPDF_Backend && CAN_IMAGE_PDF)) {
510
511 path = make_filename(writePath, renderModeDescriptor, name, "png");
512 success = write_bitmap(path, bitmap);
513 }
514 if (kPDF_Backend == gRec.fBackend) {
515 path = make_filename(writePath, renderModeDescriptor, name, "pdf");
516 success = write_document(path, *document);
517 }
518 if (kXPS_Backend == gRec.fBackend) {
519 path = make_filename(writePath, renderModeDescriptor, name, "xps");
520 success = write_document(path, *document);
521 }
522 if (success) {
523 return ERROR_NONE;
524 } else {
525 fprintf(stderr, "FAILED to write %s\n", path.c_str());
epoger@google.com57f7abc2012-11-13 03:41:55 +0000526 RecordError(ERROR_WRITING_REFERENCE_IMAGE, name,
527 renderModeDescriptor);
epoger@google.comde961632012-10-26 18:56:36 +0000528 return ERROR_WRITING_REFERENCE_IMAGE;
529 }
530 }
531
532 // Compares bitmap "bitmap" to "referenceBitmap"; if they are
533 // different, writes out "bitmap" (in PNG format) within the
534 // diffPath subdir.
535 //
536 // Returns the ErrorBitfield from compare(), describing any differences
537 // between "bitmap" and "referenceBitmap" (or ERROR_NONE if there are none).
epoger@google.com57f7abc2012-11-13 03:41:55 +0000538 ErrorBitfield compare_to_reference_image_in_memory(
epoger@google.comde961632012-10-26 18:56:36 +0000539 const SkString& name, SkBitmap &bitmap, const SkBitmap& referenceBitmap,
epoger@google.com57f7abc2012-11-13 03:41:55 +0000540 const char diffPath [], const char renderModeDescriptor []) {
epoger@google.comde961632012-10-26 18:56:36 +0000541 ErrorBitfield errors;
542 SkBitmap diffBitmap;
543 errors = compare(bitmap, referenceBitmap, name, renderModeDescriptor,
epoger@google.com57f7abc2012-11-13 03:41:55 +0000544 diffPath ? &diffBitmap : NULL);
epoger@google.comde961632012-10-26 18:56:36 +0000545 if ((ERROR_NONE != errors) && diffPath) {
546 // write out the generated image
547 SkString genName = make_filename(diffPath, "", name, "png");
548 if (!write_bitmap(genName, bitmap)) {
epoger@google.com57f7abc2012-11-13 03:41:55 +0000549 RecordError(ERROR_WRITING_REFERENCE_IMAGE, name,
550 renderModeDescriptor);
epoger@google.comde961632012-10-26 18:56:36 +0000551 errors |= ERROR_WRITING_REFERENCE_IMAGE;
552 }
553 }
554 return errors;
555 }
556
557 // Compares bitmap "bitmap" to a reference bitmap read from disk;
558 // if they are different, writes out "bitmap" (in PNG format)
559 // within the diffPath subdir.
560 //
561 // Returns a description of the difference between "bitmap" and
562 // the reference bitmap, or ERROR_READING_REFERENCE_IMAGE if
563 // unable to read the reference bitmap from disk.
epoger@google.come8ebeb12012-10-29 16:42:11 +0000564 ErrorBitfield compare_to_reference_image_on_disk(
epoger@google.comde961632012-10-26 18:56:36 +0000565 const char readPath [], const SkString& name, SkBitmap &bitmap,
epoger@google.com57f7abc2012-11-13 03:41:55 +0000566 const char diffPath [], const char renderModeDescriptor []) {
epoger@google.comde961632012-10-26 18:56:36 +0000567 SkString path = make_filename(readPath, "", name, "png");
568 SkBitmap referenceBitmap;
569 if (SkImageDecoder::DecodeFile(path.c_str(), &referenceBitmap,
570 SkBitmap::kARGB_8888_Config,
571 SkImageDecoder::kDecodePixels_Mode,
572 NULL)) {
573 return compare_to_reference_image_in_memory(name, bitmap,
574 referenceBitmap,
575 diffPath,
epoger@google.com57f7abc2012-11-13 03:41:55 +0000576 renderModeDescriptor);
epoger@google.comde961632012-10-26 18:56:36 +0000577 } else {
epoger@google.come8ebeb12012-10-29 16:42:11 +0000578 if (fNotifyMissingReadReference) {
epoger@google.comde961632012-10-26 18:56:36 +0000579 fprintf(stderr, "FAILED to read %s\n", path.c_str());
580 }
epoger@google.com57f7abc2012-11-13 03:41:55 +0000581 RecordError(ERROR_READING_REFERENCE_IMAGE, name,
582 renderModeDescriptor);
epoger@google.comde961632012-10-26 18:56:36 +0000583 return ERROR_READING_REFERENCE_IMAGE;
584 }
585 }
586
587 // NOTE: As far as I can tell, this function is NEVER called with a
588 // non-blank renderModeDescriptor, EXCEPT when readPath and writePath are
589 // both NULL (and thus no images are read from or written to disk).
590 // So I don't trust that the renderModeDescriptor is being used for
591 // anything other than debug output these days.
epoger@google.come8ebeb12012-10-29 16:42:11 +0000592 ErrorBitfield handle_test_results(GM* gm,
593 const ConfigData& gRec,
594 const char writePath [],
595 const char readPath [],
596 const char diffPath [],
597 const char renderModeDescriptor [],
598 SkBitmap& bitmap,
599 SkDynamicMemoryWStream* pdf,
epoger@google.com57f7abc2012-11-13 03:41:55 +0000600 const SkBitmap* referenceBitmap) {
epoger@google.comde961632012-10-26 18:56:36 +0000601 SkString name = make_name(gm->shortName(), gRec.fName);
602 ErrorBitfield retval = ERROR_NONE;
603
604 if (readPath && (gRec.fFlags & kRead_ConfigFlag)) {
605 retval |= compare_to_reference_image_on_disk(readPath, name, bitmap,
606 diffPath,
epoger@google.com57f7abc2012-11-13 03:41:55 +0000607 renderModeDescriptor);
epoger@google.comde961632012-10-26 18:56:36 +0000608 }
609 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) {
610 retval |= write_reference_image(gRec, writePath,
611 renderModeDescriptor,
612 name, bitmap, pdf);
613 }
614 if (referenceBitmap) {
615 retval |= compare_to_reference_image_in_memory(
epoger@google.com57f7abc2012-11-13 03:41:55 +0000616 name, bitmap, *referenceBitmap, diffPath, renderModeDescriptor);
epoger@google.comde961632012-10-26 18:56:36 +0000617 }
618 return retval;
619 }
620
621 static SkPicture* generate_new_picture(GM* gm) {
622 // Pictures are refcounted so must be on heap
623 SkPicture* pict = new SkPicture;
624 SkISize size = gm->getISize();
625 SkCanvas* cv = pict->beginRecording(size.width(), size.height());
reed@google.comaef73612012-11-16 13:41:45 +0000626 invokeGM(gm, cv, false, false);
epoger@google.comde961632012-10-26 18:56:36 +0000627 pict->endRecording();
628
629 return pict;
630 }
631
632 static SkPicture* stream_to_new_picture(const SkPicture& src) {
633
634 // To do in-memory commiunications with a stream, we need to:
635 // * create a dynamic memory stream
636 // * copy it into a buffer
637 // * create a read stream from it
638 // ?!?!
639
640 SkDynamicMemoryWStream storage;
641 src.serialize(&storage);
642
643 int streamSize = storage.getOffset();
644 SkAutoMalloc dstStorage(streamSize);
645 void* dst = dstStorage.get();
646 //char* dst = new char [streamSize];
647 //@todo thudson 22 April 2011 when can we safely delete [] dst?
648 storage.copyTo(dst);
649 SkMemoryStream pictReadback(dst, streamSize);
650 SkPicture* retval = new SkPicture (&pictReadback);
651 return retval;
652 }
653
654 // Test: draw into a bitmap or pdf.
655 // Depending on flags, possibly compare to an expected image
656 // and possibly output a diff image if it fails to match.
epoger@google.come8ebeb12012-10-29 16:42:11 +0000657 ErrorBitfield test_drawing(GM* gm,
658 const ConfigData& gRec,
659 const char writePath [],
660 const char readPath [],
661 const char diffPath [],
662 GrContext* context,
663 GrRenderTarget* rt,
epoger@google.com57f7abc2012-11-13 03:41:55 +0000664 SkBitmap* bitmap) {
epoger@google.comde961632012-10-26 18:56:36 +0000665 SkDynamicMemoryWStream document;
666
667 if (gRec.fBackend == kRaster_Backend ||
668 gRec.fBackend == kGPU_Backend) {
669 // Early exit if we can't generate the image.
670 ErrorBitfield errors = generate_image(gm, gRec, context, rt, bitmap,
671 false);
672 if (ERROR_NONE != errors) {
673 return errors;
674 }
675 } else if (gRec.fBackend == kPDF_Backend) {
676 generate_pdf(gm, document);
677#if CAN_IMAGE_PDF
678 SkAutoDataUnref data(document.copyToData());
679 SkMemoryStream stream(data->data(), data->size());
680 SkPDFDocumentToBitmap(&stream, bitmap);
681#endif
682 } else if (gRec.fBackend == kXPS_Backend) {
683 generate_xps(gm, document);
684 }
685 return handle_test_results(gm, gRec, writePath, readPath, diffPath,
epoger@google.com57f7abc2012-11-13 03:41:55 +0000686 "", *bitmap, &document, NULL);
epoger@google.comde961632012-10-26 18:56:36 +0000687 }
688
epoger@google.come8ebeb12012-10-29 16:42:11 +0000689 ErrorBitfield test_deferred_drawing(GM* gm,
690 const ConfigData& gRec,
691 const SkBitmap& referenceBitmap,
692 const char diffPath [],
693 GrContext* context,
694 GrRenderTarget* rt) {
epoger@google.comde961632012-10-26 18:56:36 +0000695 SkDynamicMemoryWStream document;
696
697 if (gRec.fBackend == kRaster_Backend ||
698 gRec.fBackend == kGPU_Backend) {
699 SkBitmap bitmap;
700 // Early exit if we can't generate the image, but this is
701 // expected in some cases, so don't report a test failure.
702 if (!generate_image(gm, gRec, context, rt, &bitmap, true)) {
703 return ERROR_NONE;
704 }
705 return handle_test_results(gm, gRec, NULL, NULL, diffPath,
706 "-deferred", bitmap, NULL,
epoger@google.com57f7abc2012-11-13 03:41:55 +0000707 &referenceBitmap);
epoger@google.comde961632012-10-26 18:56:36 +0000708 }
709 return ERROR_NONE;
710 }
711
epoger@google.come8ebeb12012-10-29 16:42:11 +0000712 ErrorBitfield test_pipe_playback(GM* gm,
713 const ConfigData& gRec,
714 const SkBitmap& referenceBitmap,
715 const char readPath [],
716 const char diffPath []) {
epoger@google.comde961632012-10-26 18:56:36 +0000717 ErrorBitfield errors = ERROR_NONE;
718 for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) {
719 SkBitmap bitmap;
720 SkISize size = gm->getISize();
721 setup_bitmap(gRec, size, &bitmap);
722 SkCanvas canvas(bitmap);
723 PipeController pipeController(&canvas);
724 SkGPipeWriter writer;
725 SkCanvas* pipeCanvas = writer.startRecording(
726 &pipeController, gPipeWritingFlagCombos[i].flags);
reed@google.comaef73612012-11-16 13:41:45 +0000727 invokeGM(gm, pipeCanvas, false, false);
epoger@google.comde961632012-10-26 18:56:36 +0000728 writer.endRecording();
729 SkString string("-pipe");
730 string.append(gPipeWritingFlagCombos[i].name);
731 errors |= handle_test_results(gm, gRec, NULL, NULL, diffPath,
732 string.c_str(), bitmap, NULL,
epoger@google.com57f7abc2012-11-13 03:41:55 +0000733 &referenceBitmap);
epoger@google.comde961632012-10-26 18:56:36 +0000734 if (errors != ERROR_NONE) {
735 break;
736 }
737 }
738 return errors;
739 }
740
epoger@google.come8ebeb12012-10-29 16:42:11 +0000741 ErrorBitfield test_tiled_pipe_playback(
epoger@google.comde961632012-10-26 18:56:36 +0000742 GM* gm, const ConfigData& gRec, const SkBitmap& referenceBitmap,
743 const char readPath [], const char diffPath []) {
744 ErrorBitfield errors = ERROR_NONE;
745 for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) {
746 SkBitmap bitmap;
747 SkISize size = gm->getISize();
748 setup_bitmap(gRec, size, &bitmap);
749 SkCanvas canvas(bitmap);
750 TiledPipeController pipeController(bitmap);
751 SkGPipeWriter writer;
752 SkCanvas* pipeCanvas = writer.startRecording(
753 &pipeController, gPipeWritingFlagCombos[i].flags);
reed@google.comaef73612012-11-16 13:41:45 +0000754 invokeGM(gm, pipeCanvas, false, false);
epoger@google.comde961632012-10-26 18:56:36 +0000755 writer.endRecording();
756 SkString string("-tiled pipe");
757 string.append(gPipeWritingFlagCombos[i].name);
758 errors |= handle_test_results(gm, gRec, NULL, NULL, diffPath,
759 string.c_str(), bitmap, NULL,
epoger@google.com57f7abc2012-11-13 03:41:55 +0000760 &referenceBitmap);
epoger@google.comde961632012-10-26 18:56:36 +0000761 if (errors != ERROR_NONE) {
762 break;
763 }
764 }
765 return errors;
766 }
epoger@google.come8ebeb12012-10-29 16:42:11 +0000767
768 //
769 // member variables.
770 // They are public for now, to allow easier setting by tool_main().
771 //
772
773 // if true, emit a message when we can't find a reference image to compare
774 bool fNotifyMissingReadReference;
775
776 bool fUseFileHierarchy;
777
epoger@google.com57f7abc2012-11-13 03:41:55 +0000778 // information about all failed tests we have encountered so far
779 SkTArray<FailRec> fFailedTests;
780
epoger@google.comde961632012-10-26 18:56:36 +0000781}; // end of GMMain class definition
scroggo@google.com72c96722012-06-06 21:07:10 +0000782
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000783#if SK_SUPPORT_GPU
784static const GLContextType kDontCare_GLContextType = GrContextFactory::kNative_GLContextType;
785#else
786static const GLContextType kDontCare_GLContextType = 0;
787#endif
bsalomon@google.com7361f542012-04-19 19:15:35 +0000788
789// If the platform does not support writing PNGs of PDFs then there will be no
epoger@google.comf28dd8a2012-10-25 16:27:34 +0000790// reference images to read. However, we can always write the .pdf files
bsalomon@google.com7361f542012-04-19 19:15:35 +0000791static const ConfigFlags kPDFConfigFlags = CAN_IMAGE_PDF ? kRW_ConfigFlag :
792 kWrite_ConfigFlag;
793
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000794static const ConfigData gRec[] = {
bsalomon@google.com7361f542012-04-19 19:15:35 +0000795 { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "8888" },
reed@google.com69dc4ff2012-11-29 21:21:54 +0000796#if 0 // stop testing this (for now at least) since we want to remove support for it (soon please!!!)
bsalomon@google.com7361f542012-04-19 19:15:35 +0000797 { SkBitmap::kARGB_4444_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "4444" },
reed@google.com69dc4ff2012-11-29 21:21:54 +0000798#endif
bsalomon@google.com7361f542012-04-19 19:15:35 +0000799 { SkBitmap::kRGB_565_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "565" },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000800#if defined(SK_SCALAR_IS_FLOAT) && SK_SUPPORT_GPU
bsalomon@google.com7361f542012-04-19 19:15:35 +0000801 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 0, kRW_ConfigFlag, "gpu" },
robertphillips@google.coma73e8602012-08-02 17:56:02 +0000802#ifndef SK_BUILD_FOR_ANDROID
803 // currently we don't want to run MSAA tests on Android
bsalomon@google.com7361f542012-04-19 19:15:35 +0000804 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 16, kRW_ConfigFlag, "msaa16" },
robertphillips@google.coma73e8602012-08-02 17:56:02 +0000805#endif
bsalomon@google.com7361f542012-04-19 19:15:35 +0000806 /* The debug context does not generate images */
807 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kDebug_GLContextType, 0, kNone_ConfigFlag, "debug" },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000808#if SK_ANGLE
bsalomon@google.com7361f542012-04-19 19:15:35 +0000809 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 0, kRW_ConfigFlag, "angle" },
810 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 16, kRW_ConfigFlag, "anglemsaa16" },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000811#endif // SK_ANGLE
812#ifdef SK_MESA
bsalomon@google.com7361f542012-04-19 19:15:35 +0000813 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kMESA_GLContextType, 0, kRW_ConfigFlag, "mesa" },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000814#endif // SK_MESA
robertphillips@google.coma73e8602012-08-02 17:56:02 +0000815#endif // defined(SK_SCALAR_IS_FLOAT) && SK_SUPPORT_GPU
bungeman@google.comb29c8832011-10-10 13:19:10 +0000816#ifdef SK_SUPPORT_XPS
bsalomon@google.com7361f542012-04-19 19:15:35 +0000817 /* At present we have no way of comparing XPS files (either natively or by converting to PNG). */
818 { SkBitmap::kARGB_8888_Config, kXPS_Backend, kDontCare_GLContextType, 0, kWrite_ConfigFlag, "xps" },
robertphillips@google.coma73e8602012-08-02 17:56:02 +0000819#endif // SK_SUPPORT_XPS
bsalomon@google.com7361f542012-04-19 19:15:35 +0000820#ifdef SK_SUPPORT_PDF
821 { SkBitmap::kARGB_8888_Config, kPDF_Backend, kDontCare_GLContextType, 0, kPDFConfigFlags, "pdf" },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000822#endif // SK_SUPPORT_PDF
reed@android.com00dae862009-06-10 15:38:48 +0000823};
824
scroggo@google.com5867c0f2012-06-07 17:39:48 +0000825static void usage(const char * argv0) {
826 SkDebugf("%s\n", argv0);
reed@google.come5f48b92012-06-22 15:27:39 +0000827 SkDebugf(" [--config ");
scroggo@google.com5867c0f2012-06-07 17:39:48 +0000828 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
829 if (i > 0) {
830 SkDebugf("|");
831 }
832 SkDebugf(gRec[i].fName);
833 }
epoger@google.com82cb65b2012-10-29 18:59:17 +0000834 SkDebugf("]:\n run these configurations\n");
835 SkDebugf(
836// Alphabetized ignoring "no" prefix ("readPath", "noreplay", "resourcePath").
837// It would probably be better if we allowed both yes-and-no settings for each
838// one, e.g.:
839// [--replay|--noreplay]: whether to exercise SkPicture replay; default is yes
840" [--nodeferred]: skip the deferred rendering test pass\n"
841" [--diffPath|-d <path>]: write difference images into this directory\n"
842" [--disable-missing-warning]: don't print a message to stderr if\n"
843" unable to read a reference image for any tests (NOT default behavior)\n"
844" [--enable-missing-warning]: print message to stderr (but don't fail) if\n"
845" unable to read a reference image for any tests (default behavior)\n"
846" [--forceBWtext]: disable text anti-aliasing\n"
847" [--help|-h]: show this help message\n"
848" [--hierarchy|--nohierarchy]: whether to use multilevel directory structure\n"
849" when reading/writing files; default is no\n"
850" [--match <substring>]: only run tests whose name includes this substring\n"
851" [--modulo <remainder> <divisor>]: only run tests for which \n"
852" testIndex %% divisor == remainder\n"
853" [--nopdf]: skip the pdf rendering test pass\n"
854" [--nopipe]: Skip SkGPipe replay\n"
855" [--readPath|-r <path>]: read reference images from this dir, and report\n"
856" any differences between those and the newly generated ones\n"
857" [--noreplay]: do not exercise SkPicture replay\n"
858" [--resourcePath|-i <path>]: directory that stores image resources\n"
859" [--noserialize]: do not exercise SkPicture serialization & deserialization\n"
860" [--notexturecache]: disable the gpu texture cache\n"
861" [--tiledPipe]: Exercise tiled SkGPipe replay\n"
862" [--writePath|-w <path>]: write rendered images into this directory\n"
863" [--writePicturePath|-wp <path>]: write .skp files into this directory\n"
scroggo@google.com5867c0f2012-06-07 17:39:48 +0000864 );
scroggo@google.com5867c0f2012-06-07 17:39:48 +0000865}
866
867static int findConfig(const char config[]) {
868 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
869 if (!strcmp(config, gRec[i].fName)) {
870 return i;
871 }
872 }
873 return -1;
874}
875
reed@google.comb2a51622011-10-31 16:30:04 +0000876static bool skip_name(const SkTDArray<const char*> array, const char name[]) {
877 if (0 == array.count()) {
878 // no names, so don't skip anything
879 return false;
880 }
881 for (int i = 0; i < array.count(); ++i) {
882 if (strstr(name, array[i])) {
883 // found the name, so don't skip
884 return false;
885 }
886 }
887 return true;
888}
889
bsalomon@google.comd9f826c2011-07-18 15:25:04 +0000890namespace skiagm {
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000891#if SK_SUPPORT_GPU
bsalomon@google.com7361f542012-04-19 19:15:35 +0000892SkAutoTUnref<GrContext> gGrContext;
893/**
bsalomon@google.comc7a24d22012-11-01 18:03:48 +0000894 * Sets the global GrContext, accessible by individual GMs
bsalomon@google.com7361f542012-04-19 19:15:35 +0000895 */
caryclark@google.com13130862012-06-06 12:10:45 +0000896static void SetGr(GrContext* grContext) {
bsalomon@google.com7361f542012-04-19 19:15:35 +0000897 SkSafeRef(grContext);
898 gGrContext.reset(grContext);
bsalomon@google.comd9f826c2011-07-18 15:25:04 +0000899}
bsalomon@google.com7361f542012-04-19 19:15:35 +0000900
901/**
902 * Gets the global GrContext, can be called by GM tests.
903 */
caryclark@google.com13130862012-06-06 12:10:45 +0000904GrContext* GetGr();
bsalomon@google.com7361f542012-04-19 19:15:35 +0000905GrContext* GetGr() {
906 return gGrContext.get();
907}
908
909/**
910 * Sets the global GrContext and then resets it to its previous value at
911 * destruction.
912 */
913class AutoResetGr : SkNoncopyable {
914public:
915 AutoResetGr() : fOld(NULL) {}
916 void set(GrContext* context) {
917 SkASSERT(NULL == fOld);
918 fOld = GetGr();
919 SkSafeRef(fOld);
920 SetGr(context);
921 }
922 ~AutoResetGr() { SetGr(fOld); SkSafeUnref(fOld); }
923private:
924 GrContext* fOld;
925};
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000926#else
927GrContext* GetGr() { return NULL; }
928#endif
bsalomon@google.comd9f826c2011-07-18 15:25:04 +0000929}
930
caryclark@google.com5987f582012-10-02 18:33:14 +0000931int tool_main(int argc, char** argv);
932int tool_main(int argc, char** argv) {
robertphillips@google.comb74af872012-06-27 19:41:42 +0000933
934#ifdef SK_ENABLE_INST_COUNT
935 gPrintInstCount = true;
936#endif
937
robertphillips@google.com977b9c82012-06-05 19:35:09 +0000938 SkGraphics::Init();
reed@google.com8923c6c2011-11-08 14:59:38 +0000939 // we don't need to see this during a run
940 gSkSuppressFontCachePurgeSpew = true;
reed@google.comd4dfd102011-01-18 21:05:42 +0000941
epoger@google.com7bc13a62012-02-14 14:53:59 +0000942 setSystemPreferences();
epoger@google.comde961632012-10-26 18:56:36 +0000943 GMMain gmmain;
epoger@google.com7bc13a62012-02-14 14:53:59 +0000944
reed@android.com8015dd82009-06-21 00:49:18 +0000945 const char* writePath = NULL; // if non-null, where we write the originals
mike@reedtribe.org5d0c62f2012-06-02 14:50:13 +0000946 const char* writePicturePath = NULL; // if non-null, where we write serialized pictures
reed@android.com8015dd82009-06-21 00:49:18 +0000947 const char* readPath = NULL; // if non-null, were we read from to compare
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000948 const char* diffPath = NULL; // if non-null, where we write our diffs (from compare)
robertphillips@google.com8570b5c2012-03-20 17:40:58 +0000949 const char* resourcePath = NULL;// if non-null, where we read from for image resources
reed@android.com8015dd82009-06-21 00:49:18 +0000950
reed@google.comb2a51622011-10-31 16:30:04 +0000951 SkTDArray<const char*> fMatches;
twiz@google.come24a0792012-01-31 18:35:30 +0000952
reed@google.comab973972011-09-19 19:01:38 +0000953 bool doPDF = true;
reed@google.comb8b09832011-05-26 15:57:56 +0000954 bool doReplay = true;
scroggo@google.com565254b2012-06-28 15:41:32 +0000955 bool doPipe = true;
scroggo@google.com72c96722012-06-06 21:07:10 +0000956 bool doTiledPipe = false;
scroggo@google.com39362522012-09-14 17:37:46 +0000957 bool doSerialize = true;
junov@google.com4370aed2012-01-18 16:21:08 +0000958 bool doDeferred = true;
twiz@google.come24a0792012-01-31 18:35:30 +0000959 bool disableTextureCache = false;
scroggo@google.com5867c0f2012-06-07 17:39:48 +0000960 SkTDArray<size_t> configs;
961 bool userConfig = false;
twiz@google.come24a0792012-01-31 18:35:30 +0000962
epoger@google.com82cb65b2012-10-29 18:59:17 +0000963 int moduloRemainder = -1;
964 int moduloDivisor = -1;
reed@google.comae7b8f32012-10-18 21:30:57 +0000965
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000966 const char* const commandName = argv[0];
reed@android.com8015dd82009-06-21 00:49:18 +0000967 char* const* stop = argv + argc;
968 for (++argv; argv < stop; ++argv) {
epoger@google.com82cb65b2012-10-29 18:59:17 +0000969 if (strcmp(*argv, "--config") == 0) {
scroggo@google.com5867c0f2012-06-07 17:39:48 +0000970 argv++;
971 if (argv < stop) {
972 int index = findConfig(*argv);
973 if (index >= 0) {
974 *configs.append() = index;
975 userConfig = true;
976 } else {
977 SkString str;
978 str.printf("unrecognized config %s\n", *argv);
979 SkDebugf(str.c_str());
980 usage(commandName);
981 return -1;
982 }
983 } else {
reed@google.come5f48b92012-06-22 15:27:39 +0000984 SkDebugf("missing arg for --config\n");
scroggo@google.com5867c0f2012-06-07 17:39:48 +0000985 usage(commandName);
986 return -1;
987 }
epoger@google.com82cb65b2012-10-29 18:59:17 +0000988 } else if (strcmp(*argv, "--nodeferred") == 0) {
989 doDeferred = false;
990 } else if ((0 == strcmp(*argv, "--diffPath")) ||
991 (0 == strcmp(*argv, "-d"))) {
992 argv++;
993 if (argv < stop && **argv) {
994 diffPath = *argv;
995 }
996 } else if (strcmp(*argv, "--disable-missing-warning") == 0) {
997 gmmain.fNotifyMissingReadReference = false;
998 } else if (strcmp(*argv, "--enable-missing-warning") == 0) {
999 gmmain.fNotifyMissingReadReference = true;
1000 } else if (strcmp(*argv, "--forceBWtext") == 0) {
1001 gForceBWtext = true;
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001002 } else if (strcmp(*argv, "--help") == 0 || strcmp(*argv, "-h") == 0) {
1003 usage(commandName);
1004 return -1;
epoger@google.com82cb65b2012-10-29 18:59:17 +00001005 } else if (strcmp(*argv, "--hierarchy") == 0) {
1006 gmmain.fUseFileHierarchy = true;
1007 } else if (strcmp(*argv, "--nohierarchy") == 0) {
1008 gmmain.fUseFileHierarchy = false;
1009 } else if (strcmp(*argv, "--match") == 0) {
1010 ++argv;
1011 if (argv < stop && **argv) {
1012 // just record the ptr, no need for a deep copy
1013 *fMatches.append() = *argv;
1014 }
1015 } else if (strcmp(*argv, "--modulo") == 0) {
1016 ++argv;
1017 if (argv >= stop) {
1018 continue;
1019 }
1020 moduloRemainder = atoi(*argv);
1021
1022 ++argv;
1023 if (argv >= stop) {
1024 continue;
1025 }
1026 moduloDivisor = atoi(*argv);
bsalomon@google.comc7a24d22012-11-01 18:03:48 +00001027 if (moduloRemainder < 0 || moduloDivisor <= 0 || moduloRemainder >= moduloDivisor) {
1028 SkDebugf("invalid modulo values.");
1029 return -1;
1030 }
epoger@google.com82cb65b2012-10-29 18:59:17 +00001031 } else if (strcmp(*argv, "--nopdf") == 0) {
1032 doPDF = false;
1033 } else if (strcmp(*argv, "--nopipe") == 0) {
1034 doPipe = false;
1035 } else if ((0 == strcmp(*argv, "--readPath")) ||
1036 (0 == strcmp(*argv, "-r"))) {
1037 argv++;
1038 if (argv < stop && **argv) {
1039 readPath = *argv;
1040 }
1041 } else if (strcmp(*argv, "--noreplay") == 0) {
1042 doReplay = false;
1043 } else if ((0 == strcmp(*argv, "--resourcePath")) ||
1044 (0 == strcmp(*argv, "-i"))) {
1045 argv++;
1046 if (argv < stop && **argv) {
1047 resourcePath = *argv;
1048 }
1049 } else if (strcmp(*argv, "--serialize") == 0) {
1050 doSerialize = true;
1051 } else if (strcmp(*argv, "--noserialize") == 0) {
1052 doSerialize = false;
1053 } else if (strcmp(*argv, "--notexturecache") == 0) {
1054 disableTextureCache = true;
1055 } else if (strcmp(*argv, "--tiledPipe") == 0) {
1056 doTiledPipe = true;
1057 } else if ((0 == strcmp(*argv, "--writePath")) ||
1058 (0 == strcmp(*argv, "-w"))) {
1059 argv++;
1060 if (argv < stop && **argv) {
1061 writePath = *argv;
1062 }
1063 } else if ((0 == strcmp(*argv, "--writePicturePath")) ||
1064 (0 == strcmp(*argv, "-wp"))) {
1065 argv++;
1066 if (argv < stop && **argv) {
1067 writePicturePath = *argv;
1068 }
tomhudson@google.com9875dd12011-04-25 15:49:53 +00001069 } else {
robertphillips@google.com8570b5c2012-03-20 17:40:58 +00001070 usage(commandName);
1071 return -1;
tomhudson@google.com9875dd12011-04-25 15:49:53 +00001072 }
1073 }
1074 if (argv != stop) {
robertphillips@google.com8570b5c2012-03-20 17:40:58 +00001075 usage(commandName);
1076 return -1;
tomhudson@google.com9875dd12011-04-25 15:49:53 +00001077 }
reed@google.com873cb1e2010-12-23 15:00:45 +00001078
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001079 if (!userConfig) {
1080 // if no config is specified by user, we add them all.
1081 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
1082 *configs.append() = i;
1083 }
1084 }
1085
robertphillips@google.com8570b5c2012-03-20 17:40:58 +00001086 GM::SetResourcePath(resourcePath);
1087
reed@android.com00f883e2010-12-14 17:46:14 +00001088 if (readPath) {
1089 fprintf(stderr, "reading from %s\n", readPath);
chudy@google.comf32f6e82012-07-12 15:42:37 +00001090 }
epoger@google.com9284ccd2012-04-18 13:36:54 +00001091 if (writePath) {
reed@android.com00f883e2010-12-14 17:46:14 +00001092 fprintf(stderr, "writing to %s\n", writePath);
1093 }
mike@reedtribe.org5d0c62f2012-06-02 14:50:13 +00001094 if (writePicturePath) {
1095 fprintf(stderr, "writing pictures to %s\n", writePicturePath);
1096 }
robertphillips@google.com8570b5c2012-03-20 17:40:58 +00001097 if (resourcePath) {
1098 fprintf(stderr, "reading resources from %s\n", resourcePath);
1099 }
1100
epoger@google.com82cb65b2012-10-29 18:59:17 +00001101 if (moduloDivisor <= 0) {
1102 moduloRemainder = -1;
reed@google.comae7b8f32012-10-18 21:30:57 +00001103 }
epoger@google.com82cb65b2012-10-29 18:59:17 +00001104 if (moduloRemainder < 0 || moduloRemainder >= moduloDivisor) {
1105 moduloRemainder = -1;
reed@google.comae7b8f32012-10-18 21:30:57 +00001106 }
1107
epoger@google.comc7cf2b32011-12-28 19:31:01 +00001108 // Accumulate success of all tests.
1109 int testsRun = 0;
1110 int testsPassed = 0;
1111 int testsFailed = 0;
1112 int testsMissingReferenceImages = 0;
1113
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001114#if SK_SUPPORT_GPU
1115 GrContextFactory* grFactory = new GrContextFactory;
twiz@google.come24a0792012-01-31 18:35:30 +00001116 if (disableTextureCache) {
1117 skiagm::GetGr()->setTextureCacheLimits(0, 0);
1118 }
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001119#endif
twiz@google.come24a0792012-01-31 18:35:30 +00001120
reed@google.comae7b8f32012-10-18 21:30:57 +00001121 int gmIndex = -1;
1122 SkString moduloStr;
1123
epoger@google.come8ebeb12012-10-29 16:42:11 +00001124 // If we will be writing out files, prepare subdirectories.
1125 if (writePath) {
1126 if (!sk_mkdir(writePath)) {
1127 return -1;
1128 }
1129 if (gmmain.fUseFileHierarchy) {
1130 for (int i = 0; i < configs.count(); i++) {
1131 ConfigData config = gRec[configs[i]];
1132 SkString subdir;
1133 subdir.appendf("%s%c%s", writePath, SkPATH_SEPARATOR,
1134 config.fName);
1135 if (!sk_mkdir(subdir.c_str())) {
1136 return -1;
1137 }
1138 }
1139 }
1140 }
1141
bsalomon@google.com7361f542012-04-19 19:15:35 +00001142 Iter iter;
1143 GM* gm;
reed@android.com00dae862009-06-10 15:38:48 +00001144 while ((gm = iter.next()) != NULL) {
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +00001145
reed@google.comae7b8f32012-10-18 21:30:57 +00001146 ++gmIndex;
epoger@google.com82cb65b2012-10-29 18:59:17 +00001147 if (moduloRemainder >= 0) {
1148 if ((gmIndex % moduloDivisor) != moduloRemainder) {
reed@google.comae7b8f32012-10-18 21:30:57 +00001149 continue;
1150 }
epoger@google.com82cb65b2012-10-29 18:59:17 +00001151 moduloStr.printf("[%d.%d] ", gmIndex, moduloDivisor);
reed@google.comae7b8f32012-10-18 21:30:57 +00001152 }
1153
reed@google.comece2b022011-07-25 14:28:57 +00001154 const char* shortName = gm->shortName();
reed@google.comb2a51622011-10-31 16:30:04 +00001155 if (skip_name(fMatches, shortName)) {
reed@google.comece2b022011-07-25 14:28:57 +00001156 SkDELETE(gm);
1157 continue;
1158 }
1159
tomhudson@google.com9875dd12011-04-25 15:49:53 +00001160 SkISize size = gm->getISize();
reed@google.comae7b8f32012-10-18 21:30:57 +00001161 SkDebugf("%sdrawing... %s [%d %d]\n", moduloStr.c_str(), shortName,
reed@android.com8015dd82009-06-21 00:49:18 +00001162 size.width(), size.height());
djsollen@google.comebce16d2012-10-26 14:07:13 +00001163
1164 ErrorBitfield testErrors = ERROR_NONE;
1165 uint32_t gmFlags = gm->getFlags();
reed@android.com8015dd82009-06-21 00:49:18 +00001166
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001167 for (int i = 0; i < configs.count(); i++) {
1168 ConfigData config = gRec[configs[i]];
epoger@google.come8ebeb12012-10-29 16:42:11 +00001169
epoger@google.comc7cf2b32011-12-28 19:31:01 +00001170 // Skip any tests that we don't even need to try.
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001171 if ((kPDF_Backend == config.fBackend) &&
bungeman@google.com64e011a2011-09-19 19:31:04 +00001172 (!doPDF || (gmFlags & GM::kSkipPDF_Flag)))
epoger@google.comde961632012-10-26 18:56:36 +00001173 {
1174 continue;
1175 }
reed@google.com1b6c73d2012-10-10 15:17:24 +00001176 if ((gmFlags & GM::kSkip565_Flag) &&
1177 (kRaster_Backend == config.fBackend) &&
1178 (SkBitmap::kRGB_565_Config == config.fConfig)) {
1179 continue;
1180 }
reed@google.comab973972011-09-19 19:01:38 +00001181
epoger@google.comc7cf2b32011-12-28 19:31:01 +00001182 // Now we know that we want to run this test and record its
1183 // success or failure.
djsollen@google.comebce16d2012-10-26 14:07:13 +00001184 ErrorBitfield renderErrors = ERROR_NONE;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001185 GrRenderTarget* renderTarget = NULL;
1186#if SK_SUPPORT_GPU
1187 SkAutoTUnref<GrRenderTarget> rt;
1188 AutoResetGr autogr;
djsollen@google.comebce16d2012-10-26 14:07:13 +00001189 if ((ERROR_NONE == renderErrors) &&
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001190 kGPU_Backend == config.fBackend) {
1191 GrContext* gr = grFactory->get(config.fGLContextType);
1192 bool grSuccess = false;
1193 if (gr) {
1194 // create a render target to back the device
1195 GrTextureDesc desc;
1196 desc.fConfig = kSkia8888_PM_GrPixelConfig;
1197 desc.fFlags = kRenderTarget_GrTextureFlagBit;
1198 desc.fWidth = gm->getISize().width();
1199 desc.fHeight = gm->getISize().height();
1200 desc.fSampleCnt = config.fSampleCnt;
1201 GrTexture* tex = gr->createUncachedTexture(desc, NULL, 0);
1202 if (tex) {
1203 rt.reset(tex->asRenderTarget());
1204 rt.get()->ref();
1205 tex->unref();
1206 autogr.set(gr);
1207 renderTarget = rt.get();
1208 grSuccess = NULL != renderTarget;
1209 }
1210 }
1211 if (!grSuccess) {
djsollen@google.comebce16d2012-10-26 14:07:13 +00001212 renderErrors |= ERROR_NO_GPU_CONTEXT;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001213 }
tomhudson@google.com73fb0422011-04-25 19:20:54 +00001214 }
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001215#endif
vandebo@chromium.org686abdf2011-02-03 23:00:40 +00001216
djsollen@google.comebce16d2012-10-26 14:07:13 +00001217 SkBitmap comparisonBitmap;
1218
1219 if (ERROR_NONE == renderErrors) {
epoger@google.comde961632012-10-26 18:56:36 +00001220 renderErrors |= gmmain.test_drawing(gm, config, writePath,
1221 readPath, diffPath, GetGr(),
1222 renderTarget,
epoger@google.com57f7abc2012-11-13 03:41:55 +00001223 &comparisonBitmap);
epoger@google.comc7cf2b32011-12-28 19:31:01 +00001224 }
1225
djsollen@google.comebce16d2012-10-26 14:07:13 +00001226 if (doDeferred && !renderErrors &&
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001227 (kGPU_Backend == config.fBackend ||
1228 kRaster_Backend == config.fBackend)) {
epoger@google.comde961632012-10-26 18:56:36 +00001229 renderErrors |= gmmain.test_deferred_drawing(gm, config,
1230 comparisonBitmap,
1231 diffPath, GetGr(),
1232 renderTarget);
junov@google.com4370aed2012-01-18 16:21:08 +00001233 }
1234
djsollen@google.comebce16d2012-10-26 14:07:13 +00001235 testErrors |= renderErrors;
tomhudson@google.com9875dd12011-04-25 15:49:53 +00001236 }
djsollen@google.comebce16d2012-10-26 14:07:13 +00001237
1238 SkBitmap comparisonBitmap;
1239 const ConfigData compareConfig =
1240 { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "comparison" };
epoger@google.comde961632012-10-26 18:56:36 +00001241 testErrors |= gmmain.generate_image(gm, compareConfig, NULL, NULL, &comparisonBitmap, false);
djsollen@google.comebce16d2012-10-26 14:07:13 +00001242
1243 // run the picture centric GM steps
1244 if (!(gmFlags & GM::kSkipPicture_Flag)) {
1245
1246 ErrorBitfield pictErrors = ERROR_NONE;
1247
1248 //SkAutoTUnref<SkPicture> pict(generate_new_picture(gm));
epoger@google.comde961632012-10-26 18:56:36 +00001249 SkPicture* pict = gmmain.generate_new_picture(gm);
djsollen@google.comebce16d2012-10-26 14:07:13 +00001250 SkAutoUnref aur(pict);
1251
1252 if ((ERROR_NONE == testErrors) && doReplay) {
1253 SkBitmap bitmap;
epoger@google.comde961632012-10-26 18:56:36 +00001254 gmmain.generate_image_from_picture(gm, compareConfig, pict,
1255 &bitmap);
1256 pictErrors |= gmmain.handle_test_results(gm, compareConfig,
1257 NULL, NULL, diffPath,
1258 "-replay", bitmap,
1259 NULL,
epoger@google.com57f7abc2012-11-13 03:41:55 +00001260 &comparisonBitmap);
djsollen@google.comebce16d2012-10-26 14:07:13 +00001261 }
1262
epoger@google.comde961632012-10-26 18:56:36 +00001263 if ((ERROR_NONE == testErrors) &&
1264 (ERROR_NONE == pictErrors) &&
1265 doSerialize) {
1266 SkPicture* repict = gmmain.stream_to_new_picture(*pict);
djsollen@google.comebce16d2012-10-26 14:07:13 +00001267 SkAutoUnref aurr(repict);
1268
1269 SkBitmap bitmap;
epoger@google.comde961632012-10-26 18:56:36 +00001270 gmmain.generate_image_from_picture(gm, compareConfig, repict,
1271 &bitmap);
1272 pictErrors |= gmmain.handle_test_results(gm, compareConfig,
1273 NULL, NULL, diffPath,
1274 "-serialize", bitmap,
1275 NULL,
epoger@google.com57f7abc2012-11-13 03:41:55 +00001276 &comparisonBitmap);
djsollen@google.comebce16d2012-10-26 14:07:13 +00001277 }
1278
1279 if (writePicturePath) {
1280 const char* pictureSuffix = "skp";
epoger@google.comde961632012-10-26 18:56:36 +00001281 SkString path = gmmain.make_filename(writePicturePath, "",
1282 SkString(gm->shortName()),
1283 pictureSuffix);
djsollen@google.comebce16d2012-10-26 14:07:13 +00001284 SkFILEWStream stream(path.c_str());
1285 pict->serialize(&stream);
1286 }
1287
1288 testErrors |= pictErrors;
1289 }
1290
1291 // run the pipe centric GM steps
1292 if (!(gmFlags & GM::kSkipPipe_Flag)) {
1293
1294 ErrorBitfield pipeErrors = ERROR_NONE;
1295
1296 if ((ERROR_NONE == testErrors) && doPipe) {
epoger@google.comde961632012-10-26 18:56:36 +00001297 pipeErrors |= gmmain.test_pipe_playback(gm, compareConfig,
1298 comparisonBitmap,
1299 readPath, diffPath);
djsollen@google.comebce16d2012-10-26 14:07:13 +00001300 }
1301
1302 if ((ERROR_NONE == testErrors) &&
1303 (ERROR_NONE == pipeErrors) &&
1304 doTiledPipe && !(gmFlags & GM::kSkipTiled_Flag)) {
epoger@google.comde961632012-10-26 18:56:36 +00001305 pipeErrors |= gmmain.test_tiled_pipe_playback(gm, compareConfig,
1306 comparisonBitmap,
1307 readPath,
1308 diffPath);
djsollen@google.comebce16d2012-10-26 14:07:13 +00001309 }
1310
1311 testErrors |= pipeErrors;
1312 }
1313
1314 // Update overall results.
1315 // We only tabulate the particular error types that we currently
1316 // care about (e.g., missing reference images). Later on, if we
1317 // want to also tabulate pixel mismatches vs dimension mistmatches
1318 // (or whatever else), we can do so.
1319 testsRun++;
1320 if (ERROR_NONE == testErrors) {
1321 testsPassed++;
1322 } else if (ERROR_READING_REFERENCE_IMAGE & testErrors) {
1323 testsMissingReferenceImages++;
1324 } else {
1325 testsFailed++;
1326 }
1327
reed@android.com00dae862009-06-10 15:38:48 +00001328 SkDELETE(gm);
1329 }
robertphillips@google.coma2f80082012-08-02 16:22:47 +00001330 SkDebugf("Ran %d tests: %d passed, %d failed, %d missing reference images\n",
1331 testsRun, testsPassed, testsFailed, testsMissingReferenceImages);
epoger@google.com57f7abc2012-11-13 03:41:55 +00001332 gmmain.ListErrors();
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00001333
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001334#if SK_SUPPORT_GPU
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00001335
robertphillips@google.com59552022012-08-31 13:07:37 +00001336#if GR_CACHE_STATS
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00001337 for (int i = 0; i < configs.count(); i++) {
1338 ConfigData config = gRec[configs[i]];
1339
1340 if (kGPU_Backend == config.fBackend) {
1341 GrContext* gr = grFactory->get(config.fGLContextType);
1342
1343 SkDebugf("config: %s %x\n", config.fName, gr);
1344 gr->printCacheStats();
1345 }
1346 }
1347#endif
1348
robertphillips@google.com977b9c82012-06-05 19:35:09 +00001349 delete grFactory;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001350#endif
robertphillips@google.com977b9c82012-06-05 19:35:09 +00001351 SkGraphics::Term();
1352
epoger@google.comc7cf2b32011-12-28 19:31:01 +00001353 return (0 == testsFailed) ? 0 : -1;
reed@android.com00dae862009-06-10 15:38:48 +00001354}
caryclark@google.com5987f582012-10-02 18:33:14 +00001355
borenet@google.com7158e6a2012-11-01 17:43:44 +00001356#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
caryclark@google.com5987f582012-10-02 18:33:14 +00001357int main(int argc, char * const argv[]) {
1358 return tool_main(argc, (char**) argv);
1359}
1360#endif