blob: 9b51eb0ad6265fc9ad57d74a1a78f03909661db7 [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"
mtklein30e6e2a2014-06-18 11:44:15 -070020#include "CrashHandler.h"
tfarinabcbc1782014-06-18 14:32:48 -070021#include "Resources.h"
22#include "SamplePipeControllers.h"
epoger@google.com5f6a0072013-01-31 16:30:55 +000023#include "SkBitmap.h"
reed@android.comb9b9a182009-07-08 02:54:47 +000024#include "SkColorPriv.h"
scroggo@google.comd9ba9a02013-03-21 19:43:15 +000025#include "SkCommandLineFlags.h"
reed@google.com8a85d0c2011-06-24 19:12:12 +000026#include "SkData.h"
junov@google.com4370aed2012-01-18 16:21:08 +000027#include "SkDeferredCanvas.h"
bsalomon@google.com971d0c82011-08-19 17:22:05 +000028#include "SkDevice.h"
commit-bot@chromium.org5e009892013-10-14 13:42:12 +000029#include "SkDocument.h"
epoger@google.comde961632012-10-26 18:56:36 +000030#include "SkDrawFilter.h"
commit-bot@chromium.orgc41295d2013-06-18 20:06:36 +000031#include "SkForceLinking.h"
scroggo@google.com5af9b202012-06-04 17:17:36 +000032#include "SkGPipe.h"
reed@android.com8015dd82009-06-21 00:49:18 +000033#include "SkGraphics.h"
34#include "SkImageDecoder.h"
35#include "SkImageEncoder.h"
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +000036#include "SkJSONCPP.h"
epoger@google.come8ebeb12012-10-29 16:42:11 +000037#include "SkOSFile.h"
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +000038#include "SkPDFRasterizer.h"
tomhudson@google.com9875dd12011-04-25 15:49:53 +000039#include "SkPicture.h"
robertphillips@google.com770963f2014-04-18 18:04:41 +000040#include "SkPictureRecorder.h"
robertphillips@google.com977b9c82012-06-05 19:35:09 +000041#include "SkRefCnt.h"
commit-bot@chromium.org5e009892013-10-14 13:42:12 +000042#include "SkScalar.h"
scroggo@google.com72c96722012-06-06 21:07:10 +000043#include "SkStream.h"
epoger@google.comf711f322013-10-18 14:55:47 +000044#include "SkString.h"
reed@google.com11db6fa2014-02-04 15:30:57 +000045#include "SkSurface.h"
bsalomon@google.com2a48c3a2012-08-03 14:54:45 +000046#include "SkTArray.h"
epoger@google.com310478e2013-04-03 18:00:39 +000047#include "SkTDict.h"
reed@google.com07700442010-12-20 19:46:07 +000048
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000049#ifdef SK_DEBUG
50static const bool kDebugOnly = true;
commit-bot@chromium.org8065ec52014-03-11 15:57:40 +000051#define GR_DUMP_FONT_CACHE 0
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000052#else
53static const bool kDebugOnly = false;
54#endif
55
epoger@google.comed5eb4e2013-07-23 17:56:20 +000056__SK_FORCE_IMAGE_DECODER_LINKING;
57
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000058#if SK_SUPPORT_GPU
59#include "GrContextFactory.h"
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000060#include "SkGpuDevice.h"
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000061typedef GrContextFactory::GLContextType GLContextType;
epoger@google.com6f6568b2013-03-22 17:29:46 +000062#define DEFAULT_CACHE_VALUE -1
63static int gGpuCacheSizeBytes;
64static int gGpuCacheSizeCount;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000065#else
epoger@google.com80724df2013-03-21 13:49:54 +000066class GrContextFactory;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000067class GrContext;
bsalomon@google.com123ac1d2013-03-28 19:18:12 +000068class GrSurface;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000069typedef int GLContextType;
kkinnunen80549fc2014-06-30 06:36:31 -070070typedef int GrGLStandard;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000071#endif
72
epoger@google.com76c913d2013-04-26 15:06:44 +000073#define DEBUGFAIL_SEE_STDERR SkDEBUGFAIL("see stderr for message")
74
commit-bot@chromium.org5e009892013-10-14 13:42:12 +000075DECLARE_bool(useDocumentInsteadOfDevice);
reed@google.com8923c6c2011-11-08 14:59:38 +000076
reed@google.com07700442010-12-20 19:46:07 +000077#ifdef SK_SUPPORT_PDF
tomhudson@google.com9875dd12011-04-25 15:49:53 +000078 #include "SkPDFDevice.h"
79 #include "SkPDFDocument.h"
reed@google.com07700442010-12-20 19:46:07 +000080#endif
reed@android.com00dae862009-06-10 15:38:48 +000081
epoger@google.come3cc2eb2012-01-18 20:11:13 +000082// Until we resolve http://code.google.com/p/skia/issues/detail?id=455 ,
83// stop writing out XPS-format image baselines in gm.
84#undef SK_SUPPORT_XPS
bungeman@google.comb29c8832011-10-10 13:19:10 +000085#ifdef SK_SUPPORT_XPS
86 #include "SkXPSDevice.h"
87#endif
88
reed@google.com46cce912011-06-29 12:54:46 +000089#ifdef SK_BUILD_FOR_MAC
90 #include "SkCGUtils.h"
reed@google.com46cce912011-06-29 12:54:46 +000091#endif
92
reed@android.com00dae862009-06-10 15:38:48 +000093using namespace skiagm;
94
reed@android.com00dae862009-06-10 15:38:48 +000095class Iter {
96public:
97 Iter() {
bsalomon@google.com39149582011-06-13 21:55:32 +000098 this->reset();
99 }
100
101 void reset() {
reed@android.comdd0ac282009-06-20 02:38:16 +0000102 fReg = GMRegistry::Head();
reed@android.com00dae862009-06-10 15:38:48 +0000103 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000104
reed@android.comdd0ac282009-06-20 02:38:16 +0000105 GM* next() {
reed@android.com00dae862009-06-10 15:38:48 +0000106 if (fReg) {
reed@android.comdd0ac282009-06-20 02:38:16 +0000107 GMRegistry::Factory fact = fReg->factory();
reed@android.com00dae862009-06-10 15:38:48 +0000108 fReg = fReg->next();
reed@android.comdd0ac282009-06-20 02:38:16 +0000109 return fact(0);
reed@android.com00dae862009-06-10 15:38:48 +0000110 }
111 return NULL;
112 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000113
reed@android.com00dae862009-06-10 15:38:48 +0000114 static int Count() {
reed@android.comdd0ac282009-06-20 02:38:16 +0000115 const GMRegistry* reg = GMRegistry::Head();
reed@android.com00dae862009-06-10 15:38:48 +0000116 int count = 0;
117 while (reg) {
118 count += 1;
119 reg = reg->next();
120 }
121 return count;
122 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000123
reed@android.com00dae862009-06-10 15:38:48 +0000124private:
125 const GMRegistry* fReg;
126};
127
epoger@google.comce057fe2013-05-14 15:17:46 +0000128// TODO(epoger): Right now, various places in this code assume that all the
129// image files read/written by GM use this file extension.
130// Search for references to this constant to find these assumptions.
131const static char kPNG_FileExtension[] = "png";
132
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000133enum Backend {
junov@chromium.org3cb834b2012-12-13 16:39:53 +0000134 kRaster_Backend,
135 kGPU_Backend,
136 kPDF_Backend,
137 kXPS_Backend,
138};
139
140enum BbhType {
141 kNone_BbhType,
142 kRTree_BbhType,
143 kTileGrid_BbhType,
commit-bot@chromium.orgd393b172014-04-16 16:02:10 +0000144 kQuadTree_BbhType
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000145};
146
bsalomon@google.com7361f542012-04-19 19:15:35 +0000147enum ConfigFlags {
148 kNone_ConfigFlag = 0x0,
149 /* Write GM images if a write path is provided. */
150 kWrite_ConfigFlag = 0x1,
epoger@google.comf28dd8a2012-10-25 16:27:34 +0000151 /* Read reference GM images if a read path is provided. */
bsalomon@google.com7361f542012-04-19 19:15:35 +0000152 kRead_ConfigFlag = 0x2,
153 kRW_ConfigFlag = (kWrite_ConfigFlag | kRead_ConfigFlag),
154};
155
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000156struct ConfigData {
reedddd014e2014-06-05 08:51:20 -0700157 SkColorType fColorType;
bsalomon@google.com7361f542012-04-19 19:15:35 +0000158 Backend fBackend;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000159 GLContextType fGLContextType; // GPU backend only
bsalomon@google.com7361f542012-04-19 19:15:35 +0000160 int fSampleCnt; // GPU backend only
161 ConfigFlags fFlags;
162 const char* fName;
bsalomon@google.com4c75f242013-03-19 18:58:43 +0000163 bool fRunByDefault;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000164};
165
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000166struct PDFRasterizerData {
167 bool (*fRasterizerFunction)(SkStream*, SkBitmap*);
168 const char* fName;
169 bool fRunByDefault;
170};
171
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000172class BWTextDrawFilter : public SkDrawFilter {
173public:
reed@google.com971aca72012-11-26 20:26:54 +0000174 virtual bool filter(SkPaint*, Type) SK_OVERRIDE;
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000175};
reed@google.com971aca72012-11-26 20:26:54 +0000176bool BWTextDrawFilter::filter(SkPaint* p, Type t) {
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000177 if (kText_Type == t) {
178 p->setAntiAlias(false);
179 }
reed@google.com971aca72012-11-26 20:26:54 +0000180 return true;
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000181}
182
scroggo@google.com565254b2012-06-28 15:41:32 +0000183struct PipeFlagComboData {
184 const char* name;
185 uint32_t flags;
186};
187
188static PipeFlagComboData gPipeWritingFlagCombos[] = {
189 { "", 0 },
190 { " cross-process", SkGPipeWriter::kCrossProcess_Flag },
scroggob3c0f482012-07-02 19:07:57 +0000191 { " cross-process, shared address", SkGPipeWriter::kCrossProcess_Flag
scroggo@google.com15011ee2012-07-26 20:03:32 +0000192 | SkGPipeWriter::kSharedAddressSpace_Flag }
scroggo@google.com565254b2012-06-28 15:41:32 +0000193};
194
commit-bot@chromium.org608ea652013-10-03 19:29:21 +0000195static SkData* encode_to_dct_data(size_t* pixelRefOffset, const SkBitmap& bitmap);
edisonn@google.com73a7ea32013-11-11 20:55:15 +0000196DECLARE_int32(pdfRasterDpi);
edisonn@google.comd9dfa182013-04-24 13:01:01 +0000197
epoger@google.com5079d2c2013-04-12 14:11:21 +0000198const static ErrorCombination kDefaultIgnorableErrorTypes = ErrorCombination()
199 .plus(kMissingExpectations_ErrorType)
200 .plus(kIntentionallySkipped_ErrorType);
201
epoger@google.comde961632012-10-26 18:56:36 +0000202class GMMain {
203public:
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000204 GMMain() : fUseFileHierarchy(false), fWriteChecksumBasedFilenames(false),
205 fIgnorableErrorTypes(kDefaultIgnorableErrorTypes),
epoger@google.com5f995452013-06-21 18:16:47 +0000206 fMismatchPath(NULL), fMissingExpectationsPath(NULL), fTestsRun(0),
207 fRenderModesEncountered(1) {}
epoger@google.come8ebeb12012-10-29 16:42:11 +0000208
epoger@google.com659c8c02013-05-21 15:45:45 +0000209 /**
210 * Assemble shortNamePlusConfig from (surprise!) shortName and configName.
211 *
212 * The method for doing so depends on whether we are using hierarchical naming.
213 * For example, shortName "selftest1" and configName "8888" could be assembled into
214 * either "selftest1_8888" or "8888/selftest1".
215 */
216 SkString make_shortname_plus_config(const char *shortName, const char *configName) {
epoger@google.come8ebeb12012-10-29 16:42:11 +0000217 SkString name;
epoger@google.com57f7abc2012-11-13 03:41:55 +0000218 if (0 == strlen(configName)) {
219 name.append(shortName);
220 } else if (fUseFileHierarchy) {
epoger@google.come8ebeb12012-10-29 16:42:11 +0000221 name.appendf("%s%c%s", configName, SkPATH_SEPARATOR, shortName);
222 } else {
223 name.appendf("%s_%s", shortName, configName);
224 }
epoger@google.comde961632012-10-26 18:56:36 +0000225 return name;
226 }
227
epoger@google.com659c8c02013-05-21 15:45:45 +0000228 /**
229 * Assemble filename, suitable for writing out the results of a particular test.
230 */
231 SkString make_filename(const char *path,
232 const char *shortName,
233 const char *configName,
234 const char *renderModeDescriptor,
235 const char *suffix) {
236 SkString filename = make_shortname_plus_config(shortName, configName);
237 filename.append(renderModeDescriptor);
238 filename.appendUnichar('.');
239 filename.append(suffix);
tfarinaa8e2e152014-07-28 19:26:58 -0700240 return SkOSPath::Join(path, filename.c_str());
epoger@google.com659c8c02013-05-21 15:45:45 +0000241 }
242
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000243 /**
244 * Assemble filename suitable for writing out an SkBitmap.
245 */
246 SkString make_bitmap_filename(const char *path,
247 const char *shortName,
248 const char *configName,
249 const char *renderModeDescriptor,
250 const GmResultDigest &bitmapDigest) {
251 if (fWriteChecksumBasedFilenames) {
252 SkString filename;
253 filename.append(bitmapDigest.getHashType());
254 filename.appendUnichar('_');
255 filename.append(shortName);
256 filename.appendUnichar('_');
257 filename.append(bitmapDigest.getDigestValue());
258 filename.appendUnichar('.');
259 filename.append(kPNG_FileExtension);
tfarinaa8e2e152014-07-28 19:26:58 -0700260 return SkOSPath::Join(path, filename.c_str());
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000261 } else {
262 return make_filename(path, shortName, configName, renderModeDescriptor,
263 kPNG_FileExtension);
264 }
265 }
266
epoger@google.com5f6a0072013-01-31 16:30:55 +0000267 /* since PNG insists on unpremultiplying our alpha, we take no
268 precision chances and force all pixels to be 100% opaque,
269 otherwise on compare we may not get a perfect match.
270 */
271 static void force_all_opaque(const SkBitmap& bitmap) {
commit-bot@chromium.orgdac52252014-02-17 21:21:46 +0000272 SkColorType colorType = bitmap.colorType();
273 switch (colorType) {
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000274 case kN32_SkColorType:
epoger@google.com5f6a0072013-01-31 16:30:55 +0000275 force_all_opaque_8888(bitmap);
276 break;
commit-bot@chromium.orgdac52252014-02-17 21:21:46 +0000277 case kRGB_565_SkColorType:
epoger@google.com5f6a0072013-01-31 16:30:55 +0000278 // nothing to do here; 565 bitmaps are inherently opaque
279 break;
280 default:
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000281 SkDebugf("unsupported bitmap colorType %d\n", colorType);
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000282 DEBUGFAIL_SEE_STDERR;
epoger@google.com5f6a0072013-01-31 16:30:55 +0000283 }
284 }
285
286 static void force_all_opaque_8888(const SkBitmap& bitmap) {
287 SkAutoLockPixels lock(bitmap);
288 for (int y = 0; y < bitmap.height(); y++) {
289 for (int x = 0; x < bitmap.width(); x++) {
290 *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT);
291 }
292 }
293 }
294
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000295 static ErrorCombination write_bitmap(const SkString& path, const SkBitmap& bitmap) {
epoger@google.com5f6a0072013-01-31 16:30:55 +0000296 // TODO(epoger): Now that we have removed force_all_opaque()
297 // from this method, we should be able to get rid of the
298 // transformation to 8888 format also.
299 SkBitmap copy;
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000300 bitmap.copyTo(&copy, kN32_SkColorType);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000301 if (!SkImageEncoder::EncodeFile(path.c_str(), copy,
302 SkImageEncoder::kPNG_Type,
303 100)) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000304 SkDebugf("FAILED to write bitmap: %s\n", path.c_str());
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000305 return ErrorCombination(kWritingReferenceImage_ErrorType);
306 }
307 return kEmpty_ErrorCombination;
epoger@google.com5f6a0072013-01-31 16:30:55 +0000308 }
309
epoger@google.com6f6568b2013-03-22 17:29:46 +0000310 /**
epoger@google.com310478e2013-04-03 18:00:39 +0000311 * Add all render modes encountered thus far to the "modes" array.
epoger@google.com6f6568b2013-03-22 17:29:46 +0000312 */
epoger@google.com310478e2013-04-03 18:00:39 +0000313 void GetRenderModesEncountered(SkTArray<SkString> &modes) {
314 SkTDict<int>::Iter iter(this->fRenderModesEncountered);
315 const char* mode;
316 while ((mode = iter.next(NULL)) != NULL) {
317 SkString modeAsString = SkString(mode);
318 // TODO(epoger): It seems a bit silly that all of these modes were
319 // recorded with a leading "-" which we have to remove here
320 // (except for mode "", which means plain old original mode).
321 // But that's how renderModeDescriptor has been passed into
322 // compare_test_results_to_reference_bitmap() historically,
323 // and changing that now may affect other parts of our code.
324 if (modeAsString.startsWith("-")) {
325 modeAsString.remove(0, 1);
epoger@google.com310478e2013-04-03 18:00:39 +0000326 }
commit-bot@chromium.org85195482014-01-13 18:27:59 +0000327 modes.push_back(modeAsString);
epoger@google.com310478e2013-04-03 18:00:39 +0000328 }
329 }
330
331 /**
epoger@google.com3a882dd2013-10-07 18:55:09 +0000332 * Returns true if failures on this test should be ignored.
333 */
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +0000334 bool ShouldIgnoreTest(const char *name) const {
335 for (int i = 0; i < fIgnorableTestNames.count(); i++) {
336 if (fIgnorableTestNames[i].equals(name)) {
epoger@google.com3a882dd2013-10-07 18:55:09 +0000337 return true;
338 }
339 }
340 return false;
341 }
342
343 /**
commit-bot@chromium.org85195482014-01-13 18:27:59 +0000344 * Calls RecordTestResults to record that we skipped a test.
345 *
346 * Depending on the backend, this may mean that we skipped a single rendermode, or all
347 * rendermodes; see http://skbug.com/1994 and https://codereview.chromium.org/129203002/
348 */
349 void RecordSkippedTest(const SkString& shortNamePlusConfig,
350 const char renderModeDescriptor [], Backend backend) {
351 if (kRaster_Backend == backend) {
352 // Skipping a test on kRaster_Backend means that we will skip ALL renderModes
353 // (as opposed to other backends, on which we only run the default renderMode).
354 //
355 // We cannot call RecordTestResults yet, because we won't know the full set of
356 // renderModes until we have run all tests.
357 fTestsSkippedOnAllRenderModes.push_back(shortNamePlusConfig);
358 } else {
359 this->RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
360 renderModeDescriptor);
361 }
362 }
363
364 /**
epoger@google.com310478e2013-04-03 18:00:39 +0000365 * Records the results of this test in fTestsRun and fFailedTests.
366 *
367 * We even record successes, and errors that we regard as
368 * "ignorable"; we can filter them out later.
369 */
epoger@google.com659c8c02013-05-21 15:45:45 +0000370 void RecordTestResults(const ErrorCombination& errorCombination,
371 const SkString& shortNamePlusConfig,
epoger@google.com310478e2013-04-03 18:00:39 +0000372 const char renderModeDescriptor []) {
373 // Things to do regardless of errorCombination.
374 fTestsRun++;
375 int renderModeCount = 0;
376 this->fRenderModesEncountered.find(renderModeDescriptor, &renderModeCount);
377 renderModeCount++;
378 this->fRenderModesEncountered.set(renderModeDescriptor, renderModeCount);
379
epoger@google.com6f6568b2013-03-22 17:29:46 +0000380 if (errorCombination.isEmpty()) {
epoger@google.com5f6a0072013-01-31 16:30:55 +0000381 return;
epoger@google.comeb066362013-03-08 09:39:36 +0000382 }
383
epoger@google.com310478e2013-04-03 18:00:39 +0000384 // Things to do only if there is some error condition.
epoger@google.com659c8c02013-05-21 15:45:45 +0000385 SkString fullName = shortNamePlusConfig;
epoger@google.comcaac3db2013-04-04 19:23:11 +0000386 fullName.append(renderModeDescriptor);
epoger@google.com310478e2013-04-03 18:00:39 +0000387 for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) {
388 ErrorType type = static_cast<ErrorType>(typeInt);
389 if (errorCombination.includes(type)) {
390 fFailedTests[type].push_back(fullName);
epoger@google.comf60494b2013-04-03 17:02:53 +0000391 }
epoger@google.comf60494b2013-04-03 17:02:53 +0000392 }
epoger@google.comf60494b2013-04-03 17:02:53 +0000393 }
394
epoger@google.com310478e2013-04-03 18:00:39 +0000395 /**
396 * Return the number of significant (non-ignorable) errors we have
397 * encountered so far.
398 */
399 int NumSignificantErrors() {
400 int significantErrors = 0;
401 for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) {
402 ErrorType type = static_cast<ErrorType>(typeInt);
epoger@google.com5079d2c2013-04-12 14:11:21 +0000403 if (!fIgnorableErrorTypes.includes(type)) {
epoger@google.com310478e2013-04-03 18:00:39 +0000404 significantErrors += fFailedTests[type].count();
405 }
406 }
407 return significantErrors;
408 }
409
410 /**
epoger@google.com51dbabe2013-04-10 15:24:53 +0000411 * Display the summary of results with this ErrorType.
412 *
413 * @param type which ErrorType
414 * @param verbose whether to be all verbose about it
epoger@google.com310478e2013-04-03 18:00:39 +0000415 */
epoger@google.com51dbabe2013-04-10 15:24:53 +0000416 void DisplayResultTypeSummary(ErrorType type, bool verbose) {
epoger@google.com5079d2c2013-04-12 14:11:21 +0000417 bool isIgnorableType = fIgnorableErrorTypes.includes(type);
epoger@google.com51dbabe2013-04-10 15:24:53 +0000418
419 SkString line;
420 if (isIgnorableType) {
421 line.append("[ ] ");
422 } else {
423 line.append("[*] ");
424 }
425
426 SkTArray<SkString> *failedTestsOfThisType = &fFailedTests[type];
427 int count = failedTestsOfThisType->count();
428 line.appendf("%d %s", count, getErrorTypeName(type));
429 if (!isIgnorableType || verbose) {
430 line.append(":");
431 for (int i = 0; i < count; ++i) {
432 line.append(" ");
433 line.append((*failedTestsOfThisType)[i]);
434 }
435 }
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000436 SkDebugf("%s\n", line.c_str());
epoger@google.com51dbabe2013-04-10 15:24:53 +0000437 }
438
439 /**
440 * List contents of fFailedTests to stdout.
441 *
442 * @param verbose whether to be all verbose about it
443 */
444 void ListErrors(bool verbose) {
epoger@google.com310478e2013-04-03 18:00:39 +0000445 // First, print a single summary line.
446 SkString summary;
447 summary.appendf("Ran %d tests:", fTestsRun);
448 for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) {
449 ErrorType type = static_cast<ErrorType>(typeInt);
450 summary.appendf(" %s=%d", getErrorTypeName(type), fFailedTests[type].count());
451 }
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000452 SkDebugf("%s\n", summary.c_str());
epoger@google.com310478e2013-04-03 18:00:39 +0000453
454 // Now, for each failure type, list the tests that failed that way.
455 for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) {
epoger@google.com51dbabe2013-04-10 15:24:53 +0000456 this->DisplayResultTypeSummary(static_cast<ErrorType>(typeInt), verbose);
epoger@google.com310478e2013-04-03 18:00:39 +0000457 }
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000458 SkDebugf("(results marked with [*] will cause nonzero return value)\n");
epoger@google.com310478e2013-04-03 18:00:39 +0000459 }
460
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000461 static ErrorCombination write_document(const SkString& path, SkStreamAsset* asset) {
epoger@google.com5f6a0072013-01-31 16:30:55 +0000462 SkFILEWStream stream(path.c_str());
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000463 if (!stream.writeStream(asset, asset->getLength())) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000464 SkDebugf("FAILED to write document: %s\n", path.c_str());
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000465 return ErrorCombination(kWritingReferenceImage_ErrorType);
466 }
467 return kEmpty_ErrorCombination;
epoger@google.com5f6a0072013-01-31 16:30:55 +0000468 }
469
epoger@google.com37269602013-01-19 04:21:27 +0000470 /**
epoger@google.com5f6a0072013-01-31 16:30:55 +0000471 * Prepare an SkBitmap to render a GM into.
472 *
473 * After you've rendered the GM into the SkBitmap, you must call
474 * complete_bitmap()!
475 *
476 * @todo thudson 22 April 2011 - could refactor this to take in
477 * a factory to generate the context, always call readPixels()
478 * (logically a noop for rasters, if wasted time), and thus collapse the
479 * GPU special case and also let this be used for SkPicture testing.
480 */
481 static void setup_bitmap(const ConfigData& gRec, SkISize& size,
482 SkBitmap* bitmap) {
reedddd014e2014-06-05 08:51:20 -0700483 bitmap->allocPixels(SkImageInfo::Make(size.width(), size.height(),
484 gRec.fColorType, kPremul_SkAlphaType));
epoger@google.com5f6a0072013-01-31 16:30:55 +0000485 bitmap->eraseColor(SK_ColorTRANSPARENT);
486 }
487
488 /**
489 * Any finalization steps we need to perform on the SkBitmap after
490 * we have rendered the GM into it.
epoger@google.com37269602013-01-19 04:21:27 +0000491 *
492 * It's too bad that we are throwing away alpha channel data
493 * we could otherwise be examining, but this had always been happening
494 * before... it was buried within the compare() method at
495 * https://code.google.com/p/skia/source/browse/trunk/gm/gmmain.cpp?r=7289#305 .
496 *
497 * Apparently we need this, at least for bitmaps that are either:
498 * (a) destined to be written out as PNG files, or
499 * (b) compared against bitmaps read in from PNG files
500 * for the reasons described just above the force_all_opaque() method.
501 *
502 * Neglecting to do this led to the difficult-to-diagnose
503 * http://code.google.com/p/skia/issues/detail?id=1079 ('gm generating
504 * spurious pixel_error messages as of r7258')
505 *
506 * TODO(epoger): Come up with a better solution that allows us to
507 * compare full pixel data, including alpha channel, while still being
508 * robust in the face of transformations to/from PNG files.
509 * Options include:
510 *
511 * 1. Continue to call force_all_opaque(), but ONLY for bitmaps that
512 * will be written to, or compared against, PNG files.
513 * PRO: Preserve/compare alpha channel info for the non-PNG cases
514 * (comparing different renderModes in-memory)
epoger@google.com908f5832013-04-12 02:23:55 +0000515 * CON: The bitmaps (and hash digests) for these non-PNG cases would be
epoger@google.com37269602013-01-19 04:21:27 +0000516 * different than those for the PNG-compared cases, and in the
517 * case of a failed renderMode comparison, how would we write the
518 * image to disk for examination?
519 *
epoger@google.com908f5832013-04-12 02:23:55 +0000520 * 2. Always compute image hash digests from PNG format (either
epoger@google.com37269602013-01-19 04:21:27 +0000521 * directly from the the bytes of a PNG file, or capturing the
522 * bytes we would have written to disk if we were writing the
523 * bitmap out as a PNG).
524 * PRO: I think this would allow us to never force opaque, and to
525 * the extent that alpha channel data can be preserved in a PNG
526 * file, we could observe it.
epoger@google.com908f5832013-04-12 02:23:55 +0000527 * CON: If we read a bitmap from disk, we need to take its hash digest
epoger@google.com37269602013-01-19 04:21:27 +0000528 * from the source PNG (we can't compute it from the bitmap we
529 * read out of the PNG, because we will have already premultiplied
530 * the alpha).
531 * CON: Seems wasteful to convert a bitmap to PNG format just to take
epoger@google.com908f5832013-04-12 02:23:55 +0000532 * its hash digest. (Although we're wasting lots of effort already
epoger@google.com37269602013-01-19 04:21:27 +0000533 * calling force_all_opaque().)
534 *
535 * 3. Make the alpha premultiply/unpremultiply routines 100% consistent,
536 * so we can transform images back and forth without fear of off-by-one
537 * errors.
538 * CON: Math is hard.
539 *
540 * 4. Perform a "close enough" comparison of bitmaps (+/- 1 bit in each
541 * channel), rather than demanding absolute equality.
epoger@google.com908f5832013-04-12 02:23:55 +0000542 * CON: Can't do this with hash digests.
epoger@google.com37269602013-01-19 04:21:27 +0000543 */
epoger@google.com5f6a0072013-01-31 16:30:55 +0000544 static void complete_bitmap(SkBitmap* bitmap) {
545 force_all_opaque(*bitmap);
epoger@google.comde961632012-10-26 18:56:36 +0000546 }
547
scroggo@google.com09fd4d22013-03-20 14:20:18 +0000548 static void installFilter(SkCanvas* canvas);
epoger@google.comde961632012-10-26 18:56:36 +0000549
reed@google.comaef73612012-11-16 13:41:45 +0000550 static void invokeGM(GM* gm, SkCanvas* canvas, bool isPDF, bool isDeferred) {
epoger@google.comde961632012-10-26 18:56:36 +0000551 SkAutoCanvasRestore acr(canvas, true);
552
553 if (!isPDF) {
554 canvas->concat(gm->getInitialTransform());
555 }
556 installFilter(canvas);
reed@google.comaef73612012-11-16 13:41:45 +0000557 gm->setCanvasIsDeferred(isDeferred);
epoger@google.comde961632012-10-26 18:56:36 +0000558 gm->draw(canvas);
559 canvas->setDrawFilter(NULL);
560 }
561
epoger@google.com6f6568b2013-03-22 17:29:46 +0000562 static ErrorCombination generate_image(GM* gm, const ConfigData& gRec,
bsalomon@google.com123ac1d2013-03-28 19:18:12 +0000563 GrSurface* gpuTarget,
epoger@google.com6f6568b2013-03-22 17:29:46 +0000564 SkBitmap* bitmap,
565 bool deferred) {
epoger@google.comde961632012-10-26 18:56:36 +0000566 SkISize size (gm->getISize());
567 setup_bitmap(gRec, size, bitmap);
commit-bot@chromium.org466f5f32014-05-27 21:30:37 +0000568 const SkImageInfo info = bitmap->info();
epoger@google.comde961632012-10-26 18:56:36 +0000569
reed@google.com11db6fa2014-02-04 15:30:57 +0000570 SkAutoTUnref<SkSurface> surface;
epoger@google.comde961632012-10-26 18:56:36 +0000571 SkAutoTUnref<SkCanvas> canvas;
572
573 if (gRec.fBackend == kRaster_Backend) {
reed@google.com11db6fa2014-02-04 15:30:57 +0000574 surface.reset(SkSurface::NewRasterDirect(info,
575 bitmap->getPixels(),
576 bitmap->rowBytes()));
epoger@google.comde961632012-10-26 18:56:36 +0000577 if (deferred) {
reed@google.com11db6fa2014-02-04 15:30:57 +0000578 canvas.reset(SkDeferredCanvas::Create(surface));
epoger@google.comde961632012-10-26 18:56:36 +0000579 } else {
reed@google.com11db6fa2014-02-04 15:30:57 +0000580 canvas.reset(SkRef(surface->getCanvas()));
epoger@google.comde961632012-10-26 18:56:36 +0000581 }
reed@google.comaef73612012-11-16 13:41:45 +0000582 invokeGM(gm, canvas, false, deferred);
epoger@google.comde961632012-10-26 18:56:36 +0000583 canvas->flush();
584 }
585#if SK_SUPPORT_GPU
586 else { // GPU
reed@google.com11db6fa2014-02-04 15:30:57 +0000587 surface.reset(SkSurface::NewRenderTargetDirect(gpuTarget->asRenderTarget()));
epoger@google.comde961632012-10-26 18:56:36 +0000588 if (deferred) {
reed@google.com11db6fa2014-02-04 15:30:57 +0000589 canvas.reset(SkDeferredCanvas::Create(surface));
epoger@google.comde961632012-10-26 18:56:36 +0000590 } else {
reed@google.com11db6fa2014-02-04 15:30:57 +0000591 canvas.reset(SkRef(surface->getCanvas()));
epoger@google.comde961632012-10-26 18:56:36 +0000592 }
reed@google.comaef73612012-11-16 13:41:45 +0000593 invokeGM(gm, canvas, false, deferred);
epoger@google.comde961632012-10-26 18:56:36 +0000594 // the device is as large as the current rendertarget, so
595 // we explicitly only readback the amount we expect (in
596 // size) overwrite our previous allocation
commit-bot@chromium.orga3264e52014-05-30 13:26:10 +0000597 bitmap->setInfo(SkImageInfo::MakeN32Premul(size.fWidth, size.fHeight));
epoger@google.comde961632012-10-26 18:56:36 +0000598 canvas->readPixels(bitmap, 0, 0);
599 }
600#endif
epoger@google.com5f6a0072013-01-31 16:30:55 +0000601 complete_bitmap(bitmap);
epoger@google.com6f6568b2013-03-22 17:29:46 +0000602 return kEmpty_ErrorCombination;
epoger@google.comde961632012-10-26 18:56:36 +0000603 }
604
605 static void generate_image_from_picture(GM* gm, const ConfigData& gRec,
junov@chromium.orgc938c482012-12-19 15:24:38 +0000606 SkPicture* pict, SkBitmap* bitmap,
robertphillips@google.com5a7d0292013-04-02 15:18:41 +0000607 SkScalar scale = SK_Scalar1,
608 bool tile = false) {
epoger@google.comde961632012-10-26 18:56:36 +0000609 SkISize size = gm->getISize();
610 setup_bitmap(gRec, size, bitmap);
robertphillips@google.com5a7d0292013-04-02 15:18:41 +0000611
612 if (tile) {
613 // Generate the result image by rendering to tiles and accumulating
614 // the results in 'bitmap'
615
skia.committer@gmail.com041e2db2013-04-03 07:01:14 +0000616 // This 16x16 tiling matches the settings applied to 'pict' in
robertphillips@google.com5a7d0292013-04-02 15:18:41 +0000617 // 'generate_new_picture'
618 SkISize tileSize = SkISize::Make(16, 16);
619
620 SkBitmap tileBM;
621 setup_bitmap(gRec, tileSize, &tileBM);
622 SkCanvas tileCanvas(tileBM);
623 installFilter(&tileCanvas);
624
625 SkCanvas bmpCanvas(*bitmap);
626 SkPaint bmpPaint;
627 bmpPaint.setXfermodeMode(SkXfermode::kSrc_Mode);
628
629 for (int yTile = 0; yTile < (size.height()+15)/16; ++yTile) {
630 for (int xTile = 0; xTile < (size.width()+15)/16; ++xTile) {
631 int saveCount = tileCanvas.save();
632 SkMatrix mat(tileCanvas.getTotalMatrix());
skia.committer@gmail.com041e2db2013-04-03 07:01:14 +0000633 mat.postTranslate(SkIntToScalar(-xTile*tileSize.width()),
robertphillips@google.com5a7d0292013-04-02 15:18:41 +0000634 SkIntToScalar(-yTile*tileSize.height()));
635 tileCanvas.setMatrix(mat);
636 pict->draw(&tileCanvas);
637 tileCanvas.flush();
638 tileCanvas.restoreToCount(saveCount);
skia.committer@gmail.com041e2db2013-04-03 07:01:14 +0000639 bmpCanvas.drawBitmap(tileBM,
640 SkIntToScalar(xTile * tileSize.width()),
robertphillips@google.com5a7d0292013-04-02 15:18:41 +0000641 SkIntToScalar(yTile * tileSize.height()),
642 &bmpPaint);
643 }
644 }
645 } else {
646 SkCanvas canvas(*bitmap);
647 installFilter(&canvas);
648 canvas.scale(scale, scale);
robertphillips9b14f262014-06-04 05:40:44 -0700649 canvas.drawPicture(pict);
robertphillips@google.com5a7d0292013-04-02 15:18:41 +0000650 complete_bitmap(bitmap);
651 }
epoger@google.comde961632012-10-26 18:56:36 +0000652 }
653
commit-bot@chromium.org5e009892013-10-14 13:42:12 +0000654 static bool generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) {
epoger@google.comde961632012-10-26 18:56:36 +0000655#ifdef SK_SUPPORT_PDF
656 SkMatrix initialTransform = gm->getInitialTransform();
commit-bot@chromium.org5e009892013-10-14 13:42:12 +0000657 if (FLAGS_useDocumentInsteadOfDevice) {
658 SkISize pageISize = gm->getISize();
edisonn@google.com73a7ea32013-11-11 20:55:15 +0000659 SkAutoTUnref<SkDocument> pdfDoc(
660 SkDocument::CreatePDF(&pdf, NULL,
661 encode_to_dct_data,
662 SkIntToScalar(FLAGS_pdfRasterDpi)));
commit-bot@chromium.org5e009892013-10-14 13:42:12 +0000663
664 if (!pdfDoc.get()) {
665 return false;
666 }
667
668 SkCanvas* canvas = NULL;
669 canvas = pdfDoc->beginPage(SkIntToScalar(pageISize.width()),
670 SkIntToScalar(pageISize.height()));
671 canvas->concat(initialTransform);
672
673 invokeGM(gm, canvas, true, false);
674
675 return pdfDoc->close();
epoger@google.comde961632012-10-26 18:56:36 +0000676 } else {
commit-bot@chromium.org5e009892013-10-14 13:42:12 +0000677 SkISize pageSize = gm->getISize();
678 SkPDFDevice* dev = NULL;
679 if (initialTransform.isIdentity()) {
680 dev = new SkPDFDevice(pageSize, pageSize, initialTransform);
681 } else {
682 SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()),
683 SkIntToScalar(pageSize.height()));
684 initialTransform.mapRect(&content);
685 content.intersect(0, 0, SkIntToScalar(pageSize.width()),
686 SkIntToScalar(pageSize.height()));
687 SkISize contentSize =
688 SkISize::Make(SkScalarRoundToInt(content.width()),
689 SkScalarRoundToInt(content.height()));
690 dev = new SkPDFDevice(pageSize, contentSize, initialTransform);
691 }
692 dev->setDCTEncoder(encode_to_dct_data);
edisonn@google.com73a7ea32013-11-11 20:55:15 +0000693 dev->setRasterDpi(SkIntToScalar(FLAGS_pdfRasterDpi));
commit-bot@chromium.org5e009892013-10-14 13:42:12 +0000694 SkAutoUnref aur(dev);
695 SkCanvas c(dev);
696 invokeGM(gm, &c, true, false);
697 SkPDFDocument doc;
698 doc.appendPage(dev);
699 doc.emitPDF(&pdf);
epoger@google.comde961632012-10-26 18:56:36 +0000700 }
commit-bot@chromium.org5e009892013-10-14 13:42:12 +0000701#endif // SK_SUPPORT_PDF
702 return true; // Do not report failure if pdf is not supported.
epoger@google.comde961632012-10-26 18:56:36 +0000703 }
704
705 static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) {
706#ifdef SK_SUPPORT_XPS
707 SkISize size = gm->getISize();
708
709 SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()),
710 SkIntToScalar(size.height()));
711 static const SkScalar inchesPerMeter = SkScalarDiv(10000, 254);
712 static const SkScalar upm = 72 * inchesPerMeter;
713 SkVector unitsPerMeter = SkPoint::Make(upm, upm);
714 static const SkScalar ppm = 200 * inchesPerMeter;
715 SkVector pixelsPerMeter = SkPoint::Make(ppm, ppm);
716
717 SkXPSDevice* dev = new SkXPSDevice();
718 SkAutoUnref aur(dev);
719
720 SkCanvas c(dev);
721 dev->beginPortfolio(&xps);
722 dev->beginSheet(unitsPerMeter, pixelsPerMeter, trimSize);
reed@google.comaef73612012-11-16 13:41:45 +0000723 invokeGM(gm, &c, false, false);
epoger@google.comde961632012-10-26 18:56:36 +0000724 dev->endSheet();
725 dev->endPortfolio();
726
727#endif
728 }
729
epoger@google.com37269602013-01-19 04:21:27 +0000730 /**
epoger@google.com84a18022013-02-01 20:39:15 +0000731 * Log more detail about the mistmatch between expectedBitmap and
732 * actualBitmap.
733 */
734 void report_bitmap_diffs(const SkBitmap& expectedBitmap, const SkBitmap& actualBitmap,
735 const char *testName) {
736 const int expectedWidth = expectedBitmap.width();
737 const int expectedHeight = expectedBitmap.height();
738 const int width = actualBitmap.width();
739 const int height = actualBitmap.height();
740 if ((expectedWidth != width) || (expectedHeight != height)) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000741 SkDebugf("---- %s: dimension mismatch -- expected [%d %d], actual [%d %d]\n",
742 testName, expectedWidth, expectedHeight, width, height);
epoger@google.com84a18022013-02-01 20:39:15 +0000743 return;
744 }
745
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000746 if ((kN32_SkColorType != expectedBitmap.colorType()) ||
747 (kN32_SkColorType != actualBitmap.colorType())) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000748 SkDebugf("---- %s: not computing max per-channel pixel mismatch because non-8888\n",
749 testName);
epoger@google.com84a18022013-02-01 20:39:15 +0000750 return;
751 }
752
753 SkAutoLockPixels alp0(expectedBitmap);
754 SkAutoLockPixels alp1(actualBitmap);
755 int errR = 0;
756 int errG = 0;
757 int errB = 0;
758 int errA = 0;
759 int differingPixels = 0;
760
761 for (int y = 0; y < height; ++y) {
762 const SkPMColor* expectedPixelPtr = expectedBitmap.getAddr32(0, y);
763 const SkPMColor* actualPixelPtr = actualBitmap.getAddr32(0, y);
764 for (int x = 0; x < width; ++x) {
765 SkPMColor expectedPixel = *expectedPixelPtr++;
766 SkPMColor actualPixel = *actualPixelPtr++;
767 if (expectedPixel != actualPixel) {
768 differingPixels++;
769 errR = SkMax32(errR, SkAbs32((int)SkGetPackedR32(expectedPixel) -
770 (int)SkGetPackedR32(actualPixel)));
771 errG = SkMax32(errG, SkAbs32((int)SkGetPackedG32(expectedPixel) -
772 (int)SkGetPackedG32(actualPixel)));
773 errB = SkMax32(errB, SkAbs32((int)SkGetPackedB32(expectedPixel) -
774 (int)SkGetPackedB32(actualPixel)));
775 errA = SkMax32(errA, SkAbs32((int)SkGetPackedA32(expectedPixel) -
776 (int)SkGetPackedA32(actualPixel)));
777 }
778 }
779 }
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000780 SkDebugf("---- %s: %d (of %d) differing pixels, "
781 "max per-channel mismatch R=%d G=%d B=%d A=%d\n",
782 testName, differingPixels, width*height, errR, errG, errB, errA);
epoger@google.com84a18022013-02-01 20:39:15 +0000783 }
784
785 /**
epoger@google.com908f5832013-04-12 02:23:55 +0000786 * Compares actual hash digest to expectations, returning the set of errors
epoger@google.com6f6568b2013-03-22 17:29:46 +0000787 * (if any) that we saw along the way.
epoger@google.com37269602013-01-19 04:21:27 +0000788 *
789 * If fMismatchPath has been set, and there are pixel diffs, then the
790 * actual bitmap will be written out to a file within fMismatchPath.
epoger@google.com5f995452013-06-21 18:16:47 +0000791 * And similarly for fMissingExpectationsPath...
epoger@google.com37269602013-01-19 04:21:27 +0000792 *
793 * @param expectations what expectations to compare actualBitmap against
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000794 * @param actualBitmapAndDigest the SkBitmap we actually generated, and its GmResultDigest
epoger@google.com659c8c02013-05-21 15:45:45 +0000795 * @param shortName name of test, e.g. "selftest1"
796 * @param configName name of config, e.g. "8888"
epoger@google.com37269602013-01-19 04:21:27 +0000797 * @param renderModeDescriptor e.g., "-rtree", "-deferred"
798 * @param addToJsonSummary whether to add these results (both actual and
epoger@google.comcaac3db2013-04-04 19:23:11 +0000799 * expected) to the JSON summary. Regardless of this setting, if
800 * we find an image mismatch in this test, we will write these
801 * results to the JSON summary. (This is so that we will always
802 * report errors across rendering modes, such as pipe vs tiled.
803 * See https://codereview.chromium.org/13650002/ )
epoger@google.com37269602013-01-19 04:21:27 +0000804 */
epoger@google.com6f6568b2013-03-22 17:29:46 +0000805 ErrorCombination compare_to_expectations(Expectations expectations,
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000806 const BitmapAndDigest& actualBitmapAndDigest,
epoger@google.com659c8c02013-05-21 15:45:45 +0000807 const char *shortName, const char *configName,
808 const char *renderModeDescriptor,
epoger@google.comcaac3db2013-04-04 19:23:11 +0000809 bool addToJsonSummary) {
epoger@google.com6f6568b2013-03-22 17:29:46 +0000810 ErrorCombination errors;
epoger@google.com659c8c02013-05-21 15:45:45 +0000811 SkString shortNamePlusConfig = make_shortname_plus_config(shortName, configName);
812 SkString completeNameString(shortNamePlusConfig);
epoger@google.com37269602013-01-19 04:21:27 +0000813 completeNameString.append(renderModeDescriptor);
epoger@google.comce057fe2013-05-14 15:17:46 +0000814 completeNameString.append(".");
815 completeNameString.append(kPNG_FileExtension);
epoger@google.com37269602013-01-19 04:21:27 +0000816 const char* completeName = completeNameString.c_str();
epoger@google.comee8a8e32012-12-18 19:13:49 +0000817
epoger@google.com37269602013-01-19 04:21:27 +0000818 if (expectations.empty()) {
epoger@google.com6f6568b2013-03-22 17:29:46 +0000819 errors.add(kMissingExpectations_ErrorType);
epoger@google.com5f995452013-06-21 18:16:47 +0000820
821 // Write out the "actuals" for any tests without expectations, if we have
822 // been directed to do so.
823 if (fMissingExpectationsPath) {
824 SkString path = make_bitmap_filename(fMissingExpectationsPath, shortName,
825 configName, renderModeDescriptor,
826 actualBitmapAndDigest.fDigest);
827 write_bitmap(path, actualBitmapAndDigest.fBitmap);
828 }
829
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000830 } else if (!expectations.match(actualBitmapAndDigest.fDigest)) {
epoger@google.comcaac3db2013-04-04 19:23:11 +0000831 addToJsonSummary = true;
832 // The error mode we record depends on whether this was running
833 // in a non-standard renderMode.
834 if ('\0' == *renderModeDescriptor) {
835 errors.add(kExpectationsMismatch_ErrorType);
836 } else {
837 errors.add(kRenderModeMismatch_ErrorType);
838 }
epoger@google.com84a18022013-02-01 20:39:15 +0000839
840 // Write out the "actuals" for any mismatches, if we have
841 // been directed to do so.
epoger@google.com37269602013-01-19 04:21:27 +0000842 if (fMismatchPath) {
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000843 SkString path = make_bitmap_filename(fMismatchPath, shortName, configName,
844 renderModeDescriptor,
845 actualBitmapAndDigest.fDigest);
846 write_bitmap(path, actualBitmapAndDigest.fBitmap);
epoger@google.com37269602013-01-19 04:21:27 +0000847 }
epoger@google.com84a18022013-02-01 20:39:15 +0000848
849 // If we have access to a single expected bitmap, log more
850 // detail about the mismatch.
851 const SkBitmap *expectedBitmapPtr = expectations.asBitmap();
852 if (NULL != expectedBitmapPtr) {
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000853 report_bitmap_diffs(*expectedBitmapPtr, actualBitmapAndDigest.fBitmap,
854 completeName);
epoger@google.com84a18022013-02-01 20:39:15 +0000855 }
epoger@google.coma243b222013-01-17 17:54:28 +0000856 }
epoger@google.coma243b222013-01-17 17:54:28 +0000857
epoger@google.com37269602013-01-19 04:21:27 +0000858 if (addToJsonSummary) {
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000859 add_actual_results_to_json_summary(completeName, actualBitmapAndDigest.fDigest, errors,
epoger@google.com37269602013-01-19 04:21:27 +0000860 expectations.ignoreFailure());
861 add_expected_results_to_json_summary(completeName, expectations);
862 }
epoger@google.coma243b222013-01-17 17:54:28 +0000863
epoger@google.com6f6568b2013-03-22 17:29:46 +0000864 return errors;
epoger@google.com06b8a192013-01-15 19:10:16 +0000865 }
866
epoger@google.com37269602013-01-19 04:21:27 +0000867 /**
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000868 * Add this result to the appropriate JSON collection of actual results (but just ONE),
epoger@google.com76c913d2013-04-26 15:06:44 +0000869 * depending on errors encountered.
epoger@google.com37269602013-01-19 04:21:27 +0000870 */
871 void add_actual_results_to_json_summary(const char testName[],
epoger@google.comd4993ff2013-05-24 14:33:28 +0000872 const GmResultDigest &actualResultDigest,
epoger@google.com76c913d2013-04-26 15:06:44 +0000873 ErrorCombination errors,
epoger@google.com37269602013-01-19 04:21:27 +0000874 bool ignoreFailure) {
epoger@google.comd4993ff2013-05-24 14:33:28 +0000875 Json::Value jsonActualResults = actualResultDigest.asJsonTypeValuePair();
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000876 Json::Value *resultCollection = NULL;
877
epoger@google.com76c913d2013-04-26 15:06:44 +0000878 if (errors.isEmpty()) {
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000879 resultCollection = &this->fJsonActualResults_Succeeded;
880 } else if (errors.includes(kRenderModeMismatch_ErrorType)) {
881 resultCollection = &this->fJsonActualResults_Failed;
882 } else if (errors.includes(kExpectationsMismatch_ErrorType)) {
epoger@google.com37269602013-01-19 04:21:27 +0000883 if (ignoreFailure) {
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000884 resultCollection = &this->fJsonActualResults_FailureIgnored;
epoger@google.com37269602013-01-19 04:21:27 +0000885 } else {
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000886 resultCollection = &this->fJsonActualResults_Failed;
epoger@google.com37269602013-01-19 04:21:27 +0000887 }
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000888 } else if (errors.includes(kMissingExpectations_ErrorType)) {
889 // TODO: What about the case where there IS an expected
890 // image hash digest, but that gm test doesn't actually
891 // run? For now, those cases will always be ignored,
892 // because gm only looks at expectations that correspond
893 // to gm tests that were actually run.
894 //
895 // Once we have the ability to express expectations as a
896 // JSON file, we should fix this (and add a test case for
897 // which an expectation is given but the test is never
898 // run).
899 resultCollection = &this->fJsonActualResults_NoComparison;
900 }
901
902 // If none of the above cases match, we don't add it to ANY tally of actual results.
903 if (resultCollection) {
904 (*resultCollection)[testName] = jsonActualResults;
epoger@google.com37269602013-01-19 04:21:27 +0000905 }
906 }
907
908 /**
909 * Add this test to the JSON collection of expected results.
910 */
911 void add_expected_results_to_json_summary(const char testName[],
912 Expectations expectations) {
epoger@google.com76c913d2013-04-26 15:06:44 +0000913 this->fJsonExpectedResults[testName] = expectations.asJsonValue();
epoger@google.com37269602013-01-19 04:21:27 +0000914 }
915
916 /**
917 * Compare actualBitmap to expectations stored in this->fExpectationsSource.
918 *
919 * @param gm which test generated the actualBitmap
920 * @param gRec
vandebo@chromium.org8fc37662013-08-21 18:04:09 +0000921 * @param configName The config name to look for in the expectation file.
epoger@google.come33e1372013-07-08 19:13:33 +0000922 * @param actualBitmapAndDigest ptr to bitmap generated by this run, or NULL
923 * if we don't have a usable bitmap representation
epoger@google.com37269602013-01-19 04:21:27 +0000924 */
epoger@google.com6f6568b2013-03-22 17:29:46 +0000925 ErrorCombination compare_test_results_to_stored_expectations(
vandebo@chromium.org8fc37662013-08-21 18:04:09 +0000926 GM* gm, const ConfigData& gRec, const char* configName,
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000927 const BitmapAndDigest* actualBitmapAndDigest) {
epoger@google.com659c8c02013-05-21 15:45:45 +0000928 ErrorCombination errors;
epoger@google.come33e1372013-07-08 19:13:33 +0000929
930 if (NULL == actualBitmapAndDigest) {
931 // Note that we intentionally skipped validating the results for
932 // this test, because we don't know how to generate an SkBitmap
933 // version of the output.
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000934 errors.add(ErrorCombination(kIntentionallySkipped_ErrorType));
epoger@google.comc824c832013-07-12 15:52:59 +0000935 } else if (!(gRec.fFlags & kWrite_ConfigFlag)) {
936 // We don't record the results for this test or compare them
937 // against any expectations, because the output image isn't
938 // meaningful.
939 // See https://code.google.com/p/skia/issues/detail?id=1410 ('some
940 // GM result images not available for download from Google Storage')
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000941 errors.add(ErrorCombination(kIntentionallySkipped_ErrorType));
epoger@google.come33e1372013-07-08 19:13:33 +0000942 } else {
943 ExpectationsSource *expectationsSource = this->fExpectationsSource.get();
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000944 SkString nameWithExtension = make_shortname_plus_config(gm->getName(), configName);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000945 nameWithExtension.append(".");
946 nameWithExtension.append(kPNG_FileExtension);
947
epoger@google.come33e1372013-07-08 19:13:33 +0000948 if (expectationsSource && (gRec.fFlags & kRead_ConfigFlag)) {
949 /*
950 * Get the expected results for this test, as one or more allowed
951 * hash digests. The current implementation of expectationsSource
952 * get this by computing the hash digest of a single PNG file on disk.
953 *
954 * TODO(epoger): This relies on the fact that
955 * force_all_opaque() was called on the bitmap before it
956 * was written to disk as a PNG in the first place. If
957 * not, the hash digest returned here may not match the
958 * hash digest of actualBitmap, which *has* been run through
959 * force_all_opaque().
960 * See comments above complete_bitmap() for more detail.
961 */
962 Expectations expectations = expectationsSource->get(nameWithExtension.c_str());
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000963 if (this->ShouldIgnoreTest(gm->getName())) {
epoger@google.comdefc4872013-09-19 06:18:27 +0000964 expectations.setIgnoreFailure(true);
965 }
epoger@google.come33e1372013-07-08 19:13:33 +0000966 errors.add(compare_to_expectations(expectations, *actualBitmapAndDigest,
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000967 gm->getName(), configName, "", true));
epoger@google.come33e1372013-07-08 19:13:33 +0000968 } else {
969 // If we are running without expectations, we still want to
970 // record the actual results.
971 add_actual_results_to_json_summary(nameWithExtension.c_str(),
972 actualBitmapAndDigest->fDigest,
973 ErrorCombination(kMissingExpectations_ErrorType),
974 false);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000975 errors.add(ErrorCombination(kMissingExpectations_ErrorType));
epoger@google.come33e1372013-07-08 19:13:33 +0000976 }
epoger@google.com9ef89ce2013-01-18 21:45:42 +0000977 }
epoger@google.com6f6568b2013-03-22 17:29:46 +0000978 return errors;
epoger@google.coma243b222013-01-17 17:54:28 +0000979 }
980
epoger@google.com37269602013-01-19 04:21:27 +0000981 /**
982 * Compare actualBitmap to referenceBitmap.
983 *
epoger@google.com659c8c02013-05-21 15:45:45 +0000984 * @param shortName test name, e.g. "selftest1"
985 * @param configName configuration name, e.g. "8888"
epoger@google.com37269602013-01-19 04:21:27 +0000986 * @param renderModeDescriptor
987 * @param actualBitmap actual bitmap generated by this run
988 * @param referenceBitmap bitmap we expected to be generated
989 */
epoger@google.com6f6568b2013-03-22 17:29:46 +0000990 ErrorCombination compare_test_results_to_reference_bitmap(
epoger@google.com659c8c02013-05-21 15:45:45 +0000991 const char *shortName, const char *configName, const char *renderModeDescriptor,
epoger@google.com37269602013-01-19 04:21:27 +0000992 SkBitmap& actualBitmap, const SkBitmap* referenceBitmap) {
993
994 SkASSERT(referenceBitmap);
epoger@google.com84a18022013-02-01 20:39:15 +0000995 Expectations expectations(*referenceBitmap);
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000996 BitmapAndDigest actualBitmapAndDigest(actualBitmap);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000997
998 // TODO: Eliminate RecordTestResults from here.
999 // Results recording code for the test_drawing path has been refactored so that
1000 // RecordTestResults is only called once, at the topmost level. However, the
1001 // other paths have not yet been refactored, and RecordTestResults has been added
1002 // here to maintain proper behavior for calls not coming from the test_drawing path.
1003 ErrorCombination errors;
1004 errors.add(compare_to_expectations(expectations, actualBitmapAndDigest, shortName,
1005 configName, renderModeDescriptor, false));
1006 SkString shortNamePlusConfig = make_shortname_plus_config(shortName, configName);
1007 RecordTestResults(errors, shortNamePlusConfig, renderModeDescriptor);
1008
1009 return errors;
epoger@google.com37269602013-01-19 04:21:27 +00001010 }
1011
junov@chromium.org20bd04e2013-01-16 18:43:36 +00001012 static SkPicture* generate_new_picture(GM* gm, BbhType bbhType, uint32_t recordFlags,
1013 SkScalar scale = SK_Scalar1) {
junov@chromium.org706ff2f2012-12-19 15:55:40 +00001014 int width = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().width()), scale));
1015 int height = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().height()), scale));
skia.committer@gmail.comd8b27992012-12-20 02:01:41 +00001016
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +00001017 SkAutoTDelete<SkBBHFactory> factory;
junov@chromium.org3cb834b2012-12-13 16:39:53 +00001018 if (kTileGrid_BbhType == bbhType) {
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +00001019 SkTileGridFactory::TileGridInfo info;
junov@chromium.org29b19e52013-02-27 18:35:16 +00001020 info.fMargin.setEmpty();
1021 info.fOffset.setZero();
1022 info.fTileInterval.set(16, 16);
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +00001023 factory.reset(SkNEW_ARGS(SkTileGridFactory, (info)));
commit-bot@chromium.orgd393b172014-04-16 16:02:10 +00001024 } else if (kQuadTree_BbhType == bbhType) {
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +00001025 factory.reset(SkNEW(SkQuadTreeFactory));
commit-bot@chromium.orgd393b172014-04-16 16:02:10 +00001026 } else if (kRTree_BbhType == bbhType) {
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +00001027 factory.reset(SkNEW(SkRTreeFactory));
junov@chromium.org20bd04e2013-01-16 18:43:36 +00001028 }
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +00001029 SkPictureRecorder recorder;
1030 SkCanvas* cv = recorder.beginRecording(width, height, factory.get(), recordFlags);
junov@chromium.orgc938c482012-12-19 15:24:38 +00001031 cv->scale(scale, scale);
reed@google.comaef73612012-11-16 13:41:45 +00001032 invokeGM(gm, cv, false, false);
robertphillips@google.com84b18c72014-04-13 19:09:42 +00001033 return recorder.endRecording();
epoger@google.comde961632012-10-26 18:56:36 +00001034 }
1035
1036 static SkPicture* stream_to_new_picture(const SkPicture& src) {
epoger@google.comde961632012-10-26 18:56:36 +00001037 SkDynamicMemoryWStream storage;
reed@google.com672588b2014-01-08 15:42:01 +00001038 src.serialize(&storage, NULL);
bungeman@google.comc29f3d82013-07-19 22:32:11 +00001039 SkAutoTUnref<SkStreamAsset> pictReadback(storage.detachAsStream());
commit-bot@chromium.org805df1a2013-08-16 19:18:12 +00001040 SkPicture* retval = SkPicture::CreateFromStream(pictReadback,
1041 &SkImageDecoder::DecodeMemory);
epoger@google.comde961632012-10-26 18:56:36 +00001042 return retval;
1043 }
1044
1045 // Test: draw into a bitmap or pdf.
epoger@google.com15655b22013-01-08 18:47:31 +00001046 // Depending on flags, possibly compare to an expected image.
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001047 // If writePath is not NULL, also write images (or documents) to the specified path.
1048 ErrorCombination test_drawing(GM* gm, const ConfigData& gRec,
1049 const SkTDArray<const PDFRasterizerData*> &pdfRasterizers,
epoger@google.com6f6568b2013-03-22 17:29:46 +00001050 const char writePath [],
bsalomon@google.com123ac1d2013-03-28 19:18:12 +00001051 GrSurface* gpuTarget,
epoger@google.com6f6568b2013-03-22 17:29:46 +00001052 SkBitmap* bitmap) {
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001053 ErrorCombination errors;
epoger@google.comde961632012-10-26 18:56:36 +00001054 SkDynamicMemoryWStream document;
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001055 SkString path;
epoger@google.comde961632012-10-26 18:56:36 +00001056
1057 if (gRec.fBackend == kRaster_Backend ||
1058 gRec.fBackend == kGPU_Backend) {
1059 // Early exit if we can't generate the image.
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001060 errors.add(generate_image(gm, gRec, gpuTarget, bitmap, false));
epoger@google.com6f6568b2013-03-22 17:29:46 +00001061 if (!errors.isEmpty()) {
epoger@google.com37269602013-01-19 04:21:27 +00001062 // TODO: Add a test to exercise what the stdout and
1063 // JSON look like if we get an "early error" while
1064 // trying to generate the image.
epoger@google.comde961632012-10-26 18:56:36 +00001065 return errors;
1066 }
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001067 BitmapAndDigest bitmapAndDigest(*bitmap);
1068 errors.add(compare_test_results_to_stored_expectations(
vandebo@chromium.org8fc37662013-08-21 18:04:09 +00001069 gm, gRec, gRec.fName, &bitmapAndDigest));
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001070
1071 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001072 path = make_bitmap_filename(writePath, gm->getName(), gRec.fName,
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001073 "", bitmapAndDigest.fDigest);
1074 errors.add(write_bitmap(path, bitmapAndDigest.fBitmap));
1075 }
epoger@google.comde961632012-10-26 18:56:36 +00001076 } else if (gRec.fBackend == kPDF_Backend) {
commit-bot@chromium.org5e009892013-10-14 13:42:12 +00001077 if (!generate_pdf(gm, document)) {
1078 errors.add(kGeneratePdfFailed_ErrorType);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001079 } else {
commit-bot@chromium.org5e009892013-10-14 13:42:12 +00001080 SkAutoTUnref<SkStreamAsset> documentStream(document.detachAsStream());
1081 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001082 path = make_filename(writePath, gm->getName(), gRec.fName, "", "pdf");
commit-bot@chromium.org5e009892013-10-14 13:42:12 +00001083 errors.add(write_document(path, documentStream));
1084 }
1085
1086 if (!(gm->getFlags() & GM::kSkipPDFRasterization_Flag)) {
1087 for (int i = 0; i < pdfRasterizers.count(); i++) {
1088 SkBitmap pdfBitmap;
vandebo@chromium.org969967e2013-12-09 23:22:15 +00001089 documentStream->rewind();
commit-bot@chromium.org5e009892013-10-14 13:42:12 +00001090 bool success = (*pdfRasterizers[i]->fRasterizerFunction)(
1091 documentStream.get(), &pdfBitmap);
1092 if (!success) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00001093 SkDebugf("FAILED to render PDF for %s using renderer %s\n",
1094 gm->getName(),
1095 pdfRasterizers[i]->fName);
commit-bot@chromium.org5e009892013-10-14 13:42:12 +00001096 continue;
1097 }
1098
1099 SkString configName(gRec.fName);
1100 configName.append("-");
1101 configName.append(pdfRasterizers[i]->fName);
1102
1103 BitmapAndDigest bitmapAndDigest(pdfBitmap);
1104 errors.add(compare_test_results_to_stored_expectations(
1105 gm, gRec, configName.c_str(), &bitmapAndDigest));
1106
1107 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001108 path = make_bitmap_filename(writePath, gm->getName(),
commit-bot@chromium.org5e009892013-10-14 13:42:12 +00001109 configName.c_str(),
1110 "", bitmapAndDigest.fDigest);
1111 errors.add(write_bitmap(path, bitmapAndDigest.fBitmap));
1112 }
1113 }
1114 } else {
1115 errors.add(kIntentionallySkipped_ErrorType);
1116 }
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001117 }
epoger@google.comde961632012-10-26 18:56:36 +00001118 } else if (gRec.fBackend == kXPS_Backend) {
1119 generate_xps(gm, document);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001120 SkAutoTUnref<SkStreamAsset> documentStream(document.detachAsStream());
epoger@google.come33e1372013-07-08 19:13:33 +00001121
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001122 errors.add(compare_test_results_to_stored_expectations(
vandebo@chromium.org8fc37662013-08-21 18:04:09 +00001123 gm, gRec, gRec.fName, NULL));
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001124
1125 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001126 path = make_filename(writePath, gm->getName(), gRec.fName, "", "xps");
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001127 errors.add(write_document(path, documentStream));
1128 }
epoger@google.come33e1372013-07-08 19:13:33 +00001129 } else {
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001130 SkASSERT(false);
epoger@google.come33e1372013-07-08 19:13:33 +00001131 }
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001132 return errors;
epoger@google.comde961632012-10-26 18:56:36 +00001133 }
1134
epoger@google.com6f6568b2013-03-22 17:29:46 +00001135 ErrorCombination test_deferred_drawing(GM* gm,
1136 const ConfigData& gRec,
1137 const SkBitmap& referenceBitmap,
bsalomon@google.com123ac1d2013-03-28 19:18:12 +00001138 GrSurface* gpuTarget) {
epoger@google.comde961632012-10-26 18:56:36 +00001139 if (gRec.fBackend == kRaster_Backend ||
1140 gRec.fBackend == kGPU_Backend) {
epoger@google.comc8263e72013-04-10 12:17:34 +00001141 const char renderModeDescriptor[] = "-deferred";
epoger@google.comde961632012-10-26 18:56:36 +00001142 SkBitmap bitmap;
1143 // Early exit if we can't generate the image, but this is
1144 // expected in some cases, so don't report a test failure.
bsalomon@google.com123ac1d2013-03-28 19:18:12 +00001145 ErrorCombination errors = generate_image(gm, gRec, gpuTarget, &bitmap, true);
epoger@google.com6f6568b2013-03-22 17:29:46 +00001146 // TODO(epoger): This logic is the opposite of what is
1147 // described above... if we succeeded in generating the
1148 // -deferred image, we exit early! We should fix this
1149 // ASAP, because it is hiding -deferred errors... but for
1150 // now, I'm leaving the logic as it is so that the
1151 // refactoring change
1152 // https://codereview.chromium.org/12992003/ is unblocked.
1153 //
1154 // Filed as https://code.google.com/p/skia/issues/detail?id=1180
1155 // ('image-surface gm test is failing in "deferred" mode,
1156 // and gm is not reporting the failure')
1157 if (errors.isEmpty()) {
epoger@google.com310478e2013-04-03 18:00:39 +00001158 // TODO(epoger): Report this as a new ErrorType,
1159 // something like kImageGeneration_ErrorType?
epoger@google.com6f6568b2013-03-22 17:29:46 +00001160 return kEmpty_ErrorCombination;
epoger@google.comde961632012-10-26 18:56:36 +00001161 }
epoger@google.com37269602013-01-19 04:21:27 +00001162 return compare_test_results_to_reference_bitmap(
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001163 gm->getName(), gRec.fName, renderModeDescriptor, bitmap, &referenceBitmap);
epoger@google.comde961632012-10-26 18:56:36 +00001164 }
epoger@google.com6f6568b2013-03-22 17:29:46 +00001165 return kEmpty_ErrorCombination;
epoger@google.comde961632012-10-26 18:56:36 +00001166 }
1167
epoger@google.comcaac3db2013-04-04 19:23:11 +00001168 ErrorCombination test_pipe_playback(GM* gm, const ConfigData& gRec,
1169 const SkBitmap& referenceBitmap, bool simulateFailure) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001170 const SkString shortNamePlusConfig = make_shortname_plus_config(gm->getName(),
epoger@google.com659c8c02013-05-21 15:45:45 +00001171 gRec.fName);
epoger@google.com6f6568b2013-03-22 17:29:46 +00001172 ErrorCombination errors;
epoger@google.comde961632012-10-26 18:56:36 +00001173 for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) {
epoger@google.comc8263e72013-04-10 12:17:34 +00001174 SkString renderModeDescriptor("-pipe");
1175 renderModeDescriptor.append(gPipeWritingFlagCombos[i].name);
1176
commit-bot@chromium.org805df1a2013-08-16 19:18:12 +00001177 if (gm->getFlags() & GM::kSkipPipe_Flag
1178 || (gPipeWritingFlagCombos[i].flags == SkGPipeWriter::kCrossProcess_Flag
1179 && gm->getFlags() & GM::kSkipPipeCrossProcess_Flag)) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001180 RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
epoger@google.comc8263e72013-04-10 12:17:34 +00001181 renderModeDescriptor.c_str());
1182 errors.add(kIntentionallySkipped_ErrorType);
1183 } else {
1184 SkBitmap bitmap;
1185 SkISize size = gm->getISize();
1186 setup_bitmap(gRec, size, &bitmap);
1187 SkCanvas canvas(bitmap);
1188 installFilter(&canvas);
scroggo@google.com74b7ffd2013-04-30 02:32:41 +00001189 // Pass a decoding function so the factory GM (which has an SkBitmap
1190 // with encoded data) will not fail playback.
1191 PipeController pipeController(&canvas, &SkImageDecoder::DecodeMemory);
epoger@google.comc8263e72013-04-10 12:17:34 +00001192 SkGPipeWriter writer;
1193 SkCanvas* pipeCanvas = writer.startRecording(&pipeController,
scroggo@google.comaef2d3b2013-04-10 18:10:41 +00001194 gPipeWritingFlagCombos[i].flags,
1195 size.width(), size.height());
epoger@google.comc8263e72013-04-10 12:17:34 +00001196 if (!simulateFailure) {
1197 invokeGM(gm, pipeCanvas, false, false);
1198 }
1199 complete_bitmap(&bitmap);
1200 writer.endRecording();
1201 errors.add(compare_test_results_to_reference_bitmap(
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001202 gm->getName(), gRec.fName, renderModeDescriptor.c_str(), bitmap,
epoger@google.com659c8c02013-05-21 15:45:45 +00001203 &referenceBitmap));
epoger@google.comc8263e72013-04-10 12:17:34 +00001204 if (!errors.isEmpty()) {
1205 break;
1206 }
epoger@google.comde961632012-10-26 18:56:36 +00001207 }
1208 }
1209 return errors;
1210 }
1211
epoger@google.com6f6568b2013-03-22 17:29:46 +00001212 ErrorCombination test_tiled_pipe_playback(GM* gm, const ConfigData& gRec,
1213 const SkBitmap& referenceBitmap) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001214 const SkString shortNamePlusConfig = make_shortname_plus_config(gm->getName(),
epoger@google.com659c8c02013-05-21 15:45:45 +00001215 gRec.fName);
epoger@google.com6f6568b2013-03-22 17:29:46 +00001216 ErrorCombination errors;
epoger@google.comde961632012-10-26 18:56:36 +00001217 for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) {
epoger@google.comc8263e72013-04-10 12:17:34 +00001218 SkString renderModeDescriptor("-tiled pipe");
1219 renderModeDescriptor.append(gPipeWritingFlagCombos[i].name);
1220
1221 if ((gm->getFlags() & GM::kSkipPipe_Flag) ||
1222 (gm->getFlags() & GM::kSkipTiled_Flag)) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001223 RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
epoger@google.comc8263e72013-04-10 12:17:34 +00001224 renderModeDescriptor.c_str());
1225 errors.add(kIntentionallySkipped_ErrorType);
1226 } else {
1227 SkBitmap bitmap;
1228 SkISize size = gm->getISize();
1229 setup_bitmap(gRec, size, &bitmap);
1230 SkCanvas canvas(bitmap);
1231 installFilter(&canvas);
scroggo@google.com74b7ffd2013-04-30 02:32:41 +00001232 TiledPipeController pipeController(bitmap, &SkImageDecoder::DecodeMemory);
epoger@google.comc8263e72013-04-10 12:17:34 +00001233 SkGPipeWriter writer;
1234 SkCanvas* pipeCanvas = writer.startRecording(&pipeController,
scroggo@google.comaef2d3b2013-04-10 18:10:41 +00001235 gPipeWritingFlagCombos[i].flags,
1236 size.width(), size.height());
epoger@google.comc8263e72013-04-10 12:17:34 +00001237 invokeGM(gm, pipeCanvas, false, false);
1238 complete_bitmap(&bitmap);
1239 writer.endRecording();
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001240 errors.add(compare_test_results_to_reference_bitmap(gm->getName(), gRec.fName,
epoger@google.comc8263e72013-04-10 12:17:34 +00001241 renderModeDescriptor.c_str(),
1242 bitmap, &referenceBitmap));
1243 if (!errors.isEmpty()) {
1244 break;
1245 }
epoger@google.comde961632012-10-26 18:56:36 +00001246 }
1247 }
1248 return errors;
1249 }
epoger@google.come8ebeb12012-10-29 16:42:11 +00001250
1251 //
1252 // member variables.
1253 // They are public for now, to allow easier setting by tool_main().
1254 //
1255
epoger@google.com6f7f14d2013-06-19 18:28:31 +00001256 bool fUseFileHierarchy, fWriteChecksumBasedFilenames;
epoger@google.com5079d2c2013-04-12 14:11:21 +00001257 ErrorCombination fIgnorableErrorTypes;
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +00001258 SkTArray<SkString> fIgnorableTestNames;
epoger@google.come8ebeb12012-10-29 16:42:11 +00001259
junov@chromium.org95146eb2013-01-11 21:04:40 +00001260 const char* fMismatchPath;
epoger@google.com5f995452013-06-21 18:16:47 +00001261 const char* fMissingExpectationsPath;
junov@chromium.org95146eb2013-01-11 21:04:40 +00001262
epoger@google.com310478e2013-04-03 18:00:39 +00001263 // collection of tests that have failed with each ErrorType
1264 SkTArray<SkString> fFailedTests[kLast_ErrorType+1];
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001265 SkTArray<SkString> fTestsSkippedOnAllRenderModes;
epoger@google.com310478e2013-04-03 18:00:39 +00001266 int fTestsRun;
1267 SkTDict<int> fRenderModesEncountered;
epoger@google.com57f7abc2012-11-13 03:41:55 +00001268
epoger@google.com908f5832013-04-12 02:23:55 +00001269 // Where to read expectations (expected image hash digests, etc.) from.
epoger@google.com37269602013-01-19 04:21:27 +00001270 // If unset, we don't do comparisons.
1271 SkAutoTUnref<ExpectationsSource> fExpectationsSource;
1272
1273 // JSON summaries that we generate as we go (just for output).
epoger@google.comee8a8e32012-12-18 19:13:49 +00001274 Json::Value fJsonExpectedResults;
1275 Json::Value fJsonActualResults_Failed;
1276 Json::Value fJsonActualResults_FailureIgnored;
epoger@google.com9c56a8d2012-12-20 18:34:29 +00001277 Json::Value fJsonActualResults_NoComparison;
epoger@google.comee8a8e32012-12-18 19:13:49 +00001278 Json::Value fJsonActualResults_Succeeded;
epoger@google.comde961632012-10-26 18:56:36 +00001279}; // end of GMMain class definition
scroggo@google.com72c96722012-06-06 21:07:10 +00001280
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001281#if SK_SUPPORT_GPU
1282static const GLContextType kDontCare_GLContextType = GrContextFactory::kNative_GLContextType;
1283#else
1284static const GLContextType kDontCare_GLContextType = 0;
1285#endif
bsalomon@google.com7361f542012-04-19 19:15:35 +00001286
tomhudson@google.com9875dd12011-04-25 15:49:53 +00001287static const ConfigData gRec[] = {
reedddd014e2014-06-05 08:51:20 -07001288 { kN32_SkColorType, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "8888", true },
1289 { kRGB_565_SkColorType, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "565", true },
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001290#if SK_SUPPORT_GPU
reedddd014e2014-06-05 08:51:20 -07001291 { kN32_SkColorType, kGPU_Backend, GrContextFactory::kNative_GLContextType, 0, kRW_ConfigFlag, "gpu", true },
1292 { kN32_SkColorType, kGPU_Backend, GrContextFactory::kNative_GLContextType, 16, kRW_ConfigFlag, "msaa16", false},
1293 { kN32_SkColorType, kGPU_Backend, GrContextFactory::kNative_GLContextType, 4, kRW_ConfigFlag, "msaa4", false},
1294 { kN32_SkColorType, kGPU_Backend, GrContextFactory::kNVPR_GLContextType, 4, kRW_ConfigFlag, "nvprmsaa4", true },
1295 { kN32_SkColorType, kGPU_Backend, GrContextFactory::kNVPR_GLContextType, 16, kRW_ConfigFlag, "nvprmsaa16", false},
epoger@google.comc824c832013-07-12 15:52:59 +00001296 /* The gpudebug context does not generate meaningful images, so don't record
1297 * the images it generates! We only run it to look for asserts. */
reedddd014e2014-06-05 08:51:20 -07001298 { kN32_SkColorType, kGPU_Backend, GrContextFactory::kDebug_GLContextType, 0, kNone_ConfigFlag, "gpudebug", kDebugOnly},
robertphillips@google.comd6543e52013-07-18 17:39:14 +00001299 /* The gpunull context does the least amount of work possible and doesn't
1300 generate meaninful images, so don't record them!. It can be run to
1301 isolate the CPU-side processing expense from the GPU-side.
1302 */
reedddd014e2014-06-05 08:51:20 -07001303 { kN32_SkColorType, kGPU_Backend, GrContextFactory::kNull_GLContextType, 0, kNone_ConfigFlag, "gpunull", kDebugOnly},
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001304#if SK_ANGLE
reedddd014e2014-06-05 08:51:20 -07001305 { kN32_SkColorType, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 0, kRW_ConfigFlag, "angle", true },
1306 { kN32_SkColorType, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 16, kRW_ConfigFlag, "anglemsaa16", true },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001307#endif // SK_ANGLE
1308#ifdef SK_MESA
reedddd014e2014-06-05 08:51:20 -07001309 { kN32_SkColorType, kGPU_Backend, GrContextFactory::kMESA_GLContextType, 0, kRW_ConfigFlag, "mesa", true },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001310#endif // SK_MESA
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001311#endif // SK_SUPPORT_GPU
bungeman@google.comb29c8832011-10-10 13:19:10 +00001312#ifdef SK_SUPPORT_XPS
bsalomon@google.com7361f542012-04-19 19:15:35 +00001313 /* At present we have no way of comparing XPS files (either natively or by converting to PNG). */
reedddd014e2014-06-05 08:51:20 -07001314 { kN32_SkColorType, kXPS_Backend, kDontCare_GLContextType, 0, kWrite_ConfigFlag, "xps", true },
robertphillips@google.coma73e8602012-08-02 17:56:02 +00001315#endif // SK_SUPPORT_XPS
bsalomon@google.com7361f542012-04-19 19:15:35 +00001316#ifdef SK_SUPPORT_PDF
reedddd014e2014-06-05 08:51:20 -07001317 { kN32_SkColorType, kPDF_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "pdf", true },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001318#endif // SK_SUPPORT_PDF
reed@android.com00dae862009-06-10 15:38:48 +00001319};
1320
bungeman@google.com5d20cae2014-05-09 15:22:41 +00001321static bool SkNoRasterizePDF(SkStream*, SkBitmap*) { return false; }
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
bungeman@google.com5d20cae2014-05-09 15:22:41 +00001333 // The following exists so that this array is never zero length.
1334 { &SkNoRasterizePDF, "none", false},
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001335};
1336
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001337static const char kDefaultsConfigStr[] = "defaults";
1338static const char kExcludeConfigChar = '~';
kkinnunen80549fc2014-06-30 06:36:31 -07001339#if SK_SUPPORT_GPU
1340static const char kGpuAPINameGL[] = "gl";
1341static const char kGpuAPINameGLES[] = "gles";
1342#endif
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001343
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001344static SkString configUsage() {
scroggo@google.com0f567c62013-03-20 15:35:08 +00001345 SkString result;
1346 result.appendf("Space delimited list of which configs to run. Possible options: [");
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001347 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001348 SkASSERT(gRec[i].fName != kDefaultsConfigStr);
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001349 if (i > 0) {
scroggo@google.com0f567c62013-03-20 15:35:08 +00001350 result.append("|");
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001351 }
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001352 result.appendf("%s", gRec[i].fName);
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001353 }
scroggo@google.com0f567c62013-03-20 15:35:08 +00001354 result.append("]\n");
1355 result.appendf("The default value is: \"");
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001356 SkString firstDefault;
1357 SkString allButFirstDefaults;
1358 SkString nonDefault;
scroggo@google.com0f567c62013-03-20 15:35:08 +00001359 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
1360 if (gRec[i].fRunByDefault) {
1361 if (i > 0) {
1362 result.append(" ");
1363 }
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001364 result.append(gRec[i].fName);
1365 if (firstDefault.isEmpty()) {
1366 firstDefault = gRec[i].fName;
1367 } else {
1368 if (!allButFirstDefaults.isEmpty()) {
1369 allButFirstDefaults.append(" ");
1370 }
1371 allButFirstDefaults.append(gRec[i].fName);
1372 }
1373 } else {
1374 nonDefault = gRec[i].fName;
scroggo@google.com0f567c62013-03-20 15:35:08 +00001375 }
1376 }
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001377 result.append("\"\n");
1378 result.appendf("\"%s\" evaluates to the default set of configs.\n", kDefaultsConfigStr);
1379 result.appendf("Prepending \"%c\" on a config name excludes it from the set of configs to run.\n"
1380 "Exclusions always override inclusions regardless of order.\n",
1381 kExcludeConfigChar);
1382 result.appendf("E.g. \"--config %s %c%s %s\" will run these configs:\n\t%s %s",
1383 kDefaultsConfigStr,
1384 kExcludeConfigChar,
1385 firstDefault.c_str(),
1386 nonDefault.c_str(),
1387 allButFirstDefaults.c_str(),
1388 nonDefault.c_str());
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001389 return result;
scroggo@google.com0b735632013-03-19 17:38:50 +00001390}
scroggo@google.com7d519302013-03-19 17:28:10 +00001391
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001392static SkString pdfRasterizerUsage() {
1393 SkString result;
1394 result.appendf("Space delimited list of which PDF rasterizers to run. Possible options: [");
1395 // For this (and further) loops through kPDFRasterizers, there is a typecast to int to avoid
1396 // the compiler giving an "comparison of unsigned expression < 0 is always false" warning
1397 // and turning it into a build-breaking error.
1398 for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); ++i) {
1399 if (i > 0) {
1400 result.append(" ");
1401 }
1402 result.append(kPDFRasterizers[i].fName);
1403 }
1404 result.append("]\n");
1405 result.append("The default value is: \"");
1406 for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); ++i) {
1407 if (kPDFRasterizers[i].fRunByDefault) {
1408 if (i > 0) {
1409 result.append(" ");
1410 }
1411 result.append(kPDFRasterizers[i].fName);
1412 }
1413 }
1414 result.append("\"");
1415 return result;
1416}
1417
epoger@google.com6f6568b2013-03-22 17:29:46 +00001418// Macro magic to convert a numeric preprocessor token into a string.
1419// Adapted from http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
1420// This should probably be moved into one of our common headers...
1421#define TOSTRING_INTERNAL(x) #x
1422#define TOSTRING(x) TOSTRING_INTERNAL(x)
1423
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001424// Alphabetized ignoring "no" prefix ("readPath", "noreplay", "resourcePath").
scroggo@google.com0f567c62013-03-20 15:35:08 +00001425DEFINE_string(config, "", configUsage().c_str());
bsalomon69456182014-07-07 10:46:58 -07001426DEFINE_bool(cpu, true, "Allows non-GPU configs to be run. Applied after --config.");
vandebo@chromium.orgf8afb2b2013-11-06 16:32:15 +00001427DEFINE_string(pdfRasterizers, "default", pdfRasterizerUsage().c_str());
epoger@google.com5e497382013-09-30 07:01:55 +00001428DEFINE_bool(deferred, false, "Exercise the deferred rendering test pass.");
commit-bot@chromium.orgb17ccc92014-03-13 16:16:36 +00001429DEFINE_bool(dryRun, false, "Don't actually run the tests, just print what would have been done.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001430DEFINE_string(excludeConfig, "", "Space delimited list of configs to skip.");
1431DEFINE_bool(forceBWtext, false, "Disable text anti-aliasing.");
1432#if SK_SUPPORT_GPU
kkinnunen80549fc2014-06-30 06:36:31 -07001433DEFINE_string(gpuAPI, "", "Force use of specific gpu API. Using \"gl\" "
1434 "forces OpenGL API. Using \"gles\" forces OpenGL ES API. "
1435 "Defaults to empty string, which selects the API native to the "
1436 "system.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001437DEFINE_string(gpuCacheSize, "", "<bytes> <count>: Limit the gpu cache to byte size or "
epoger@google.com6f6568b2013-03-22 17:29:46 +00001438 "object count. " TOSTRING(DEFAULT_CACHE_VALUE) " for either value means "
1439 "use the default. 0 for either disables the cache.");
bsalomon69456182014-07-07 10:46:58 -07001440DEFINE_bool(gpu, true, "Allows GPU configs to be run. Applied after --config.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001441#endif
1442DEFINE_bool(hierarchy, false, "Whether to use multilevel directory structure "
1443 "when reading/writing files.");
epoger@google.com5079d2c2013-04-12 14:11:21 +00001444DEFINE_string(ignoreErrorTypes, kDefaultIgnorableErrorTypes.asString(" ").c_str(),
1445 "Space-separated list of ErrorTypes that should be ignored. If any *other* error "
1446 "types are encountered, the tool will exit with a nonzero return value.");
epoger@google.comf711f322013-10-18 14:55:47 +00001447DEFINE_string(ignoreFailuresFile, "", "Path to file containing a list of tests for which we "
1448 "should ignore failures.\n"
1449 "The file should list one test per line, except for comment lines starting with #");
commit-bot@chromium.org6dda8272014-01-23 17:21:19 +00001450DEFINE_bool2(leaks, l, false, "show leaked ref cnt'd objects.");
caryclark@google.com512c9b62013-05-10 15:16:13 +00001451DEFINE_string(match, "", "[~][^]substring[$] [...] of test name to run.\n"
1452 "Multiple matches may be separated by spaces.\n"
1453 "~ causes a matching test to always be skipped\n"
1454 "^ requires the start of the test to match\n"
1455 "$ requires the end of the test to match\n"
1456 "^ and $ requires an exact match\n"
1457 "If a test does not match any list entry,\n"
1458 "it is skipped unless some list entry starts with ~");
epoger@google.com5f995452013-06-21 18:16:47 +00001459DEFINE_string(missingExpectationsPath, "", "Write images for tests without expectations "
1460 "into this directory.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001461DEFINE_string(mismatchPath, "", "Write images for tests that failed due to "
1462 "pixel mismatches into this directory.");
1463DEFINE_string(modulo, "", "[--modulo <remainder> <divisor>]: only run tests for which "
1464 "testIndex %% divisor == remainder.");
epoger@google.com5e497382013-09-30 07:01:55 +00001465DEFINE_bool(pipe, false, "Exercise the SkGPipe replay test pass.");
commit-bot@chromium.orgd393b172014-04-16 16:02:10 +00001466DEFINE_bool(quadtree, false, "Exercise the QuadTree variant of SkPicture test pass.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001467DEFINE_string2(readPath, r, "", "Read reference images from this dir, and report "
1468 "any differences between those and the newly generated ones.");
epoger@google.com5e497382013-09-30 07:01:55 +00001469DEFINE_bool(replay, false, "Exercise the SkPicture replay test pass.");
djsollen@google.comac8f3a42013-10-04 14:57:00 +00001470#if SK_SUPPORT_GPU
1471DEFINE_bool(resetGpuContext, false, "Reset the GrContext prior to running each GM.");
1472#endif
epoger@google.com5e497382013-09-30 07:01:55 +00001473DEFINE_bool(rtree, false, "Exercise the R-Tree variant of SkPicture test pass.");
1474DEFINE_bool(serialize, false, "Exercise the SkPicture serialization & deserialization test pass.");
epoger@google.comcaac3db2013-04-04 19:23:11 +00001475DEFINE_bool(simulatePipePlaybackFailure, false, "Simulate a rendering failure in pipe mode only.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001476DEFINE_bool(tiledPipe, false, "Exercise tiled SkGPipe replay.");
epoger@google.com5e497382013-09-30 07:01:55 +00001477DEFINE_bool(tileGrid, false, "Exercise the tile grid variant of SkPicture.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001478DEFINE_string(tileGridReplayScales, "", "Space separated list of floating-point scale "
1479 "factors to be used for tileGrid playback testing. Default value: 1.0");
epoger@google.comb0f8b432013-04-10 18:46:25 +00001480DEFINE_bool2(verbose, v, false, "Give more detail (e.g. list all GMs run, more info about "
1481 "each test).");
epoger@google.com6f7f14d2013-06-19 18:28:31 +00001482DEFINE_bool(writeChecksumBasedFilenames, false, "When writing out actual images, use checksum-"
1483 "based filenames, as rebaseline.py will use when downloading them from Google Storage");
1484DEFINE_string(writeJsonSummaryPath, "", "Write a JSON-formatted result summary to this file.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001485DEFINE_string2(writePath, w, "", "Write rendered images into this directory.");
scroggo@google.com604e0c22013-04-09 21:25:46 +00001486DEFINE_string2(writePicturePath, p, "", "Write .skp files into this directory.");
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001487DEFINE_int32(pdfJpegQuality, -1, "Encodes images in JPEG at quality level N, "
1488 "which can be in range 0-100). N = -1 will disable JPEG compression. "
1489 "Default is N = 100, maximum quality.");
commit-bot@chromium.orgf4f9df42013-09-26 20:44:24 +00001490// TODO(edisonn): pass a matrix instead of forcePerspectiveMatrix
1491// Either the 9 numbers defining the matrix
1492// or probably more readable would be to replace it with a set of a few predicates
1493// Like --prerotate 100 200 10 --posttranslate 10, 10
1494// Probably define spacial names like centerx, centery, top, bottom, left, right
1495// then we can write something reabable like --rotate centerx centery 90
1496DEFINE_bool(forcePerspectiveMatrix, false, "Force a perspective matrix.");
commit-bot@chromium.org5e009892013-10-14 13:42:12 +00001497DEFINE_bool(useDocumentInsteadOfDevice, false, "Use SkDocument::CreateFoo instead of SkFooDevice.");
edisonn@google.com73a7ea32013-11-11 20:55:15 +00001498DEFINE_int32(pdfRasterDpi, 72, "Scale at which at which the non suported "
1499 "features in PDF are rasterized. Must be be in range 0-10000. "
1500 "Default is 72. N = 0 will disable rasterizing features like "
1501 "text shadows or perspective bitmaps.");
reed@google.com672588b2014-01-08 15:42:01 +00001502static SkData* encode_to_dct_data(size_t*, const SkBitmap& bitmap) {
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001503 // Filter output of warnings that JPEG is not available for the image.
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001504 if (bitmap.width() >= 65500 || bitmap.height() >= 65500) return NULL;
1505 if (FLAGS_pdfJpegQuality == -1) return NULL;
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001506
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001507 SkBitmap bm = bitmap;
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001508#if defined(SK_BUILD_FOR_MAC)
1509 // Workaround bug #1043 where bitmaps with referenced pixels cause
1510 // CGImageDestinationFinalize to crash
1511 SkBitmap copy;
commit-bot@chromium.orgd5f032d2014-02-24 18:51:43 +00001512 bitmap.deepCopyTo(&copy);
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001513 bm = copy;
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001514#endif
1515
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001516 SkPixelRef* pr = bm.pixelRef();
1517 if (pr != NULL) {
1518 SkData* data = pr->refEncodedData();
1519 if (data != NULL) {
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001520 return data;
1521 }
1522 }
1523
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001524 return SkImageEncoder::EncodeData(bm,
1525 SkImageEncoder::kJPEG_Type,
1526 FLAGS_pdfJpegQuality);
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001527}
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001528
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001529static int findConfig(const char config[]) {
1530 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
1531 if (!strcmp(config, gRec[i].fName)) {
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001532 return (int) i;
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001533 }
1534 }
1535 return -1;
1536}
1537
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001538static const PDFRasterizerData* findPDFRasterizer(const char rasterizer[]) {
1539 for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); i++) {
1540 if (!strcmp(rasterizer, kPDFRasterizers[i].fName)) {
1541 return &kPDFRasterizers[i];
1542 }
1543 }
1544 return NULL;
1545}
1546
reed@google.comfb2cd422013-01-04 14:43:03 +00001547template <typename T> void appendUnique(SkTDArray<T>* array, const T& value) {
1548 int index = array->find(value);
1549 if (index < 0) {
1550 *array->append() = value;
1551 }
1552}
1553
epoger@google.com80724df2013-03-21 13:49:54 +00001554/**
epoger@google.com80724df2013-03-21 13:49:54 +00001555 * Run this test in a number of different drawing modes (pipe,
1556 * deferred, tiled, etc.), confirming that the resulting bitmaps all
1557 * *exactly* match comparisonBitmap.
1558 *
1559 * Returns all errors encountered while doing so.
1560 */
epoger@google.com6f6568b2013-03-22 17:29:46 +00001561ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm, const ConfigData &compareConfig,
1562 const SkBitmap &comparisonBitmap,
1563 const SkTDArray<SkScalar> &tileGridReplayScales);
1564ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm, const ConfigData &compareConfig,
1565 const SkBitmap &comparisonBitmap,
1566 const SkTDArray<SkScalar> &tileGridReplayScales) {
1567 ErrorCombination errorsForAllModes;
epoger@google.com80724df2013-03-21 13:49:54 +00001568 uint32_t gmFlags = gm->getFlags();
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001569 const SkString shortNamePlusConfig = gmmain.make_shortname_plus_config(gm->getName(),
epoger@google.com659c8c02013-05-21 15:45:45 +00001570 compareConfig.fName);
epoger@google.com80724df2013-03-21 13:49:54 +00001571
epoger@google.comc8263e72013-04-10 12:17:34 +00001572 SkPicture* pict = gmmain.generate_new_picture(gm, kNone_BbhType, 0);
1573 SkAutoUnref aur(pict);
1574 if (FLAGS_replay) {
1575 const char renderModeDescriptor[] = "-replay";
1576 if (gmFlags & GM::kSkipPicture_Flag) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001577 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
1578 renderModeDescriptor);
epoger@google.comc8263e72013-04-10 12:17:34 +00001579 errorsForAllModes.add(kIntentionallySkipped_ErrorType);
1580 } else {
epoger@google.com80724df2013-03-21 13:49:54 +00001581 SkBitmap bitmap;
1582 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap);
epoger@google.comc8263e72013-04-10 12:17:34 +00001583 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap(
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001584 gm->getName(), compareConfig.fName, renderModeDescriptor, bitmap,
epoger@google.com659c8c02013-05-21 15:45:45 +00001585 &comparisonBitmap));
epoger@google.com80724df2013-03-21 13:49:54 +00001586 }
epoger@google.comc8263e72013-04-10 12:17:34 +00001587 }
epoger@google.com80724df2013-03-21 13:49:54 +00001588
epoger@google.comc8263e72013-04-10 12:17:34 +00001589 if (FLAGS_serialize) {
1590 const char renderModeDescriptor[] = "-serialize";
1591 if (gmFlags & GM::kSkipPicture_Flag) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001592 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
1593 renderModeDescriptor);
epoger@google.comc8263e72013-04-10 12:17:34 +00001594 errorsForAllModes.add(kIntentionallySkipped_ErrorType);
1595 } else {
epoger@google.com80724df2013-03-21 13:49:54 +00001596 SkPicture* repict = gmmain.stream_to_new_picture(*pict);
1597 SkAutoUnref aurr(repict);
epoger@google.com80724df2013-03-21 13:49:54 +00001598 SkBitmap bitmap;
1599 gmmain.generate_image_from_picture(gm, compareConfig, repict, &bitmap);
epoger@google.comc8263e72013-04-10 12:17:34 +00001600 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap(
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001601 gm->getName(), compareConfig.fName, renderModeDescriptor, bitmap,
epoger@google.com659c8c02013-05-21 15:45:45 +00001602 &comparisonBitmap));
epoger@google.com80724df2013-03-21 13:49:54 +00001603 }
epoger@google.com80724df2013-03-21 13:49:54 +00001604 }
1605
epoger@google.comc8263e72013-04-10 12:17:34 +00001606 if ((1 == FLAGS_writePicturePath.count()) &&
1607 !(gmFlags & GM::kSkipPicture_Flag)) {
1608 const char* pictureSuffix = "skp";
epoger@google.com659c8c02013-05-21 15:45:45 +00001609 // TODO(epoger): Make sure this still works even though the
1610 // filename now contains the config name (it used to contain
1611 // just the shortName). I think this is actually an
1612 // *improvement*, because now runs with different configs will
1613 // write out their SkPictures to separate files rather than
1614 // overwriting each other. But we should make sure it doesn't
1615 // break anybody.
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001616 SkString path = gmmain.make_filename(FLAGS_writePicturePath[0], gm->getName(),
epoger@google.com659c8c02013-05-21 15:45:45 +00001617 compareConfig.fName, "", pictureSuffix);
epoger@google.comc8263e72013-04-10 12:17:34 +00001618 SkFILEWStream stream(path.c_str());
1619 pict->serialize(&stream);
epoger@google.com80724df2013-03-21 13:49:54 +00001620 }
1621
epoger@google.comc8263e72013-04-10 12:17:34 +00001622 if (FLAGS_rtree) {
1623 const char renderModeDescriptor[] = "-rtree";
commit-bot@chromium.orgd393b172014-04-16 16:02:10 +00001624 if ((gmFlags & GM::kSkipPicture_Flag) || (gmFlags & GM::kSkipTiled_Flag)) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001625 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
1626 renderModeDescriptor);
epoger@google.comc8263e72013-04-10 12:17:34 +00001627 errorsForAllModes.add(kIntentionallySkipped_ErrorType);
1628 } else {
commit-bot@chromium.orgd393b172014-04-16 16:02:10 +00001629 SkPicture* pict = gmmain.generate_new_picture(gm, kRTree_BbhType, 0);
1630 SkAutoUnref aur(pict);
1631 SkBitmap bitmap;
1632 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap);
1633 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap(
1634 gm->getName(), compareConfig.fName, renderModeDescriptor, bitmap,
1635 &comparisonBitmap));
1636 }
1637 }
1638
1639 if (FLAGS_quadtree) {
1640 const char renderModeDescriptor[] = "-quadtree";
1641 if ((gmFlags & GM::kSkipPicture_Flag) || (gmFlags & GM::kSkipTiled_Flag)) {
1642 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
1643 renderModeDescriptor);
1644 errorsForAllModes.add(kIntentionallySkipped_ErrorType);
1645 } else {
1646 SkPicture* pict = gmmain.generate_new_picture(gm, kQuadTree_BbhType, 0);
epoger@google.com80724df2013-03-21 13:49:54 +00001647 SkAutoUnref aur(pict);
1648 SkBitmap bitmap;
epoger@google.comc8263e72013-04-10 12:17:34 +00001649 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap);
epoger@google.com6f6568b2013-03-22 17:29:46 +00001650 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap(
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001651 gm->getName(), compareConfig.fName, renderModeDescriptor, bitmap,
epoger@google.com659c8c02013-05-21 15:45:45 +00001652 &comparisonBitmap));
epoger@google.comc8263e72013-04-10 12:17:34 +00001653 }
1654 }
1655
1656 if (FLAGS_tileGrid) {
1657 for(int scaleIndex = 0; scaleIndex < tileGridReplayScales.count(); ++scaleIndex) {
1658 SkScalar replayScale = tileGridReplayScales[scaleIndex];
1659 SkString renderModeDescriptor("-tilegrid");
1660 if (SK_Scalar1 != replayScale) {
1661 renderModeDescriptor += "-scale-";
1662 renderModeDescriptor.appendScalar(replayScale);
1663 }
1664
1665 if ((gmFlags & GM::kSkipPicture_Flag) ||
senorblanco@chromium.orgd4d44f02014-02-20 17:17:57 +00001666 (gmFlags & GM::kSkipTiled_Flag) ||
epoger@google.comc8263e72013-04-10 12:17:34 +00001667 ((gmFlags & GM::kSkipScaledReplay_Flag) && replayScale != 1)) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001668 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
epoger@google.comc8263e72013-04-10 12:17:34 +00001669 renderModeDescriptor.c_str());
1670 errorsForAllModes.add(kIntentionallySkipped_ErrorType);
1671 } else {
1672 // We record with the reciprocal scale to obtain a replay
1673 // result that can be validated against comparisonBitmap.
1674 SkScalar recordScale = SkScalarInvert(replayScale);
1675 SkPicture* pict = gmmain.generate_new_picture(
robertphillips9f1c2412014-06-09 06:25:34 -07001676 gm, kTileGrid_BbhType, 0, recordScale);
epoger@google.comc8263e72013-04-10 12:17:34 +00001677 SkAutoUnref aur(pict);
1678 SkBitmap bitmap;
1679 // We cannot yet pass 'true' to generate_image_from_picture to
1680 // perform actual tiled rendering (see Issue 1198 -
1681 // https://code.google.com/p/skia/issues/detail?id=1198)
1682 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap,
1683 replayScale /*, true */);
1684 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap(
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001685 gm->getName(), compareConfig.fName, renderModeDescriptor.c_str(), bitmap,
epoger@google.com659c8c02013-05-21 15:45:45 +00001686 &comparisonBitmap));
epoger@google.comc8263e72013-04-10 12:17:34 +00001687 }
epoger@google.com80724df2013-03-21 13:49:54 +00001688 }
1689 }
1690
1691 // run the pipe centric GM steps
epoger@google.comc8263e72013-04-10 12:17:34 +00001692 if (FLAGS_pipe) {
1693 errorsForAllModes.add(gmmain.test_pipe_playback(gm, compareConfig, comparisonBitmap,
1694 FLAGS_simulatePipePlaybackFailure));
1695 if (FLAGS_tiledPipe) {
1696 errorsForAllModes.add(gmmain.test_tiled_pipe_playback(gm, compareConfig,
1697 comparisonBitmap));
epoger@google.com80724df2013-03-21 13:49:54 +00001698 }
epoger@google.com80724df2013-03-21 13:49:54 +00001699 }
1700 return errorsForAllModes;
1701}
1702
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001703
1704/**
1705 * Run this test in a number of different configs (8888, 565, PDF,
1706 * etc.), confirming that the resulting bitmaps match expectations
1707 * (which may be different for each config).
1708 *
1709 * Returns all errors encountered while doing so.
1710 */
1711ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm,
1712 const SkTDArray<size_t> &configs,
1713 const SkTDArray<const PDFRasterizerData*> &pdfRasterizers,
1714 const SkTDArray<SkScalar> &tileGridReplayScales,
kkinnunen80549fc2014-06-30 06:36:31 -07001715 GrContextFactory *grFactory,
1716 GrGLStandard gpuAPI);
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001717ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm,
1718 const SkTDArray<size_t> &configs,
1719 const SkTDArray<const PDFRasterizerData*> &pdfRasterizers,
1720 const SkTDArray<SkScalar> &tileGridReplayScales,
kkinnunen80549fc2014-06-30 06:36:31 -07001721 GrContextFactory *grFactory,
1722 GrGLStandard gpuAPI) {
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001723 const char renderModeDescriptor[] = "";
1724 ErrorCombination errorsForAllConfigs;
1725 uint32_t gmFlags = gm->getFlags();
1726
1727 for (int i = 0; i < configs.count(); i++) {
1728 ConfigData config = gRec[configs[i]];
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001729 const SkString shortNamePlusConfig = gmmain.make_shortname_plus_config(gm->getName(),
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001730 config.fName);
1731
1732 // Skip any tests that we don't even need to try.
1733 // If any of these were skipped on a per-GM basis, record them as
1734 // kIntentionallySkipped.
1735 if (kPDF_Backend == config.fBackend) {
1736 if (gmFlags & GM::kSkipPDF_Flag) {
1737 gmmain.RecordSkippedTest(shortNamePlusConfig,
1738 renderModeDescriptor,
1739 config.fBackend);
1740 errorsForAllConfigs.add(kIntentionallySkipped_ErrorType);
1741 continue;
1742 }
1743 }
1744 if ((gmFlags & GM::kSkip565_Flag) &&
1745 (kRaster_Backend == config.fBackend) &&
reedddd014e2014-06-05 08:51:20 -07001746 (kRGB_565_SkColorType == config.fColorType)) {
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001747 gmmain.RecordSkippedTest(shortNamePlusConfig,
1748 renderModeDescriptor,
1749 config.fBackend);
1750 errorsForAllConfigs.add(kIntentionallySkipped_ErrorType);
1751 continue;
1752 }
1753 if (((gmFlags & GM::kSkipGPU_Flag) && kGPU_Backend == config.fBackend) ||
1754 ((gmFlags & GM::kGPUOnly_Flag) && kGPU_Backend != config.fBackend)) {
1755 gmmain.RecordSkippedTest(shortNamePlusConfig,
1756 renderModeDescriptor,
1757 config.fBackend);
1758 errorsForAllConfigs.add(kIntentionallySkipped_ErrorType);
1759 continue;
1760 }
1761
1762 // Now we know that we want to run this test and record its
1763 // success or failure.
1764 ErrorCombination errorsForThisConfig;
1765 GrSurface* gpuTarget = NULL;
1766#if SK_SUPPORT_GPU
1767 SkAutoTUnref<GrSurface> auGpuTarget;
1768 if ((errorsForThisConfig.isEmpty()) && (kGPU_Backend == config.fBackend)) {
1769 if (FLAGS_resetGpuContext) {
1770 grFactory->destroyContexts();
1771 }
kkinnunen80549fc2014-06-30 06:36:31 -07001772 GrContext* gr = grFactory->get(config.fGLContextType, gpuAPI);
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001773 bool grSuccess = false;
1774 if (gr) {
1775 // create a render target to back the device
1776 GrTextureDesc desc;
1777 desc.fConfig = kSkia8888_GrPixelConfig;
1778 desc.fFlags = kRenderTarget_GrTextureFlagBit;
1779 desc.fWidth = gm->getISize().width();
1780 desc.fHeight = gm->getISize().height();
1781 desc.fSampleCnt = config.fSampleCnt;
1782 auGpuTarget.reset(gr->createUncachedTexture(desc, NULL, 0));
1783 if (NULL != auGpuTarget) {
1784 gpuTarget = auGpuTarget;
1785 grSuccess = true;
1786 // Set the user specified cache limits if non-default.
1787 size_t bytes;
1788 int count;
commit-bot@chromium.org95c20032014-05-09 14:29:32 +00001789 gr->getResourceCacheLimits(&count, &bytes);
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001790 if (DEFAULT_CACHE_VALUE != gGpuCacheSizeBytes) {
1791 bytes = static_cast<size_t>(gGpuCacheSizeBytes);
1792 }
1793 if (DEFAULT_CACHE_VALUE != gGpuCacheSizeCount) {
1794 count = gGpuCacheSizeCount;
1795 }
commit-bot@chromium.org95c20032014-05-09 14:29:32 +00001796 gr->setResourceCacheLimits(count, bytes);
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001797 }
1798 }
1799 if (!grSuccess) {
1800 errorsForThisConfig.add(kNoGpuContext_ErrorType);
1801 }
1802 }
1803#endif
1804
1805 SkBitmap comparisonBitmap;
1806
1807 const char* writePath;
1808 if (FLAGS_writePath.count() == 1) {
1809 writePath = FLAGS_writePath[0];
1810 } else {
1811 writePath = NULL;
1812 }
1813
1814 if (errorsForThisConfig.isEmpty()) {
1815 errorsForThisConfig.add(gmmain.test_drawing(gm, config, pdfRasterizers,
1816 writePath, gpuTarget,
1817 &comparisonBitmap));
1818 gmmain.RecordTestResults(errorsForThisConfig, shortNamePlusConfig, "");
1819 }
1820
1821 // TODO: run only if gmmain.test_drawing succeeded.
1822 if (kRaster_Backend == config.fBackend) {
1823 run_multiple_modes(gmmain, gm, config, comparisonBitmap, tileGridReplayScales);
1824 }
1825
1826 if (FLAGS_deferred && errorsForThisConfig.isEmpty() &&
1827 (kGPU_Backend == config.fBackend || kRaster_Backend == config.fBackend)) {
1828 errorsForThisConfig.add(gmmain.test_deferred_drawing(gm, config, comparisonBitmap,
1829 gpuTarget));
1830 }
1831
1832 errorsForAllConfigs.add(errorsForThisConfig);
1833 }
1834 return errorsForAllConfigs;
1835}
1836
1837
epoger@google.com310478e2013-04-03 18:00:39 +00001838/**
epoger@google.comf711f322013-10-18 14:55:47 +00001839 * Read individual lines from a file, pushing them into the given array.
1840 *
1841 * @param filename path to the file to read
1842 * @param lines array of strings to add the lines to
1843 * @returns true if able to read lines from the file
1844 */
1845static bool read_lines_from_file(const char* filename, SkTArray<SkString> &lines) {
1846 SkAutoTUnref<SkStream> streamWrapper(SkStream::NewFromFile(filename));
1847 SkStream *stream = streamWrapper.get();
1848 if (!stream) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00001849 SkDebugf("unable to read file '%s'\n", filename);
epoger@google.comf711f322013-10-18 14:55:47 +00001850 return false;
1851 }
1852
1853 char c;
1854 SkString line;
1855 while (1 == stream->read(&c, 1)) {
1856 // If we hit either CR or LF, we've completed a line.
1857 //
1858 // TODO: If the file uses both CR and LF, this will return an extra blank
1859 // line for each line of the file. Which is OK for current purposes...
1860 //
1861 // TODO: Does this properly handle unicode? It doesn't matter for
1862 // current purposes...
1863 if ((c == 0x0d) || (c == 0x0a)) {
1864 lines.push_back(line);
1865 line.reset();
1866 } else {
1867 line.append(&c, 1);
1868 }
1869 }
1870 lines.push_back(line);
1871 return true;
1872}
1873
1874/**
epoger@google.com310478e2013-04-03 18:00:39 +00001875 * Return a list of all entries in an array of strings as a single string
1876 * of this form:
1877 * "item1", "item2", "item3"
1878 */
1879SkString list_all(const SkTArray<SkString> &stringArray);
1880SkString list_all(const SkTArray<SkString> &stringArray) {
1881 SkString total;
1882 for (int i = 0; i < stringArray.count(); i++) {
1883 if (i > 0) {
1884 total.append(", ");
1885 }
1886 total.append("\"");
1887 total.append(stringArray[i]);
1888 total.append("\"");
1889 }
1890 return total;
1891}
1892
1893/**
1894 * Return a list of configuration names, as a single string of this form:
1895 * "item1", "item2", "item3"
1896 *
1897 * @param configs configurations, as a list of indices into gRec
1898 */
1899SkString list_all_config_names(const SkTDArray<size_t> &configs);
1900SkString list_all_config_names(const SkTDArray<size_t> &configs) {
1901 SkString total;
1902 for (int i = 0; i < configs.count(); i++) {
1903 if (i > 0) {
1904 total.append(", ");
1905 }
1906 total.append("\"");
1907 total.append(gRec[configs[i]].fName);
1908 total.append("\"");
1909 }
1910 return total;
1911}
1912
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001913static bool prepare_subdirectories(const char *root, bool useFileHierarchy,
1914 const SkTDArray<size_t> &configs,
1915 const SkTDArray<const PDFRasterizerData*>& pdfRasterizers) {
epoger@google.comfdea3252013-05-02 18:24:03 +00001916 if (!sk_mkdir(root)) {
1917 return false;
1918 }
1919 if (useFileHierarchy) {
1920 for (int i = 0; i < configs.count(); i++) {
1921 ConfigData config = gRec[configs[i]];
1922 SkString subdir;
1923 subdir.appendf("%s%c%s", root, SkPATH_SEPARATOR, config.fName);
1924 if (!sk_mkdir(subdir.c_str())) {
1925 return false;
1926 }
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001927
1928 if (config.fBackend == kPDF_Backend) {
1929 for (int j = 0; j < pdfRasterizers.count(); j++) {
1930 SkString pdfSubdir = subdir;
vandebo@chromium.org8fc37662013-08-21 18:04:09 +00001931 pdfSubdir.appendf("-%s", pdfRasterizers[j]->fName);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001932 if (!sk_mkdir(pdfSubdir.c_str())) {
1933 return false;
1934 }
1935 }
1936 }
epoger@google.comfdea3252013-05-02 18:24:03 +00001937 }
1938 }
1939 return true;
1940}
1941
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00001942static bool parse_flags_configs(SkTDArray<size_t>* outConfigs,
kkinnunen80549fc2014-06-30 06:36:31 -07001943 GrContextFactory* grFactory, GrGLStandard gpuAPI) {
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00001944 SkTDArray<size_t> excludeConfigs;
1945
1946 for (int i = 0; i < FLAGS_config.count(); i++) {
1947 const char* config = FLAGS_config[i];
1948 bool exclude = false;
1949 if (*config == kExcludeConfigChar) {
1950 exclude = true;
1951 config += 1;
1952 }
1953 int index = findConfig(config);
1954 if (index >= 0) {
1955 if (exclude) {
1956 *excludeConfigs.append() = index;
1957 } else {
1958 appendUnique<size_t>(outConfigs, index);
1959 }
1960 } else if (0 == strcmp(kDefaultsConfigStr, config)) {
1961 if (exclude) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00001962 SkDebugf("%c%s is not allowed.\n",
1963 kExcludeConfigChar, kDefaultsConfigStr);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00001964 return false;
1965 }
1966 for (size_t c = 0; c < SK_ARRAY_COUNT(gRec); ++c) {
1967 if (gRec[c].fRunByDefault) {
1968 appendUnique<size_t>(outConfigs, c);
1969 }
1970 }
1971 } else {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00001972 SkDebugf("unrecognized config %s\n", config);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00001973 return false;
1974 }
1975 }
1976
1977 for (int i = 0; i < FLAGS_excludeConfig.count(); i++) {
1978 int index = findConfig(FLAGS_excludeConfig[i]);
1979 if (index >= 0) {
1980 *excludeConfigs.append() = index;
1981 } else {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00001982 SkDebugf("unrecognized excludeConfig %s\n", FLAGS_excludeConfig[i]);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00001983 return false;
1984 }
1985 }
1986
1987 if (outConfigs->count() == 0) {
1988 // if no config is specified by user, add the defaults
1989 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
1990 if (gRec[i].fRunByDefault) {
1991 *outConfigs->append() = i;
1992 }
1993 }
1994 }
1995 // now remove any explicitly excluded configs
1996 for (int i = 0; i < excludeConfigs.count(); ++i) {
1997 int index = outConfigs->find(excludeConfigs[i]);
1998 if (index >= 0) {
1999 outConfigs->remove(index);
2000 // now assert that there was only one copy in configs[]
2001 SkASSERT(outConfigs->find(excludeConfigs[i]) < 0);
2002 }
2003 }
2004
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002005 for (int i = 0; i < outConfigs->count(); ++i) {
2006 size_t index = (*outConfigs)[i];
2007 if (kGPU_Backend == gRec[index].fBackend) {
bsalomon69456182014-07-07 10:46:58 -07002008#if SK_SUPPORT_GPU
2009 if (!FLAGS_gpu) {
2010 outConfigs->remove(i);
2011 --i;
2012 continue;
2013 }
2014#endif
2015 } else if (!FLAGS_cpu) {
2016 outConfigs->remove(i);
2017 --i;
2018 continue;
2019 }
2020#if SK_SUPPORT_GPU
2021 SkASSERT(grFactory != NULL);
2022 if (kGPU_Backend == gRec[index].fBackend) {
kkinnunen80549fc2014-06-30 06:36:31 -07002023 GrContext* ctx = grFactory->get(gRec[index].fGLContextType, gpuAPI);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002024 if (NULL == ctx) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002025 SkDebugf("GrContext could not be created for config %s. Config will be skipped.\n",
2026 gRec[index].fName);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002027 outConfigs->remove(i);
2028 --i;
2029 continue;
2030 }
2031 if (gRec[index].fSampleCnt > ctx->getMaxSampleCount()) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002032 SkDebugf("Sample count (%d) of config %s is not supported."
2033 " Config will be skipped.\n",
2034 gRec[index].fSampleCnt, gRec[index].fName);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002035 outConfigs->remove(i);
2036 --i;
2037 }
2038 }
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002039#endif
bsalomon69456182014-07-07 10:46:58 -07002040 }
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002041
2042 if (outConfigs->isEmpty()) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002043 SkDebugf("No configs to run.");
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002044 return false;
2045 }
2046
2047 // now show the user the set of configs that will be run.
2048 SkString configStr("These configs will be run:");
2049 // show the user the config that will run.
2050 for (int i = 0; i < outConfigs->count(); ++i) {
2051 configStr.appendf(" %s", gRec[(*outConfigs)[i]].fName);
2052 }
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002053 SkDebugf("%s\n", configStr.c_str());
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002054
2055 return true;
2056}
2057
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002058static bool parse_flags_pdf_rasterizers(const SkTDArray<size_t>& configs,
2059 SkTDArray<const PDFRasterizerData*>* outRasterizers) {
2060 // No need to run this check (and display the PDF rasterizers message)
2061 // if no PDF backends are in the configs.
2062 bool configHasPDF = false;
2063 for (int i = 0; i < configs.count(); i++) {
2064 if (gRec[configs[i]].fBackend == kPDF_Backend) {
2065 configHasPDF = true;
2066 break;
2067 }
2068 }
2069 if (!configHasPDF) {
2070 return true;
2071 }
2072
vandebo@chromium.orgf8afb2b2013-11-06 16:32:15 +00002073 if (FLAGS_pdfRasterizers.count() == 1 &&
2074 !strcmp(FLAGS_pdfRasterizers[0], "default")) {
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002075 for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); ++i) {
2076 if (kPDFRasterizers[i].fRunByDefault) {
2077 *outRasterizers->append() = &kPDFRasterizers[i];
2078 }
2079 }
vandebo@chromium.orgf8afb2b2013-11-06 16:32:15 +00002080 } else {
2081 for (int i = 0; i < FLAGS_pdfRasterizers.count(); i++) {
2082 const char* rasterizer = FLAGS_pdfRasterizers[i];
2083 const PDFRasterizerData* rasterizerPtr =
2084 findPDFRasterizer(rasterizer);
2085 if (rasterizerPtr == NULL) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002086 SkDebugf("unrecognized rasterizer %s\n", rasterizer);
vandebo@chromium.orgf8afb2b2013-11-06 16:32:15 +00002087 return false;
2088 }
2089 appendUnique<const PDFRasterizerData*>(outRasterizers,
2090 rasterizerPtr);
2091 }
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002092 }
2093
2094 // now show the user the set of configs that will be run.
2095 SkString configStr("These PDF rasterizers will be run:");
2096 // show the user the config that will run.
2097 for (int i = 0; i < outRasterizers->count(); ++i) {
2098 configStr.appendf(" %s", (*outRasterizers)[i]->fName);
2099 }
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002100 SkDebugf("%s\n", configStr.c_str());
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002101
2102 return true;
2103}
2104
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002105static bool parse_flags_ignore_error_types(ErrorCombination* outErrorTypes) {
2106 if (FLAGS_ignoreErrorTypes.count() > 0) {
2107 *outErrorTypes = ErrorCombination();
2108 for (int i = 0; i < FLAGS_ignoreErrorTypes.count(); i++) {
2109 ErrorType type;
2110 const char *name = FLAGS_ignoreErrorTypes[i];
2111 if (!getErrorTypeByName(name, &type)) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002112 SkDebugf("cannot find ErrorType with name '%s'\n", name);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002113 return false;
2114 } else {
2115 outErrorTypes->add(type);
2116 }
2117 }
2118 }
2119 return true;
2120}
2121
epoger@google.com3a882dd2013-10-07 18:55:09 +00002122/**
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +00002123 * Replace contents of ignoreTestNames with a list of test names, indicating
epoger@google.com3a882dd2013-10-07 18:55:09 +00002124 * which tests' failures should be ignored.
2125 */
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +00002126static bool parse_flags_ignore_tests(SkTArray<SkString> &ignoreTestNames) {
2127 ignoreTestNames.reset();
epoger@google.comf711f322013-10-18 14:55:47 +00002128
epoger@google.comf711f322013-10-18 14:55:47 +00002129 // Parse --ignoreFailuresFile
2130 for (int i = 0; i < FLAGS_ignoreFailuresFile.count(); i++) {
2131 SkTArray<SkString> linesFromFile;
2132 if (!read_lines_from_file(FLAGS_ignoreFailuresFile[i], linesFromFile)) {
2133 return false;
2134 } else {
2135 for (int j = 0; j < linesFromFile.count(); j++) {
2136 SkString thisLine = linesFromFile[j];
2137 if (thisLine.isEmpty() || thisLine.startsWith('#')) {
2138 // skip this line
2139 } else {
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +00002140 ignoreTestNames.push_back(thisLine);
epoger@google.comf711f322013-10-18 14:55:47 +00002141 }
2142 }
2143 }
2144 }
2145
epoger@google.com3a882dd2013-10-07 18:55:09 +00002146 return true;
2147}
2148
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002149static bool parse_flags_modulo(int* moduloRemainder, int* moduloDivisor) {
2150 if (FLAGS_modulo.count() == 2) {
2151 *moduloRemainder = atoi(FLAGS_modulo[0]);
2152 *moduloDivisor = atoi(FLAGS_modulo[1]);
2153 if (*moduloRemainder < 0 || *moduloDivisor <= 0 ||
2154 *moduloRemainder >= *moduloDivisor) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002155 SkDebugf("invalid modulo values.");
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002156 return false;
2157 }
2158 }
2159 return true;
2160}
2161
2162#if SK_SUPPORT_GPU
2163static bool parse_flags_gpu_cache(int* sizeBytes, int* sizeCount) {
2164 if (FLAGS_gpuCacheSize.count() > 0) {
2165 if (FLAGS_gpuCacheSize.count() != 2) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002166 SkDebugf("--gpuCacheSize requires two arguments\n");
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002167 return false;
2168 }
2169 *sizeBytes = atoi(FLAGS_gpuCacheSize[0]);
2170 *sizeCount = atoi(FLAGS_gpuCacheSize[1]);
2171 } else {
2172 *sizeBytes = DEFAULT_CACHE_VALUE;
2173 *sizeCount = DEFAULT_CACHE_VALUE;
2174 }
2175 return true;
2176}
kkinnunen80549fc2014-06-30 06:36:31 -07002177
2178static bool parse_flags_gl_standard(GrGLStandard* gpuAPI) {
2179 if (0 == FLAGS_gpuAPI.count()) {
2180 *gpuAPI = kNone_GrGLStandard;
2181 return true;
2182 }
2183 if (1 == FLAGS_gpuAPI.count()) {
2184 if (FLAGS_gpuAPI.contains(kGpuAPINameGL)) {
2185 *gpuAPI = kGL_GrGLStandard;
2186 return true;
2187 }
2188 if (FLAGS_gpuAPI.contains(kGpuAPINameGLES)) {
2189 *gpuAPI = kGLES_GrGLStandard;
2190 return true;
2191 }
2192 }
2193 SkDebugf("--gpuAPI invalid api value");
2194 return false;
2195}
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002196#endif
2197
2198static bool parse_flags_tile_grid_replay_scales(SkTDArray<SkScalar>* outScales) {
2199 *outScales->append() = SK_Scalar1; // By default only test at scale 1.0
2200 if (FLAGS_tileGridReplayScales.count() > 0) {
2201 outScales->reset();
2202 for (int i = 0; i < FLAGS_tileGridReplayScales.count(); i++) {
2203 double val = atof(FLAGS_tileGridReplayScales[i]);
2204 if (0 < val) {
2205 *outScales->append() = SkDoubleToScalar(val);
2206 }
2207 }
2208 if (0 == outScales->count()) {
2209 // Should have at least one scale
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002210 SkDebugf("--tileGridReplayScales requires at least one scale.\n");
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002211 return false;
2212 }
2213 }
2214 return true;
2215}
2216
2217static bool parse_flags_gmmain_paths(GMMain* gmmain) {
2218 gmmain->fUseFileHierarchy = FLAGS_hierarchy;
2219 gmmain->fWriteChecksumBasedFilenames = FLAGS_writeChecksumBasedFilenames;
2220
2221 if (FLAGS_mismatchPath.count() == 1) {
2222 gmmain->fMismatchPath = FLAGS_mismatchPath[0];
2223 }
2224
2225 if (FLAGS_missingExpectationsPath.count() == 1) {
2226 gmmain->fMissingExpectationsPath = FLAGS_missingExpectationsPath[0];
2227 }
2228
2229 if (FLAGS_readPath.count() == 1) {
2230 const char* readPath = FLAGS_readPath[0];
2231 if (!sk_exists(readPath)) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002232 SkDebugf("readPath %s does not exist!\n", readPath);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002233 return false;
2234 }
2235 if (sk_isdir(readPath)) {
2236 if (FLAGS_verbose) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002237 SkDebugf("reading from %s\n", readPath);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002238 }
2239 gmmain->fExpectationsSource.reset(SkNEW_ARGS(
2240 IndividualImageExpectationsSource, (readPath)));
2241 } else {
2242 if (FLAGS_verbose) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002243 SkDebugf("reading expectations from JSON summary file %s\n", readPath);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002244 }
2245 gmmain->fExpectationsSource.reset(SkNEW_ARGS(JsonExpectationsSource, (readPath)));
2246 }
2247 }
2248 return true;
2249}
2250
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002251static bool parse_flags_jpeg_quality() {
2252 if (FLAGS_pdfJpegQuality < -1 || FLAGS_pdfJpegQuality > 100) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002253 SkDebugf("%s\n", "pdfJpegQuality must be in [-1 .. 100] range.");
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002254 return false;
2255 }
2256 return true;
2257}
2258
epoger@google.com0b62b3d2013-03-20 17:59:28 +00002259int tool_main(int argc, char** argv);
2260int tool_main(int argc, char** argv) {
mtklein30e6e2a2014-06-18 11:44:15 -07002261 SetupCrashHandler();
epoger@google.com0b62b3d2013-03-20 17:59:28 +00002262
commit-bot@chromium.org6dda8272014-01-23 17:21:19 +00002263 SkString usage;
2264 usage.printf("Run the golden master tests.\n");
2265 SkCommandLineFlags::SetUsage(usage.c_str());
2266 SkCommandLineFlags::Parse(argc, argv);
2267
epoger@google.com0b62b3d2013-03-20 17:59:28 +00002268#if SK_ENABLE_INST_COUNT
commit-bot@chromium.org6dda8272014-01-23 17:21:19 +00002269 if (FLAGS_leaks) {
2270 gPrintInstCount = true;
2271 }
epoger@google.com0b62b3d2013-03-20 17:59:28 +00002272#endif
2273
2274 SkGraphics::Init();
epoger@google.com0b62b3d2013-03-20 17:59:28 +00002275
2276 setSystemPreferences();
2277 GMMain gmmain;
2278
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002279 SkTDArray<size_t> configs;
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002280
scroggo@google.com09fd4d22013-03-20 14:20:18 +00002281 int moduloRemainder = -1;
2282 int moduloDivisor = -1;
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002283 SkTDArray<const PDFRasterizerData*> pdfRasterizers;
epoger@google.com6f6568b2013-03-22 17:29:46 +00002284 SkTDArray<SkScalar> tileGridReplayScales;
bsalomon@google.com4c75f242013-03-19 18:58:43 +00002285#if SK_SUPPORT_GPU
kkinnunen80549fc2014-06-30 06:36:31 -07002286 GrGLStandard gpuAPI = kNone_GrGLStandard;
bsalomon@google.com4c75f242013-03-19 18:58:43 +00002287 GrContextFactory* grFactory = new GrContextFactory;
epoger@google.com80724df2013-03-21 13:49:54 +00002288#else
kkinnunen80549fc2014-06-30 06:36:31 -07002289 GrGLStandard gpuAPI = 0;
epoger@google.com80724df2013-03-21 13:49:54 +00002290 GrContextFactory* grFactory = NULL;
bsalomon@google.com4c75f242013-03-19 18:58:43 +00002291#endif
2292
commit-bot@chromium.orgb17ccc92014-03-13 16:16:36 +00002293 if (FLAGS_dryRun) {
2294 SkDebugf( "Doing a dry run; no tests will actually be executed.\n");
2295 }
2296
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002297 if (!parse_flags_modulo(&moduloRemainder, &moduloDivisor) ||
2298 !parse_flags_ignore_error_types(&gmmain.fIgnorableErrorTypes) ||
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +00002299 !parse_flags_ignore_tests(gmmain.fIgnorableTestNames) ||
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002300#if SK_SUPPORT_GPU
2301 !parse_flags_gpu_cache(&gGpuCacheSizeBytes, &gGpuCacheSizeCount) ||
kkinnunen80549fc2014-06-30 06:36:31 -07002302 !parse_flags_gl_standard(&gpuAPI) ||
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002303#endif
2304 !parse_flags_tile_grid_replay_scales(&tileGridReplayScales) ||
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002305 !parse_flags_jpeg_quality() ||
kkinnunen80549fc2014-06-30 06:36:31 -07002306 !parse_flags_configs(&configs, grFactory, gpuAPI) ||
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002307 !parse_flags_pdf_rasterizers(configs, &pdfRasterizers) ||
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002308 !parse_flags_gmmain_paths(&gmmain)) {
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00002309 return -1;
2310 }
2311
epoger@google.comb0f8b432013-04-10 18:46:25 +00002312 if (FLAGS_verbose) {
2313 if (FLAGS_writePath.count() == 1) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002314 SkDebugf("writing to %s\n", FLAGS_writePath[0]);
epoger@google.comb0f8b432013-04-10 18:46:25 +00002315 }
epoger@google.comfdea3252013-05-02 18:24:03 +00002316 if (NULL != gmmain.fMismatchPath) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002317 SkDebugf("writing mismatches to %s\n", gmmain.fMismatchPath);
epoger@google.comfdea3252013-05-02 18:24:03 +00002318 }
epoger@google.com5f995452013-06-21 18:16:47 +00002319 if (NULL != gmmain.fMissingExpectationsPath) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002320 SkDebugf("writing images without expectations to %s\n",
2321 gmmain.fMissingExpectationsPath);
epoger@google.com5f995452013-06-21 18:16:47 +00002322 }
epoger@google.comb0f8b432013-04-10 18:46:25 +00002323 if (FLAGS_writePicturePath.count() == 1) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002324 SkDebugf("writing pictures to %s\n", FLAGS_writePicturePath[0]);
epoger@google.comb0f8b432013-04-10 18:46:25 +00002325 }
tfarinabcbc1782014-06-18 14:32:48 -07002326 if (!GetResourcePath().isEmpty()) {
2327 SkDebugf("reading resources from %s\n", GetResourcePath().c_str());
epoger@google.comb0f8b432013-04-10 18:46:25 +00002328 }
robertphillips@google.com8570b5c2012-03-20 17:40:58 +00002329 }
2330
epoger@google.com310478e2013-04-03 18:00:39 +00002331 int gmsRun = 0;
reed@google.comae7b8f32012-10-18 21:30:57 +00002332 int gmIndex = -1;
2333 SkString moduloStr;
2334
commit-bot@chromium.orgb17ccc92014-03-13 16:16:36 +00002335 if (!FLAGS_dryRun) {
2336 // If we will be writing out files, prepare subdirectories.
2337 if (FLAGS_writePath.count() == 1) {
2338 if (!prepare_subdirectories(FLAGS_writePath[0], gmmain.fUseFileHierarchy,
2339 configs, pdfRasterizers)) {
2340 return -1;
2341 }
2342 }
2343 if (NULL != gmmain.fMismatchPath) {
2344 if (!prepare_subdirectories(gmmain.fMismatchPath, gmmain.fUseFileHierarchy,
2345 configs, pdfRasterizers)) {
2346 return -1;
2347 }
2348 }
2349 if (NULL != gmmain.fMissingExpectationsPath) {
2350 if (!prepare_subdirectories(gmmain.fMissingExpectationsPath, gmmain.fUseFileHierarchy,
2351 configs, pdfRasterizers)) {
2352 return -1;
2353 }
epoger@google.come8ebeb12012-10-29 16:42:11 +00002354 }
epoger@google.comfdea3252013-05-02 18:24:03 +00002355 }
bsalomon@google.com7361f542012-04-19 19:15:35 +00002356 Iter iter;
2357 GM* gm;
reed@android.com00dae862009-06-10 15:38:48 +00002358 while ((gm = iter.next()) != NULL) {
commit-bot@chromium.orgf4f9df42013-09-26 20:44:24 +00002359 if (FLAGS_forcePerspectiveMatrix) {
2360 SkMatrix perspective;
2361 perspective.setIdentity();
2362 perspective.setPerspY(SkScalarDiv(SK_Scalar1, SkIntToScalar(1000)));
2363 perspective.setSkewX(SkScalarDiv(SkIntToScalar(8),
2364 SkIntToScalar(25)));
2365
2366 gm->setStarterMatrix(perspective);
skia.committer@gmail.com65caeaf2013-09-27 07:01:29 +00002367 }
scroggo@google.com7fd2d702013-04-16 19:11:14 +00002368 SkAutoTDelete<GM> adgm(gm);
reed@google.comae7b8f32012-10-18 21:30:57 +00002369 ++gmIndex;
epoger@google.com82cb65b2012-10-29 18:59:17 +00002370 if (moduloRemainder >= 0) {
2371 if ((gmIndex % moduloDivisor) != moduloRemainder) {
reed@google.comae7b8f32012-10-18 21:30:57 +00002372 continue;
2373 }
epoger@google.com82cb65b2012-10-29 18:59:17 +00002374 moduloStr.printf("[%d.%d] ", gmIndex, moduloDivisor);
reed@google.comae7b8f32012-10-18 21:30:57 +00002375 }
2376
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00002377 const char* shortName = gm->getName();
sglez@google.com586db932013-07-24 17:24:23 +00002378
commit-bot@chromium.orga6f37e72013-08-30 15:52:46 +00002379 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, shortName)) {
reed@google.comece2b022011-07-25 14:28:57 +00002380 continue;
2381 }
2382
epoger@google.com310478e2013-04-03 18:00:39 +00002383 gmsRun++;
tomhudson@google.com9875dd12011-04-25 15:49:53 +00002384 SkISize size = gm->getISize();
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002385 SkDebugf("%sdrawing... %s [%d %d]\n", moduloStr.c_str(), shortName,
2386 size.width(), size.height());
commit-bot@chromium.orgb17ccc92014-03-13 16:16:36 +00002387 if (!FLAGS_dryRun)
kkinnunen80549fc2014-06-30 06:36:31 -07002388 run_multiple_configs(gmmain, gm, configs, pdfRasterizers, tileGridReplayScales,
2389 grFactory, gpuAPI);
reed@android.com00dae862009-06-10 15:38:48 +00002390 }
epoger@google.com310478e2013-04-03 18:00:39 +00002391
commit-bot@chromium.orgb17ccc92014-03-13 16:16:36 +00002392 if (FLAGS_dryRun)
2393 return 0;
2394
epoger@google.com310478e2013-04-03 18:00:39 +00002395 SkTArray<SkString> modes;
2396 gmmain.GetRenderModesEncountered(modes);
commit-bot@chromium.org85195482014-01-13 18:27:59 +00002397 int modeCount = modes.count();
2398
2399 // Now that we have run all the tests and thus know the full set of renderModes that we
2400 // tried to run, we can call RecordTestResults() to record the cases in which we skipped
2401 // ALL renderModes.
2402 // See http://skbug.com/1994 and https://codereview.chromium.org/129203002/
2403 int testCount = gmmain.fTestsSkippedOnAllRenderModes.count();
2404 for (int testNum = 0; testNum < testCount; ++testNum) {
2405 const SkString &shortNamePlusConfig = gmmain.fTestsSkippedOnAllRenderModes[testNum];
2406 for (int modeNum = 0; modeNum < modeCount; ++modeNum) {
2407 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
2408 modes[modeNum].c_str());
2409 }
2410 }
2411
epoger@google.comc8263e72013-04-10 12:17:34 +00002412 bool reportError = false;
2413 if (gmmain.NumSignificantErrors() > 0) {
2414 reportError = true;
2415 }
commit-bot@chromium.org85195482014-01-13 18:27:59 +00002416
2417 // We test every GM against every config, and for every raster config also test every mode.
2418 int rasterConfigs = 0;
2419 for (int i = 0; i < configs.count(); i++) {
2420 if (gRec[configs[i]].fBackend == kRaster_Backend) {
2421 rasterConfigs++;
2422 }
2423 }
2424 // For raster configs, we run all renderModes; for non-raster configs, just default renderMode
2425 const int expectedNumberOfTests = rasterConfigs * gmsRun * modeCount
2426 + (configs.count() - rasterConfigs) * gmsRun;
epoger@google.com310478e2013-04-03 18:00:39 +00002427
2428 // Output summary to stdout.
epoger@google.com51dbabe2013-04-10 15:24:53 +00002429 if (FLAGS_verbose) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002430 SkDebugf("Ran %d GMs\n", gmsRun);
2431 SkDebugf("... over %2d configs [%s]\n", configs.count(),
2432 list_all_config_names(configs).c_str());
2433 SkDebugf("... and %2d modes [%s]\n", modeCount, list_all(modes).c_str());
2434 SkDebugf("... so there should be a total of %d tests.\n", expectedNumberOfTests);
epoger@google.com51dbabe2013-04-10 15:24:53 +00002435 }
2436 gmmain.ListErrors(FLAGS_verbose);
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00002437
epoger@google.com07947d92013-04-11 15:41:02 +00002438 // TODO(epoger): Enable this check for Android, too, once we resolve
2439 // https://code.google.com/p/skia/issues/detail?id=1222
2440 // ('GM is unexpectedly skipping tests on Android')
2441#ifndef SK_BUILD_FOR_ANDROID
epoger@google.comc8263e72013-04-10 12:17:34 +00002442 if (expectedNumberOfTests != gmmain.fTestsRun) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002443 SkDebugf("expected %d tests, but ran or skipped %d tests\n",
2444 expectedNumberOfTests, gmmain.fTestsRun);
epoger@google.comc8263e72013-04-10 12:17:34 +00002445 reportError = true;
2446 }
2447#endif
2448
scroggo@google.com09fd4d22013-03-20 14:20:18 +00002449 if (FLAGS_writeJsonSummaryPath.count() == 1) {
epoger@google.com76c913d2013-04-26 15:06:44 +00002450 Json::Value root = CreateJsonTree(
2451 gmmain.fJsonExpectedResults,
2452 gmmain.fJsonActualResults_Failed, gmmain.fJsonActualResults_FailureIgnored,
2453 gmmain.fJsonActualResults_NoComparison, gmmain.fJsonActualResults_Succeeded);
epoger@google.comee8a8e32012-12-18 19:13:49 +00002454 std::string jsonStdString = root.toStyledString();
scroggo@google.com09fd4d22013-03-20 14:20:18 +00002455 SkFILEWStream stream(FLAGS_writeJsonSummaryPath[0]);
epoger@google.comee8a8e32012-12-18 19:13:49 +00002456 stream.write(jsonStdString.c_str(), jsonStdString.length());
2457 }
2458
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00002459#if SK_SUPPORT_GPU
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00002460
robertphillips@google.com59552022012-08-31 13:07:37 +00002461#if GR_CACHE_STATS
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00002462 for (int i = 0; i < configs.count(); i++) {
2463 ConfigData config = gRec[configs[i]];
2464
epoger@google.comb0f8b432013-04-10 18:46:25 +00002465 if (FLAGS_verbose && (kGPU_Backend == config.fBackend)) {
kkinnunen80549fc2014-06-30 06:36:31 -07002466 GrContext* gr = grFactory->get(config.fGLContextType, gpuAPI);
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00002467
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002468 SkDebugf("config: %s %x\n", config.fName, gr);
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00002469 gr->printCacheStats();
2470 }
2471 }
2472#endif
2473
commit-bot@chromium.org8065ec52014-03-11 15:57:40 +00002474#if GR_DUMP_FONT_CACHE
2475 for (int i = 0; i < configs.count(); i++) {
2476 ConfigData config = gRec[configs[i]];
2477
2478 if (kGPU_Backend == config.fBackend) {
kkinnunen80549fc2014-06-30 06:36:31 -07002479 GrContext* gr = grFactory->get(config.fGLContextType, gpuAPI);
commit-bot@chromium.org8065ec52014-03-11 15:57:40 +00002480
2481 gr->dumpFontCache();
2482 }
2483 }
2484#endif
2485
robertphillips@google.com977b9c82012-06-05 19:35:09 +00002486 delete grFactory;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00002487#endif
robertphillips@google.com977b9c82012-06-05 19:35:09 +00002488 SkGraphics::Term();
2489
epoger@google.comc8263e72013-04-10 12:17:34 +00002490 return (reportError) ? -1 : 0;
reed@android.com00dae862009-06-10 15:38:48 +00002491}
caryclark@google.com5987f582012-10-02 18:33:14 +00002492
scroggo@google.com09fd4d22013-03-20 14:20:18 +00002493void GMMain::installFilter(SkCanvas* canvas) {
2494 if (FLAGS_forceBWtext) {
2495 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref();
2496 }
2497}
2498
borenet@google.com7158e6a2012-11-01 17:43:44 +00002499#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
caryclark@google.com5987f582012-10-02 18:33:14 +00002500int main(int argc, char * const argv[]) {
2501 return tool_main(argc, (char**) argv);
2502}
2503#endif