blob: 55e1c2a3c38b96d4957783c064f2131d408fe17b [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.com6f6568b2013-03-22 17:29:46 +000017#include "gm_error.h"
epoger@google.com37269602013-01-19 04:21:27 +000018#include "gm_expectations.h"
epoger@google.com7bc13a62012-02-14 14:53:59 +000019#include "system_preferences.h"
epoger@google.com5f6a0072013-01-31 16:30:55 +000020#include "SkBitmap.h"
epoger@google.comee8a8e32012-12-18 19:13:49 +000021#include "SkBitmapChecksummer.h"
reed@android.comb9b9a182009-07-08 02:54:47 +000022#include "SkColorPriv.h"
scroggo@google.comd9ba9a02013-03-21 19:43:15 +000023#include "SkCommandLineFlags.h"
reed@google.com8a85d0c2011-06-24 19:12:12 +000024#include "SkData.h"
junov@google.com4370aed2012-01-18 16:21:08 +000025#include "SkDeferredCanvas.h"
bsalomon@google.com971d0c82011-08-19 17:22:05 +000026#include "SkDevice.h"
epoger@google.comde961632012-10-26 18:56:36 +000027#include "SkDrawFilter.h"
scroggo@google.com5af9b202012-06-04 17:17:36 +000028#include "SkGPipe.h"
reed@android.com8015dd82009-06-21 00:49:18 +000029#include "SkGraphics.h"
30#include "SkImageDecoder.h"
31#include "SkImageEncoder.h"
epoger@google.come8ebeb12012-10-29 16:42:11 +000032#include "SkOSFile.h"
tomhudson@google.com9875dd12011-04-25 15:49:53 +000033#include "SkPicture.h"
robertphillips@google.com977b9c82012-06-05 19:35:09 +000034#include "SkRefCnt.h"
scroggo@google.com72c96722012-06-06 21:07:10 +000035#include "SkStream.h"
bsalomon@google.com2a48c3a2012-08-03 14:54:45 +000036#include "SkTArray.h"
junov@chromium.org3cb834b2012-12-13 16:39:53 +000037#include "SkTileGridPicture.h"
scroggo@google.com72c96722012-06-06 21:07:10 +000038#include "SamplePipeControllers.h"
reed@google.com07700442010-12-20 19:46:07 +000039
bsalomon@google.com50c79d82013-01-08 20:31:53 +000040#ifdef SK_BUILD_FOR_WIN
41 // json includes xlocale which generates warning 4530 because we're compiling without
epoger@google.com37269602013-01-19 04:21:27 +000042 // exceptions; see https://code.google.com/p/skia/issues/detail?id=1067
bsalomon@google.com50c79d82013-01-08 20:31:53 +000043 #pragma warning(push)
44 #pragma warning(disable : 4530)
45#endif
epoger@google.comee8a8e32012-12-18 19:13:49 +000046#include "json/value.h"
bsalomon@google.com50c79d82013-01-08 20:31:53 +000047#ifdef SK_BUILD_FOR_WIN
48 #pragma warning(pop)
49#endif
epoger@google.comee8a8e32012-12-18 19:13:49 +000050
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000051#if SK_SUPPORT_GPU
52#include "GrContextFactory.h"
53#include "GrRenderTarget.h"
54#include "SkGpuDevice.h"
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000055typedef GrContextFactory::GLContextType GLContextType;
epoger@google.com6f6568b2013-03-22 17:29:46 +000056#define DEFAULT_CACHE_VALUE -1
57static int gGpuCacheSizeBytes;
58static int gGpuCacheSizeCount;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000059#else
epoger@google.com80724df2013-03-21 13:49:54 +000060class GrContextFactory;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000061class GrContext;
62class GrRenderTarget;
63typedef int GLContextType;
64#endif
65
reed@google.com8923c6c2011-11-08 14:59:38 +000066extern bool gSkSuppressFontCachePurgeSpew;
67
reed@google.com07700442010-12-20 19:46:07 +000068#ifdef SK_SUPPORT_PDF
tomhudson@google.com9875dd12011-04-25 15:49:53 +000069 #include "SkPDFDevice.h"
70 #include "SkPDFDocument.h"
reed@google.com07700442010-12-20 19:46:07 +000071#endif
reed@android.com00dae862009-06-10 15:38:48 +000072
epoger@google.come3cc2eb2012-01-18 20:11:13 +000073// Until we resolve http://code.google.com/p/skia/issues/detail?id=455 ,
74// stop writing out XPS-format image baselines in gm.
75#undef SK_SUPPORT_XPS
bungeman@google.comb29c8832011-10-10 13:19:10 +000076#ifdef SK_SUPPORT_XPS
77 #include "SkXPSDevice.h"
78#endif
79
reed@google.com46cce912011-06-29 12:54:46 +000080#ifdef SK_BUILD_FOR_MAC
81 #include "SkCGUtils.h"
bsalomon@google.com0a09eef2011-06-29 19:42:58 +000082 #define CAN_IMAGE_PDF 1
reed@google.com46cce912011-06-29 12:54:46 +000083#else
bsalomon@google.com0a09eef2011-06-29 19:42:58 +000084 #define CAN_IMAGE_PDF 0
reed@google.com46cce912011-06-29 12:54:46 +000085#endif
86
reed@android.com00dae862009-06-10 15:38:48 +000087using namespace skiagm;
88
epoger@google.com57f7abc2012-11-13 03:41:55 +000089struct FailRec {
90 SkString fName;
epoger@google.com15655b22013-01-08 18:47:31 +000091 bool fIsPixelError;
epoger@google.com57f7abc2012-11-13 03:41:55 +000092
epoger@google.com15655b22013-01-08 18:47:31 +000093 FailRec() : fIsPixelError(false) {}
94 FailRec(const SkString& name) : fName(name), fIsPixelError(false) {}
epoger@google.com57f7abc2012-11-13 03:41:55 +000095};
96
reed@android.com00dae862009-06-10 15:38:48 +000097class Iter {
98public:
99 Iter() {
bsalomon@google.com39149582011-06-13 21:55:32 +0000100 this->reset();
101 }
102
103 void reset() {
reed@android.comdd0ac282009-06-20 02:38:16 +0000104 fReg = GMRegistry::Head();
reed@android.com00dae862009-06-10 15:38:48 +0000105 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000106
reed@android.comdd0ac282009-06-20 02:38:16 +0000107 GM* next() {
reed@android.com00dae862009-06-10 15:38:48 +0000108 if (fReg) {
reed@android.comdd0ac282009-06-20 02:38:16 +0000109 GMRegistry::Factory fact = fReg->factory();
reed@android.com00dae862009-06-10 15:38:48 +0000110 fReg = fReg->next();
reed@android.comdd0ac282009-06-20 02:38:16 +0000111 return fact(0);
reed@android.com00dae862009-06-10 15:38:48 +0000112 }
113 return NULL;
114 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000115
reed@android.com00dae862009-06-10 15:38:48 +0000116 static int Count() {
reed@android.comdd0ac282009-06-20 02:38:16 +0000117 const GMRegistry* reg = GMRegistry::Head();
reed@android.com00dae862009-06-10 15:38:48 +0000118 int count = 0;
119 while (reg) {
120 count += 1;
121 reg = reg->next();
122 }
123 return count;
124 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000125
reed@android.com00dae862009-06-10 15:38:48 +0000126private:
127 const GMRegistry* fReg;
128};
129
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000130enum Backend {
junov@chromium.org3cb834b2012-12-13 16:39:53 +0000131 kRaster_Backend,
132 kGPU_Backend,
133 kPDF_Backend,
134 kXPS_Backend,
135};
136
137enum BbhType {
138 kNone_BbhType,
139 kRTree_BbhType,
140 kTileGrid_BbhType,
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000141};
142
bsalomon@google.com7361f542012-04-19 19:15:35 +0000143enum ConfigFlags {
144 kNone_ConfigFlag = 0x0,
145 /* Write GM images if a write path is provided. */
146 kWrite_ConfigFlag = 0x1,
epoger@google.comf28dd8a2012-10-25 16:27:34 +0000147 /* Read reference GM images if a read path is provided. */
bsalomon@google.com7361f542012-04-19 19:15:35 +0000148 kRead_ConfigFlag = 0x2,
149 kRW_ConfigFlag = (kWrite_ConfigFlag | kRead_ConfigFlag),
150};
151
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000152struct ConfigData {
bsalomon@google.com7361f542012-04-19 19:15:35 +0000153 SkBitmap::Config fConfig;
154 Backend fBackend;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000155 GLContextType fGLContextType; // GPU backend only
bsalomon@google.com7361f542012-04-19 19:15:35 +0000156 int fSampleCnt; // GPU backend only
157 ConfigFlags fFlags;
158 const char* fName;
bsalomon@google.com4c75f242013-03-19 18:58:43 +0000159 bool fRunByDefault;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000160};
161
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000162class BWTextDrawFilter : public SkDrawFilter {
163public:
reed@google.com971aca72012-11-26 20:26:54 +0000164 virtual bool filter(SkPaint*, Type) SK_OVERRIDE;
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000165};
reed@google.com971aca72012-11-26 20:26:54 +0000166bool BWTextDrawFilter::filter(SkPaint* p, Type t) {
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000167 if (kText_Type == t) {
168 p->setAntiAlias(false);
169 }
reed@google.com971aca72012-11-26 20:26:54 +0000170 return true;
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000171}
172
scroggo@google.com565254b2012-06-28 15:41:32 +0000173struct PipeFlagComboData {
174 const char* name;
175 uint32_t flags;
176};
177
178static PipeFlagComboData gPipeWritingFlagCombos[] = {
179 { "", 0 },
180 { " cross-process", SkGPipeWriter::kCrossProcess_Flag },
scroggob3c0f482012-07-02 19:07:57 +0000181 { " cross-process, shared address", SkGPipeWriter::kCrossProcess_Flag
scroggo@google.com15011ee2012-07-26 20:03:32 +0000182 | SkGPipeWriter::kSharedAddressSpace_Flag }
scroggo@google.com565254b2012-06-28 15:41:32 +0000183};
184
epoger@google.comde961632012-10-26 18:56:36 +0000185class GMMain {
186public:
epoger@google.come8ebeb12012-10-29 16:42:11 +0000187 GMMain() {
188 // Set default values of member variables, which tool_main()
189 // may override.
epoger@google.come8ebeb12012-10-29 16:42:11 +0000190 fUseFileHierarchy = false;
epoger@google.com6f6568b2013-03-22 17:29:46 +0000191 fIgnorableErrorCombination.add(kMissingExpectations_ErrorType);
junov@chromium.org95146eb2013-01-11 21:04:40 +0000192 fMismatchPath = NULL;
epoger@google.come8ebeb12012-10-29 16:42:11 +0000193 }
194
195 SkString make_name(const char shortName[], const char configName[]) {
196 SkString name;
epoger@google.com57f7abc2012-11-13 03:41:55 +0000197 if (0 == strlen(configName)) {
198 name.append(shortName);
199 } else if (fUseFileHierarchy) {
epoger@google.come8ebeb12012-10-29 16:42:11 +0000200 name.appendf("%s%c%s", configName, SkPATH_SEPARATOR, shortName);
201 } else {
202 name.appendf("%s_%s", shortName, configName);
203 }
epoger@google.comde961632012-10-26 18:56:36 +0000204 return name;
205 }
206
epoger@google.com5f6a0072013-01-31 16:30:55 +0000207 /* since PNG insists on unpremultiplying our alpha, we take no
208 precision chances and force all pixels to be 100% opaque,
209 otherwise on compare we may not get a perfect match.
210 */
211 static void force_all_opaque(const SkBitmap& bitmap) {
212 SkBitmap::Config config = bitmap.config();
213 switch (config) {
214 case SkBitmap::kARGB_8888_Config:
215 force_all_opaque_8888(bitmap);
216 break;
217 case SkBitmap::kRGB_565_Config:
218 // nothing to do here; 565 bitmaps are inherently opaque
219 break;
220 default:
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000221 gm_fprintf(stderr, "unsupported bitmap config %d\n", config);
222 DEBUGFAIL_SEE_STDERR;
epoger@google.com5f6a0072013-01-31 16:30:55 +0000223 }
224 }
225
226 static void force_all_opaque_8888(const SkBitmap& bitmap) {
227 SkAutoLockPixels lock(bitmap);
228 for (int y = 0; y < bitmap.height(); y++) {
229 for (int x = 0; x < bitmap.width(); x++) {
230 *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT);
231 }
232 }
233 }
234
235 static bool write_bitmap(const SkString& path, const SkBitmap& bitmap) {
236 // TODO(epoger): Now that we have removed force_all_opaque()
237 // from this method, we should be able to get rid of the
238 // transformation to 8888 format also.
239 SkBitmap copy;
240 bitmap.copyTo(&copy, SkBitmap::kARGB_8888_Config);
241 return SkImageEncoder::EncodeFile(path.c_str(), copy,
242 SkImageEncoder::kPNG_Type, 100);
243 }
244
epoger@google.com6f6568b2013-03-22 17:29:46 +0000245 /**
246 * Records the errors encountered in fFailedTests, except for any error
247 * types we want to ignore.
248 */
249 void RecordError(const ErrorCombination& errorCombination, const SkString& name,
epoger@google.com5f6a0072013-01-31 16:30:55 +0000250 const char renderModeDescriptor []) {
epoger@google.comeb066362013-03-08 09:39:36 +0000251 // The common case: no error means nothing to record.
epoger@google.com6f6568b2013-03-22 17:29:46 +0000252 if (errorCombination.isEmpty()) {
epoger@google.com5f6a0072013-01-31 16:30:55 +0000253 return;
epoger@google.comeb066362013-03-08 09:39:36 +0000254 }
255
256 // If only certain error type(s) were reported, we know we can ignore them.
epoger@google.com6f6568b2013-03-22 17:29:46 +0000257 if (errorCombination.minus(fIgnorableErrorCombination).isEmpty()) {
epoger@google.com5f6a0072013-01-31 16:30:55 +0000258 return;
epoger@google.com5f6a0072013-01-31 16:30:55 +0000259 }
260
epoger@google.com6f6568b2013-03-22 17:29:46 +0000261 FailRec& rec = fFailedTests.push_back(make_name(name.c_str(), renderModeDescriptor));
262 rec.fIsPixelError = errorCombination.includes(kImageMismatch_ErrorType);
epoger@google.com5f6a0072013-01-31 16:30:55 +0000263 }
264
265 // List contents of fFailedTests via SkDebug.
266 void ListErrors() {
267 for (int i = 0; i < fFailedTests.count(); ++i) {
268 if (fFailedTests[i].fIsPixelError) {
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000269 gm_fprintf(stderr, "\t\t%s pixel_error\n", fFailedTests[i].fName.c_str());
epoger@google.com5f6a0072013-01-31 16:30:55 +0000270 } else {
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000271 gm_fprintf(stderr, "\t\t%s\n", fFailedTests[i].fName.c_str());
epoger@google.com5f6a0072013-01-31 16:30:55 +0000272 }
273 }
274 }
275
276 static bool write_document(const SkString& path,
277 const SkDynamicMemoryWStream& document) {
278 SkFILEWStream stream(path.c_str());
279 SkAutoDataUnref data(document.copyToData());
280 return stream.writeData(data.get());
281 }
282
epoger@google.com37269602013-01-19 04:21:27 +0000283 /**
epoger@google.com5f6a0072013-01-31 16:30:55 +0000284 * Prepare an SkBitmap to render a GM into.
285 *
286 * After you've rendered the GM into the SkBitmap, you must call
287 * complete_bitmap()!
288 *
289 * @todo thudson 22 April 2011 - could refactor this to take in
290 * a factory to generate the context, always call readPixels()
291 * (logically a noop for rasters, if wasted time), and thus collapse the
292 * GPU special case and also let this be used for SkPicture testing.
293 */
294 static void setup_bitmap(const ConfigData& gRec, SkISize& size,
295 SkBitmap* bitmap) {
296 bitmap->setConfig(gRec.fConfig, size.width(), size.height());
297 bitmap->allocPixels();
298 bitmap->eraseColor(SK_ColorTRANSPARENT);
299 }
300
301 /**
302 * Any finalization steps we need to perform on the SkBitmap after
303 * we have rendered the GM into it.
epoger@google.com37269602013-01-19 04:21:27 +0000304 *
305 * It's too bad that we are throwing away alpha channel data
306 * we could otherwise be examining, but this had always been happening
307 * before... it was buried within the compare() method at
308 * https://code.google.com/p/skia/source/browse/trunk/gm/gmmain.cpp?r=7289#305 .
309 *
310 * Apparently we need this, at least for bitmaps that are either:
311 * (a) destined to be written out as PNG files, or
312 * (b) compared against bitmaps read in from PNG files
313 * for the reasons described just above the force_all_opaque() method.
314 *
315 * Neglecting to do this led to the difficult-to-diagnose
316 * http://code.google.com/p/skia/issues/detail?id=1079 ('gm generating
317 * spurious pixel_error messages as of r7258')
318 *
319 * TODO(epoger): Come up with a better solution that allows us to
320 * compare full pixel data, including alpha channel, while still being
321 * robust in the face of transformations to/from PNG files.
322 * Options include:
323 *
324 * 1. Continue to call force_all_opaque(), but ONLY for bitmaps that
325 * will be written to, or compared against, PNG files.
326 * PRO: Preserve/compare alpha channel info for the non-PNG cases
327 * (comparing different renderModes in-memory)
328 * CON: The bitmaps (and checksums) for these non-PNG cases would be
329 * different than those for the PNG-compared cases, and in the
330 * case of a failed renderMode comparison, how would we write the
331 * image to disk for examination?
332 *
333 * 2. Always compute image checksums from PNG format (either
334 * directly from the the bytes of a PNG file, or capturing the
335 * bytes we would have written to disk if we were writing the
336 * bitmap out as a PNG).
337 * PRO: I think this would allow us to never force opaque, and to
338 * the extent that alpha channel data can be preserved in a PNG
339 * file, we could observe it.
340 * CON: If we read a bitmap from disk, we need to take its checksum
341 * from the source PNG (we can't compute it from the bitmap we
342 * read out of the PNG, because we will have already premultiplied
343 * the alpha).
344 * CON: Seems wasteful to convert a bitmap to PNG format just to take
345 * its checksum. (Although we're wasting lots of effort already
346 * calling force_all_opaque().)
347 *
348 * 3. Make the alpha premultiply/unpremultiply routines 100% consistent,
349 * so we can transform images back and forth without fear of off-by-one
350 * errors.
351 * CON: Math is hard.
352 *
353 * 4. Perform a "close enough" comparison of bitmaps (+/- 1 bit in each
354 * channel), rather than demanding absolute equality.
355 * CON: Can't do this with checksums.
356 */
epoger@google.com5f6a0072013-01-31 16:30:55 +0000357 static void complete_bitmap(SkBitmap* bitmap) {
358 force_all_opaque(*bitmap);
epoger@google.comde961632012-10-26 18:56:36 +0000359 }
360
scroggo@google.com09fd4d22013-03-20 14:20:18 +0000361 static void installFilter(SkCanvas* canvas);
epoger@google.comde961632012-10-26 18:56:36 +0000362
reed@google.comaef73612012-11-16 13:41:45 +0000363 static void invokeGM(GM* gm, SkCanvas* canvas, bool isPDF, bool isDeferred) {
epoger@google.comde961632012-10-26 18:56:36 +0000364 SkAutoCanvasRestore acr(canvas, true);
365
366 if (!isPDF) {
367 canvas->concat(gm->getInitialTransform());
368 }
369 installFilter(canvas);
reed@google.comaef73612012-11-16 13:41:45 +0000370 gm->setCanvasIsDeferred(isDeferred);
epoger@google.comde961632012-10-26 18:56:36 +0000371 gm->draw(canvas);
372 canvas->setDrawFilter(NULL);
373 }
374
epoger@google.com6f6568b2013-03-22 17:29:46 +0000375 static ErrorCombination generate_image(GM* gm, const ConfigData& gRec,
376 GrContext* context,
377 GrRenderTarget* rt,
378 SkBitmap* bitmap,
379 bool deferred) {
epoger@google.comde961632012-10-26 18:56:36 +0000380 SkISize size (gm->getISize());
381 setup_bitmap(gRec, size, bitmap);
382
383 SkAutoTUnref<SkCanvas> canvas;
384
385 if (gRec.fBackend == kRaster_Backend) {
386 SkAutoTUnref<SkDevice> device(new SkDevice(*bitmap));
387 if (deferred) {
388 canvas.reset(new SkDeferredCanvas(device));
389 } else {
390 canvas.reset(new SkCanvas(device));
391 }
reed@google.comaef73612012-11-16 13:41:45 +0000392 invokeGM(gm, canvas, false, deferred);
epoger@google.comde961632012-10-26 18:56:36 +0000393 canvas->flush();
394 }
395#if SK_SUPPORT_GPU
396 else { // GPU
397 if (NULL == context) {
epoger@google.com6f6568b2013-03-22 17:29:46 +0000398 return ErrorCombination(kNoGpuContext_ErrorType);
epoger@google.comde961632012-10-26 18:56:36 +0000399 }
400 SkAutoTUnref<SkDevice> device(new SkGpuDevice(context, rt));
401 if (deferred) {
402 canvas.reset(new SkDeferredCanvas(device));
403 } else {
404 canvas.reset(new SkCanvas(device));
405 }
reed@google.comaef73612012-11-16 13:41:45 +0000406 invokeGM(gm, canvas, false, deferred);
epoger@google.comde961632012-10-26 18:56:36 +0000407 // the device is as large as the current rendertarget, so
408 // we explicitly only readback the amount we expect (in
409 // size) overwrite our previous allocation
410 bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth,
411 size.fHeight);
412 canvas->readPixels(bitmap, 0, 0);
413 }
414#endif
epoger@google.com5f6a0072013-01-31 16:30:55 +0000415 complete_bitmap(bitmap);
epoger@google.com6f6568b2013-03-22 17:29:46 +0000416 return kEmpty_ErrorCombination;
epoger@google.comde961632012-10-26 18:56:36 +0000417 }
418
419 static void generate_image_from_picture(GM* gm, const ConfigData& gRec,
junov@chromium.orgc938c482012-12-19 15:24:38 +0000420 SkPicture* pict, SkBitmap* bitmap,
421 SkScalar scale = SK_Scalar1) {
epoger@google.comde961632012-10-26 18:56:36 +0000422 SkISize size = gm->getISize();
423 setup_bitmap(gRec, size, bitmap);
424 SkCanvas canvas(*bitmap);
425 installFilter(&canvas);
junov@chromium.orgc938c482012-12-19 15:24:38 +0000426 canvas.scale(scale, scale);
epoger@google.comde961632012-10-26 18:56:36 +0000427 canvas.drawPicture(*pict);
epoger@google.com5f6a0072013-01-31 16:30:55 +0000428 complete_bitmap(bitmap);
epoger@google.comde961632012-10-26 18:56:36 +0000429 }
430
431 static void generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) {
432#ifdef SK_SUPPORT_PDF
433 SkMatrix initialTransform = gm->getInitialTransform();
434 SkISize pageSize = gm->getISize();
435 SkPDFDevice* dev = NULL;
436 if (initialTransform.isIdentity()) {
437 dev = new SkPDFDevice(pageSize, pageSize, initialTransform);
438 } else {
439 SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()),
440 SkIntToScalar(pageSize.height()));
441 initialTransform.mapRect(&content);
442 content.intersect(0, 0, SkIntToScalar(pageSize.width()),
443 SkIntToScalar(pageSize.height()));
444 SkISize contentSize =
445 SkISize::Make(SkScalarRoundToInt(content.width()),
446 SkScalarRoundToInt(content.height()));
447 dev = new SkPDFDevice(pageSize, contentSize, initialTransform);
448 }
449 SkAutoUnref aur(dev);
450
451 SkCanvas c(dev);
reed@google.comaef73612012-11-16 13:41:45 +0000452 invokeGM(gm, &c, true, false);
epoger@google.comde961632012-10-26 18:56:36 +0000453
454 SkPDFDocument doc;
455 doc.appendPage(dev);
456 doc.emitPDF(&pdf);
457#endif
458 }
459
460 static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) {
461#ifdef SK_SUPPORT_XPS
462 SkISize size = gm->getISize();
463
464 SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()),
465 SkIntToScalar(size.height()));
466 static const SkScalar inchesPerMeter = SkScalarDiv(10000, 254);
467 static const SkScalar upm = 72 * inchesPerMeter;
468 SkVector unitsPerMeter = SkPoint::Make(upm, upm);
469 static const SkScalar ppm = 200 * inchesPerMeter;
470 SkVector pixelsPerMeter = SkPoint::Make(ppm, ppm);
471
472 SkXPSDevice* dev = new SkXPSDevice();
473 SkAutoUnref aur(dev);
474
475 SkCanvas c(dev);
476 dev->beginPortfolio(&xps);
477 dev->beginSheet(unitsPerMeter, pixelsPerMeter, trimSize);
reed@google.comaef73612012-11-16 13:41:45 +0000478 invokeGM(gm, &c, false, false);
epoger@google.comde961632012-10-26 18:56:36 +0000479 dev->endSheet();
480 dev->endPortfolio();
481
482#endif
483 }
484
epoger@google.com6f6568b2013-03-22 17:29:46 +0000485 ErrorCombination write_reference_image(const ConfigData& gRec, const char writePath [],
486 const char renderModeDescriptor [], const SkString& name,
487 SkBitmap& bitmap, SkDynamicMemoryWStream* document) {
epoger@google.comde961632012-10-26 18:56:36 +0000488 SkString path;
489 bool success = false;
490 if (gRec.fBackend == kRaster_Backend ||
491 gRec.fBackend == kGPU_Backend ||
492 (gRec.fBackend == kPDF_Backend && CAN_IMAGE_PDF)) {
493
epoger@google.com37269602013-01-19 04:21:27 +0000494 path = make_filename(writePath, renderModeDescriptor, name.c_str(),
495 "png");
epoger@google.comde961632012-10-26 18:56:36 +0000496 success = write_bitmap(path, bitmap);
497 }
498 if (kPDF_Backend == gRec.fBackend) {
epoger@google.com37269602013-01-19 04:21:27 +0000499 path = make_filename(writePath, renderModeDescriptor, name.c_str(),
500 "pdf");
epoger@google.comde961632012-10-26 18:56:36 +0000501 success = write_document(path, *document);
502 }
503 if (kXPS_Backend == gRec.fBackend) {
epoger@google.com37269602013-01-19 04:21:27 +0000504 path = make_filename(writePath, renderModeDescriptor, name.c_str(),
505 "xps");
epoger@google.comde961632012-10-26 18:56:36 +0000506 success = write_document(path, *document);
507 }
508 if (success) {
epoger@google.com6f6568b2013-03-22 17:29:46 +0000509 return kEmpty_ErrorCombination;
epoger@google.comde961632012-10-26 18:56:36 +0000510 } else {
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000511 gm_fprintf(stderr, "FAILED to write %s\n", path.c_str());
epoger@google.com6f6568b2013-03-22 17:29:46 +0000512 ErrorCombination errors(kWritingReferenceImage_ErrorType);
513 RecordError(errors, name, renderModeDescriptor);
514 return errors;
epoger@google.comde961632012-10-26 18:56:36 +0000515 }
516 }
517
epoger@google.com37269602013-01-19 04:21:27 +0000518 /**
epoger@google.com84a18022013-02-01 20:39:15 +0000519 * Log more detail about the mistmatch between expectedBitmap and
520 * actualBitmap.
521 */
522 void report_bitmap_diffs(const SkBitmap& expectedBitmap, const SkBitmap& actualBitmap,
523 const char *testName) {
524 const int expectedWidth = expectedBitmap.width();
525 const int expectedHeight = expectedBitmap.height();
526 const int width = actualBitmap.width();
527 const int height = actualBitmap.height();
528 if ((expectedWidth != width) || (expectedHeight != height)) {
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000529 gm_fprintf(stderr, "---- %s: dimension mismatch --"
530 " expected [%d %d], actual [%d %d]\n",
531 testName, expectedWidth, expectedHeight, width, height);
epoger@google.com84a18022013-02-01 20:39:15 +0000532 return;
533 }
534
535 if ((SkBitmap::kARGB_8888_Config != expectedBitmap.config()) ||
536 (SkBitmap::kARGB_8888_Config != actualBitmap.config())) {
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000537 gm_fprintf(stderr, "---- %s: not computing max per-channel"
538 " pixel mismatch because non-8888\n", testName);
epoger@google.com84a18022013-02-01 20:39:15 +0000539 return;
540 }
541
542 SkAutoLockPixels alp0(expectedBitmap);
543 SkAutoLockPixels alp1(actualBitmap);
544 int errR = 0;
545 int errG = 0;
546 int errB = 0;
547 int errA = 0;
548 int differingPixels = 0;
549
550 for (int y = 0; y < height; ++y) {
551 const SkPMColor* expectedPixelPtr = expectedBitmap.getAddr32(0, y);
552 const SkPMColor* actualPixelPtr = actualBitmap.getAddr32(0, y);
553 for (int x = 0; x < width; ++x) {
554 SkPMColor expectedPixel = *expectedPixelPtr++;
555 SkPMColor actualPixel = *actualPixelPtr++;
556 if (expectedPixel != actualPixel) {
557 differingPixels++;
558 errR = SkMax32(errR, SkAbs32((int)SkGetPackedR32(expectedPixel) -
559 (int)SkGetPackedR32(actualPixel)));
560 errG = SkMax32(errG, SkAbs32((int)SkGetPackedG32(expectedPixel) -
561 (int)SkGetPackedG32(actualPixel)));
562 errB = SkMax32(errB, SkAbs32((int)SkGetPackedB32(expectedPixel) -
563 (int)SkGetPackedB32(actualPixel)));
564 errA = SkMax32(errA, SkAbs32((int)SkGetPackedA32(expectedPixel) -
565 (int)SkGetPackedA32(actualPixel)));
566 }
567 }
568 }
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000569 gm_fprintf(stderr, "---- %s: %d (of %d) differing pixels,"
570 " max per-channel mismatch R=%d G=%d B=%d A=%d\n",
571 testName, differingPixels, width*height, errR, errG, errB, errA);
epoger@google.com84a18022013-02-01 20:39:15 +0000572 }
573
574 /**
epoger@google.com6f6568b2013-03-22 17:29:46 +0000575 * Compares actual checksum to expectations, returning the set of errors
576 * (if any) that we saw along the way.
epoger@google.com37269602013-01-19 04:21:27 +0000577 *
578 * If fMismatchPath has been set, and there are pixel diffs, then the
579 * actual bitmap will be written out to a file within fMismatchPath.
580 *
581 * @param expectations what expectations to compare actualBitmap against
582 * @param actualBitmap the image we actually generated
583 * @param baseNameString name of test without renderModeDescriptor added
584 * @param renderModeDescriptor e.g., "-rtree", "-deferred"
585 * @param addToJsonSummary whether to add these results (both actual and
586 * expected) to the JSON summary
587 *
588 * TODO: For now, addToJsonSummary is only set to true within
589 * compare_test_results_to_stored_expectations(), so results of our
590 * in-memory comparisons (Rtree vs regular, etc.) are not written to the
591 * JSON summary. We may wish to change that.
592 */
epoger@google.com6f6568b2013-03-22 17:29:46 +0000593 ErrorCombination compare_to_expectations(Expectations expectations,
594 const SkBitmap& actualBitmap,
595 const SkString& baseNameString,
596 const char renderModeDescriptor[],
597 bool addToJsonSummary=false) {
598 ErrorCombination errors;
epoger@google.com5f6a0072013-01-31 16:30:55 +0000599 Checksum actualChecksum = SkBitmapChecksummer::Compute64(actualBitmap);
epoger@google.com37269602013-01-19 04:21:27 +0000600 SkString completeNameString = baseNameString;
601 completeNameString.append(renderModeDescriptor);
602 const char* completeName = completeNameString.c_str();
epoger@google.comee8a8e32012-12-18 19:13:49 +0000603
epoger@google.com37269602013-01-19 04:21:27 +0000604 if (expectations.empty()) {
epoger@google.com6f6568b2013-03-22 17:29:46 +0000605 errors.add(kMissingExpectations_ErrorType);
606 } else if (!expectations.match(actualChecksum)) {
607 errors.add(kImageMismatch_ErrorType);
epoger@google.com84a18022013-02-01 20:39:15 +0000608
609 // Write out the "actuals" for any mismatches, if we have
610 // been directed to do so.
epoger@google.com37269602013-01-19 04:21:27 +0000611 if (fMismatchPath) {
612 SkString path =
613 make_filename(fMismatchPath, renderModeDescriptor,
614 baseNameString.c_str(), "png");
615 write_bitmap(path, actualBitmap);
616 }
epoger@google.com84a18022013-02-01 20:39:15 +0000617
618 // If we have access to a single expected bitmap, log more
619 // detail about the mismatch.
620 const SkBitmap *expectedBitmapPtr = expectations.asBitmap();
621 if (NULL != expectedBitmapPtr) {
622 report_bitmap_diffs(*expectedBitmapPtr, actualBitmap, completeName);
623 }
epoger@google.coma243b222013-01-17 17:54:28 +0000624 }
epoger@google.com6f6568b2013-03-22 17:29:46 +0000625 RecordError(errors, baseNameString, renderModeDescriptor);
epoger@google.coma243b222013-01-17 17:54:28 +0000626
epoger@google.com37269602013-01-19 04:21:27 +0000627 if (addToJsonSummary) {
epoger@google.com6f6568b2013-03-22 17:29:46 +0000628 add_actual_results_to_json_summary(completeName, actualChecksum, errors,
epoger@google.com37269602013-01-19 04:21:27 +0000629 expectations.ignoreFailure());
630 add_expected_results_to_json_summary(completeName, expectations);
631 }
epoger@google.coma243b222013-01-17 17:54:28 +0000632
epoger@google.com6f6568b2013-03-22 17:29:46 +0000633 return errors;
epoger@google.com06b8a192013-01-15 19:10:16 +0000634 }
635
epoger@google.com37269602013-01-19 04:21:27 +0000636 /**
637 * Add this result to the appropriate JSON collection of actual results,
638 * depending on status.
639 */
640 void add_actual_results_to_json_summary(const char testName[],
641 Checksum actualChecksum,
epoger@google.com6f6568b2013-03-22 17:29:46 +0000642 ErrorCombination result,
epoger@google.com37269602013-01-19 04:21:27 +0000643 bool ignoreFailure) {
644 Json::Value actualResults;
645 actualResults[kJsonKey_ActualResults_AnyStatus_Checksum] =
646 asJsonValue(actualChecksum);
epoger@google.com6f6568b2013-03-22 17:29:46 +0000647 if (result.isEmpty()) {
epoger@google.com37269602013-01-19 04:21:27 +0000648 this->fJsonActualResults_Succeeded[testName] = actualResults;
649 } else {
650 if (ignoreFailure) {
651 // TODO: Once we have added the ability to compare
652 // actual results against expectations in a JSON file
653 // (where we can set ignore-failure to either true or
epoger@google.com84a18022013-02-01 20:39:15 +0000654 // false), add test cases that exercise ignored
epoger@google.com6f6568b2013-03-22 17:29:46 +0000655 // failures (both for kMissingExpectations_ErrorType
656 // and kImageMismatch_ErrorType).
epoger@google.com37269602013-01-19 04:21:27 +0000657 this->fJsonActualResults_FailureIgnored[testName] =
658 actualResults;
659 } else {
epoger@google.com6f6568b2013-03-22 17:29:46 +0000660 if (result.includes(kMissingExpectations_ErrorType)) {
epoger@google.com37269602013-01-19 04:21:27 +0000661 // TODO: What about the case where there IS an
662 // expected image checksum, but that gm test
663 // doesn't actually run? For now, those cases
664 // will always be ignored, because gm only looks
665 // at expectations that correspond to gm tests
666 // that were actually run.
667 //
668 // Once we have the ability to express
669 // expectations as a JSON file, we should fix this
670 // (and add a test case for which an expectation
671 // is given but the test is never run).
672 this->fJsonActualResults_NoComparison[testName] =
673 actualResults;
epoger@google.comeb066362013-03-08 09:39:36 +0000674 }
epoger@google.com6f6568b2013-03-22 17:29:46 +0000675 if (result.includes(kImageMismatch_ErrorType)) {
epoger@google.com37269602013-01-19 04:21:27 +0000676 this->fJsonActualResults_Failed[testName] = actualResults;
epoger@google.com37269602013-01-19 04:21:27 +0000677 }
678 }
679 }
680 }
681
682 /**
683 * Add this test to the JSON collection of expected results.
684 */
685 void add_expected_results_to_json_summary(const char testName[],
686 Expectations expectations) {
687 // For now, we assume that this collection starts out empty and we
688 // just fill it in as we go; once gm accepts a JSON file as input,
689 // we'll have to change that.
690 Json::Value expectedResults;
691 expectedResults[kJsonKey_ExpectedResults_Checksums] =
692 expectations.allowedChecksumsAsJson();
693 expectedResults[kJsonKey_ExpectedResults_IgnoreFailure] =
694 expectations.ignoreFailure();
695 this->fJsonExpectedResults[testName] = expectedResults;
696 }
697
698 /**
699 * Compare actualBitmap to expectations stored in this->fExpectationsSource.
700 *
701 * @param gm which test generated the actualBitmap
702 * @param gRec
703 * @param writePath unless this is NULL, write out actual images into this
704 * directory
705 * @param actualBitmap bitmap generated by this run
706 * @param pdf
707 */
epoger@google.com6f6568b2013-03-22 17:29:46 +0000708 ErrorCombination compare_test_results_to_stored_expectations(
epoger@google.com37269602013-01-19 04:21:27 +0000709 GM* gm, const ConfigData& gRec, const char writePath[],
710 SkBitmap& actualBitmap, SkDynamicMemoryWStream* pdf) {
711
epoger@google.coma243b222013-01-17 17:54:28 +0000712 SkString name = make_name(gm->shortName(), gRec.fName);
epoger@google.com6f6568b2013-03-22 17:29:46 +0000713 ErrorCombination errors;
epoger@google.com9ef89ce2013-01-18 21:45:42 +0000714
epoger@google.com6f6568b2013-03-22 17:29:46 +0000715 ExpectationsSource *expectationsSource = this->fExpectationsSource.get();
epoger@google.com37269602013-01-19 04:21:27 +0000716 if (expectationsSource && (gRec.fFlags & kRead_ConfigFlag)) {
717 /*
718 * Get the expected results for this test, as one or more allowed
719 * checksums. The current implementation of expectationsSource
720 * get this by computing the checksum of a single PNG file on disk.
721 *
722 * TODO(epoger): This relies on the fact that
723 * force_all_opaque() was called on the bitmap before it
724 * was written to disk as a PNG in the first place. If
725 * not, the checksum returned here may not match the
726 * checksum of actualBitmap, which *has* been run through
727 * force_all_opaque().
epoger@google.com5f6a0072013-01-31 16:30:55 +0000728 * See comments above complete_bitmap() for more detail.
epoger@google.com37269602013-01-19 04:21:27 +0000729 */
730 Expectations expectations = expectationsSource->get(name.c_str());
epoger@google.com6f6568b2013-03-22 17:29:46 +0000731 errors.add(compare_to_expectations(expectations, actualBitmap,
732 name, "", true));
epoger@google.com37269602013-01-19 04:21:27 +0000733 } else {
734 // If we are running without expectations, we still want to
epoger@google.com9ef89ce2013-01-18 21:45:42 +0000735 // record the actual results.
epoger@google.com5f6a0072013-01-31 16:30:55 +0000736 Checksum actualChecksum =
737 SkBitmapChecksummer::Compute64(actualBitmap);
epoger@google.com37269602013-01-19 04:21:27 +0000738 add_actual_results_to_json_summary(name.c_str(), actualChecksum,
epoger@google.com6f6568b2013-03-22 17:29:46 +0000739 ErrorCombination(kMissingExpectations_ErrorType),
epoger@google.com37269602013-01-19 04:21:27 +0000740 false);
epoger@google.com9ef89ce2013-01-18 21:45:42 +0000741 }
epoger@google.com37269602013-01-19 04:21:27 +0000742
743 // TODO: Consider moving this into compare_to_expectations(),
744 // similar to fMismatchPath... for now, we don't do that, because
745 // we don't want to write out the actual bitmaps for all
746 // renderModes of all tests! That would be a lot of files.
epoger@google.com9ef89ce2013-01-18 21:45:42 +0000747 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) {
epoger@google.com6f6568b2013-03-22 17:29:46 +0000748 errors.add(write_reference_image(gRec, writePath, "",
749 name, actualBitmap, pdf));
epoger@google.com9ef89ce2013-01-18 21:45:42 +0000750 }
epoger@google.com37269602013-01-19 04:21:27 +0000751
epoger@google.com6f6568b2013-03-22 17:29:46 +0000752 return errors;
epoger@google.coma243b222013-01-17 17:54:28 +0000753 }
754
epoger@google.com37269602013-01-19 04:21:27 +0000755 /**
756 * Compare actualBitmap to referenceBitmap.
757 *
758 * @param gm which test generated the bitmap
759 * @param gRec
760 * @param renderModeDescriptor
761 * @param actualBitmap actual bitmap generated by this run
762 * @param referenceBitmap bitmap we expected to be generated
763 */
epoger@google.com6f6568b2013-03-22 17:29:46 +0000764 ErrorCombination compare_test_results_to_reference_bitmap(
epoger@google.com37269602013-01-19 04:21:27 +0000765 GM* gm, const ConfigData& gRec, const char renderModeDescriptor [],
766 SkBitmap& actualBitmap, const SkBitmap* referenceBitmap) {
767
768 SkASSERT(referenceBitmap);
769 SkString name = make_name(gm->shortName(), gRec.fName);
epoger@google.com84a18022013-02-01 20:39:15 +0000770 Expectations expectations(*referenceBitmap);
epoger@google.com37269602013-01-19 04:21:27 +0000771 return compare_to_expectations(expectations, actualBitmap,
772 name, renderModeDescriptor);
773 }
774
junov@chromium.org20bd04e2013-01-16 18:43:36 +0000775 static SkPicture* generate_new_picture(GM* gm, BbhType bbhType, uint32_t recordFlags,
776 SkScalar scale = SK_Scalar1) {
epoger@google.comde961632012-10-26 18:56:36 +0000777 // Pictures are refcounted so must be on heap
junov@chromium.org3cb834b2012-12-13 16:39:53 +0000778 SkPicture* pict;
junov@chromium.org706ff2f2012-12-19 15:55:40 +0000779 int width = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().width()), scale));
780 int height = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().height()), scale));
skia.committer@gmail.comd8b27992012-12-20 02:01:41 +0000781
junov@chromium.org3cb834b2012-12-13 16:39:53 +0000782 if (kTileGrid_BbhType == bbhType) {
junov@chromium.org29b19e52013-02-27 18:35:16 +0000783 SkTileGridPicture::TileGridInfo info;
784 info.fMargin.setEmpty();
785 info.fOffset.setZero();
786 info.fTileInterval.set(16, 16);
787 pict = new SkTileGridPicture(width, height, info);
junov@chromium.org3cb834b2012-12-13 16:39:53 +0000788 } else {
789 pict = new SkPicture;
790 }
junov@chromium.org20bd04e2013-01-16 18:43:36 +0000791 if (kNone_BbhType != bbhType) {
792 recordFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag;
793 }
junov@chromium.org706ff2f2012-12-19 15:55:40 +0000794 SkCanvas* cv = pict->beginRecording(width, height, recordFlags);
junov@chromium.orgc938c482012-12-19 15:24:38 +0000795 cv->scale(scale, scale);
reed@google.comaef73612012-11-16 13:41:45 +0000796 invokeGM(gm, cv, false, false);
epoger@google.comde961632012-10-26 18:56:36 +0000797 pict->endRecording();
798
799 return pict;
800 }
801
802 static SkPicture* stream_to_new_picture(const SkPicture& src) {
803
804 // To do in-memory commiunications with a stream, we need to:
805 // * create a dynamic memory stream
806 // * copy it into a buffer
807 // * create a read stream from it
808 // ?!?!
809
810 SkDynamicMemoryWStream storage;
811 src.serialize(&storage);
812
scroggo@google.com09fd4d22013-03-20 14:20:18 +0000813 size_t streamSize = storage.getOffset();
epoger@google.comde961632012-10-26 18:56:36 +0000814 SkAutoMalloc dstStorage(streamSize);
815 void* dst = dstStorage.get();
816 //char* dst = new char [streamSize];
817 //@todo thudson 22 April 2011 when can we safely delete [] dst?
818 storage.copyTo(dst);
819 SkMemoryStream pictReadback(dst, streamSize);
820 SkPicture* retval = new SkPicture (&pictReadback);
821 return retval;
822 }
823
824 // Test: draw into a bitmap or pdf.
epoger@google.com15655b22013-01-08 18:47:31 +0000825 // Depending on flags, possibly compare to an expected image.
epoger@google.com6f6568b2013-03-22 17:29:46 +0000826 ErrorCombination test_drawing(GM* gm,
827 const ConfigData& gRec,
828 const char writePath [],
829 GrContext* context,
830 GrRenderTarget* rt,
831 SkBitmap* bitmap) {
epoger@google.comde961632012-10-26 18:56:36 +0000832 SkDynamicMemoryWStream document;
833
834 if (gRec.fBackend == kRaster_Backend ||
835 gRec.fBackend == kGPU_Backend) {
836 // Early exit if we can't generate the image.
epoger@google.com6f6568b2013-03-22 17:29:46 +0000837 ErrorCombination errors = generate_image(gm, gRec, context, rt, bitmap, false);
838 if (!errors.isEmpty()) {
epoger@google.com37269602013-01-19 04:21:27 +0000839 // TODO: Add a test to exercise what the stdout and
840 // JSON look like if we get an "early error" while
841 // trying to generate the image.
epoger@google.comde961632012-10-26 18:56:36 +0000842 return errors;
843 }
844 } else if (gRec.fBackend == kPDF_Backend) {
845 generate_pdf(gm, document);
846#if CAN_IMAGE_PDF
847 SkAutoDataUnref data(document.copyToData());
848 SkMemoryStream stream(data->data(), data->size());
849 SkPDFDocumentToBitmap(&stream, bitmap);
850#endif
851 } else if (gRec.fBackend == kXPS_Backend) {
852 generate_xps(gm, document);
853 }
epoger@google.com37269602013-01-19 04:21:27 +0000854 return compare_test_results_to_stored_expectations(
855 gm, gRec, writePath, *bitmap, &document);
epoger@google.comde961632012-10-26 18:56:36 +0000856 }
857
epoger@google.com6f6568b2013-03-22 17:29:46 +0000858 ErrorCombination test_deferred_drawing(GM* gm,
859 const ConfigData& gRec,
860 const SkBitmap& referenceBitmap,
861 GrContext* context,
862 GrRenderTarget* rt) {
epoger@google.comde961632012-10-26 18:56:36 +0000863 SkDynamicMemoryWStream document;
864
865 if (gRec.fBackend == kRaster_Backend ||
866 gRec.fBackend == kGPU_Backend) {
867 SkBitmap bitmap;
868 // Early exit if we can't generate the image, but this is
869 // expected in some cases, so don't report a test failure.
epoger@google.com6f6568b2013-03-22 17:29:46 +0000870 ErrorCombination errors = generate_image(gm, gRec, context, rt, &bitmap, true);
871 // TODO(epoger): This logic is the opposite of what is
872 // described above... if we succeeded in generating the
873 // -deferred image, we exit early! We should fix this
874 // ASAP, because it is hiding -deferred errors... but for
875 // now, I'm leaving the logic as it is so that the
876 // refactoring change
877 // https://codereview.chromium.org/12992003/ is unblocked.
878 //
879 // Filed as https://code.google.com/p/skia/issues/detail?id=1180
880 // ('image-surface gm test is failing in "deferred" mode,
881 // and gm is not reporting the failure')
882 if (errors.isEmpty()) {
883 return kEmpty_ErrorCombination;
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.com6f6568b2013-03-22 17:29:46 +0000888 return kEmpty_ErrorCombination;
epoger@google.comde961632012-10-26 18:56:36 +0000889 }
890
epoger@google.com6f6568b2013-03-22 17:29:46 +0000891 ErrorCombination test_pipe_playback(GM* gm,
892 const ConfigData& gRec,
893 const SkBitmap& referenceBitmap) {
894 ErrorCombination errors;
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.com6f6568b2013-03-22 17:29:46 +0000910 errors.add(compare_test_results_to_reference_bitmap(
911 gm, gRec, string.c_str(), bitmap, &referenceBitmap));
912 if (!errors.isEmpty()) {
epoger@google.comde961632012-10-26 18:56:36 +0000913 break;
914 }
915 }
916 return errors;
917 }
918
epoger@google.com6f6568b2013-03-22 17:29:46 +0000919 ErrorCombination test_tiled_pipe_playback(GM* gm, const ConfigData& gRec,
920 const SkBitmap& referenceBitmap) {
921 ErrorCombination errors;
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.com6f6568b2013-03-22 17:29:46 +0000937 errors.add(compare_test_results_to_reference_bitmap(
938 gm, gRec, string.c_str(), bitmap, &referenceBitmap));
939 if (!errors.isEmpty()) {
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;
epoger@google.com6f6568b2013-03-22 17:29:46 +0000952 ErrorCombination fIgnorableErrorCombination;
epoger@google.come8ebeb12012-10-29 16:42:11 +0000953
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
epoger@google.com6f6568b2013-03-22 17:29:46 +00001036// Macro magic to convert a numeric preprocessor token into a string.
1037// Adapted from http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
1038// This should probably be moved into one of our common headers...
1039#define TOSTRING_INTERNAL(x) #x
1040#define TOSTRING(x) TOSTRING_INTERNAL(x)
1041
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001042// Alphabetized ignoring "no" prefix ("readPath", "noreplay", "resourcePath").
scroggo@google.com0f567c62013-03-20 15:35:08 +00001043DEFINE_string(config, "", configUsage().c_str());
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001044DEFINE_bool(deferred, true, "Exercise the deferred rendering test pass.");
1045DEFINE_bool(enableMissingWarning, true, "Print message to stderr (but don't fail) if "
1046 "unable to read a reference image for any tests.");
1047DEFINE_string(excludeConfig, "", "Space delimited list of configs to skip.");
1048DEFINE_bool(forceBWtext, false, "Disable text anti-aliasing.");
1049#if SK_SUPPORT_GPU
1050DEFINE_string(gpuCacheSize, "", "<bytes> <count>: Limit the gpu cache to byte size or "
epoger@google.com6f6568b2013-03-22 17:29:46 +00001051 "object count. " TOSTRING(DEFAULT_CACHE_VALUE) " for either value means "
1052 "use the default. 0 for either disables the cache.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001053#endif
1054DEFINE_bool(hierarchy, false, "Whether to use multilevel directory structure "
1055 "when reading/writing files.");
1056DEFINE_string(match, "", "Only run tests whose name includes this substring/these substrings "
1057 "(more than one can be supplied, separated by spaces).");
1058DEFINE_string(mismatchPath, "", "Write images for tests that failed due to "
1059 "pixel mismatches into this directory.");
1060DEFINE_string(modulo, "", "[--modulo <remainder> <divisor>]: only run tests for which "
1061 "testIndex %% divisor == remainder.");
1062DEFINE_bool(pdf, true, "Exercise the pdf rendering test pass.");
1063DEFINE_bool(pipe, true, "Exercise the SkGPipe replay test pass.");
1064DEFINE_string2(readPath, r, "", "Read reference images from this dir, and report "
1065 "any differences between those and the newly generated ones.");
1066DEFINE_bool(replay, true, "Exercise the SkPicture replay test pass.");
1067DEFINE_string2(resourcePath, i, "", "Directory that stores image resources.");
1068DEFINE_bool(rtree, true, "Exercise the R-Tree variant of SkPicture test pass.");
1069DEFINE_bool(serialize, true, "Exercise the SkPicture serialization & deserialization test pass.");
1070DEFINE_bool(tiledPipe, false, "Exercise tiled SkGPipe replay.");
1071DEFINE_bool(tileGrid, true, "Exercise the tile grid variant of SkPicture.");
1072DEFINE_string(tileGridReplayScales, "", "Space separated list of floating-point scale "
1073 "factors to be used for tileGrid playback testing. Default value: 1.0");
1074DEFINE_string(writeJsonSummaryPath, "", "Write a JSON-formatted result summary to this file.");
1075DEFINE_bool2(verbose, v, false, "Print diagnostics (e.g. list each config to be tested).");
1076DEFINE_string2(writePath, w, "", "Write rendered images into this directory.");
1077DEFINE_string2(writePicturePath, wp, "", "Write .skp files into this directory.");
1078
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001079static int findConfig(const char config[]) {
1080 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
1081 if (!strcmp(config, gRec[i].fName)) {
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001082 return (int) i;
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001083 }
1084 }
1085 return -1;
1086}
1087
reed@google.comb2a51622011-10-31 16:30:04 +00001088static bool skip_name(const SkTDArray<const char*> array, const char name[]) {
1089 if (0 == array.count()) {
1090 // no names, so don't skip anything
1091 return false;
1092 }
1093 for (int i = 0; i < array.count(); ++i) {
1094 if (strstr(name, array[i])) {
1095 // found the name, so don't skip
1096 return false;
1097 }
1098 }
1099 return true;
1100}
1101
bsalomon@google.comd9f826c2011-07-18 15:25:04 +00001102namespace skiagm {
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001103#if SK_SUPPORT_GPU
bsalomon@google.com7361f542012-04-19 19:15:35 +00001104SkAutoTUnref<GrContext> gGrContext;
1105/**
bsalomon@google.comc7a24d22012-11-01 18:03:48 +00001106 * Sets the global GrContext, accessible by individual GMs
bsalomon@google.com7361f542012-04-19 19:15:35 +00001107 */
caryclark@google.com13130862012-06-06 12:10:45 +00001108static void SetGr(GrContext* grContext) {
bsalomon@google.com7361f542012-04-19 19:15:35 +00001109 SkSafeRef(grContext);
1110 gGrContext.reset(grContext);
bsalomon@google.comd9f826c2011-07-18 15:25:04 +00001111}
bsalomon@google.com7361f542012-04-19 19:15:35 +00001112
1113/**
1114 * Gets the global GrContext, can be called by GM tests.
1115 */
caryclark@google.com13130862012-06-06 12:10:45 +00001116GrContext* GetGr();
bsalomon@google.com7361f542012-04-19 19:15:35 +00001117GrContext* GetGr() {
1118 return gGrContext.get();
1119}
1120
1121/**
1122 * Sets the global GrContext and then resets it to its previous value at
1123 * destruction.
1124 */
1125class AutoResetGr : SkNoncopyable {
1126public:
1127 AutoResetGr() : fOld(NULL) {}
1128 void set(GrContext* context) {
1129 SkASSERT(NULL == fOld);
1130 fOld = GetGr();
1131 SkSafeRef(fOld);
1132 SetGr(context);
1133 }
1134 ~AutoResetGr() { SetGr(fOld); SkSafeUnref(fOld); }
1135private:
1136 GrContext* fOld;
1137};
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001138#else
epoger@google.com80724df2013-03-21 13:49:54 +00001139GrContext* GetGr();
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001140GrContext* GetGr() { return NULL; }
1141#endif
bsalomon@google.comd9f826c2011-07-18 15:25:04 +00001142}
1143
reed@google.comfb2cd422013-01-04 14:43:03 +00001144template <typename T> void appendUnique(SkTDArray<T>* array, const T& value) {
1145 int index = array->find(value);
1146 if (index < 0) {
1147 *array->append() = value;
1148 }
1149}
1150
epoger@google.com80724df2013-03-21 13:49:54 +00001151/**
1152 * Run this test in a number of different configs (8888, 565, PDF,
1153 * etc.), confirming that the resulting bitmaps match expectations
1154 * (which may be different for each config).
1155 *
1156 * Returns all errors encountered while doing so.
1157 */
epoger@google.com6f6568b2013-03-22 17:29:46 +00001158ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm, const SkTDArray<size_t> &configs,
1159 GrContextFactory *grFactory);
1160ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm, const SkTDArray<size_t> &configs,
1161 GrContextFactory *grFactory) {
1162 ErrorCombination errorsForAllConfigs;
epoger@google.com80724df2013-03-21 13:49:54 +00001163 uint32_t gmFlags = gm->getFlags();
1164
epoger@google.com80724df2013-03-21 13:49:54 +00001165 for (int i = 0; i < configs.count(); i++) {
1166 ConfigData config = gRec[configs[i]];
1167
1168 // Skip any tests that we don't even need to try.
1169 if ((kPDF_Backend == config.fBackend) &&
1170 (!FLAGS_pdf|| (gmFlags & GM::kSkipPDF_Flag))) {
1171 continue;
1172 }
1173 if ((gmFlags & GM::kSkip565_Flag) &&
1174 (kRaster_Backend == config.fBackend) &&
1175 (SkBitmap::kRGB_565_Config == config.fConfig)) {
1176 continue;
1177 }
1178 if ((gmFlags & GM::kSkipGPU_Flag) &&
1179 kGPU_Backend == config.fBackend) {
1180 continue;
1181 }
1182
1183 // Now we know that we want to run this test and record its
1184 // success or failure.
epoger@google.com6f6568b2013-03-22 17:29:46 +00001185 ErrorCombination errorsForThisConfig;
epoger@google.com80724df2013-03-21 13:49:54 +00001186 GrRenderTarget* renderTarget = NULL;
1187#if SK_SUPPORT_GPU
1188 SkAutoTUnref<GrRenderTarget> rt;
1189 AutoResetGr autogr;
epoger@google.com6f6568b2013-03-22 17:29:46 +00001190 if ((errorsForThisConfig.isEmpty()) && (kGPU_Backend == config.fBackend)) {
epoger@google.com80724df2013-03-21 13:49:54 +00001191 GrContext* gr = grFactory->get(config.fGLContextType);
1192 bool grSuccess = false;
1193 if (gr) {
1194 // create a render target to back the device
1195 GrTextureDesc desc;
1196 desc.fConfig = kSkia8888_GrPixelConfig;
1197 desc.fFlags = kRenderTarget_GrTextureFlagBit;
1198 desc.fWidth = gm->getISize().width();
1199 desc.fHeight = gm->getISize().height();
1200 desc.fSampleCnt = config.fSampleCnt;
1201 GrTexture* tex = gr->createUncachedTexture(desc, NULL, 0);
1202 if (tex) {
1203 rt.reset(tex->asRenderTarget());
1204 rt.get()->ref();
1205 tex->unref();
1206 autogr.set(gr);
1207 renderTarget = rt.get();
1208 grSuccess = NULL != renderTarget;
1209 }
1210 // Set the user specified cache limits if non-default.
1211 size_t bytes;
1212 int count;
1213 gr->getTextureCacheLimits(&count, &bytes);
epoger@google.com6f6568b2013-03-22 17:29:46 +00001214 if (DEFAULT_CACHE_VALUE != gGpuCacheSizeBytes) {
1215 bytes = static_cast<size_t>(gGpuCacheSizeBytes);
epoger@google.com80724df2013-03-21 13:49:54 +00001216 }
epoger@google.com6f6568b2013-03-22 17:29:46 +00001217 if (DEFAULT_CACHE_VALUE != gGpuCacheSizeCount) {
1218 count = gGpuCacheSizeCount;
epoger@google.com80724df2013-03-21 13:49:54 +00001219 }
1220 gr->setTextureCacheLimits(count, bytes);
1221 }
1222 if (!grSuccess) {
epoger@google.com6f6568b2013-03-22 17:29:46 +00001223 errorsForThisConfig.add(kNoGpuContext_ErrorType);
epoger@google.com80724df2013-03-21 13:49:54 +00001224 }
1225 }
1226#endif
1227
1228 SkBitmap comparisonBitmap;
1229
1230 const char* writePath;
1231 if (FLAGS_writePath.count() == 1) {
1232 writePath = FLAGS_writePath[0];
1233 } else {
1234 writePath = NULL;
1235 }
epoger@google.com6f6568b2013-03-22 17:29:46 +00001236 if (errorsForThisConfig.isEmpty()) {
1237 errorsForThisConfig.add(gmmain.test_drawing(gm, config, writePath, GetGr(),
1238 renderTarget, &comparisonBitmap));
epoger@google.com80724df2013-03-21 13:49:54 +00001239 }
1240
epoger@google.com6f6568b2013-03-22 17:29:46 +00001241 if (FLAGS_deferred && errorsForThisConfig.isEmpty() &&
1242 (kGPU_Backend == config.fBackend || kRaster_Backend == config.fBackend)) {
1243 errorsForThisConfig.add(gmmain.test_deferred_drawing(gm, config, comparisonBitmap,
1244 GetGr(), renderTarget));
epoger@google.com80724df2013-03-21 13:49:54 +00001245 }
1246
epoger@google.com6f6568b2013-03-22 17:29:46 +00001247 errorsForAllConfigs.add(errorsForThisConfig);
epoger@google.com80724df2013-03-21 13:49:54 +00001248 }
1249 return errorsForAllConfigs;
1250}
1251
1252/**
1253 * Run this test in a number of different drawing modes (pipe,
1254 * deferred, tiled, etc.), confirming that the resulting bitmaps all
1255 * *exactly* match comparisonBitmap.
1256 *
1257 * Returns all errors encountered while doing so.
1258 */
epoger@google.com6f6568b2013-03-22 17:29:46 +00001259ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm, const ConfigData &compareConfig,
1260 const SkBitmap &comparisonBitmap,
1261 const SkTDArray<SkScalar> &tileGridReplayScales);
1262ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm, const ConfigData &compareConfig,
1263 const SkBitmap &comparisonBitmap,
1264 const SkTDArray<SkScalar> &tileGridReplayScales) {
1265 ErrorCombination errorsForAllModes;
epoger@google.com80724df2013-03-21 13:49:54 +00001266 uint32_t gmFlags = gm->getFlags();
1267
1268 // run the picture centric GM steps
1269 if (!(gmFlags & GM::kSkipPicture_Flag)) {
1270
epoger@google.com6f6568b2013-03-22 17:29:46 +00001271 ErrorCombination pictErrors;
epoger@google.com80724df2013-03-21 13:49:54 +00001272
1273 //SkAutoTUnref<SkPicture> pict(generate_new_picture(gm));
1274 SkPicture* pict = gmmain.generate_new_picture(gm, kNone_BbhType, 0);
1275 SkAutoUnref aur(pict);
1276
1277 if (FLAGS_replay) {
1278 SkBitmap bitmap;
1279 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap);
epoger@google.com6f6568b2013-03-22 17:29:46 +00001280 pictErrors.add(gmmain.compare_test_results_to_reference_bitmap(
1281 gm, compareConfig, "-replay", bitmap, &comparisonBitmap));
epoger@google.com80724df2013-03-21 13:49:54 +00001282 }
1283
epoger@google.com6f6568b2013-03-22 17:29:46 +00001284 if ((pictErrors.isEmpty()) && FLAGS_serialize) {
epoger@google.com80724df2013-03-21 13:49:54 +00001285 SkPicture* repict = gmmain.stream_to_new_picture(*pict);
1286 SkAutoUnref aurr(repict);
1287
1288 SkBitmap bitmap;
1289 gmmain.generate_image_from_picture(gm, compareConfig, repict, &bitmap);
epoger@google.com6f6568b2013-03-22 17:29:46 +00001290 pictErrors.add(gmmain.compare_test_results_to_reference_bitmap(
1291 gm, compareConfig, "-serialize", bitmap, &comparisonBitmap));
epoger@google.com80724df2013-03-21 13:49:54 +00001292 }
1293
1294 if (FLAGS_writePicturePath.count() == 1) {
1295 const char* pictureSuffix = "skp";
1296 SkString path = make_filename(FLAGS_writePicturePath[0], "",
1297 gm->shortName(), pictureSuffix);
1298 SkFILEWStream stream(path.c_str());
1299 pict->serialize(&stream);
1300 }
1301
epoger@google.com6f6568b2013-03-22 17:29:46 +00001302 errorsForAllModes.add(pictErrors);
epoger@google.com80724df2013-03-21 13:49:54 +00001303 }
1304
1305 // TODO: add a test in which the RTree rendering results in a
1306 // different bitmap than the standard rendering. It should
1307 // show up as failed in the JSON summary, and should be listed
1308 // in the stdout also.
1309 if (!(gmFlags & GM::kSkipPicture_Flag) && FLAGS_rtree) {
1310 SkPicture* pict = gmmain.generate_new_picture(
1311 gm, kRTree_BbhType, SkPicture::kUsePathBoundsForClip_RecordingFlag);
1312 SkAutoUnref aur(pict);
1313 SkBitmap bitmap;
1314 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap);
epoger@google.com6f6568b2013-03-22 17:29:46 +00001315 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap(
1316 gm, compareConfig, "-rtree", bitmap, &comparisonBitmap));
epoger@google.com80724df2013-03-21 13:49:54 +00001317 }
1318
1319 if (!(gmFlags & GM::kSkipPicture_Flag) && FLAGS_tileGrid) {
1320 for(int scaleIndex = 0; scaleIndex < tileGridReplayScales.count(); ++scaleIndex) {
1321 SkScalar replayScale = tileGridReplayScales[scaleIndex];
1322 if ((gmFlags & GM::kSkipScaledReplay_Flag) && replayScale != 1) {
1323 continue;
1324 }
1325 // We record with the reciprocal scale to obtain a replay
1326 // result that can be validated against comparisonBitmap.
1327 SkScalar recordScale = SkScalarInvert(replayScale);
1328 SkPicture* pict = gmmain.generate_new_picture(
1329 gm, kTileGrid_BbhType, SkPicture::kUsePathBoundsForClip_RecordingFlag, recordScale);
1330 SkAutoUnref aur(pict);
1331 SkBitmap bitmap;
1332 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap, replayScale);
1333 SkString suffix("-tilegrid");
1334 if (SK_Scalar1 != replayScale) {
1335 suffix += "-scale-";
1336 suffix.appendScalar(replayScale);
1337 }
epoger@google.com6f6568b2013-03-22 17:29:46 +00001338 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap(
1339 gm, compareConfig, suffix.c_str(), bitmap, &comparisonBitmap));
epoger@google.com80724df2013-03-21 13:49:54 +00001340 }
1341 }
1342
1343 // run the pipe centric GM steps
1344 if (!(gmFlags & GM::kSkipPipe_Flag)) {
1345
epoger@google.com6f6568b2013-03-22 17:29:46 +00001346 ErrorCombination pipeErrors;
epoger@google.com80724df2013-03-21 13:49:54 +00001347
1348 if (FLAGS_pipe) {
epoger@google.com6f6568b2013-03-22 17:29:46 +00001349 pipeErrors.add(gmmain.test_pipe_playback(gm, compareConfig, comparisonBitmap));
epoger@google.com80724df2013-03-21 13:49:54 +00001350 }
1351
epoger@google.com6f6568b2013-03-22 17:29:46 +00001352 if ((pipeErrors.isEmpty()) &&
epoger@google.com80724df2013-03-21 13:49:54 +00001353 FLAGS_tiledPipe && !(gmFlags & GM::kSkipTiled_Flag)) {
epoger@google.com6f6568b2013-03-22 17:29:46 +00001354 pipeErrors.add(gmmain.test_tiled_pipe_playback(gm, compareConfig, comparisonBitmap));
epoger@google.com80724df2013-03-21 13:49:54 +00001355 }
1356
epoger@google.com6f6568b2013-03-22 17:29:46 +00001357 errorsForAllModes.add(pipeErrors);
epoger@google.com80724df2013-03-21 13:49:54 +00001358 }
1359 return errorsForAllModes;
1360}
1361
epoger@google.com0b62b3d2013-03-20 17:59:28 +00001362int tool_main(int argc, char** argv);
1363int tool_main(int argc, char** argv) {
1364
1365#if SK_ENABLE_INST_COUNT
1366 gPrintInstCount = true;
1367#endif
1368
1369 SkGraphics::Init();
1370 // we don't need to see this during a run
1371 gSkSuppressFontCachePurgeSpew = true;
1372
1373 setSystemPreferences();
1374 GMMain gmmain;
1375
1376 SkTDArray<size_t> configs;
1377 SkTDArray<size_t> excludeConfigs;
1378 bool userConfig = false;
1379
1380 SkString usage;
1381 usage.printf("Run the golden master tests.\n");
scroggo@google.comd9ba9a02013-03-21 19:43:15 +00001382 SkCommandLineFlags::SetUsage(usage.c_str());
1383 SkCommandLineFlags::Parse(argc, argv);
epoger@google.com0b62b3d2013-03-20 17:59:28 +00001384
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001385 gmmain.fUseFileHierarchy = FLAGS_hierarchy;
1386 if (FLAGS_mismatchPath.count() == 1) {
1387 gmmain.fMismatchPath = FLAGS_mismatchPath[0];
1388 }
1389
1390 for (int i = 0; i < FLAGS_config.count(); i++) {
1391 int index = findConfig(FLAGS_config[i]);
1392 if (index >= 0) {
1393 appendUnique<size_t>(&configs, index);
1394 userConfig = true;
scroggo@google.com0b735632013-03-19 17:38:50 +00001395 } else {
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001396 gm_fprintf(stderr, "unrecognized config %s\n", FLAGS_config[i]);
scroggo@google.com7d519302013-03-19 17:28:10 +00001397 return -1;
1398 }
1399 }
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001400
1401 for (int i = 0; i < FLAGS_excludeConfig.count(); i++) {
1402 int index = findConfig(FLAGS_excludeConfig[i]);
1403 if (index >= 0) {
1404 *excludeConfigs.append() = index;
1405 } else {
1406 gm_fprintf(stderr, "unrecognized excludeConfig %s\n", FLAGS_excludeConfig[i]);
1407 return -1;
1408 }
1409 }
1410
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001411 int moduloRemainder = -1;
1412 int moduloDivisor = -1;
1413
1414 if (FLAGS_modulo.count() == 2) {
1415 moduloRemainder = atoi(FLAGS_modulo[0]);
1416 moduloDivisor = atoi(FLAGS_modulo[1]);
1417 if (moduloRemainder < 0 || moduloDivisor <= 0 || moduloRemainder >= moduloDivisor) {
1418 gm_fprintf(stderr, "invalid modulo values.");
1419 return -1;
1420 }
tomhudson@google.com9875dd12011-04-25 15:49:53 +00001421 }
reed@google.com873cb1e2010-12-23 15:00:45 +00001422
epoger@google.com6f6568b2013-03-22 17:29:46 +00001423#if SK_SUPPORT_GPU
1424 if (FLAGS_gpuCacheSize.count() > 0) {
1425 if (FLAGS_gpuCacheSize.count() != 2) {
1426 gm_fprintf(stderr, "--gpuCacheSize requires two arguments\n");
1427 return -1;
1428 }
1429 gGpuCacheSizeBytes = atoi(FLAGS_gpuCacheSize[0]);
1430 gGpuCacheSizeCount = atoi(FLAGS_gpuCacheSize[1]);
1431 } else {
1432 gGpuCacheSizeBytes = DEFAULT_CACHE_VALUE;
1433 gGpuCacheSizeCount = DEFAULT_CACHE_VALUE;
1434 }
1435#endif
1436
1437 SkTDArray<SkScalar> tileGridReplayScales;
1438 *tileGridReplayScales.append() = SK_Scalar1; // By default only test at scale 1.0
1439 if (FLAGS_tileGridReplayScales.count() > 0) {
1440 tileGridReplayScales.reset();
1441 for (int i = 0; i < FLAGS_tileGridReplayScales.count(); i++) {
1442 double val = atof(FLAGS_tileGridReplayScales[i]);
1443 if (0 < val) {
1444 *tileGridReplayScales.append() = SkDoubleToScalar(val);
1445 }
1446 }
1447 if (0 == tileGridReplayScales.count()) {
1448 // Should have at least one scale
1449 gm_fprintf(stderr, "--tileGridReplayScales requires at least one scale.\n");
1450 return -1;
1451 }
1452 }
1453
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001454 if (!userConfig) {
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001455 // if no config is specified by user, add the defaults
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001456 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001457 if (gRec[i].fRunByDefault) {
1458 *configs.append() = i;
1459 }
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001460 }
1461 }
reed@google.comfb2cd422013-01-04 14:43:03 +00001462 // now remove any explicitly excluded configs
1463 for (int i = 0; i < excludeConfigs.count(); ++i) {
1464 int index = configs.find(excludeConfigs[i]);
1465 if (index >= 0) {
1466 configs.remove(index);
1467 // now assert that there was only one copy in configs[]
1468 SkASSERT(configs.find(excludeConfigs[i]) < 0);
1469 }
1470 }
1471
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001472#if SK_SUPPORT_GPU
1473 GrContextFactory* grFactory = new GrContextFactory;
1474 for (int i = 0; i < configs.count(); ++i) {
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001475 size_t index = configs[i];
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001476 if (kGPU_Backend == gRec[index].fBackend) {
1477 GrContext* ctx = grFactory->get(gRec[index].fGLContextType);
1478 if (NULL == ctx) {
1479 SkDebugf("GrContext could not be created for config %s. Config will be skipped.",
1480 gRec[index].fName);
1481 configs.remove(i);
1482 --i;
1483 }
1484 if (gRec[index].fSampleCnt > ctx->getMaxSampleCount()) {
1485 SkDebugf("Sample count (%d) of config %s is not supported. Config will be skipped.",
1486 gRec[index].fSampleCnt, gRec[index].fName);
1487 configs.remove(i);
1488 --i;
1489 }
1490 }
1491 }
epoger@google.com80724df2013-03-21 13:49:54 +00001492#else
1493 GrContextFactory* grFactory = NULL;
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001494#endif
1495
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001496 if (FLAGS_verbose) {
reed@google.comfb2cd422013-01-04 14:43:03 +00001497 SkString str;
epoger@google.com5efdd0c2013-03-13 14:18:40 +00001498 str.printf("%d configs:", configs.count());
reed@google.comfb2cd422013-01-04 14:43:03 +00001499 for (int i = 0; i < configs.count(); ++i) {
1500 str.appendf(" %s", gRec[configs[i]].fName);
1501 }
epoger@google.com5efdd0c2013-03-13 14:18:40 +00001502 gm_fprintf(stderr, "%s\n", str.c_str());
reed@google.comfb2cd422013-01-04 14:43:03 +00001503 }
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001504
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001505 if (FLAGS_resourcePath.count() == 1) {
1506 GM::SetResourcePath(FLAGS_resourcePath[0]);
1507 }
robertphillips@google.com8570b5c2012-03-20 17:40:58 +00001508
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001509 if (FLAGS_readPath.count() == 1) {
1510 const char* readPath = FLAGS_readPath[0];
epoger@google.com37269602013-01-19 04:21:27 +00001511 if (!sk_exists(readPath)) {
epoger@google.com5efdd0c2013-03-13 14:18:40 +00001512 gm_fprintf(stderr, "readPath %s does not exist!\n", readPath);
epoger@google.com37269602013-01-19 04:21:27 +00001513 return -1;
1514 }
1515 if (sk_isdir(readPath)) {
epoger@google.com5efdd0c2013-03-13 14:18:40 +00001516 gm_fprintf(stdout, "reading from %s\n", readPath);
epoger@google.com37269602013-01-19 04:21:27 +00001517 gmmain.fExpectationsSource.reset(SkNEW_ARGS(
1518 IndividualImageExpectationsSource,
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001519 (readPath, FLAGS_enableMissingWarning)));
epoger@google.com37269602013-01-19 04:21:27 +00001520 } else {
epoger@google.com5efdd0c2013-03-13 14:18:40 +00001521 gm_fprintf(stdout, "reading expectations from JSON summary file %s\n", readPath);
epoger@google.comd271d242013-02-13 18:14:48 +00001522 gmmain.fExpectationsSource.reset(SkNEW_ARGS(
1523 JsonExpectationsSource, (readPath)));
epoger@google.com37269602013-01-19 04:21:27 +00001524 }
chudy@google.comf32f6e82012-07-12 15:42:37 +00001525 }
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001526 if (FLAGS_writePath.count() == 1) {
1527 gm_fprintf(stderr, "writing to %s\n", FLAGS_writePath[0]);
reed@android.com00f883e2010-12-14 17:46:14 +00001528 }
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001529 if (FLAGS_writePicturePath.count() == 1) {
1530 gm_fprintf(stderr, "writing pictures to %s\n", FLAGS_writePicturePath[0]);
mike@reedtribe.org5d0c62f2012-06-02 14:50:13 +00001531 }
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001532 if (FLAGS_resourcePath.count() == 1) {
1533 gm_fprintf(stderr, "reading resources from %s\n", FLAGS_resourcePath[0]);
robertphillips@google.com8570b5c2012-03-20 17:40:58 +00001534 }
1535
epoger@google.com82cb65b2012-10-29 18:59:17 +00001536 if (moduloDivisor <= 0) {
1537 moduloRemainder = -1;
reed@google.comae7b8f32012-10-18 21:30:57 +00001538 }
epoger@google.com82cb65b2012-10-29 18:59:17 +00001539 if (moduloRemainder < 0 || moduloRemainder >= moduloDivisor) {
1540 moduloRemainder = -1;
reed@google.comae7b8f32012-10-18 21:30:57 +00001541 }
1542
epoger@google.comc7cf2b32011-12-28 19:31:01 +00001543 // Accumulate success of all tests.
1544 int testsRun = 0;
1545 int testsPassed = 0;
1546 int testsFailed = 0;
1547 int testsMissingReferenceImages = 0;
1548
reed@google.comae7b8f32012-10-18 21:30:57 +00001549 int gmIndex = -1;
1550 SkString moduloStr;
1551
epoger@google.come8ebeb12012-10-29 16:42:11 +00001552 // If we will be writing out files, prepare subdirectories.
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001553 if (FLAGS_writePath.count() == 1) {
1554 if (!sk_mkdir(FLAGS_writePath[0])) {
epoger@google.come8ebeb12012-10-29 16:42:11 +00001555 return -1;
1556 }
1557 if (gmmain.fUseFileHierarchy) {
1558 for (int i = 0; i < configs.count(); i++) {
1559 ConfigData config = gRec[configs[i]];
1560 SkString subdir;
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001561 subdir.appendf("%s%c%s", FLAGS_writePath[0], SkPATH_SEPARATOR,
epoger@google.come8ebeb12012-10-29 16:42:11 +00001562 config.fName);
1563 if (!sk_mkdir(subdir.c_str())) {
1564 return -1;
1565 }
1566 }
1567 }
1568 }
1569
bsalomon@google.com7361f542012-04-19 19:15:35 +00001570 Iter iter;
1571 GM* gm;
reed@android.com00dae862009-06-10 15:38:48 +00001572 while ((gm = iter.next()) != NULL) {
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +00001573
reed@google.comae7b8f32012-10-18 21:30:57 +00001574 ++gmIndex;
epoger@google.com82cb65b2012-10-29 18:59:17 +00001575 if (moduloRemainder >= 0) {
1576 if ((gmIndex % moduloDivisor) != moduloRemainder) {
reed@google.comae7b8f32012-10-18 21:30:57 +00001577 continue;
1578 }
epoger@google.com82cb65b2012-10-29 18:59:17 +00001579 moduloStr.printf("[%d.%d] ", gmIndex, moduloDivisor);
reed@google.comae7b8f32012-10-18 21:30:57 +00001580 }
1581
reed@google.comece2b022011-07-25 14:28:57 +00001582 const char* shortName = gm->shortName();
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001583 if (skip_name(FLAGS_match, shortName)) {
reed@google.comece2b022011-07-25 14:28:57 +00001584 SkDELETE(gm);
1585 continue;
1586 }
1587
tomhudson@google.com9875dd12011-04-25 15:49:53 +00001588 SkISize size = gm->getISize();
epoger@google.com5efdd0c2013-03-13 14:18:40 +00001589 gm_fprintf(stdout, "%sdrawing... %s [%d %d]\n", moduloStr.c_str(), shortName,
1590 size.width(), size.height());
djsollen@google.comebce16d2012-10-26 14:07:13 +00001591
epoger@google.com6f6568b2013-03-22 17:29:46 +00001592 ErrorCombination testErrors;
1593 testErrors.add(run_multiple_configs(gmmain, gm, configs, grFactory));
djsollen@google.comebce16d2012-10-26 14:07:13 +00001594
1595 SkBitmap comparisonBitmap;
1596 const ConfigData compareConfig =
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001597 { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "comparison", false };
epoger@google.com6f6568b2013-03-22 17:29:46 +00001598 testErrors.add(gmmain.generate_image(
1599 gm, compareConfig, NULL, NULL, &comparisonBitmap, false));
djsollen@google.comebce16d2012-10-26 14:07:13 +00001600
epoger@google.com80724df2013-03-21 13:49:54 +00001601 // TODO(epoger): only run this if gmmain.generate_image() succeeded?
1602 // Otherwise, what are we comparing against?
epoger@google.com6f6568b2013-03-22 17:29:46 +00001603 testErrors.add(run_multiple_modes(gmmain, gm, compareConfig, comparisonBitmap,
1604 tileGridReplayScales));
djsollen@google.comebce16d2012-10-26 14:07:13 +00001605
1606 // Update overall results.
1607 // We only tabulate the particular error types that we currently
1608 // care about (e.g., missing reference images). Later on, if we
epoger@google.com37269602013-01-19 04:21:27 +00001609 // want to also tabulate other error types, we can do so.
djsollen@google.comebce16d2012-10-26 14:07:13 +00001610 testsRun++;
epoger@google.com37269602013-01-19 04:21:27 +00001611 if (!gmmain.fExpectationsSource.get() ||
epoger@google.com6f6568b2013-03-22 17:29:46 +00001612 (testErrors.includes(kMissingExpectations_ErrorType))) {
djsollen@google.comebce16d2012-10-26 14:07:13 +00001613 testsMissingReferenceImages++;
borenet@google.coma904ea12013-02-21 18:34:14 +00001614 }
epoger@google.com6f6568b2013-03-22 17:29:46 +00001615 if (testErrors.minus(gmmain.fIgnorableErrorCombination).isEmpty()) {
epoger@google.com3499f3c2013-01-10 17:11:27 +00001616 testsPassed++;
djsollen@google.comebce16d2012-10-26 14:07:13 +00001617 } else {
1618 testsFailed++;
1619 }
1620
reed@android.com00dae862009-06-10 15:38:48 +00001621 SkDELETE(gm);
1622 }
epoger@google.com5efdd0c2013-03-13 14:18:40 +00001623 gm_fprintf(stdout, "Ran %d tests: %d passed, %d failed, %d missing reference images\n",
1624 testsRun, testsPassed, testsFailed, testsMissingReferenceImages);
epoger@google.com57f7abc2012-11-13 03:41:55 +00001625 gmmain.ListErrors();
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00001626
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001627 if (FLAGS_writeJsonSummaryPath.count() == 1) {
epoger@google.comee8a8e32012-12-18 19:13:49 +00001628 Json::Value actualResults;
1629 actualResults[kJsonKey_ActualResults_Failed] =
1630 gmmain.fJsonActualResults_Failed;
1631 actualResults[kJsonKey_ActualResults_FailureIgnored] =
1632 gmmain.fJsonActualResults_FailureIgnored;
epoger@google.com9c56a8d2012-12-20 18:34:29 +00001633 actualResults[kJsonKey_ActualResults_NoComparison] =
1634 gmmain.fJsonActualResults_NoComparison;
epoger@google.comee8a8e32012-12-18 19:13:49 +00001635 actualResults[kJsonKey_ActualResults_Succeeded] =
1636 gmmain.fJsonActualResults_Succeeded;
1637 Json::Value root;
1638 root[kJsonKey_ActualResults] = actualResults;
1639 root[kJsonKey_ExpectedResults] = gmmain.fJsonExpectedResults;
1640 std::string jsonStdString = root.toStyledString();
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001641 SkFILEWStream stream(FLAGS_writeJsonSummaryPath[0]);
epoger@google.comee8a8e32012-12-18 19:13:49 +00001642 stream.write(jsonStdString.c_str(), jsonStdString.length());
1643 }
1644
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001645#if SK_SUPPORT_GPU
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00001646
robertphillips@google.com59552022012-08-31 13:07:37 +00001647#if GR_CACHE_STATS
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00001648 for (int i = 0; i < configs.count(); i++) {
1649 ConfigData config = gRec[configs[i]];
1650
1651 if (kGPU_Backend == config.fBackend) {
1652 GrContext* gr = grFactory->get(config.fGLContextType);
1653
epoger@google.com5efdd0c2013-03-13 14:18:40 +00001654 gm_fprintf(stdout, "config: %s %x\n", config.fName, gr);
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00001655 gr->printCacheStats();
1656 }
1657 }
1658#endif
1659
robertphillips@google.com977b9c82012-06-05 19:35:09 +00001660 delete grFactory;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001661#endif
robertphillips@google.com977b9c82012-06-05 19:35:09 +00001662 SkGraphics::Term();
1663
epoger@google.comc7cf2b32011-12-28 19:31:01 +00001664 return (0 == testsFailed) ? 0 : -1;
reed@android.com00dae862009-06-10 15:38:48 +00001665}
caryclark@google.com5987f582012-10-02 18:33:14 +00001666
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001667void GMMain::installFilter(SkCanvas* canvas) {
1668 if (FLAGS_forceBWtext) {
1669 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref();
1670 }
1671}
1672
borenet@google.com7158e6a2012-11-01 17:43:44 +00001673#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
caryclark@google.com5987f582012-10-02 18:33:14 +00001674int main(int argc, char * const argv[]) {
1675 return tool_main(argc, (char**) argv);
1676}
1677#endif