blob: 9774d9ee418219c9394c26fd7aef83e475862402 [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
epoger@google.com80724df2013-03-21 13:49:54 +000056class GrContextFactory;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000057class GrContext;
58class GrRenderTarget;
59typedef int GLContextType;
60#endif
61
reed@google.com8923c6c2011-11-08 14:59:38 +000062extern bool gSkSuppressFontCachePurgeSpew;
63
reed@google.com07700442010-12-20 19:46:07 +000064#ifdef SK_SUPPORT_PDF
tomhudson@google.com9875dd12011-04-25 15:49:53 +000065 #include "SkPDFDevice.h"
66 #include "SkPDFDocument.h"
reed@google.com07700442010-12-20 19:46:07 +000067#endif
reed@android.com00dae862009-06-10 15:38:48 +000068
epoger@google.come3cc2eb2012-01-18 20:11:13 +000069// Until we resolve http://code.google.com/p/skia/issues/detail?id=455 ,
70// stop writing out XPS-format image baselines in gm.
71#undef SK_SUPPORT_XPS
bungeman@google.comb29c8832011-10-10 13:19:10 +000072#ifdef SK_SUPPORT_XPS
73 #include "SkXPSDevice.h"
74#endif
75
reed@google.com46cce912011-06-29 12:54:46 +000076#ifdef SK_BUILD_FOR_MAC
77 #include "SkCGUtils.h"
bsalomon@google.com0a09eef2011-06-29 19:42:58 +000078 #define CAN_IMAGE_PDF 1
reed@google.com46cce912011-06-29 12:54:46 +000079#else
bsalomon@google.com0a09eef2011-06-29 19:42:58 +000080 #define CAN_IMAGE_PDF 0
reed@google.com46cce912011-06-29 12:54:46 +000081#endif
82
epoger@google.comc7cf2b32011-12-28 19:31:01 +000083typedef int ErrorBitfield;
epoger@google.comeb066362013-03-08 09:39:36 +000084// an empty bitfield means no errors:
85const static ErrorBitfield kEmptyErrorBitfield = 0x00;
86// individual error types:
87const static ErrorBitfield kNoGpuContext_ErrorBitmask = 0x01;
88const static ErrorBitfield kImageMismatch_ErrorBitmask = 0x02;
89const static ErrorBitfield kMissingExpectations_ErrorBitmask = 0x04;
90const static ErrorBitfield kWritingReferenceImage_ErrorBitmask = 0x08;
91// we typically ignore any errors matching this bitmask:
92const static ErrorBitfield kIgnorable_ErrorBitmask = kMissingExpectations_ErrorBitmask;
epoger@google.comc7cf2b32011-12-28 19:31:01 +000093
reed@android.com00dae862009-06-10 15:38:48 +000094using namespace skiagm;
95
epoger@google.com57f7abc2012-11-13 03:41:55 +000096struct FailRec {
97 SkString fName;
epoger@google.com15655b22013-01-08 18:47:31 +000098 bool fIsPixelError;
epoger@google.com57f7abc2012-11-13 03:41:55 +000099
epoger@google.com15655b22013-01-08 18:47:31 +0000100 FailRec() : fIsPixelError(false) {}
101 FailRec(const SkString& name) : fName(name), fIsPixelError(false) {}
epoger@google.com57f7abc2012-11-13 03:41:55 +0000102};
103
reed@android.com00dae862009-06-10 15:38:48 +0000104class Iter {
105public:
106 Iter() {
bsalomon@google.com39149582011-06-13 21:55:32 +0000107 this->reset();
108 }
109
110 void reset() {
reed@android.comdd0ac282009-06-20 02:38:16 +0000111 fReg = GMRegistry::Head();
reed@android.com00dae862009-06-10 15:38:48 +0000112 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000113
reed@android.comdd0ac282009-06-20 02:38:16 +0000114 GM* next() {
reed@android.com00dae862009-06-10 15:38:48 +0000115 if (fReg) {
reed@android.comdd0ac282009-06-20 02:38:16 +0000116 GMRegistry::Factory fact = fReg->factory();
reed@android.com00dae862009-06-10 15:38:48 +0000117 fReg = fReg->next();
reed@android.comdd0ac282009-06-20 02:38:16 +0000118 return fact(0);
reed@android.com00dae862009-06-10 15:38:48 +0000119 }
120 return NULL;
121 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000122
reed@android.com00dae862009-06-10 15:38:48 +0000123 static int Count() {
reed@android.comdd0ac282009-06-20 02:38:16 +0000124 const GMRegistry* reg = GMRegistry::Head();
reed@android.com00dae862009-06-10 15:38:48 +0000125 int count = 0;
126 while (reg) {
127 count += 1;
128 reg = reg->next();
129 }
130 return count;
131 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000132
reed@android.com00dae862009-06-10 15:38:48 +0000133private:
134 const GMRegistry* fReg;
135};
136
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000137enum Backend {
junov@chromium.org3cb834b2012-12-13 16:39:53 +0000138 kRaster_Backend,
139 kGPU_Backend,
140 kPDF_Backend,
141 kXPS_Backend,
142};
143
144enum BbhType {
145 kNone_BbhType,
146 kRTree_BbhType,
147 kTileGrid_BbhType,
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000148};
149
bsalomon@google.com7361f542012-04-19 19:15:35 +0000150enum ConfigFlags {
151 kNone_ConfigFlag = 0x0,
152 /* Write GM images if a write path is provided. */
153 kWrite_ConfigFlag = 0x1,
epoger@google.comf28dd8a2012-10-25 16:27:34 +0000154 /* Read reference GM images if a read path is provided. */
bsalomon@google.com7361f542012-04-19 19:15:35 +0000155 kRead_ConfigFlag = 0x2,
156 kRW_ConfigFlag = (kWrite_ConfigFlag | kRead_ConfigFlag),
157};
158
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000159struct ConfigData {
bsalomon@google.com7361f542012-04-19 19:15:35 +0000160 SkBitmap::Config fConfig;
161 Backend fBackend;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000162 GLContextType fGLContextType; // GPU backend only
bsalomon@google.com7361f542012-04-19 19:15:35 +0000163 int fSampleCnt; // GPU backend only
164 ConfigFlags fFlags;
165 const char* fName;
bsalomon@google.com4c75f242013-03-19 18:58:43 +0000166 bool fRunByDefault;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000167};
168
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000169class BWTextDrawFilter : public SkDrawFilter {
170public:
reed@google.com971aca72012-11-26 20:26:54 +0000171 virtual bool filter(SkPaint*, Type) SK_OVERRIDE;
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000172};
reed@google.com971aca72012-11-26 20:26:54 +0000173bool BWTextDrawFilter::filter(SkPaint* p, Type t) {
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000174 if (kText_Type == t) {
175 p->setAntiAlias(false);
176 }
reed@google.com971aca72012-11-26 20:26:54 +0000177 return true;
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000178}
179
scroggo@google.com565254b2012-06-28 15:41:32 +0000180struct PipeFlagComboData {
181 const char* name;
182 uint32_t flags;
183};
184
185static PipeFlagComboData gPipeWritingFlagCombos[] = {
186 { "", 0 },
187 { " cross-process", SkGPipeWriter::kCrossProcess_Flag },
scroggob3c0f482012-07-02 19:07:57 +0000188 { " cross-process, shared address", SkGPipeWriter::kCrossProcess_Flag
scroggo@google.com15011ee2012-07-26 20:03:32 +0000189 | SkGPipeWriter::kSharedAddressSpace_Flag }
scroggo@google.com565254b2012-06-28 15:41:32 +0000190};
191
epoger@google.comde961632012-10-26 18:56:36 +0000192class GMMain {
193public:
epoger@google.come8ebeb12012-10-29 16:42:11 +0000194 GMMain() {
195 // Set default values of member variables, which tool_main()
196 // may override.
epoger@google.come8ebeb12012-10-29 16:42:11 +0000197 fUseFileHierarchy = false;
junov@chromium.org95146eb2013-01-11 21:04:40 +0000198 fMismatchPath = NULL;
epoger@google.come8ebeb12012-10-29 16:42:11 +0000199 }
200
201 SkString make_name(const char shortName[], const char configName[]) {
202 SkString name;
epoger@google.com57f7abc2012-11-13 03:41:55 +0000203 if (0 == strlen(configName)) {
204 name.append(shortName);
205 } else if (fUseFileHierarchy) {
epoger@google.come8ebeb12012-10-29 16:42:11 +0000206 name.appendf("%s%c%s", configName, SkPATH_SEPARATOR, shortName);
207 } else {
208 name.appendf("%s_%s", shortName, configName);
209 }
epoger@google.comde961632012-10-26 18:56:36 +0000210 return name;
211 }
212
epoger@google.com5f6a0072013-01-31 16:30:55 +0000213 /* since PNG insists on unpremultiplying our alpha, we take no
214 precision chances and force all pixels to be 100% opaque,
215 otherwise on compare we may not get a perfect match.
216 */
217 static void force_all_opaque(const SkBitmap& bitmap) {
218 SkBitmap::Config config = bitmap.config();
219 switch (config) {
220 case SkBitmap::kARGB_8888_Config:
221 force_all_opaque_8888(bitmap);
222 break;
223 case SkBitmap::kRGB_565_Config:
224 // nothing to do here; 565 bitmaps are inherently opaque
225 break;
226 default:
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000227 gm_fprintf(stderr, "unsupported bitmap config %d\n", config);
228 DEBUGFAIL_SEE_STDERR;
epoger@google.com5f6a0072013-01-31 16:30:55 +0000229 }
230 }
231
232 static void force_all_opaque_8888(const SkBitmap& bitmap) {
233 SkAutoLockPixels lock(bitmap);
234 for (int y = 0; y < bitmap.height(); y++) {
235 for (int x = 0; x < bitmap.width(); x++) {
236 *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT);
237 }
238 }
239 }
240
241 static bool write_bitmap(const SkString& path, const SkBitmap& bitmap) {
242 // TODO(epoger): Now that we have removed force_all_opaque()
243 // from this method, we should be able to get rid of the
244 // transformation to 8888 format also.
245 SkBitmap copy;
246 bitmap.copyTo(&copy, SkBitmap::kARGB_8888_Config);
247 return SkImageEncoder::EncodeFile(path.c_str(), copy,
248 SkImageEncoder::kPNG_Type, 100);
249 }
250
251 // Records an error in fFailedTests, if we want to record errors
252 // of this type.
253 void RecordError(ErrorBitfield errorType, const SkString& name,
254 const char renderModeDescriptor []) {
epoger@google.comeb066362013-03-08 09:39:36 +0000255 // The common case: no error means nothing to record.
256 if (kEmptyErrorBitfield == errorType) {
epoger@google.com5f6a0072013-01-31 16:30:55 +0000257 return;
epoger@google.comeb066362013-03-08 09:39:36 +0000258 }
259
260 // If only certain error type(s) were reported, we know we can ignore them.
261 if (errorType == (errorType & kIgnorable_ErrorBitmask)) {
epoger@google.com5f6a0072013-01-31 16:30:55 +0000262 return;
epoger@google.com5f6a0072013-01-31 16:30:55 +0000263 }
264
265 FailRec& rec = fFailedTests.push_back(make_name(
266 name.c_str(), renderModeDescriptor));
epoger@google.comeb066362013-03-08 09:39:36 +0000267 rec.fIsPixelError =
268 (kEmptyErrorBitfield != (errorType & kImageMismatch_ErrorBitmask));
epoger@google.com5f6a0072013-01-31 16:30:55 +0000269 }
270
271 // List contents of fFailedTests via SkDebug.
272 void ListErrors() {
273 for (int i = 0; i < fFailedTests.count(); ++i) {
274 if (fFailedTests[i].fIsPixelError) {
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000275 gm_fprintf(stderr, "\t\t%s pixel_error\n", fFailedTests[i].fName.c_str());
epoger@google.com5f6a0072013-01-31 16:30:55 +0000276 } else {
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000277 gm_fprintf(stderr, "\t\t%s\n", fFailedTests[i].fName.c_str());
epoger@google.com5f6a0072013-01-31 16:30:55 +0000278 }
279 }
280 }
281
282 static bool write_document(const SkString& path,
283 const SkDynamicMemoryWStream& document) {
284 SkFILEWStream stream(path.c_str());
285 SkAutoDataUnref data(document.copyToData());
286 return stream.writeData(data.get());
287 }
288
epoger@google.com37269602013-01-19 04:21:27 +0000289 /**
epoger@google.com5f6a0072013-01-31 16:30:55 +0000290 * Prepare an SkBitmap to render a GM into.
291 *
292 * After you've rendered the GM into the SkBitmap, you must call
293 * complete_bitmap()!
294 *
295 * @todo thudson 22 April 2011 - could refactor this to take in
296 * a factory to generate the context, always call readPixels()
297 * (logically a noop for rasters, if wasted time), and thus collapse the
298 * GPU special case and also let this be used for SkPicture testing.
299 */
300 static void setup_bitmap(const ConfigData& gRec, SkISize& size,
301 SkBitmap* bitmap) {
302 bitmap->setConfig(gRec.fConfig, size.width(), size.height());
303 bitmap->allocPixels();
304 bitmap->eraseColor(SK_ColorTRANSPARENT);
305 }
306
307 /**
308 * Any finalization steps we need to perform on the SkBitmap after
309 * we have rendered the GM into it.
epoger@google.com37269602013-01-19 04:21:27 +0000310 *
311 * It's too bad that we are throwing away alpha channel data
312 * we could otherwise be examining, but this had always been happening
313 * before... it was buried within the compare() method at
314 * https://code.google.com/p/skia/source/browse/trunk/gm/gmmain.cpp?r=7289#305 .
315 *
316 * Apparently we need this, at least for bitmaps that are either:
317 * (a) destined to be written out as PNG files, or
318 * (b) compared against bitmaps read in from PNG files
319 * for the reasons described just above the force_all_opaque() method.
320 *
321 * Neglecting to do this led to the difficult-to-diagnose
322 * http://code.google.com/p/skia/issues/detail?id=1079 ('gm generating
323 * spurious pixel_error messages as of r7258')
324 *
325 * TODO(epoger): Come up with a better solution that allows us to
326 * compare full pixel data, including alpha channel, while still being
327 * robust in the face of transformations to/from PNG files.
328 * Options include:
329 *
330 * 1. Continue to call force_all_opaque(), but ONLY for bitmaps that
331 * will be written to, or compared against, PNG files.
332 * PRO: Preserve/compare alpha channel info for the non-PNG cases
333 * (comparing different renderModes in-memory)
334 * CON: The bitmaps (and checksums) for these non-PNG cases would be
335 * different than those for the PNG-compared cases, and in the
336 * case of a failed renderMode comparison, how would we write the
337 * image to disk for examination?
338 *
339 * 2. Always compute image checksums from PNG format (either
340 * directly from the the bytes of a PNG file, or capturing the
341 * bytes we would have written to disk if we were writing the
342 * bitmap out as a PNG).
343 * PRO: I think this would allow us to never force opaque, and to
344 * the extent that alpha channel data can be preserved in a PNG
345 * file, we could observe it.
346 * CON: If we read a bitmap from disk, we need to take its checksum
347 * from the source PNG (we can't compute it from the bitmap we
348 * read out of the PNG, because we will have already premultiplied
349 * the alpha).
350 * CON: Seems wasteful to convert a bitmap to PNG format just to take
351 * its checksum. (Although we're wasting lots of effort already
352 * calling force_all_opaque().)
353 *
354 * 3. Make the alpha premultiply/unpremultiply routines 100% consistent,
355 * so we can transform images back and forth without fear of off-by-one
356 * errors.
357 * CON: Math is hard.
358 *
359 * 4. Perform a "close enough" comparison of bitmaps (+/- 1 bit in each
360 * channel), rather than demanding absolute equality.
361 * CON: Can't do this with checksums.
362 */
epoger@google.com5f6a0072013-01-31 16:30:55 +0000363 static void complete_bitmap(SkBitmap* bitmap) {
364 force_all_opaque(*bitmap);
epoger@google.comde961632012-10-26 18:56:36 +0000365 }
366
scroggo@google.com09fd4d22013-03-20 14:20:18 +0000367 static void installFilter(SkCanvas* canvas);
epoger@google.comde961632012-10-26 18:56:36 +0000368
reed@google.comaef73612012-11-16 13:41:45 +0000369 static void invokeGM(GM* gm, SkCanvas* canvas, bool isPDF, bool isDeferred) {
epoger@google.comde961632012-10-26 18:56:36 +0000370 SkAutoCanvasRestore acr(canvas, true);
371
372 if (!isPDF) {
373 canvas->concat(gm->getInitialTransform());
374 }
375 installFilter(canvas);
reed@google.comaef73612012-11-16 13:41:45 +0000376 gm->setCanvasIsDeferred(isDeferred);
epoger@google.comde961632012-10-26 18:56:36 +0000377 gm->draw(canvas);
378 canvas->setDrawFilter(NULL);
379 }
380
381 static ErrorBitfield generate_image(GM* gm, const ConfigData& gRec,
382 GrContext* context,
383 GrRenderTarget* rt,
384 SkBitmap* bitmap,
385 bool deferred) {
386 SkISize size (gm->getISize());
387 setup_bitmap(gRec, size, bitmap);
388
389 SkAutoTUnref<SkCanvas> canvas;
390
391 if (gRec.fBackend == kRaster_Backend) {
392 SkAutoTUnref<SkDevice> device(new SkDevice(*bitmap));
393 if (deferred) {
394 canvas.reset(new SkDeferredCanvas(device));
395 } else {
396 canvas.reset(new SkCanvas(device));
397 }
reed@google.comaef73612012-11-16 13:41:45 +0000398 invokeGM(gm, canvas, false, deferred);
epoger@google.comde961632012-10-26 18:56:36 +0000399 canvas->flush();
400 }
401#if SK_SUPPORT_GPU
402 else { // GPU
403 if (NULL == context) {
epoger@google.comeb066362013-03-08 09:39:36 +0000404 return kNoGpuContext_ErrorBitmask;
epoger@google.comde961632012-10-26 18:56:36 +0000405 }
406 SkAutoTUnref<SkDevice> device(new SkGpuDevice(context, rt));
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 // the device is as large as the current rendertarget, so
414 // we explicitly only readback the amount we expect (in
415 // size) overwrite our previous allocation
416 bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth,
417 size.fHeight);
418 canvas->readPixels(bitmap, 0, 0);
419 }
420#endif
epoger@google.com5f6a0072013-01-31 16:30:55 +0000421 complete_bitmap(bitmap);
epoger@google.comeb066362013-03-08 09:39:36 +0000422 return kEmptyErrorBitfield;
epoger@google.comde961632012-10-26 18:56:36 +0000423 }
424
425 static void generate_image_from_picture(GM* gm, const ConfigData& gRec,
junov@chromium.orgc938c482012-12-19 15:24:38 +0000426 SkPicture* pict, SkBitmap* bitmap,
427 SkScalar scale = SK_Scalar1) {
epoger@google.comde961632012-10-26 18:56:36 +0000428 SkISize size = gm->getISize();
429 setup_bitmap(gRec, size, bitmap);
430 SkCanvas canvas(*bitmap);
431 installFilter(&canvas);
junov@chromium.orgc938c482012-12-19 15:24:38 +0000432 canvas.scale(scale, scale);
epoger@google.comde961632012-10-26 18:56:36 +0000433 canvas.drawPicture(*pict);
epoger@google.com5f6a0072013-01-31 16:30:55 +0000434 complete_bitmap(bitmap);
epoger@google.comde961632012-10-26 18:56:36 +0000435 }
436
437 static void generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) {
438#ifdef SK_SUPPORT_PDF
439 SkMatrix initialTransform = gm->getInitialTransform();
440 SkISize pageSize = gm->getISize();
441 SkPDFDevice* dev = NULL;
442 if (initialTransform.isIdentity()) {
443 dev = new SkPDFDevice(pageSize, pageSize, initialTransform);
444 } else {
445 SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()),
446 SkIntToScalar(pageSize.height()));
447 initialTransform.mapRect(&content);
448 content.intersect(0, 0, SkIntToScalar(pageSize.width()),
449 SkIntToScalar(pageSize.height()));
450 SkISize contentSize =
451 SkISize::Make(SkScalarRoundToInt(content.width()),
452 SkScalarRoundToInt(content.height()));
453 dev = new SkPDFDevice(pageSize, contentSize, initialTransform);
454 }
455 SkAutoUnref aur(dev);
456
457 SkCanvas c(dev);
reed@google.comaef73612012-11-16 13:41:45 +0000458 invokeGM(gm, &c, true, false);
epoger@google.comde961632012-10-26 18:56:36 +0000459
460 SkPDFDocument doc;
461 doc.appendPage(dev);
462 doc.emitPDF(&pdf);
463#endif
464 }
465
466 static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) {
467#ifdef SK_SUPPORT_XPS
468 SkISize size = gm->getISize();
469
470 SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()),
471 SkIntToScalar(size.height()));
472 static const SkScalar inchesPerMeter = SkScalarDiv(10000, 254);
473 static const SkScalar upm = 72 * inchesPerMeter;
474 SkVector unitsPerMeter = SkPoint::Make(upm, upm);
475 static const SkScalar ppm = 200 * inchesPerMeter;
476 SkVector pixelsPerMeter = SkPoint::Make(ppm, ppm);
477
478 SkXPSDevice* dev = new SkXPSDevice();
479 SkAutoUnref aur(dev);
480
481 SkCanvas c(dev);
482 dev->beginPortfolio(&xps);
483 dev->beginSheet(unitsPerMeter, pixelsPerMeter, trimSize);
reed@google.comaef73612012-11-16 13:41:45 +0000484 invokeGM(gm, &c, false, false);
epoger@google.comde961632012-10-26 18:56:36 +0000485 dev->endSheet();
486 dev->endPortfolio();
487
488#endif
489 }
490
epoger@google.com57f7abc2012-11-13 03:41:55 +0000491 ErrorBitfield write_reference_image(
epoger@google.comde961632012-10-26 18:56:36 +0000492 const ConfigData& gRec, const char writePath [],
493 const char renderModeDescriptor [], const SkString& name,
494 SkBitmap& bitmap, SkDynamicMemoryWStream* document) {
495 SkString path;
496 bool success = false;
497 if (gRec.fBackend == kRaster_Backend ||
498 gRec.fBackend == kGPU_Backend ||
499 (gRec.fBackend == kPDF_Backend && CAN_IMAGE_PDF)) {
500
epoger@google.com37269602013-01-19 04:21:27 +0000501 path = make_filename(writePath, renderModeDescriptor, name.c_str(),
502 "png");
epoger@google.comde961632012-10-26 18:56:36 +0000503 success = write_bitmap(path, bitmap);
504 }
505 if (kPDF_Backend == gRec.fBackend) {
epoger@google.com37269602013-01-19 04:21:27 +0000506 path = make_filename(writePath, renderModeDescriptor, name.c_str(),
507 "pdf");
epoger@google.comde961632012-10-26 18:56:36 +0000508 success = write_document(path, *document);
509 }
510 if (kXPS_Backend == gRec.fBackend) {
epoger@google.com37269602013-01-19 04:21:27 +0000511 path = make_filename(writePath, renderModeDescriptor, name.c_str(),
512 "xps");
epoger@google.comde961632012-10-26 18:56:36 +0000513 success = write_document(path, *document);
514 }
515 if (success) {
epoger@google.comeb066362013-03-08 09:39:36 +0000516 return kEmptyErrorBitfield;
epoger@google.comde961632012-10-26 18:56:36 +0000517 } else {
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000518 gm_fprintf(stderr, "FAILED to write %s\n", path.c_str());
epoger@google.comeb066362013-03-08 09:39:36 +0000519 RecordError(kWritingReferenceImage_ErrorBitmask, name,
epoger@google.com57f7abc2012-11-13 03:41:55 +0000520 renderModeDescriptor);
epoger@google.comeb066362013-03-08 09:39:36 +0000521 return kWritingReferenceImage_ErrorBitmask;
epoger@google.comde961632012-10-26 18:56:36 +0000522 }
523 }
524
epoger@google.com37269602013-01-19 04:21:27 +0000525 /**
epoger@google.com84a18022013-02-01 20:39:15 +0000526 * Log more detail about the mistmatch between expectedBitmap and
527 * actualBitmap.
528 */
529 void report_bitmap_diffs(const SkBitmap& expectedBitmap, const SkBitmap& actualBitmap,
530 const char *testName) {
531 const int expectedWidth = expectedBitmap.width();
532 const int expectedHeight = expectedBitmap.height();
533 const int width = actualBitmap.width();
534 const int height = actualBitmap.height();
535 if ((expectedWidth != width) || (expectedHeight != height)) {
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000536 gm_fprintf(stderr, "---- %s: dimension mismatch --"
537 " expected [%d %d], actual [%d %d]\n",
538 testName, expectedWidth, expectedHeight, width, height);
epoger@google.com84a18022013-02-01 20:39:15 +0000539 return;
540 }
541
542 if ((SkBitmap::kARGB_8888_Config != expectedBitmap.config()) ||
543 (SkBitmap::kARGB_8888_Config != actualBitmap.config())) {
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000544 gm_fprintf(stderr, "---- %s: not computing max per-channel"
545 " pixel mismatch because non-8888\n", testName);
epoger@google.com84a18022013-02-01 20:39:15 +0000546 return;
547 }
548
549 SkAutoLockPixels alp0(expectedBitmap);
550 SkAutoLockPixels alp1(actualBitmap);
551 int errR = 0;
552 int errG = 0;
553 int errB = 0;
554 int errA = 0;
555 int differingPixels = 0;
556
557 for (int y = 0; y < height; ++y) {
558 const SkPMColor* expectedPixelPtr = expectedBitmap.getAddr32(0, y);
559 const SkPMColor* actualPixelPtr = actualBitmap.getAddr32(0, y);
560 for (int x = 0; x < width; ++x) {
561 SkPMColor expectedPixel = *expectedPixelPtr++;
562 SkPMColor actualPixel = *actualPixelPtr++;
563 if (expectedPixel != actualPixel) {
564 differingPixels++;
565 errR = SkMax32(errR, SkAbs32((int)SkGetPackedR32(expectedPixel) -
566 (int)SkGetPackedR32(actualPixel)));
567 errG = SkMax32(errG, SkAbs32((int)SkGetPackedG32(expectedPixel) -
568 (int)SkGetPackedG32(actualPixel)));
569 errB = SkMax32(errB, SkAbs32((int)SkGetPackedB32(expectedPixel) -
570 (int)SkGetPackedB32(actualPixel)));
571 errA = SkMax32(errA, SkAbs32((int)SkGetPackedA32(expectedPixel) -
572 (int)SkGetPackedA32(actualPixel)));
573 }
574 }
575 }
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000576 gm_fprintf(stderr, "---- %s: %d (of %d) differing pixels,"
577 " max per-channel mismatch R=%d G=%d B=%d A=%d\n",
578 testName, differingPixels, width*height, errR, errG, errB, errA);
epoger@google.com84a18022013-02-01 20:39:15 +0000579 }
580
581 /**
epoger@google.comeb066362013-03-08 09:39:36 +0000582 * Compares actual checksum to expectations. Returns
583 * kEmptyErrorBitfield if they match, or some combination of
584 * _ErrorBitmask values otherwise.
epoger@google.com37269602013-01-19 04:21:27 +0000585 *
586 * If fMismatchPath has been set, and there are pixel diffs, then the
587 * actual bitmap will be written out to a file within fMismatchPath.
588 *
589 * @param expectations what expectations to compare actualBitmap against
590 * @param actualBitmap the image we actually generated
591 * @param baseNameString name of test without renderModeDescriptor added
592 * @param renderModeDescriptor e.g., "-rtree", "-deferred"
593 * @param addToJsonSummary whether to add these results (both actual and
594 * expected) to the JSON summary
595 *
596 * TODO: For now, addToJsonSummary is only set to true within
597 * compare_test_results_to_stored_expectations(), so results of our
598 * in-memory comparisons (Rtree vs regular, etc.) are not written to the
599 * JSON summary. We may wish to change that.
600 */
601 ErrorBitfield compare_to_expectations(Expectations expectations,
602 const SkBitmap& actualBitmap,
603 const SkString& baseNameString,
604 const char renderModeDescriptor[],
605 bool addToJsonSummary=false) {
epoger@google.comee8a8e32012-12-18 19:13:49 +0000606 ErrorBitfield retval;
epoger@google.com5f6a0072013-01-31 16:30:55 +0000607 Checksum actualChecksum = SkBitmapChecksummer::Compute64(actualBitmap);
epoger@google.com37269602013-01-19 04:21:27 +0000608 SkString completeNameString = baseNameString;
609 completeNameString.append(renderModeDescriptor);
610 const char* completeName = completeNameString.c_str();
epoger@google.comee8a8e32012-12-18 19:13:49 +0000611
epoger@google.com37269602013-01-19 04:21:27 +0000612 if (expectations.empty()) {
epoger@google.comeb066362013-03-08 09:39:36 +0000613 retval = kMissingExpectations_ErrorBitmask;
epoger@google.com37269602013-01-19 04:21:27 +0000614 } else if (expectations.match(actualChecksum)) {
epoger@google.comeb066362013-03-08 09:39:36 +0000615 retval = kEmptyErrorBitfield;
epoger@google.com9ef89ce2013-01-18 21:45:42 +0000616 } else {
epoger@google.comeb066362013-03-08 09:39:36 +0000617 retval = kImageMismatch_ErrorBitmask;
epoger@google.com84a18022013-02-01 20:39:15 +0000618
619 // Write out the "actuals" for any mismatches, if we have
620 // been directed to do so.
epoger@google.com37269602013-01-19 04:21:27 +0000621 if (fMismatchPath) {
622 SkString path =
623 make_filename(fMismatchPath, renderModeDescriptor,
624 baseNameString.c_str(), "png");
625 write_bitmap(path, actualBitmap);
626 }
epoger@google.com84a18022013-02-01 20:39:15 +0000627
628 // If we have access to a single expected bitmap, log more
629 // detail about the mismatch.
630 const SkBitmap *expectedBitmapPtr = expectations.asBitmap();
631 if (NULL != expectedBitmapPtr) {
632 report_bitmap_diffs(*expectedBitmapPtr, actualBitmap, completeName);
633 }
epoger@google.coma243b222013-01-17 17:54:28 +0000634 }
epoger@google.com37269602013-01-19 04:21:27 +0000635 RecordError(retval, baseNameString, renderModeDescriptor);
epoger@google.coma243b222013-01-17 17:54:28 +0000636
epoger@google.com37269602013-01-19 04:21:27 +0000637 if (addToJsonSummary) {
638 add_actual_results_to_json_summary(completeName, actualChecksum,
639 retval,
640 expectations.ignoreFailure());
641 add_expected_results_to_json_summary(completeName, expectations);
642 }
epoger@google.coma243b222013-01-17 17:54:28 +0000643
epoger@google.combc159bd2013-01-15 20:24:03 +0000644 return retval;
epoger@google.com06b8a192013-01-15 19:10:16 +0000645 }
646
epoger@google.com37269602013-01-19 04:21:27 +0000647 /**
648 * Add this result to the appropriate JSON collection of actual results,
649 * depending on status.
650 */
651 void add_actual_results_to_json_summary(const char testName[],
652 Checksum actualChecksum,
653 ErrorBitfield result,
654 bool ignoreFailure) {
655 Json::Value actualResults;
656 actualResults[kJsonKey_ActualResults_AnyStatus_Checksum] =
657 asJsonValue(actualChecksum);
epoger@google.comeb066362013-03-08 09:39:36 +0000658 if (kEmptyErrorBitfield == result) {
epoger@google.com37269602013-01-19 04:21:27 +0000659 this->fJsonActualResults_Succeeded[testName] = actualResults;
660 } else {
661 if (ignoreFailure) {
662 // TODO: Once we have added the ability to compare
663 // actual results against expectations in a JSON file
664 // (where we can set ignore-failure to either true or
epoger@google.com84a18022013-02-01 20:39:15 +0000665 // false), add test cases that exercise ignored
epoger@google.comeb066362013-03-08 09:39:36 +0000666 // failures (both for kMissingExpectations_ErrorBitmask
667 // and kImageMismatch_ErrorBitmask).
epoger@google.com37269602013-01-19 04:21:27 +0000668 this->fJsonActualResults_FailureIgnored[testName] =
669 actualResults;
670 } else {
epoger@google.comeb066362013-03-08 09:39:36 +0000671 if (kEmptyErrorBitfield != (result & kMissingExpectations_ErrorBitmask)) {
epoger@google.com37269602013-01-19 04:21:27 +0000672 // TODO: What about the case where there IS an
673 // expected image checksum, but that gm test
674 // doesn't actually run? For now, those cases
675 // will always be ignored, because gm only looks
676 // at expectations that correspond to gm tests
677 // that were actually run.
678 //
679 // Once we have the ability to express
680 // expectations as a JSON file, we should fix this
681 // (and add a test case for which an expectation
682 // is given but the test is never run).
683 this->fJsonActualResults_NoComparison[testName] =
684 actualResults;
epoger@google.comeb066362013-03-08 09:39:36 +0000685 }
686 if (kEmptyErrorBitfield != (result & kImageMismatch_ErrorBitmask)) {
epoger@google.com37269602013-01-19 04:21:27 +0000687 this->fJsonActualResults_Failed[testName] = actualResults;
epoger@google.com37269602013-01-19 04:21:27 +0000688 }
689 }
690 }
691 }
692
693 /**
694 * Add this test to the JSON collection of expected results.
695 */
696 void add_expected_results_to_json_summary(const char testName[],
697 Expectations expectations) {
698 // For now, we assume that this collection starts out empty and we
699 // just fill it in as we go; once gm accepts a JSON file as input,
700 // we'll have to change that.
701 Json::Value expectedResults;
702 expectedResults[kJsonKey_ExpectedResults_Checksums] =
703 expectations.allowedChecksumsAsJson();
704 expectedResults[kJsonKey_ExpectedResults_IgnoreFailure] =
705 expectations.ignoreFailure();
706 this->fJsonExpectedResults[testName] = expectedResults;
707 }
708
709 /**
710 * Compare actualBitmap to expectations stored in this->fExpectationsSource.
711 *
712 * @param gm which test generated the actualBitmap
713 * @param gRec
714 * @param writePath unless this is NULL, write out actual images into this
715 * directory
716 * @param actualBitmap bitmap generated by this run
717 * @param pdf
718 */
719 ErrorBitfield compare_test_results_to_stored_expectations(
720 GM* gm, const ConfigData& gRec, const char writePath[],
721 SkBitmap& actualBitmap, SkDynamicMemoryWStream* pdf) {
722
epoger@google.coma243b222013-01-17 17:54:28 +0000723 SkString name = make_name(gm->shortName(), gRec.fName);
epoger@google.comeb066362013-03-08 09:39:36 +0000724 ErrorBitfield retval = kEmptyErrorBitfield;
epoger@google.com9ef89ce2013-01-18 21:45:42 +0000725
epoger@google.com37269602013-01-19 04:21:27 +0000726 ExpectationsSource *expectationsSource =
727 this->fExpectationsSource.get();
728 if (expectationsSource && (gRec.fFlags & kRead_ConfigFlag)) {
729 /*
730 * Get the expected results for this test, as one or more allowed
731 * checksums. The current implementation of expectationsSource
732 * get this by computing the checksum of a single PNG file on disk.
733 *
734 * TODO(epoger): This relies on the fact that
735 * force_all_opaque() was called on the bitmap before it
736 * was written to disk as a PNG in the first place. If
737 * not, the checksum returned here may not match the
738 * checksum of actualBitmap, which *has* been run through
739 * force_all_opaque().
epoger@google.com5f6a0072013-01-31 16:30:55 +0000740 * See comments above complete_bitmap() for more detail.
epoger@google.com37269602013-01-19 04:21:27 +0000741 */
742 Expectations expectations = expectationsSource->get(name.c_str());
743 retval |= compare_to_expectations(expectations, actualBitmap,
744 name, "", true);
745 } else {
746 // If we are running without expectations, we still want to
epoger@google.com9ef89ce2013-01-18 21:45:42 +0000747 // record the actual results.
epoger@google.com5f6a0072013-01-31 16:30:55 +0000748 Checksum actualChecksum =
749 SkBitmapChecksummer::Compute64(actualBitmap);
epoger@google.com37269602013-01-19 04:21:27 +0000750 add_actual_results_to_json_summary(name.c_str(), actualChecksum,
epoger@google.comeb066362013-03-08 09:39:36 +0000751 kMissingExpectations_ErrorBitmask,
epoger@google.com37269602013-01-19 04:21:27 +0000752 false);
epoger@google.com9ef89ce2013-01-18 21:45:42 +0000753 }
epoger@google.com37269602013-01-19 04:21:27 +0000754
755 // TODO: Consider moving this into compare_to_expectations(),
756 // similar to fMismatchPath... for now, we don't do that, because
757 // we don't want to write out the actual bitmaps for all
758 // renderModes of all tests! That would be a lot of files.
epoger@google.com9ef89ce2013-01-18 21:45:42 +0000759 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) {
epoger@google.com37269602013-01-19 04:21:27 +0000760 retval |= write_reference_image(gRec, writePath, "",
761 name, actualBitmap, pdf);
epoger@google.com9ef89ce2013-01-18 21:45:42 +0000762 }
epoger@google.com37269602013-01-19 04:21:27 +0000763
epoger@google.com9ef89ce2013-01-18 21:45:42 +0000764 return retval;
epoger@google.coma243b222013-01-17 17:54:28 +0000765 }
766
epoger@google.com37269602013-01-19 04:21:27 +0000767 /**
768 * Compare actualBitmap to referenceBitmap.
769 *
770 * @param gm which test generated the bitmap
771 * @param gRec
772 * @param renderModeDescriptor
773 * @param actualBitmap actual bitmap generated by this run
774 * @param referenceBitmap bitmap we expected to be generated
775 */
776 ErrorBitfield compare_test_results_to_reference_bitmap(
777 GM* gm, const ConfigData& gRec, const char renderModeDescriptor [],
778 SkBitmap& actualBitmap, const SkBitmap* referenceBitmap) {
779
780 SkASSERT(referenceBitmap);
781 SkString name = make_name(gm->shortName(), gRec.fName);
epoger@google.com84a18022013-02-01 20:39:15 +0000782 Expectations expectations(*referenceBitmap);
epoger@google.com37269602013-01-19 04:21:27 +0000783 return compare_to_expectations(expectations, actualBitmap,
784 name, renderModeDescriptor);
785 }
786
junov@chromium.org20bd04e2013-01-16 18:43:36 +0000787 static SkPicture* generate_new_picture(GM* gm, BbhType bbhType, uint32_t recordFlags,
788 SkScalar scale = SK_Scalar1) {
epoger@google.comde961632012-10-26 18:56:36 +0000789 // Pictures are refcounted so must be on heap
junov@chromium.org3cb834b2012-12-13 16:39:53 +0000790 SkPicture* pict;
junov@chromium.org706ff2f2012-12-19 15:55:40 +0000791 int width = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().width()), scale));
792 int height = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().height()), scale));
skia.committer@gmail.comd8b27992012-12-20 02:01:41 +0000793
junov@chromium.org3cb834b2012-12-13 16:39:53 +0000794 if (kTileGrid_BbhType == bbhType) {
junov@chromium.org29b19e52013-02-27 18:35:16 +0000795 SkTileGridPicture::TileGridInfo info;
796 info.fMargin.setEmpty();
797 info.fOffset.setZero();
798 info.fTileInterval.set(16, 16);
799 pict = new SkTileGridPicture(width, height, info);
junov@chromium.org3cb834b2012-12-13 16:39:53 +0000800 } else {
801 pict = new SkPicture;
802 }
junov@chromium.org20bd04e2013-01-16 18:43:36 +0000803 if (kNone_BbhType != bbhType) {
804 recordFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag;
805 }
junov@chromium.org706ff2f2012-12-19 15:55:40 +0000806 SkCanvas* cv = pict->beginRecording(width, height, recordFlags);
junov@chromium.orgc938c482012-12-19 15:24:38 +0000807 cv->scale(scale, scale);
reed@google.comaef73612012-11-16 13:41:45 +0000808 invokeGM(gm, cv, false, false);
epoger@google.comde961632012-10-26 18:56:36 +0000809 pict->endRecording();
810
811 return pict;
812 }
813
814 static SkPicture* stream_to_new_picture(const SkPicture& src) {
815
816 // To do in-memory commiunications with a stream, we need to:
817 // * create a dynamic memory stream
818 // * copy it into a buffer
819 // * create a read stream from it
820 // ?!?!
821
822 SkDynamicMemoryWStream storage;
823 src.serialize(&storage);
824
scroggo@google.com09fd4d22013-03-20 14:20:18 +0000825 size_t streamSize = storage.getOffset();
epoger@google.comde961632012-10-26 18:56:36 +0000826 SkAutoMalloc dstStorage(streamSize);
827 void* dst = dstStorage.get();
828 //char* dst = new char [streamSize];
829 //@todo thudson 22 April 2011 when can we safely delete [] dst?
830 storage.copyTo(dst);
831 SkMemoryStream pictReadback(dst, streamSize);
832 SkPicture* retval = new SkPicture (&pictReadback);
833 return retval;
834 }
835
836 // Test: draw into a bitmap or pdf.
epoger@google.com15655b22013-01-08 18:47:31 +0000837 // Depending on flags, possibly compare to an expected image.
epoger@google.come8ebeb12012-10-29 16:42:11 +0000838 ErrorBitfield test_drawing(GM* gm,
839 const ConfigData& gRec,
840 const char writePath [],
epoger@google.come8ebeb12012-10-29 16:42:11 +0000841 GrContext* context,
842 GrRenderTarget* rt,
epoger@google.com57f7abc2012-11-13 03:41:55 +0000843 SkBitmap* bitmap) {
epoger@google.comde961632012-10-26 18:56:36 +0000844 SkDynamicMemoryWStream document;
845
846 if (gRec.fBackend == kRaster_Backend ||
847 gRec.fBackend == kGPU_Backend) {
848 // Early exit if we can't generate the image.
849 ErrorBitfield errors = generate_image(gm, gRec, context, rt, bitmap,
850 false);
epoger@google.comeb066362013-03-08 09:39:36 +0000851 if (kEmptyErrorBitfield != errors) {
epoger@google.com37269602013-01-19 04:21:27 +0000852 // TODO: Add a test to exercise what the stdout and
853 // JSON look like if we get an "early error" while
854 // trying to generate the image.
epoger@google.comde961632012-10-26 18:56:36 +0000855 return errors;
856 }
857 } else if (gRec.fBackend == kPDF_Backend) {
858 generate_pdf(gm, document);
859#if CAN_IMAGE_PDF
860 SkAutoDataUnref data(document.copyToData());
861 SkMemoryStream stream(data->data(), data->size());
862 SkPDFDocumentToBitmap(&stream, bitmap);
863#endif
864 } else if (gRec.fBackend == kXPS_Backend) {
865 generate_xps(gm, document);
866 }
epoger@google.com37269602013-01-19 04:21:27 +0000867 return compare_test_results_to_stored_expectations(
868 gm, gRec, writePath, *bitmap, &document);
epoger@google.comde961632012-10-26 18:56:36 +0000869 }
870
epoger@google.come8ebeb12012-10-29 16:42:11 +0000871 ErrorBitfield test_deferred_drawing(GM* gm,
872 const ConfigData& gRec,
873 const SkBitmap& referenceBitmap,
epoger@google.come8ebeb12012-10-29 16:42:11 +0000874 GrContext* context,
875 GrRenderTarget* rt) {
epoger@google.comde961632012-10-26 18:56:36 +0000876 SkDynamicMemoryWStream document;
877
878 if (gRec.fBackend == kRaster_Backend ||
879 gRec.fBackend == kGPU_Backend) {
880 SkBitmap bitmap;
881 // Early exit if we can't generate the image, but this is
882 // expected in some cases, so don't report a test failure.
883 if (!generate_image(gm, gRec, context, rt, &bitmap, true)) {
epoger@google.comeb066362013-03-08 09:39:36 +0000884 return kEmptyErrorBitfield;
epoger@google.comde961632012-10-26 18:56:36 +0000885 }
epoger@google.com37269602013-01-19 04:21:27 +0000886 return compare_test_results_to_reference_bitmap(
887 gm, gRec, "-deferred", bitmap, &referenceBitmap);
epoger@google.comde961632012-10-26 18:56:36 +0000888 }
epoger@google.comeb066362013-03-08 09:39:36 +0000889 return kEmptyErrorBitfield;
epoger@google.comde961632012-10-26 18:56:36 +0000890 }
891
epoger@google.come8ebeb12012-10-29 16:42:11 +0000892 ErrorBitfield test_pipe_playback(GM* gm,
893 const ConfigData& gRec,
epoger@google.com37269602013-01-19 04:21:27 +0000894 const SkBitmap& referenceBitmap) {
epoger@google.comeb066362013-03-08 09:39:36 +0000895 ErrorBitfield errors = kEmptyErrorBitfield;
epoger@google.comde961632012-10-26 18:56:36 +0000896 for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) {
897 SkBitmap bitmap;
898 SkISize size = gm->getISize();
899 setup_bitmap(gRec, size, &bitmap);
900 SkCanvas canvas(bitmap);
scroggo@google.com0b735632013-03-19 17:38:50 +0000901 installFilter(&canvas);
epoger@google.comde961632012-10-26 18:56:36 +0000902 PipeController pipeController(&canvas);
903 SkGPipeWriter writer;
904 SkCanvas* pipeCanvas = writer.startRecording(
905 &pipeController, gPipeWritingFlagCombos[i].flags);
reed@google.comaef73612012-11-16 13:41:45 +0000906 invokeGM(gm, pipeCanvas, false, false);
epoger@google.com5f6a0072013-01-31 16:30:55 +0000907 complete_bitmap(&bitmap);
epoger@google.comde961632012-10-26 18:56:36 +0000908 writer.endRecording();
909 SkString string("-pipe");
910 string.append(gPipeWritingFlagCombos[i].name);
epoger@google.com37269602013-01-19 04:21:27 +0000911 errors |= compare_test_results_to_reference_bitmap(
912 gm, gRec, string.c_str(), bitmap, &referenceBitmap);
epoger@google.comeb066362013-03-08 09:39:36 +0000913 if (errors != kEmptyErrorBitfield) {
epoger@google.comde961632012-10-26 18:56:36 +0000914 break;
915 }
916 }
917 return errors;
918 }
919
epoger@google.come8ebeb12012-10-29 16:42:11 +0000920 ErrorBitfield test_tiled_pipe_playback(
epoger@google.com37269602013-01-19 04:21:27 +0000921 GM* gm, const ConfigData& gRec, const SkBitmap& referenceBitmap) {
epoger@google.comeb066362013-03-08 09:39:36 +0000922 ErrorBitfield errors = kEmptyErrorBitfield;
epoger@google.comde961632012-10-26 18:56:36 +0000923 for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) {
924 SkBitmap bitmap;
925 SkISize size = gm->getISize();
926 setup_bitmap(gRec, size, &bitmap);
927 SkCanvas canvas(bitmap);
scroggo@google.com0b735632013-03-19 17:38:50 +0000928 installFilter(&canvas);
epoger@google.comde961632012-10-26 18:56:36 +0000929 TiledPipeController pipeController(bitmap);
930 SkGPipeWriter writer;
931 SkCanvas* pipeCanvas = writer.startRecording(
932 &pipeController, gPipeWritingFlagCombos[i].flags);
reed@google.comaef73612012-11-16 13:41:45 +0000933 invokeGM(gm, pipeCanvas, false, false);
epoger@google.com5f6a0072013-01-31 16:30:55 +0000934 complete_bitmap(&bitmap);
epoger@google.comde961632012-10-26 18:56:36 +0000935 writer.endRecording();
936 SkString string("-tiled pipe");
937 string.append(gPipeWritingFlagCombos[i].name);
epoger@google.com37269602013-01-19 04:21:27 +0000938 errors |= compare_test_results_to_reference_bitmap(
939 gm, gRec, string.c_str(), bitmap, &referenceBitmap);
epoger@google.comeb066362013-03-08 09:39:36 +0000940 if (errors != kEmptyErrorBitfield) {
epoger@google.comde961632012-10-26 18:56:36 +0000941 break;
942 }
943 }
944 return errors;
945 }
epoger@google.come8ebeb12012-10-29 16:42:11 +0000946
947 //
948 // member variables.
949 // They are public for now, to allow easier setting by tool_main().
950 //
951
epoger@google.come8ebeb12012-10-29 16:42:11 +0000952 bool fUseFileHierarchy;
953
junov@chromium.org95146eb2013-01-11 21:04:40 +0000954 const char* fMismatchPath;
955
epoger@google.com57f7abc2012-11-13 03:41:55 +0000956 // information about all failed tests we have encountered so far
957 SkTArray<FailRec> fFailedTests;
958
epoger@google.com37269602013-01-19 04:21:27 +0000959 // Where to read expectations (expected image checksums, etc.) from.
960 // If unset, we don't do comparisons.
961 SkAutoTUnref<ExpectationsSource> fExpectationsSource;
962
963 // JSON summaries that we generate as we go (just for output).
epoger@google.comee8a8e32012-12-18 19:13:49 +0000964 Json::Value fJsonExpectedResults;
965 Json::Value fJsonActualResults_Failed;
966 Json::Value fJsonActualResults_FailureIgnored;
epoger@google.com9c56a8d2012-12-20 18:34:29 +0000967 Json::Value fJsonActualResults_NoComparison;
epoger@google.comee8a8e32012-12-18 19:13:49 +0000968 Json::Value fJsonActualResults_Succeeded;
969
epoger@google.comde961632012-10-26 18:56:36 +0000970}; // end of GMMain class definition
scroggo@google.com72c96722012-06-06 21:07:10 +0000971
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000972#if SK_SUPPORT_GPU
973static const GLContextType kDontCare_GLContextType = GrContextFactory::kNative_GLContextType;
974#else
975static const GLContextType kDontCare_GLContextType = 0;
976#endif
bsalomon@google.com7361f542012-04-19 19:15:35 +0000977
978// If the platform does not support writing PNGs of PDFs then there will be no
epoger@google.comf28dd8a2012-10-25 16:27:34 +0000979// reference images to read. However, we can always write the .pdf files
bsalomon@google.com7361f542012-04-19 19:15:35 +0000980static const ConfigFlags kPDFConfigFlags = CAN_IMAGE_PDF ? kRW_ConfigFlag :
981 kWrite_ConfigFlag;
982
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000983static const ConfigData gRec[] = {
bsalomon@google.com4c75f242013-03-19 18:58:43 +0000984 { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "8888", true },
reed@google.com69dc4ff2012-11-29 21:21:54 +0000985#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 +0000986 { SkBitmap::kARGB_4444_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "4444", true },
reed@google.com69dc4ff2012-11-29 21:21:54 +0000987#endif
bsalomon@google.com4c75f242013-03-19 18:58:43 +0000988 { SkBitmap::kRGB_565_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "565", true },
989#if SK_SUPPORT_GPU
990 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 0, kRW_ConfigFlag, "gpu", true },
991 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 16, kRW_ConfigFlag, "msaa16", true },
992 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 4, kRW_ConfigFlag, "msaa4", false},
bsalomon@google.com7361f542012-04-19 19:15:35 +0000993 /* The debug context does not generate images */
scroggo@google.com0f567c62013-03-20 15:35:08 +0000994 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kDebug_GLContextType, 0, kNone_ConfigFlag, "gpudebug", GR_DEBUG},
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000995#if SK_ANGLE
bsalomon@google.com4c75f242013-03-19 18:58:43 +0000996 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 0, kRW_ConfigFlag, "angle", true },
997 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 16, kRW_ConfigFlag, "anglemsaa16", true },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000998#endif // SK_ANGLE
999#ifdef SK_MESA
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001000 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kMESA_GLContextType, 0, kRW_ConfigFlag, "mesa", true },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001001#endif // SK_MESA
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001002#endif // SK_SUPPORT_GPU
bungeman@google.comb29c8832011-10-10 13:19:10 +00001003#ifdef SK_SUPPORT_XPS
bsalomon@google.com7361f542012-04-19 19:15:35 +00001004 /* 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 +00001005 { SkBitmap::kARGB_8888_Config, kXPS_Backend, kDontCare_GLContextType, 0, kWrite_ConfigFlag, "xps", true },
robertphillips@google.coma73e8602012-08-02 17:56:02 +00001006#endif // SK_SUPPORT_XPS
bsalomon@google.com7361f542012-04-19 19:15:35 +00001007#ifdef SK_SUPPORT_PDF
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001008 { SkBitmap::kARGB_8888_Config, kPDF_Backend, kDontCare_GLContextType, 0, kPDFConfigFlags, "pdf", true },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001009#endif // SK_SUPPORT_PDF
reed@android.com00dae862009-06-10 15:38:48 +00001010};
1011
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001012static SkString configUsage() {
scroggo@google.com0f567c62013-03-20 15:35:08 +00001013 SkString result;
1014 result.appendf("Space delimited list of which configs to run. Possible options: [");
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001015 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
1016 if (i > 0) {
scroggo@google.com0f567c62013-03-20 15:35:08 +00001017 result.append("|");
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001018 }
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001019 result.appendf("%s", gRec[i].fName);
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001020 }
scroggo@google.com0f567c62013-03-20 15:35:08 +00001021 result.append("]\n");
1022 result.appendf("The default value is: \"");
1023 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
1024 if (gRec[i].fRunByDefault) {
1025 if (i > 0) {
1026 result.append(" ");
1027 }
1028 result.appendf("%s", gRec[i].fName);
1029 }
1030 }
1031 result.appendf("\"");
1032
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001033 return result;
scroggo@google.com0b735632013-03-19 17:38:50 +00001034}
scroggo@google.com7d519302013-03-19 17:28:10 +00001035
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001036// Alphabetized ignoring "no" prefix ("readPath", "noreplay", "resourcePath").
scroggo@google.com0f567c62013-03-20 15:35:08 +00001037DEFINE_string(config, "", configUsage().c_str());
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001038DEFINE_bool(deferred, true, "Exercise the deferred rendering test pass.");
1039DEFINE_bool(enableMissingWarning, true, "Print message to stderr (but don't fail) if "
1040 "unable to read a reference image for any tests.");
1041DEFINE_string(excludeConfig, "", "Space delimited list of configs to skip.");
1042DEFINE_bool(forceBWtext, false, "Disable text anti-aliasing.");
1043#if SK_SUPPORT_GPU
1044DEFINE_string(gpuCacheSize, "", "<bytes> <count>: Limit the gpu cache to byte size or "
1045 "object count. -1 for either value means use the default. 0 for either "
1046 "disables the cache.");
1047#endif
1048DEFINE_bool(hierarchy, false, "Whether to use multilevel directory structure "
1049 "when reading/writing files.");
1050DEFINE_string(match, "", "Only run tests whose name includes this substring/these substrings "
1051 "(more than one can be supplied, separated by spaces).");
1052DEFINE_string(mismatchPath, "", "Write images for tests that failed due to "
1053 "pixel mismatches into this directory.");
1054DEFINE_string(modulo, "", "[--modulo <remainder> <divisor>]: only run tests for which "
1055 "testIndex %% divisor == remainder.");
1056DEFINE_bool(pdf, true, "Exercise the pdf rendering test pass.");
1057DEFINE_bool(pipe, true, "Exercise the SkGPipe replay test pass.");
1058DEFINE_string2(readPath, r, "", "Read reference images from this dir, and report "
1059 "any differences between those and the newly generated ones.");
1060DEFINE_bool(replay, true, "Exercise the SkPicture replay test pass.");
1061DEFINE_string2(resourcePath, i, "", "Directory that stores image resources.");
1062DEFINE_bool(rtree, true, "Exercise the R-Tree variant of SkPicture test pass.");
1063DEFINE_bool(serialize, true, "Exercise the SkPicture serialization & deserialization test pass.");
1064DEFINE_bool(tiledPipe, false, "Exercise tiled SkGPipe replay.");
1065DEFINE_bool(tileGrid, true, "Exercise the tile grid variant of SkPicture.");
1066DEFINE_string(tileGridReplayScales, "", "Space separated list of floating-point scale "
1067 "factors to be used for tileGrid playback testing. Default value: 1.0");
1068DEFINE_string(writeJsonSummaryPath, "", "Write a JSON-formatted result summary to this file.");
1069DEFINE_bool2(verbose, v, false, "Print diagnostics (e.g. list each config to be tested).");
1070DEFINE_string2(writePath, w, "", "Write rendered images into this directory.");
1071DEFINE_string2(writePicturePath, wp, "", "Write .skp files into this directory.");
1072
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001073static int findConfig(const char config[]) {
1074 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
1075 if (!strcmp(config, gRec[i].fName)) {
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001076 return (int) i;
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001077 }
1078 }
1079 return -1;
1080}
1081
reed@google.comb2a51622011-10-31 16:30:04 +00001082static bool skip_name(const SkTDArray<const char*> array, const char name[]) {
1083 if (0 == array.count()) {
1084 // no names, so don't skip anything
1085 return false;
1086 }
1087 for (int i = 0; i < array.count(); ++i) {
1088 if (strstr(name, array[i])) {
1089 // found the name, so don't skip
1090 return false;
1091 }
1092 }
1093 return true;
1094}
1095
bsalomon@google.comd9f826c2011-07-18 15:25:04 +00001096namespace skiagm {
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001097#if SK_SUPPORT_GPU
bsalomon@google.com7361f542012-04-19 19:15:35 +00001098SkAutoTUnref<GrContext> gGrContext;
1099/**
bsalomon@google.comc7a24d22012-11-01 18:03:48 +00001100 * Sets the global GrContext, accessible by individual GMs
bsalomon@google.com7361f542012-04-19 19:15:35 +00001101 */
caryclark@google.com13130862012-06-06 12:10:45 +00001102static void SetGr(GrContext* grContext) {
bsalomon@google.com7361f542012-04-19 19:15:35 +00001103 SkSafeRef(grContext);
1104 gGrContext.reset(grContext);
bsalomon@google.comd9f826c2011-07-18 15:25:04 +00001105}
bsalomon@google.com7361f542012-04-19 19:15:35 +00001106
1107/**
1108 * Gets the global GrContext, can be called by GM tests.
1109 */
caryclark@google.com13130862012-06-06 12:10:45 +00001110GrContext* GetGr();
bsalomon@google.com7361f542012-04-19 19:15:35 +00001111GrContext* GetGr() {
1112 return gGrContext.get();
1113}
1114
1115/**
1116 * Sets the global GrContext and then resets it to its previous value at
1117 * destruction.
1118 */
1119class AutoResetGr : SkNoncopyable {
1120public:
1121 AutoResetGr() : fOld(NULL) {}
1122 void set(GrContext* context) {
1123 SkASSERT(NULL == fOld);
1124 fOld = GetGr();
1125 SkSafeRef(fOld);
1126 SetGr(context);
1127 }
1128 ~AutoResetGr() { SetGr(fOld); SkSafeUnref(fOld); }
1129private:
1130 GrContext* fOld;
1131};
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001132#else
epoger@google.com80724df2013-03-21 13:49:54 +00001133GrContext* GetGr();
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001134GrContext* GetGr() { return NULL; }
1135#endif
bsalomon@google.comd9f826c2011-07-18 15:25:04 +00001136}
1137
reed@google.comfb2cd422013-01-04 14:43:03 +00001138template <typename T> void appendUnique(SkTDArray<T>* array, const T& value) {
1139 int index = array->find(value);
1140 if (index < 0) {
1141 *array->append() = value;
1142 }
1143}
1144
epoger@google.com80724df2013-03-21 13:49:54 +00001145/**
1146 * Run this test in a number of different configs (8888, 565, PDF,
1147 * etc.), confirming that the resulting bitmaps match expectations
1148 * (which may be different for each config).
1149 *
1150 * Returns all errors encountered while doing so.
1151 */
1152ErrorBitfield run_multiple_configs(GMMain &gmmain, GM *gm, const SkTDArray<size_t> &configs,
1153 GrContextFactory *grFactory);
1154ErrorBitfield run_multiple_configs(GMMain &gmmain, GM *gm, const SkTDArray<size_t> &configs,
1155 GrContextFactory *grFactory) {
1156 ErrorBitfield errorsForAllConfigs = kEmptyErrorBitfield;
1157 uint32_t gmFlags = gm->getFlags();
1158
1159#if SK_SUPPORT_GPU
1160 struct {
1161 int fBytes;
1162 int fCount;
1163 } gpuCacheSize = { -1, -1 }; // -1s mean use the default
1164
1165 if (FLAGS_gpuCacheSize.count() > 0) {
1166 if (FLAGS_gpuCacheSize.count() != 2) {
1167 gm_fprintf(stderr, "--gpuCacheSize requires two arguments\n");
1168 return -1;
1169 }
1170 gpuCacheSize.fBytes = atoi(FLAGS_gpuCacheSize[0]);
1171 gpuCacheSize.fCount = atoi(FLAGS_gpuCacheSize[1]);
1172 }
1173#endif
1174
1175 for (int i = 0; i < configs.count(); i++) {
1176 ConfigData config = gRec[configs[i]];
1177
1178 // Skip any tests that we don't even need to try.
1179 if ((kPDF_Backend == config.fBackend) &&
1180 (!FLAGS_pdf|| (gmFlags & GM::kSkipPDF_Flag))) {
1181 continue;
1182 }
1183 if ((gmFlags & GM::kSkip565_Flag) &&
1184 (kRaster_Backend == config.fBackend) &&
1185 (SkBitmap::kRGB_565_Config == config.fConfig)) {
1186 continue;
1187 }
1188 if ((gmFlags & GM::kSkipGPU_Flag) &&
1189 kGPU_Backend == config.fBackend) {
1190 continue;
1191 }
1192
1193 // Now we know that we want to run this test and record its
1194 // success or failure.
1195 ErrorBitfield errorsForThisConfig = kEmptyErrorBitfield;
1196 GrRenderTarget* renderTarget = NULL;
1197#if SK_SUPPORT_GPU
1198 SkAutoTUnref<GrRenderTarget> rt;
1199 AutoResetGr autogr;
1200 if ((kEmptyErrorBitfield == errorsForThisConfig) && (kGPU_Backend == config.fBackend)) {
1201 GrContext* gr = grFactory->get(config.fGLContextType);
1202 bool grSuccess = false;
1203 if (gr) {
1204 // create a render target to back the device
1205 GrTextureDesc desc;
1206 desc.fConfig = kSkia8888_GrPixelConfig;
1207 desc.fFlags = kRenderTarget_GrTextureFlagBit;
1208 desc.fWidth = gm->getISize().width();
1209 desc.fHeight = gm->getISize().height();
1210 desc.fSampleCnt = config.fSampleCnt;
1211 GrTexture* tex = gr->createUncachedTexture(desc, NULL, 0);
1212 if (tex) {
1213 rt.reset(tex->asRenderTarget());
1214 rt.get()->ref();
1215 tex->unref();
1216 autogr.set(gr);
1217 renderTarget = rt.get();
1218 grSuccess = NULL != renderTarget;
1219 }
1220 // Set the user specified cache limits if non-default.
1221 size_t bytes;
1222 int count;
1223 gr->getTextureCacheLimits(&count, &bytes);
1224 if (-1 != gpuCacheSize.fBytes) {
1225 bytes = static_cast<size_t>(gpuCacheSize.fBytes);
1226 }
1227 if (-1 != gpuCacheSize.fCount) {
1228 count = gpuCacheSize.fCount;
1229 }
1230 gr->setTextureCacheLimits(count, bytes);
1231 }
1232 if (!grSuccess) {
1233 errorsForThisConfig |= kNoGpuContext_ErrorBitmask;
1234 }
1235 }
1236#endif
1237
1238 SkBitmap comparisonBitmap;
1239
1240 const char* writePath;
1241 if (FLAGS_writePath.count() == 1) {
1242 writePath = FLAGS_writePath[0];
1243 } else {
1244 writePath = NULL;
1245 }
1246 if (kEmptyErrorBitfield == errorsForThisConfig) {
1247 errorsForThisConfig |= gmmain.test_drawing(gm, config, writePath, GetGr(),
1248 renderTarget, &comparisonBitmap);
1249 }
1250
1251 if (FLAGS_deferred && !errorsForThisConfig &&
1252 (kGPU_Backend == config.fBackend ||
1253 kRaster_Backend == config.fBackend)) {
1254 errorsForThisConfig |= gmmain.test_deferred_drawing(gm, config, comparisonBitmap,
1255 GetGr(), renderTarget);
1256 }
1257
1258 errorsForAllConfigs |= errorsForThisConfig;
1259 }
1260 return errorsForAllConfigs;
1261}
1262
1263/**
1264 * Run this test in a number of different drawing modes (pipe,
1265 * deferred, tiled, etc.), confirming that the resulting bitmaps all
1266 * *exactly* match comparisonBitmap.
1267 *
1268 * Returns all errors encountered while doing so.
1269 */
1270ErrorBitfield run_multiple_modes(GMMain &gmmain, GM *gm, const ConfigData &compareConfig,
1271 const SkBitmap &comparisonBitmap);
1272ErrorBitfield run_multiple_modes(GMMain &gmmain, GM *gm, const ConfigData &compareConfig,
1273 const SkBitmap &comparisonBitmap) {
1274 SkTDArray<SkScalar> tileGridReplayScales;
1275 *tileGridReplayScales.append() = SK_Scalar1; // By default only test at scale 1.0
1276 if (FLAGS_tileGridReplayScales.count() > 0) {
1277 tileGridReplayScales.reset();
1278 for (int i = 0; i < FLAGS_tileGridReplayScales.count(); i++) {
1279 double val = atof(FLAGS_tileGridReplayScales[i]);
1280 if (0 < val) {
1281 *tileGridReplayScales.append() = SkDoubleToScalar(val);
1282 }
1283 }
1284 if (0 == tileGridReplayScales.count()) {
1285 // Should have at least one scale
1286 gm_fprintf(stderr, "--tileGridReplayScales requires at least one scale.\n");
1287 return -1;
1288 }
1289 }
1290
1291 ErrorBitfield errorsForAllModes = kEmptyErrorBitfield;
1292 uint32_t gmFlags = gm->getFlags();
1293
1294 // run the picture centric GM steps
1295 if (!(gmFlags & GM::kSkipPicture_Flag)) {
1296
1297 ErrorBitfield pictErrors = kEmptyErrorBitfield;
1298
1299 //SkAutoTUnref<SkPicture> pict(generate_new_picture(gm));
1300 SkPicture* pict = gmmain.generate_new_picture(gm, kNone_BbhType, 0);
1301 SkAutoUnref aur(pict);
1302
1303 if (FLAGS_replay) {
1304 SkBitmap bitmap;
1305 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap);
1306 pictErrors |= gmmain.compare_test_results_to_reference_bitmap(
1307 gm, compareConfig, "-replay", bitmap, &comparisonBitmap);
1308 }
1309
1310 if ((kEmptyErrorBitfield == pictErrors) && FLAGS_serialize) {
1311 SkPicture* repict = gmmain.stream_to_new_picture(*pict);
1312 SkAutoUnref aurr(repict);
1313
1314 SkBitmap bitmap;
1315 gmmain.generate_image_from_picture(gm, compareConfig, repict, &bitmap);
1316 pictErrors |= gmmain.compare_test_results_to_reference_bitmap(
1317 gm, compareConfig, "-serialize", bitmap, &comparisonBitmap);
1318 }
1319
1320 if (FLAGS_writePicturePath.count() == 1) {
1321 const char* pictureSuffix = "skp";
1322 SkString path = make_filename(FLAGS_writePicturePath[0], "",
1323 gm->shortName(), pictureSuffix);
1324 SkFILEWStream stream(path.c_str());
1325 pict->serialize(&stream);
1326 }
1327
1328 errorsForAllModes |= pictErrors;
1329 }
1330
1331 // TODO: add a test in which the RTree rendering results in a
1332 // different bitmap than the standard rendering. It should
1333 // show up as failed in the JSON summary, and should be listed
1334 // in the stdout also.
1335 if (!(gmFlags & GM::kSkipPicture_Flag) && FLAGS_rtree) {
1336 SkPicture* pict = gmmain.generate_new_picture(
1337 gm, kRTree_BbhType, SkPicture::kUsePathBoundsForClip_RecordingFlag);
1338 SkAutoUnref aur(pict);
1339 SkBitmap bitmap;
1340 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap);
1341 errorsForAllModes |= gmmain.compare_test_results_to_reference_bitmap(
1342 gm, compareConfig, "-rtree", bitmap, &comparisonBitmap);
1343 }
1344
1345 if (!(gmFlags & GM::kSkipPicture_Flag) && FLAGS_tileGrid) {
1346 for(int scaleIndex = 0; scaleIndex < tileGridReplayScales.count(); ++scaleIndex) {
1347 SkScalar replayScale = tileGridReplayScales[scaleIndex];
1348 if ((gmFlags & GM::kSkipScaledReplay_Flag) && replayScale != 1) {
1349 continue;
1350 }
1351 // We record with the reciprocal scale to obtain a replay
1352 // result that can be validated against comparisonBitmap.
1353 SkScalar recordScale = SkScalarInvert(replayScale);
1354 SkPicture* pict = gmmain.generate_new_picture(
1355 gm, kTileGrid_BbhType, SkPicture::kUsePathBoundsForClip_RecordingFlag, recordScale);
1356 SkAutoUnref aur(pict);
1357 SkBitmap bitmap;
1358 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap, replayScale);
1359 SkString suffix("-tilegrid");
1360 if (SK_Scalar1 != replayScale) {
1361 suffix += "-scale-";
1362 suffix.appendScalar(replayScale);
1363 }
1364 errorsForAllModes |= gmmain.compare_test_results_to_reference_bitmap(
1365 gm, compareConfig, suffix.c_str(), bitmap, &comparisonBitmap);
1366 }
1367 }
1368
1369 // run the pipe centric GM steps
1370 if (!(gmFlags & GM::kSkipPipe_Flag)) {
1371
1372 ErrorBitfield pipeErrors = kEmptyErrorBitfield;
1373
1374 if (FLAGS_pipe) {
1375 pipeErrors |= gmmain.test_pipe_playback(gm, compareConfig, comparisonBitmap);
1376 }
1377
1378 if ((kEmptyErrorBitfield == pipeErrors) &&
1379 FLAGS_tiledPipe && !(gmFlags & GM::kSkipTiled_Flag)) {
1380 pipeErrors |= gmmain.test_tiled_pipe_playback(gm, compareConfig, comparisonBitmap);
1381 }
1382
1383 errorsForAllModes |= pipeErrors;
1384 }
1385 return errorsForAllModes;
1386}
1387
epoger@google.com0b62b3d2013-03-20 17:59:28 +00001388int tool_main(int argc, char** argv);
1389int tool_main(int argc, char** argv) {
1390
1391#if SK_ENABLE_INST_COUNT
1392 gPrintInstCount = true;
1393#endif
1394
1395 SkGraphics::Init();
1396 // we don't need to see this during a run
1397 gSkSuppressFontCachePurgeSpew = true;
1398
1399 setSystemPreferences();
1400 GMMain gmmain;
1401
1402 SkTDArray<size_t> configs;
1403 SkTDArray<size_t> excludeConfigs;
1404 bool userConfig = false;
1405
1406 SkString usage;
1407 usage.printf("Run the golden master tests.\n");
1408 SkFlags::SetUsage(usage.c_str());
1409 SkFlags::ParseCommandLine(argc, argv);
1410
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001411 gmmain.fUseFileHierarchy = FLAGS_hierarchy;
1412 if (FLAGS_mismatchPath.count() == 1) {
1413 gmmain.fMismatchPath = FLAGS_mismatchPath[0];
1414 }
1415
1416 for (int i = 0; i < FLAGS_config.count(); i++) {
1417 int index = findConfig(FLAGS_config[i]);
1418 if (index >= 0) {
1419 appendUnique<size_t>(&configs, index);
1420 userConfig = true;
scroggo@google.com0b735632013-03-19 17:38:50 +00001421 } else {
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001422 gm_fprintf(stderr, "unrecognized config %s\n", FLAGS_config[i]);
scroggo@google.com7d519302013-03-19 17:28:10 +00001423 return -1;
1424 }
1425 }
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001426
1427 for (int i = 0; i < FLAGS_excludeConfig.count(); i++) {
1428 int index = findConfig(FLAGS_excludeConfig[i]);
1429 if (index >= 0) {
1430 *excludeConfigs.append() = index;
1431 } else {
1432 gm_fprintf(stderr, "unrecognized excludeConfig %s\n", FLAGS_excludeConfig[i]);
1433 return -1;
1434 }
1435 }
1436
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001437 int moduloRemainder = -1;
1438 int moduloDivisor = -1;
1439
1440 if (FLAGS_modulo.count() == 2) {
1441 moduloRemainder = atoi(FLAGS_modulo[0]);
1442 moduloDivisor = atoi(FLAGS_modulo[1]);
1443 if (moduloRemainder < 0 || moduloDivisor <= 0 || moduloRemainder >= moduloDivisor) {
1444 gm_fprintf(stderr, "invalid modulo values.");
1445 return -1;
1446 }
tomhudson@google.com9875dd12011-04-25 15:49:53 +00001447 }
reed@google.com873cb1e2010-12-23 15:00:45 +00001448
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001449 if (!userConfig) {
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001450 // if no config is specified by user, add the defaults
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001451 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001452 if (gRec[i].fRunByDefault) {
1453 *configs.append() = i;
1454 }
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001455 }
1456 }
reed@google.comfb2cd422013-01-04 14:43:03 +00001457 // now remove any explicitly excluded configs
1458 for (int i = 0; i < excludeConfigs.count(); ++i) {
1459 int index = configs.find(excludeConfigs[i]);
1460 if (index >= 0) {
1461 configs.remove(index);
1462 // now assert that there was only one copy in configs[]
1463 SkASSERT(configs.find(excludeConfigs[i]) < 0);
1464 }
1465 }
1466
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001467#if SK_SUPPORT_GPU
1468 GrContextFactory* grFactory = new GrContextFactory;
1469 for (int i = 0; i < configs.count(); ++i) {
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001470 size_t index = configs[i];
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001471 if (kGPU_Backend == gRec[index].fBackend) {
1472 GrContext* ctx = grFactory->get(gRec[index].fGLContextType);
1473 if (NULL == ctx) {
1474 SkDebugf("GrContext could not be created for config %s. Config will be skipped.",
1475 gRec[index].fName);
1476 configs.remove(i);
1477 --i;
1478 }
1479 if (gRec[index].fSampleCnt > ctx->getMaxSampleCount()) {
1480 SkDebugf("Sample count (%d) of config %s is not supported. Config will be skipped.",
1481 gRec[index].fSampleCnt, gRec[index].fName);
1482 configs.remove(i);
1483 --i;
1484 }
1485 }
1486 }
epoger@google.com80724df2013-03-21 13:49:54 +00001487#else
1488 GrContextFactory* grFactory = NULL;
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001489#endif
1490
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001491 if (FLAGS_verbose) {
reed@google.comfb2cd422013-01-04 14:43:03 +00001492 SkString str;
epoger@google.com5efdd0c2013-03-13 14:18:40 +00001493 str.printf("%d configs:", configs.count());
reed@google.comfb2cd422013-01-04 14:43:03 +00001494 for (int i = 0; i < configs.count(); ++i) {
1495 str.appendf(" %s", gRec[configs[i]].fName);
1496 }
epoger@google.com5efdd0c2013-03-13 14:18:40 +00001497 gm_fprintf(stderr, "%s\n", str.c_str());
reed@google.comfb2cd422013-01-04 14:43:03 +00001498 }
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001499
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001500 if (FLAGS_resourcePath.count() == 1) {
1501 GM::SetResourcePath(FLAGS_resourcePath[0]);
1502 }
robertphillips@google.com8570b5c2012-03-20 17:40:58 +00001503
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001504 if (FLAGS_readPath.count() == 1) {
1505 const char* readPath = FLAGS_readPath[0];
epoger@google.com37269602013-01-19 04:21:27 +00001506 if (!sk_exists(readPath)) {
epoger@google.com5efdd0c2013-03-13 14:18:40 +00001507 gm_fprintf(stderr, "readPath %s does not exist!\n", readPath);
epoger@google.com37269602013-01-19 04:21:27 +00001508 return -1;
1509 }
1510 if (sk_isdir(readPath)) {
epoger@google.com5efdd0c2013-03-13 14:18:40 +00001511 gm_fprintf(stdout, "reading from %s\n", readPath);
epoger@google.com37269602013-01-19 04:21:27 +00001512 gmmain.fExpectationsSource.reset(SkNEW_ARGS(
1513 IndividualImageExpectationsSource,
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001514 (readPath, FLAGS_enableMissingWarning)));
epoger@google.com37269602013-01-19 04:21:27 +00001515 } else {
epoger@google.com5efdd0c2013-03-13 14:18:40 +00001516 gm_fprintf(stdout, "reading expectations from JSON summary file %s\n", readPath);
epoger@google.comd271d242013-02-13 18:14:48 +00001517 gmmain.fExpectationsSource.reset(SkNEW_ARGS(
1518 JsonExpectationsSource, (readPath)));
epoger@google.com37269602013-01-19 04:21:27 +00001519 }
chudy@google.comf32f6e82012-07-12 15:42:37 +00001520 }
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001521 if (FLAGS_writePath.count() == 1) {
1522 gm_fprintf(stderr, "writing to %s\n", FLAGS_writePath[0]);
reed@android.com00f883e2010-12-14 17:46:14 +00001523 }
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001524 if (FLAGS_writePicturePath.count() == 1) {
1525 gm_fprintf(stderr, "writing pictures to %s\n", FLAGS_writePicturePath[0]);
mike@reedtribe.org5d0c62f2012-06-02 14:50:13 +00001526 }
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001527 if (FLAGS_resourcePath.count() == 1) {
1528 gm_fprintf(stderr, "reading resources from %s\n", FLAGS_resourcePath[0]);
robertphillips@google.com8570b5c2012-03-20 17:40:58 +00001529 }
1530
epoger@google.com82cb65b2012-10-29 18:59:17 +00001531 if (moduloDivisor <= 0) {
1532 moduloRemainder = -1;
reed@google.comae7b8f32012-10-18 21:30:57 +00001533 }
epoger@google.com82cb65b2012-10-29 18:59:17 +00001534 if (moduloRemainder < 0 || moduloRemainder >= moduloDivisor) {
1535 moduloRemainder = -1;
reed@google.comae7b8f32012-10-18 21:30:57 +00001536 }
1537
epoger@google.comc7cf2b32011-12-28 19:31:01 +00001538 // Accumulate success of all tests.
1539 int testsRun = 0;
1540 int testsPassed = 0;
1541 int testsFailed = 0;
1542 int testsMissingReferenceImages = 0;
1543
reed@google.comae7b8f32012-10-18 21:30:57 +00001544 int gmIndex = -1;
1545 SkString moduloStr;
1546
epoger@google.come8ebeb12012-10-29 16:42:11 +00001547 // If we will be writing out files, prepare subdirectories.
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001548 if (FLAGS_writePath.count() == 1) {
1549 if (!sk_mkdir(FLAGS_writePath[0])) {
epoger@google.come8ebeb12012-10-29 16:42:11 +00001550 return -1;
1551 }
1552 if (gmmain.fUseFileHierarchy) {
1553 for (int i = 0; i < configs.count(); i++) {
1554 ConfigData config = gRec[configs[i]];
1555 SkString subdir;
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001556 subdir.appendf("%s%c%s", FLAGS_writePath[0], SkPATH_SEPARATOR,
epoger@google.come8ebeb12012-10-29 16:42:11 +00001557 config.fName);
1558 if (!sk_mkdir(subdir.c_str())) {
1559 return -1;
1560 }
1561 }
1562 }
1563 }
1564
bsalomon@google.com7361f542012-04-19 19:15:35 +00001565 Iter iter;
1566 GM* gm;
reed@android.com00dae862009-06-10 15:38:48 +00001567 while ((gm = iter.next()) != NULL) {
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +00001568
reed@google.comae7b8f32012-10-18 21:30:57 +00001569 ++gmIndex;
epoger@google.com82cb65b2012-10-29 18:59:17 +00001570 if (moduloRemainder >= 0) {
1571 if ((gmIndex % moduloDivisor) != moduloRemainder) {
reed@google.comae7b8f32012-10-18 21:30:57 +00001572 continue;
1573 }
epoger@google.com82cb65b2012-10-29 18:59:17 +00001574 moduloStr.printf("[%d.%d] ", gmIndex, moduloDivisor);
reed@google.comae7b8f32012-10-18 21:30:57 +00001575 }
1576
reed@google.comece2b022011-07-25 14:28:57 +00001577 const char* shortName = gm->shortName();
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001578 if (skip_name(FLAGS_match, shortName)) {
reed@google.comece2b022011-07-25 14:28:57 +00001579 SkDELETE(gm);
1580 continue;
1581 }
1582
tomhudson@google.com9875dd12011-04-25 15:49:53 +00001583 SkISize size = gm->getISize();
epoger@google.com5efdd0c2013-03-13 14:18:40 +00001584 gm_fprintf(stdout, "%sdrawing... %s [%d %d]\n", moduloStr.c_str(), shortName,
1585 size.width(), size.height());
djsollen@google.comebce16d2012-10-26 14:07:13 +00001586
epoger@google.comeb066362013-03-08 09:39:36 +00001587 ErrorBitfield testErrors = kEmptyErrorBitfield;
epoger@google.com80724df2013-03-21 13:49:54 +00001588 testErrors |= run_multiple_configs(gmmain, gm, configs, grFactory);
djsollen@google.comebce16d2012-10-26 14:07:13 +00001589
1590 SkBitmap comparisonBitmap;
1591 const ConfigData compareConfig =
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001592 { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "comparison", false };
epoger@google.comde961632012-10-26 18:56:36 +00001593 testErrors |= gmmain.generate_image(gm, compareConfig, NULL, NULL, &comparisonBitmap, false);
djsollen@google.comebce16d2012-10-26 14:07:13 +00001594
epoger@google.com80724df2013-03-21 13:49:54 +00001595 // TODO(epoger): only run this if gmmain.generate_image() succeeded?
1596 // Otherwise, what are we comparing against?
1597 testErrors |= run_multiple_modes(gmmain, gm, compareConfig, comparisonBitmap);
djsollen@google.comebce16d2012-10-26 14:07:13 +00001598
1599 // Update overall results.
1600 // We only tabulate the particular error types that we currently
1601 // care about (e.g., missing reference images). Later on, if we
epoger@google.com37269602013-01-19 04:21:27 +00001602 // want to also tabulate other error types, we can do so.
djsollen@google.comebce16d2012-10-26 14:07:13 +00001603 testsRun++;
epoger@google.com37269602013-01-19 04:21:27 +00001604 if (!gmmain.fExpectationsSource.get() ||
epoger@google.comeb066362013-03-08 09:39:36 +00001605 (kEmptyErrorBitfield != (kMissingExpectations_ErrorBitmask & testErrors))) {
djsollen@google.comebce16d2012-10-26 14:07:13 +00001606 testsMissingReferenceImages++;
borenet@google.coma904ea12013-02-21 18:34:14 +00001607 }
epoger@google.comeb066362013-03-08 09:39:36 +00001608 if (testErrors == (testErrors & kIgnorable_ErrorBitmask)) {
epoger@google.com3499f3c2013-01-10 17:11:27 +00001609 testsPassed++;
djsollen@google.comebce16d2012-10-26 14:07:13 +00001610 } else {
1611 testsFailed++;
1612 }
1613
reed@android.com00dae862009-06-10 15:38:48 +00001614 SkDELETE(gm);
1615 }
epoger@google.com5efdd0c2013-03-13 14:18:40 +00001616 gm_fprintf(stdout, "Ran %d tests: %d passed, %d failed, %d missing reference images\n",
1617 testsRun, testsPassed, testsFailed, testsMissingReferenceImages);
epoger@google.com57f7abc2012-11-13 03:41:55 +00001618 gmmain.ListErrors();
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00001619
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001620 if (FLAGS_writeJsonSummaryPath.count() == 1) {
epoger@google.comee8a8e32012-12-18 19:13:49 +00001621 Json::Value actualResults;
1622 actualResults[kJsonKey_ActualResults_Failed] =
1623 gmmain.fJsonActualResults_Failed;
1624 actualResults[kJsonKey_ActualResults_FailureIgnored] =
1625 gmmain.fJsonActualResults_FailureIgnored;
epoger@google.com9c56a8d2012-12-20 18:34:29 +00001626 actualResults[kJsonKey_ActualResults_NoComparison] =
1627 gmmain.fJsonActualResults_NoComparison;
epoger@google.comee8a8e32012-12-18 19:13:49 +00001628 actualResults[kJsonKey_ActualResults_Succeeded] =
1629 gmmain.fJsonActualResults_Succeeded;
1630 Json::Value root;
1631 root[kJsonKey_ActualResults] = actualResults;
1632 root[kJsonKey_ExpectedResults] = gmmain.fJsonExpectedResults;
1633 std::string jsonStdString = root.toStyledString();
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001634 SkFILEWStream stream(FLAGS_writeJsonSummaryPath[0]);
epoger@google.comee8a8e32012-12-18 19:13:49 +00001635 stream.write(jsonStdString.c_str(), jsonStdString.length());
1636 }
1637
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001638#if SK_SUPPORT_GPU
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00001639
robertphillips@google.com59552022012-08-31 13:07:37 +00001640#if GR_CACHE_STATS
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00001641 for (int i = 0; i < configs.count(); i++) {
1642 ConfigData config = gRec[configs[i]];
1643
1644 if (kGPU_Backend == config.fBackend) {
1645 GrContext* gr = grFactory->get(config.fGLContextType);
1646
epoger@google.com5efdd0c2013-03-13 14:18:40 +00001647 gm_fprintf(stdout, "config: %s %x\n", config.fName, gr);
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00001648 gr->printCacheStats();
1649 }
1650 }
1651#endif
1652
robertphillips@google.com977b9c82012-06-05 19:35:09 +00001653 delete grFactory;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001654#endif
robertphillips@google.com977b9c82012-06-05 19:35:09 +00001655 SkGraphics::Term();
1656
epoger@google.comc7cf2b32011-12-28 19:31:01 +00001657 return (0 == testsFailed) ? 0 : -1;
reed@android.com00dae862009-06-10 15:38:48 +00001658}
caryclark@google.com5987f582012-10-02 18:33:14 +00001659
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001660void GMMain::installFilter(SkCanvas* canvas) {
1661 if (FLAGS_forceBWtext) {
1662 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref();
1663 }
1664}
1665
borenet@google.com7158e6a2012-11-01 17:43:44 +00001666#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
caryclark@google.com5987f582012-10-02 18:33:14 +00001667int main(int argc, char * const argv[]) {
1668 return tool_main(argc, (char**) argv);
1669}
1670#endif