blob: b2313f6d400ad78f9ca25c981f0a51fd1a5f9135 [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.com37269602013-01-19 04:21:27 +000017#include "gm_expectations.h"
epoger@google.com7bc13a62012-02-14 14:53:59 +000018#include "system_preferences.h"
epoger@google.com5f6a0072013-01-31 16:30:55 +000019#include "SkBitmap.h"
epoger@google.comee8a8e32012-12-18 19:13:49 +000020#include "SkBitmapChecksummer.h"
reed@android.comb9b9a182009-07-08 02:54:47 +000021#include "SkColorPriv.h"
reed@google.com8a85d0c2011-06-24 19:12:12 +000022#include "SkData.h"
junov@google.com4370aed2012-01-18 16:21:08 +000023#include "SkDeferredCanvas.h"
bsalomon@google.com971d0c82011-08-19 17:22:05 +000024#include "SkDevice.h"
epoger@google.comde961632012-10-26 18:56:36 +000025#include "SkDrawFilter.h"
scroggo@google.com09fd4d22013-03-20 14:20:18 +000026#include "SkFlags.h"
scroggo@google.com5af9b202012-06-04 17:17:36 +000027#include "SkGPipe.h"
reed@android.com8015dd82009-06-21 00:49:18 +000028#include "SkGraphics.h"
29#include "SkImageDecoder.h"
30#include "SkImageEncoder.h"
epoger@google.come8ebeb12012-10-29 16:42:11 +000031#include "SkOSFile.h"
tomhudson@google.com9875dd12011-04-25 15:49:53 +000032#include "SkPicture.h"
robertphillips@google.com977b9c82012-06-05 19:35:09 +000033#include "SkRefCnt.h"
scroggo@google.com72c96722012-06-06 21:07:10 +000034#include "SkStream.h"
bsalomon@google.com2a48c3a2012-08-03 14:54:45 +000035#include "SkTArray.h"
junov@chromium.org3cb834b2012-12-13 16:39:53 +000036#include "SkTileGridPicture.h"
scroggo@google.com72c96722012-06-06 21:07:10 +000037#include "SamplePipeControllers.h"
reed@google.com07700442010-12-20 19:46:07 +000038
bsalomon@google.com50c79d82013-01-08 20:31:53 +000039#ifdef SK_BUILD_FOR_WIN
40 // json includes xlocale which generates warning 4530 because we're compiling without
epoger@google.com37269602013-01-19 04:21:27 +000041 // exceptions; see https://code.google.com/p/skia/issues/detail?id=1067
bsalomon@google.com50c79d82013-01-08 20:31:53 +000042 #pragma warning(push)
43 #pragma warning(disable : 4530)
44#endif
epoger@google.comee8a8e32012-12-18 19:13:49 +000045#include "json/value.h"
bsalomon@google.com50c79d82013-01-08 20:31:53 +000046#ifdef SK_BUILD_FOR_WIN
47 #pragma warning(pop)
48#endif
epoger@google.comee8a8e32012-12-18 19:13:49 +000049
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000050#if SK_SUPPORT_GPU
51#include "GrContextFactory.h"
52#include "GrRenderTarget.h"
53#include "SkGpuDevice.h"
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000054typedef GrContextFactory::GLContextType GLContextType;
55#else
56class GrContext;
57class GrRenderTarget;
58typedef int GLContextType;
59#endif
60
reed@google.com8923c6c2011-11-08 14:59:38 +000061extern bool gSkSuppressFontCachePurgeSpew;
62
reed@google.com07700442010-12-20 19:46:07 +000063#ifdef SK_SUPPORT_PDF
tomhudson@google.com9875dd12011-04-25 15:49:53 +000064 #include "SkPDFDevice.h"
65 #include "SkPDFDocument.h"
reed@google.com07700442010-12-20 19:46:07 +000066#endif
reed@android.com00dae862009-06-10 15:38:48 +000067
epoger@google.come3cc2eb2012-01-18 20:11:13 +000068// Until we resolve http://code.google.com/p/skia/issues/detail?id=455 ,
69// stop writing out XPS-format image baselines in gm.
70#undef SK_SUPPORT_XPS
bungeman@google.comb29c8832011-10-10 13:19:10 +000071#ifdef SK_SUPPORT_XPS
72 #include "SkXPSDevice.h"
73#endif
74
reed@google.com46cce912011-06-29 12:54:46 +000075#ifdef SK_BUILD_FOR_MAC
76 #include "SkCGUtils.h"
bsalomon@google.com0a09eef2011-06-29 19:42:58 +000077 #define CAN_IMAGE_PDF 1
reed@google.com46cce912011-06-29 12:54:46 +000078#else
bsalomon@google.com0a09eef2011-06-29 19:42:58 +000079 #define CAN_IMAGE_PDF 0
reed@google.com46cce912011-06-29 12:54:46 +000080#endif
81
epoger@google.comc7cf2b32011-12-28 19:31:01 +000082typedef int ErrorBitfield;
epoger@google.comeb066362013-03-08 09:39:36 +000083// an empty bitfield means no errors:
84const static ErrorBitfield kEmptyErrorBitfield = 0x00;
85// individual error types:
86const static ErrorBitfield kNoGpuContext_ErrorBitmask = 0x01;
87const static ErrorBitfield kImageMismatch_ErrorBitmask = 0x02;
88const static ErrorBitfield kMissingExpectations_ErrorBitmask = 0x04;
89const static ErrorBitfield kWritingReferenceImage_ErrorBitmask = 0x08;
90// we typically ignore any errors matching this bitmask:
91const static ErrorBitfield kIgnorable_ErrorBitmask = kMissingExpectations_ErrorBitmask;
epoger@google.comc7cf2b32011-12-28 19:31:01 +000092
reed@android.com00dae862009-06-10 15:38:48 +000093using namespace skiagm;
94
epoger@google.com57f7abc2012-11-13 03:41:55 +000095struct FailRec {
96 SkString fName;
epoger@google.com15655b22013-01-08 18:47:31 +000097 bool fIsPixelError;
epoger@google.com57f7abc2012-11-13 03:41:55 +000098
epoger@google.com15655b22013-01-08 18:47:31 +000099 FailRec() : fIsPixelError(false) {}
100 FailRec(const SkString& name) : fName(name), fIsPixelError(false) {}
epoger@google.com57f7abc2012-11-13 03:41:55 +0000101};
102
reed@android.com00dae862009-06-10 15:38:48 +0000103class Iter {
104public:
105 Iter() {
bsalomon@google.com39149582011-06-13 21:55:32 +0000106 this->reset();
107 }
108
109 void reset() {
reed@android.comdd0ac282009-06-20 02:38:16 +0000110 fReg = GMRegistry::Head();
reed@android.com00dae862009-06-10 15:38:48 +0000111 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000112
reed@android.comdd0ac282009-06-20 02:38:16 +0000113 GM* next() {
reed@android.com00dae862009-06-10 15:38:48 +0000114 if (fReg) {
reed@android.comdd0ac282009-06-20 02:38:16 +0000115 GMRegistry::Factory fact = fReg->factory();
reed@android.com00dae862009-06-10 15:38:48 +0000116 fReg = fReg->next();
reed@android.comdd0ac282009-06-20 02:38:16 +0000117 return fact(0);
reed@android.com00dae862009-06-10 15:38:48 +0000118 }
119 return NULL;
120 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000121
reed@android.com00dae862009-06-10 15:38:48 +0000122 static int Count() {
reed@android.comdd0ac282009-06-20 02:38:16 +0000123 const GMRegistry* reg = GMRegistry::Head();
reed@android.com00dae862009-06-10 15:38:48 +0000124 int count = 0;
125 while (reg) {
126 count += 1;
127 reg = reg->next();
128 }
129 return count;
130 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000131
reed@android.com00dae862009-06-10 15:38:48 +0000132private:
133 const GMRegistry* fReg;
134};
135
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000136enum Backend {
junov@chromium.org3cb834b2012-12-13 16:39:53 +0000137 kRaster_Backend,
138 kGPU_Backend,
139 kPDF_Backend,
140 kXPS_Backend,
141};
142
143enum BbhType {
144 kNone_BbhType,
145 kRTree_BbhType,
146 kTileGrid_BbhType,
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000147};
148
bsalomon@google.com7361f542012-04-19 19:15:35 +0000149enum ConfigFlags {
150 kNone_ConfigFlag = 0x0,
151 /* Write GM images if a write path is provided. */
152 kWrite_ConfigFlag = 0x1,
epoger@google.comf28dd8a2012-10-25 16:27:34 +0000153 /* Read reference GM images if a read path is provided. */
bsalomon@google.com7361f542012-04-19 19:15:35 +0000154 kRead_ConfigFlag = 0x2,
155 kRW_ConfigFlag = (kWrite_ConfigFlag | kRead_ConfigFlag),
156};
157
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000158struct ConfigData {
bsalomon@google.com7361f542012-04-19 19:15:35 +0000159 SkBitmap::Config fConfig;
160 Backend fBackend;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000161 GLContextType fGLContextType; // GPU backend only
bsalomon@google.com7361f542012-04-19 19:15:35 +0000162 int fSampleCnt; // GPU backend only
163 ConfigFlags fFlags;
164 const char* fName;
bsalomon@google.com4c75f242013-03-19 18:58:43 +0000165 bool fRunByDefault;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000166};
167
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000168class BWTextDrawFilter : public SkDrawFilter {
169public:
reed@google.com971aca72012-11-26 20:26:54 +0000170 virtual bool filter(SkPaint*, Type) SK_OVERRIDE;
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000171};
reed@google.com971aca72012-11-26 20:26:54 +0000172bool BWTextDrawFilter::filter(SkPaint* p, Type t) {
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000173 if (kText_Type == t) {
174 p->setAntiAlias(false);
175 }
reed@google.com971aca72012-11-26 20:26:54 +0000176 return true;
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000177}
178
scroggo@google.com565254b2012-06-28 15:41:32 +0000179struct PipeFlagComboData {
180 const char* name;
181 uint32_t flags;
182};
183
184static PipeFlagComboData gPipeWritingFlagCombos[] = {
185 { "", 0 },
186 { " cross-process", SkGPipeWriter::kCrossProcess_Flag },
scroggob3c0f482012-07-02 19:07:57 +0000187 { " cross-process, shared address", SkGPipeWriter::kCrossProcess_Flag
scroggo@google.com15011ee2012-07-26 20:03:32 +0000188 | SkGPipeWriter::kSharedAddressSpace_Flag }
scroggo@google.com565254b2012-06-28 15:41:32 +0000189};
190
epoger@google.comde961632012-10-26 18:56:36 +0000191class GMMain {
192public:
epoger@google.come8ebeb12012-10-29 16:42:11 +0000193 GMMain() {
194 // Set default values of member variables, which tool_main()
195 // may override.
epoger@google.come8ebeb12012-10-29 16:42:11 +0000196 fUseFileHierarchy = false;
junov@chromium.org95146eb2013-01-11 21:04:40 +0000197 fMismatchPath = NULL;
epoger@google.come8ebeb12012-10-29 16:42:11 +0000198 }
199
200 SkString make_name(const char shortName[], const char configName[]) {
201 SkString name;
epoger@google.com57f7abc2012-11-13 03:41:55 +0000202 if (0 == strlen(configName)) {
203 name.append(shortName);
204 } else if (fUseFileHierarchy) {
epoger@google.come8ebeb12012-10-29 16:42:11 +0000205 name.appendf("%s%c%s", configName, SkPATH_SEPARATOR, shortName);
206 } else {
207 name.appendf("%s_%s", shortName, configName);
208 }
epoger@google.comde961632012-10-26 18:56:36 +0000209 return name;
210 }
211
epoger@google.com5f6a0072013-01-31 16:30:55 +0000212 /* since PNG insists on unpremultiplying our alpha, we take no
213 precision chances and force all pixels to be 100% opaque,
214 otherwise on compare we may not get a perfect match.
215 */
216 static void force_all_opaque(const SkBitmap& bitmap) {
217 SkBitmap::Config config = bitmap.config();
218 switch (config) {
219 case SkBitmap::kARGB_8888_Config:
220 force_all_opaque_8888(bitmap);
221 break;
222 case SkBitmap::kRGB_565_Config:
223 // nothing to do here; 565 bitmaps are inherently opaque
224 break;
225 default:
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000226 gm_fprintf(stderr, "unsupported bitmap config %d\n", config);
227 DEBUGFAIL_SEE_STDERR;
epoger@google.com5f6a0072013-01-31 16:30:55 +0000228 }
229 }
230
231 static void force_all_opaque_8888(const SkBitmap& bitmap) {
232 SkAutoLockPixels lock(bitmap);
233 for (int y = 0; y < bitmap.height(); y++) {
234 for (int x = 0; x < bitmap.width(); x++) {
235 *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT);
236 }
237 }
238 }
239
240 static bool write_bitmap(const SkString& path, const SkBitmap& bitmap) {
241 // TODO(epoger): Now that we have removed force_all_opaque()
242 // from this method, we should be able to get rid of the
243 // transformation to 8888 format also.
244 SkBitmap copy;
245 bitmap.copyTo(&copy, SkBitmap::kARGB_8888_Config);
246 return SkImageEncoder::EncodeFile(path.c_str(), copy,
247 SkImageEncoder::kPNG_Type, 100);
248 }
249
250 // Records an error in fFailedTests, if we want to record errors
251 // of this type.
252 void RecordError(ErrorBitfield errorType, const SkString& name,
253 const char renderModeDescriptor []) {
epoger@google.comeb066362013-03-08 09:39:36 +0000254 // The common case: no error means nothing to record.
255 if (kEmptyErrorBitfield == errorType) {
epoger@google.com5f6a0072013-01-31 16:30:55 +0000256 return;
epoger@google.comeb066362013-03-08 09:39:36 +0000257 }
258
259 // If only certain error type(s) were reported, we know we can ignore them.
260 if (errorType == (errorType & kIgnorable_ErrorBitmask)) {
epoger@google.com5f6a0072013-01-31 16:30:55 +0000261 return;
epoger@google.com5f6a0072013-01-31 16:30:55 +0000262 }
263
264 FailRec& rec = fFailedTests.push_back(make_name(
265 name.c_str(), renderModeDescriptor));
epoger@google.comeb066362013-03-08 09:39:36 +0000266 rec.fIsPixelError =
267 (kEmptyErrorBitfield != (errorType & kImageMismatch_ErrorBitmask));
epoger@google.com5f6a0072013-01-31 16:30:55 +0000268 }
269
270 // List contents of fFailedTests via SkDebug.
271 void ListErrors() {
272 for (int i = 0; i < fFailedTests.count(); ++i) {
273 if (fFailedTests[i].fIsPixelError) {
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000274 gm_fprintf(stderr, "\t\t%s pixel_error\n", fFailedTests[i].fName.c_str());
epoger@google.com5f6a0072013-01-31 16:30:55 +0000275 } else {
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000276 gm_fprintf(stderr, "\t\t%s\n", fFailedTests[i].fName.c_str());
epoger@google.com5f6a0072013-01-31 16:30:55 +0000277 }
278 }
279 }
280
281 static bool write_document(const SkString& path,
282 const SkDynamicMemoryWStream& document) {
283 SkFILEWStream stream(path.c_str());
284 SkAutoDataUnref data(document.copyToData());
285 return stream.writeData(data.get());
286 }
287
epoger@google.com37269602013-01-19 04:21:27 +0000288 /**
epoger@google.com5f6a0072013-01-31 16:30:55 +0000289 * Prepare an SkBitmap to render a GM into.
290 *
291 * After you've rendered the GM into the SkBitmap, you must call
292 * complete_bitmap()!
293 *
294 * @todo thudson 22 April 2011 - could refactor this to take in
295 * a factory to generate the context, always call readPixels()
296 * (logically a noop for rasters, if wasted time), and thus collapse the
297 * GPU special case and also let this be used for SkPicture testing.
298 */
299 static void setup_bitmap(const ConfigData& gRec, SkISize& size,
300 SkBitmap* bitmap) {
301 bitmap->setConfig(gRec.fConfig, size.width(), size.height());
302 bitmap->allocPixels();
303 bitmap->eraseColor(SK_ColorTRANSPARENT);
304 }
305
306 /**
307 * Any finalization steps we need to perform on the SkBitmap after
308 * we have rendered the GM into it.
epoger@google.com37269602013-01-19 04:21:27 +0000309 *
310 * It's too bad that we are throwing away alpha channel data
311 * we could otherwise be examining, but this had always been happening
312 * before... it was buried within the compare() method at
313 * https://code.google.com/p/skia/source/browse/trunk/gm/gmmain.cpp?r=7289#305 .
314 *
315 * Apparently we need this, at least for bitmaps that are either:
316 * (a) destined to be written out as PNG files, or
317 * (b) compared against bitmaps read in from PNG files
318 * for the reasons described just above the force_all_opaque() method.
319 *
320 * Neglecting to do this led to the difficult-to-diagnose
321 * http://code.google.com/p/skia/issues/detail?id=1079 ('gm generating
322 * spurious pixel_error messages as of r7258')
323 *
324 * TODO(epoger): Come up with a better solution that allows us to
325 * compare full pixel data, including alpha channel, while still being
326 * robust in the face of transformations to/from PNG files.
327 * Options include:
328 *
329 * 1. Continue to call force_all_opaque(), but ONLY for bitmaps that
330 * will be written to, or compared against, PNG files.
331 * PRO: Preserve/compare alpha channel info for the non-PNG cases
332 * (comparing different renderModes in-memory)
333 * CON: The bitmaps (and checksums) for these non-PNG cases would be
334 * different than those for the PNG-compared cases, and in the
335 * case of a failed renderMode comparison, how would we write the
336 * image to disk for examination?
337 *
338 * 2. Always compute image checksums from PNG format (either
339 * directly from the the bytes of a PNG file, or capturing the
340 * bytes we would have written to disk if we were writing the
341 * bitmap out as a PNG).
342 * PRO: I think this would allow us to never force opaque, and to
343 * the extent that alpha channel data can be preserved in a PNG
344 * file, we could observe it.
345 * CON: If we read a bitmap from disk, we need to take its checksum
346 * from the source PNG (we can't compute it from the bitmap we
347 * read out of the PNG, because we will have already premultiplied
348 * the alpha).
349 * CON: Seems wasteful to convert a bitmap to PNG format just to take
350 * its checksum. (Although we're wasting lots of effort already
351 * calling force_all_opaque().)
352 *
353 * 3. Make the alpha premultiply/unpremultiply routines 100% consistent,
354 * so we can transform images back and forth without fear of off-by-one
355 * errors.
356 * CON: Math is hard.
357 *
358 * 4. Perform a "close enough" comparison of bitmaps (+/- 1 bit in each
359 * channel), rather than demanding absolute equality.
360 * CON: Can't do this with checksums.
361 */
epoger@google.com5f6a0072013-01-31 16:30:55 +0000362 static void complete_bitmap(SkBitmap* bitmap) {
363 force_all_opaque(*bitmap);
epoger@google.comde961632012-10-26 18:56:36 +0000364 }
365
scroggo@google.com09fd4d22013-03-20 14:20:18 +0000366 static void installFilter(SkCanvas* canvas);
epoger@google.comde961632012-10-26 18:56:36 +0000367
reed@google.comaef73612012-11-16 13:41:45 +0000368 static void invokeGM(GM* gm, SkCanvas* canvas, bool isPDF, bool isDeferred) {
epoger@google.comde961632012-10-26 18:56:36 +0000369 SkAutoCanvasRestore acr(canvas, true);
370
371 if (!isPDF) {
372 canvas->concat(gm->getInitialTransform());
373 }
374 installFilter(canvas);
reed@google.comaef73612012-11-16 13:41:45 +0000375 gm->setCanvasIsDeferred(isDeferred);
epoger@google.comde961632012-10-26 18:56:36 +0000376 gm->draw(canvas);
377 canvas->setDrawFilter(NULL);
378 }
379
380 static ErrorBitfield generate_image(GM* gm, const ConfigData& gRec,
381 GrContext* context,
382 GrRenderTarget* rt,
383 SkBitmap* bitmap,
384 bool deferred) {
385 SkISize size (gm->getISize());
386 setup_bitmap(gRec, size, bitmap);
387
388 SkAutoTUnref<SkCanvas> canvas;
389
390 if (gRec.fBackend == kRaster_Backend) {
391 SkAutoTUnref<SkDevice> device(new SkDevice(*bitmap));
392 if (deferred) {
393 canvas.reset(new SkDeferredCanvas(device));
394 } else {
395 canvas.reset(new SkCanvas(device));
396 }
reed@google.comaef73612012-11-16 13:41:45 +0000397 invokeGM(gm, canvas, false, deferred);
epoger@google.comde961632012-10-26 18:56:36 +0000398 canvas->flush();
399 }
400#if SK_SUPPORT_GPU
401 else { // GPU
402 if (NULL == context) {
epoger@google.comeb066362013-03-08 09:39:36 +0000403 return kNoGpuContext_ErrorBitmask;
epoger@google.comde961632012-10-26 18:56:36 +0000404 }
405 SkAutoTUnref<SkDevice> device(new SkGpuDevice(context, rt));
406 if (deferred) {
407 canvas.reset(new SkDeferredCanvas(device));
408 } else {
409 canvas.reset(new SkCanvas(device));
410 }
reed@google.comaef73612012-11-16 13:41:45 +0000411 invokeGM(gm, canvas, false, deferred);
epoger@google.comde961632012-10-26 18:56:36 +0000412 // the device is as large as the current rendertarget, so
413 // we explicitly only readback the amount we expect (in
414 // size) overwrite our previous allocation
415 bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth,
416 size.fHeight);
417 canvas->readPixels(bitmap, 0, 0);
418 }
419#endif
epoger@google.com5f6a0072013-01-31 16:30:55 +0000420 complete_bitmap(bitmap);
epoger@google.comeb066362013-03-08 09:39:36 +0000421 return kEmptyErrorBitfield;
epoger@google.comde961632012-10-26 18:56:36 +0000422 }
423
424 static void generate_image_from_picture(GM* gm, const ConfigData& gRec,
junov@chromium.orgc938c482012-12-19 15:24:38 +0000425 SkPicture* pict, SkBitmap* bitmap,
426 SkScalar scale = SK_Scalar1) {
epoger@google.comde961632012-10-26 18:56:36 +0000427 SkISize size = gm->getISize();
428 setup_bitmap(gRec, size, bitmap);
429 SkCanvas canvas(*bitmap);
430 installFilter(&canvas);
junov@chromium.orgc938c482012-12-19 15:24:38 +0000431 canvas.scale(scale, scale);
epoger@google.comde961632012-10-26 18:56:36 +0000432 canvas.drawPicture(*pict);
epoger@google.com5f6a0072013-01-31 16:30:55 +0000433 complete_bitmap(bitmap);
epoger@google.comde961632012-10-26 18:56:36 +0000434 }
435
436 static void generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) {
437#ifdef SK_SUPPORT_PDF
438 SkMatrix initialTransform = gm->getInitialTransform();
439 SkISize pageSize = gm->getISize();
440 SkPDFDevice* dev = NULL;
441 if (initialTransform.isIdentity()) {
442 dev = new SkPDFDevice(pageSize, pageSize, initialTransform);
443 } else {
444 SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()),
445 SkIntToScalar(pageSize.height()));
446 initialTransform.mapRect(&content);
447 content.intersect(0, 0, SkIntToScalar(pageSize.width()),
448 SkIntToScalar(pageSize.height()));
449 SkISize contentSize =
450 SkISize::Make(SkScalarRoundToInt(content.width()),
451 SkScalarRoundToInt(content.height()));
452 dev = new SkPDFDevice(pageSize, contentSize, initialTransform);
453 }
454 SkAutoUnref aur(dev);
455
456 SkCanvas c(dev);
reed@google.comaef73612012-11-16 13:41:45 +0000457 invokeGM(gm, &c, true, false);
epoger@google.comde961632012-10-26 18:56:36 +0000458
459 SkPDFDocument doc;
460 doc.appendPage(dev);
461 doc.emitPDF(&pdf);
462#endif
463 }
464
465 static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) {
466#ifdef SK_SUPPORT_XPS
467 SkISize size = gm->getISize();
468
469 SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()),
470 SkIntToScalar(size.height()));
471 static const SkScalar inchesPerMeter = SkScalarDiv(10000, 254);
472 static const SkScalar upm = 72 * inchesPerMeter;
473 SkVector unitsPerMeter = SkPoint::Make(upm, upm);
474 static const SkScalar ppm = 200 * inchesPerMeter;
475 SkVector pixelsPerMeter = SkPoint::Make(ppm, ppm);
476
477 SkXPSDevice* dev = new SkXPSDevice();
478 SkAutoUnref aur(dev);
479
480 SkCanvas c(dev);
481 dev->beginPortfolio(&xps);
482 dev->beginSheet(unitsPerMeter, pixelsPerMeter, trimSize);
reed@google.comaef73612012-11-16 13:41:45 +0000483 invokeGM(gm, &c, false, false);
epoger@google.comde961632012-10-26 18:56:36 +0000484 dev->endSheet();
485 dev->endPortfolio();
486
487#endif
488 }
489
epoger@google.com57f7abc2012-11-13 03:41:55 +0000490 ErrorBitfield write_reference_image(
epoger@google.comde961632012-10-26 18:56:36 +0000491 const ConfigData& gRec, const char writePath [],
492 const char renderModeDescriptor [], const SkString& name,
493 SkBitmap& bitmap, SkDynamicMemoryWStream* document) {
494 SkString path;
495 bool success = false;
496 if (gRec.fBackend == kRaster_Backend ||
497 gRec.fBackend == kGPU_Backend ||
498 (gRec.fBackend == kPDF_Backend && CAN_IMAGE_PDF)) {
499
epoger@google.com37269602013-01-19 04:21:27 +0000500 path = make_filename(writePath, renderModeDescriptor, name.c_str(),
501 "png");
epoger@google.comde961632012-10-26 18:56:36 +0000502 success = write_bitmap(path, bitmap);
503 }
504 if (kPDF_Backend == gRec.fBackend) {
epoger@google.com37269602013-01-19 04:21:27 +0000505 path = make_filename(writePath, renderModeDescriptor, name.c_str(),
506 "pdf");
epoger@google.comde961632012-10-26 18:56:36 +0000507 success = write_document(path, *document);
508 }
509 if (kXPS_Backend == gRec.fBackend) {
epoger@google.com37269602013-01-19 04:21:27 +0000510 path = make_filename(writePath, renderModeDescriptor, name.c_str(),
511 "xps");
epoger@google.comde961632012-10-26 18:56:36 +0000512 success = write_document(path, *document);
513 }
514 if (success) {
epoger@google.comeb066362013-03-08 09:39:36 +0000515 return kEmptyErrorBitfield;
epoger@google.comde961632012-10-26 18:56:36 +0000516 } else {
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000517 gm_fprintf(stderr, "FAILED to write %s\n", path.c_str());
epoger@google.comeb066362013-03-08 09:39:36 +0000518 RecordError(kWritingReferenceImage_ErrorBitmask, name,
epoger@google.com57f7abc2012-11-13 03:41:55 +0000519 renderModeDescriptor);
epoger@google.comeb066362013-03-08 09:39:36 +0000520 return kWritingReferenceImage_ErrorBitmask;
epoger@google.comde961632012-10-26 18:56:36 +0000521 }
522 }
523
epoger@google.com37269602013-01-19 04:21:27 +0000524 /**
epoger@google.com84a18022013-02-01 20:39:15 +0000525 * Log more detail about the mistmatch between expectedBitmap and
526 * actualBitmap.
527 */
528 void report_bitmap_diffs(const SkBitmap& expectedBitmap, const SkBitmap& actualBitmap,
529 const char *testName) {
530 const int expectedWidth = expectedBitmap.width();
531 const int expectedHeight = expectedBitmap.height();
532 const int width = actualBitmap.width();
533 const int height = actualBitmap.height();
534 if ((expectedWidth != width) || (expectedHeight != height)) {
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000535 gm_fprintf(stderr, "---- %s: dimension mismatch --"
536 " expected [%d %d], actual [%d %d]\n",
537 testName, expectedWidth, expectedHeight, width, height);
epoger@google.com84a18022013-02-01 20:39:15 +0000538 return;
539 }
540
541 if ((SkBitmap::kARGB_8888_Config != expectedBitmap.config()) ||
542 (SkBitmap::kARGB_8888_Config != actualBitmap.config())) {
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000543 gm_fprintf(stderr, "---- %s: not computing max per-channel"
544 " pixel mismatch because non-8888\n", testName);
epoger@google.com84a18022013-02-01 20:39:15 +0000545 return;
546 }
547
548 SkAutoLockPixels alp0(expectedBitmap);
549 SkAutoLockPixels alp1(actualBitmap);
550 int errR = 0;
551 int errG = 0;
552 int errB = 0;
553 int errA = 0;
554 int differingPixels = 0;
555
556 for (int y = 0; y < height; ++y) {
557 const SkPMColor* expectedPixelPtr = expectedBitmap.getAddr32(0, y);
558 const SkPMColor* actualPixelPtr = actualBitmap.getAddr32(0, y);
559 for (int x = 0; x < width; ++x) {
560 SkPMColor expectedPixel = *expectedPixelPtr++;
561 SkPMColor actualPixel = *actualPixelPtr++;
562 if (expectedPixel != actualPixel) {
563 differingPixels++;
564 errR = SkMax32(errR, SkAbs32((int)SkGetPackedR32(expectedPixel) -
565 (int)SkGetPackedR32(actualPixel)));
566 errG = SkMax32(errG, SkAbs32((int)SkGetPackedG32(expectedPixel) -
567 (int)SkGetPackedG32(actualPixel)));
568 errB = SkMax32(errB, SkAbs32((int)SkGetPackedB32(expectedPixel) -
569 (int)SkGetPackedB32(actualPixel)));
570 errA = SkMax32(errA, SkAbs32((int)SkGetPackedA32(expectedPixel) -
571 (int)SkGetPackedA32(actualPixel)));
572 }
573 }
574 }
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000575 gm_fprintf(stderr, "---- %s: %d (of %d) differing pixels,"
576 " max per-channel mismatch R=%d G=%d B=%d A=%d\n",
577 testName, differingPixels, width*height, errR, errG, errB, errA);
epoger@google.com84a18022013-02-01 20:39:15 +0000578 }
579
580 /**
epoger@google.comeb066362013-03-08 09:39:36 +0000581 * Compares actual checksum to expectations. Returns
582 * kEmptyErrorBitfield if they match, or some combination of
583 * _ErrorBitmask values otherwise.
epoger@google.com37269602013-01-19 04:21:27 +0000584 *
585 * If fMismatchPath has been set, and there are pixel diffs, then the
586 * actual bitmap will be written out to a file within fMismatchPath.
587 *
588 * @param expectations what expectations to compare actualBitmap against
589 * @param actualBitmap the image we actually generated
590 * @param baseNameString name of test without renderModeDescriptor added
591 * @param renderModeDescriptor e.g., "-rtree", "-deferred"
592 * @param addToJsonSummary whether to add these results (both actual and
593 * expected) to the JSON summary
594 *
595 * TODO: For now, addToJsonSummary is only set to true within
596 * compare_test_results_to_stored_expectations(), so results of our
597 * in-memory comparisons (Rtree vs regular, etc.) are not written to the
598 * JSON summary. We may wish to change that.
599 */
600 ErrorBitfield compare_to_expectations(Expectations expectations,
601 const SkBitmap& actualBitmap,
602 const SkString& baseNameString,
603 const char renderModeDescriptor[],
604 bool addToJsonSummary=false) {
epoger@google.comee8a8e32012-12-18 19:13:49 +0000605 ErrorBitfield retval;
epoger@google.com5f6a0072013-01-31 16:30:55 +0000606 Checksum actualChecksum = SkBitmapChecksummer::Compute64(actualBitmap);
epoger@google.com37269602013-01-19 04:21:27 +0000607 SkString completeNameString = baseNameString;
608 completeNameString.append(renderModeDescriptor);
609 const char* completeName = completeNameString.c_str();
epoger@google.comee8a8e32012-12-18 19:13:49 +0000610
epoger@google.com37269602013-01-19 04:21:27 +0000611 if (expectations.empty()) {
epoger@google.comeb066362013-03-08 09:39:36 +0000612 retval = kMissingExpectations_ErrorBitmask;
epoger@google.com37269602013-01-19 04:21:27 +0000613 } else if (expectations.match(actualChecksum)) {
epoger@google.comeb066362013-03-08 09:39:36 +0000614 retval = kEmptyErrorBitfield;
epoger@google.com9ef89ce2013-01-18 21:45:42 +0000615 } else {
epoger@google.comeb066362013-03-08 09:39:36 +0000616 retval = kImageMismatch_ErrorBitmask;
epoger@google.com84a18022013-02-01 20:39:15 +0000617
618 // Write out the "actuals" for any mismatches, if we have
619 // been directed to do so.
epoger@google.com37269602013-01-19 04:21:27 +0000620 if (fMismatchPath) {
621 SkString path =
622 make_filename(fMismatchPath, renderModeDescriptor,
623 baseNameString.c_str(), "png");
624 write_bitmap(path, actualBitmap);
625 }
epoger@google.com84a18022013-02-01 20:39:15 +0000626
627 // If we have access to a single expected bitmap, log more
628 // detail about the mismatch.
629 const SkBitmap *expectedBitmapPtr = expectations.asBitmap();
630 if (NULL != expectedBitmapPtr) {
631 report_bitmap_diffs(*expectedBitmapPtr, actualBitmap, completeName);
632 }
epoger@google.coma243b222013-01-17 17:54:28 +0000633 }
epoger@google.com37269602013-01-19 04:21:27 +0000634 RecordError(retval, baseNameString, renderModeDescriptor);
epoger@google.coma243b222013-01-17 17:54:28 +0000635
epoger@google.com37269602013-01-19 04:21:27 +0000636 if (addToJsonSummary) {
637 add_actual_results_to_json_summary(completeName, actualChecksum,
638 retval,
639 expectations.ignoreFailure());
640 add_expected_results_to_json_summary(completeName, expectations);
641 }
epoger@google.coma243b222013-01-17 17:54:28 +0000642
epoger@google.combc159bd2013-01-15 20:24:03 +0000643 return retval;
epoger@google.com06b8a192013-01-15 19:10:16 +0000644 }
645
epoger@google.com37269602013-01-19 04:21:27 +0000646 /**
647 * Add this result to the appropriate JSON collection of actual results,
648 * depending on status.
649 */
650 void add_actual_results_to_json_summary(const char testName[],
651 Checksum actualChecksum,
652 ErrorBitfield result,
653 bool ignoreFailure) {
654 Json::Value actualResults;
655 actualResults[kJsonKey_ActualResults_AnyStatus_Checksum] =
656 asJsonValue(actualChecksum);
epoger@google.comeb066362013-03-08 09:39:36 +0000657 if (kEmptyErrorBitfield == result) {
epoger@google.com37269602013-01-19 04:21:27 +0000658 this->fJsonActualResults_Succeeded[testName] = actualResults;
659 } else {
660 if (ignoreFailure) {
661 // TODO: Once we have added the ability to compare
662 // actual results against expectations in a JSON file
663 // (where we can set ignore-failure to either true or
epoger@google.com84a18022013-02-01 20:39:15 +0000664 // false), add test cases that exercise ignored
epoger@google.comeb066362013-03-08 09:39:36 +0000665 // failures (both for kMissingExpectations_ErrorBitmask
666 // and kImageMismatch_ErrorBitmask).
epoger@google.com37269602013-01-19 04:21:27 +0000667 this->fJsonActualResults_FailureIgnored[testName] =
668 actualResults;
669 } else {
epoger@google.comeb066362013-03-08 09:39:36 +0000670 if (kEmptyErrorBitfield != (result & kMissingExpectations_ErrorBitmask)) {
epoger@google.com37269602013-01-19 04:21:27 +0000671 // TODO: What about the case where there IS an
672 // expected image checksum, but that gm test
673 // doesn't actually run? For now, those cases
674 // will always be ignored, because gm only looks
675 // at expectations that correspond to gm tests
676 // that were actually run.
677 //
678 // Once we have the ability to express
679 // expectations as a JSON file, we should fix this
680 // (and add a test case for which an expectation
681 // is given but the test is never run).
682 this->fJsonActualResults_NoComparison[testName] =
683 actualResults;
epoger@google.comeb066362013-03-08 09:39:36 +0000684 }
685 if (kEmptyErrorBitfield != (result & kImageMismatch_ErrorBitmask)) {
epoger@google.com37269602013-01-19 04:21:27 +0000686 this->fJsonActualResults_Failed[testName] = actualResults;
epoger@google.com37269602013-01-19 04:21:27 +0000687 }
688 }
689 }
690 }
691
692 /**
693 * Add this test to the JSON collection of expected results.
694 */
695 void add_expected_results_to_json_summary(const char testName[],
696 Expectations expectations) {
697 // For now, we assume that this collection starts out empty and we
698 // just fill it in as we go; once gm accepts a JSON file as input,
699 // we'll have to change that.
700 Json::Value expectedResults;
701 expectedResults[kJsonKey_ExpectedResults_Checksums] =
702 expectations.allowedChecksumsAsJson();
703 expectedResults[kJsonKey_ExpectedResults_IgnoreFailure] =
704 expectations.ignoreFailure();
705 this->fJsonExpectedResults[testName] = expectedResults;
706 }
707
708 /**
709 * Compare actualBitmap to expectations stored in this->fExpectationsSource.
710 *
711 * @param gm which test generated the actualBitmap
712 * @param gRec
713 * @param writePath unless this is NULL, write out actual images into this
714 * directory
715 * @param actualBitmap bitmap generated by this run
716 * @param pdf
717 */
718 ErrorBitfield compare_test_results_to_stored_expectations(
719 GM* gm, const ConfigData& gRec, const char writePath[],
720 SkBitmap& actualBitmap, SkDynamicMemoryWStream* pdf) {
721
epoger@google.coma243b222013-01-17 17:54:28 +0000722 SkString name = make_name(gm->shortName(), gRec.fName);
epoger@google.comeb066362013-03-08 09:39:36 +0000723 ErrorBitfield retval = kEmptyErrorBitfield;
epoger@google.com9ef89ce2013-01-18 21:45:42 +0000724
epoger@google.com37269602013-01-19 04:21:27 +0000725 ExpectationsSource *expectationsSource =
726 this->fExpectationsSource.get();
727 if (expectationsSource && (gRec.fFlags & kRead_ConfigFlag)) {
728 /*
729 * Get the expected results for this test, as one or more allowed
730 * checksums. The current implementation of expectationsSource
731 * get this by computing the checksum of a single PNG file on disk.
732 *
733 * TODO(epoger): This relies on the fact that
734 * force_all_opaque() was called on the bitmap before it
735 * was written to disk as a PNG in the first place. If
736 * not, the checksum returned here may not match the
737 * checksum of actualBitmap, which *has* been run through
738 * force_all_opaque().
epoger@google.com5f6a0072013-01-31 16:30:55 +0000739 * See comments above complete_bitmap() for more detail.
epoger@google.com37269602013-01-19 04:21:27 +0000740 */
741 Expectations expectations = expectationsSource->get(name.c_str());
742 retval |= compare_to_expectations(expectations, actualBitmap,
743 name, "", true);
744 } else {
745 // If we are running without expectations, we still want to
epoger@google.com9ef89ce2013-01-18 21:45:42 +0000746 // record the actual results.
epoger@google.com5f6a0072013-01-31 16:30:55 +0000747 Checksum actualChecksum =
748 SkBitmapChecksummer::Compute64(actualBitmap);
epoger@google.com37269602013-01-19 04:21:27 +0000749 add_actual_results_to_json_summary(name.c_str(), actualChecksum,
epoger@google.comeb066362013-03-08 09:39:36 +0000750 kMissingExpectations_ErrorBitmask,
epoger@google.com37269602013-01-19 04:21:27 +0000751 false);
epoger@google.com9ef89ce2013-01-18 21:45:42 +0000752 }
epoger@google.com37269602013-01-19 04:21:27 +0000753
754 // TODO: Consider moving this into compare_to_expectations(),
755 // similar to fMismatchPath... for now, we don't do that, because
756 // we don't want to write out the actual bitmaps for all
757 // renderModes of all tests! That would be a lot of files.
epoger@google.com9ef89ce2013-01-18 21:45:42 +0000758 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) {
epoger@google.com37269602013-01-19 04:21:27 +0000759 retval |= write_reference_image(gRec, writePath, "",
760 name, actualBitmap, pdf);
epoger@google.com9ef89ce2013-01-18 21:45:42 +0000761 }
epoger@google.com37269602013-01-19 04:21:27 +0000762
epoger@google.com9ef89ce2013-01-18 21:45:42 +0000763 return retval;
epoger@google.coma243b222013-01-17 17:54:28 +0000764 }
765
epoger@google.com37269602013-01-19 04:21:27 +0000766 /**
767 * Compare actualBitmap to referenceBitmap.
768 *
769 * @param gm which test generated the bitmap
770 * @param gRec
771 * @param renderModeDescriptor
772 * @param actualBitmap actual bitmap generated by this run
773 * @param referenceBitmap bitmap we expected to be generated
774 */
775 ErrorBitfield compare_test_results_to_reference_bitmap(
776 GM* gm, const ConfigData& gRec, const char renderModeDescriptor [],
777 SkBitmap& actualBitmap, const SkBitmap* referenceBitmap) {
778
779 SkASSERT(referenceBitmap);
780 SkString name = make_name(gm->shortName(), gRec.fName);
epoger@google.com84a18022013-02-01 20:39:15 +0000781 Expectations expectations(*referenceBitmap);
epoger@google.com37269602013-01-19 04:21:27 +0000782 return compare_to_expectations(expectations, actualBitmap,
783 name, renderModeDescriptor);
784 }
785
junov@chromium.org20bd04e2013-01-16 18:43:36 +0000786 static SkPicture* generate_new_picture(GM* gm, BbhType bbhType, uint32_t recordFlags,
787 SkScalar scale = SK_Scalar1) {
epoger@google.comde961632012-10-26 18:56:36 +0000788 // Pictures are refcounted so must be on heap
junov@chromium.org3cb834b2012-12-13 16:39:53 +0000789 SkPicture* pict;
junov@chromium.org706ff2f2012-12-19 15:55:40 +0000790 int width = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().width()), scale));
791 int height = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().height()), scale));
skia.committer@gmail.comd8b27992012-12-20 02:01:41 +0000792
junov@chromium.org3cb834b2012-12-13 16:39:53 +0000793 if (kTileGrid_BbhType == bbhType) {
junov@chromium.org29b19e52013-02-27 18:35:16 +0000794 SkTileGridPicture::TileGridInfo info;
795 info.fMargin.setEmpty();
796 info.fOffset.setZero();
797 info.fTileInterval.set(16, 16);
798 pict = new SkTileGridPicture(width, height, info);
junov@chromium.org3cb834b2012-12-13 16:39:53 +0000799 } else {
800 pict = new SkPicture;
801 }
junov@chromium.org20bd04e2013-01-16 18:43:36 +0000802 if (kNone_BbhType != bbhType) {
803 recordFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag;
804 }
junov@chromium.org706ff2f2012-12-19 15:55:40 +0000805 SkCanvas* cv = pict->beginRecording(width, height, recordFlags);
junov@chromium.orgc938c482012-12-19 15:24:38 +0000806 cv->scale(scale, scale);
reed@google.comaef73612012-11-16 13:41:45 +0000807 invokeGM(gm, cv, false, false);
epoger@google.comde961632012-10-26 18:56:36 +0000808 pict->endRecording();
809
810 return pict;
811 }
812
813 static SkPicture* stream_to_new_picture(const SkPicture& src) {
814
815 // To do in-memory commiunications with a stream, we need to:
816 // * create a dynamic memory stream
817 // * copy it into a buffer
818 // * create a read stream from it
819 // ?!?!
820
821 SkDynamicMemoryWStream storage;
822 src.serialize(&storage);
823
scroggo@google.com09fd4d22013-03-20 14:20:18 +0000824 size_t streamSize = storage.getOffset();
epoger@google.comde961632012-10-26 18:56:36 +0000825 SkAutoMalloc dstStorage(streamSize);
826 void* dst = dstStorage.get();
827 //char* dst = new char [streamSize];
828 //@todo thudson 22 April 2011 when can we safely delete [] dst?
829 storage.copyTo(dst);
830 SkMemoryStream pictReadback(dst, streamSize);
831 SkPicture* retval = new SkPicture (&pictReadback);
832 return retval;
833 }
834
835 // Test: draw into a bitmap or pdf.
epoger@google.com15655b22013-01-08 18:47:31 +0000836 // Depending on flags, possibly compare to an expected image.
epoger@google.come8ebeb12012-10-29 16:42:11 +0000837 ErrorBitfield test_drawing(GM* gm,
838 const ConfigData& gRec,
839 const char writePath [],
epoger@google.come8ebeb12012-10-29 16:42:11 +0000840 GrContext* context,
841 GrRenderTarget* rt,
epoger@google.com57f7abc2012-11-13 03:41:55 +0000842 SkBitmap* bitmap) {
epoger@google.comde961632012-10-26 18:56:36 +0000843 SkDynamicMemoryWStream document;
844
845 if (gRec.fBackend == kRaster_Backend ||
846 gRec.fBackend == kGPU_Backend) {
847 // Early exit if we can't generate the image.
848 ErrorBitfield errors = generate_image(gm, gRec, context, rt, bitmap,
849 false);
epoger@google.comeb066362013-03-08 09:39:36 +0000850 if (kEmptyErrorBitfield != errors) {
epoger@google.com37269602013-01-19 04:21:27 +0000851 // TODO: Add a test to exercise what the stdout and
852 // JSON look like if we get an "early error" while
853 // trying to generate the image.
epoger@google.comde961632012-10-26 18:56:36 +0000854 return errors;
855 }
856 } else if (gRec.fBackend == kPDF_Backend) {
857 generate_pdf(gm, document);
858#if CAN_IMAGE_PDF
859 SkAutoDataUnref data(document.copyToData());
860 SkMemoryStream stream(data->data(), data->size());
861 SkPDFDocumentToBitmap(&stream, bitmap);
862#endif
863 } else if (gRec.fBackend == kXPS_Backend) {
864 generate_xps(gm, document);
865 }
epoger@google.com37269602013-01-19 04:21:27 +0000866 return compare_test_results_to_stored_expectations(
867 gm, gRec, writePath, *bitmap, &document);
epoger@google.comde961632012-10-26 18:56:36 +0000868 }
869
epoger@google.come8ebeb12012-10-29 16:42:11 +0000870 ErrorBitfield test_deferred_drawing(GM* gm,
871 const ConfigData& gRec,
872 const SkBitmap& referenceBitmap,
epoger@google.come8ebeb12012-10-29 16:42:11 +0000873 GrContext* context,
874 GrRenderTarget* rt) {
epoger@google.comde961632012-10-26 18:56:36 +0000875 SkDynamicMemoryWStream document;
876
877 if (gRec.fBackend == kRaster_Backend ||
878 gRec.fBackend == kGPU_Backend) {
879 SkBitmap bitmap;
880 // Early exit if we can't generate the image, but this is
881 // expected in some cases, so don't report a test failure.
882 if (!generate_image(gm, gRec, context, rt, &bitmap, true)) {
epoger@google.comeb066362013-03-08 09:39:36 +0000883 return kEmptyErrorBitfield;
epoger@google.comde961632012-10-26 18:56:36 +0000884 }
epoger@google.com37269602013-01-19 04:21:27 +0000885 return compare_test_results_to_reference_bitmap(
886 gm, gRec, "-deferred", bitmap, &referenceBitmap);
epoger@google.comde961632012-10-26 18:56:36 +0000887 }
epoger@google.comeb066362013-03-08 09:39:36 +0000888 return kEmptyErrorBitfield;
epoger@google.comde961632012-10-26 18:56:36 +0000889 }
890
epoger@google.come8ebeb12012-10-29 16:42:11 +0000891 ErrorBitfield test_pipe_playback(GM* gm,
892 const ConfigData& gRec,
epoger@google.com37269602013-01-19 04:21:27 +0000893 const SkBitmap& referenceBitmap) {
epoger@google.comeb066362013-03-08 09:39:36 +0000894 ErrorBitfield errors = kEmptyErrorBitfield;
epoger@google.comde961632012-10-26 18:56:36 +0000895 for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) {
896 SkBitmap bitmap;
897 SkISize size = gm->getISize();
898 setup_bitmap(gRec, size, &bitmap);
899 SkCanvas canvas(bitmap);
scroggo@google.com0b735632013-03-19 17:38:50 +0000900 installFilter(&canvas);
epoger@google.comde961632012-10-26 18:56:36 +0000901 PipeController pipeController(&canvas);
902 SkGPipeWriter writer;
903 SkCanvas* pipeCanvas = writer.startRecording(
904 &pipeController, gPipeWritingFlagCombos[i].flags);
reed@google.comaef73612012-11-16 13:41:45 +0000905 invokeGM(gm, pipeCanvas, false, false);
epoger@google.com5f6a0072013-01-31 16:30:55 +0000906 complete_bitmap(&bitmap);
epoger@google.comde961632012-10-26 18:56:36 +0000907 writer.endRecording();
908 SkString string("-pipe");
909 string.append(gPipeWritingFlagCombos[i].name);
epoger@google.com37269602013-01-19 04:21:27 +0000910 errors |= compare_test_results_to_reference_bitmap(
911 gm, gRec, string.c_str(), bitmap, &referenceBitmap);
epoger@google.comeb066362013-03-08 09:39:36 +0000912 if (errors != kEmptyErrorBitfield) {
epoger@google.comde961632012-10-26 18:56:36 +0000913 break;
914 }
915 }
916 return errors;
917 }
918
epoger@google.come8ebeb12012-10-29 16:42:11 +0000919 ErrorBitfield test_tiled_pipe_playback(
epoger@google.com37269602013-01-19 04:21:27 +0000920 GM* gm, const ConfigData& gRec, const SkBitmap& referenceBitmap) {
epoger@google.comeb066362013-03-08 09:39:36 +0000921 ErrorBitfield errors = kEmptyErrorBitfield;
epoger@google.comde961632012-10-26 18:56:36 +0000922 for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) {
923 SkBitmap bitmap;
924 SkISize size = gm->getISize();
925 setup_bitmap(gRec, size, &bitmap);
926 SkCanvas canvas(bitmap);
scroggo@google.com0b735632013-03-19 17:38:50 +0000927 installFilter(&canvas);
epoger@google.comde961632012-10-26 18:56:36 +0000928 TiledPipeController pipeController(bitmap);
929 SkGPipeWriter writer;
930 SkCanvas* pipeCanvas = writer.startRecording(
931 &pipeController, gPipeWritingFlagCombos[i].flags);
reed@google.comaef73612012-11-16 13:41:45 +0000932 invokeGM(gm, pipeCanvas, false, false);
epoger@google.com5f6a0072013-01-31 16:30:55 +0000933 complete_bitmap(&bitmap);
epoger@google.comde961632012-10-26 18:56:36 +0000934 writer.endRecording();
935 SkString string("-tiled pipe");
936 string.append(gPipeWritingFlagCombos[i].name);
epoger@google.com37269602013-01-19 04:21:27 +0000937 errors |= compare_test_results_to_reference_bitmap(
938 gm, gRec, string.c_str(), bitmap, &referenceBitmap);
epoger@google.comeb066362013-03-08 09:39:36 +0000939 if (errors != kEmptyErrorBitfield) {
epoger@google.comde961632012-10-26 18:56:36 +0000940 break;
941 }
942 }
943 return errors;
944 }
epoger@google.come8ebeb12012-10-29 16:42:11 +0000945
946 //
947 // member variables.
948 // They are public for now, to allow easier setting by tool_main().
949 //
950
epoger@google.come8ebeb12012-10-29 16:42:11 +0000951 bool fUseFileHierarchy;
952
junov@chromium.org95146eb2013-01-11 21:04:40 +0000953 const char* fMismatchPath;
954
epoger@google.com57f7abc2012-11-13 03:41:55 +0000955 // information about all failed tests we have encountered so far
956 SkTArray<FailRec> fFailedTests;
957
epoger@google.com37269602013-01-19 04:21:27 +0000958 // Where to read expectations (expected image checksums, etc.) from.
959 // If unset, we don't do comparisons.
960 SkAutoTUnref<ExpectationsSource> fExpectationsSource;
961
962 // JSON summaries that we generate as we go (just for output).
epoger@google.comee8a8e32012-12-18 19:13:49 +0000963 Json::Value fJsonExpectedResults;
964 Json::Value fJsonActualResults_Failed;
965 Json::Value fJsonActualResults_FailureIgnored;
epoger@google.com9c56a8d2012-12-20 18:34:29 +0000966 Json::Value fJsonActualResults_NoComparison;
epoger@google.comee8a8e32012-12-18 19:13:49 +0000967 Json::Value fJsonActualResults_Succeeded;
968
epoger@google.comde961632012-10-26 18:56:36 +0000969}; // end of GMMain class definition
scroggo@google.com72c96722012-06-06 21:07:10 +0000970
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000971#if SK_SUPPORT_GPU
972static const GLContextType kDontCare_GLContextType = GrContextFactory::kNative_GLContextType;
973#else
974static const GLContextType kDontCare_GLContextType = 0;
975#endif
bsalomon@google.com7361f542012-04-19 19:15:35 +0000976
977// If the platform does not support writing PNGs of PDFs then there will be no
epoger@google.comf28dd8a2012-10-25 16:27:34 +0000978// reference images to read. However, we can always write the .pdf files
bsalomon@google.com7361f542012-04-19 19:15:35 +0000979static const ConfigFlags kPDFConfigFlags = CAN_IMAGE_PDF ? kRW_ConfigFlag :
980 kWrite_ConfigFlag;
981
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000982static const ConfigData gRec[] = {
bsalomon@google.com4c75f242013-03-19 18:58:43 +0000983 { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "8888", true },
reed@google.com69dc4ff2012-11-29 21:21:54 +0000984#if 0 // stop testing this (for now at least) since we want to remove support for it (soon please!!!)
bsalomon@google.com4c75f242013-03-19 18:58:43 +0000985 { SkBitmap::kARGB_4444_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "4444", true },
reed@google.com69dc4ff2012-11-29 21:21:54 +0000986#endif
bsalomon@google.com4c75f242013-03-19 18:58:43 +0000987 { SkBitmap::kRGB_565_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "565", true },
988#if SK_SUPPORT_GPU
989 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 0, kRW_ConfigFlag, "gpu", true },
990 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 16, kRW_ConfigFlag, "msaa16", true },
991 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 4, kRW_ConfigFlag, "msaa4", false},
bsalomon@google.com7361f542012-04-19 19:15:35 +0000992 /* The debug context does not generate images */
scroggo@google.com0f567c62013-03-20 15:35:08 +0000993 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kDebug_GLContextType, 0, kNone_ConfigFlag, "gpudebug", GR_DEBUG},
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000994#if SK_ANGLE
bsalomon@google.com4c75f242013-03-19 18:58:43 +0000995 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 0, kRW_ConfigFlag, "angle", true },
996 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 16, kRW_ConfigFlag, "anglemsaa16", true },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000997#endif // SK_ANGLE
998#ifdef SK_MESA
bsalomon@google.com4c75f242013-03-19 18:58:43 +0000999 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kMESA_GLContextType, 0, kRW_ConfigFlag, "mesa", true },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001000#endif // SK_MESA
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001001#endif // SK_SUPPORT_GPU
bungeman@google.comb29c8832011-10-10 13:19:10 +00001002#ifdef SK_SUPPORT_XPS
bsalomon@google.com7361f542012-04-19 19:15:35 +00001003 /* At present we have no way of comparing XPS files (either natively or by converting to PNG). */
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001004 { SkBitmap::kARGB_8888_Config, kXPS_Backend, kDontCare_GLContextType, 0, kWrite_ConfigFlag, "xps", true },
robertphillips@google.coma73e8602012-08-02 17:56:02 +00001005#endif // SK_SUPPORT_XPS
bsalomon@google.com7361f542012-04-19 19:15:35 +00001006#ifdef SK_SUPPORT_PDF
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001007 { SkBitmap::kARGB_8888_Config, kPDF_Backend, kDontCare_GLContextType, 0, kPDFConfigFlags, "pdf", true },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001008#endif // SK_SUPPORT_PDF
reed@android.com00dae862009-06-10 15:38:48 +00001009};
1010
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001011static SkString configUsage() {
scroggo@google.com0f567c62013-03-20 15:35:08 +00001012 SkString result;
1013 result.appendf("Space delimited list of which configs to run. Possible options: [");
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001014 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
1015 if (i > 0) {
scroggo@google.com0f567c62013-03-20 15:35:08 +00001016 result.append("|");
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001017 }
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001018 result.appendf("%s", gRec[i].fName);
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001019 }
scroggo@google.com0f567c62013-03-20 15:35:08 +00001020 result.append("]\n");
1021 result.appendf("The default value is: \"");
1022 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
1023 if (gRec[i].fRunByDefault) {
1024 if (i > 0) {
1025 result.append(" ");
1026 }
1027 result.appendf("%s", gRec[i].fName);
1028 }
1029 }
1030 result.appendf("\"");
1031
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001032 return result;
scroggo@google.com0b735632013-03-19 17:38:50 +00001033}
scroggo@google.com7d519302013-03-19 17:28:10 +00001034
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001035// Alphabetized ignoring "no" prefix ("readPath", "noreplay", "resourcePath").
scroggo@google.com0f567c62013-03-20 15:35:08 +00001036DEFINE_string(config, "", configUsage().c_str());
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001037DEFINE_bool(deferred, true, "Exercise the deferred rendering test pass.");
1038DEFINE_bool(enableMissingWarning, true, "Print message to stderr (but don't fail) if "
1039 "unable to read a reference image for any tests.");
1040DEFINE_string(excludeConfig, "", "Space delimited list of configs to skip.");
1041DEFINE_bool(forceBWtext, false, "Disable text anti-aliasing.");
1042#if SK_SUPPORT_GPU
1043DEFINE_string(gpuCacheSize, "", "<bytes> <count>: Limit the gpu cache to byte size or "
1044 "object count. -1 for either value means use the default. 0 for either "
1045 "disables the cache.");
1046#endif
1047DEFINE_bool(hierarchy, false, "Whether to use multilevel directory structure "
1048 "when reading/writing files.");
1049DEFINE_string(match, "", "Only run tests whose name includes this substring/these substrings "
1050 "(more than one can be supplied, separated by spaces).");
1051DEFINE_string(mismatchPath, "", "Write images for tests that failed due to "
1052 "pixel mismatches into this directory.");
1053DEFINE_string(modulo, "", "[--modulo <remainder> <divisor>]: only run tests for which "
1054 "testIndex %% divisor == remainder.");
1055DEFINE_bool(pdf, true, "Exercise the pdf rendering test pass.");
1056DEFINE_bool(pipe, true, "Exercise the SkGPipe replay test pass.");
1057DEFINE_string2(readPath, r, "", "Read reference images from this dir, and report "
1058 "any differences between those and the newly generated ones.");
1059DEFINE_bool(replay, true, "Exercise the SkPicture replay test pass.");
1060DEFINE_string2(resourcePath, i, "", "Directory that stores image resources.");
1061DEFINE_bool(rtree, true, "Exercise the R-Tree variant of SkPicture test pass.");
1062DEFINE_bool(serialize, true, "Exercise the SkPicture serialization & deserialization test pass.");
1063DEFINE_bool(tiledPipe, false, "Exercise tiled SkGPipe replay.");
1064DEFINE_bool(tileGrid, true, "Exercise the tile grid variant of SkPicture.");
1065DEFINE_string(tileGridReplayScales, "", "Space separated list of floating-point scale "
1066 "factors to be used for tileGrid playback testing. Default value: 1.0");
1067DEFINE_string(writeJsonSummaryPath, "", "Write a JSON-formatted result summary to this file.");
1068DEFINE_bool2(verbose, v, false, "Print diagnostics (e.g. list each config to be tested).");
1069DEFINE_string2(writePath, w, "", "Write rendered images into this directory.");
1070DEFINE_string2(writePicturePath, wp, "", "Write .skp files into this directory.");
1071
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001072static int findConfig(const char config[]) {
1073 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
1074 if (!strcmp(config, gRec[i].fName)) {
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001075 return (int) i;
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001076 }
1077 }
1078 return -1;
1079}
1080
reed@google.comb2a51622011-10-31 16:30:04 +00001081static bool skip_name(const SkTDArray<const char*> array, const char name[]) {
1082 if (0 == array.count()) {
1083 // no names, so don't skip anything
1084 return false;
1085 }
1086 for (int i = 0; i < array.count(); ++i) {
1087 if (strstr(name, array[i])) {
1088 // found the name, so don't skip
1089 return false;
1090 }
1091 }
1092 return true;
1093}
1094
bsalomon@google.comd9f826c2011-07-18 15:25:04 +00001095namespace skiagm {
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001096#if SK_SUPPORT_GPU
bsalomon@google.com7361f542012-04-19 19:15:35 +00001097SkAutoTUnref<GrContext> gGrContext;
1098/**
bsalomon@google.comc7a24d22012-11-01 18:03:48 +00001099 * Sets the global GrContext, accessible by individual GMs
bsalomon@google.com7361f542012-04-19 19:15:35 +00001100 */
caryclark@google.com13130862012-06-06 12:10:45 +00001101static void SetGr(GrContext* grContext) {
bsalomon@google.com7361f542012-04-19 19:15:35 +00001102 SkSafeRef(grContext);
1103 gGrContext.reset(grContext);
bsalomon@google.comd9f826c2011-07-18 15:25:04 +00001104}
bsalomon@google.com7361f542012-04-19 19:15:35 +00001105
1106/**
1107 * Gets the global GrContext, can be called by GM tests.
1108 */
caryclark@google.com13130862012-06-06 12:10:45 +00001109GrContext* GetGr();
bsalomon@google.com7361f542012-04-19 19:15:35 +00001110GrContext* GetGr() {
1111 return gGrContext.get();
1112}
1113
1114/**
1115 * Sets the global GrContext and then resets it to its previous value at
1116 * destruction.
1117 */
1118class AutoResetGr : SkNoncopyable {
1119public:
1120 AutoResetGr() : fOld(NULL) {}
1121 void set(GrContext* context) {
1122 SkASSERT(NULL == fOld);
1123 fOld = GetGr();
1124 SkSafeRef(fOld);
1125 SetGr(context);
1126 }
1127 ~AutoResetGr() { SetGr(fOld); SkSafeUnref(fOld); }
1128private:
1129 GrContext* fOld;
1130};
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001131#else
1132GrContext* GetGr() { return NULL; }
1133#endif
bsalomon@google.comd9f826c2011-07-18 15:25:04 +00001134}
1135
reed@google.comfb2cd422013-01-04 14:43:03 +00001136template <typename T> void appendUnique(SkTDArray<T>* array, const T& value) {
1137 int index = array->find(value);
1138 if (index < 0) {
1139 *array->append() = value;
1140 }
1141}
1142
epoger@google.com0b62b3d2013-03-20 17:59:28 +00001143/**
1144 * Run this test in a number of different configs (8888, 565, PDF,
1145 * etc.), confirming that the resulting bitmaps match expectations
1146 * (which may be different for each config).
1147 *
1148 * Returns all errors encountered while doing so.
1149 */
1150ErrorBitfield run_multiple_configs(GMMain &gmmain, GM *gm, const SkTDArray<size_t> &configs,
1151 GrContextFactory *grFactory) {
1152 ErrorBitfield errorsForAllConfigs = kEmptyErrorBitfield;
1153 uint32_t gmFlags = gm->getFlags();
reed@google.comae7b8f32012-10-18 21:30:57 +00001154
scroggo@google.com0b735632013-03-19 17:38:50 +00001155#if SK_SUPPORT_GPU
bsalomon@google.com8a8fcba2013-03-11 20:22:31 +00001156 struct {
bsalomon@google.come3613ce2013-03-11 20:33:45 +00001157 int fBytes;
bsalomon@google.com8a8fcba2013-03-11 20:22:31 +00001158 int fCount;
1159 } gpuCacheSize = { -1, -1 }; // -1s mean use the default
bsalomon@google.com8a8fcba2013-03-11 20:22:31 +00001160
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001161 if (FLAGS_gpuCacheSize.count() > 0) {
1162 if (FLAGS_gpuCacheSize.count() != 2) {
1163 gm_fprintf(stderr, "--gpuCacheSize requires two arguments\n");
scroggo@google.com0b735632013-03-19 17:38:50 +00001164 return -1;
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001165 }
1166 gpuCacheSize.fBytes = atoi(FLAGS_gpuCacheSize[0]);
1167 gpuCacheSize.fCount = atoi(FLAGS_gpuCacheSize[1]);
1168 }
1169#endif
scroggo@google.com0b735632013-03-19 17:38:50 +00001170
epoger@google.com0b62b3d2013-03-20 17:59:28 +00001171 for (int i = 0; i < configs.count(); i++) {
1172 ConfigData config = gRec[configs[i]];
1173
1174 // Skip any tests that we don't even need to try.
1175 if ((kPDF_Backend == config.fBackend) &&
1176 (!FLAGS_pdf|| (gmFlags & GM::kSkipPDF_Flag))) {
1177 continue;
1178 }
1179 if ((gmFlags & GM::kSkip565_Flag) &&
1180 (kRaster_Backend == config.fBackend) &&
1181 (SkBitmap::kRGB_565_Config == config.fConfig)) {
1182 continue;
1183 }
1184 if ((gmFlags & GM::kSkipGPU_Flag) &&
1185 kGPU_Backend == config.fBackend) {
1186 continue;
1187 }
1188
1189 // Now we know that we want to run this test and record its
1190 // success or failure.
1191 ErrorBitfield errorsForThisConfig = kEmptyErrorBitfield;
1192 GrRenderTarget* renderTarget = NULL;
1193#if SK_SUPPORT_GPU
1194 SkAutoTUnref<GrRenderTarget> rt;
1195 AutoResetGr autogr;
1196 if ((kEmptyErrorBitfield == errorsForThisConfig) && (kGPU_Backend == config.fBackend)) {
1197 GrContext* gr = grFactory->get(config.fGLContextType);
1198 bool grSuccess = false;
1199 if (gr) {
1200 // create a render target to back the device
1201 GrTextureDesc desc;
1202 desc.fConfig = kSkia8888_GrPixelConfig;
1203 desc.fFlags = kRenderTarget_GrTextureFlagBit;
1204 desc.fWidth = gm->getISize().width();
1205 desc.fHeight = gm->getISize().height();
1206 desc.fSampleCnt = config.fSampleCnt;
1207 GrTexture* tex = gr->createUncachedTexture(desc, NULL, 0);
1208 if (tex) {
1209 rt.reset(tex->asRenderTarget());
1210 rt.get()->ref();
1211 tex->unref();
1212 autogr.set(gr);
1213 renderTarget = rt.get();
1214 grSuccess = NULL != renderTarget;
1215 }
1216 // Set the user specified cache limits if non-default.
1217 size_t bytes;
1218 int count;
1219 gr->getTextureCacheLimits(&count, &bytes);
1220 if (-1 != gpuCacheSize.fBytes) {
1221 bytes = static_cast<size_t>(gpuCacheSize.fBytes);
1222 }
1223 if (-1 != gpuCacheSize.fCount) {
1224 count = gpuCacheSize.fCount;
1225 }
1226 gr->setTextureCacheLimits(count, bytes);
1227 }
1228 if (!grSuccess) {
1229 errorsForThisConfig |= kNoGpuContext_ErrorBitmask;
1230 }
1231 }
1232#endif
1233
1234 SkBitmap comparisonBitmap;
1235
1236 const char* writePath;
1237 if (FLAGS_writePath.count() == 1) {
1238 writePath = FLAGS_writePath[0];
1239 } else {
1240 writePath = NULL;
1241 }
1242 if (kEmptyErrorBitfield == errorsForThisConfig) {
1243 errorsForThisConfig |= gmmain.test_drawing(gm, config, writePath, GetGr(),
1244 renderTarget, &comparisonBitmap);
1245 }
1246
1247 if (FLAGS_deferred && !errorsForThisConfig &&
1248 (kGPU_Backend == config.fBackend ||
1249 kRaster_Backend == config.fBackend)) {
1250 errorsForThisConfig |= gmmain.test_deferred_drawing(gm, config, comparisonBitmap,
1251 GetGr(), renderTarget);
1252 }
1253
1254 errorsForAllConfigs |= errorsForThisConfig;
1255 }
1256 return errorsForAllConfigs;
1257}
1258
1259/**
1260 * Run this test in a number of different drawing modes (pipe,
1261 * deferred, tiled, etc.), confirming that the resulting bitmaps all
1262 * *exactly* match comparisonBitmap.
1263 *
1264 * Returns all errors encountered while doing so.
1265 */
1266ErrorBitfield run_multiple_modes(GMMain &gmmain, GM *gm, const ConfigData &compareConfig,
1267 const SkBitmap &comparisonBitmap) {
1268 SkTDArray<SkScalar> tileGridReplayScales;
1269 *tileGridReplayScales.append() = SK_Scalar1; // By default only test at scale 1.0
1270 if (FLAGS_tileGridReplayScales.count() > 0) {
1271 tileGridReplayScales.reset();
1272 for (int i = 0; i < FLAGS_tileGridReplayScales.count(); i++) {
1273 double val = atof(FLAGS_tileGridReplayScales[i]);
1274 if (0 < val) {
1275 *tileGridReplayScales.append() = SkDoubleToScalar(val);
1276 }
1277 }
1278 if (0 == tileGridReplayScales.count()) {
1279 // Should have at least one scale
1280 gm_fprintf(stderr, "--tileGridReplayScales requires at least one scale.\n");
1281 return -1;
1282 }
1283 }
1284
1285 ErrorBitfield errorsForAllModes = kEmptyErrorBitfield;
1286 uint32_t gmFlags = gm->getFlags();
1287
1288 // run the picture centric GM steps
1289 if (!(gmFlags & GM::kSkipPicture_Flag)) {
1290
1291 ErrorBitfield pictErrors = kEmptyErrorBitfield;
1292
1293 //SkAutoTUnref<SkPicture> pict(generate_new_picture(gm));
1294 SkPicture* pict = gmmain.generate_new_picture(gm, kNone_BbhType, 0);
1295 SkAutoUnref aur(pict);
1296
1297 if (FLAGS_replay) {
1298 SkBitmap bitmap;
1299 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap);
1300 pictErrors |= gmmain.compare_test_results_to_reference_bitmap(
1301 gm, compareConfig, "-replay", bitmap, &comparisonBitmap);
1302 }
1303
1304 if ((kEmptyErrorBitfield == pictErrors) && FLAGS_serialize) {
1305 SkPicture* repict = gmmain.stream_to_new_picture(*pict);
1306 SkAutoUnref aurr(repict);
1307
1308 SkBitmap bitmap;
1309 gmmain.generate_image_from_picture(gm, compareConfig, repict, &bitmap);
1310 pictErrors |= gmmain.compare_test_results_to_reference_bitmap(
1311 gm, compareConfig, "-serialize", bitmap, &comparisonBitmap);
1312 }
1313
1314 if (FLAGS_writePicturePath.count() == 1) {
1315 const char* pictureSuffix = "skp";
1316 SkString path = make_filename(FLAGS_writePicturePath[0], "",
1317 gm->shortName(), pictureSuffix);
1318 SkFILEWStream stream(path.c_str());
1319 pict->serialize(&stream);
1320 }
1321
1322 errorsForAllModes |= pictErrors;
1323 }
1324
1325 // TODO: add a test in which the RTree rendering results in a
1326 // different bitmap than the standard rendering. It should
1327 // show up as failed in the JSON summary, and should be listed
1328 // in the stdout also.
1329 if (!(gmFlags & GM::kSkipPicture_Flag) && FLAGS_rtree) {
1330 SkPicture* pict = gmmain.generate_new_picture(
1331 gm, kRTree_BbhType, SkPicture::kUsePathBoundsForClip_RecordingFlag);
1332 SkAutoUnref aur(pict);
1333 SkBitmap bitmap;
1334 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap);
1335 errorsForAllModes |= gmmain.compare_test_results_to_reference_bitmap(
1336 gm, compareConfig, "-rtree", bitmap, &comparisonBitmap);
1337 }
1338
1339 if (!(gmFlags & GM::kSkipPicture_Flag) && FLAGS_tileGrid) {
1340 for(int scaleIndex = 0; scaleIndex < tileGridReplayScales.count(); ++scaleIndex) {
1341 SkScalar replayScale = tileGridReplayScales[scaleIndex];
1342 if ((gmFlags & GM::kSkipScaledReplay_Flag) && replayScale != 1) {
1343 continue;
1344 }
1345 // We record with the reciprocal scale to obtain a replay
1346 // result that can be validated against comparisonBitmap.
1347 SkScalar recordScale = SkScalarInvert(replayScale);
1348 SkPicture* pict = gmmain.generate_new_picture(
1349 gm, kTileGrid_BbhType, SkPicture::kUsePathBoundsForClip_RecordingFlag, recordScale);
1350 SkAutoUnref aur(pict);
1351 SkBitmap bitmap;
1352 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap, replayScale);
1353 SkString suffix("-tilegrid");
1354 if (SK_Scalar1 != replayScale) {
1355 suffix += "-scale-";
1356 suffix.appendScalar(replayScale);
1357 }
1358 errorsForAllModes |= gmmain.compare_test_results_to_reference_bitmap(
1359 gm, compareConfig, suffix.c_str(), bitmap, &comparisonBitmap);
1360 }
1361 }
1362
1363 // run the pipe centric GM steps
1364 if (!(gmFlags & GM::kSkipPipe_Flag)) {
1365
1366 ErrorBitfield pipeErrors = kEmptyErrorBitfield;
1367
1368 if (FLAGS_pipe) {
1369 pipeErrors |= gmmain.test_pipe_playback(gm, compareConfig, comparisonBitmap);
1370 }
1371
1372 if ((kEmptyErrorBitfield == pipeErrors) &&
1373 FLAGS_tiledPipe && !(gmFlags & GM::kSkipTiled_Flag)) {
1374 pipeErrors |= gmmain.test_tiled_pipe_playback(gm, compareConfig, comparisonBitmap);
1375 }
1376
1377 errorsForAllModes |= pipeErrors;
1378 }
1379 return errorsForAllModes;
1380}
1381
1382int tool_main(int argc, char** argv);
1383int tool_main(int argc, char** argv) {
1384
1385#if SK_ENABLE_INST_COUNT
1386 gPrintInstCount = true;
1387#endif
1388
1389 SkGraphics::Init();
1390 // we don't need to see this during a run
1391 gSkSuppressFontCachePurgeSpew = true;
1392
1393 setSystemPreferences();
1394 GMMain gmmain;
1395
1396 SkTDArray<size_t> configs;
1397 SkTDArray<size_t> excludeConfigs;
1398 bool userConfig = false;
1399
1400 SkString usage;
1401 usage.printf("Run the golden master tests.\n");
1402 SkFlags::SetUsage(usage.c_str());
1403 SkFlags::ParseCommandLine(argc, argv);
1404
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001405 gmmain.fUseFileHierarchy = FLAGS_hierarchy;
1406 if (FLAGS_mismatchPath.count() == 1) {
1407 gmmain.fMismatchPath = FLAGS_mismatchPath[0];
1408 }
1409
1410 for (int i = 0; i < FLAGS_config.count(); i++) {
1411 int index = findConfig(FLAGS_config[i]);
1412 if (index >= 0) {
1413 appendUnique<size_t>(&configs, index);
1414 userConfig = true;
scroggo@google.com0b735632013-03-19 17:38:50 +00001415 } else {
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001416 gm_fprintf(stderr, "unrecognized config %s\n", FLAGS_config[i]);
scroggo@google.com7d519302013-03-19 17:28:10 +00001417 return -1;
1418 }
1419 }
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001420
1421 for (int i = 0; i < FLAGS_excludeConfig.count(); i++) {
1422 int index = findConfig(FLAGS_excludeConfig[i]);
1423 if (index >= 0) {
1424 *excludeConfigs.append() = index;
1425 } else {
1426 gm_fprintf(stderr, "unrecognized excludeConfig %s\n", FLAGS_excludeConfig[i]);
1427 return -1;
1428 }
1429 }
1430
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001431 int moduloRemainder = -1;
1432 int moduloDivisor = -1;
1433
1434 if (FLAGS_modulo.count() == 2) {
1435 moduloRemainder = atoi(FLAGS_modulo[0]);
1436 moduloDivisor = atoi(FLAGS_modulo[1]);
1437 if (moduloRemainder < 0 || moduloDivisor <= 0 || moduloRemainder >= moduloDivisor) {
1438 gm_fprintf(stderr, "invalid modulo values.");
1439 return -1;
1440 }
tomhudson@google.com9875dd12011-04-25 15:49:53 +00001441 }
reed@google.com873cb1e2010-12-23 15:00:45 +00001442
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001443 if (!userConfig) {
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001444 // if no config is specified by user, add the defaults
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001445 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001446 if (gRec[i].fRunByDefault) {
1447 *configs.append() = i;
1448 }
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001449 }
1450 }
reed@google.comfb2cd422013-01-04 14:43:03 +00001451 // now remove any explicitly excluded configs
1452 for (int i = 0; i < excludeConfigs.count(); ++i) {
1453 int index = configs.find(excludeConfigs[i]);
1454 if (index >= 0) {
1455 configs.remove(index);
1456 // now assert that there was only one copy in configs[]
1457 SkASSERT(configs.find(excludeConfigs[i]) < 0);
1458 }
1459 }
1460
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001461#if SK_SUPPORT_GPU
1462 GrContextFactory* grFactory = new GrContextFactory;
1463 for (int i = 0; i < configs.count(); ++i) {
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001464 size_t index = configs[i];
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001465 if (kGPU_Backend == gRec[index].fBackend) {
1466 GrContext* ctx = grFactory->get(gRec[index].fGLContextType);
1467 if (NULL == ctx) {
1468 SkDebugf("GrContext could not be created for config %s. Config will be skipped.",
1469 gRec[index].fName);
1470 configs.remove(i);
1471 --i;
1472 }
1473 if (gRec[index].fSampleCnt > ctx->getMaxSampleCount()) {
1474 SkDebugf("Sample count (%d) of config %s is not supported. Config will be skipped.",
1475 gRec[index].fSampleCnt, gRec[index].fName);
1476 configs.remove(i);
1477 --i;
1478 }
1479 }
1480 }
1481#endif
1482
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001483 if (FLAGS_verbose) {
reed@google.comfb2cd422013-01-04 14:43:03 +00001484 SkString str;
epoger@google.com5efdd0c2013-03-13 14:18:40 +00001485 str.printf("%d configs:", configs.count());
reed@google.comfb2cd422013-01-04 14:43:03 +00001486 for (int i = 0; i < configs.count(); ++i) {
1487 str.appendf(" %s", gRec[configs[i]].fName);
1488 }
epoger@google.com5efdd0c2013-03-13 14:18:40 +00001489 gm_fprintf(stderr, "%s\n", str.c_str());
reed@google.comfb2cd422013-01-04 14:43:03 +00001490 }
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001491
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001492 if (FLAGS_resourcePath.count() == 1) {
1493 GM::SetResourcePath(FLAGS_resourcePath[0]);
1494 }
robertphillips@google.com8570b5c2012-03-20 17:40:58 +00001495
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001496 if (FLAGS_readPath.count() == 1) {
1497 const char* readPath = FLAGS_readPath[0];
epoger@google.com37269602013-01-19 04:21:27 +00001498 if (!sk_exists(readPath)) {
epoger@google.com5efdd0c2013-03-13 14:18:40 +00001499 gm_fprintf(stderr, "readPath %s does not exist!\n", readPath);
epoger@google.com37269602013-01-19 04:21:27 +00001500 return -1;
1501 }
1502 if (sk_isdir(readPath)) {
epoger@google.com5efdd0c2013-03-13 14:18:40 +00001503 gm_fprintf(stdout, "reading from %s\n", readPath);
epoger@google.com37269602013-01-19 04:21:27 +00001504 gmmain.fExpectationsSource.reset(SkNEW_ARGS(
1505 IndividualImageExpectationsSource,
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001506 (readPath, FLAGS_enableMissingWarning)));
epoger@google.com37269602013-01-19 04:21:27 +00001507 } else {
epoger@google.com5efdd0c2013-03-13 14:18:40 +00001508 gm_fprintf(stdout, "reading expectations from JSON summary file %s\n", readPath);
epoger@google.comd271d242013-02-13 18:14:48 +00001509 gmmain.fExpectationsSource.reset(SkNEW_ARGS(
1510 JsonExpectationsSource, (readPath)));
epoger@google.com37269602013-01-19 04:21:27 +00001511 }
chudy@google.comf32f6e82012-07-12 15:42:37 +00001512 }
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001513 if (FLAGS_writePath.count() == 1) {
1514 gm_fprintf(stderr, "writing to %s\n", FLAGS_writePath[0]);
reed@android.com00f883e2010-12-14 17:46:14 +00001515 }
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001516 if (FLAGS_writePicturePath.count() == 1) {
1517 gm_fprintf(stderr, "writing pictures to %s\n", FLAGS_writePicturePath[0]);
mike@reedtribe.org5d0c62f2012-06-02 14:50:13 +00001518 }
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001519 if (FLAGS_resourcePath.count() == 1) {
1520 gm_fprintf(stderr, "reading resources from %s\n", FLAGS_resourcePath[0]);
robertphillips@google.com8570b5c2012-03-20 17:40:58 +00001521 }
1522
epoger@google.com82cb65b2012-10-29 18:59:17 +00001523 if (moduloDivisor <= 0) {
1524 moduloRemainder = -1;
reed@google.comae7b8f32012-10-18 21:30:57 +00001525 }
epoger@google.com82cb65b2012-10-29 18:59:17 +00001526 if (moduloRemainder < 0 || moduloRemainder >= moduloDivisor) {
1527 moduloRemainder = -1;
reed@google.comae7b8f32012-10-18 21:30:57 +00001528 }
1529
epoger@google.comc7cf2b32011-12-28 19:31:01 +00001530 // Accumulate success of all tests.
1531 int testsRun = 0;
1532 int testsPassed = 0;
1533 int testsFailed = 0;
1534 int testsMissingReferenceImages = 0;
1535
reed@google.comae7b8f32012-10-18 21:30:57 +00001536 int gmIndex = -1;
1537 SkString moduloStr;
1538
epoger@google.come8ebeb12012-10-29 16:42:11 +00001539 // If we will be writing out files, prepare subdirectories.
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001540 if (FLAGS_writePath.count() == 1) {
1541 if (!sk_mkdir(FLAGS_writePath[0])) {
epoger@google.come8ebeb12012-10-29 16:42:11 +00001542 return -1;
1543 }
1544 if (gmmain.fUseFileHierarchy) {
1545 for (int i = 0; i < configs.count(); i++) {
1546 ConfigData config = gRec[configs[i]];
1547 SkString subdir;
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001548 subdir.appendf("%s%c%s", FLAGS_writePath[0], SkPATH_SEPARATOR,
epoger@google.come8ebeb12012-10-29 16:42:11 +00001549 config.fName);
1550 if (!sk_mkdir(subdir.c_str())) {
1551 return -1;
1552 }
1553 }
1554 }
1555 }
1556
bsalomon@google.com7361f542012-04-19 19:15:35 +00001557 Iter iter;
1558 GM* gm;
reed@android.com00dae862009-06-10 15:38:48 +00001559 while ((gm = iter.next()) != NULL) {
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +00001560
reed@google.comae7b8f32012-10-18 21:30:57 +00001561 ++gmIndex;
epoger@google.com82cb65b2012-10-29 18:59:17 +00001562 if (moduloRemainder >= 0) {
1563 if ((gmIndex % moduloDivisor) != moduloRemainder) {
reed@google.comae7b8f32012-10-18 21:30:57 +00001564 continue;
1565 }
epoger@google.com82cb65b2012-10-29 18:59:17 +00001566 moduloStr.printf("[%d.%d] ", gmIndex, moduloDivisor);
reed@google.comae7b8f32012-10-18 21:30:57 +00001567 }
1568
reed@google.comece2b022011-07-25 14:28:57 +00001569 const char* shortName = gm->shortName();
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001570 if (skip_name(FLAGS_match, shortName)) {
reed@google.comece2b022011-07-25 14:28:57 +00001571 SkDELETE(gm);
1572 continue;
1573 }
1574
tomhudson@google.com9875dd12011-04-25 15:49:53 +00001575 SkISize size = gm->getISize();
epoger@google.com5efdd0c2013-03-13 14:18:40 +00001576 gm_fprintf(stdout, "%sdrawing... %s [%d %d]\n", moduloStr.c_str(), shortName,
1577 size.width(), size.height());
djsollen@google.comebce16d2012-10-26 14:07:13 +00001578
epoger@google.comeb066362013-03-08 09:39:36 +00001579 ErrorBitfield testErrors = kEmptyErrorBitfield;
epoger@google.com0b62b3d2013-03-20 17:59:28 +00001580 testErrors |= run_multiple_configs(gmmain, gm, configs, grFactory);
djsollen@google.comebce16d2012-10-26 14:07:13 +00001581
1582 SkBitmap comparisonBitmap;
1583 const ConfigData compareConfig =
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001584 { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "comparison", false };
epoger@google.comde961632012-10-26 18:56:36 +00001585 testErrors |= gmmain.generate_image(gm, compareConfig, NULL, NULL, &comparisonBitmap, false);
djsollen@google.comebce16d2012-10-26 14:07:13 +00001586
epoger@google.com0b62b3d2013-03-20 17:59:28 +00001587 // TODO(epoger): only run this if gmmain.generate_image() succeeded?
1588 // Otherwise, what are we comparing against?
1589 testErrors |= run_multiple_modes(gmmain, gm, compareConfig, comparisonBitmap);
djsollen@google.comebce16d2012-10-26 14:07:13 +00001590
1591 // Update overall results.
1592 // We only tabulate the particular error types that we currently
1593 // care about (e.g., missing reference images). Later on, if we
epoger@google.com37269602013-01-19 04:21:27 +00001594 // want to also tabulate other error types, we can do so.
djsollen@google.comebce16d2012-10-26 14:07:13 +00001595 testsRun++;
epoger@google.com37269602013-01-19 04:21:27 +00001596 if (!gmmain.fExpectationsSource.get() ||
epoger@google.comeb066362013-03-08 09:39:36 +00001597 (kEmptyErrorBitfield != (kMissingExpectations_ErrorBitmask & testErrors))) {
djsollen@google.comebce16d2012-10-26 14:07:13 +00001598 testsMissingReferenceImages++;
borenet@google.coma904ea12013-02-21 18:34:14 +00001599 }
epoger@google.comeb066362013-03-08 09:39:36 +00001600 if (testErrors == (testErrors & kIgnorable_ErrorBitmask)) {
epoger@google.com3499f3c2013-01-10 17:11:27 +00001601 testsPassed++;
djsollen@google.comebce16d2012-10-26 14:07:13 +00001602 } else {
1603 testsFailed++;
1604 }
1605
reed@android.com00dae862009-06-10 15:38:48 +00001606 SkDELETE(gm);
1607 }
epoger@google.com5efdd0c2013-03-13 14:18:40 +00001608 gm_fprintf(stdout, "Ran %d tests: %d passed, %d failed, %d missing reference images\n",
1609 testsRun, testsPassed, testsFailed, testsMissingReferenceImages);
epoger@google.com57f7abc2012-11-13 03:41:55 +00001610 gmmain.ListErrors();
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00001611
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001612 if (FLAGS_writeJsonSummaryPath.count() == 1) {
epoger@google.comee8a8e32012-12-18 19:13:49 +00001613 Json::Value actualResults;
1614 actualResults[kJsonKey_ActualResults_Failed] =
1615 gmmain.fJsonActualResults_Failed;
1616 actualResults[kJsonKey_ActualResults_FailureIgnored] =
1617 gmmain.fJsonActualResults_FailureIgnored;
epoger@google.com9c56a8d2012-12-20 18:34:29 +00001618 actualResults[kJsonKey_ActualResults_NoComparison] =
1619 gmmain.fJsonActualResults_NoComparison;
epoger@google.comee8a8e32012-12-18 19:13:49 +00001620 actualResults[kJsonKey_ActualResults_Succeeded] =
1621 gmmain.fJsonActualResults_Succeeded;
1622 Json::Value root;
1623 root[kJsonKey_ActualResults] = actualResults;
1624 root[kJsonKey_ExpectedResults] = gmmain.fJsonExpectedResults;
1625 std::string jsonStdString = root.toStyledString();
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001626 SkFILEWStream stream(FLAGS_writeJsonSummaryPath[0]);
epoger@google.comee8a8e32012-12-18 19:13:49 +00001627 stream.write(jsonStdString.c_str(), jsonStdString.length());
1628 }
1629
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001630#if SK_SUPPORT_GPU
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00001631
robertphillips@google.com59552022012-08-31 13:07:37 +00001632#if GR_CACHE_STATS
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00001633 for (int i = 0; i < configs.count(); i++) {
1634 ConfigData config = gRec[configs[i]];
1635
1636 if (kGPU_Backend == config.fBackend) {
1637 GrContext* gr = grFactory->get(config.fGLContextType);
1638
epoger@google.com5efdd0c2013-03-13 14:18:40 +00001639 gm_fprintf(stdout, "config: %s %x\n", config.fName, gr);
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00001640 gr->printCacheStats();
1641 }
1642 }
1643#endif
1644
robertphillips@google.com977b9c82012-06-05 19:35:09 +00001645 delete grFactory;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001646#endif
robertphillips@google.com977b9c82012-06-05 19:35:09 +00001647 SkGraphics::Term();
1648
epoger@google.comc7cf2b32011-12-28 19:31:01 +00001649 return (0 == testsFailed) ? 0 : -1;
reed@android.com00dae862009-06-10 15:38:48 +00001650}
caryclark@google.com5987f582012-10-02 18:33:14 +00001651
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001652void GMMain::installFilter(SkCanvas* canvas) {
1653 if (FLAGS_forceBWtext) {
1654 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref();
1655 }
1656}
1657
borenet@google.com7158e6a2012-11-01 17:43:44 +00001658#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
caryclark@google.com5987f582012-10-02 18:33:14 +00001659int main(int argc, char * const argv[]) {
1660 return tool_main(argc, (char**) argv);
1661}
1662#endif