blob: abec1055ae21a8937e9bf30331b3e2f36c73a3b8 [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"
reed@android.comb9b9a182009-07-08 02:54:47 +000021#include "SkColorPriv.h"
scroggo@google.comd9ba9a02013-03-21 19:43:15 +000022#include "SkCommandLineFlags.h"
reed@google.com8a85d0c2011-06-24 19:12:12 +000023#include "SkData.h"
junov@google.com4370aed2012-01-18 16:21:08 +000024#include "SkDeferredCanvas.h"
bsalomon@google.com971d0c82011-08-19 17:22:05 +000025#include "SkDevice.h"
commit-bot@chromium.org5e009892013-10-14 13:42:12 +000026#include "SkDocument.h"
epoger@google.comde961632012-10-26 18:56:36 +000027#include "SkDrawFilter.h"
commit-bot@chromium.orgc41295d2013-06-18 20:06:36 +000028#include "SkForceLinking.h"
scroggo@google.com5af9b202012-06-04 17:17:36 +000029#include "SkGPipe.h"
reed@android.com8015dd82009-06-21 00:49:18 +000030#include "SkGraphics.h"
31#include "SkImageDecoder.h"
32#include "SkImageEncoder.h"
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +000033#include "SkJSONCPP.h"
epoger@google.come8ebeb12012-10-29 16:42:11 +000034#include "SkOSFile.h"
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +000035#include "SkPDFRasterizer.h"
tomhudson@google.com9875dd12011-04-25 15:49:53 +000036#include "SkPicture.h"
robertphillips@google.com770963f2014-04-18 18:04:41 +000037#include "SkPictureRecorder.h"
robertphillips@google.com977b9c82012-06-05 19:35:09 +000038#include "SkRefCnt.h"
commit-bot@chromium.org5e009892013-10-14 13:42:12 +000039#include "SkScalar.h"
scroggo@google.com72c96722012-06-06 21:07:10 +000040#include "SkStream.h"
epoger@google.comf711f322013-10-18 14:55:47 +000041#include "SkString.h"
reed@google.com11db6fa2014-02-04 15:30:57 +000042#include "SkSurface.h"
bsalomon@google.com2a48c3a2012-08-03 14:54:45 +000043#include "SkTArray.h"
epoger@google.com310478e2013-04-03 18:00:39 +000044#include "SkTDict.h"
scroggo@google.com72c96722012-06-06 21:07:10 +000045#include "SamplePipeControllers.h"
reed@google.com07700442010-12-20 19:46:07 +000046
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000047#ifdef SK_DEBUG
48static const bool kDebugOnly = true;
commit-bot@chromium.org8065ec52014-03-11 15:57:40 +000049#define GR_DUMP_FONT_CACHE 0
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000050#else
51static const bool kDebugOnly = false;
52#endif
53
epoger@google.comed5eb4e2013-07-23 17:56:20 +000054__SK_FORCE_IMAGE_DECODER_LINKING;
55
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000056#if SK_SUPPORT_GPU
57#include "GrContextFactory.h"
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000058#include "SkGpuDevice.h"
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000059typedef GrContextFactory::GLContextType GLContextType;
epoger@google.com6f6568b2013-03-22 17:29:46 +000060#define DEFAULT_CACHE_VALUE -1
61static int gGpuCacheSizeBytes;
62static int gGpuCacheSizeCount;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000063#else
epoger@google.com80724df2013-03-21 13:49:54 +000064class GrContextFactory;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000065class GrContext;
bsalomon@google.com123ac1d2013-03-28 19:18:12 +000066class GrSurface;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000067typedef int GLContextType;
68#endif
69
epoger@google.com76c913d2013-04-26 15:06:44 +000070#define DEBUGFAIL_SEE_STDERR SkDEBUGFAIL("see stderr for message")
71
reed@google.com8923c6c2011-11-08 14:59:38 +000072extern bool gSkSuppressFontCachePurgeSpew;
commit-bot@chromium.org5e009892013-10-14 13:42:12 +000073DECLARE_bool(useDocumentInsteadOfDevice);
reed@google.com8923c6c2011-11-08 14:59:38 +000074
reed@google.com07700442010-12-20 19:46:07 +000075#ifdef SK_SUPPORT_PDF
tomhudson@google.com9875dd12011-04-25 15:49:53 +000076 #include "SkPDFDevice.h"
77 #include "SkPDFDocument.h"
reed@google.com07700442010-12-20 19:46:07 +000078#endif
reed@android.com00dae862009-06-10 15:38:48 +000079
epoger@google.come3cc2eb2012-01-18 20:11:13 +000080// Until we resolve http://code.google.com/p/skia/issues/detail?id=455 ,
81// stop writing out XPS-format image baselines in gm.
82#undef SK_SUPPORT_XPS
bungeman@google.comb29c8832011-10-10 13:19:10 +000083#ifdef SK_SUPPORT_XPS
84 #include "SkXPSDevice.h"
85#endif
86
reed@google.com46cce912011-06-29 12:54:46 +000087#ifdef SK_BUILD_FOR_MAC
88 #include "SkCGUtils.h"
reed@google.com46cce912011-06-29 12:54:46 +000089#endif
90
reed@android.com00dae862009-06-10 15:38:48 +000091using namespace skiagm;
92
reed@android.com00dae862009-06-10 15:38:48 +000093class Iter {
94public:
95 Iter() {
bsalomon@google.com39149582011-06-13 21:55:32 +000096 this->reset();
97 }
98
99 void reset() {
reed@android.comdd0ac282009-06-20 02:38:16 +0000100 fReg = GMRegistry::Head();
reed@android.com00dae862009-06-10 15:38:48 +0000101 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000102
reed@android.comdd0ac282009-06-20 02:38:16 +0000103 GM* next() {
reed@android.com00dae862009-06-10 15:38:48 +0000104 if (fReg) {
reed@android.comdd0ac282009-06-20 02:38:16 +0000105 GMRegistry::Factory fact = fReg->factory();
reed@android.com00dae862009-06-10 15:38:48 +0000106 fReg = fReg->next();
reed@android.comdd0ac282009-06-20 02:38:16 +0000107 return fact(0);
reed@android.com00dae862009-06-10 15:38:48 +0000108 }
109 return NULL;
110 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000111
reed@android.com00dae862009-06-10 15:38:48 +0000112 static int Count() {
reed@android.comdd0ac282009-06-20 02:38:16 +0000113 const GMRegistry* reg = GMRegistry::Head();
reed@android.com00dae862009-06-10 15:38:48 +0000114 int count = 0;
115 while (reg) {
116 count += 1;
117 reg = reg->next();
118 }
119 return count;
120 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000121
reed@android.com00dae862009-06-10 15:38:48 +0000122private:
123 const GMRegistry* fReg;
124};
125
epoger@google.comce057fe2013-05-14 15:17:46 +0000126// TODO(epoger): Right now, various places in this code assume that all the
127// image files read/written by GM use this file extension.
128// Search for references to this constant to find these assumptions.
129const static char kPNG_FileExtension[] = "png";
130
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000131enum Backend {
junov@chromium.org3cb834b2012-12-13 16:39:53 +0000132 kRaster_Backend,
133 kGPU_Backend,
134 kPDF_Backend,
135 kXPS_Backend,
136};
137
138enum BbhType {
139 kNone_BbhType,
140 kRTree_BbhType,
141 kTileGrid_BbhType,
commit-bot@chromium.orgd393b172014-04-16 16:02:10 +0000142 kQuadTree_BbhType
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000143};
144
bsalomon@google.com7361f542012-04-19 19:15:35 +0000145enum ConfigFlags {
146 kNone_ConfigFlag = 0x0,
147 /* Write GM images if a write path is provided. */
148 kWrite_ConfigFlag = 0x1,
epoger@google.comf28dd8a2012-10-25 16:27:34 +0000149 /* Read reference GM images if a read path is provided. */
bsalomon@google.com7361f542012-04-19 19:15:35 +0000150 kRead_ConfigFlag = 0x2,
151 kRW_ConfigFlag = (kWrite_ConfigFlag | kRead_ConfigFlag),
152};
153
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000154struct ConfigData {
bsalomon@google.com7361f542012-04-19 19:15:35 +0000155 SkBitmap::Config fConfig;
156 Backend fBackend;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000157 GLContextType fGLContextType; // GPU backend only
bsalomon@google.com7361f542012-04-19 19:15:35 +0000158 int fSampleCnt; // GPU backend only
159 ConfigFlags fFlags;
160 const char* fName;
bsalomon@google.com4c75f242013-03-19 18:58:43 +0000161 bool fRunByDefault;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000162};
163
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000164struct PDFRasterizerData {
165 bool (*fRasterizerFunction)(SkStream*, SkBitmap*);
166 const char* fName;
167 bool fRunByDefault;
168};
169
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000170class BWTextDrawFilter : public SkDrawFilter {
171public:
reed@google.com971aca72012-11-26 20:26:54 +0000172 virtual bool filter(SkPaint*, Type) SK_OVERRIDE;
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000173};
reed@google.com971aca72012-11-26 20:26:54 +0000174bool BWTextDrawFilter::filter(SkPaint* p, Type t) {
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000175 if (kText_Type == t) {
176 p->setAntiAlias(false);
177 }
reed@google.com971aca72012-11-26 20:26:54 +0000178 return true;
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000179}
180
scroggo@google.com565254b2012-06-28 15:41:32 +0000181struct PipeFlagComboData {
182 const char* name;
183 uint32_t flags;
184};
185
186static PipeFlagComboData gPipeWritingFlagCombos[] = {
187 { "", 0 },
188 { " cross-process", SkGPipeWriter::kCrossProcess_Flag },
scroggob3c0f482012-07-02 19:07:57 +0000189 { " cross-process, shared address", SkGPipeWriter::kCrossProcess_Flag
scroggo@google.com15011ee2012-07-26 20:03:32 +0000190 | SkGPipeWriter::kSharedAddressSpace_Flag }
scroggo@google.com565254b2012-06-28 15:41:32 +0000191};
192
commit-bot@chromium.org608ea652013-10-03 19:29:21 +0000193static SkData* encode_to_dct_data(size_t* pixelRefOffset, const SkBitmap& bitmap);
edisonn@google.com73a7ea32013-11-11 20:55:15 +0000194DECLARE_int32(pdfRasterDpi);
edisonn@google.comd9dfa182013-04-24 13:01:01 +0000195
epoger@google.com5079d2c2013-04-12 14:11:21 +0000196const static ErrorCombination kDefaultIgnorableErrorTypes = ErrorCombination()
197 .plus(kMissingExpectations_ErrorType)
198 .plus(kIntentionallySkipped_ErrorType);
199
epoger@google.comde961632012-10-26 18:56:36 +0000200class GMMain {
201public:
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000202 GMMain() : fUseFileHierarchy(false), fWriteChecksumBasedFilenames(false),
203 fIgnorableErrorTypes(kDefaultIgnorableErrorTypes),
epoger@google.com5f995452013-06-21 18:16:47 +0000204 fMismatchPath(NULL), fMissingExpectationsPath(NULL), fTestsRun(0),
205 fRenderModesEncountered(1) {}
epoger@google.come8ebeb12012-10-29 16:42:11 +0000206
epoger@google.com659c8c02013-05-21 15:45:45 +0000207 /**
208 * Assemble shortNamePlusConfig from (surprise!) shortName and configName.
209 *
210 * The method for doing so depends on whether we are using hierarchical naming.
211 * For example, shortName "selftest1" and configName "8888" could be assembled into
212 * either "selftest1_8888" or "8888/selftest1".
213 */
214 SkString make_shortname_plus_config(const char *shortName, const char *configName) {
epoger@google.come8ebeb12012-10-29 16:42:11 +0000215 SkString name;
epoger@google.com57f7abc2012-11-13 03:41:55 +0000216 if (0 == strlen(configName)) {
217 name.append(shortName);
218 } else if (fUseFileHierarchy) {
epoger@google.come8ebeb12012-10-29 16:42:11 +0000219 name.appendf("%s%c%s", configName, SkPATH_SEPARATOR, shortName);
220 } else {
221 name.appendf("%s_%s", shortName, configName);
222 }
epoger@google.comde961632012-10-26 18:56:36 +0000223 return name;
224 }
225
epoger@google.com659c8c02013-05-21 15:45:45 +0000226 /**
227 * Assemble filename, suitable for writing out the results of a particular test.
228 */
229 SkString make_filename(const char *path,
230 const char *shortName,
231 const char *configName,
232 const char *renderModeDescriptor,
233 const char *suffix) {
234 SkString filename = make_shortname_plus_config(shortName, configName);
235 filename.append(renderModeDescriptor);
236 filename.appendUnichar('.');
237 filename.append(suffix);
scroggo@google.comccd7afb2013-05-28 16:45:07 +0000238 return SkOSPath::SkPathJoin(path, filename.c_str());
epoger@google.com659c8c02013-05-21 15:45:45 +0000239 }
240
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000241 /**
242 * Assemble filename suitable for writing out an SkBitmap.
243 */
244 SkString make_bitmap_filename(const char *path,
245 const char *shortName,
246 const char *configName,
247 const char *renderModeDescriptor,
248 const GmResultDigest &bitmapDigest) {
249 if (fWriteChecksumBasedFilenames) {
250 SkString filename;
251 filename.append(bitmapDigest.getHashType());
252 filename.appendUnichar('_');
253 filename.append(shortName);
254 filename.appendUnichar('_');
255 filename.append(bitmapDigest.getDigestValue());
256 filename.appendUnichar('.');
257 filename.append(kPNG_FileExtension);
258 return SkOSPath::SkPathJoin(path, filename.c_str());
259 } else {
260 return make_filename(path, shortName, configName, renderModeDescriptor,
261 kPNG_FileExtension);
262 }
263 }
264
epoger@google.com5f6a0072013-01-31 16:30:55 +0000265 /* since PNG insists on unpremultiplying our alpha, we take no
266 precision chances and force all pixels to be 100% opaque,
267 otherwise on compare we may not get a perfect match.
268 */
269 static void force_all_opaque(const SkBitmap& bitmap) {
commit-bot@chromium.orgdac52252014-02-17 21:21:46 +0000270 SkColorType colorType = bitmap.colorType();
271 switch (colorType) {
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000272 case kN32_SkColorType:
epoger@google.com5f6a0072013-01-31 16:30:55 +0000273 force_all_opaque_8888(bitmap);
274 break;
commit-bot@chromium.orgdac52252014-02-17 21:21:46 +0000275 case kRGB_565_SkColorType:
epoger@google.com5f6a0072013-01-31 16:30:55 +0000276 // nothing to do here; 565 bitmaps are inherently opaque
277 break;
278 default:
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000279 SkDebugf("unsupported bitmap colorType %d\n", colorType);
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000280 DEBUGFAIL_SEE_STDERR;
epoger@google.com5f6a0072013-01-31 16:30:55 +0000281 }
282 }
283
284 static void force_all_opaque_8888(const SkBitmap& bitmap) {
285 SkAutoLockPixels lock(bitmap);
286 for (int y = 0; y < bitmap.height(); y++) {
287 for (int x = 0; x < bitmap.width(); x++) {
288 *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT);
289 }
290 }
291 }
292
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000293 static ErrorCombination write_bitmap(const SkString& path, const SkBitmap& bitmap) {
epoger@google.com5f6a0072013-01-31 16:30:55 +0000294 // TODO(epoger): Now that we have removed force_all_opaque()
295 // from this method, we should be able to get rid of the
296 // transformation to 8888 format also.
297 SkBitmap copy;
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000298 bitmap.copyTo(&copy, kN32_SkColorType);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000299 if (!SkImageEncoder::EncodeFile(path.c_str(), copy,
300 SkImageEncoder::kPNG_Type,
301 100)) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000302 SkDebugf("FAILED to write bitmap: %s\n", path.c_str());
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000303 return ErrorCombination(kWritingReferenceImage_ErrorType);
304 }
305 return kEmpty_ErrorCombination;
epoger@google.com5f6a0072013-01-31 16:30:55 +0000306 }
307
epoger@google.com6f6568b2013-03-22 17:29:46 +0000308 /**
epoger@google.com310478e2013-04-03 18:00:39 +0000309 * Add all render modes encountered thus far to the "modes" array.
epoger@google.com6f6568b2013-03-22 17:29:46 +0000310 */
epoger@google.com310478e2013-04-03 18:00:39 +0000311 void GetRenderModesEncountered(SkTArray<SkString> &modes) {
312 SkTDict<int>::Iter iter(this->fRenderModesEncountered);
313 const char* mode;
314 while ((mode = iter.next(NULL)) != NULL) {
315 SkString modeAsString = SkString(mode);
316 // TODO(epoger): It seems a bit silly that all of these modes were
317 // recorded with a leading "-" which we have to remove here
318 // (except for mode "", which means plain old original mode).
319 // But that's how renderModeDescriptor has been passed into
320 // compare_test_results_to_reference_bitmap() historically,
321 // and changing that now may affect other parts of our code.
322 if (modeAsString.startsWith("-")) {
323 modeAsString.remove(0, 1);
epoger@google.com310478e2013-04-03 18:00:39 +0000324 }
commit-bot@chromium.org85195482014-01-13 18:27:59 +0000325 modes.push_back(modeAsString);
epoger@google.com310478e2013-04-03 18:00:39 +0000326 }
327 }
328
329 /**
epoger@google.com3a882dd2013-10-07 18:55:09 +0000330 * Returns true if failures on this test should be ignored.
331 */
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +0000332 bool ShouldIgnoreTest(const char *name) const {
333 for (int i = 0; i < fIgnorableTestNames.count(); i++) {
334 if (fIgnorableTestNames[i].equals(name)) {
epoger@google.com3a882dd2013-10-07 18:55:09 +0000335 return true;
336 }
337 }
338 return false;
339 }
340
341 /**
commit-bot@chromium.org85195482014-01-13 18:27:59 +0000342 * Calls RecordTestResults to record that we skipped a test.
343 *
344 * Depending on the backend, this may mean that we skipped a single rendermode, or all
345 * rendermodes; see http://skbug.com/1994 and https://codereview.chromium.org/129203002/
346 */
347 void RecordSkippedTest(const SkString& shortNamePlusConfig,
348 const char renderModeDescriptor [], Backend backend) {
349 if (kRaster_Backend == backend) {
350 // Skipping a test on kRaster_Backend means that we will skip ALL renderModes
351 // (as opposed to other backends, on which we only run the default renderMode).
352 //
353 // We cannot call RecordTestResults yet, because we won't know the full set of
354 // renderModes until we have run all tests.
355 fTestsSkippedOnAllRenderModes.push_back(shortNamePlusConfig);
356 } else {
357 this->RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
358 renderModeDescriptor);
359 }
360 }
361
362 /**
epoger@google.com310478e2013-04-03 18:00:39 +0000363 * Records the results of this test in fTestsRun and fFailedTests.
364 *
365 * We even record successes, and errors that we regard as
366 * "ignorable"; we can filter them out later.
367 */
epoger@google.com659c8c02013-05-21 15:45:45 +0000368 void RecordTestResults(const ErrorCombination& errorCombination,
369 const SkString& shortNamePlusConfig,
epoger@google.com310478e2013-04-03 18:00:39 +0000370 const char renderModeDescriptor []) {
371 // Things to do regardless of errorCombination.
372 fTestsRun++;
373 int renderModeCount = 0;
374 this->fRenderModesEncountered.find(renderModeDescriptor, &renderModeCount);
375 renderModeCount++;
376 this->fRenderModesEncountered.set(renderModeDescriptor, renderModeCount);
377
epoger@google.com6f6568b2013-03-22 17:29:46 +0000378 if (errorCombination.isEmpty()) {
epoger@google.com5f6a0072013-01-31 16:30:55 +0000379 return;
epoger@google.comeb066362013-03-08 09:39:36 +0000380 }
381
epoger@google.com310478e2013-04-03 18:00:39 +0000382 // Things to do only if there is some error condition.
epoger@google.com659c8c02013-05-21 15:45:45 +0000383 SkString fullName = shortNamePlusConfig;
epoger@google.comcaac3db2013-04-04 19:23:11 +0000384 fullName.append(renderModeDescriptor);
epoger@google.com310478e2013-04-03 18:00:39 +0000385 for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) {
386 ErrorType type = static_cast<ErrorType>(typeInt);
387 if (errorCombination.includes(type)) {
388 fFailedTests[type].push_back(fullName);
epoger@google.comf60494b2013-04-03 17:02:53 +0000389 }
epoger@google.comf60494b2013-04-03 17:02:53 +0000390 }
epoger@google.comf60494b2013-04-03 17:02:53 +0000391 }
392
epoger@google.com310478e2013-04-03 18:00:39 +0000393 /**
394 * Return the number of significant (non-ignorable) errors we have
395 * encountered so far.
396 */
397 int NumSignificantErrors() {
398 int significantErrors = 0;
399 for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) {
400 ErrorType type = static_cast<ErrorType>(typeInt);
epoger@google.com5079d2c2013-04-12 14:11:21 +0000401 if (!fIgnorableErrorTypes.includes(type)) {
epoger@google.com310478e2013-04-03 18:00:39 +0000402 significantErrors += fFailedTests[type].count();
403 }
404 }
405 return significantErrors;
406 }
407
408 /**
epoger@google.com51dbabe2013-04-10 15:24:53 +0000409 * Display the summary of results with this ErrorType.
410 *
411 * @param type which ErrorType
412 * @param verbose whether to be all verbose about it
epoger@google.com310478e2013-04-03 18:00:39 +0000413 */
epoger@google.com51dbabe2013-04-10 15:24:53 +0000414 void DisplayResultTypeSummary(ErrorType type, bool verbose) {
epoger@google.com5079d2c2013-04-12 14:11:21 +0000415 bool isIgnorableType = fIgnorableErrorTypes.includes(type);
epoger@google.com51dbabe2013-04-10 15:24:53 +0000416
417 SkString line;
418 if (isIgnorableType) {
419 line.append("[ ] ");
420 } else {
421 line.append("[*] ");
422 }
423
424 SkTArray<SkString> *failedTestsOfThisType = &fFailedTests[type];
425 int count = failedTestsOfThisType->count();
426 line.appendf("%d %s", count, getErrorTypeName(type));
427 if (!isIgnorableType || verbose) {
428 line.append(":");
429 for (int i = 0; i < count; ++i) {
430 line.append(" ");
431 line.append((*failedTestsOfThisType)[i]);
432 }
433 }
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000434 SkDebugf("%s\n", line.c_str());
epoger@google.com51dbabe2013-04-10 15:24:53 +0000435 }
436
437 /**
438 * List contents of fFailedTests to stdout.
439 *
440 * @param verbose whether to be all verbose about it
441 */
442 void ListErrors(bool verbose) {
epoger@google.com310478e2013-04-03 18:00:39 +0000443 // First, print a single summary line.
444 SkString summary;
445 summary.appendf("Ran %d tests:", fTestsRun);
446 for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) {
447 ErrorType type = static_cast<ErrorType>(typeInt);
448 summary.appendf(" %s=%d", getErrorTypeName(type), fFailedTests[type].count());
449 }
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000450 SkDebugf("%s\n", summary.c_str());
epoger@google.com310478e2013-04-03 18:00:39 +0000451
452 // Now, for each failure type, list the tests that failed that way.
453 for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) {
epoger@google.com51dbabe2013-04-10 15:24:53 +0000454 this->DisplayResultTypeSummary(static_cast<ErrorType>(typeInt), verbose);
epoger@google.com310478e2013-04-03 18:00:39 +0000455 }
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000456 SkDebugf("(results marked with [*] will cause nonzero return value)\n");
epoger@google.com310478e2013-04-03 18:00:39 +0000457 }
458
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000459 static ErrorCombination write_document(const SkString& path, SkStreamAsset* asset) {
epoger@google.com5f6a0072013-01-31 16:30:55 +0000460 SkFILEWStream stream(path.c_str());
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000461 if (!stream.writeStream(asset, asset->getLength())) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000462 SkDebugf("FAILED to write document: %s\n", path.c_str());
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000463 return ErrorCombination(kWritingReferenceImage_ErrorType);
464 }
465 return kEmpty_ErrorCombination;
epoger@google.com5f6a0072013-01-31 16:30:55 +0000466 }
467
epoger@google.com37269602013-01-19 04:21:27 +0000468 /**
epoger@google.com5f6a0072013-01-31 16:30:55 +0000469 * Prepare an SkBitmap to render a GM into.
470 *
471 * After you've rendered the GM into the SkBitmap, you must call
472 * complete_bitmap()!
473 *
474 * @todo thudson 22 April 2011 - could refactor this to take in
475 * a factory to generate the context, always call readPixels()
476 * (logically a noop for rasters, if wasted time), and thus collapse the
477 * GPU special case and also let this be used for SkPicture testing.
478 */
479 static void setup_bitmap(const ConfigData& gRec, SkISize& size,
480 SkBitmap* bitmap) {
reed@google.comeb9a46c2014-01-25 16:46:20 +0000481 bitmap->allocConfigPixels(gRec.fConfig, size.width(), size.height());
epoger@google.com5f6a0072013-01-31 16:30:55 +0000482 bitmap->eraseColor(SK_ColorTRANSPARENT);
483 }
484
485 /**
486 * Any finalization steps we need to perform on the SkBitmap after
487 * we have rendered the GM into it.
epoger@google.com37269602013-01-19 04:21:27 +0000488 *
489 * It's too bad that we are throwing away alpha channel data
490 * we could otherwise be examining, but this had always been happening
491 * before... it was buried within the compare() method at
492 * https://code.google.com/p/skia/source/browse/trunk/gm/gmmain.cpp?r=7289#305 .
493 *
494 * Apparently we need this, at least for bitmaps that are either:
495 * (a) destined to be written out as PNG files, or
496 * (b) compared against bitmaps read in from PNG files
497 * for the reasons described just above the force_all_opaque() method.
498 *
499 * Neglecting to do this led to the difficult-to-diagnose
500 * http://code.google.com/p/skia/issues/detail?id=1079 ('gm generating
501 * spurious pixel_error messages as of r7258')
502 *
503 * TODO(epoger): Come up with a better solution that allows us to
504 * compare full pixel data, including alpha channel, while still being
505 * robust in the face of transformations to/from PNG files.
506 * Options include:
507 *
508 * 1. Continue to call force_all_opaque(), but ONLY for bitmaps that
509 * will be written to, or compared against, PNG files.
510 * PRO: Preserve/compare alpha channel info for the non-PNG cases
511 * (comparing different renderModes in-memory)
epoger@google.com908f5832013-04-12 02:23:55 +0000512 * CON: The bitmaps (and hash digests) for these non-PNG cases would be
epoger@google.com37269602013-01-19 04:21:27 +0000513 * different than those for the PNG-compared cases, and in the
514 * case of a failed renderMode comparison, how would we write the
515 * image to disk for examination?
516 *
epoger@google.com908f5832013-04-12 02:23:55 +0000517 * 2. Always compute image hash digests from PNG format (either
epoger@google.com37269602013-01-19 04:21:27 +0000518 * directly from the the bytes of a PNG file, or capturing the
519 * bytes we would have written to disk if we were writing the
520 * bitmap out as a PNG).
521 * PRO: I think this would allow us to never force opaque, and to
522 * the extent that alpha channel data can be preserved in a PNG
523 * file, we could observe it.
epoger@google.com908f5832013-04-12 02:23:55 +0000524 * CON: If we read a bitmap from disk, we need to take its hash digest
epoger@google.com37269602013-01-19 04:21:27 +0000525 * from the source PNG (we can't compute it from the bitmap we
526 * read out of the PNG, because we will have already premultiplied
527 * the alpha).
528 * CON: Seems wasteful to convert a bitmap to PNG format just to take
epoger@google.com908f5832013-04-12 02:23:55 +0000529 * its hash digest. (Although we're wasting lots of effort already
epoger@google.com37269602013-01-19 04:21:27 +0000530 * calling force_all_opaque().)
531 *
532 * 3. Make the alpha premultiply/unpremultiply routines 100% consistent,
533 * so we can transform images back and forth without fear of off-by-one
534 * errors.
535 * CON: Math is hard.
536 *
537 * 4. Perform a "close enough" comparison of bitmaps (+/- 1 bit in each
538 * channel), rather than demanding absolute equality.
epoger@google.com908f5832013-04-12 02:23:55 +0000539 * CON: Can't do this with hash digests.
epoger@google.com37269602013-01-19 04:21:27 +0000540 */
epoger@google.com5f6a0072013-01-31 16:30:55 +0000541 static void complete_bitmap(SkBitmap* bitmap) {
542 force_all_opaque(*bitmap);
epoger@google.comde961632012-10-26 18:56:36 +0000543 }
544
scroggo@google.com09fd4d22013-03-20 14:20:18 +0000545 static void installFilter(SkCanvas* canvas);
epoger@google.comde961632012-10-26 18:56:36 +0000546
reed@google.comaef73612012-11-16 13:41:45 +0000547 static void invokeGM(GM* gm, SkCanvas* canvas, bool isPDF, bool isDeferred) {
epoger@google.comde961632012-10-26 18:56:36 +0000548 SkAutoCanvasRestore acr(canvas, true);
549
550 if (!isPDF) {
551 canvas->concat(gm->getInitialTransform());
552 }
553 installFilter(canvas);
reed@google.comaef73612012-11-16 13:41:45 +0000554 gm->setCanvasIsDeferred(isDeferred);
epoger@google.comde961632012-10-26 18:56:36 +0000555 gm->draw(canvas);
556 canvas->setDrawFilter(NULL);
557 }
558
epoger@google.com6f6568b2013-03-22 17:29:46 +0000559 static ErrorCombination generate_image(GM* gm, const ConfigData& gRec,
bsalomon@google.com123ac1d2013-03-28 19:18:12 +0000560 GrSurface* gpuTarget,
epoger@google.com6f6568b2013-03-22 17:29:46 +0000561 SkBitmap* bitmap,
562 bool deferred) {
epoger@google.comde961632012-10-26 18:56:36 +0000563 SkISize size (gm->getISize());
564 setup_bitmap(gRec, size, bitmap);
reed@google.com11db6fa2014-02-04 15:30:57 +0000565 SkImageInfo info;
566 bitmap->asImageInfo(&info);
epoger@google.comde961632012-10-26 18:56:36 +0000567
reed@google.com11db6fa2014-02-04 15:30:57 +0000568 SkAutoTUnref<SkSurface> surface;
epoger@google.comde961632012-10-26 18:56:36 +0000569 SkAutoTUnref<SkCanvas> canvas;
570
571 if (gRec.fBackend == kRaster_Backend) {
reed@google.com11db6fa2014-02-04 15:30:57 +0000572 surface.reset(SkSurface::NewRasterDirect(info,
573 bitmap->getPixels(),
574 bitmap->rowBytes()));
epoger@google.comde961632012-10-26 18:56:36 +0000575 if (deferred) {
reed@google.com11db6fa2014-02-04 15:30:57 +0000576 canvas.reset(SkDeferredCanvas::Create(surface));
epoger@google.comde961632012-10-26 18:56:36 +0000577 } else {
reed@google.com11db6fa2014-02-04 15:30:57 +0000578 canvas.reset(SkRef(surface->getCanvas()));
epoger@google.comde961632012-10-26 18:56:36 +0000579 }
reed@google.comaef73612012-11-16 13:41:45 +0000580 invokeGM(gm, canvas, false, deferred);
epoger@google.comde961632012-10-26 18:56:36 +0000581 canvas->flush();
582 }
583#if SK_SUPPORT_GPU
584 else { // GPU
reed@google.com11db6fa2014-02-04 15:30:57 +0000585 surface.reset(SkSurface::NewRenderTargetDirect(gpuTarget->asRenderTarget()));
epoger@google.comde961632012-10-26 18:56:36 +0000586 if (deferred) {
reed@google.com11db6fa2014-02-04 15:30:57 +0000587 canvas.reset(SkDeferredCanvas::Create(surface));
epoger@google.comde961632012-10-26 18:56:36 +0000588 } else {
reed@google.com11db6fa2014-02-04 15:30:57 +0000589 canvas.reset(SkRef(surface->getCanvas()));
epoger@google.comde961632012-10-26 18:56:36 +0000590 }
reed@google.comaef73612012-11-16 13:41:45 +0000591 invokeGM(gm, canvas, false, deferred);
epoger@google.comde961632012-10-26 18:56:36 +0000592 // the device is as large as the current rendertarget, so
593 // we explicitly only readback the amount we expect (in
594 // size) overwrite our previous allocation
commit-bot@chromium.orgdac52252014-02-17 21:21:46 +0000595 bitmap->setConfig(SkImageInfo::MakeN32Premul(size.fWidth, size.fHeight));
epoger@google.comde961632012-10-26 18:56:36 +0000596 canvas->readPixels(bitmap, 0, 0);
597 }
598#endif
epoger@google.com5f6a0072013-01-31 16:30:55 +0000599 complete_bitmap(bitmap);
epoger@google.com6f6568b2013-03-22 17:29:46 +0000600 return kEmpty_ErrorCombination;
epoger@google.comde961632012-10-26 18:56:36 +0000601 }
602
603 static void generate_image_from_picture(GM* gm, const ConfigData& gRec,
junov@chromium.orgc938c482012-12-19 15:24:38 +0000604 SkPicture* pict, SkBitmap* bitmap,
robertphillips@google.com5a7d0292013-04-02 15:18:41 +0000605 SkScalar scale = SK_Scalar1,
606 bool tile = false) {
epoger@google.comde961632012-10-26 18:56:36 +0000607 SkISize size = gm->getISize();
608 setup_bitmap(gRec, size, bitmap);
robertphillips@google.com5a7d0292013-04-02 15:18:41 +0000609
610 if (tile) {
611 // Generate the result image by rendering to tiles and accumulating
612 // the results in 'bitmap'
613
skia.committer@gmail.com041e2db2013-04-03 07:01:14 +0000614 // This 16x16 tiling matches the settings applied to 'pict' in
robertphillips@google.com5a7d0292013-04-02 15:18:41 +0000615 // 'generate_new_picture'
616 SkISize tileSize = SkISize::Make(16, 16);
617
618 SkBitmap tileBM;
619 setup_bitmap(gRec, tileSize, &tileBM);
620 SkCanvas tileCanvas(tileBM);
621 installFilter(&tileCanvas);
622
623 SkCanvas bmpCanvas(*bitmap);
624 SkPaint bmpPaint;
625 bmpPaint.setXfermodeMode(SkXfermode::kSrc_Mode);
626
627 for (int yTile = 0; yTile < (size.height()+15)/16; ++yTile) {
628 for (int xTile = 0; xTile < (size.width()+15)/16; ++xTile) {
629 int saveCount = tileCanvas.save();
630 SkMatrix mat(tileCanvas.getTotalMatrix());
skia.committer@gmail.com041e2db2013-04-03 07:01:14 +0000631 mat.postTranslate(SkIntToScalar(-xTile*tileSize.width()),
robertphillips@google.com5a7d0292013-04-02 15:18:41 +0000632 SkIntToScalar(-yTile*tileSize.height()));
633 tileCanvas.setMatrix(mat);
634 pict->draw(&tileCanvas);
635 tileCanvas.flush();
636 tileCanvas.restoreToCount(saveCount);
skia.committer@gmail.com041e2db2013-04-03 07:01:14 +0000637 bmpCanvas.drawBitmap(tileBM,
638 SkIntToScalar(xTile * tileSize.width()),
robertphillips@google.com5a7d0292013-04-02 15:18:41 +0000639 SkIntToScalar(yTile * tileSize.height()),
640 &bmpPaint);
641 }
642 }
643 } else {
644 SkCanvas canvas(*bitmap);
645 installFilter(&canvas);
646 canvas.scale(scale, scale);
647 canvas.drawPicture(*pict);
648 complete_bitmap(bitmap);
649 }
epoger@google.comde961632012-10-26 18:56:36 +0000650 }
651
commit-bot@chromium.org5e009892013-10-14 13:42:12 +0000652 static bool generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) {
epoger@google.comde961632012-10-26 18:56:36 +0000653#ifdef SK_SUPPORT_PDF
654 SkMatrix initialTransform = gm->getInitialTransform();
commit-bot@chromium.org5e009892013-10-14 13:42:12 +0000655 if (FLAGS_useDocumentInsteadOfDevice) {
656 SkISize pageISize = gm->getISize();
edisonn@google.com73a7ea32013-11-11 20:55:15 +0000657 SkAutoTUnref<SkDocument> pdfDoc(
658 SkDocument::CreatePDF(&pdf, NULL,
659 encode_to_dct_data,
660 SkIntToScalar(FLAGS_pdfRasterDpi)));
commit-bot@chromium.org5e009892013-10-14 13:42:12 +0000661
662 if (!pdfDoc.get()) {
663 return false;
664 }
665
666 SkCanvas* canvas = NULL;
667 canvas = pdfDoc->beginPage(SkIntToScalar(pageISize.width()),
668 SkIntToScalar(pageISize.height()));
669 canvas->concat(initialTransform);
670
671 invokeGM(gm, canvas, true, false);
672
673 return pdfDoc->close();
epoger@google.comde961632012-10-26 18:56:36 +0000674 } else {
commit-bot@chromium.org5e009892013-10-14 13:42:12 +0000675 SkISize pageSize = gm->getISize();
676 SkPDFDevice* dev = NULL;
677 if (initialTransform.isIdentity()) {
678 dev = new SkPDFDevice(pageSize, pageSize, initialTransform);
679 } else {
680 SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()),
681 SkIntToScalar(pageSize.height()));
682 initialTransform.mapRect(&content);
683 content.intersect(0, 0, SkIntToScalar(pageSize.width()),
684 SkIntToScalar(pageSize.height()));
685 SkISize contentSize =
686 SkISize::Make(SkScalarRoundToInt(content.width()),
687 SkScalarRoundToInt(content.height()));
688 dev = new SkPDFDevice(pageSize, contentSize, initialTransform);
689 }
690 dev->setDCTEncoder(encode_to_dct_data);
edisonn@google.com73a7ea32013-11-11 20:55:15 +0000691 dev->setRasterDpi(SkIntToScalar(FLAGS_pdfRasterDpi));
commit-bot@chromium.org5e009892013-10-14 13:42:12 +0000692 SkAutoUnref aur(dev);
693 SkCanvas c(dev);
694 invokeGM(gm, &c, true, false);
695 SkPDFDocument doc;
696 doc.appendPage(dev);
697 doc.emitPDF(&pdf);
epoger@google.comde961632012-10-26 18:56:36 +0000698 }
commit-bot@chromium.org5e009892013-10-14 13:42:12 +0000699#endif // SK_SUPPORT_PDF
700 return true; // Do not report failure if pdf is not supported.
epoger@google.comde961632012-10-26 18:56:36 +0000701 }
702
703 static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) {
704#ifdef SK_SUPPORT_XPS
705 SkISize size = gm->getISize();
706
707 SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()),
708 SkIntToScalar(size.height()));
709 static const SkScalar inchesPerMeter = SkScalarDiv(10000, 254);
710 static const SkScalar upm = 72 * inchesPerMeter;
711 SkVector unitsPerMeter = SkPoint::Make(upm, upm);
712 static const SkScalar ppm = 200 * inchesPerMeter;
713 SkVector pixelsPerMeter = SkPoint::Make(ppm, ppm);
714
715 SkXPSDevice* dev = new SkXPSDevice();
716 SkAutoUnref aur(dev);
717
718 SkCanvas c(dev);
719 dev->beginPortfolio(&xps);
720 dev->beginSheet(unitsPerMeter, pixelsPerMeter, trimSize);
reed@google.comaef73612012-11-16 13:41:45 +0000721 invokeGM(gm, &c, false, false);
epoger@google.comde961632012-10-26 18:56:36 +0000722 dev->endSheet();
723 dev->endPortfolio();
724
725#endif
726 }
727
epoger@google.com37269602013-01-19 04:21:27 +0000728 /**
epoger@google.com84a18022013-02-01 20:39:15 +0000729 * Log more detail about the mistmatch between expectedBitmap and
730 * actualBitmap.
731 */
732 void report_bitmap_diffs(const SkBitmap& expectedBitmap, const SkBitmap& actualBitmap,
733 const char *testName) {
734 const int expectedWidth = expectedBitmap.width();
735 const int expectedHeight = expectedBitmap.height();
736 const int width = actualBitmap.width();
737 const int height = actualBitmap.height();
738 if ((expectedWidth != width) || (expectedHeight != height)) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000739 SkDebugf("---- %s: dimension mismatch -- expected [%d %d], actual [%d %d]\n",
740 testName, expectedWidth, expectedHeight, width, height);
epoger@google.com84a18022013-02-01 20:39:15 +0000741 return;
742 }
743
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000744 if ((kN32_SkColorType != expectedBitmap.colorType()) ||
745 (kN32_SkColorType != actualBitmap.colorType())) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000746 SkDebugf("---- %s: not computing max per-channel pixel mismatch because non-8888\n",
747 testName);
epoger@google.com84a18022013-02-01 20:39:15 +0000748 return;
749 }
750
751 SkAutoLockPixels alp0(expectedBitmap);
752 SkAutoLockPixels alp1(actualBitmap);
753 int errR = 0;
754 int errG = 0;
755 int errB = 0;
756 int errA = 0;
757 int differingPixels = 0;
758
759 for (int y = 0; y < height; ++y) {
760 const SkPMColor* expectedPixelPtr = expectedBitmap.getAddr32(0, y);
761 const SkPMColor* actualPixelPtr = actualBitmap.getAddr32(0, y);
762 for (int x = 0; x < width; ++x) {
763 SkPMColor expectedPixel = *expectedPixelPtr++;
764 SkPMColor actualPixel = *actualPixelPtr++;
765 if (expectedPixel != actualPixel) {
766 differingPixels++;
767 errR = SkMax32(errR, SkAbs32((int)SkGetPackedR32(expectedPixel) -
768 (int)SkGetPackedR32(actualPixel)));
769 errG = SkMax32(errG, SkAbs32((int)SkGetPackedG32(expectedPixel) -
770 (int)SkGetPackedG32(actualPixel)));
771 errB = SkMax32(errB, SkAbs32((int)SkGetPackedB32(expectedPixel) -
772 (int)SkGetPackedB32(actualPixel)));
773 errA = SkMax32(errA, SkAbs32((int)SkGetPackedA32(expectedPixel) -
774 (int)SkGetPackedA32(actualPixel)));
775 }
776 }
777 }
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000778 SkDebugf("---- %s: %d (of %d) differing pixels, "
779 "max per-channel mismatch R=%d G=%d B=%d A=%d\n",
780 testName, differingPixels, width*height, errR, errG, errB, errA);
epoger@google.com84a18022013-02-01 20:39:15 +0000781 }
782
783 /**
epoger@google.com908f5832013-04-12 02:23:55 +0000784 * Compares actual hash digest to expectations, returning the set of errors
epoger@google.com6f6568b2013-03-22 17:29:46 +0000785 * (if any) that we saw along the way.
epoger@google.com37269602013-01-19 04:21:27 +0000786 *
787 * If fMismatchPath has been set, and there are pixel diffs, then the
788 * actual bitmap will be written out to a file within fMismatchPath.
epoger@google.com5f995452013-06-21 18:16:47 +0000789 * And similarly for fMissingExpectationsPath...
epoger@google.com37269602013-01-19 04:21:27 +0000790 *
791 * @param expectations what expectations to compare actualBitmap against
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000792 * @param actualBitmapAndDigest the SkBitmap we actually generated, and its GmResultDigest
epoger@google.com659c8c02013-05-21 15:45:45 +0000793 * @param shortName name of test, e.g. "selftest1"
794 * @param configName name of config, e.g. "8888"
epoger@google.com37269602013-01-19 04:21:27 +0000795 * @param renderModeDescriptor e.g., "-rtree", "-deferred"
796 * @param addToJsonSummary whether to add these results (both actual and
epoger@google.comcaac3db2013-04-04 19:23:11 +0000797 * expected) to the JSON summary. Regardless of this setting, if
798 * we find an image mismatch in this test, we will write these
799 * results to the JSON summary. (This is so that we will always
800 * report errors across rendering modes, such as pipe vs tiled.
801 * See https://codereview.chromium.org/13650002/ )
epoger@google.com37269602013-01-19 04:21:27 +0000802 */
epoger@google.com6f6568b2013-03-22 17:29:46 +0000803 ErrorCombination compare_to_expectations(Expectations expectations,
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000804 const BitmapAndDigest& actualBitmapAndDigest,
epoger@google.com659c8c02013-05-21 15:45:45 +0000805 const char *shortName, const char *configName,
806 const char *renderModeDescriptor,
epoger@google.comcaac3db2013-04-04 19:23:11 +0000807 bool addToJsonSummary) {
epoger@google.com6f6568b2013-03-22 17:29:46 +0000808 ErrorCombination errors;
epoger@google.com659c8c02013-05-21 15:45:45 +0000809 SkString shortNamePlusConfig = make_shortname_plus_config(shortName, configName);
810 SkString completeNameString(shortNamePlusConfig);
epoger@google.com37269602013-01-19 04:21:27 +0000811 completeNameString.append(renderModeDescriptor);
epoger@google.comce057fe2013-05-14 15:17:46 +0000812 completeNameString.append(".");
813 completeNameString.append(kPNG_FileExtension);
epoger@google.com37269602013-01-19 04:21:27 +0000814 const char* completeName = completeNameString.c_str();
epoger@google.comee8a8e32012-12-18 19:13:49 +0000815
epoger@google.com37269602013-01-19 04:21:27 +0000816 if (expectations.empty()) {
epoger@google.com6f6568b2013-03-22 17:29:46 +0000817 errors.add(kMissingExpectations_ErrorType);
epoger@google.com5f995452013-06-21 18:16:47 +0000818
819 // Write out the "actuals" for any tests without expectations, if we have
820 // been directed to do so.
821 if (fMissingExpectationsPath) {
822 SkString path = make_bitmap_filename(fMissingExpectationsPath, shortName,
823 configName, renderModeDescriptor,
824 actualBitmapAndDigest.fDigest);
825 write_bitmap(path, actualBitmapAndDigest.fBitmap);
826 }
827
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000828 } else if (!expectations.match(actualBitmapAndDigest.fDigest)) {
epoger@google.comcaac3db2013-04-04 19:23:11 +0000829 addToJsonSummary = true;
830 // The error mode we record depends on whether this was running
831 // in a non-standard renderMode.
832 if ('\0' == *renderModeDescriptor) {
833 errors.add(kExpectationsMismatch_ErrorType);
834 } else {
835 errors.add(kRenderModeMismatch_ErrorType);
836 }
epoger@google.com84a18022013-02-01 20:39:15 +0000837
838 // Write out the "actuals" for any mismatches, if we have
839 // been directed to do so.
epoger@google.com37269602013-01-19 04:21:27 +0000840 if (fMismatchPath) {
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000841 SkString path = make_bitmap_filename(fMismatchPath, shortName, configName,
842 renderModeDescriptor,
843 actualBitmapAndDigest.fDigest);
844 write_bitmap(path, actualBitmapAndDigest.fBitmap);
epoger@google.com37269602013-01-19 04:21:27 +0000845 }
epoger@google.com84a18022013-02-01 20:39:15 +0000846
847 // If we have access to a single expected bitmap, log more
848 // detail about the mismatch.
849 const SkBitmap *expectedBitmapPtr = expectations.asBitmap();
850 if (NULL != expectedBitmapPtr) {
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000851 report_bitmap_diffs(*expectedBitmapPtr, actualBitmapAndDigest.fBitmap,
852 completeName);
epoger@google.com84a18022013-02-01 20:39:15 +0000853 }
epoger@google.coma243b222013-01-17 17:54:28 +0000854 }
epoger@google.coma243b222013-01-17 17:54:28 +0000855
epoger@google.com37269602013-01-19 04:21:27 +0000856 if (addToJsonSummary) {
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000857 add_actual_results_to_json_summary(completeName, actualBitmapAndDigest.fDigest, errors,
epoger@google.com37269602013-01-19 04:21:27 +0000858 expectations.ignoreFailure());
859 add_expected_results_to_json_summary(completeName, expectations);
860 }
epoger@google.coma243b222013-01-17 17:54:28 +0000861
epoger@google.com6f6568b2013-03-22 17:29:46 +0000862 return errors;
epoger@google.com06b8a192013-01-15 19:10:16 +0000863 }
864
epoger@google.com37269602013-01-19 04:21:27 +0000865 /**
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000866 * Add this result to the appropriate JSON collection of actual results (but just ONE),
epoger@google.com76c913d2013-04-26 15:06:44 +0000867 * depending on errors encountered.
epoger@google.com37269602013-01-19 04:21:27 +0000868 */
869 void add_actual_results_to_json_summary(const char testName[],
epoger@google.comd4993ff2013-05-24 14:33:28 +0000870 const GmResultDigest &actualResultDigest,
epoger@google.com76c913d2013-04-26 15:06:44 +0000871 ErrorCombination errors,
epoger@google.com37269602013-01-19 04:21:27 +0000872 bool ignoreFailure) {
epoger@google.comd4993ff2013-05-24 14:33:28 +0000873 Json::Value jsonActualResults = actualResultDigest.asJsonTypeValuePair();
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000874 Json::Value *resultCollection = NULL;
875
epoger@google.com76c913d2013-04-26 15:06:44 +0000876 if (errors.isEmpty()) {
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000877 resultCollection = &this->fJsonActualResults_Succeeded;
878 } else if (errors.includes(kRenderModeMismatch_ErrorType)) {
879 resultCollection = &this->fJsonActualResults_Failed;
880 } else if (errors.includes(kExpectationsMismatch_ErrorType)) {
epoger@google.com37269602013-01-19 04:21:27 +0000881 if (ignoreFailure) {
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000882 resultCollection = &this->fJsonActualResults_FailureIgnored;
epoger@google.com37269602013-01-19 04:21:27 +0000883 } else {
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000884 resultCollection = &this->fJsonActualResults_Failed;
epoger@google.com37269602013-01-19 04:21:27 +0000885 }
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000886 } else if (errors.includes(kMissingExpectations_ErrorType)) {
887 // TODO: What about the case where there IS an expected
888 // image hash digest, but that gm test doesn't actually
889 // run? For now, those cases will always be ignored,
890 // because gm only looks at expectations that correspond
891 // to gm tests that were actually run.
892 //
893 // Once we have the ability to express expectations as a
894 // JSON file, we should fix this (and add a test case for
895 // which an expectation is given but the test is never
896 // run).
897 resultCollection = &this->fJsonActualResults_NoComparison;
898 }
899
900 // If none of the above cases match, we don't add it to ANY tally of actual results.
901 if (resultCollection) {
902 (*resultCollection)[testName] = jsonActualResults;
epoger@google.com37269602013-01-19 04:21:27 +0000903 }
904 }
905
906 /**
907 * Add this test to the JSON collection of expected results.
908 */
909 void add_expected_results_to_json_summary(const char testName[],
910 Expectations expectations) {
epoger@google.com76c913d2013-04-26 15:06:44 +0000911 this->fJsonExpectedResults[testName] = expectations.asJsonValue();
epoger@google.com37269602013-01-19 04:21:27 +0000912 }
913
914 /**
915 * Compare actualBitmap to expectations stored in this->fExpectationsSource.
916 *
917 * @param gm which test generated the actualBitmap
918 * @param gRec
vandebo@chromium.org8fc37662013-08-21 18:04:09 +0000919 * @param configName The config name to look for in the expectation file.
epoger@google.come33e1372013-07-08 19:13:33 +0000920 * @param actualBitmapAndDigest ptr to bitmap generated by this run, or NULL
921 * if we don't have a usable bitmap representation
epoger@google.com37269602013-01-19 04:21:27 +0000922 */
epoger@google.com6f6568b2013-03-22 17:29:46 +0000923 ErrorCombination compare_test_results_to_stored_expectations(
vandebo@chromium.org8fc37662013-08-21 18:04:09 +0000924 GM* gm, const ConfigData& gRec, const char* configName,
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000925 const BitmapAndDigest* actualBitmapAndDigest) {
epoger@google.com659c8c02013-05-21 15:45:45 +0000926 ErrorCombination errors;
epoger@google.come33e1372013-07-08 19:13:33 +0000927
928 if (NULL == actualBitmapAndDigest) {
929 // Note that we intentionally skipped validating the results for
930 // this test, because we don't know how to generate an SkBitmap
931 // version of the output.
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000932 errors.add(ErrorCombination(kIntentionallySkipped_ErrorType));
epoger@google.comc824c832013-07-12 15:52:59 +0000933 } else if (!(gRec.fFlags & kWrite_ConfigFlag)) {
934 // We don't record the results for this test or compare them
935 // against any expectations, because the output image isn't
936 // meaningful.
937 // See https://code.google.com/p/skia/issues/detail?id=1410 ('some
938 // GM result images not available for download from Google Storage')
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000939 errors.add(ErrorCombination(kIntentionallySkipped_ErrorType));
epoger@google.come33e1372013-07-08 19:13:33 +0000940 } else {
941 ExpectationsSource *expectationsSource = this->fExpectationsSource.get();
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000942 SkString nameWithExtension = make_shortname_plus_config(gm->getName(), configName);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000943 nameWithExtension.append(".");
944 nameWithExtension.append(kPNG_FileExtension);
945
epoger@google.come33e1372013-07-08 19:13:33 +0000946 if (expectationsSource && (gRec.fFlags & kRead_ConfigFlag)) {
947 /*
948 * Get the expected results for this test, as one or more allowed
949 * hash digests. The current implementation of expectationsSource
950 * get this by computing the hash digest of a single PNG file on disk.
951 *
952 * TODO(epoger): This relies on the fact that
953 * force_all_opaque() was called on the bitmap before it
954 * was written to disk as a PNG in the first place. If
955 * not, the hash digest returned here may not match the
956 * hash digest of actualBitmap, which *has* been run through
957 * force_all_opaque().
958 * See comments above complete_bitmap() for more detail.
959 */
960 Expectations expectations = expectationsSource->get(nameWithExtension.c_str());
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000961 if (this->ShouldIgnoreTest(gm->getName())) {
epoger@google.comdefc4872013-09-19 06:18:27 +0000962 expectations.setIgnoreFailure(true);
963 }
epoger@google.come33e1372013-07-08 19:13:33 +0000964 errors.add(compare_to_expectations(expectations, *actualBitmapAndDigest,
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000965 gm->getName(), configName, "", true));
epoger@google.come33e1372013-07-08 19:13:33 +0000966 } else {
967 // If we are running without expectations, we still want to
968 // record the actual results.
969 add_actual_results_to_json_summary(nameWithExtension.c_str(),
970 actualBitmapAndDigest->fDigest,
971 ErrorCombination(kMissingExpectations_ErrorType),
972 false);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000973 errors.add(ErrorCombination(kMissingExpectations_ErrorType));
epoger@google.come33e1372013-07-08 19:13:33 +0000974 }
epoger@google.com9ef89ce2013-01-18 21:45:42 +0000975 }
epoger@google.com6f6568b2013-03-22 17:29:46 +0000976 return errors;
epoger@google.coma243b222013-01-17 17:54:28 +0000977 }
978
epoger@google.com37269602013-01-19 04:21:27 +0000979 /**
980 * Compare actualBitmap to referenceBitmap.
981 *
epoger@google.com659c8c02013-05-21 15:45:45 +0000982 * @param shortName test name, e.g. "selftest1"
983 * @param configName configuration name, e.g. "8888"
epoger@google.com37269602013-01-19 04:21:27 +0000984 * @param renderModeDescriptor
985 * @param actualBitmap actual bitmap generated by this run
986 * @param referenceBitmap bitmap we expected to be generated
987 */
epoger@google.com6f6568b2013-03-22 17:29:46 +0000988 ErrorCombination compare_test_results_to_reference_bitmap(
epoger@google.com659c8c02013-05-21 15:45:45 +0000989 const char *shortName, const char *configName, const char *renderModeDescriptor,
epoger@google.com37269602013-01-19 04:21:27 +0000990 SkBitmap& actualBitmap, const SkBitmap* referenceBitmap) {
991
992 SkASSERT(referenceBitmap);
epoger@google.com84a18022013-02-01 20:39:15 +0000993 Expectations expectations(*referenceBitmap);
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000994 BitmapAndDigest actualBitmapAndDigest(actualBitmap);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000995
996 // TODO: Eliminate RecordTestResults from here.
997 // Results recording code for the test_drawing path has been refactored so that
998 // RecordTestResults is only called once, at the topmost level. However, the
999 // other paths have not yet been refactored, and RecordTestResults has been added
1000 // here to maintain proper behavior for calls not coming from the test_drawing path.
1001 ErrorCombination errors;
1002 errors.add(compare_to_expectations(expectations, actualBitmapAndDigest, shortName,
1003 configName, renderModeDescriptor, false));
1004 SkString shortNamePlusConfig = make_shortname_plus_config(shortName, configName);
1005 RecordTestResults(errors, shortNamePlusConfig, renderModeDescriptor);
1006
1007 return errors;
epoger@google.com37269602013-01-19 04:21:27 +00001008 }
1009
junov@chromium.org20bd04e2013-01-16 18:43:36 +00001010 static SkPicture* generate_new_picture(GM* gm, BbhType bbhType, uint32_t recordFlags,
1011 SkScalar scale = SK_Scalar1) {
junov@chromium.org706ff2f2012-12-19 15:55:40 +00001012 int width = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().width()), scale));
1013 int height = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().height()), scale));
skia.committer@gmail.comd8b27992012-12-20 02:01:41 +00001014
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +00001015 SkAutoTDelete<SkBBHFactory> factory;
junov@chromium.org3cb834b2012-12-13 16:39:53 +00001016 if (kTileGrid_BbhType == bbhType) {
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +00001017 SkTileGridFactory::TileGridInfo info;
junov@chromium.org29b19e52013-02-27 18:35:16 +00001018 info.fMargin.setEmpty();
1019 info.fOffset.setZero();
1020 info.fTileInterval.set(16, 16);
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +00001021 factory.reset(SkNEW_ARGS(SkTileGridFactory, (info)));
commit-bot@chromium.orgd393b172014-04-16 16:02:10 +00001022 } else if (kQuadTree_BbhType == bbhType) {
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +00001023 factory.reset(SkNEW(SkQuadTreeFactory));
commit-bot@chromium.orgd393b172014-04-16 16:02:10 +00001024 } else if (kRTree_BbhType == bbhType) {
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +00001025 factory.reset(SkNEW(SkRTreeFactory));
junov@chromium.org20bd04e2013-01-16 18:43:36 +00001026 }
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +00001027 SkPictureRecorder recorder;
1028 SkCanvas* cv = recorder.beginRecording(width, height, factory.get(), recordFlags);
junov@chromium.orgc938c482012-12-19 15:24:38 +00001029 cv->scale(scale, scale);
reed@google.comaef73612012-11-16 13:41:45 +00001030 invokeGM(gm, cv, false, false);
robertphillips@google.com84b18c72014-04-13 19:09:42 +00001031 return recorder.endRecording();
epoger@google.comde961632012-10-26 18:56:36 +00001032 }
1033
1034 static SkPicture* stream_to_new_picture(const SkPicture& src) {
epoger@google.comde961632012-10-26 18:56:36 +00001035 SkDynamicMemoryWStream storage;
reed@google.com672588b2014-01-08 15:42:01 +00001036 src.serialize(&storage, NULL);
bungeman@google.comc29f3d82013-07-19 22:32:11 +00001037 SkAutoTUnref<SkStreamAsset> pictReadback(storage.detachAsStream());
commit-bot@chromium.org805df1a2013-08-16 19:18:12 +00001038 SkPicture* retval = SkPicture::CreateFromStream(pictReadback,
1039 &SkImageDecoder::DecodeMemory);
epoger@google.comde961632012-10-26 18:56:36 +00001040 return retval;
1041 }
1042
1043 // Test: draw into a bitmap or pdf.
epoger@google.com15655b22013-01-08 18:47:31 +00001044 // Depending on flags, possibly compare to an expected image.
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001045 // If writePath is not NULL, also write images (or documents) to the specified path.
1046 ErrorCombination test_drawing(GM* gm, const ConfigData& gRec,
1047 const SkTDArray<const PDFRasterizerData*> &pdfRasterizers,
epoger@google.com6f6568b2013-03-22 17:29:46 +00001048 const char writePath [],
bsalomon@google.com123ac1d2013-03-28 19:18:12 +00001049 GrSurface* gpuTarget,
epoger@google.com6f6568b2013-03-22 17:29:46 +00001050 SkBitmap* bitmap) {
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001051 ErrorCombination errors;
epoger@google.comde961632012-10-26 18:56:36 +00001052 SkDynamicMemoryWStream document;
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001053 SkString path;
epoger@google.comde961632012-10-26 18:56:36 +00001054
1055 if (gRec.fBackend == kRaster_Backend ||
1056 gRec.fBackend == kGPU_Backend) {
1057 // Early exit if we can't generate the image.
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001058 errors.add(generate_image(gm, gRec, gpuTarget, bitmap, false));
epoger@google.com6f6568b2013-03-22 17:29:46 +00001059 if (!errors.isEmpty()) {
epoger@google.com37269602013-01-19 04:21:27 +00001060 // TODO: Add a test to exercise what the stdout and
1061 // JSON look like if we get an "early error" while
1062 // trying to generate the image.
epoger@google.comde961632012-10-26 18:56:36 +00001063 return errors;
1064 }
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001065 BitmapAndDigest bitmapAndDigest(*bitmap);
1066 errors.add(compare_test_results_to_stored_expectations(
vandebo@chromium.org8fc37662013-08-21 18:04:09 +00001067 gm, gRec, gRec.fName, &bitmapAndDigest));
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001068
1069 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001070 path = make_bitmap_filename(writePath, gm->getName(), gRec.fName,
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001071 "", bitmapAndDigest.fDigest);
1072 errors.add(write_bitmap(path, bitmapAndDigest.fBitmap));
1073 }
epoger@google.comde961632012-10-26 18:56:36 +00001074 } else if (gRec.fBackend == kPDF_Backend) {
commit-bot@chromium.org5e009892013-10-14 13:42:12 +00001075 if (!generate_pdf(gm, document)) {
1076 errors.add(kGeneratePdfFailed_ErrorType);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001077 } else {
commit-bot@chromium.org5e009892013-10-14 13:42:12 +00001078 SkAutoTUnref<SkStreamAsset> documentStream(document.detachAsStream());
1079 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001080 path = make_filename(writePath, gm->getName(), gRec.fName, "", "pdf");
commit-bot@chromium.org5e009892013-10-14 13:42:12 +00001081 errors.add(write_document(path, documentStream));
1082 }
1083
1084 if (!(gm->getFlags() & GM::kSkipPDFRasterization_Flag)) {
1085 for (int i = 0; i < pdfRasterizers.count(); i++) {
1086 SkBitmap pdfBitmap;
vandebo@chromium.org969967e2013-12-09 23:22:15 +00001087 documentStream->rewind();
commit-bot@chromium.org5e009892013-10-14 13:42:12 +00001088 bool success = (*pdfRasterizers[i]->fRasterizerFunction)(
1089 documentStream.get(), &pdfBitmap);
1090 if (!success) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00001091 SkDebugf("FAILED to render PDF for %s using renderer %s\n",
1092 gm->getName(),
1093 pdfRasterizers[i]->fName);
commit-bot@chromium.org5e009892013-10-14 13:42:12 +00001094 continue;
1095 }
1096
1097 SkString configName(gRec.fName);
1098 configName.append("-");
1099 configName.append(pdfRasterizers[i]->fName);
1100
1101 BitmapAndDigest bitmapAndDigest(pdfBitmap);
1102 errors.add(compare_test_results_to_stored_expectations(
1103 gm, gRec, configName.c_str(), &bitmapAndDigest));
1104
1105 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001106 path = make_bitmap_filename(writePath, gm->getName(),
commit-bot@chromium.org5e009892013-10-14 13:42:12 +00001107 configName.c_str(),
1108 "", bitmapAndDigest.fDigest);
1109 errors.add(write_bitmap(path, bitmapAndDigest.fBitmap));
1110 }
1111 }
1112 } else {
1113 errors.add(kIntentionallySkipped_ErrorType);
1114 }
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001115 }
epoger@google.comde961632012-10-26 18:56:36 +00001116 } else if (gRec.fBackend == kXPS_Backend) {
1117 generate_xps(gm, document);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001118 SkAutoTUnref<SkStreamAsset> documentStream(document.detachAsStream());
epoger@google.come33e1372013-07-08 19:13:33 +00001119
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001120 errors.add(compare_test_results_to_stored_expectations(
vandebo@chromium.org8fc37662013-08-21 18:04:09 +00001121 gm, gRec, gRec.fName, NULL));
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001122
1123 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001124 path = make_filename(writePath, gm->getName(), gRec.fName, "", "xps");
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001125 errors.add(write_document(path, documentStream));
1126 }
epoger@google.come33e1372013-07-08 19:13:33 +00001127 } else {
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001128 SkASSERT(false);
epoger@google.come33e1372013-07-08 19:13:33 +00001129 }
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001130 return errors;
epoger@google.comde961632012-10-26 18:56:36 +00001131 }
1132
epoger@google.com6f6568b2013-03-22 17:29:46 +00001133 ErrorCombination test_deferred_drawing(GM* gm,
1134 const ConfigData& gRec,
1135 const SkBitmap& referenceBitmap,
bsalomon@google.com123ac1d2013-03-28 19:18:12 +00001136 GrSurface* gpuTarget) {
epoger@google.comde961632012-10-26 18:56:36 +00001137 if (gRec.fBackend == kRaster_Backend ||
1138 gRec.fBackend == kGPU_Backend) {
epoger@google.comc8263e72013-04-10 12:17:34 +00001139 const char renderModeDescriptor[] = "-deferred";
epoger@google.comde961632012-10-26 18:56:36 +00001140 SkBitmap bitmap;
1141 // Early exit if we can't generate the image, but this is
1142 // expected in some cases, so don't report a test failure.
bsalomon@google.com123ac1d2013-03-28 19:18:12 +00001143 ErrorCombination errors = generate_image(gm, gRec, gpuTarget, &bitmap, true);
epoger@google.com6f6568b2013-03-22 17:29:46 +00001144 // TODO(epoger): This logic is the opposite of what is
1145 // described above... if we succeeded in generating the
1146 // -deferred image, we exit early! We should fix this
1147 // ASAP, because it is hiding -deferred errors... but for
1148 // now, I'm leaving the logic as it is so that the
1149 // refactoring change
1150 // https://codereview.chromium.org/12992003/ is unblocked.
1151 //
1152 // Filed as https://code.google.com/p/skia/issues/detail?id=1180
1153 // ('image-surface gm test is failing in "deferred" mode,
1154 // and gm is not reporting the failure')
1155 if (errors.isEmpty()) {
epoger@google.com310478e2013-04-03 18:00:39 +00001156 // TODO(epoger): Report this as a new ErrorType,
1157 // something like kImageGeneration_ErrorType?
epoger@google.com6f6568b2013-03-22 17:29:46 +00001158 return kEmpty_ErrorCombination;
epoger@google.comde961632012-10-26 18:56:36 +00001159 }
epoger@google.com37269602013-01-19 04:21:27 +00001160 return compare_test_results_to_reference_bitmap(
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001161 gm->getName(), gRec.fName, renderModeDescriptor, bitmap, &referenceBitmap);
epoger@google.comde961632012-10-26 18:56:36 +00001162 }
epoger@google.com6f6568b2013-03-22 17:29:46 +00001163 return kEmpty_ErrorCombination;
epoger@google.comde961632012-10-26 18:56:36 +00001164 }
1165
epoger@google.comcaac3db2013-04-04 19:23:11 +00001166 ErrorCombination test_pipe_playback(GM* gm, const ConfigData& gRec,
1167 const SkBitmap& referenceBitmap, bool simulateFailure) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001168 const SkString shortNamePlusConfig = make_shortname_plus_config(gm->getName(),
epoger@google.com659c8c02013-05-21 15:45:45 +00001169 gRec.fName);
epoger@google.com6f6568b2013-03-22 17:29:46 +00001170 ErrorCombination errors;
epoger@google.comde961632012-10-26 18:56:36 +00001171 for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) {
epoger@google.comc8263e72013-04-10 12:17:34 +00001172 SkString renderModeDescriptor("-pipe");
1173 renderModeDescriptor.append(gPipeWritingFlagCombos[i].name);
1174
commit-bot@chromium.org805df1a2013-08-16 19:18:12 +00001175 if (gm->getFlags() & GM::kSkipPipe_Flag
1176 || (gPipeWritingFlagCombos[i].flags == SkGPipeWriter::kCrossProcess_Flag
1177 && gm->getFlags() & GM::kSkipPipeCrossProcess_Flag)) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001178 RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
epoger@google.comc8263e72013-04-10 12:17:34 +00001179 renderModeDescriptor.c_str());
1180 errors.add(kIntentionallySkipped_ErrorType);
1181 } else {
1182 SkBitmap bitmap;
1183 SkISize size = gm->getISize();
1184 setup_bitmap(gRec, size, &bitmap);
1185 SkCanvas canvas(bitmap);
1186 installFilter(&canvas);
scroggo@google.com74b7ffd2013-04-30 02:32:41 +00001187 // Pass a decoding function so the factory GM (which has an SkBitmap
1188 // with encoded data) will not fail playback.
1189 PipeController pipeController(&canvas, &SkImageDecoder::DecodeMemory);
epoger@google.comc8263e72013-04-10 12:17:34 +00001190 SkGPipeWriter writer;
1191 SkCanvas* pipeCanvas = writer.startRecording(&pipeController,
scroggo@google.comaef2d3b2013-04-10 18:10:41 +00001192 gPipeWritingFlagCombos[i].flags,
1193 size.width(), size.height());
epoger@google.comc8263e72013-04-10 12:17:34 +00001194 if (!simulateFailure) {
1195 invokeGM(gm, pipeCanvas, false, false);
1196 }
1197 complete_bitmap(&bitmap);
1198 writer.endRecording();
1199 errors.add(compare_test_results_to_reference_bitmap(
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001200 gm->getName(), gRec.fName, renderModeDescriptor.c_str(), bitmap,
epoger@google.com659c8c02013-05-21 15:45:45 +00001201 &referenceBitmap));
epoger@google.comc8263e72013-04-10 12:17:34 +00001202 if (!errors.isEmpty()) {
1203 break;
1204 }
epoger@google.comde961632012-10-26 18:56:36 +00001205 }
1206 }
1207 return errors;
1208 }
1209
epoger@google.com6f6568b2013-03-22 17:29:46 +00001210 ErrorCombination test_tiled_pipe_playback(GM* gm, const ConfigData& gRec,
1211 const SkBitmap& referenceBitmap) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001212 const SkString shortNamePlusConfig = make_shortname_plus_config(gm->getName(),
epoger@google.com659c8c02013-05-21 15:45:45 +00001213 gRec.fName);
epoger@google.com6f6568b2013-03-22 17:29:46 +00001214 ErrorCombination errors;
epoger@google.comde961632012-10-26 18:56:36 +00001215 for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) {
epoger@google.comc8263e72013-04-10 12:17:34 +00001216 SkString renderModeDescriptor("-tiled pipe");
1217 renderModeDescriptor.append(gPipeWritingFlagCombos[i].name);
1218
1219 if ((gm->getFlags() & GM::kSkipPipe_Flag) ||
1220 (gm->getFlags() & GM::kSkipTiled_Flag)) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001221 RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
epoger@google.comc8263e72013-04-10 12:17:34 +00001222 renderModeDescriptor.c_str());
1223 errors.add(kIntentionallySkipped_ErrorType);
1224 } else {
1225 SkBitmap bitmap;
1226 SkISize size = gm->getISize();
1227 setup_bitmap(gRec, size, &bitmap);
1228 SkCanvas canvas(bitmap);
1229 installFilter(&canvas);
scroggo@google.com74b7ffd2013-04-30 02:32:41 +00001230 TiledPipeController pipeController(bitmap, &SkImageDecoder::DecodeMemory);
epoger@google.comc8263e72013-04-10 12:17:34 +00001231 SkGPipeWriter writer;
1232 SkCanvas* pipeCanvas = writer.startRecording(&pipeController,
scroggo@google.comaef2d3b2013-04-10 18:10:41 +00001233 gPipeWritingFlagCombos[i].flags,
1234 size.width(), size.height());
epoger@google.comc8263e72013-04-10 12:17:34 +00001235 invokeGM(gm, pipeCanvas, false, false);
1236 complete_bitmap(&bitmap);
1237 writer.endRecording();
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001238 errors.add(compare_test_results_to_reference_bitmap(gm->getName(), gRec.fName,
epoger@google.comc8263e72013-04-10 12:17:34 +00001239 renderModeDescriptor.c_str(),
1240 bitmap, &referenceBitmap));
1241 if (!errors.isEmpty()) {
1242 break;
1243 }
epoger@google.comde961632012-10-26 18:56:36 +00001244 }
1245 }
1246 return errors;
1247 }
epoger@google.come8ebeb12012-10-29 16:42:11 +00001248
1249 //
1250 // member variables.
1251 // They are public for now, to allow easier setting by tool_main().
1252 //
1253
epoger@google.com6f7f14d2013-06-19 18:28:31 +00001254 bool fUseFileHierarchy, fWriteChecksumBasedFilenames;
epoger@google.com5079d2c2013-04-12 14:11:21 +00001255 ErrorCombination fIgnorableErrorTypes;
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +00001256 SkTArray<SkString> fIgnorableTestNames;
epoger@google.come8ebeb12012-10-29 16:42:11 +00001257
junov@chromium.org95146eb2013-01-11 21:04:40 +00001258 const char* fMismatchPath;
epoger@google.com5f995452013-06-21 18:16:47 +00001259 const char* fMissingExpectationsPath;
junov@chromium.org95146eb2013-01-11 21:04:40 +00001260
epoger@google.com310478e2013-04-03 18:00:39 +00001261 // collection of tests that have failed with each ErrorType
1262 SkTArray<SkString> fFailedTests[kLast_ErrorType+1];
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001263 SkTArray<SkString> fTestsSkippedOnAllRenderModes;
epoger@google.com310478e2013-04-03 18:00:39 +00001264 int fTestsRun;
1265 SkTDict<int> fRenderModesEncountered;
epoger@google.com57f7abc2012-11-13 03:41:55 +00001266
epoger@google.com908f5832013-04-12 02:23:55 +00001267 // Where to read expectations (expected image hash digests, etc.) from.
epoger@google.com37269602013-01-19 04:21:27 +00001268 // If unset, we don't do comparisons.
1269 SkAutoTUnref<ExpectationsSource> fExpectationsSource;
1270
1271 // JSON summaries that we generate as we go (just for output).
epoger@google.comee8a8e32012-12-18 19:13:49 +00001272 Json::Value fJsonExpectedResults;
1273 Json::Value fJsonActualResults_Failed;
1274 Json::Value fJsonActualResults_FailureIgnored;
epoger@google.com9c56a8d2012-12-20 18:34:29 +00001275 Json::Value fJsonActualResults_NoComparison;
epoger@google.comee8a8e32012-12-18 19:13:49 +00001276 Json::Value fJsonActualResults_Succeeded;
1277
epoger@google.comde961632012-10-26 18:56:36 +00001278}; // end of GMMain class definition
scroggo@google.com72c96722012-06-06 21:07:10 +00001279
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001280#if SK_SUPPORT_GPU
1281static const GLContextType kDontCare_GLContextType = GrContextFactory::kNative_GLContextType;
1282#else
1283static const GLContextType kDontCare_GLContextType = 0;
1284#endif
bsalomon@google.com7361f542012-04-19 19:15:35 +00001285
tomhudson@google.com9875dd12011-04-25 15:49:53 +00001286static const ConfigData gRec[] = {
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001287 { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "8888", true },
reed@google.com69dc4ff2012-11-29 21:21:54 +00001288#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 +00001289 { SkBitmap::kARGB_4444_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "4444", true },
reed@google.com69dc4ff2012-11-29 21:21:54 +00001290#endif
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001291 { SkBitmap::kRGB_565_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "565", true },
1292#if SK_SUPPORT_GPU
1293 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 0, kRW_ConfigFlag, "gpu", true },
robertphillips@google.com7bb28a12013-06-06 21:29:39 +00001294 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 16, kRW_ConfigFlag, "msaa16", false},
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001295 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 4, kRW_ConfigFlag, "msaa4", false},
commit-bot@chromium.org440ddf42014-01-26 18:07:40 +00001296 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNVPR_GLContextType, 4, kRW_ConfigFlag, "nvprmsaa4", true },
1297 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNVPR_GLContextType, 16, kRW_ConfigFlag, "nvprmsaa16", false},
epoger@google.comc824c832013-07-12 15:52:59 +00001298 /* The gpudebug context does not generate meaningful images, so don't record
1299 * the images it generates! We only run it to look for asserts. */
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +00001300 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kDebug_GLContextType, 0, kNone_ConfigFlag, "gpudebug", kDebugOnly},
robertphillips@google.comd6543e52013-07-18 17:39:14 +00001301 /* The gpunull context does the least amount of work possible and doesn't
1302 generate meaninful images, so don't record them!. It can be run to
1303 isolate the CPU-side processing expense from the GPU-side.
1304 */
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +00001305 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNull_GLContextType, 0, kNone_ConfigFlag, "gpunull", kDebugOnly},
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001306#if SK_ANGLE
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001307 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 0, kRW_ConfigFlag, "angle", true },
1308 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 16, kRW_ConfigFlag, "anglemsaa16", true },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001309#endif // SK_ANGLE
1310#ifdef SK_MESA
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001311 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kMESA_GLContextType, 0, kRW_ConfigFlag, "mesa", true },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001312#endif // SK_MESA
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001313#endif // SK_SUPPORT_GPU
bungeman@google.comb29c8832011-10-10 13:19:10 +00001314#ifdef SK_SUPPORT_XPS
bsalomon@google.com7361f542012-04-19 19:15:35 +00001315 /* 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 +00001316 { SkBitmap::kARGB_8888_Config, kXPS_Backend, kDontCare_GLContextType, 0, kWrite_ConfigFlag, "xps", true },
robertphillips@google.coma73e8602012-08-02 17:56:02 +00001317#endif // SK_SUPPORT_XPS
bsalomon@google.com7361f542012-04-19 19:15:35 +00001318#ifdef SK_SUPPORT_PDF
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001319 { SkBitmap::kARGB_8888_Config, kPDF_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "pdf", true },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001320#endif // SK_SUPPORT_PDF
reed@android.com00dae862009-06-10 15:38:48 +00001321};
1322
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001323static const PDFRasterizerData kPDFRasterizers[] = {
1324#ifdef SK_BUILD_FOR_MAC
1325 { &SkPDFDocumentToBitmap, "mac", true },
1326#endif
1327#ifdef SK_BUILD_POPPLER
1328 { &SkPopplerRasterizePDF, "poppler", true },
1329#endif
commit-bot@chromium.orgffd178c2013-11-11 15:10:47 +00001330#ifdef SK_BUILD_NATIVE_PDF_RENDERER
1331 { &SkNativeRasterizePDF, "native", true },
1332#endif // SK_BUILD_NATIVE_PDF_RENDERER
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001333};
1334
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001335static const char kDefaultsConfigStr[] = "defaults";
1336static const char kExcludeConfigChar = '~';
1337
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001338static SkString configUsage() {
scroggo@google.com0f567c62013-03-20 15:35:08 +00001339 SkString result;
1340 result.appendf("Space delimited list of which configs to run. Possible options: [");
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001341 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001342 SkASSERT(gRec[i].fName != kDefaultsConfigStr);
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001343 if (i > 0) {
scroggo@google.com0f567c62013-03-20 15:35:08 +00001344 result.append("|");
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001345 }
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001346 result.appendf("%s", gRec[i].fName);
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001347 }
scroggo@google.com0f567c62013-03-20 15:35:08 +00001348 result.append("]\n");
1349 result.appendf("The default value is: \"");
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001350 SkString firstDefault;
1351 SkString allButFirstDefaults;
1352 SkString nonDefault;
scroggo@google.com0f567c62013-03-20 15:35:08 +00001353 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
1354 if (gRec[i].fRunByDefault) {
1355 if (i > 0) {
1356 result.append(" ");
1357 }
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001358 result.append(gRec[i].fName);
1359 if (firstDefault.isEmpty()) {
1360 firstDefault = gRec[i].fName;
1361 } else {
1362 if (!allButFirstDefaults.isEmpty()) {
1363 allButFirstDefaults.append(" ");
1364 }
1365 allButFirstDefaults.append(gRec[i].fName);
1366 }
1367 } else {
1368 nonDefault = gRec[i].fName;
scroggo@google.com0f567c62013-03-20 15:35:08 +00001369 }
1370 }
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001371 result.append("\"\n");
1372 result.appendf("\"%s\" evaluates to the default set of configs.\n", kDefaultsConfigStr);
1373 result.appendf("Prepending \"%c\" on a config name excludes it from the set of configs to run.\n"
1374 "Exclusions always override inclusions regardless of order.\n",
1375 kExcludeConfigChar);
1376 result.appendf("E.g. \"--config %s %c%s %s\" will run these configs:\n\t%s %s",
1377 kDefaultsConfigStr,
1378 kExcludeConfigChar,
1379 firstDefault.c_str(),
1380 nonDefault.c_str(),
1381 allButFirstDefaults.c_str(),
1382 nonDefault.c_str());
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001383 return result;
scroggo@google.com0b735632013-03-19 17:38:50 +00001384}
scroggo@google.com7d519302013-03-19 17:28:10 +00001385
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001386static SkString pdfRasterizerUsage() {
1387 SkString result;
1388 result.appendf("Space delimited list of which PDF rasterizers to run. Possible options: [");
1389 // For this (and further) loops through kPDFRasterizers, there is a typecast to int to avoid
1390 // the compiler giving an "comparison of unsigned expression < 0 is always false" warning
1391 // and turning it into a build-breaking error.
1392 for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); ++i) {
1393 if (i > 0) {
1394 result.append(" ");
1395 }
1396 result.append(kPDFRasterizers[i].fName);
1397 }
1398 result.append("]\n");
1399 result.append("The default value is: \"");
1400 for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); ++i) {
1401 if (kPDFRasterizers[i].fRunByDefault) {
1402 if (i > 0) {
1403 result.append(" ");
1404 }
1405 result.append(kPDFRasterizers[i].fName);
1406 }
1407 }
1408 result.append("\"");
1409 return result;
1410}
1411
epoger@google.com6f6568b2013-03-22 17:29:46 +00001412// Macro magic to convert a numeric preprocessor token into a string.
1413// Adapted from http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
1414// This should probably be moved into one of our common headers...
1415#define TOSTRING_INTERNAL(x) #x
1416#define TOSTRING(x) TOSTRING_INTERNAL(x)
1417
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001418// Alphabetized ignoring "no" prefix ("readPath", "noreplay", "resourcePath").
scroggo@google.com0f567c62013-03-20 15:35:08 +00001419DEFINE_string(config, "", configUsage().c_str());
vandebo@chromium.orgf8afb2b2013-11-06 16:32:15 +00001420DEFINE_string(pdfRasterizers, "default", pdfRasterizerUsage().c_str());
epoger@google.com5e497382013-09-30 07:01:55 +00001421DEFINE_bool(deferred, false, "Exercise the deferred rendering test pass.");
commit-bot@chromium.orgb17ccc92014-03-13 16:16:36 +00001422DEFINE_bool(dryRun, false, "Don't actually run the tests, just print what would have been done.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001423DEFINE_string(excludeConfig, "", "Space delimited list of configs to skip.");
1424DEFINE_bool(forceBWtext, false, "Disable text anti-aliasing.");
1425#if SK_SUPPORT_GPU
1426DEFINE_string(gpuCacheSize, "", "<bytes> <count>: Limit the gpu cache to byte size or "
epoger@google.com6f6568b2013-03-22 17:29:46 +00001427 "object count. " TOSTRING(DEFAULT_CACHE_VALUE) " for either value means "
1428 "use the default. 0 for either disables the cache.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001429#endif
1430DEFINE_bool(hierarchy, false, "Whether to use multilevel directory structure "
1431 "when reading/writing files.");
epoger@google.com5079d2c2013-04-12 14:11:21 +00001432DEFINE_string(ignoreErrorTypes, kDefaultIgnorableErrorTypes.asString(" ").c_str(),
1433 "Space-separated list of ErrorTypes that should be ignored. If any *other* error "
1434 "types are encountered, the tool will exit with a nonzero return value.");
epoger@google.comf711f322013-10-18 14:55:47 +00001435DEFINE_string(ignoreFailuresFile, "", "Path to file containing a list of tests for which we "
1436 "should ignore failures.\n"
1437 "The file should list one test per line, except for comment lines starting with #");
commit-bot@chromium.org6dda8272014-01-23 17:21:19 +00001438DEFINE_bool2(leaks, l, false, "show leaked ref cnt'd objects.");
caryclark@google.com512c9b62013-05-10 15:16:13 +00001439DEFINE_string(match, "", "[~][^]substring[$] [...] of test name to run.\n"
1440 "Multiple matches may be separated by spaces.\n"
1441 "~ causes a matching test to always be skipped\n"
1442 "^ requires the start of the test to match\n"
1443 "$ requires the end of the test to match\n"
1444 "^ and $ requires an exact match\n"
1445 "If a test does not match any list entry,\n"
1446 "it is skipped unless some list entry starts with ~");
epoger@google.com5f995452013-06-21 18:16:47 +00001447DEFINE_string(missingExpectationsPath, "", "Write images for tests without expectations "
1448 "into this directory.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001449DEFINE_string(mismatchPath, "", "Write images for tests that failed due to "
1450 "pixel mismatches into this directory.");
1451DEFINE_string(modulo, "", "[--modulo <remainder> <divisor>]: only run tests for which "
1452 "testIndex %% divisor == remainder.");
epoger@google.com5e497382013-09-30 07:01:55 +00001453DEFINE_bool(pipe, false, "Exercise the SkGPipe replay test pass.");
commit-bot@chromium.orgd393b172014-04-16 16:02:10 +00001454DEFINE_bool(quadtree, false, "Exercise the QuadTree variant of SkPicture test pass.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001455DEFINE_string2(readPath, r, "", "Read reference images from this dir, and report "
1456 "any differences between those and the newly generated ones.");
epoger@google.com5e497382013-09-30 07:01:55 +00001457DEFINE_bool(replay, false, "Exercise the SkPicture replay test pass.");
djsollen@google.comac8f3a42013-10-04 14:57:00 +00001458#if SK_SUPPORT_GPU
1459DEFINE_bool(resetGpuContext, false, "Reset the GrContext prior to running each GM.");
1460#endif
tfarina@chromium.org725a64c2013-12-31 14:29:52 +00001461DEFINE_string2(resourcePath, i, "resources", "Directory that stores image resources.");
epoger@google.com5e497382013-09-30 07:01:55 +00001462DEFINE_bool(rtree, false, "Exercise the R-Tree variant of SkPicture test pass.");
1463DEFINE_bool(serialize, false, "Exercise the SkPicture serialization & deserialization test pass.");
epoger@google.comcaac3db2013-04-04 19:23:11 +00001464DEFINE_bool(simulatePipePlaybackFailure, false, "Simulate a rendering failure in pipe mode only.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001465DEFINE_bool(tiledPipe, false, "Exercise tiled SkGPipe replay.");
epoger@google.com5e497382013-09-30 07:01:55 +00001466DEFINE_bool(tileGrid, false, "Exercise the tile grid variant of SkPicture.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001467DEFINE_string(tileGridReplayScales, "", "Space separated list of floating-point scale "
1468 "factors to be used for tileGrid playback testing. Default value: 1.0");
epoger@google.comb0f8b432013-04-10 18:46:25 +00001469DEFINE_bool2(verbose, v, false, "Give more detail (e.g. list all GMs run, more info about "
1470 "each test).");
epoger@google.com6f7f14d2013-06-19 18:28:31 +00001471DEFINE_bool(writeChecksumBasedFilenames, false, "When writing out actual images, use checksum-"
1472 "based filenames, as rebaseline.py will use when downloading them from Google Storage");
1473DEFINE_string(writeJsonSummaryPath, "", "Write a JSON-formatted result summary to this file.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001474DEFINE_string2(writePath, w, "", "Write rendered images into this directory.");
scroggo@google.com604e0c22013-04-09 21:25:46 +00001475DEFINE_string2(writePicturePath, p, "", "Write .skp files into this directory.");
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001476DEFINE_int32(pdfJpegQuality, -1, "Encodes images in JPEG at quality level N, "
1477 "which can be in range 0-100). N = -1 will disable JPEG compression. "
1478 "Default is N = 100, maximum quality.");
commit-bot@chromium.orgf4f9df42013-09-26 20:44:24 +00001479// TODO(edisonn): pass a matrix instead of forcePerspectiveMatrix
1480// Either the 9 numbers defining the matrix
1481// or probably more readable would be to replace it with a set of a few predicates
1482// Like --prerotate 100 200 10 --posttranslate 10, 10
1483// Probably define spacial names like centerx, centery, top, bottom, left, right
1484// then we can write something reabable like --rotate centerx centery 90
1485DEFINE_bool(forcePerspectiveMatrix, false, "Force a perspective matrix.");
commit-bot@chromium.org5e009892013-10-14 13:42:12 +00001486DEFINE_bool(useDocumentInsteadOfDevice, false, "Use SkDocument::CreateFoo instead of SkFooDevice.");
edisonn@google.com73a7ea32013-11-11 20:55:15 +00001487DEFINE_int32(pdfRasterDpi, 72, "Scale at which at which the non suported "
1488 "features in PDF are rasterized. Must be be in range 0-10000. "
1489 "Default is 72. N = 0 will disable rasterizing features like "
1490 "text shadows or perspective bitmaps.");
reed@google.com672588b2014-01-08 15:42:01 +00001491static SkData* encode_to_dct_data(size_t*, const SkBitmap& bitmap) {
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001492 // Filter output of warnings that JPEG is not available for the image.
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001493 if (bitmap.width() >= 65500 || bitmap.height() >= 65500) return NULL;
1494 if (FLAGS_pdfJpegQuality == -1) return NULL;
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001495
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001496 SkBitmap bm = bitmap;
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001497#if defined(SK_BUILD_FOR_MAC)
1498 // Workaround bug #1043 where bitmaps with referenced pixels cause
1499 // CGImageDestinationFinalize to crash
1500 SkBitmap copy;
commit-bot@chromium.orgd5f032d2014-02-24 18:51:43 +00001501 bitmap.deepCopyTo(&copy);
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001502 bm = copy;
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001503#endif
1504
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001505 SkPixelRef* pr = bm.pixelRef();
1506 if (pr != NULL) {
1507 SkData* data = pr->refEncodedData();
1508 if (data != NULL) {
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001509 return data;
1510 }
1511 }
1512
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001513 return SkImageEncoder::EncodeData(bm,
1514 SkImageEncoder::kJPEG_Type,
1515 FLAGS_pdfJpegQuality);
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001516}
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001517
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001518static int findConfig(const char config[]) {
1519 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
1520 if (!strcmp(config, gRec[i].fName)) {
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001521 return (int) i;
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001522 }
1523 }
1524 return -1;
1525}
1526
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001527static const PDFRasterizerData* findPDFRasterizer(const char rasterizer[]) {
1528 for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); i++) {
1529 if (!strcmp(rasterizer, kPDFRasterizers[i].fName)) {
1530 return &kPDFRasterizers[i];
1531 }
1532 }
1533 return NULL;
1534}
1535
reed@google.comfb2cd422013-01-04 14:43:03 +00001536template <typename T> void appendUnique(SkTDArray<T>* array, const T& value) {
1537 int index = array->find(value);
1538 if (index < 0) {
1539 *array->append() = value;
1540 }
1541}
1542
epoger@google.com80724df2013-03-21 13:49:54 +00001543/**
epoger@google.com80724df2013-03-21 13:49:54 +00001544 * Run this test in a number of different drawing modes (pipe,
1545 * deferred, tiled, etc.), confirming that the resulting bitmaps all
1546 * *exactly* match comparisonBitmap.
1547 *
1548 * Returns all errors encountered while doing so.
1549 */
epoger@google.com6f6568b2013-03-22 17:29:46 +00001550ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm, const ConfigData &compareConfig,
1551 const SkBitmap &comparisonBitmap,
1552 const SkTDArray<SkScalar> &tileGridReplayScales);
1553ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm, const ConfigData &compareConfig,
1554 const SkBitmap &comparisonBitmap,
1555 const SkTDArray<SkScalar> &tileGridReplayScales) {
1556 ErrorCombination errorsForAllModes;
epoger@google.com80724df2013-03-21 13:49:54 +00001557 uint32_t gmFlags = gm->getFlags();
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001558 const SkString shortNamePlusConfig = gmmain.make_shortname_plus_config(gm->getName(),
epoger@google.com659c8c02013-05-21 15:45:45 +00001559 compareConfig.fName);
epoger@google.com80724df2013-03-21 13:49:54 +00001560
epoger@google.comc8263e72013-04-10 12:17:34 +00001561 SkPicture* pict = gmmain.generate_new_picture(gm, kNone_BbhType, 0);
1562 SkAutoUnref aur(pict);
1563 if (FLAGS_replay) {
1564 const char renderModeDescriptor[] = "-replay";
1565 if (gmFlags & GM::kSkipPicture_Flag) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001566 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
1567 renderModeDescriptor);
epoger@google.comc8263e72013-04-10 12:17:34 +00001568 errorsForAllModes.add(kIntentionallySkipped_ErrorType);
1569 } else {
epoger@google.com80724df2013-03-21 13:49:54 +00001570 SkBitmap bitmap;
1571 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap);
epoger@google.comc8263e72013-04-10 12:17:34 +00001572 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap(
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001573 gm->getName(), compareConfig.fName, renderModeDescriptor, bitmap,
epoger@google.com659c8c02013-05-21 15:45:45 +00001574 &comparisonBitmap));
epoger@google.com80724df2013-03-21 13:49:54 +00001575 }
epoger@google.comc8263e72013-04-10 12:17:34 +00001576 }
epoger@google.com80724df2013-03-21 13:49:54 +00001577
epoger@google.comc8263e72013-04-10 12:17:34 +00001578 if (FLAGS_serialize) {
1579 const char renderModeDescriptor[] = "-serialize";
1580 if (gmFlags & GM::kSkipPicture_Flag) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001581 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
1582 renderModeDescriptor);
epoger@google.comc8263e72013-04-10 12:17:34 +00001583 errorsForAllModes.add(kIntentionallySkipped_ErrorType);
1584 } else {
epoger@google.com80724df2013-03-21 13:49:54 +00001585 SkPicture* repict = gmmain.stream_to_new_picture(*pict);
1586 SkAutoUnref aurr(repict);
epoger@google.com80724df2013-03-21 13:49:54 +00001587 SkBitmap bitmap;
1588 gmmain.generate_image_from_picture(gm, compareConfig, repict, &bitmap);
epoger@google.comc8263e72013-04-10 12:17:34 +00001589 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap(
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001590 gm->getName(), compareConfig.fName, renderModeDescriptor, bitmap,
epoger@google.com659c8c02013-05-21 15:45:45 +00001591 &comparisonBitmap));
epoger@google.com80724df2013-03-21 13:49:54 +00001592 }
epoger@google.com80724df2013-03-21 13:49:54 +00001593 }
1594
epoger@google.comc8263e72013-04-10 12:17:34 +00001595 if ((1 == FLAGS_writePicturePath.count()) &&
1596 !(gmFlags & GM::kSkipPicture_Flag)) {
1597 const char* pictureSuffix = "skp";
epoger@google.com659c8c02013-05-21 15:45:45 +00001598 // TODO(epoger): Make sure this still works even though the
1599 // filename now contains the config name (it used to contain
1600 // just the shortName). I think this is actually an
1601 // *improvement*, because now runs with different configs will
1602 // write out their SkPictures to separate files rather than
1603 // overwriting each other. But we should make sure it doesn't
1604 // break anybody.
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001605 SkString path = gmmain.make_filename(FLAGS_writePicturePath[0], gm->getName(),
epoger@google.com659c8c02013-05-21 15:45:45 +00001606 compareConfig.fName, "", pictureSuffix);
epoger@google.comc8263e72013-04-10 12:17:34 +00001607 SkFILEWStream stream(path.c_str());
1608 pict->serialize(&stream);
epoger@google.com80724df2013-03-21 13:49:54 +00001609 }
1610
epoger@google.comc8263e72013-04-10 12:17:34 +00001611 if (FLAGS_rtree) {
1612 const char renderModeDescriptor[] = "-rtree";
commit-bot@chromium.orgd393b172014-04-16 16:02:10 +00001613 if ((gmFlags & GM::kSkipPicture_Flag) || (gmFlags & GM::kSkipTiled_Flag)) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001614 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
1615 renderModeDescriptor);
epoger@google.comc8263e72013-04-10 12:17:34 +00001616 errorsForAllModes.add(kIntentionallySkipped_ErrorType);
1617 } else {
commit-bot@chromium.orgd393b172014-04-16 16:02:10 +00001618 SkPicture* pict = gmmain.generate_new_picture(gm, kRTree_BbhType, 0);
1619 SkAutoUnref aur(pict);
1620 SkBitmap bitmap;
1621 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap);
1622 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap(
1623 gm->getName(), compareConfig.fName, renderModeDescriptor, bitmap,
1624 &comparisonBitmap));
1625 }
1626 }
1627
1628 if (FLAGS_quadtree) {
1629 const char renderModeDescriptor[] = "-quadtree";
1630 if ((gmFlags & GM::kSkipPicture_Flag) || (gmFlags & GM::kSkipTiled_Flag)) {
1631 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
1632 renderModeDescriptor);
1633 errorsForAllModes.add(kIntentionallySkipped_ErrorType);
1634 } else {
1635 SkPicture* pict = gmmain.generate_new_picture(gm, kQuadTree_BbhType, 0);
epoger@google.com80724df2013-03-21 13:49:54 +00001636 SkAutoUnref aur(pict);
1637 SkBitmap bitmap;
epoger@google.comc8263e72013-04-10 12:17:34 +00001638 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap);
epoger@google.com6f6568b2013-03-22 17:29:46 +00001639 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap(
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001640 gm->getName(), compareConfig.fName, renderModeDescriptor, bitmap,
epoger@google.com659c8c02013-05-21 15:45:45 +00001641 &comparisonBitmap));
epoger@google.comc8263e72013-04-10 12:17:34 +00001642 }
1643 }
1644
1645 if (FLAGS_tileGrid) {
1646 for(int scaleIndex = 0; scaleIndex < tileGridReplayScales.count(); ++scaleIndex) {
1647 SkScalar replayScale = tileGridReplayScales[scaleIndex];
1648 SkString renderModeDescriptor("-tilegrid");
1649 if (SK_Scalar1 != replayScale) {
1650 renderModeDescriptor += "-scale-";
1651 renderModeDescriptor.appendScalar(replayScale);
1652 }
1653
1654 if ((gmFlags & GM::kSkipPicture_Flag) ||
senorblanco@chromium.orgd4d44f02014-02-20 17:17:57 +00001655 (gmFlags & GM::kSkipTiled_Flag) ||
epoger@google.comc8263e72013-04-10 12:17:34 +00001656 ((gmFlags & GM::kSkipScaledReplay_Flag) && replayScale != 1)) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001657 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
epoger@google.comc8263e72013-04-10 12:17:34 +00001658 renderModeDescriptor.c_str());
1659 errorsForAllModes.add(kIntentionallySkipped_ErrorType);
1660 } else {
1661 // We record with the reciprocal scale to obtain a replay
1662 // result that can be validated against comparisonBitmap.
1663 SkScalar recordScale = SkScalarInvert(replayScale);
1664 SkPicture* pict = gmmain.generate_new_picture(
1665 gm, kTileGrid_BbhType, SkPicture::kUsePathBoundsForClip_RecordingFlag,
1666 recordScale);
1667 SkAutoUnref aur(pict);
1668 SkBitmap bitmap;
1669 // We cannot yet pass 'true' to generate_image_from_picture to
1670 // perform actual tiled rendering (see Issue 1198 -
1671 // https://code.google.com/p/skia/issues/detail?id=1198)
1672 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap,
1673 replayScale /*, true */);
1674 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap(
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001675 gm->getName(), compareConfig.fName, renderModeDescriptor.c_str(), bitmap,
epoger@google.com659c8c02013-05-21 15:45:45 +00001676 &comparisonBitmap));
epoger@google.comc8263e72013-04-10 12:17:34 +00001677 }
epoger@google.com80724df2013-03-21 13:49:54 +00001678 }
1679 }
1680
1681 // run the pipe centric GM steps
epoger@google.comc8263e72013-04-10 12:17:34 +00001682 if (FLAGS_pipe) {
1683 errorsForAllModes.add(gmmain.test_pipe_playback(gm, compareConfig, comparisonBitmap,
1684 FLAGS_simulatePipePlaybackFailure));
1685 if (FLAGS_tiledPipe) {
1686 errorsForAllModes.add(gmmain.test_tiled_pipe_playback(gm, compareConfig,
1687 comparisonBitmap));
epoger@google.com80724df2013-03-21 13:49:54 +00001688 }
epoger@google.com80724df2013-03-21 13:49:54 +00001689 }
1690 return errorsForAllModes;
1691}
1692
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001693
1694/**
1695 * Run this test in a number of different configs (8888, 565, PDF,
1696 * etc.), confirming that the resulting bitmaps match expectations
1697 * (which may be different for each config).
1698 *
1699 * Returns all errors encountered while doing so.
1700 */
1701ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm,
1702 const SkTDArray<size_t> &configs,
1703 const SkTDArray<const PDFRasterizerData*> &pdfRasterizers,
1704 const SkTDArray<SkScalar> &tileGridReplayScales,
1705 GrContextFactory *grFactory);
1706ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm,
1707 const SkTDArray<size_t> &configs,
1708 const SkTDArray<const PDFRasterizerData*> &pdfRasterizers,
1709 const SkTDArray<SkScalar> &tileGridReplayScales,
1710 GrContextFactory *grFactory) {
1711 const char renderModeDescriptor[] = "";
1712 ErrorCombination errorsForAllConfigs;
1713 uint32_t gmFlags = gm->getFlags();
1714
1715 for (int i = 0; i < configs.count(); i++) {
1716 ConfigData config = gRec[configs[i]];
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001717 const SkString shortNamePlusConfig = gmmain.make_shortname_plus_config(gm->getName(),
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001718 config.fName);
1719
1720 // Skip any tests that we don't even need to try.
1721 // If any of these were skipped on a per-GM basis, record them as
1722 // kIntentionallySkipped.
1723 if (kPDF_Backend == config.fBackend) {
1724 if (gmFlags & GM::kSkipPDF_Flag) {
1725 gmmain.RecordSkippedTest(shortNamePlusConfig,
1726 renderModeDescriptor,
1727 config.fBackend);
1728 errorsForAllConfigs.add(kIntentionallySkipped_ErrorType);
1729 continue;
1730 }
1731 }
1732 if ((gmFlags & GM::kSkip565_Flag) &&
1733 (kRaster_Backend == config.fBackend) &&
1734 (SkBitmap::kRGB_565_Config == config.fConfig)) {
1735 gmmain.RecordSkippedTest(shortNamePlusConfig,
1736 renderModeDescriptor,
1737 config.fBackend);
1738 errorsForAllConfigs.add(kIntentionallySkipped_ErrorType);
1739 continue;
1740 }
1741 if (((gmFlags & GM::kSkipGPU_Flag) && kGPU_Backend == config.fBackend) ||
1742 ((gmFlags & GM::kGPUOnly_Flag) && kGPU_Backend != config.fBackend)) {
1743 gmmain.RecordSkippedTest(shortNamePlusConfig,
1744 renderModeDescriptor,
1745 config.fBackend);
1746 errorsForAllConfigs.add(kIntentionallySkipped_ErrorType);
1747 continue;
1748 }
1749
1750 // Now we know that we want to run this test and record its
1751 // success or failure.
1752 ErrorCombination errorsForThisConfig;
1753 GrSurface* gpuTarget = NULL;
1754#if SK_SUPPORT_GPU
1755 SkAutoTUnref<GrSurface> auGpuTarget;
1756 if ((errorsForThisConfig.isEmpty()) && (kGPU_Backend == config.fBackend)) {
1757 if (FLAGS_resetGpuContext) {
1758 grFactory->destroyContexts();
1759 }
1760 GrContext* gr = grFactory->get(config.fGLContextType);
1761 bool grSuccess = false;
1762 if (gr) {
1763 // create a render target to back the device
1764 GrTextureDesc desc;
1765 desc.fConfig = kSkia8888_GrPixelConfig;
1766 desc.fFlags = kRenderTarget_GrTextureFlagBit;
1767 desc.fWidth = gm->getISize().width();
1768 desc.fHeight = gm->getISize().height();
1769 desc.fSampleCnt = config.fSampleCnt;
1770 auGpuTarget.reset(gr->createUncachedTexture(desc, NULL, 0));
1771 if (NULL != auGpuTarget) {
1772 gpuTarget = auGpuTarget;
1773 grSuccess = true;
1774 // Set the user specified cache limits if non-default.
1775 size_t bytes;
1776 int count;
1777 gr->getTextureCacheLimits(&count, &bytes);
1778 if (DEFAULT_CACHE_VALUE != gGpuCacheSizeBytes) {
1779 bytes = static_cast<size_t>(gGpuCacheSizeBytes);
1780 }
1781 if (DEFAULT_CACHE_VALUE != gGpuCacheSizeCount) {
1782 count = gGpuCacheSizeCount;
1783 }
1784 gr->setTextureCacheLimits(count, bytes);
1785 }
1786 }
1787 if (!grSuccess) {
1788 errorsForThisConfig.add(kNoGpuContext_ErrorType);
1789 }
1790 }
1791#endif
1792
1793 SkBitmap comparisonBitmap;
1794
1795 const char* writePath;
1796 if (FLAGS_writePath.count() == 1) {
1797 writePath = FLAGS_writePath[0];
1798 } else {
1799 writePath = NULL;
1800 }
1801
1802 if (errorsForThisConfig.isEmpty()) {
1803 errorsForThisConfig.add(gmmain.test_drawing(gm, config, pdfRasterizers,
1804 writePath, gpuTarget,
1805 &comparisonBitmap));
1806 gmmain.RecordTestResults(errorsForThisConfig, shortNamePlusConfig, "");
1807 }
1808
1809 // TODO: run only if gmmain.test_drawing succeeded.
1810 if (kRaster_Backend == config.fBackend) {
1811 run_multiple_modes(gmmain, gm, config, comparisonBitmap, tileGridReplayScales);
1812 }
1813
1814 if (FLAGS_deferred && errorsForThisConfig.isEmpty() &&
1815 (kGPU_Backend == config.fBackend || kRaster_Backend == config.fBackend)) {
1816 errorsForThisConfig.add(gmmain.test_deferred_drawing(gm, config, comparisonBitmap,
1817 gpuTarget));
1818 }
1819
1820 errorsForAllConfigs.add(errorsForThisConfig);
1821 }
1822 return errorsForAllConfigs;
1823}
1824
1825
epoger@google.com310478e2013-04-03 18:00:39 +00001826/**
epoger@google.comf711f322013-10-18 14:55:47 +00001827 * Read individual lines from a file, pushing them into the given array.
1828 *
1829 * @param filename path to the file to read
1830 * @param lines array of strings to add the lines to
1831 * @returns true if able to read lines from the file
1832 */
1833static bool read_lines_from_file(const char* filename, SkTArray<SkString> &lines) {
1834 SkAutoTUnref<SkStream> streamWrapper(SkStream::NewFromFile(filename));
1835 SkStream *stream = streamWrapper.get();
1836 if (!stream) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00001837 SkDebugf("unable to read file '%s'\n", filename);
epoger@google.comf711f322013-10-18 14:55:47 +00001838 return false;
1839 }
1840
1841 char c;
1842 SkString line;
1843 while (1 == stream->read(&c, 1)) {
1844 // If we hit either CR or LF, we've completed a line.
1845 //
1846 // TODO: If the file uses both CR and LF, this will return an extra blank
1847 // line for each line of the file. Which is OK for current purposes...
1848 //
1849 // TODO: Does this properly handle unicode? It doesn't matter for
1850 // current purposes...
1851 if ((c == 0x0d) || (c == 0x0a)) {
1852 lines.push_back(line);
1853 line.reset();
1854 } else {
1855 line.append(&c, 1);
1856 }
1857 }
1858 lines.push_back(line);
1859 return true;
1860}
1861
1862/**
epoger@google.com310478e2013-04-03 18:00:39 +00001863 * Return a list of all entries in an array of strings as a single string
1864 * of this form:
1865 * "item1", "item2", "item3"
1866 */
1867SkString list_all(const SkTArray<SkString> &stringArray);
1868SkString list_all(const SkTArray<SkString> &stringArray) {
1869 SkString total;
1870 for (int i = 0; i < stringArray.count(); i++) {
1871 if (i > 0) {
1872 total.append(", ");
1873 }
1874 total.append("\"");
1875 total.append(stringArray[i]);
1876 total.append("\"");
1877 }
1878 return total;
1879}
1880
1881/**
1882 * Return a list of configuration names, as a single string of this form:
1883 * "item1", "item2", "item3"
1884 *
1885 * @param configs configurations, as a list of indices into gRec
1886 */
1887SkString list_all_config_names(const SkTDArray<size_t> &configs);
1888SkString list_all_config_names(const SkTDArray<size_t> &configs) {
1889 SkString total;
1890 for (int i = 0; i < configs.count(); i++) {
1891 if (i > 0) {
1892 total.append(", ");
1893 }
1894 total.append("\"");
1895 total.append(gRec[configs[i]].fName);
1896 total.append("\"");
1897 }
1898 return total;
1899}
1900
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001901static bool prepare_subdirectories(const char *root, bool useFileHierarchy,
1902 const SkTDArray<size_t> &configs,
1903 const SkTDArray<const PDFRasterizerData*>& pdfRasterizers) {
epoger@google.comfdea3252013-05-02 18:24:03 +00001904 if (!sk_mkdir(root)) {
1905 return false;
1906 }
1907 if (useFileHierarchy) {
1908 for (int i = 0; i < configs.count(); i++) {
1909 ConfigData config = gRec[configs[i]];
1910 SkString subdir;
1911 subdir.appendf("%s%c%s", root, SkPATH_SEPARATOR, config.fName);
1912 if (!sk_mkdir(subdir.c_str())) {
1913 return false;
1914 }
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001915
1916 if (config.fBackend == kPDF_Backend) {
1917 for (int j = 0; j < pdfRasterizers.count(); j++) {
1918 SkString pdfSubdir = subdir;
vandebo@chromium.org8fc37662013-08-21 18:04:09 +00001919 pdfSubdir.appendf("-%s", pdfRasterizers[j]->fName);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001920 if (!sk_mkdir(pdfSubdir.c_str())) {
1921 return false;
1922 }
1923 }
1924 }
epoger@google.comfdea3252013-05-02 18:24:03 +00001925 }
1926 }
1927 return true;
1928}
1929
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00001930static bool parse_flags_configs(SkTDArray<size_t>* outConfigs,
1931 GrContextFactory* grFactory) {
1932 SkTDArray<size_t> excludeConfigs;
1933
1934 for (int i = 0; i < FLAGS_config.count(); i++) {
1935 const char* config = FLAGS_config[i];
1936 bool exclude = false;
1937 if (*config == kExcludeConfigChar) {
1938 exclude = true;
1939 config += 1;
1940 }
1941 int index = findConfig(config);
1942 if (index >= 0) {
1943 if (exclude) {
1944 *excludeConfigs.append() = index;
1945 } else {
1946 appendUnique<size_t>(outConfigs, index);
1947 }
1948 } else if (0 == strcmp(kDefaultsConfigStr, config)) {
1949 if (exclude) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00001950 SkDebugf("%c%s is not allowed.\n",
1951 kExcludeConfigChar, kDefaultsConfigStr);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00001952 return false;
1953 }
1954 for (size_t c = 0; c < SK_ARRAY_COUNT(gRec); ++c) {
1955 if (gRec[c].fRunByDefault) {
1956 appendUnique<size_t>(outConfigs, c);
1957 }
1958 }
1959 } else {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00001960 SkDebugf("unrecognized config %s\n", config);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00001961 return false;
1962 }
1963 }
1964
1965 for (int i = 0; i < FLAGS_excludeConfig.count(); i++) {
1966 int index = findConfig(FLAGS_excludeConfig[i]);
1967 if (index >= 0) {
1968 *excludeConfigs.append() = index;
1969 } else {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00001970 SkDebugf("unrecognized excludeConfig %s\n", FLAGS_excludeConfig[i]);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00001971 return false;
1972 }
1973 }
1974
1975 if (outConfigs->count() == 0) {
1976 // if no config is specified by user, add the defaults
1977 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
1978 if (gRec[i].fRunByDefault) {
1979 *outConfigs->append() = i;
1980 }
1981 }
1982 }
1983 // now remove any explicitly excluded configs
1984 for (int i = 0; i < excludeConfigs.count(); ++i) {
1985 int index = outConfigs->find(excludeConfigs[i]);
1986 if (index >= 0) {
1987 outConfigs->remove(index);
1988 // now assert that there was only one copy in configs[]
1989 SkASSERT(outConfigs->find(excludeConfigs[i]) < 0);
1990 }
1991 }
1992
1993#if SK_SUPPORT_GPU
1994 SkASSERT(grFactory != NULL);
1995 for (int i = 0; i < outConfigs->count(); ++i) {
1996 size_t index = (*outConfigs)[i];
1997 if (kGPU_Backend == gRec[index].fBackend) {
1998 GrContext* ctx = grFactory->get(gRec[index].fGLContextType);
1999 if (NULL == ctx) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002000 SkDebugf("GrContext could not be created for config %s. Config will be skipped.\n",
2001 gRec[index].fName);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002002 outConfigs->remove(i);
2003 --i;
2004 continue;
2005 }
2006 if (gRec[index].fSampleCnt > ctx->getMaxSampleCount()) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002007 SkDebugf("Sample count (%d) of config %s is not supported."
2008 " Config will be skipped.\n",
2009 gRec[index].fSampleCnt, gRec[index].fName);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002010 outConfigs->remove(i);
2011 --i;
2012 }
2013 }
2014 }
2015#endif
2016
2017 if (outConfigs->isEmpty()) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002018 SkDebugf("No configs to run.");
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002019 return false;
2020 }
2021
2022 // now show the user the set of configs that will be run.
2023 SkString configStr("These configs will be run:");
2024 // show the user the config that will run.
2025 for (int i = 0; i < outConfigs->count(); ++i) {
2026 configStr.appendf(" %s", gRec[(*outConfigs)[i]].fName);
2027 }
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002028 SkDebugf("%s\n", configStr.c_str());
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002029
2030 return true;
2031}
2032
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002033static bool parse_flags_pdf_rasterizers(const SkTDArray<size_t>& configs,
2034 SkTDArray<const PDFRasterizerData*>* outRasterizers) {
2035 // No need to run this check (and display the PDF rasterizers message)
2036 // if no PDF backends are in the configs.
2037 bool configHasPDF = false;
2038 for (int i = 0; i < configs.count(); i++) {
2039 if (gRec[configs[i]].fBackend == kPDF_Backend) {
2040 configHasPDF = true;
2041 break;
2042 }
2043 }
2044 if (!configHasPDF) {
2045 return true;
2046 }
2047
vandebo@chromium.orgf8afb2b2013-11-06 16:32:15 +00002048 if (FLAGS_pdfRasterizers.count() == 1 &&
2049 !strcmp(FLAGS_pdfRasterizers[0], "default")) {
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002050 for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); ++i) {
2051 if (kPDFRasterizers[i].fRunByDefault) {
2052 *outRasterizers->append() = &kPDFRasterizers[i];
2053 }
2054 }
vandebo@chromium.orgf8afb2b2013-11-06 16:32:15 +00002055 } else {
2056 for (int i = 0; i < FLAGS_pdfRasterizers.count(); i++) {
2057 const char* rasterizer = FLAGS_pdfRasterizers[i];
2058 const PDFRasterizerData* rasterizerPtr =
2059 findPDFRasterizer(rasterizer);
2060 if (rasterizerPtr == NULL) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002061 SkDebugf("unrecognized rasterizer %s\n", rasterizer);
vandebo@chromium.orgf8afb2b2013-11-06 16:32:15 +00002062 return false;
2063 }
2064 appendUnique<const PDFRasterizerData*>(outRasterizers,
2065 rasterizerPtr);
2066 }
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002067 }
2068
2069 // now show the user the set of configs that will be run.
2070 SkString configStr("These PDF rasterizers will be run:");
2071 // show the user the config that will run.
2072 for (int i = 0; i < outRasterizers->count(); ++i) {
2073 configStr.appendf(" %s", (*outRasterizers)[i]->fName);
2074 }
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002075 SkDebugf("%s\n", configStr.c_str());
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002076
2077 return true;
2078}
2079
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002080static bool parse_flags_ignore_error_types(ErrorCombination* outErrorTypes) {
2081 if (FLAGS_ignoreErrorTypes.count() > 0) {
2082 *outErrorTypes = ErrorCombination();
2083 for (int i = 0; i < FLAGS_ignoreErrorTypes.count(); i++) {
2084 ErrorType type;
2085 const char *name = FLAGS_ignoreErrorTypes[i];
2086 if (!getErrorTypeByName(name, &type)) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002087 SkDebugf("cannot find ErrorType with name '%s'\n", name);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002088 return false;
2089 } else {
2090 outErrorTypes->add(type);
2091 }
2092 }
2093 }
2094 return true;
2095}
2096
epoger@google.com3a882dd2013-10-07 18:55:09 +00002097/**
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +00002098 * Replace contents of ignoreTestNames with a list of test names, indicating
epoger@google.com3a882dd2013-10-07 18:55:09 +00002099 * which tests' failures should be ignored.
2100 */
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +00002101static bool parse_flags_ignore_tests(SkTArray<SkString> &ignoreTestNames) {
2102 ignoreTestNames.reset();
epoger@google.comf711f322013-10-18 14:55:47 +00002103
epoger@google.comf711f322013-10-18 14:55:47 +00002104 // Parse --ignoreFailuresFile
2105 for (int i = 0; i < FLAGS_ignoreFailuresFile.count(); i++) {
2106 SkTArray<SkString> linesFromFile;
2107 if (!read_lines_from_file(FLAGS_ignoreFailuresFile[i], linesFromFile)) {
2108 return false;
2109 } else {
2110 for (int j = 0; j < linesFromFile.count(); j++) {
2111 SkString thisLine = linesFromFile[j];
2112 if (thisLine.isEmpty() || thisLine.startsWith('#')) {
2113 // skip this line
2114 } else {
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +00002115 ignoreTestNames.push_back(thisLine);
epoger@google.comf711f322013-10-18 14:55:47 +00002116 }
2117 }
2118 }
2119 }
2120
epoger@google.com3a882dd2013-10-07 18:55:09 +00002121 return true;
2122}
2123
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002124static bool parse_flags_modulo(int* moduloRemainder, int* moduloDivisor) {
2125 if (FLAGS_modulo.count() == 2) {
2126 *moduloRemainder = atoi(FLAGS_modulo[0]);
2127 *moduloDivisor = atoi(FLAGS_modulo[1]);
2128 if (*moduloRemainder < 0 || *moduloDivisor <= 0 ||
2129 *moduloRemainder >= *moduloDivisor) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002130 SkDebugf("invalid modulo values.");
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002131 return false;
2132 }
2133 }
2134 return true;
2135}
2136
2137#if SK_SUPPORT_GPU
2138static bool parse_flags_gpu_cache(int* sizeBytes, int* sizeCount) {
2139 if (FLAGS_gpuCacheSize.count() > 0) {
2140 if (FLAGS_gpuCacheSize.count() != 2) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002141 SkDebugf("--gpuCacheSize requires two arguments\n");
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002142 return false;
2143 }
2144 *sizeBytes = atoi(FLAGS_gpuCacheSize[0]);
2145 *sizeCount = atoi(FLAGS_gpuCacheSize[1]);
2146 } else {
2147 *sizeBytes = DEFAULT_CACHE_VALUE;
2148 *sizeCount = DEFAULT_CACHE_VALUE;
2149 }
2150 return true;
2151}
2152#endif
2153
2154static bool parse_flags_tile_grid_replay_scales(SkTDArray<SkScalar>* outScales) {
2155 *outScales->append() = SK_Scalar1; // By default only test at scale 1.0
2156 if (FLAGS_tileGridReplayScales.count() > 0) {
2157 outScales->reset();
2158 for (int i = 0; i < FLAGS_tileGridReplayScales.count(); i++) {
2159 double val = atof(FLAGS_tileGridReplayScales[i]);
2160 if (0 < val) {
2161 *outScales->append() = SkDoubleToScalar(val);
2162 }
2163 }
2164 if (0 == outScales->count()) {
2165 // Should have at least one scale
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002166 SkDebugf("--tileGridReplayScales requires at least one scale.\n");
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002167 return false;
2168 }
2169 }
2170 return true;
2171}
2172
2173static bool parse_flags_gmmain_paths(GMMain* gmmain) {
2174 gmmain->fUseFileHierarchy = FLAGS_hierarchy;
2175 gmmain->fWriteChecksumBasedFilenames = FLAGS_writeChecksumBasedFilenames;
2176
2177 if (FLAGS_mismatchPath.count() == 1) {
2178 gmmain->fMismatchPath = FLAGS_mismatchPath[0];
2179 }
2180
2181 if (FLAGS_missingExpectationsPath.count() == 1) {
2182 gmmain->fMissingExpectationsPath = FLAGS_missingExpectationsPath[0];
2183 }
2184
2185 if (FLAGS_readPath.count() == 1) {
2186 const char* readPath = FLAGS_readPath[0];
2187 if (!sk_exists(readPath)) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002188 SkDebugf("readPath %s does not exist!\n", readPath);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002189 return false;
2190 }
2191 if (sk_isdir(readPath)) {
2192 if (FLAGS_verbose) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002193 SkDebugf("reading from %s\n", readPath);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002194 }
2195 gmmain->fExpectationsSource.reset(SkNEW_ARGS(
2196 IndividualImageExpectationsSource, (readPath)));
2197 } else {
2198 if (FLAGS_verbose) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002199 SkDebugf("reading expectations from JSON summary file %s\n", readPath);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002200 }
2201 gmmain->fExpectationsSource.reset(SkNEW_ARGS(JsonExpectationsSource, (readPath)));
2202 }
2203 }
2204 return true;
2205}
2206
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002207static bool parse_flags_resource_path() {
2208 if (FLAGS_resourcePath.count() == 1) {
2209 GM::SetResourcePath(FLAGS_resourcePath[0]);
2210 }
2211 return true;
2212}
2213
2214static bool parse_flags_jpeg_quality() {
2215 if (FLAGS_pdfJpegQuality < -1 || FLAGS_pdfJpegQuality > 100) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002216 SkDebugf("%s\n", "pdfJpegQuality must be in [-1 .. 100] range.");
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002217 return false;
2218 }
2219 return true;
2220}
2221
epoger@google.com0b62b3d2013-03-20 17:59:28 +00002222int tool_main(int argc, char** argv);
2223int tool_main(int argc, char** argv) {
2224
commit-bot@chromium.org6dda8272014-01-23 17:21:19 +00002225 SkString usage;
2226 usage.printf("Run the golden master tests.\n");
2227 SkCommandLineFlags::SetUsage(usage.c_str());
2228 SkCommandLineFlags::Parse(argc, argv);
2229
epoger@google.com0b62b3d2013-03-20 17:59:28 +00002230#if SK_ENABLE_INST_COUNT
commit-bot@chromium.org6dda8272014-01-23 17:21:19 +00002231 if (FLAGS_leaks) {
2232 gPrintInstCount = true;
2233 }
epoger@google.com0b62b3d2013-03-20 17:59:28 +00002234#endif
2235
2236 SkGraphics::Init();
2237 // we don't need to see this during a run
2238 gSkSuppressFontCachePurgeSpew = true;
2239
2240 setSystemPreferences();
2241 GMMain gmmain;
2242
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002243 SkTDArray<size_t> configs;
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002244
scroggo@google.com09fd4d22013-03-20 14:20:18 +00002245 int moduloRemainder = -1;
2246 int moduloDivisor = -1;
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002247 SkTDArray<const PDFRasterizerData*> pdfRasterizers;
epoger@google.com6f6568b2013-03-22 17:29:46 +00002248 SkTDArray<SkScalar> tileGridReplayScales;
bsalomon@google.com4c75f242013-03-19 18:58:43 +00002249#if SK_SUPPORT_GPU
2250 GrContextFactory* grFactory = new GrContextFactory;
epoger@google.com80724df2013-03-21 13:49:54 +00002251#else
2252 GrContextFactory* grFactory = NULL;
bsalomon@google.com4c75f242013-03-19 18:58:43 +00002253#endif
2254
commit-bot@chromium.orgb17ccc92014-03-13 16:16:36 +00002255 if (FLAGS_dryRun) {
2256 SkDebugf( "Doing a dry run; no tests will actually be executed.\n");
2257 }
2258
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002259 if (!parse_flags_modulo(&moduloRemainder, &moduloDivisor) ||
2260 !parse_flags_ignore_error_types(&gmmain.fIgnorableErrorTypes) ||
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +00002261 !parse_flags_ignore_tests(gmmain.fIgnorableTestNames) ||
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002262#if SK_SUPPORT_GPU
2263 !parse_flags_gpu_cache(&gGpuCacheSizeBytes, &gGpuCacheSizeCount) ||
2264#endif
2265 !parse_flags_tile_grid_replay_scales(&tileGridReplayScales) ||
2266 !parse_flags_resource_path() ||
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002267 !parse_flags_jpeg_quality() ||
2268 !parse_flags_configs(&configs, grFactory) ||
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002269 !parse_flags_pdf_rasterizers(configs, &pdfRasterizers) ||
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002270 !parse_flags_gmmain_paths(&gmmain)) {
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00002271 return -1;
2272 }
2273
epoger@google.comb0f8b432013-04-10 18:46:25 +00002274 if (FLAGS_verbose) {
2275 if (FLAGS_writePath.count() == 1) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002276 SkDebugf("writing to %s\n", FLAGS_writePath[0]);
epoger@google.comb0f8b432013-04-10 18:46:25 +00002277 }
epoger@google.comfdea3252013-05-02 18:24:03 +00002278 if (NULL != gmmain.fMismatchPath) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002279 SkDebugf("writing mismatches to %s\n", gmmain.fMismatchPath);
epoger@google.comfdea3252013-05-02 18:24:03 +00002280 }
epoger@google.com5f995452013-06-21 18:16:47 +00002281 if (NULL != gmmain.fMissingExpectationsPath) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002282 SkDebugf("writing images without expectations to %s\n",
2283 gmmain.fMissingExpectationsPath);
epoger@google.com5f995452013-06-21 18:16:47 +00002284 }
epoger@google.comb0f8b432013-04-10 18:46:25 +00002285 if (FLAGS_writePicturePath.count() == 1) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002286 SkDebugf("writing pictures to %s\n", FLAGS_writePicturePath[0]);
epoger@google.comb0f8b432013-04-10 18:46:25 +00002287 }
2288 if (FLAGS_resourcePath.count() == 1) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002289 SkDebugf("reading resources from %s\n", FLAGS_resourcePath[0]);
epoger@google.comb0f8b432013-04-10 18:46:25 +00002290 }
robertphillips@google.com8570b5c2012-03-20 17:40:58 +00002291 }
2292
epoger@google.com310478e2013-04-03 18:00:39 +00002293 int gmsRun = 0;
reed@google.comae7b8f32012-10-18 21:30:57 +00002294 int gmIndex = -1;
2295 SkString moduloStr;
2296
commit-bot@chromium.orgb17ccc92014-03-13 16:16:36 +00002297 if (!FLAGS_dryRun) {
2298 // If we will be writing out files, prepare subdirectories.
2299 if (FLAGS_writePath.count() == 1) {
2300 if (!prepare_subdirectories(FLAGS_writePath[0], gmmain.fUseFileHierarchy,
2301 configs, pdfRasterizers)) {
2302 return -1;
2303 }
2304 }
2305 if (NULL != gmmain.fMismatchPath) {
2306 if (!prepare_subdirectories(gmmain.fMismatchPath, gmmain.fUseFileHierarchy,
2307 configs, pdfRasterizers)) {
2308 return -1;
2309 }
2310 }
2311 if (NULL != gmmain.fMissingExpectationsPath) {
2312 if (!prepare_subdirectories(gmmain.fMissingExpectationsPath, gmmain.fUseFileHierarchy,
2313 configs, pdfRasterizers)) {
2314 return -1;
2315 }
epoger@google.come8ebeb12012-10-29 16:42:11 +00002316 }
epoger@google.comfdea3252013-05-02 18:24:03 +00002317 }
bsalomon@google.com7361f542012-04-19 19:15:35 +00002318 Iter iter;
2319 GM* gm;
reed@android.com00dae862009-06-10 15:38:48 +00002320 while ((gm = iter.next()) != NULL) {
commit-bot@chromium.orgf4f9df42013-09-26 20:44:24 +00002321 if (FLAGS_forcePerspectiveMatrix) {
2322 SkMatrix perspective;
2323 perspective.setIdentity();
2324 perspective.setPerspY(SkScalarDiv(SK_Scalar1, SkIntToScalar(1000)));
2325 perspective.setSkewX(SkScalarDiv(SkIntToScalar(8),
2326 SkIntToScalar(25)));
2327
2328 gm->setStarterMatrix(perspective);
skia.committer@gmail.com65caeaf2013-09-27 07:01:29 +00002329 }
scroggo@google.com7fd2d702013-04-16 19:11:14 +00002330 SkAutoTDelete<GM> adgm(gm);
reed@google.comae7b8f32012-10-18 21:30:57 +00002331 ++gmIndex;
epoger@google.com82cb65b2012-10-29 18:59:17 +00002332 if (moduloRemainder >= 0) {
2333 if ((gmIndex % moduloDivisor) != moduloRemainder) {
reed@google.comae7b8f32012-10-18 21:30:57 +00002334 continue;
2335 }
epoger@google.com82cb65b2012-10-29 18:59:17 +00002336 moduloStr.printf("[%d.%d] ", gmIndex, moduloDivisor);
reed@google.comae7b8f32012-10-18 21:30:57 +00002337 }
2338
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00002339 const char* shortName = gm->getName();
sglez@google.com586db932013-07-24 17:24:23 +00002340
commit-bot@chromium.orga6f37e72013-08-30 15:52:46 +00002341 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, shortName)) {
reed@google.comece2b022011-07-25 14:28:57 +00002342 continue;
2343 }
2344
epoger@google.com310478e2013-04-03 18:00:39 +00002345 gmsRun++;
tomhudson@google.com9875dd12011-04-25 15:49:53 +00002346 SkISize size = gm->getISize();
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002347 SkDebugf("%sdrawing... %s [%d %d]\n", moduloStr.c_str(), shortName,
2348 size.width(), size.height());
commit-bot@chromium.orgb17ccc92014-03-13 16:16:36 +00002349 if (!FLAGS_dryRun)
2350 run_multiple_configs(gmmain, gm, configs, pdfRasterizers, tileGridReplayScales, grFactory);
reed@android.com00dae862009-06-10 15:38:48 +00002351 }
epoger@google.com310478e2013-04-03 18:00:39 +00002352
commit-bot@chromium.orgb17ccc92014-03-13 16:16:36 +00002353 if (FLAGS_dryRun)
2354 return 0;
2355
epoger@google.com310478e2013-04-03 18:00:39 +00002356 SkTArray<SkString> modes;
2357 gmmain.GetRenderModesEncountered(modes);
commit-bot@chromium.org85195482014-01-13 18:27:59 +00002358 int modeCount = modes.count();
2359
2360 // Now that we have run all the tests and thus know the full set of renderModes that we
2361 // tried to run, we can call RecordTestResults() to record the cases in which we skipped
2362 // ALL renderModes.
2363 // See http://skbug.com/1994 and https://codereview.chromium.org/129203002/
2364 int testCount = gmmain.fTestsSkippedOnAllRenderModes.count();
2365 for (int testNum = 0; testNum < testCount; ++testNum) {
2366 const SkString &shortNamePlusConfig = gmmain.fTestsSkippedOnAllRenderModes[testNum];
2367 for (int modeNum = 0; modeNum < modeCount; ++modeNum) {
2368 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
2369 modes[modeNum].c_str());
2370 }
2371 }
2372
epoger@google.comc8263e72013-04-10 12:17:34 +00002373 bool reportError = false;
2374 if (gmmain.NumSignificantErrors() > 0) {
2375 reportError = true;
2376 }
commit-bot@chromium.org85195482014-01-13 18:27:59 +00002377
2378 // We test every GM against every config, and for every raster config also test every mode.
2379 int rasterConfigs = 0;
2380 for (int i = 0; i < configs.count(); i++) {
2381 if (gRec[configs[i]].fBackend == kRaster_Backend) {
2382 rasterConfigs++;
2383 }
2384 }
2385 // For raster configs, we run all renderModes; for non-raster configs, just default renderMode
2386 const int expectedNumberOfTests = rasterConfigs * gmsRun * modeCount
2387 + (configs.count() - rasterConfigs) * gmsRun;
epoger@google.com310478e2013-04-03 18:00:39 +00002388
2389 // Output summary to stdout.
epoger@google.com51dbabe2013-04-10 15:24:53 +00002390 if (FLAGS_verbose) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002391 SkDebugf("Ran %d GMs\n", gmsRun);
2392 SkDebugf("... over %2d configs [%s]\n", configs.count(),
2393 list_all_config_names(configs).c_str());
2394 SkDebugf("... and %2d modes [%s]\n", modeCount, list_all(modes).c_str());
2395 SkDebugf("... so there should be a total of %d tests.\n", expectedNumberOfTests);
epoger@google.com51dbabe2013-04-10 15:24:53 +00002396 }
2397 gmmain.ListErrors(FLAGS_verbose);
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00002398
epoger@google.com07947d92013-04-11 15:41:02 +00002399 // TODO(epoger): Enable this check for Android, too, once we resolve
2400 // https://code.google.com/p/skia/issues/detail?id=1222
2401 // ('GM is unexpectedly skipping tests on Android')
2402#ifndef SK_BUILD_FOR_ANDROID
epoger@google.comc8263e72013-04-10 12:17:34 +00002403 if (expectedNumberOfTests != gmmain.fTestsRun) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002404 SkDebugf("expected %d tests, but ran or skipped %d tests\n",
2405 expectedNumberOfTests, gmmain.fTestsRun);
epoger@google.comc8263e72013-04-10 12:17:34 +00002406 reportError = true;
2407 }
2408#endif
2409
scroggo@google.com09fd4d22013-03-20 14:20:18 +00002410 if (FLAGS_writeJsonSummaryPath.count() == 1) {
epoger@google.com76c913d2013-04-26 15:06:44 +00002411 Json::Value root = CreateJsonTree(
2412 gmmain.fJsonExpectedResults,
2413 gmmain.fJsonActualResults_Failed, gmmain.fJsonActualResults_FailureIgnored,
2414 gmmain.fJsonActualResults_NoComparison, gmmain.fJsonActualResults_Succeeded);
epoger@google.comee8a8e32012-12-18 19:13:49 +00002415 std::string jsonStdString = root.toStyledString();
scroggo@google.com09fd4d22013-03-20 14:20:18 +00002416 SkFILEWStream stream(FLAGS_writeJsonSummaryPath[0]);
epoger@google.comee8a8e32012-12-18 19:13:49 +00002417 stream.write(jsonStdString.c_str(), jsonStdString.length());
2418 }
2419
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00002420#if SK_SUPPORT_GPU
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00002421
robertphillips@google.com59552022012-08-31 13:07:37 +00002422#if GR_CACHE_STATS
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00002423 for (int i = 0; i < configs.count(); i++) {
2424 ConfigData config = gRec[configs[i]];
2425
epoger@google.comb0f8b432013-04-10 18:46:25 +00002426 if (FLAGS_verbose && (kGPU_Backend == config.fBackend)) {
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00002427 GrContext* gr = grFactory->get(config.fGLContextType);
2428
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002429 SkDebugf("config: %s %x\n", config.fName, gr);
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00002430 gr->printCacheStats();
2431 }
2432 }
2433#endif
2434
commit-bot@chromium.org8065ec52014-03-11 15:57:40 +00002435#if GR_DUMP_FONT_CACHE
2436 for (int i = 0; i < configs.count(); i++) {
2437 ConfigData config = gRec[configs[i]];
2438
2439 if (kGPU_Backend == config.fBackend) {
2440 GrContext* gr = grFactory->get(config.fGLContextType);
2441
2442 gr->dumpFontCache();
2443 }
2444 }
2445#endif
2446
robertphillips@google.com977b9c82012-06-05 19:35:09 +00002447 delete grFactory;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00002448#endif
robertphillips@google.com977b9c82012-06-05 19:35:09 +00002449 SkGraphics::Term();
2450
epoger@google.comc8263e72013-04-10 12:17:34 +00002451 return (reportError) ? -1 : 0;
reed@android.com00dae862009-06-10 15:38:48 +00002452}
caryclark@google.com5987f582012-10-02 18:33:14 +00002453
scroggo@google.com09fd4d22013-03-20 14:20:18 +00002454void GMMain::installFilter(SkCanvas* canvas) {
2455 if (FLAGS_forceBWtext) {
2456 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref();
2457 }
2458}
2459
borenet@google.com7158e6a2012-11-01 17:43:44 +00002460#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
caryclark@google.com5987f582012-10-02 18:33:14 +00002461int main(int argc, char * const argv[]) {
2462 return tool_main(argc, (char**) argv);
2463}
2464#endif