blob: 8f6d53a25530efd509d3ae3b3d48e5d1a4ffade7 [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"
mtkleinafb43792014-08-19 15:55:55 -070021#include "ProcStats.h"
tfarinabcbc1782014-06-18 14:32:48 -070022#include "Resources.h"
23#include "SamplePipeControllers.h"
epoger@google.com5f6a0072013-01-31 16:30:55 +000024#include "SkBitmap.h"
reed@android.comb9b9a182009-07-08 02:54:47 +000025#include "SkColorPriv.h"
scroggo@google.comd9ba9a02013-03-21 19:43:15 +000026#include "SkCommandLineFlags.h"
reed@google.com8a85d0c2011-06-24 19:12:12 +000027#include "SkData.h"
junov@google.com4370aed2012-01-18 16:21:08 +000028#include "SkDeferredCanvas.h"
bsalomon@google.com971d0c82011-08-19 17:22:05 +000029#include "SkDevice.h"
commit-bot@chromium.org5e009892013-10-14 13:42:12 +000030#include "SkDocument.h"
epoger@google.comde961632012-10-26 18:56:36 +000031#include "SkDrawFilter.h"
commit-bot@chromium.orgc41295d2013-06-18 20:06:36 +000032#include "SkForceLinking.h"
scroggo@google.com5af9b202012-06-04 17:17:36 +000033#include "SkGPipe.h"
reed@android.com8015dd82009-06-21 00:49:18 +000034#include "SkGraphics.h"
35#include "SkImageDecoder.h"
36#include "SkImageEncoder.h"
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +000037#include "SkJSONCPP.h"
robertphillips8c508b42014-12-11 13:10:23 -080038#include "SkMultiPictureDraw.h"
epoger@google.come8ebeb12012-10-29 16:42:11 +000039#include "SkOSFile.h"
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +000040#include "SkPDFRasterizer.h"
tomhudson@google.com9875dd12011-04-25 15:49:53 +000041#include "SkPicture.h"
robertphillips@google.com770963f2014-04-18 18:04:41 +000042#include "SkPictureRecorder.h"
robertphillips@google.com977b9c82012-06-05 19:35:09 +000043#include "SkRefCnt.h"
commit-bot@chromium.org5e009892013-10-14 13:42:12 +000044#include "SkScalar.h"
scroggo@google.com72c96722012-06-06 21:07:10 +000045#include "SkStream.h"
epoger@google.comf711f322013-10-18 14:55:47 +000046#include "SkString.h"
reed@google.com11db6fa2014-02-04 15:30:57 +000047#include "SkSurface.h"
bsalomon@google.com2a48c3a2012-08-03 14:54:45 +000048#include "SkTArray.h"
epoger@google.com310478e2013-04-03 18:00:39 +000049#include "SkTDict.h"
reed@google.com07700442010-12-20 19:46:07 +000050
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000051#ifdef SK_DEBUG
52static const bool kDebugOnly = true;
commit-bot@chromium.org8065ec52014-03-11 15:57:40 +000053#define GR_DUMP_FONT_CACHE 0
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000054#else
55static const bool kDebugOnly = false;
56#endif
57
epoger@google.comed5eb4e2013-07-23 17:56:20 +000058__SK_FORCE_IMAGE_DECODER_LINKING;
59
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000060#if SK_SUPPORT_GPU
61#include "GrContextFactory.h"
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000062#include "SkGpuDevice.h"
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000063typedef GrContextFactory::GLContextType GLContextType;
epoger@google.com6f6568b2013-03-22 17:29:46 +000064#define DEFAULT_CACHE_VALUE -1
65static int gGpuCacheSizeBytes;
66static int gGpuCacheSizeCount;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000067#else
epoger@google.com80724df2013-03-21 13:49:54 +000068class GrContextFactory;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000069class GrContext;
bsalomon@google.com123ac1d2013-03-28 19:18:12 +000070class GrSurface;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000071typedef int GLContextType;
kkinnunen80549fc2014-06-30 06:36:31 -070072typedef int GrGLStandard;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000073#endif
74
epoger@google.com76c913d2013-04-26 15:06:44 +000075#define DEBUGFAIL_SEE_STDERR SkDEBUGFAIL("see stderr for message")
76
caryclarkac8d8b82015-01-07 07:36:52 -080077DECLARE_bool(useDocumentInsteadOfDevice);
78
79#ifdef SK_SUPPORT_PDF
80 #include "SkPDFDevice.h"
81 #include "SkPDFDocument.h"
82#endif
83
epoger@google.come3cc2eb2012-01-18 20:11:13 +000084// Until we resolve http://code.google.com/p/skia/issues/detail?id=455 ,
85// stop writing out XPS-format image baselines in gm.
86#undef SK_SUPPORT_XPS
bungeman@google.comb29c8832011-10-10 13:19:10 +000087#ifdef SK_SUPPORT_XPS
88 #include "SkXPSDevice.h"
89#endif
90
reed@google.com46cce912011-06-29 12:54:46 +000091#ifdef SK_BUILD_FOR_MAC
92 #include "SkCGUtils.h"
reed@google.com46cce912011-06-29 12:54:46 +000093#endif
94
reed@android.com00dae862009-06-10 15:38:48 +000095using namespace skiagm;
96
reed@android.com00dae862009-06-10 15:38:48 +000097class Iter {
98public:
99 Iter() {
bsalomon@google.com39149582011-06-13 21:55:32 +0000100 this->reset();
101 }
102
103 void reset() {
reed@android.comdd0ac282009-06-20 02:38:16 +0000104 fReg = GMRegistry::Head();
reed@android.com00dae862009-06-10 15:38:48 +0000105 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000106
reed@android.comdd0ac282009-06-20 02:38:16 +0000107 GM* next() {
reed@android.com00dae862009-06-10 15:38:48 +0000108 if (fReg) {
reed@android.comdd0ac282009-06-20 02:38:16 +0000109 GMRegistry::Factory fact = fReg->factory();
reed@android.com00dae862009-06-10 15:38:48 +0000110 fReg = fReg->next();
reed@android.comdd0ac282009-06-20 02:38:16 +0000111 return fact(0);
reed@android.com00dae862009-06-10 15:38:48 +0000112 }
113 return NULL;
114 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000115
reed@android.com00dae862009-06-10 15:38:48 +0000116 static int Count() {
reed@android.comdd0ac282009-06-20 02:38:16 +0000117 const GMRegistry* reg = GMRegistry::Head();
reed@android.com00dae862009-06-10 15:38:48 +0000118 int count = 0;
119 while (reg) {
120 count += 1;
121 reg = reg->next();
122 }
123 return count;
124 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000125
reed@android.com00dae862009-06-10 15:38:48 +0000126private:
127 const GMRegistry* fReg;
128};
129
epoger@google.comce057fe2013-05-14 15:17:46 +0000130// TODO(epoger): Right now, various places in this code assume that all the
131// image files read/written by GM use this file extension.
132// Search for references to this constant to find these assumptions.
133const static char kPNG_FileExtension[] = "png";
134
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000135enum Backend {
junov@chromium.org3cb834b2012-12-13 16:39:53 +0000136 kRaster_Backend,
137 kGPU_Backend,
138 kPDF_Backend,
139 kXPS_Backend,
140};
141
142enum BbhType {
143 kNone_BbhType,
144 kRTree_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),
jvanverth4736e142014-11-07 07:12:46 -0800154 /* Use distance fields for rendering text */
155 kDFText_ConfigFlag = 0x4,
156 kRWDFT_ConfigFlag = (kRW_ConfigFlag | kDFText_ConfigFlag),
bsalomon@google.com7361f542012-04-19 19:15:35 +0000157};
158
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000159struct ConfigData {
reedddd014e2014-06-05 08:51:20 -0700160 SkColorType fColorType;
bsalomon@google.com7361f542012-04-19 19:15:35 +0000161 Backend fBackend;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000162 GLContextType fGLContextType; // GPU backend only
bsalomon@google.com7361f542012-04-19 19:15:35 +0000163 int fSampleCnt; // GPU backend only
164 ConfigFlags fFlags;
165 const char* fName;
bsalomon@google.com4c75f242013-03-19 18:58:43 +0000166 bool fRunByDefault;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000167};
168
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000169struct PDFRasterizerData {
170 bool (*fRasterizerFunction)(SkStream*, SkBitmap*);
171 const char* fName;
172 bool fRunByDefault;
173};
174
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000175class BWTextDrawFilter : public SkDrawFilter {
176public:
mtklein72c9faa2015-01-09 10:06:39 -0800177 bool filter(SkPaint*, Type) SK_OVERRIDE;
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000178};
reed@google.com971aca72012-11-26 20:26:54 +0000179bool BWTextDrawFilter::filter(SkPaint* p, Type t) {
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000180 if (kText_Type == t) {
181 p->setAntiAlias(false);
182 }
reed@google.com971aca72012-11-26 20:26:54 +0000183 return true;
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000184}
185
scroggo@google.com565254b2012-06-28 15:41:32 +0000186struct PipeFlagComboData {
187 const char* name;
188 uint32_t flags;
189};
190
191static PipeFlagComboData gPipeWritingFlagCombos[] = {
192 { "", 0 },
193 { " cross-process", SkGPipeWriter::kCrossProcess_Flag },
scroggob3c0f482012-07-02 19:07:57 +0000194 { " cross-process, shared address", SkGPipeWriter::kCrossProcess_Flag
scroggo@google.com15011ee2012-07-26 20:03:32 +0000195 | SkGPipeWriter::kSharedAddressSpace_Flag }
scroggo@google.com565254b2012-06-28 15:41:32 +0000196};
197
commit-bot@chromium.org608ea652013-10-03 19:29:21 +0000198static SkData* encode_to_dct_data(size_t* pixelRefOffset, const SkBitmap& bitmap);
edisonn@google.com73a7ea32013-11-11 20:55:15 +0000199DECLARE_int32(pdfRasterDpi);
edisonn@google.comd9dfa182013-04-24 13:01:01 +0000200
epoger@google.com5079d2c2013-04-12 14:11:21 +0000201const static ErrorCombination kDefaultIgnorableErrorTypes = ErrorCombination()
202 .plus(kMissingExpectations_ErrorType)
203 .plus(kIntentionallySkipped_ErrorType);
204
epoger@google.comde961632012-10-26 18:56:36 +0000205class GMMain {
206public:
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000207 GMMain() : fUseFileHierarchy(false), fWriteChecksumBasedFilenames(false),
208 fIgnorableErrorTypes(kDefaultIgnorableErrorTypes),
epoger@google.com5f995452013-06-21 18:16:47 +0000209 fMismatchPath(NULL), fMissingExpectationsPath(NULL), fTestsRun(0),
210 fRenderModesEncountered(1) {}
epoger@google.come8ebeb12012-10-29 16:42:11 +0000211
epoger@google.com659c8c02013-05-21 15:45:45 +0000212 /**
213 * Assemble shortNamePlusConfig from (surprise!) shortName and configName.
214 *
215 * The method for doing so depends on whether we are using hierarchical naming.
216 * For example, shortName "selftest1" and configName "8888" could be assembled into
217 * either "selftest1_8888" or "8888/selftest1".
218 */
219 SkString make_shortname_plus_config(const char *shortName, const char *configName) {
epoger@google.come8ebeb12012-10-29 16:42:11 +0000220 SkString name;
epoger@google.com57f7abc2012-11-13 03:41:55 +0000221 if (0 == strlen(configName)) {
222 name.append(shortName);
223 } else if (fUseFileHierarchy) {
epoger@google.come8ebeb12012-10-29 16:42:11 +0000224 name.appendf("%s%c%s", configName, SkPATH_SEPARATOR, shortName);
225 } else {
226 name.appendf("%s_%s", shortName, configName);
227 }
epoger@google.comde961632012-10-26 18:56:36 +0000228 return name;
229 }
230
epoger@google.com659c8c02013-05-21 15:45:45 +0000231 /**
232 * Assemble filename, suitable for writing out the results of a particular test.
233 */
234 SkString make_filename(const char *path,
235 const char *shortName,
236 const char *configName,
237 const char *renderModeDescriptor,
238 const char *suffix) {
239 SkString filename = make_shortname_plus_config(shortName, configName);
240 filename.append(renderModeDescriptor);
241 filename.appendUnichar('.');
242 filename.append(suffix);
tfarinaa8e2e152014-07-28 19:26:58 -0700243 return SkOSPath::Join(path, filename.c_str());
epoger@google.com659c8c02013-05-21 15:45:45 +0000244 }
245
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000246 /**
247 * Assemble filename suitable for writing out an SkBitmap.
248 */
robertphillipsed313432014-12-16 09:31:42 -0800249 SkString makeBitmapFilename(const char *path,
250 const char *shortName,
251 const char *configName,
252 const char *renderModeDescriptor,
253 const GmResultDigest &bitmapDigest) {
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000254 if (fWriteChecksumBasedFilenames) {
255 SkString filename;
256 filename.append(bitmapDigest.getHashType());
257 filename.appendUnichar('_');
258 filename.append(shortName);
259 filename.appendUnichar('_');
260 filename.append(bitmapDigest.getDigestValue());
261 filename.appendUnichar('.');
262 filename.append(kPNG_FileExtension);
tfarinaa8e2e152014-07-28 19:26:58 -0700263 return SkOSPath::Join(path, filename.c_str());
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000264 } else {
265 return make_filename(path, shortName, configName, renderModeDescriptor,
266 kPNG_FileExtension);
267 }
268 }
269
epoger@google.com5f6a0072013-01-31 16:30:55 +0000270 /* since PNG insists on unpremultiplying our alpha, we take no
271 precision chances and force all pixels to be 100% opaque,
272 otherwise on compare we may not get a perfect match.
273 */
274 static void force_all_opaque(const SkBitmap& bitmap) {
commit-bot@chromium.orgdac52252014-02-17 21:21:46 +0000275 SkColorType colorType = bitmap.colorType();
276 switch (colorType) {
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000277 case kN32_SkColorType:
epoger@google.com5f6a0072013-01-31 16:30:55 +0000278 force_all_opaque_8888(bitmap);
279 break;
commit-bot@chromium.orgdac52252014-02-17 21:21:46 +0000280 case kRGB_565_SkColorType:
epoger@google.com5f6a0072013-01-31 16:30:55 +0000281 // nothing to do here; 565 bitmaps are inherently opaque
282 break;
283 default:
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000284 SkDebugf("unsupported bitmap colorType %d\n", colorType);
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000285 DEBUGFAIL_SEE_STDERR;
epoger@google.com5f6a0072013-01-31 16:30:55 +0000286 }
287 }
288
289 static void force_all_opaque_8888(const SkBitmap& bitmap) {
290 SkAutoLockPixels lock(bitmap);
291 for (int y = 0; y < bitmap.height(); y++) {
292 for (int x = 0; x < bitmap.width(); x++) {
293 *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT);
294 }
295 }
296 }
297
robertphillipsed313432014-12-16 09:31:42 -0800298 static ErrorCombination WriteBitmap(const SkString& path, const SkBitmap& bitmap) {
epoger@google.com5f6a0072013-01-31 16:30:55 +0000299 // TODO(epoger): Now that we have removed force_all_opaque()
300 // from this method, we should be able to get rid of the
301 // transformation to 8888 format also.
302 SkBitmap copy;
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000303 bitmap.copyTo(&copy, kN32_SkColorType);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000304 if (!SkImageEncoder::EncodeFile(path.c_str(), copy,
305 SkImageEncoder::kPNG_Type,
306 100)) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000307 SkDebugf("FAILED to write bitmap: %s\n", path.c_str());
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000308 return ErrorCombination(kWritingReferenceImage_ErrorType);
309 }
310 return kEmpty_ErrorCombination;
epoger@google.com5f6a0072013-01-31 16:30:55 +0000311 }
312
epoger@google.com6f6568b2013-03-22 17:29:46 +0000313 /**
epoger@google.com310478e2013-04-03 18:00:39 +0000314 * Add all render modes encountered thus far to the "modes" array.
epoger@google.com6f6568b2013-03-22 17:29:46 +0000315 */
epoger@google.com310478e2013-04-03 18:00:39 +0000316 void GetRenderModesEncountered(SkTArray<SkString> &modes) {
317 SkTDict<int>::Iter iter(this->fRenderModesEncountered);
318 const char* mode;
319 while ((mode = iter.next(NULL)) != NULL) {
320 SkString modeAsString = SkString(mode);
321 // TODO(epoger): It seems a bit silly that all of these modes were
322 // recorded with a leading "-" which we have to remove here
323 // (except for mode "", which means plain old original mode).
324 // But that's how renderModeDescriptor has been passed into
325 // compare_test_results_to_reference_bitmap() historically,
326 // and changing that now may affect other parts of our code.
327 if (modeAsString.startsWith("-")) {
328 modeAsString.remove(0, 1);
epoger@google.com310478e2013-04-03 18:00:39 +0000329 }
commit-bot@chromium.org85195482014-01-13 18:27:59 +0000330 modes.push_back(modeAsString);
epoger@google.com310478e2013-04-03 18:00:39 +0000331 }
332 }
333
334 /**
epoger@google.com3a882dd2013-10-07 18:55:09 +0000335 * Returns true if failures on this test should be ignored.
336 */
robertphillipsed313432014-12-16 09:31:42 -0800337 bool shouldIgnoreTest(const char *name) const {
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +0000338 for (int i = 0; i < fIgnorableTestNames.count(); i++) {
339 if (fIgnorableTestNames[i].equals(name)) {
epoger@google.com3a882dd2013-10-07 18:55:09 +0000340 return true;
341 }
342 }
343 return false;
344 }
345
346 /**
commit-bot@chromium.org85195482014-01-13 18:27:59 +0000347 * Calls RecordTestResults to record that we skipped a test.
348 *
349 * Depending on the backend, this may mean that we skipped a single rendermode, or all
350 * rendermodes; see http://skbug.com/1994 and https://codereview.chromium.org/129203002/
351 */
352 void RecordSkippedTest(const SkString& shortNamePlusConfig,
353 const char renderModeDescriptor [], Backend backend) {
354 if (kRaster_Backend == backend) {
355 // Skipping a test on kRaster_Backend means that we will skip ALL renderModes
356 // (as opposed to other backends, on which we only run the default renderMode).
357 //
358 // We cannot call RecordTestResults yet, because we won't know the full set of
359 // renderModes until we have run all tests.
360 fTestsSkippedOnAllRenderModes.push_back(shortNamePlusConfig);
361 } else {
362 this->RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
363 renderModeDescriptor);
364 }
365 }
366
367 /**
epoger@google.com310478e2013-04-03 18:00:39 +0000368 * Records the results of this test in fTestsRun and fFailedTests.
369 *
370 * We even record successes, and errors that we regard as
371 * "ignorable"; we can filter them out later.
372 */
epoger@google.com659c8c02013-05-21 15:45:45 +0000373 void RecordTestResults(const ErrorCombination& errorCombination,
374 const SkString& shortNamePlusConfig,
epoger@google.com310478e2013-04-03 18:00:39 +0000375 const char renderModeDescriptor []) {
376 // Things to do regardless of errorCombination.
377 fTestsRun++;
378 int renderModeCount = 0;
379 this->fRenderModesEncountered.find(renderModeDescriptor, &renderModeCount);
380 renderModeCount++;
381 this->fRenderModesEncountered.set(renderModeDescriptor, renderModeCount);
382
epoger@google.com6f6568b2013-03-22 17:29:46 +0000383 if (errorCombination.isEmpty()) {
epoger@google.com5f6a0072013-01-31 16:30:55 +0000384 return;
epoger@google.comeb066362013-03-08 09:39:36 +0000385 }
386
epoger@google.com310478e2013-04-03 18:00:39 +0000387 // Things to do only if there is some error condition.
epoger@google.com659c8c02013-05-21 15:45:45 +0000388 SkString fullName = shortNamePlusConfig;
epoger@google.comcaac3db2013-04-04 19:23:11 +0000389 fullName.append(renderModeDescriptor);
epoger@google.com310478e2013-04-03 18:00:39 +0000390 for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) {
391 ErrorType type = static_cast<ErrorType>(typeInt);
392 if (errorCombination.includes(type)) {
393 fFailedTests[type].push_back(fullName);
epoger@google.comf60494b2013-04-03 17:02:53 +0000394 }
epoger@google.comf60494b2013-04-03 17:02:53 +0000395 }
epoger@google.comf60494b2013-04-03 17:02:53 +0000396 }
397
epoger@google.com310478e2013-04-03 18:00:39 +0000398 /**
399 * Return the number of significant (non-ignorable) errors we have
400 * encountered so far.
401 */
402 int NumSignificantErrors() {
403 int significantErrors = 0;
404 for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) {
405 ErrorType type = static_cast<ErrorType>(typeInt);
epoger@google.com5079d2c2013-04-12 14:11:21 +0000406 if (!fIgnorableErrorTypes.includes(type)) {
epoger@google.com310478e2013-04-03 18:00:39 +0000407 significantErrors += fFailedTests[type].count();
408 }
409 }
410 return significantErrors;
411 }
412
413 /**
epoger@google.com51dbabe2013-04-10 15:24:53 +0000414 * Display the summary of results with this ErrorType.
415 *
416 * @param type which ErrorType
417 * @param verbose whether to be all verbose about it
epoger@google.com310478e2013-04-03 18:00:39 +0000418 */
epoger@google.com51dbabe2013-04-10 15:24:53 +0000419 void DisplayResultTypeSummary(ErrorType type, bool verbose) {
epoger@google.com5079d2c2013-04-12 14:11:21 +0000420 bool isIgnorableType = fIgnorableErrorTypes.includes(type);
epoger@google.com51dbabe2013-04-10 15:24:53 +0000421
422 SkString line;
423 if (isIgnorableType) {
424 line.append("[ ] ");
425 } else {
426 line.append("[*] ");
427 }
428
429 SkTArray<SkString> *failedTestsOfThisType = &fFailedTests[type];
430 int count = failedTestsOfThisType->count();
431 line.appendf("%d %s", count, getErrorTypeName(type));
432 if (!isIgnorableType || verbose) {
433 line.append(":");
434 for (int i = 0; i < count; ++i) {
435 line.append(" ");
436 line.append((*failedTestsOfThisType)[i]);
437 }
438 }
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000439 SkDebugf("%s\n", line.c_str());
epoger@google.com51dbabe2013-04-10 15:24:53 +0000440 }
441
442 /**
443 * List contents of fFailedTests to stdout.
444 *
445 * @param verbose whether to be all verbose about it
446 */
447 void ListErrors(bool verbose) {
epoger@google.com310478e2013-04-03 18:00:39 +0000448 // First, print a single summary line.
449 SkString summary;
450 summary.appendf("Ran %d tests:", fTestsRun);
451 for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) {
452 ErrorType type = static_cast<ErrorType>(typeInt);
453 summary.appendf(" %s=%d", getErrorTypeName(type), fFailedTests[type].count());
454 }
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000455 SkDebugf("%s\n", summary.c_str());
epoger@google.com310478e2013-04-03 18:00:39 +0000456
457 // Now, for each failure type, list the tests that failed that way.
458 for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) {
epoger@google.com51dbabe2013-04-10 15:24:53 +0000459 this->DisplayResultTypeSummary(static_cast<ErrorType>(typeInt), verbose);
epoger@google.com310478e2013-04-03 18:00:39 +0000460 }
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000461 SkDebugf("(results marked with [*] will cause nonzero return value)\n");
epoger@google.com310478e2013-04-03 18:00:39 +0000462 }
463
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000464 static ErrorCombination write_document(const SkString& path, SkStreamAsset* asset) {
epoger@google.com5f6a0072013-01-31 16:30:55 +0000465 SkFILEWStream stream(path.c_str());
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000466 if (!stream.writeStream(asset, asset->getLength())) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000467 SkDebugf("FAILED to write document: %s\n", path.c_str());
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000468 return ErrorCombination(kWritingReferenceImage_ErrorType);
469 }
470 return kEmpty_ErrorCombination;
epoger@google.com5f6a0072013-01-31 16:30:55 +0000471 }
472
epoger@google.com37269602013-01-19 04:21:27 +0000473 /**
epoger@google.com5f6a0072013-01-31 16:30:55 +0000474 * Prepare an SkBitmap to render a GM into.
475 *
476 * After you've rendered the GM into the SkBitmap, you must call
477 * complete_bitmap()!
478 *
479 * @todo thudson 22 April 2011 - could refactor this to take in
480 * a factory to generate the context, always call readPixels()
481 * (logically a noop for rasters, if wasted time), and thus collapse the
482 * GPU special case and also let this be used for SkPicture testing.
483 */
robertphillips8c508b42014-12-11 13:10:23 -0800484 static void setup_bitmap(const ConfigData& gRec, const SkISize& size,
epoger@google.com5f6a0072013-01-31 16:30:55 +0000485 SkBitmap* bitmap) {
reedddd014e2014-06-05 08:51:20 -0700486 bitmap->allocPixels(SkImageInfo::Make(size.width(), size.height(),
487 gRec.fColorType, kPremul_SkAlphaType));
epoger@google.com5f6a0072013-01-31 16:30:55 +0000488 bitmap->eraseColor(SK_ColorTRANSPARENT);
489 }
490
491 /**
492 * Any finalization steps we need to perform on the SkBitmap after
493 * we have rendered the GM into it.
epoger@google.com37269602013-01-19 04:21:27 +0000494 *
495 * It's too bad that we are throwing away alpha channel data
496 * we could otherwise be examining, but this had always been happening
497 * before... it was buried within the compare() method at
498 * https://code.google.com/p/skia/source/browse/trunk/gm/gmmain.cpp?r=7289#305 .
499 *
500 * Apparently we need this, at least for bitmaps that are either:
501 * (a) destined to be written out as PNG files, or
502 * (b) compared against bitmaps read in from PNG files
503 * for the reasons described just above the force_all_opaque() method.
504 *
505 * Neglecting to do this led to the difficult-to-diagnose
506 * http://code.google.com/p/skia/issues/detail?id=1079 ('gm generating
507 * spurious pixel_error messages as of r7258')
508 *
509 * TODO(epoger): Come up with a better solution that allows us to
510 * compare full pixel data, including alpha channel, while still being
511 * robust in the face of transformations to/from PNG files.
512 * Options include:
513 *
514 * 1. Continue to call force_all_opaque(), but ONLY for bitmaps that
515 * will be written to, or compared against, PNG files.
516 * PRO: Preserve/compare alpha channel info for the non-PNG cases
517 * (comparing different renderModes in-memory)
epoger@google.com908f5832013-04-12 02:23:55 +0000518 * CON: The bitmaps (and hash digests) for these non-PNG cases would be
epoger@google.com37269602013-01-19 04:21:27 +0000519 * different than those for the PNG-compared cases, and in the
520 * case of a failed renderMode comparison, how would we write the
521 * image to disk for examination?
522 *
epoger@google.com908f5832013-04-12 02:23:55 +0000523 * 2. Always compute image hash digests from PNG format (either
epoger@google.com37269602013-01-19 04:21:27 +0000524 * directly from the the bytes of a PNG file, or capturing the
525 * bytes we would have written to disk if we were writing the
526 * bitmap out as a PNG).
527 * PRO: I think this would allow us to never force opaque, and to
528 * the extent that alpha channel data can be preserved in a PNG
529 * file, we could observe it.
epoger@google.com908f5832013-04-12 02:23:55 +0000530 * CON: If we read a bitmap from disk, we need to take its hash digest
epoger@google.com37269602013-01-19 04:21:27 +0000531 * from the source PNG (we can't compute it from the bitmap we
532 * read out of the PNG, because we will have already premultiplied
533 * the alpha).
534 * CON: Seems wasteful to convert a bitmap to PNG format just to take
epoger@google.com908f5832013-04-12 02:23:55 +0000535 * its hash digest. (Although we're wasting lots of effort already
epoger@google.com37269602013-01-19 04:21:27 +0000536 * calling force_all_opaque().)
537 *
538 * 3. Make the alpha premultiply/unpremultiply routines 100% consistent,
539 * so we can transform images back and forth without fear of off-by-one
540 * errors.
541 * CON: Math is hard.
542 *
543 * 4. Perform a "close enough" comparison of bitmaps (+/- 1 bit in each
544 * channel), rather than demanding absolute equality.
epoger@google.com908f5832013-04-12 02:23:55 +0000545 * CON: Can't do this with hash digests.
epoger@google.com37269602013-01-19 04:21:27 +0000546 */
epoger@google.com5f6a0072013-01-31 16:30:55 +0000547 static void complete_bitmap(SkBitmap* bitmap) {
548 force_all_opaque(*bitmap);
epoger@google.comde961632012-10-26 18:56:36 +0000549 }
550
robertphillips8c508b42014-12-11 13:10:23 -0800551 static void InstallFilter(SkCanvas* canvas);
epoger@google.comde961632012-10-26 18:56:36 +0000552
reed@google.comaef73612012-11-16 13:41:45 +0000553 static void invokeGM(GM* gm, SkCanvas* canvas, bool isPDF, bool isDeferred) {
epoger@google.comde961632012-10-26 18:56:36 +0000554 SkAutoCanvasRestore acr(canvas, true);
555
556 if (!isPDF) {
557 canvas->concat(gm->getInitialTransform());
558 }
robertphillips8c508b42014-12-11 13:10:23 -0800559 InstallFilter(canvas);
reed@google.comaef73612012-11-16 13:41:45 +0000560 gm->setCanvasIsDeferred(isDeferred);
epoger@google.comde961632012-10-26 18:56:36 +0000561 gm->draw(canvas);
562 canvas->setDrawFilter(NULL);
563 }
564
epoger@google.com6f6568b2013-03-22 17:29:46 +0000565 static ErrorCombination generate_image(GM* gm, const ConfigData& gRec,
bsalomon@google.com123ac1d2013-03-28 19:18:12 +0000566 GrSurface* gpuTarget,
epoger@google.com6f6568b2013-03-22 17:29:46 +0000567 SkBitmap* bitmap,
568 bool deferred) {
robertphillips8c508b42014-12-11 13:10:23 -0800569 const SkISize size (gm->getISize());
epoger@google.comde961632012-10-26 18:56:36 +0000570
robertphillips8c508b42014-12-11 13:10:23 -0800571 SkAutoTUnref<SkSurface> surface(CreateSurface(gRec, size, gpuTarget));
epoger@google.comde961632012-10-26 18:56:36 +0000572 SkAutoTUnref<SkCanvas> canvas;
573
robertphillips8c508b42014-12-11 13:10:23 -0800574 if (deferred) {
575 canvas.reset(SkDeferredCanvas::Create(surface));
576 } else {
577 canvas.reset(SkRef(surface->getCanvas()));
epoger@google.comde961632012-10-26 18:56:36 +0000578 }
robertphillips8c508b42014-12-11 13:10:23 -0800579 invokeGM(gm, canvas, false, deferred);
580 canvas->flush();
581
582 setup_bitmap(gRec, size, bitmap);
583 surface->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes(), 0, 0);
epoger@google.com5f6a0072013-01-31 16:30:55 +0000584 complete_bitmap(bitmap);
epoger@google.com6f6568b2013-03-22 17:29:46 +0000585 return kEmpty_ErrorCombination;
epoger@google.comde961632012-10-26 18:56:36 +0000586 }
587
robertphillips8c508b42014-12-11 13:10:23 -0800588 static void DrawPictureToSurface(SkSurface* surf,
589 const SkPicture* pict,
590 SkScalar scale,
591 bool tile,
592 bool useMPD) {
593 SkASSERT(surf->width() == pict->cullRect().width() &&
594 surf->height() == pict->cullRect().height());
595
596 if (tile) {
597 SkMultiPictureDraw mpd;
598 SkTDArray<SkSurface*> surfaces;
599
600 const SkISize tileSize = SkISize::Make(16, 16);
601
602 const SkImageInfo ii = surf->getCanvas()->imageInfo().makeWH(tileSize.width(),
603 tileSize.height());
604
605 for (int tileY = 0; tileY < pict->cullRect().height(); tileY += tileSize.height()) {
606 for (int tileX = 0; tileX < pict->cullRect().width(); tileX += tileSize.width()) {
607
608 *surfaces.append() = surf->getCanvas()->newSurface(ii);
609
610 InstallFilter(surfaces.top()->getCanvas());
611
612 SkMatrix matrix;
613 matrix.setTranslate(-pict->cullRect().fLeft, -pict->cullRect().fTop);
614 matrix.postTranslate(-SkIntToScalar(tileX), -SkIntToScalar(tileY));
615 matrix.postScale(scale, scale);
616
617 if (useMPD) {
618 mpd.add(surfaces.top()->getCanvas(), pict, &matrix, NULL);
619 } else {
620 surfaces.top()->getCanvas()->drawPicture(pict, &matrix, NULL);
621 }
622 }
623 }
624
625 mpd.draw();
626
627 SkPaint gatherPaint;
628 gatherPaint.setXfermodeMode(SkXfermode::kSrc_Mode);
629
630 int tileIndex = 0;
631 for (int tileY = 0; tileY < pict->cullRect().height(); tileY += tileSize.height()) {
632 for (int tileX = 0; tileX < pict->cullRect().width(); tileX += tileSize.width()) {
633 surf->getCanvas()->drawImage(surfaces[tileIndex]->newImageSnapshot(),
634 SkIntToScalar(tileX), SkIntToScalar(tileY),
635 &gatherPaint);
636 surfaces[tileIndex]->unref();
637 tileIndex++;
638 }
639 }
640 } else {
641 InstallFilter(surf->getCanvas());
642
643 SkMatrix matrix;
644 matrix.setTranslate(-pict->cullRect().fLeft, -pict->cullRect().fTop);
645 matrix.postScale(scale, scale);
646
647 if (useMPD) {
648 SkMultiPictureDraw mpd;
649 mpd.add(surf->getCanvas(), pict, &matrix, NULL);
650 mpd.draw();
651 } else {
652 surf->getCanvas()->drawPicture(pict, &matrix, NULL);
653 }
654 }
655 }
656
robertphillips478dd722014-12-16 08:25:55 -0800657 static void generate_image_from_picture(GM* gm, const ConfigData& config,
658 GrSurface* gpuTarget,
junov@chromium.orgc938c482012-12-19 15:24:38 +0000659 SkPicture* pict, SkBitmap* bitmap,
robertphillips@google.com5a7d0292013-04-02 15:18:41 +0000660 SkScalar scale = SK_Scalar1,
661 bool tile = false) {
robertphillips478dd722014-12-16 08:25:55 -0800662 const SkISize size = gm->getISize();
robertphillips@google.com5a7d0292013-04-02 15:18:41 +0000663
robertphillips478dd722014-12-16 08:25:55 -0800664 SkAutoTUnref<SkSurface> surf(CreateSurface(config, size, gpuTarget));
robertphillips@google.com5a7d0292013-04-02 15:18:41 +0000665
robertphillips8c508b42014-12-11 13:10:23 -0800666 DrawPictureToSurface(surf, pict, scale, tile, false);
robertphillips478dd722014-12-16 08:25:55 -0800667
668 setup_bitmap(config, size, bitmap);
669
670 surf->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes(), 0, 0);
671
robertphillips8c508b42014-12-11 13:10:23 -0800672 complete_bitmap(bitmap);
epoger@google.comde961632012-10-26 18:56:36 +0000673 }
674
commit-bot@chromium.org5e009892013-10-14 13:42:12 +0000675 static bool generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) {
epoger@google.comde961632012-10-26 18:56:36 +0000676#ifdef SK_SUPPORT_PDF
caryclarkac8d8b82015-01-07 07:36:52 -0800677 SkMatrix initialTransform = gm->getInitialTransform();
678 if (FLAGS_useDocumentInsteadOfDevice) {
679 SkISize pageISize = gm->getISize();
680 SkAutoTUnref<SkDocument> pdfDoc(
681 SkDocument::CreatePDF(&pdf, NULL,
682 encode_to_dct_data,
683 SkIntToScalar(FLAGS_pdfRasterDpi)));
684
685 if (!pdfDoc.get()) {
686 return false;
687 }
688
689 SkCanvas* canvas = NULL;
690 canvas = pdfDoc->beginPage(SkIntToScalar(pageISize.width()),
691 SkIntToScalar(pageISize.height()));
692 canvas->concat(initialTransform);
693
694 invokeGM(gm, canvas, true, false);
695
696 return pdfDoc->close();
697 } else {
698 SkISize pageSize = gm->getISize();
699 SkPDFDevice* dev = NULL;
700 if (initialTransform.isIdentity()) {
701 dev = new SkPDFDevice(pageSize, pageSize, initialTransform);
702 } else {
703 SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()),
704 SkIntToScalar(pageSize.height()));
705 initialTransform.mapRect(&content);
robertphillipsf4e59952015-01-07 12:16:10 -0800706 if (!content.intersect(0, 0, SkIntToScalar(pageSize.width()),
707 SkIntToScalar(pageSize.height()))) {
708 content.setEmpty();
709 }
caryclarkac8d8b82015-01-07 07:36:52 -0800710 SkISize contentSize =
711 SkISize::Make(SkScalarRoundToInt(content.width()),
712 SkScalarRoundToInt(content.height()));
713 dev = new SkPDFDevice(pageSize, contentSize, initialTransform);
714 }
715 dev->setDCTEncoder(encode_to_dct_data);
716 dev->setRasterDpi(SkIntToScalar(FLAGS_pdfRasterDpi));
717 SkAutoUnref aur(dev);
718 SkCanvas c(dev);
719 invokeGM(gm, &c, true, false);
720 SkPDFDocument doc;
721 doc.appendPage(dev);
722 doc.emitPDF(&pdf);
epoger@google.comde961632012-10-26 18:56:36 +0000723 }
commit-bot@chromium.org5e009892013-10-14 13:42:12 +0000724#endif // SK_SUPPORT_PDF
caryclarkac8d8b82015-01-07 07:36:52 -0800725 return true; // Do not report failure if pdf is not supported.
epoger@google.comde961632012-10-26 18:56:36 +0000726 }
727
728 static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) {
729#ifdef SK_SUPPORT_XPS
730 SkISize size = gm->getISize();
731
732 SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()),
733 SkIntToScalar(size.height()));
734 static const SkScalar inchesPerMeter = SkScalarDiv(10000, 254);
735 static const SkScalar upm = 72 * inchesPerMeter;
736 SkVector unitsPerMeter = SkPoint::Make(upm, upm);
737 static const SkScalar ppm = 200 * inchesPerMeter;
738 SkVector pixelsPerMeter = SkPoint::Make(ppm, ppm);
739
740 SkXPSDevice* dev = new SkXPSDevice();
741 SkAutoUnref aur(dev);
742
743 SkCanvas c(dev);
744 dev->beginPortfolio(&xps);
745 dev->beginSheet(unitsPerMeter, pixelsPerMeter, trimSize);
reed@google.comaef73612012-11-16 13:41:45 +0000746 invokeGM(gm, &c, false, false);
epoger@google.comde961632012-10-26 18:56:36 +0000747 dev->endSheet();
748 dev->endPortfolio();
749
750#endif
751 }
752
epoger@google.com37269602013-01-19 04:21:27 +0000753 /**
epoger@google.com84a18022013-02-01 20:39:15 +0000754 * Log more detail about the mistmatch between expectedBitmap and
755 * actualBitmap.
756 */
757 void report_bitmap_diffs(const SkBitmap& expectedBitmap, const SkBitmap& actualBitmap,
758 const char *testName) {
759 const int expectedWidth = expectedBitmap.width();
760 const int expectedHeight = expectedBitmap.height();
761 const int width = actualBitmap.width();
762 const int height = actualBitmap.height();
763 if ((expectedWidth != width) || (expectedHeight != height)) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000764 SkDebugf("---- %s: dimension mismatch -- expected [%d %d], actual [%d %d]\n",
765 testName, expectedWidth, expectedHeight, width, height);
epoger@google.com84a18022013-02-01 20:39:15 +0000766 return;
767 }
768
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000769 if ((kN32_SkColorType != expectedBitmap.colorType()) ||
770 (kN32_SkColorType != actualBitmap.colorType())) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000771 SkDebugf("---- %s: not computing max per-channel pixel mismatch because non-8888\n",
772 testName);
epoger@google.com84a18022013-02-01 20:39:15 +0000773 return;
774 }
775
776 SkAutoLockPixels alp0(expectedBitmap);
777 SkAutoLockPixels alp1(actualBitmap);
778 int errR = 0;
779 int errG = 0;
780 int errB = 0;
781 int errA = 0;
782 int differingPixels = 0;
783
784 for (int y = 0; y < height; ++y) {
785 const SkPMColor* expectedPixelPtr = expectedBitmap.getAddr32(0, y);
786 const SkPMColor* actualPixelPtr = actualBitmap.getAddr32(0, y);
787 for (int x = 0; x < width; ++x) {
788 SkPMColor expectedPixel = *expectedPixelPtr++;
789 SkPMColor actualPixel = *actualPixelPtr++;
790 if (expectedPixel != actualPixel) {
791 differingPixels++;
792 errR = SkMax32(errR, SkAbs32((int)SkGetPackedR32(expectedPixel) -
793 (int)SkGetPackedR32(actualPixel)));
794 errG = SkMax32(errG, SkAbs32((int)SkGetPackedG32(expectedPixel) -
795 (int)SkGetPackedG32(actualPixel)));
796 errB = SkMax32(errB, SkAbs32((int)SkGetPackedB32(expectedPixel) -
797 (int)SkGetPackedB32(actualPixel)));
798 errA = SkMax32(errA, SkAbs32((int)SkGetPackedA32(expectedPixel) -
799 (int)SkGetPackedA32(actualPixel)));
800 }
801 }
802 }
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +0000803 SkDebugf("---- %s: %d (of %d) differing pixels, "
804 "max per-channel mismatch R=%d G=%d B=%d A=%d\n",
805 testName, differingPixels, width*height, errR, errG, errB, errA);
epoger@google.com84a18022013-02-01 20:39:15 +0000806 }
807
808 /**
epoger@google.com908f5832013-04-12 02:23:55 +0000809 * Compares actual hash digest to expectations, returning the set of errors
epoger@google.com6f6568b2013-03-22 17:29:46 +0000810 * (if any) that we saw along the way.
epoger@google.com37269602013-01-19 04:21:27 +0000811 *
812 * If fMismatchPath has been set, and there are pixel diffs, then the
813 * actual bitmap will be written out to a file within fMismatchPath.
epoger@google.com5f995452013-06-21 18:16:47 +0000814 * And similarly for fMissingExpectationsPath...
epoger@google.com37269602013-01-19 04:21:27 +0000815 *
816 * @param expectations what expectations to compare actualBitmap against
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000817 * @param actualBitmapAndDigest the SkBitmap we actually generated, and its GmResultDigest
epoger@google.com659c8c02013-05-21 15:45:45 +0000818 * @param shortName name of test, e.g. "selftest1"
819 * @param configName name of config, e.g. "8888"
epoger@google.com37269602013-01-19 04:21:27 +0000820 * @param renderModeDescriptor e.g., "-rtree", "-deferred"
821 * @param addToJsonSummary whether to add these results (both actual and
epoger@google.comcaac3db2013-04-04 19:23:11 +0000822 * expected) to the JSON summary. Regardless of this setting, if
823 * we find an image mismatch in this test, we will write these
824 * results to the JSON summary. (This is so that we will always
825 * report errors across rendering modes, such as pipe vs tiled.
826 * See https://codereview.chromium.org/13650002/ )
epoger@google.com37269602013-01-19 04:21:27 +0000827 */
epoger@google.com6f6568b2013-03-22 17:29:46 +0000828 ErrorCombination compare_to_expectations(Expectations expectations,
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000829 const BitmapAndDigest& actualBitmapAndDigest,
epoger@google.com659c8c02013-05-21 15:45:45 +0000830 const char *shortName, const char *configName,
831 const char *renderModeDescriptor,
epoger@google.comcaac3db2013-04-04 19:23:11 +0000832 bool addToJsonSummary) {
epoger@google.com6f6568b2013-03-22 17:29:46 +0000833 ErrorCombination errors;
epoger@google.com659c8c02013-05-21 15:45:45 +0000834 SkString shortNamePlusConfig = make_shortname_plus_config(shortName, configName);
835 SkString completeNameString(shortNamePlusConfig);
epoger@google.com37269602013-01-19 04:21:27 +0000836 completeNameString.append(renderModeDescriptor);
epoger@google.comce057fe2013-05-14 15:17:46 +0000837 completeNameString.append(".");
838 completeNameString.append(kPNG_FileExtension);
epoger@google.com37269602013-01-19 04:21:27 +0000839 const char* completeName = completeNameString.c_str();
epoger@google.comee8a8e32012-12-18 19:13:49 +0000840
epoger@google.com37269602013-01-19 04:21:27 +0000841 if (expectations.empty()) {
epoger@google.com6f6568b2013-03-22 17:29:46 +0000842 errors.add(kMissingExpectations_ErrorType);
epoger@google.com5f995452013-06-21 18:16:47 +0000843
844 // Write out the "actuals" for any tests without expectations, if we have
845 // been directed to do so.
846 if (fMissingExpectationsPath) {
robertphillipsed313432014-12-16 09:31:42 -0800847 SkString path = this->makeBitmapFilename(fMissingExpectationsPath, shortName,
848 configName, renderModeDescriptor,
849 actualBitmapAndDigest.fDigest);
850 WriteBitmap(path, actualBitmapAndDigest.fBitmap);
epoger@google.com5f995452013-06-21 18:16:47 +0000851 }
852
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000853 } else if (!expectations.match(actualBitmapAndDigest.fDigest)) {
epoger@google.comcaac3db2013-04-04 19:23:11 +0000854 addToJsonSummary = true;
855 // The error mode we record depends on whether this was running
856 // in a non-standard renderMode.
857 if ('\0' == *renderModeDescriptor) {
858 errors.add(kExpectationsMismatch_ErrorType);
859 } else {
860 errors.add(kRenderModeMismatch_ErrorType);
861 }
epoger@google.com84a18022013-02-01 20:39:15 +0000862
863 // Write out the "actuals" for any mismatches, if we have
864 // been directed to do so.
epoger@google.com37269602013-01-19 04:21:27 +0000865 if (fMismatchPath) {
robertphillipsed313432014-12-16 09:31:42 -0800866 SkString path = this->makeBitmapFilename(fMismatchPath, shortName, configName,
867 renderModeDescriptor,
868 actualBitmapAndDigest.fDigest);
869 WriteBitmap(path, actualBitmapAndDigest.fBitmap);
epoger@google.com37269602013-01-19 04:21:27 +0000870 }
epoger@google.com84a18022013-02-01 20:39:15 +0000871
872 // If we have access to a single expected bitmap, log more
873 // detail about the mismatch.
874 const SkBitmap *expectedBitmapPtr = expectations.asBitmap();
bsalomon49f085d2014-09-05 13:34:00 -0700875 if (expectedBitmapPtr) {
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000876 report_bitmap_diffs(*expectedBitmapPtr, actualBitmapAndDigest.fBitmap,
877 completeName);
epoger@google.com84a18022013-02-01 20:39:15 +0000878 }
epoger@google.coma243b222013-01-17 17:54:28 +0000879 }
epoger@google.coma243b222013-01-17 17:54:28 +0000880
epoger@google.com37269602013-01-19 04:21:27 +0000881 if (addToJsonSummary) {
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000882 add_actual_results_to_json_summary(completeName, actualBitmapAndDigest.fDigest, errors,
epoger@google.com37269602013-01-19 04:21:27 +0000883 expectations.ignoreFailure());
884 add_expected_results_to_json_summary(completeName, expectations);
885 }
epoger@google.coma243b222013-01-17 17:54:28 +0000886
epoger@google.com6f6568b2013-03-22 17:29:46 +0000887 return errors;
epoger@google.com06b8a192013-01-15 19:10:16 +0000888 }
889
epoger@google.com37269602013-01-19 04:21:27 +0000890 /**
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000891 * Add this result to the appropriate JSON collection of actual results (but just ONE),
epoger@google.com76c913d2013-04-26 15:06:44 +0000892 * depending on errors encountered.
epoger@google.com37269602013-01-19 04:21:27 +0000893 */
894 void add_actual_results_to_json_summary(const char testName[],
epoger@google.comd4993ff2013-05-24 14:33:28 +0000895 const GmResultDigest &actualResultDigest,
epoger@google.com76c913d2013-04-26 15:06:44 +0000896 ErrorCombination errors,
epoger@google.com37269602013-01-19 04:21:27 +0000897 bool ignoreFailure) {
epoger@google.comd4993ff2013-05-24 14:33:28 +0000898 Json::Value jsonActualResults = actualResultDigest.asJsonTypeValuePair();
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000899 Json::Value *resultCollection = NULL;
900
epoger@google.com76c913d2013-04-26 15:06:44 +0000901 if (errors.isEmpty()) {
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000902 resultCollection = &this->fJsonActualResults_Succeeded;
903 } else if (errors.includes(kRenderModeMismatch_ErrorType)) {
904 resultCollection = &this->fJsonActualResults_Failed;
905 } else if (errors.includes(kExpectationsMismatch_ErrorType)) {
epoger@google.com37269602013-01-19 04:21:27 +0000906 if (ignoreFailure) {
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000907 resultCollection = &this->fJsonActualResults_FailureIgnored;
epoger@google.com37269602013-01-19 04:21:27 +0000908 } else {
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000909 resultCollection = &this->fJsonActualResults_Failed;
epoger@google.com37269602013-01-19 04:21:27 +0000910 }
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000911 } else if (errors.includes(kMissingExpectations_ErrorType)) {
912 // TODO: What about the case where there IS an expected
913 // image hash digest, but that gm test doesn't actually
914 // run? For now, those cases will always be ignored,
915 // because gm only looks at expectations that correspond
916 // to gm tests that were actually run.
917 //
918 // Once we have the ability to express expectations as a
919 // JSON file, we should fix this (and add a test case for
920 // which an expectation is given but the test is never
921 // run).
922 resultCollection = &this->fJsonActualResults_NoComparison;
923 }
924
925 // If none of the above cases match, we don't add it to ANY tally of actual results.
926 if (resultCollection) {
927 (*resultCollection)[testName] = jsonActualResults;
epoger@google.com37269602013-01-19 04:21:27 +0000928 }
929 }
930
931 /**
932 * Add this test to the JSON collection of expected results.
933 */
934 void add_expected_results_to_json_summary(const char testName[],
935 Expectations expectations) {
epoger@google.com76c913d2013-04-26 15:06:44 +0000936 this->fJsonExpectedResults[testName] = expectations.asJsonValue();
epoger@google.com37269602013-01-19 04:21:27 +0000937 }
938
939 /**
940 * Compare actualBitmap to expectations stored in this->fExpectationsSource.
941 *
942 * @param gm which test generated the actualBitmap
943 * @param gRec
vandebo@chromium.org8fc37662013-08-21 18:04:09 +0000944 * @param configName The config name to look for in the expectation file.
epoger@google.come33e1372013-07-08 19:13:33 +0000945 * @param actualBitmapAndDigest ptr to bitmap generated by this run, or NULL
946 * if we don't have a usable bitmap representation
epoger@google.com37269602013-01-19 04:21:27 +0000947 */
robertphillipsed313432014-12-16 09:31:42 -0800948 ErrorCombination compareTestResultsToStoredExpectations(
vandebo@chromium.org8fc37662013-08-21 18:04:09 +0000949 GM* gm, const ConfigData& gRec, const char* configName,
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000950 const BitmapAndDigest* actualBitmapAndDigest) {
epoger@google.com659c8c02013-05-21 15:45:45 +0000951 ErrorCombination errors;
epoger@google.come33e1372013-07-08 19:13:33 +0000952
953 if (NULL == actualBitmapAndDigest) {
954 // Note that we intentionally skipped validating the results for
955 // this test, because we don't know how to generate an SkBitmap
956 // version of the output.
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000957 errors.add(ErrorCombination(kIntentionallySkipped_ErrorType));
epoger@google.comc824c832013-07-12 15:52:59 +0000958 } else if (!(gRec.fFlags & kWrite_ConfigFlag)) {
959 // We don't record the results for this test or compare them
960 // against any expectations, because the output image isn't
961 // meaningful.
962 // See https://code.google.com/p/skia/issues/detail?id=1410 ('some
963 // GM result images not available for download from Google Storage')
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000964 errors.add(ErrorCombination(kIntentionallySkipped_ErrorType));
epoger@google.come33e1372013-07-08 19:13:33 +0000965 } else {
966 ExpectationsSource *expectationsSource = this->fExpectationsSource.get();
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000967 SkString nameWithExtension = make_shortname_plus_config(gm->getName(), configName);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000968 nameWithExtension.append(".");
969 nameWithExtension.append(kPNG_FileExtension);
970
epoger@google.come33e1372013-07-08 19:13:33 +0000971 if (expectationsSource && (gRec.fFlags & kRead_ConfigFlag)) {
972 /*
973 * Get the expected results for this test, as one or more allowed
974 * hash digests. The current implementation of expectationsSource
975 * get this by computing the hash digest of a single PNG file on disk.
976 *
977 * TODO(epoger): This relies on the fact that
978 * force_all_opaque() was called on the bitmap before it
979 * was written to disk as a PNG in the first place. If
980 * not, the hash digest returned here may not match the
981 * hash digest of actualBitmap, which *has* been run through
982 * force_all_opaque().
983 * See comments above complete_bitmap() for more detail.
984 */
985 Expectations expectations = expectationsSource->get(nameWithExtension.c_str());
robertphillipsed313432014-12-16 09:31:42 -0800986 if (this->shouldIgnoreTest(gm->getName())) {
epoger@google.comdefc4872013-09-19 06:18:27 +0000987 expectations.setIgnoreFailure(true);
988 }
epoger@google.come33e1372013-07-08 19:13:33 +0000989 errors.add(compare_to_expectations(expectations, *actualBitmapAndDigest,
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000990 gm->getName(), configName, "", true));
epoger@google.come33e1372013-07-08 19:13:33 +0000991 } else {
992 // If we are running without expectations, we still want to
993 // record the actual results.
994 add_actual_results_to_json_summary(nameWithExtension.c_str(),
995 actualBitmapAndDigest->fDigest,
996 ErrorCombination(kMissingExpectations_ErrorType),
997 false);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000998 errors.add(ErrorCombination(kMissingExpectations_ErrorType));
epoger@google.come33e1372013-07-08 19:13:33 +0000999 }
epoger@google.com9ef89ce2013-01-18 21:45:42 +00001000 }
epoger@google.com6f6568b2013-03-22 17:29:46 +00001001 return errors;
epoger@google.coma243b222013-01-17 17:54:28 +00001002 }
1003
epoger@google.com37269602013-01-19 04:21:27 +00001004 /**
1005 * Compare actualBitmap to referenceBitmap.
1006 *
epoger@google.com659c8c02013-05-21 15:45:45 +00001007 * @param shortName test name, e.g. "selftest1"
1008 * @param configName configuration name, e.g. "8888"
epoger@google.com37269602013-01-19 04:21:27 +00001009 * @param renderModeDescriptor
1010 * @param actualBitmap actual bitmap generated by this run
1011 * @param referenceBitmap bitmap we expected to be generated
1012 */
epoger@google.com6f6568b2013-03-22 17:29:46 +00001013 ErrorCombination compare_test_results_to_reference_bitmap(
epoger@google.com659c8c02013-05-21 15:45:45 +00001014 const char *shortName, const char *configName, const char *renderModeDescriptor,
epoger@google.com37269602013-01-19 04:21:27 +00001015 SkBitmap& actualBitmap, const SkBitmap* referenceBitmap) {
1016
1017 SkASSERT(referenceBitmap);
epoger@google.com84a18022013-02-01 20:39:15 +00001018 Expectations expectations(*referenceBitmap);
epoger@google.com6f7f14d2013-06-19 18:28:31 +00001019 BitmapAndDigest actualBitmapAndDigest(actualBitmap);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001020
1021 // TODO: Eliminate RecordTestResults from here.
1022 // Results recording code for the test_drawing path has been refactored so that
1023 // RecordTestResults is only called once, at the topmost level. However, the
1024 // other paths have not yet been refactored, and RecordTestResults has been added
1025 // here to maintain proper behavior for calls not coming from the test_drawing path.
1026 ErrorCombination errors;
1027 errors.add(compare_to_expectations(expectations, actualBitmapAndDigest, shortName,
1028 configName, renderModeDescriptor, false));
1029 SkString shortNamePlusConfig = make_shortname_plus_config(shortName, configName);
1030 RecordTestResults(errors, shortNamePlusConfig, renderModeDescriptor);
1031
1032 return errors;
epoger@google.com37269602013-01-19 04:21:27 +00001033 }
1034
junov@chromium.org20bd04e2013-01-16 18:43:36 +00001035 static SkPicture* generate_new_picture(GM* gm, BbhType bbhType, uint32_t recordFlags,
1036 SkScalar scale = SK_Scalar1) {
robertphillipsa8d7f0b2014-08-29 08:03:56 -07001037 SkScalar width = SkScalarMul(SkIntToScalar(gm->getISize().width()), scale);
1038 SkScalar height = SkScalarMul(SkIntToScalar(gm->getISize().height()), scale);
skia.committer@gmail.comd8b27992012-12-20 02:01:41 +00001039
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +00001040 SkAutoTDelete<SkBBHFactory> factory;
mtklein703dd2e2015-01-09 06:41:48 -08001041 if (kRTree_BbhType == bbhType) {
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +00001042 factory.reset(SkNEW(SkRTreeFactory));
junov@chromium.org20bd04e2013-01-16 18:43:36 +00001043 }
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +00001044 SkPictureRecorder recorder;
1045 SkCanvas* cv = recorder.beginRecording(width, height, factory.get(), recordFlags);
junov@chromium.orgc938c482012-12-19 15:24:38 +00001046 cv->scale(scale, scale);
reed@google.comaef73612012-11-16 13:41:45 +00001047 invokeGM(gm, cv, false, false);
robertphillips@google.com84b18c72014-04-13 19:09:42 +00001048 return recorder.endRecording();
epoger@google.comde961632012-10-26 18:56:36 +00001049 }
1050
1051 static SkPicture* stream_to_new_picture(const SkPicture& src) {
epoger@google.comde961632012-10-26 18:56:36 +00001052 SkDynamicMemoryWStream storage;
scroggo895c43b2014-12-11 10:53:58 -08001053 src.serialize(&storage);
bungeman@google.comc29f3d82013-07-19 22:32:11 +00001054 SkAutoTUnref<SkStreamAsset> pictReadback(storage.detachAsStream());
commit-bot@chromium.org805df1a2013-08-16 19:18:12 +00001055 SkPicture* retval = SkPicture::CreateFromStream(pictReadback,
1056 &SkImageDecoder::DecodeMemory);
epoger@google.comde961632012-10-26 18:56:36 +00001057 return retval;
1058 }
1059
1060 // Test: draw into a bitmap or pdf.
epoger@google.com15655b22013-01-08 18:47:31 +00001061 // Depending on flags, possibly compare to an expected image.
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001062 // If writePath is not NULL, also write images (or documents) to the specified path.
1063 ErrorCombination test_drawing(GM* gm, const ConfigData& gRec,
1064 const SkTDArray<const PDFRasterizerData*> &pdfRasterizers,
epoger@google.com6f6568b2013-03-22 17:29:46 +00001065 const char writePath [],
bsalomon@google.com123ac1d2013-03-28 19:18:12 +00001066 GrSurface* gpuTarget,
epoger@google.com6f6568b2013-03-22 17:29:46 +00001067 SkBitmap* bitmap) {
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001068 ErrorCombination errors;
epoger@google.comde961632012-10-26 18:56:36 +00001069 SkDynamicMemoryWStream document;
1070
1071 if (gRec.fBackend == kRaster_Backend ||
1072 gRec.fBackend == kGPU_Backend) {
1073 // Early exit if we can't generate the image.
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001074 errors.add(generate_image(gm, gRec, gpuTarget, bitmap, false));
epoger@google.com6f6568b2013-03-22 17:29:46 +00001075 if (!errors.isEmpty()) {
epoger@google.com37269602013-01-19 04:21:27 +00001076 // TODO: Add a test to exercise what the stdout and
1077 // JSON look like if we get an "early error" while
1078 // trying to generate the image.
epoger@google.comde961632012-10-26 18:56:36 +00001079 return errors;
1080 }
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001081
robertphillipsed313432014-12-16 09:31:42 -08001082 errors.add(this->writeBitmap(gm, gRec, gRec.fName, writePath, *bitmap));
epoger@google.comde961632012-10-26 18:56:36 +00001083 } else if (gRec.fBackend == kPDF_Backend) {
commit-bot@chromium.org5e009892013-10-14 13:42:12 +00001084 if (!generate_pdf(gm, document)) {
1085 errors.add(kGeneratePdfFailed_ErrorType);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001086 } else {
commit-bot@chromium.org5e009892013-10-14 13:42:12 +00001087 SkAutoTUnref<SkStreamAsset> documentStream(document.detachAsStream());
1088 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) {
robertphillipsed313432014-12-16 09:31:42 -08001089 SkString path = make_filename(writePath, gm->getName(), gRec.fName, "", "pdf");
commit-bot@chromium.org5e009892013-10-14 13:42:12 +00001090 errors.add(write_document(path, documentStream));
1091 }
1092
1093 if (!(gm->getFlags() & GM::kSkipPDFRasterization_Flag)) {
1094 for (int i = 0; i < pdfRasterizers.count(); i++) {
1095 SkBitmap pdfBitmap;
vandebo@chromium.org969967e2013-12-09 23:22:15 +00001096 documentStream->rewind();
commit-bot@chromium.org5e009892013-10-14 13:42:12 +00001097 bool success = (*pdfRasterizers[i]->fRasterizerFunction)(
1098 documentStream.get(), &pdfBitmap);
1099 if (!success) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00001100 SkDebugf("FAILED to render PDF for %s using renderer %s\n",
1101 gm->getName(),
1102 pdfRasterizers[i]->fName);
commit-bot@chromium.org5e009892013-10-14 13:42:12 +00001103 continue;
1104 }
1105
1106 SkString configName(gRec.fName);
1107 configName.append("-");
1108 configName.append(pdfRasterizers[i]->fName);
1109
robertphillipsed313432014-12-16 09:31:42 -08001110 errors.add(this->writeBitmap(gm, gRec, configName.c_str(),
1111 writePath, pdfBitmap));
commit-bot@chromium.org5e009892013-10-14 13:42:12 +00001112 }
1113 } else {
1114 errors.add(kIntentionallySkipped_ErrorType);
1115 }
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001116 }
epoger@google.comde961632012-10-26 18:56:36 +00001117 } else if (gRec.fBackend == kXPS_Backend) {
1118 generate_xps(gm, document);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001119 SkAutoTUnref<SkStreamAsset> documentStream(document.detachAsStream());
epoger@google.come33e1372013-07-08 19:13:33 +00001120
robertphillipsed313432014-12-16 09:31:42 -08001121 errors.add(this->compareTestResultsToStoredExpectations(
vandebo@chromium.org8fc37662013-08-21 18:04:09 +00001122 gm, gRec, gRec.fName, NULL));
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001123
1124 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) {
robertphillipsed313432014-12-16 09:31:42 -08001125 SkString path = make_filename(writePath, gm->getName(), gRec.fName, "", "xps");
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001126 errors.add(write_document(path, documentStream));
1127 }
epoger@google.come33e1372013-07-08 19:13:33 +00001128 } else {
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001129 SkASSERT(false);
epoger@google.come33e1372013-07-08 19:13:33 +00001130 }
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001131 return errors;
epoger@google.comde961632012-10-26 18:56:36 +00001132 }
1133
epoger@google.com6f6568b2013-03-22 17:29:46 +00001134 ErrorCombination test_deferred_drawing(GM* gm,
1135 const ConfigData& gRec,
1136 const SkBitmap& referenceBitmap,
bsalomon@google.com123ac1d2013-03-28 19:18:12 +00001137 GrSurface* gpuTarget) {
epoger@google.comde961632012-10-26 18:56:36 +00001138 if (gRec.fBackend == kRaster_Backend ||
1139 gRec.fBackend == kGPU_Backend) {
epoger@google.comc8263e72013-04-10 12:17:34 +00001140 const char renderModeDescriptor[] = "-deferred";
epoger@google.comde961632012-10-26 18:56:36 +00001141 SkBitmap bitmap;
1142 // Early exit if we can't generate the image, but this is
1143 // expected in some cases, so don't report a test failure.
bsalomon@google.com123ac1d2013-03-28 19:18:12 +00001144 ErrorCombination errors = generate_image(gm, gRec, gpuTarget, &bitmap, true);
epoger@google.com6f6568b2013-03-22 17:29:46 +00001145 // TODO(epoger): This logic is the opposite of what is
1146 // described above... if we succeeded in generating the
1147 // -deferred image, we exit early! We should fix this
1148 // ASAP, because it is hiding -deferred errors... but for
1149 // now, I'm leaving the logic as it is so that the
1150 // refactoring change
1151 // https://codereview.chromium.org/12992003/ is unblocked.
1152 //
1153 // Filed as https://code.google.com/p/skia/issues/detail?id=1180
1154 // ('image-surface gm test is failing in "deferred" mode,
1155 // and gm is not reporting the failure')
1156 if (errors.isEmpty()) {
epoger@google.com310478e2013-04-03 18:00:39 +00001157 // TODO(epoger): Report this as a new ErrorType,
1158 // something like kImageGeneration_ErrorType?
epoger@google.com6f6568b2013-03-22 17:29:46 +00001159 return kEmpty_ErrorCombination;
epoger@google.comde961632012-10-26 18:56:36 +00001160 }
epoger@google.com37269602013-01-19 04:21:27 +00001161 return compare_test_results_to_reference_bitmap(
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001162 gm->getName(), gRec.fName, renderModeDescriptor, bitmap, &referenceBitmap);
epoger@google.comde961632012-10-26 18:56:36 +00001163 }
epoger@google.com6f6568b2013-03-22 17:29:46 +00001164 return kEmpty_ErrorCombination;
epoger@google.comde961632012-10-26 18:56:36 +00001165 }
1166
robertphillips8c508b42014-12-11 13:10:23 -08001167 static SkSurface* CreateSurface(const ConfigData& config,
1168 const SkISize& size,
1169 GrSurface* gpuTarget) {
1170 if (config.fBackend == kRaster_Backend) {
mtklein703dd2e2015-01-09 06:41:48 -08001171 SkImageInfo ii = SkImageInfo::Make(size.width(), size.height(),
robertphillips8c508b42014-12-11 13:10:23 -08001172 config.fColorType, kPremul_SkAlphaType);
1173
1174 return SkSurface::NewRaster(ii);
1175 }
1176#if SK_SUPPORT_GPU
1177 else {
1178 uint32_t flags = (config.fFlags & kDFText_ConfigFlag) ?
1179 SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0;
1180 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
1181 return SkSurface::NewRenderTargetDirect(gpuTarget->asRenderTarget(), &props);
1182 }
1183#endif
1184
1185 return NULL;
1186 }
1187
robertphillipsed313432014-12-16 09:31:42 -08001188 ErrorCombination writeBitmap(GM* gm,
1189 const ConfigData& config,
1190 const char* configName,
1191 const char* writePath,
1192 const SkBitmap& bitmap) {
1193 ErrorCombination errors;
1194
1195 BitmapAndDigest bitmapAndDigest(bitmap);
1196 errors.add(this->compareTestResultsToStoredExpectations(gm, config,
1197 configName, &bitmapAndDigest));
1198
1199 if (writePath && (config.fFlags & kWrite_ConfigFlag)) {
1200 SkString path;
1201
1202 path = this->makeBitmapFilename(writePath, gm->getName(), configName,
1203 "", bitmapAndDigest.fDigest);
1204 errors.add(WriteBitmap(path, bitmapAndDigest.fBitmap));
1205 }
1206
1207 return errors;
1208 }
1209
robertphillips8c508b42014-12-11 13:10:23 -08001210 ErrorCombination testMPDDrawing(GM* gm,
1211 const ConfigData& config,
robertphillipsed313432014-12-16 09:31:42 -08001212 const char* writePath,
robertphillips8c508b42014-12-11 13:10:23 -08001213 GrSurface* gpuTarget,
1214 const SkBitmap& referenceBitmap) {
1215 SkASSERT(kRaster_Backend == config.fBackend || kGPU_Backend == config.fBackend);
1216
1217 static const uint32_t kMPDFlags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag;
1218
1219 SkAutoTUnref<SkPicture> pict(generate_new_picture(gm, kRTree_BbhType, kMPDFlags));
1220
1221 SkAutoTUnref<SkSurface> surf(CreateSurface(config, gm->getISize(), gpuTarget));
1222
1223 DrawPictureToSurface(surf, pict, SK_Scalar1, false, true);
1224
1225 SkBitmap bitmap;
1226
1227 setup_bitmap(config, gm->getISize(), &bitmap);
1228
1229 surf->readPixels(bitmap.info(), bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
1230 complete_bitmap(&bitmap);
1231
robertphillipsed313432014-12-16 09:31:42 -08001232 SkString configName(config.fName);
1233 configName.append("-mpd");
1234
1235 return this->writeBitmap(gm, config, configName.c_str(), writePath, bitmap);
robertphillips8c508b42014-12-11 13:10:23 -08001236 }
1237
epoger@google.comcaac3db2013-04-04 19:23:11 +00001238 ErrorCombination test_pipe_playback(GM* gm, const ConfigData& gRec,
1239 const SkBitmap& referenceBitmap, bool simulateFailure) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001240 const SkString shortNamePlusConfig = make_shortname_plus_config(gm->getName(),
epoger@google.com659c8c02013-05-21 15:45:45 +00001241 gRec.fName);
epoger@google.com6f6568b2013-03-22 17:29:46 +00001242 ErrorCombination errors;
epoger@google.comde961632012-10-26 18:56:36 +00001243 for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) {
epoger@google.comc8263e72013-04-10 12:17:34 +00001244 SkString renderModeDescriptor("-pipe");
1245 renderModeDescriptor.append(gPipeWritingFlagCombos[i].name);
1246
commit-bot@chromium.org805df1a2013-08-16 19:18:12 +00001247 if (gm->getFlags() & GM::kSkipPipe_Flag
1248 || (gPipeWritingFlagCombos[i].flags == SkGPipeWriter::kCrossProcess_Flag
1249 && gm->getFlags() & GM::kSkipPipeCrossProcess_Flag)) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001250 RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
epoger@google.comc8263e72013-04-10 12:17:34 +00001251 renderModeDescriptor.c_str());
1252 errors.add(kIntentionallySkipped_ErrorType);
1253 } else {
1254 SkBitmap bitmap;
1255 SkISize size = gm->getISize();
1256 setup_bitmap(gRec, size, &bitmap);
1257 SkCanvas canvas(bitmap);
robertphillips8c508b42014-12-11 13:10:23 -08001258 InstallFilter(&canvas);
scroggo@google.com74b7ffd2013-04-30 02:32:41 +00001259 // Pass a decoding function so the factory GM (which has an SkBitmap
1260 // with encoded data) will not fail playback.
1261 PipeController pipeController(&canvas, &SkImageDecoder::DecodeMemory);
epoger@google.comc8263e72013-04-10 12:17:34 +00001262 SkGPipeWriter writer;
1263 SkCanvas* pipeCanvas = writer.startRecording(&pipeController,
scroggo@google.comaef2d3b2013-04-10 18:10:41 +00001264 gPipeWritingFlagCombos[i].flags,
1265 size.width(), size.height());
epoger@google.comc8263e72013-04-10 12:17:34 +00001266 if (!simulateFailure) {
1267 invokeGM(gm, pipeCanvas, false, false);
1268 }
1269 complete_bitmap(&bitmap);
1270 writer.endRecording();
1271 errors.add(compare_test_results_to_reference_bitmap(
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001272 gm->getName(), gRec.fName, renderModeDescriptor.c_str(), bitmap,
epoger@google.com659c8c02013-05-21 15:45:45 +00001273 &referenceBitmap));
epoger@google.comc8263e72013-04-10 12:17:34 +00001274 if (!errors.isEmpty()) {
1275 break;
1276 }
epoger@google.comde961632012-10-26 18:56:36 +00001277 }
1278 }
1279 return errors;
1280 }
1281
epoger@google.com6f6568b2013-03-22 17:29:46 +00001282 ErrorCombination test_tiled_pipe_playback(GM* gm, const ConfigData& gRec,
1283 const SkBitmap& referenceBitmap) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001284 const SkString shortNamePlusConfig = make_shortname_plus_config(gm->getName(),
epoger@google.com659c8c02013-05-21 15:45:45 +00001285 gRec.fName);
epoger@google.com6f6568b2013-03-22 17:29:46 +00001286 ErrorCombination errors;
epoger@google.comde961632012-10-26 18:56:36 +00001287 for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) {
epoger@google.comc8263e72013-04-10 12:17:34 +00001288 SkString renderModeDescriptor("-tiled pipe");
1289 renderModeDescriptor.append(gPipeWritingFlagCombos[i].name);
1290
1291 if ((gm->getFlags() & GM::kSkipPipe_Flag) ||
1292 (gm->getFlags() & GM::kSkipTiled_Flag)) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001293 RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
epoger@google.comc8263e72013-04-10 12:17:34 +00001294 renderModeDescriptor.c_str());
1295 errors.add(kIntentionallySkipped_ErrorType);
1296 } else {
1297 SkBitmap bitmap;
1298 SkISize size = gm->getISize();
1299 setup_bitmap(gRec, size, &bitmap);
1300 SkCanvas canvas(bitmap);
robertphillips8c508b42014-12-11 13:10:23 -08001301 InstallFilter(&canvas);
scroggo@google.com74b7ffd2013-04-30 02:32:41 +00001302 TiledPipeController pipeController(bitmap, &SkImageDecoder::DecodeMemory);
epoger@google.comc8263e72013-04-10 12:17:34 +00001303 SkGPipeWriter writer;
1304 SkCanvas* pipeCanvas = writer.startRecording(&pipeController,
scroggo@google.comaef2d3b2013-04-10 18:10:41 +00001305 gPipeWritingFlagCombos[i].flags,
1306 size.width(), size.height());
epoger@google.comc8263e72013-04-10 12:17:34 +00001307 invokeGM(gm, pipeCanvas, false, false);
1308 complete_bitmap(&bitmap);
1309 writer.endRecording();
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001310 errors.add(compare_test_results_to_reference_bitmap(gm->getName(), gRec.fName,
epoger@google.comc8263e72013-04-10 12:17:34 +00001311 renderModeDescriptor.c_str(),
1312 bitmap, &referenceBitmap));
1313 if (!errors.isEmpty()) {
1314 break;
1315 }
epoger@google.comde961632012-10-26 18:56:36 +00001316 }
1317 }
1318 return errors;
1319 }
epoger@google.come8ebeb12012-10-29 16:42:11 +00001320
1321 //
1322 // member variables.
1323 // They are public for now, to allow easier setting by tool_main().
1324 //
1325
epoger@google.com6f7f14d2013-06-19 18:28:31 +00001326 bool fUseFileHierarchy, fWriteChecksumBasedFilenames;
epoger@google.com5079d2c2013-04-12 14:11:21 +00001327 ErrorCombination fIgnorableErrorTypes;
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +00001328 SkTArray<SkString> fIgnorableTestNames;
epoger@google.come8ebeb12012-10-29 16:42:11 +00001329
junov@chromium.org95146eb2013-01-11 21:04:40 +00001330 const char* fMismatchPath;
epoger@google.com5f995452013-06-21 18:16:47 +00001331 const char* fMissingExpectationsPath;
junov@chromium.org95146eb2013-01-11 21:04:40 +00001332
epoger@google.com310478e2013-04-03 18:00:39 +00001333 // collection of tests that have failed with each ErrorType
1334 SkTArray<SkString> fFailedTests[kLast_ErrorType+1];
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001335 SkTArray<SkString> fTestsSkippedOnAllRenderModes;
epoger@google.com310478e2013-04-03 18:00:39 +00001336 int fTestsRun;
1337 SkTDict<int> fRenderModesEncountered;
epoger@google.com57f7abc2012-11-13 03:41:55 +00001338
epoger@google.com908f5832013-04-12 02:23:55 +00001339 // Where to read expectations (expected image hash digests, etc.) from.
epoger@google.com37269602013-01-19 04:21:27 +00001340 // If unset, we don't do comparisons.
1341 SkAutoTUnref<ExpectationsSource> fExpectationsSource;
1342
1343 // JSON summaries that we generate as we go (just for output).
epoger@google.comee8a8e32012-12-18 19:13:49 +00001344 Json::Value fJsonExpectedResults;
1345 Json::Value fJsonActualResults_Failed;
1346 Json::Value fJsonActualResults_FailureIgnored;
epoger@google.com9c56a8d2012-12-20 18:34:29 +00001347 Json::Value fJsonActualResults_NoComparison;
epoger@google.comee8a8e32012-12-18 19:13:49 +00001348 Json::Value fJsonActualResults_Succeeded;
epoger@google.comde961632012-10-26 18:56:36 +00001349}; // end of GMMain class definition
scroggo@google.com72c96722012-06-06 21:07:10 +00001350
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001351#if SK_SUPPORT_GPU
1352static const GLContextType kDontCare_GLContextType = GrContextFactory::kNative_GLContextType;
1353#else
1354static const GLContextType kDontCare_GLContextType = 0;
1355#endif
bsalomon@google.com7361f542012-04-19 19:15:35 +00001356
tomhudson@google.com9875dd12011-04-25 15:49:53 +00001357static const ConfigData gRec[] = {
reedddd014e2014-06-05 08:51:20 -07001358 { kN32_SkColorType, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "8888", true },
1359 { kRGB_565_SkColorType, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "565", true },
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001360#if SK_SUPPORT_GPU
reedddd014e2014-06-05 08:51:20 -07001361 { kN32_SkColorType, kGPU_Backend, GrContextFactory::kNative_GLContextType, 0, kRW_ConfigFlag, "gpu", true },
1362 { kN32_SkColorType, kGPU_Backend, GrContextFactory::kNative_GLContextType, 16, kRW_ConfigFlag, "msaa16", false},
1363 { kN32_SkColorType, kGPU_Backend, GrContextFactory::kNative_GLContextType, 4, kRW_ConfigFlag, "msaa4", false},
1364 { kN32_SkColorType, kGPU_Backend, GrContextFactory::kNVPR_GLContextType, 4, kRW_ConfigFlag, "nvprmsaa4", true },
1365 { kN32_SkColorType, kGPU_Backend, GrContextFactory::kNVPR_GLContextType, 16, kRW_ConfigFlag, "nvprmsaa16", false},
jvanverth2b074432014-11-07 13:49:49 -08001366 /* Not quite ready to turn on distance field text baselines */
1367 { kN32_SkColorType, kGPU_Backend, GrContextFactory::kNative_GLContextType, 0, kRWDFT_ConfigFlag, "gpudft", false },
epoger@google.comc824c832013-07-12 15:52:59 +00001368 /* The gpudebug context does not generate meaningful images, so don't record
1369 * the images it generates! We only run it to look for asserts. */
reedddd014e2014-06-05 08:51:20 -07001370 { kN32_SkColorType, kGPU_Backend, GrContextFactory::kDebug_GLContextType, 0, kNone_ConfigFlag, "gpudebug", kDebugOnly},
robertphillips@google.comd6543e52013-07-18 17:39:14 +00001371 /* The gpunull context does the least amount of work possible and doesn't
1372 generate meaninful images, so don't record them!. It can be run to
1373 isolate the CPU-side processing expense from the GPU-side.
1374 */
reedddd014e2014-06-05 08:51:20 -07001375 { kN32_SkColorType, kGPU_Backend, GrContextFactory::kNull_GLContextType, 0, kNone_ConfigFlag, "gpunull", kDebugOnly},
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001376#if SK_ANGLE
reedddd014e2014-06-05 08:51:20 -07001377 { kN32_SkColorType, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 0, kRW_ConfigFlag, "angle", true },
1378 { kN32_SkColorType, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 16, kRW_ConfigFlag, "anglemsaa16", true },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001379#endif // SK_ANGLE
1380#ifdef SK_MESA
reedddd014e2014-06-05 08:51:20 -07001381 { kN32_SkColorType, kGPU_Backend, GrContextFactory::kMESA_GLContextType, 0, kRW_ConfigFlag, "mesa", true },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001382#endif // SK_MESA
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001383#endif // SK_SUPPORT_GPU
bungeman@google.comb29c8832011-10-10 13:19:10 +00001384#ifdef SK_SUPPORT_XPS
bsalomon@google.com7361f542012-04-19 19:15:35 +00001385 /* At present we have no way of comparing XPS files (either natively or by converting to PNG). */
reedddd014e2014-06-05 08:51:20 -07001386 { kN32_SkColorType, kXPS_Backend, kDontCare_GLContextType, 0, kWrite_ConfigFlag, "xps", true },
robertphillips@google.coma73e8602012-08-02 17:56:02 +00001387#endif // SK_SUPPORT_XPS
bsalomon@google.com7361f542012-04-19 19:15:35 +00001388#ifdef SK_SUPPORT_PDF
reedddd014e2014-06-05 08:51:20 -07001389 { kN32_SkColorType, kPDF_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "pdf", true },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001390#endif // SK_SUPPORT_PDF
reed@android.com00dae862009-06-10 15:38:48 +00001391};
1392
bungeman@google.com5d20cae2014-05-09 15:22:41 +00001393static bool SkNoRasterizePDF(SkStream*, SkBitmap*) { return false; }
1394
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001395static const PDFRasterizerData kPDFRasterizers[] = {
1396#ifdef SK_BUILD_FOR_MAC
1397 { &SkPDFDocumentToBitmap, "mac", true },
1398#endif
1399#ifdef SK_BUILD_POPPLER
1400 { &SkPopplerRasterizePDF, "poppler", true },
1401#endif
commit-bot@chromium.orgffd178c2013-11-11 15:10:47 +00001402#ifdef SK_BUILD_NATIVE_PDF_RENDERER
1403 { &SkNativeRasterizePDF, "native", true },
1404#endif // SK_BUILD_NATIVE_PDF_RENDERER
bungeman@google.com5d20cae2014-05-09 15:22:41 +00001405 // The following exists so that this array is never zero length.
1406 { &SkNoRasterizePDF, "none", false},
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001407};
1408
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001409static const char kDefaultsConfigStr[] = "defaults";
1410static const char kExcludeConfigChar = '~';
kkinnunen80549fc2014-06-30 06:36:31 -07001411#if SK_SUPPORT_GPU
1412static const char kGpuAPINameGL[] = "gl";
1413static const char kGpuAPINameGLES[] = "gles";
1414#endif
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001415
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001416static SkString configUsage() {
scroggo@google.com0f567c62013-03-20 15:35:08 +00001417 SkString result;
1418 result.appendf("Space delimited list of which configs to run. Possible options: [");
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001419 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001420 SkASSERT(gRec[i].fName != kDefaultsConfigStr);
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001421 if (i > 0) {
scroggo@google.com0f567c62013-03-20 15:35:08 +00001422 result.append("|");
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001423 }
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001424 result.appendf("%s", gRec[i].fName);
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001425 }
scroggo@google.com0f567c62013-03-20 15:35:08 +00001426 result.append("]\n");
1427 result.appendf("The default value is: \"");
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001428 SkString firstDefault;
1429 SkString allButFirstDefaults;
1430 SkString nonDefault;
scroggo@google.com0f567c62013-03-20 15:35:08 +00001431 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
1432 if (gRec[i].fRunByDefault) {
1433 if (i > 0) {
1434 result.append(" ");
1435 }
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001436 result.append(gRec[i].fName);
1437 if (firstDefault.isEmpty()) {
1438 firstDefault = gRec[i].fName;
1439 } else {
1440 if (!allButFirstDefaults.isEmpty()) {
1441 allButFirstDefaults.append(" ");
1442 }
1443 allButFirstDefaults.append(gRec[i].fName);
1444 }
1445 } else {
1446 nonDefault = gRec[i].fName;
scroggo@google.com0f567c62013-03-20 15:35:08 +00001447 }
1448 }
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001449 result.append("\"\n");
1450 result.appendf("\"%s\" evaluates to the default set of configs.\n", kDefaultsConfigStr);
1451 result.appendf("Prepending \"%c\" on a config name excludes it from the set of configs to run.\n"
1452 "Exclusions always override inclusions regardless of order.\n",
1453 kExcludeConfigChar);
1454 result.appendf("E.g. \"--config %s %c%s %s\" will run these configs:\n\t%s %s",
1455 kDefaultsConfigStr,
1456 kExcludeConfigChar,
1457 firstDefault.c_str(),
1458 nonDefault.c_str(),
1459 allButFirstDefaults.c_str(),
1460 nonDefault.c_str());
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001461 return result;
scroggo@google.com0b735632013-03-19 17:38:50 +00001462}
scroggo@google.com7d519302013-03-19 17:28:10 +00001463
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001464static SkString pdfRasterizerUsage() {
1465 SkString result;
1466 result.appendf("Space delimited list of which PDF rasterizers to run. Possible options: [");
1467 // For this (and further) loops through kPDFRasterizers, there is a typecast to int to avoid
1468 // the compiler giving an "comparison of unsigned expression < 0 is always false" warning
1469 // and turning it into a build-breaking error.
1470 for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); ++i) {
1471 if (i > 0) {
1472 result.append(" ");
1473 }
1474 result.append(kPDFRasterizers[i].fName);
1475 }
1476 result.append("]\n");
1477 result.append("The default value is: \"");
1478 for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); ++i) {
1479 if (kPDFRasterizers[i].fRunByDefault) {
1480 if (i > 0) {
1481 result.append(" ");
1482 }
1483 result.append(kPDFRasterizers[i].fName);
1484 }
1485 }
1486 result.append("\"");
1487 return result;
1488}
1489
epoger@google.com6f6568b2013-03-22 17:29:46 +00001490// Macro magic to convert a numeric preprocessor token into a string.
1491// Adapted from http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
1492// This should probably be moved into one of our common headers...
1493#define TOSTRING_INTERNAL(x) #x
1494#define TOSTRING(x) TOSTRING_INTERNAL(x)
1495
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001496// Alphabetized ignoring "no" prefix ("readPath", "noreplay", "resourcePath").
scroggo@google.com0f567c62013-03-20 15:35:08 +00001497DEFINE_string(config, "", configUsage().c_str());
bsalomon69456182014-07-07 10:46:58 -07001498DEFINE_bool(cpu, true, "Allows non-GPU configs to be run. Applied after --config.");
vandebo@chromium.orgf8afb2b2013-11-06 16:32:15 +00001499DEFINE_string(pdfRasterizers, "default", pdfRasterizerUsage().c_str());
epoger@google.com5e497382013-09-30 07:01:55 +00001500DEFINE_bool(deferred, false, "Exercise the deferred rendering test pass.");
robertphillips8c508b42014-12-11 13:10:23 -08001501DEFINE_bool(mpd, false, "Exercise MultiPictureDraw.");
1502
commit-bot@chromium.orgb17ccc92014-03-13 16:16:36 +00001503DEFINE_bool(dryRun, false, "Don't actually run the tests, just print what would have been done.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001504DEFINE_string(excludeConfig, "", "Space delimited list of configs to skip.");
1505DEFINE_bool(forceBWtext, false, "Disable text anti-aliasing.");
1506#if SK_SUPPORT_GPU
kkinnunen80549fc2014-06-30 06:36:31 -07001507DEFINE_string(gpuAPI, "", "Force use of specific gpu API. Using \"gl\" "
1508 "forces OpenGL API. Using \"gles\" forces OpenGL ES API. "
1509 "Defaults to empty string, which selects the API native to the "
1510 "system.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001511DEFINE_string(gpuCacheSize, "", "<bytes> <count>: Limit the gpu cache to byte size or "
epoger@google.com6f6568b2013-03-22 17:29:46 +00001512 "object count. " TOSTRING(DEFAULT_CACHE_VALUE) " for either value means "
1513 "use the default. 0 for either disables the cache.");
bsalomon69456182014-07-07 10:46:58 -07001514DEFINE_bool(gpu, true, "Allows GPU configs to be run. Applied after --config.");
krajcevski12b35442014-08-13 12:06:26 -07001515DEFINE_bool(gpuCompressAlphaMasks, false, "Compress masks generated from falling back to "
1516 "software path rendering.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001517#endif
1518DEFINE_bool(hierarchy, false, "Whether to use multilevel directory structure "
1519 "when reading/writing files.");
epoger@google.com5079d2c2013-04-12 14:11:21 +00001520DEFINE_string(ignoreErrorTypes, kDefaultIgnorableErrorTypes.asString(" ").c_str(),
1521 "Space-separated list of ErrorTypes that should be ignored. If any *other* error "
1522 "types are encountered, the tool will exit with a nonzero return value.");
epoger@google.comf711f322013-10-18 14:55:47 +00001523DEFINE_string(ignoreFailuresFile, "", "Path to file containing a list of tests for which we "
1524 "should ignore failures.\n"
1525 "The file should list one test per line, except for comment lines starting with #");
commit-bot@chromium.org6dda8272014-01-23 17:21:19 +00001526DEFINE_bool2(leaks, l, false, "show leaked ref cnt'd objects.");
caryclark@google.com512c9b62013-05-10 15:16:13 +00001527DEFINE_string(match, "", "[~][^]substring[$] [...] of test name to run.\n"
1528 "Multiple matches may be separated by spaces.\n"
1529 "~ causes a matching test to always be skipped\n"
1530 "^ requires the start of the test to match\n"
1531 "$ requires the end of the test to match\n"
1532 "^ and $ requires an exact match\n"
1533 "If a test does not match any list entry,\n"
1534 "it is skipped unless some list entry starts with ~");
epoger@google.com5f995452013-06-21 18:16:47 +00001535DEFINE_string(missingExpectationsPath, "", "Write images for tests without expectations "
1536 "into this directory.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001537DEFINE_string(mismatchPath, "", "Write images for tests that failed due to "
1538 "pixel mismatches into this directory.");
1539DEFINE_string(modulo, "", "[--modulo <remainder> <divisor>]: only run tests for which "
1540 "testIndex %% divisor == remainder.");
epoger@google.com5e497382013-09-30 07:01:55 +00001541DEFINE_bool(pipe, false, "Exercise the SkGPipe replay test pass.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001542DEFINE_string2(readPath, r, "", "Read reference images from this dir, and report "
1543 "any differences between those and the newly generated ones.");
epoger@google.com5e497382013-09-30 07:01:55 +00001544DEFINE_bool(replay, false, "Exercise the SkPicture replay test pass.");
bsalomonb82b9d52014-10-08 08:17:11 -07001545
1546#ifdef SK_BUILD_FOR_ANDROID
1547DEFINE_bool(resetGpuContext, true, "Reset the GrContext prior to running each GM.");
1548#else
djsollen@google.comac8f3a42013-10-04 14:57:00 +00001549DEFINE_bool(resetGpuContext, false, "Reset the GrContext prior to running each GM.");
1550#endif
bsalomonb82b9d52014-10-08 08:17:11 -07001551
epoger@google.com5e497382013-09-30 07:01:55 +00001552DEFINE_bool(rtree, false, "Exercise the R-Tree variant of SkPicture test pass.");
1553DEFINE_bool(serialize, false, "Exercise the SkPicture serialization & deserialization test pass.");
epoger@google.comcaac3db2013-04-04 19:23:11 +00001554DEFINE_bool(simulatePipePlaybackFailure, false, "Simulate a rendering failure in pipe mode only.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001555DEFINE_bool(tiledPipe, false, "Exercise tiled SkGPipe replay.");
epoger@google.com5e497382013-09-30 07:01:55 +00001556DEFINE_bool(tileGrid, false, "Exercise the tile grid variant of SkPicture.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001557DEFINE_string(tileGridReplayScales, "", "Space separated list of floating-point scale "
1558 "factors to be used for tileGrid playback testing. Default value: 1.0");
epoger@google.comb0f8b432013-04-10 18:46:25 +00001559DEFINE_bool2(verbose, v, false, "Give more detail (e.g. list all GMs run, more info about "
1560 "each test).");
epoger@google.com6f7f14d2013-06-19 18:28:31 +00001561DEFINE_bool(writeChecksumBasedFilenames, false, "When writing out actual images, use checksum-"
1562 "based filenames, as rebaseline.py will use when downloading them from Google Storage");
1563DEFINE_string(writeJsonSummaryPath, "", "Write a JSON-formatted result summary to this file.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001564DEFINE_string2(writePath, w, "", "Write rendered images into this directory.");
scroggo@google.com604e0c22013-04-09 21:25:46 +00001565DEFINE_string2(writePicturePath, p, "", "Write .skp files into this directory.");
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001566DEFINE_int32(pdfJpegQuality, -1, "Encodes images in JPEG at quality level N, "
1567 "which can be in range 0-100). N = -1 will disable JPEG compression. "
1568 "Default is N = 100, maximum quality.");
commit-bot@chromium.orgf4f9df42013-09-26 20:44:24 +00001569// TODO(edisonn): pass a matrix instead of forcePerspectiveMatrix
1570// Either the 9 numbers defining the matrix
1571// or probably more readable would be to replace it with a set of a few predicates
1572// Like --prerotate 100 200 10 --posttranslate 10, 10
1573// Probably define spacial names like centerx, centery, top, bottom, left, right
1574// then we can write something reabable like --rotate centerx centery 90
1575DEFINE_bool(forcePerspectiveMatrix, false, "Force a perspective matrix.");
caryclarkac8d8b82015-01-07 07:36:52 -08001576DEFINE_bool(useDocumentInsteadOfDevice, false, "Use SkDocument::CreateFoo instead of SkFooDevice.");
edisonn@google.com73a7ea32013-11-11 20:55:15 +00001577DEFINE_int32(pdfRasterDpi, 72, "Scale at which at which the non suported "
1578 "features in PDF are rasterized. Must be be in range 0-10000. "
1579 "Default is 72. N = 0 will disable rasterizing features like "
1580 "text shadows or perspective bitmaps.");
reed@google.com672588b2014-01-08 15:42:01 +00001581static SkData* encode_to_dct_data(size_t*, const SkBitmap& bitmap) {
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001582 // Filter output of warnings that JPEG is not available for the image.
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001583 if (bitmap.width() >= 65500 || bitmap.height() >= 65500) return NULL;
1584 if (FLAGS_pdfJpegQuality == -1) return NULL;
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001585
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001586 SkBitmap bm = bitmap;
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001587#if defined(SK_BUILD_FOR_MAC)
1588 // Workaround bug #1043 where bitmaps with referenced pixels cause
1589 // CGImageDestinationFinalize to crash
1590 SkBitmap copy;
commit-bot@chromium.orgd5f032d2014-02-24 18:51:43 +00001591 bitmap.deepCopyTo(&copy);
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001592 bm = copy;
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001593#endif
1594
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001595 SkPixelRef* pr = bm.pixelRef();
1596 if (pr != NULL) {
1597 SkData* data = pr->refEncodedData();
1598 if (data != NULL) {
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001599 return data;
1600 }
1601 }
1602
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001603 return SkImageEncoder::EncodeData(bm,
1604 SkImageEncoder::kJPEG_Type,
1605 FLAGS_pdfJpegQuality);
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001606}
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001607
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001608static int findConfig(const char config[]) {
1609 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
1610 if (!strcmp(config, gRec[i].fName)) {
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001611 return (int) i;
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001612 }
1613 }
1614 return -1;
1615}
1616
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001617static const PDFRasterizerData* findPDFRasterizer(const char rasterizer[]) {
1618 for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); i++) {
1619 if (!strcmp(rasterizer, kPDFRasterizers[i].fName)) {
1620 return &kPDFRasterizers[i];
1621 }
1622 }
1623 return NULL;
1624}
1625
reed@google.comfb2cd422013-01-04 14:43:03 +00001626template <typename T> void appendUnique(SkTDArray<T>* array, const T& value) {
1627 int index = array->find(value);
1628 if (index < 0) {
1629 *array->append() = value;
1630 }
1631}
1632
epoger@google.com80724df2013-03-21 13:49:54 +00001633/**
epoger@google.com80724df2013-03-21 13:49:54 +00001634 * Run this test in a number of different drawing modes (pipe,
1635 * deferred, tiled, etc.), confirming that the resulting bitmaps all
1636 * *exactly* match comparisonBitmap.
1637 *
1638 * Returns all errors encountered while doing so.
1639 */
robertphillips478dd722014-12-16 08:25:55 -08001640ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm,
1641 const ConfigData &compareConfig, GrSurface* gpuTarget,
epoger@google.com6f6568b2013-03-22 17:29:46 +00001642 const SkBitmap &comparisonBitmap,
1643 const SkTDArray<SkScalar> &tileGridReplayScales);
robertphillips478dd722014-12-16 08:25:55 -08001644ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm,
1645 const ConfigData &compareConfig, GrSurface* gpuTarget,
epoger@google.com6f6568b2013-03-22 17:29:46 +00001646 const SkBitmap &comparisonBitmap,
1647 const SkTDArray<SkScalar> &tileGridReplayScales) {
1648 ErrorCombination errorsForAllModes;
epoger@google.com80724df2013-03-21 13:49:54 +00001649 uint32_t gmFlags = gm->getFlags();
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001650 const SkString shortNamePlusConfig = gmmain.make_shortname_plus_config(gm->getName(),
epoger@google.com659c8c02013-05-21 15:45:45 +00001651 compareConfig.fName);
epoger@google.com80724df2013-03-21 13:49:54 +00001652
epoger@google.comc8263e72013-04-10 12:17:34 +00001653 SkPicture* pict = gmmain.generate_new_picture(gm, kNone_BbhType, 0);
mtklein08d1fcc2014-11-20 09:18:31 -08001654 SkAutoTUnref<SkPicture> aur(pict);
epoger@google.comc8263e72013-04-10 12:17:34 +00001655 if (FLAGS_replay) {
1656 const char renderModeDescriptor[] = "-replay";
1657 if (gmFlags & GM::kSkipPicture_Flag) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001658 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
1659 renderModeDescriptor);
epoger@google.comc8263e72013-04-10 12:17:34 +00001660 errorsForAllModes.add(kIntentionallySkipped_ErrorType);
1661 } else {
epoger@google.com80724df2013-03-21 13:49:54 +00001662 SkBitmap bitmap;
robertphillips478dd722014-12-16 08:25:55 -08001663 gmmain.generate_image_from_picture(gm, compareConfig, gpuTarget, pict, &bitmap);
1664
epoger@google.comc8263e72013-04-10 12:17:34 +00001665 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap(
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001666 gm->getName(), compareConfig.fName, renderModeDescriptor, bitmap,
epoger@google.com659c8c02013-05-21 15:45:45 +00001667 &comparisonBitmap));
epoger@google.com80724df2013-03-21 13:49:54 +00001668 }
epoger@google.comc8263e72013-04-10 12:17:34 +00001669 }
epoger@google.com80724df2013-03-21 13:49:54 +00001670
epoger@google.comc8263e72013-04-10 12:17:34 +00001671 if (FLAGS_serialize) {
1672 const char renderModeDescriptor[] = "-serialize";
1673 if (gmFlags & GM::kSkipPicture_Flag) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001674 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
1675 renderModeDescriptor);
epoger@google.comc8263e72013-04-10 12:17:34 +00001676 errorsForAllModes.add(kIntentionallySkipped_ErrorType);
1677 } else {
epoger@google.com80724df2013-03-21 13:49:54 +00001678 SkPicture* repict = gmmain.stream_to_new_picture(*pict);
mtklein08d1fcc2014-11-20 09:18:31 -08001679 SkAutoTUnref<SkPicture> aurr(repict);
epoger@google.com80724df2013-03-21 13:49:54 +00001680 SkBitmap bitmap;
robertphillips478dd722014-12-16 08:25:55 -08001681 gmmain.generate_image_from_picture(gm, compareConfig, gpuTarget, repict, &bitmap);
epoger@google.comc8263e72013-04-10 12:17:34 +00001682 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap(
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001683 gm->getName(), compareConfig.fName, renderModeDescriptor, bitmap,
epoger@google.com659c8c02013-05-21 15:45:45 +00001684 &comparisonBitmap));
epoger@google.com80724df2013-03-21 13:49:54 +00001685 }
epoger@google.com80724df2013-03-21 13:49:54 +00001686 }
1687
epoger@google.comc8263e72013-04-10 12:17:34 +00001688 if ((1 == FLAGS_writePicturePath.count()) &&
1689 !(gmFlags & GM::kSkipPicture_Flag)) {
1690 const char* pictureSuffix = "skp";
epoger@google.com659c8c02013-05-21 15:45:45 +00001691 // TODO(epoger): Make sure this still works even though the
1692 // filename now contains the config name (it used to contain
1693 // just the shortName). I think this is actually an
1694 // *improvement*, because now runs with different configs will
1695 // write out their SkPictures to separate files rather than
1696 // overwriting each other. But we should make sure it doesn't
1697 // break anybody.
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001698 SkString path = gmmain.make_filename(FLAGS_writePicturePath[0], gm->getName(),
epoger@google.com659c8c02013-05-21 15:45:45 +00001699 compareConfig.fName, "", pictureSuffix);
epoger@google.comc8263e72013-04-10 12:17:34 +00001700 SkFILEWStream stream(path.c_str());
1701 pict->serialize(&stream);
epoger@google.com80724df2013-03-21 13:49:54 +00001702 }
1703
epoger@google.comc8263e72013-04-10 12:17:34 +00001704 if (FLAGS_rtree) {
1705 const char renderModeDescriptor[] = "-rtree";
commit-bot@chromium.orgd393b172014-04-16 16:02:10 +00001706 if ((gmFlags & GM::kSkipPicture_Flag) || (gmFlags & GM::kSkipTiled_Flag)) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001707 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
1708 renderModeDescriptor);
epoger@google.comc8263e72013-04-10 12:17:34 +00001709 errorsForAllModes.add(kIntentionallySkipped_ErrorType);
1710 } else {
commit-bot@chromium.orgd393b172014-04-16 16:02:10 +00001711 SkPicture* pict = gmmain.generate_new_picture(gm, kRTree_BbhType, 0);
mtklein08d1fcc2014-11-20 09:18:31 -08001712 SkAutoTUnref<SkPicture> aur(pict);
commit-bot@chromium.orgd393b172014-04-16 16:02:10 +00001713 SkBitmap bitmap;
robertphillips478dd722014-12-16 08:25:55 -08001714 gmmain.generate_image_from_picture(gm, compareConfig, gpuTarget, pict, &bitmap);
commit-bot@chromium.orgd393b172014-04-16 16:02:10 +00001715 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap(
1716 gm->getName(), compareConfig.fName, renderModeDescriptor, bitmap,
1717 &comparisonBitmap));
1718 }
1719 }
1720
epoger@google.com80724df2013-03-21 13:49:54 +00001721 // run the pipe centric GM steps
epoger@google.comc8263e72013-04-10 12:17:34 +00001722 if (FLAGS_pipe) {
1723 errorsForAllModes.add(gmmain.test_pipe_playback(gm, compareConfig, comparisonBitmap,
1724 FLAGS_simulatePipePlaybackFailure));
1725 if (FLAGS_tiledPipe) {
1726 errorsForAllModes.add(gmmain.test_tiled_pipe_playback(gm, compareConfig,
1727 comparisonBitmap));
epoger@google.com80724df2013-03-21 13:49:54 +00001728 }
epoger@google.com80724df2013-03-21 13:49:54 +00001729 }
1730 return errorsForAllModes;
1731}
1732
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001733
1734/**
1735 * Run this test in a number of different configs (8888, 565, PDF,
1736 * etc.), confirming that the resulting bitmaps match expectations
1737 * (which may be different for each config).
1738 *
1739 * Returns all errors encountered while doing so.
1740 */
1741ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm,
1742 const SkTDArray<size_t> &configs,
1743 const SkTDArray<const PDFRasterizerData*> &pdfRasterizers,
1744 const SkTDArray<SkScalar> &tileGridReplayScales,
kkinnunen80549fc2014-06-30 06:36:31 -07001745 GrContextFactory *grFactory,
1746 GrGLStandard gpuAPI);
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001747ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm,
1748 const SkTDArray<size_t> &configs,
1749 const SkTDArray<const PDFRasterizerData*> &pdfRasterizers,
1750 const SkTDArray<SkScalar> &tileGridReplayScales,
kkinnunen80549fc2014-06-30 06:36:31 -07001751 GrContextFactory *grFactory,
1752 GrGLStandard gpuAPI) {
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001753 const char renderModeDescriptor[] = "";
1754 ErrorCombination errorsForAllConfigs;
1755 uint32_t gmFlags = gm->getFlags();
1756
1757 for (int i = 0; i < configs.count(); i++) {
1758 ConfigData config = gRec[configs[i]];
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001759 const SkString shortNamePlusConfig = gmmain.make_shortname_plus_config(gm->getName(),
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001760 config.fName);
1761
1762 // Skip any tests that we don't even need to try.
1763 // If any of these were skipped on a per-GM basis, record them as
1764 // kIntentionallySkipped.
1765 if (kPDF_Backend == config.fBackend) {
1766 if (gmFlags & GM::kSkipPDF_Flag) {
1767 gmmain.RecordSkippedTest(shortNamePlusConfig,
1768 renderModeDescriptor,
1769 config.fBackend);
1770 errorsForAllConfigs.add(kIntentionallySkipped_ErrorType);
1771 continue;
1772 }
1773 }
1774 if ((gmFlags & GM::kSkip565_Flag) &&
1775 (kRaster_Backend == config.fBackend) &&
reedddd014e2014-06-05 08:51:20 -07001776 (kRGB_565_SkColorType == config.fColorType)) {
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001777 gmmain.RecordSkippedTest(shortNamePlusConfig,
1778 renderModeDescriptor,
1779 config.fBackend);
1780 errorsForAllConfigs.add(kIntentionallySkipped_ErrorType);
1781 continue;
1782 }
1783 if (((gmFlags & GM::kSkipGPU_Flag) && kGPU_Backend == config.fBackend) ||
1784 ((gmFlags & GM::kGPUOnly_Flag) && kGPU_Backend != config.fBackend)) {
1785 gmmain.RecordSkippedTest(shortNamePlusConfig,
1786 renderModeDescriptor,
1787 config.fBackend);
1788 errorsForAllConfigs.add(kIntentionallySkipped_ErrorType);
1789 continue;
1790 }
1791
1792 // Now we know that we want to run this test and record its
1793 // success or failure.
1794 ErrorCombination errorsForThisConfig;
1795 GrSurface* gpuTarget = NULL;
1796#if SK_SUPPORT_GPU
1797 SkAutoTUnref<GrSurface> auGpuTarget;
1798 if ((errorsForThisConfig.isEmpty()) && (kGPU_Backend == config.fBackend)) {
1799 if (FLAGS_resetGpuContext) {
1800 grFactory->destroyContexts();
1801 }
kkinnunen80549fc2014-06-30 06:36:31 -07001802 GrContext* gr = grFactory->get(config.fGLContextType, gpuAPI);
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001803 bool grSuccess = false;
1804 if (gr) {
1805 // create a render target to back the device
bsalomonf2703d82014-10-28 14:33:06 -07001806 GrSurfaceDesc desc;
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001807 desc.fConfig = kSkia8888_GrPixelConfig;
bsalomonf2703d82014-10-28 14:33:06 -07001808 desc.fFlags = kRenderTarget_GrSurfaceFlag;
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001809 desc.fWidth = gm->getISize().width();
1810 desc.fHeight = gm->getISize().height();
1811 desc.fSampleCnt = config.fSampleCnt;
1812 auGpuTarget.reset(gr->createUncachedTexture(desc, NULL, 0));
bsalomon49f085d2014-09-05 13:34:00 -07001813 if (auGpuTarget) {
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001814 gpuTarget = auGpuTarget;
1815 grSuccess = true;
1816 // Set the user specified cache limits if non-default.
1817 size_t bytes;
1818 int count;
commit-bot@chromium.org95c20032014-05-09 14:29:32 +00001819 gr->getResourceCacheLimits(&count, &bytes);
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001820 if (DEFAULT_CACHE_VALUE != gGpuCacheSizeBytes) {
1821 bytes = static_cast<size_t>(gGpuCacheSizeBytes);
1822 }
1823 if (DEFAULT_CACHE_VALUE != gGpuCacheSizeCount) {
1824 count = gGpuCacheSizeCount;
1825 }
commit-bot@chromium.org95c20032014-05-09 14:29:32 +00001826 gr->setResourceCacheLimits(count, bytes);
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001827 }
1828 }
1829 if (!grSuccess) {
1830 errorsForThisConfig.add(kNoGpuContext_ErrorType);
1831 }
1832 }
1833#endif
1834
1835 SkBitmap comparisonBitmap;
1836
1837 const char* writePath;
1838 if (FLAGS_writePath.count() == 1) {
1839 writePath = FLAGS_writePath[0];
1840 } else {
1841 writePath = NULL;
1842 }
1843
1844 if (errorsForThisConfig.isEmpty()) {
1845 errorsForThisConfig.add(gmmain.test_drawing(gm, config, pdfRasterizers,
1846 writePath, gpuTarget,
1847 &comparisonBitmap));
1848 gmmain.RecordTestResults(errorsForThisConfig, shortNamePlusConfig, "");
1849 }
1850
1851 // TODO: run only if gmmain.test_drawing succeeded.
1852 if (kRaster_Backend == config.fBackend) {
robertphillips478dd722014-12-16 08:25:55 -08001853 run_multiple_modes(gmmain, gm, config, gpuTarget, comparisonBitmap, tileGridReplayScales);
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001854 }
1855
1856 if (FLAGS_deferred && errorsForThisConfig.isEmpty() &&
1857 (kGPU_Backend == config.fBackend || kRaster_Backend == config.fBackend)) {
1858 errorsForThisConfig.add(gmmain.test_deferred_drawing(gm, config, comparisonBitmap,
1859 gpuTarget));
1860 }
1861
robertphillips8c508b42014-12-11 13:10:23 -08001862 if (FLAGS_mpd && (kGPU_Backend == config.fBackend || kRaster_Backend == config.fBackend)) {
1863
1864 if (gmFlags & GM::kSkipPicture_Flag) {
1865 gmmain.RecordSkippedTest(shortNamePlusConfig,
1866 renderModeDescriptor,
1867 config.fBackend);
1868 errorsForThisConfig.add(kIntentionallySkipped_ErrorType);
1869 } else if (!(gmFlags & GM::kGPUOnly_Flag)) {
mtklein703dd2e2015-01-09 06:41:48 -08001870 errorsForThisConfig.add(gmmain.testMPDDrawing(gm, config,
robertphillipsed313432014-12-16 09:31:42 -08001871 writePath, gpuTarget,
robertphillips8c508b42014-12-11 13:10:23 -08001872 comparisonBitmap));
1873 }
1874 }
1875
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001876 errorsForAllConfigs.add(errorsForThisConfig);
1877 }
1878 return errorsForAllConfigs;
1879}
1880
1881
epoger@google.com310478e2013-04-03 18:00:39 +00001882/**
epoger@google.comf711f322013-10-18 14:55:47 +00001883 * Read individual lines from a file, pushing them into the given array.
1884 *
1885 * @param filename path to the file to read
1886 * @param lines array of strings to add the lines to
1887 * @returns true if able to read lines from the file
1888 */
1889static bool read_lines_from_file(const char* filename, SkTArray<SkString> &lines) {
1890 SkAutoTUnref<SkStream> streamWrapper(SkStream::NewFromFile(filename));
1891 SkStream *stream = streamWrapper.get();
1892 if (!stream) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00001893 SkDebugf("unable to read file '%s'\n", filename);
epoger@google.comf711f322013-10-18 14:55:47 +00001894 return false;
1895 }
1896
1897 char c;
1898 SkString line;
1899 while (1 == stream->read(&c, 1)) {
1900 // If we hit either CR or LF, we've completed a line.
1901 //
1902 // TODO: If the file uses both CR and LF, this will return an extra blank
1903 // line for each line of the file. Which is OK for current purposes...
1904 //
1905 // TODO: Does this properly handle unicode? It doesn't matter for
1906 // current purposes...
1907 if ((c == 0x0d) || (c == 0x0a)) {
1908 lines.push_back(line);
1909 line.reset();
1910 } else {
1911 line.append(&c, 1);
1912 }
1913 }
1914 lines.push_back(line);
1915 return true;
1916}
1917
1918/**
epoger@google.com310478e2013-04-03 18:00:39 +00001919 * Return a list of all entries in an array of strings as a single string
1920 * of this form:
1921 * "item1", "item2", "item3"
1922 */
1923SkString list_all(const SkTArray<SkString> &stringArray);
1924SkString list_all(const SkTArray<SkString> &stringArray) {
1925 SkString total;
1926 for (int i = 0; i < stringArray.count(); i++) {
1927 if (i > 0) {
1928 total.append(", ");
1929 }
1930 total.append("\"");
1931 total.append(stringArray[i]);
1932 total.append("\"");
1933 }
1934 return total;
1935}
1936
1937/**
1938 * Return a list of configuration names, as a single string of this form:
1939 * "item1", "item2", "item3"
1940 *
1941 * @param configs configurations, as a list of indices into gRec
1942 */
1943SkString list_all_config_names(const SkTDArray<size_t> &configs);
1944SkString list_all_config_names(const SkTDArray<size_t> &configs) {
1945 SkString total;
1946 for (int i = 0; i < configs.count(); i++) {
1947 if (i > 0) {
1948 total.append(", ");
1949 }
1950 total.append("\"");
1951 total.append(gRec[configs[i]].fName);
1952 total.append("\"");
1953 }
1954 return total;
1955}
1956
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001957static bool prepare_subdirectories(const char *root, bool useFileHierarchy,
1958 const SkTDArray<size_t> &configs,
1959 const SkTDArray<const PDFRasterizerData*>& pdfRasterizers) {
epoger@google.comfdea3252013-05-02 18:24:03 +00001960 if (!sk_mkdir(root)) {
1961 return false;
1962 }
1963 if (useFileHierarchy) {
1964 for (int i = 0; i < configs.count(); i++) {
1965 ConfigData config = gRec[configs[i]];
1966 SkString subdir;
1967 subdir.appendf("%s%c%s", root, SkPATH_SEPARATOR, config.fName);
1968 if (!sk_mkdir(subdir.c_str())) {
1969 return false;
1970 }
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001971
1972 if (config.fBackend == kPDF_Backend) {
1973 for (int j = 0; j < pdfRasterizers.count(); j++) {
1974 SkString pdfSubdir = subdir;
vandebo@chromium.org8fc37662013-08-21 18:04:09 +00001975 pdfSubdir.appendf("-%s", pdfRasterizers[j]->fName);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001976 if (!sk_mkdir(pdfSubdir.c_str())) {
1977 return false;
1978 }
1979 }
1980 }
epoger@google.comfdea3252013-05-02 18:24:03 +00001981 }
1982 }
1983 return true;
1984}
1985
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00001986static bool parse_flags_configs(SkTDArray<size_t>* outConfigs,
kkinnunen80549fc2014-06-30 06:36:31 -07001987 GrContextFactory* grFactory, GrGLStandard gpuAPI) {
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00001988 SkTDArray<size_t> excludeConfigs;
1989
1990 for (int i = 0; i < FLAGS_config.count(); i++) {
1991 const char* config = FLAGS_config[i];
1992 bool exclude = false;
1993 if (*config == kExcludeConfigChar) {
1994 exclude = true;
1995 config += 1;
1996 }
1997 int index = findConfig(config);
1998 if (index >= 0) {
1999 if (exclude) {
2000 *excludeConfigs.append() = index;
2001 } else {
2002 appendUnique<size_t>(outConfigs, index);
2003 }
2004 } else if (0 == strcmp(kDefaultsConfigStr, config)) {
2005 if (exclude) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002006 SkDebugf("%c%s is not allowed.\n",
2007 kExcludeConfigChar, kDefaultsConfigStr);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002008 return false;
2009 }
2010 for (size_t c = 0; c < SK_ARRAY_COUNT(gRec); ++c) {
2011 if (gRec[c].fRunByDefault) {
2012 appendUnique<size_t>(outConfigs, c);
2013 }
2014 }
2015 } else {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002016 SkDebugf("unrecognized config %s\n", config);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002017 return false;
2018 }
2019 }
2020
2021 for (int i = 0; i < FLAGS_excludeConfig.count(); i++) {
2022 int index = findConfig(FLAGS_excludeConfig[i]);
2023 if (index >= 0) {
2024 *excludeConfigs.append() = index;
2025 } else {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002026 SkDebugf("unrecognized excludeConfig %s\n", FLAGS_excludeConfig[i]);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002027 return false;
2028 }
2029 }
2030
2031 if (outConfigs->count() == 0) {
2032 // if no config is specified by user, add the defaults
2033 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
2034 if (gRec[i].fRunByDefault) {
2035 *outConfigs->append() = i;
2036 }
2037 }
2038 }
2039 // now remove any explicitly excluded configs
2040 for (int i = 0; i < excludeConfigs.count(); ++i) {
2041 int index = outConfigs->find(excludeConfigs[i]);
2042 if (index >= 0) {
2043 outConfigs->remove(index);
2044 // now assert that there was only one copy in configs[]
2045 SkASSERT(outConfigs->find(excludeConfigs[i]) < 0);
2046 }
2047 }
2048
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002049 for (int i = 0; i < outConfigs->count(); ++i) {
2050 size_t index = (*outConfigs)[i];
2051 if (kGPU_Backend == gRec[index].fBackend) {
bsalomon69456182014-07-07 10:46:58 -07002052#if SK_SUPPORT_GPU
2053 if (!FLAGS_gpu) {
2054 outConfigs->remove(i);
2055 --i;
2056 continue;
2057 }
2058#endif
2059 } else if (!FLAGS_cpu) {
2060 outConfigs->remove(i);
2061 --i;
2062 continue;
2063 }
2064#if SK_SUPPORT_GPU
2065 SkASSERT(grFactory != NULL);
2066 if (kGPU_Backend == gRec[index].fBackend) {
kkinnunen80549fc2014-06-30 06:36:31 -07002067 GrContext* ctx = grFactory->get(gRec[index].fGLContextType, gpuAPI);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002068 if (NULL == ctx) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002069 SkDebugf("GrContext could not be created for config %s. Config will be skipped.\n",
2070 gRec[index].fName);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002071 outConfigs->remove(i);
2072 --i;
2073 continue;
2074 }
2075 if (gRec[index].fSampleCnt > ctx->getMaxSampleCount()) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002076 SkDebugf("Sample count (%d) of config %s is not supported."
2077 " Config will be skipped.\n",
2078 gRec[index].fSampleCnt, gRec[index].fName);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002079 outConfigs->remove(i);
2080 --i;
2081 }
2082 }
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002083#endif
bsalomon69456182014-07-07 10:46:58 -07002084 }
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002085
2086 if (outConfigs->isEmpty()) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002087 SkDebugf("No configs to run.");
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002088 return false;
2089 }
2090
2091 // now show the user the set of configs that will be run.
2092 SkString configStr("These configs will be run:");
2093 // show the user the config that will run.
2094 for (int i = 0; i < outConfigs->count(); ++i) {
2095 configStr.appendf(" %s", gRec[(*outConfigs)[i]].fName);
2096 }
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002097 SkDebugf("%s\n", configStr.c_str());
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002098
2099 return true;
2100}
2101
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002102static bool parse_flags_pdf_rasterizers(const SkTDArray<size_t>& configs,
2103 SkTDArray<const PDFRasterizerData*>* outRasterizers) {
2104 // No need to run this check (and display the PDF rasterizers message)
2105 // if no PDF backends are in the configs.
2106 bool configHasPDF = false;
2107 for (int i = 0; i < configs.count(); i++) {
2108 if (gRec[configs[i]].fBackend == kPDF_Backend) {
2109 configHasPDF = true;
2110 break;
2111 }
2112 }
2113 if (!configHasPDF) {
2114 return true;
2115 }
2116
vandebo@chromium.orgf8afb2b2013-11-06 16:32:15 +00002117 if (FLAGS_pdfRasterizers.count() == 1 &&
2118 !strcmp(FLAGS_pdfRasterizers[0], "default")) {
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002119 for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); ++i) {
2120 if (kPDFRasterizers[i].fRunByDefault) {
2121 *outRasterizers->append() = &kPDFRasterizers[i];
2122 }
2123 }
vandebo@chromium.orgf8afb2b2013-11-06 16:32:15 +00002124 } else {
2125 for (int i = 0; i < FLAGS_pdfRasterizers.count(); i++) {
2126 const char* rasterizer = FLAGS_pdfRasterizers[i];
2127 const PDFRasterizerData* rasterizerPtr =
2128 findPDFRasterizer(rasterizer);
2129 if (rasterizerPtr == NULL) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002130 SkDebugf("unrecognized rasterizer %s\n", rasterizer);
vandebo@chromium.orgf8afb2b2013-11-06 16:32:15 +00002131 return false;
2132 }
2133 appendUnique<const PDFRasterizerData*>(outRasterizers,
2134 rasterizerPtr);
2135 }
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002136 }
2137
2138 // now show the user the set of configs that will be run.
2139 SkString configStr("These PDF rasterizers will be run:");
2140 // show the user the config that will run.
2141 for (int i = 0; i < outRasterizers->count(); ++i) {
2142 configStr.appendf(" %s", (*outRasterizers)[i]->fName);
2143 }
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002144 SkDebugf("%s\n", configStr.c_str());
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002145
2146 return true;
2147}
2148
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002149static bool parse_flags_ignore_error_types(ErrorCombination* outErrorTypes) {
2150 if (FLAGS_ignoreErrorTypes.count() > 0) {
2151 *outErrorTypes = ErrorCombination();
2152 for (int i = 0; i < FLAGS_ignoreErrorTypes.count(); i++) {
2153 ErrorType type;
2154 const char *name = FLAGS_ignoreErrorTypes[i];
2155 if (!getErrorTypeByName(name, &type)) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002156 SkDebugf("cannot find ErrorType with name '%s'\n", name);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002157 return false;
2158 } else {
2159 outErrorTypes->add(type);
2160 }
2161 }
2162 }
2163 return true;
2164}
2165
epoger@google.com3a882dd2013-10-07 18:55:09 +00002166/**
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +00002167 * Replace contents of ignoreTestNames with a list of test names, indicating
epoger@google.com3a882dd2013-10-07 18:55:09 +00002168 * which tests' failures should be ignored.
2169 */
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +00002170static bool parse_flags_ignore_tests(SkTArray<SkString> &ignoreTestNames) {
2171 ignoreTestNames.reset();
epoger@google.comf711f322013-10-18 14:55:47 +00002172
epoger@google.comf711f322013-10-18 14:55:47 +00002173 // Parse --ignoreFailuresFile
2174 for (int i = 0; i < FLAGS_ignoreFailuresFile.count(); i++) {
2175 SkTArray<SkString> linesFromFile;
2176 if (!read_lines_from_file(FLAGS_ignoreFailuresFile[i], linesFromFile)) {
2177 return false;
2178 } else {
2179 for (int j = 0; j < linesFromFile.count(); j++) {
2180 SkString thisLine = linesFromFile[j];
2181 if (thisLine.isEmpty() || thisLine.startsWith('#')) {
2182 // skip this line
2183 } else {
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +00002184 ignoreTestNames.push_back(thisLine);
epoger@google.comf711f322013-10-18 14:55:47 +00002185 }
2186 }
2187 }
2188 }
2189
epoger@google.com3a882dd2013-10-07 18:55:09 +00002190 return true;
2191}
2192
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002193static bool parse_flags_modulo(int* moduloRemainder, int* moduloDivisor) {
2194 if (FLAGS_modulo.count() == 2) {
2195 *moduloRemainder = atoi(FLAGS_modulo[0]);
2196 *moduloDivisor = atoi(FLAGS_modulo[1]);
2197 if (*moduloRemainder < 0 || *moduloDivisor <= 0 ||
2198 *moduloRemainder >= *moduloDivisor) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002199 SkDebugf("invalid modulo values.");
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002200 return false;
2201 }
2202 }
2203 return true;
2204}
2205
2206#if SK_SUPPORT_GPU
2207static bool parse_flags_gpu_cache(int* sizeBytes, int* sizeCount) {
2208 if (FLAGS_gpuCacheSize.count() > 0) {
2209 if (FLAGS_gpuCacheSize.count() != 2) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002210 SkDebugf("--gpuCacheSize requires two arguments\n");
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002211 return false;
2212 }
2213 *sizeBytes = atoi(FLAGS_gpuCacheSize[0]);
2214 *sizeCount = atoi(FLAGS_gpuCacheSize[1]);
2215 } else {
2216 *sizeBytes = DEFAULT_CACHE_VALUE;
2217 *sizeCount = DEFAULT_CACHE_VALUE;
2218 }
2219 return true;
2220}
kkinnunen80549fc2014-06-30 06:36:31 -07002221
2222static bool parse_flags_gl_standard(GrGLStandard* gpuAPI) {
2223 if (0 == FLAGS_gpuAPI.count()) {
2224 *gpuAPI = kNone_GrGLStandard;
2225 return true;
2226 }
2227 if (1 == FLAGS_gpuAPI.count()) {
2228 if (FLAGS_gpuAPI.contains(kGpuAPINameGL)) {
2229 *gpuAPI = kGL_GrGLStandard;
2230 return true;
2231 }
2232 if (FLAGS_gpuAPI.contains(kGpuAPINameGLES)) {
2233 *gpuAPI = kGLES_GrGLStandard;
2234 return true;
2235 }
2236 }
2237 SkDebugf("--gpuAPI invalid api value");
2238 return false;
2239}
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002240#endif
2241
2242static bool parse_flags_tile_grid_replay_scales(SkTDArray<SkScalar>* outScales) {
2243 *outScales->append() = SK_Scalar1; // By default only test at scale 1.0
2244 if (FLAGS_tileGridReplayScales.count() > 0) {
2245 outScales->reset();
2246 for (int i = 0; i < FLAGS_tileGridReplayScales.count(); i++) {
2247 double val = atof(FLAGS_tileGridReplayScales[i]);
2248 if (0 < val) {
2249 *outScales->append() = SkDoubleToScalar(val);
2250 }
2251 }
2252 if (0 == outScales->count()) {
2253 // Should have at least one scale
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002254 SkDebugf("--tileGridReplayScales requires at least one scale.\n");
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002255 return false;
2256 }
2257 }
2258 return true;
2259}
2260
2261static bool parse_flags_gmmain_paths(GMMain* gmmain) {
2262 gmmain->fUseFileHierarchy = FLAGS_hierarchy;
2263 gmmain->fWriteChecksumBasedFilenames = FLAGS_writeChecksumBasedFilenames;
2264
2265 if (FLAGS_mismatchPath.count() == 1) {
2266 gmmain->fMismatchPath = FLAGS_mismatchPath[0];
2267 }
2268
2269 if (FLAGS_missingExpectationsPath.count() == 1) {
2270 gmmain->fMissingExpectationsPath = FLAGS_missingExpectationsPath[0];
2271 }
2272
2273 if (FLAGS_readPath.count() == 1) {
2274 const char* readPath = FLAGS_readPath[0];
2275 if (!sk_exists(readPath)) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002276 SkDebugf("readPath %s does not exist!\n", readPath);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002277 return false;
2278 }
2279 if (sk_isdir(readPath)) {
2280 if (FLAGS_verbose) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002281 SkDebugf("reading from %s\n", readPath);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002282 }
2283 gmmain->fExpectationsSource.reset(SkNEW_ARGS(
2284 IndividualImageExpectationsSource, (readPath)));
2285 } else {
2286 if (FLAGS_verbose) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002287 SkDebugf("reading expectations from JSON summary file %s\n", readPath);
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002288 }
2289 gmmain->fExpectationsSource.reset(SkNEW_ARGS(JsonExpectationsSource, (readPath)));
2290 }
2291 }
2292 return true;
2293}
2294
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002295static bool parse_flags_jpeg_quality() {
2296 if (FLAGS_pdfJpegQuality < -1 || FLAGS_pdfJpegQuality > 100) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002297 SkDebugf("%s\n", "pdfJpegQuality must be in [-1 .. 100] range.");
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002298 return false;
2299 }
2300 return true;
2301}
2302
epoger@google.com0b62b3d2013-03-20 17:59:28 +00002303int tool_main(int argc, char** argv);
2304int tool_main(int argc, char** argv) {
mtklein30e6e2a2014-06-18 11:44:15 -07002305 SetupCrashHandler();
epoger@google.com0b62b3d2013-03-20 17:59:28 +00002306
commit-bot@chromium.org6dda8272014-01-23 17:21:19 +00002307 SkString usage;
2308 usage.printf("Run the golden master tests.\n");
2309 SkCommandLineFlags::SetUsage(usage.c_str());
2310 SkCommandLineFlags::Parse(argc, argv);
2311
epoger@google.com0b62b3d2013-03-20 17:59:28 +00002312#if SK_ENABLE_INST_COUNT
commit-bot@chromium.org6dda8272014-01-23 17:21:19 +00002313 if (FLAGS_leaks) {
2314 gPrintInstCount = true;
2315 }
epoger@google.com0b62b3d2013-03-20 17:59:28 +00002316#endif
2317
tfarinaa71d3af2014-11-07 06:12:30 -08002318 SkAutoGraphics ag;
epoger@google.com0b62b3d2013-03-20 17:59:28 +00002319
2320 setSystemPreferences();
2321 GMMain gmmain;
2322
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002323 SkTDArray<size_t> configs;
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002324
scroggo@google.com09fd4d22013-03-20 14:20:18 +00002325 int moduloRemainder = -1;
2326 int moduloDivisor = -1;
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002327 SkTDArray<const PDFRasterizerData*> pdfRasterizers;
epoger@google.com6f6568b2013-03-22 17:29:46 +00002328 SkTDArray<SkScalar> tileGridReplayScales;
bsalomon@google.com4c75f242013-03-19 18:58:43 +00002329#if SK_SUPPORT_GPU
kkinnunen80549fc2014-06-30 06:36:31 -07002330 GrGLStandard gpuAPI = kNone_GrGLStandard;
krajcevski12b35442014-08-13 12:06:26 -07002331 GrContext::Options grContextOpts;
2332 grContextOpts.fDrawPathToCompressedTexture = FLAGS_gpuCompressAlphaMasks;
2333 GrContextFactory* grFactory = new GrContextFactory(grContextOpts);
epoger@google.com80724df2013-03-21 13:49:54 +00002334#else
kkinnunen80549fc2014-06-30 06:36:31 -07002335 GrGLStandard gpuAPI = 0;
epoger@google.com80724df2013-03-21 13:49:54 +00002336 GrContextFactory* grFactory = NULL;
bsalomon@google.com4c75f242013-03-19 18:58:43 +00002337#endif
2338
commit-bot@chromium.orgb17ccc92014-03-13 16:16:36 +00002339 if (FLAGS_dryRun) {
2340 SkDebugf( "Doing a dry run; no tests will actually be executed.\n");
2341 }
2342
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002343 if (!parse_flags_modulo(&moduloRemainder, &moduloDivisor) ||
2344 !parse_flags_ignore_error_types(&gmmain.fIgnorableErrorTypes) ||
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +00002345 !parse_flags_ignore_tests(gmmain.fIgnorableTestNames) ||
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002346#if SK_SUPPORT_GPU
2347 !parse_flags_gpu_cache(&gGpuCacheSizeBytes, &gGpuCacheSizeCount) ||
kkinnunen80549fc2014-06-30 06:36:31 -07002348 !parse_flags_gl_standard(&gpuAPI) ||
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002349#endif
2350 !parse_flags_tile_grid_replay_scales(&tileGridReplayScales) ||
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002351 !parse_flags_jpeg_quality() ||
kkinnunen80549fc2014-06-30 06:36:31 -07002352 !parse_flags_configs(&configs, grFactory, gpuAPI) ||
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002353 !parse_flags_pdf_rasterizers(configs, &pdfRasterizers) ||
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002354 !parse_flags_gmmain_paths(&gmmain)) {
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00002355 return -1;
2356 }
2357
epoger@google.comb0f8b432013-04-10 18:46:25 +00002358 if (FLAGS_verbose) {
2359 if (FLAGS_writePath.count() == 1) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002360 SkDebugf("writing to %s\n", FLAGS_writePath[0]);
epoger@google.comb0f8b432013-04-10 18:46:25 +00002361 }
bsalomon49f085d2014-09-05 13:34:00 -07002362 if (gmmain.fMismatchPath) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002363 SkDebugf("writing mismatches to %s\n", gmmain.fMismatchPath);
epoger@google.comfdea3252013-05-02 18:24:03 +00002364 }
bsalomon49f085d2014-09-05 13:34:00 -07002365 if (gmmain.fMissingExpectationsPath) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002366 SkDebugf("writing images without expectations to %s\n",
2367 gmmain.fMissingExpectationsPath);
epoger@google.com5f995452013-06-21 18:16:47 +00002368 }
epoger@google.comb0f8b432013-04-10 18:46:25 +00002369 if (FLAGS_writePicturePath.count() == 1) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002370 SkDebugf("writing pictures to %s\n", FLAGS_writePicturePath[0]);
epoger@google.comb0f8b432013-04-10 18:46:25 +00002371 }
tfarinabcbc1782014-06-18 14:32:48 -07002372 if (!GetResourcePath().isEmpty()) {
2373 SkDebugf("reading resources from %s\n", GetResourcePath().c_str());
epoger@google.comb0f8b432013-04-10 18:46:25 +00002374 }
robertphillips@google.com8570b5c2012-03-20 17:40:58 +00002375 }
2376
epoger@google.com310478e2013-04-03 18:00:39 +00002377 int gmsRun = 0;
reed@google.comae7b8f32012-10-18 21:30:57 +00002378 int gmIndex = -1;
2379 SkString moduloStr;
2380
commit-bot@chromium.orgb17ccc92014-03-13 16:16:36 +00002381 if (!FLAGS_dryRun) {
2382 // If we will be writing out files, prepare subdirectories.
2383 if (FLAGS_writePath.count() == 1) {
2384 if (!prepare_subdirectories(FLAGS_writePath[0], gmmain.fUseFileHierarchy,
2385 configs, pdfRasterizers)) {
2386 return -1;
2387 }
2388 }
bsalomon49f085d2014-09-05 13:34:00 -07002389 if (gmmain.fMismatchPath) {
commit-bot@chromium.orgb17ccc92014-03-13 16:16:36 +00002390 if (!prepare_subdirectories(gmmain.fMismatchPath, gmmain.fUseFileHierarchy,
2391 configs, pdfRasterizers)) {
2392 return -1;
2393 }
2394 }
bsalomon49f085d2014-09-05 13:34:00 -07002395 if (gmmain.fMissingExpectationsPath) {
commit-bot@chromium.orgb17ccc92014-03-13 16:16:36 +00002396 if (!prepare_subdirectories(gmmain.fMissingExpectationsPath, gmmain.fUseFileHierarchy,
2397 configs, pdfRasterizers)) {
2398 return -1;
2399 }
epoger@google.come8ebeb12012-10-29 16:42:11 +00002400 }
epoger@google.comfdea3252013-05-02 18:24:03 +00002401 }
bsalomon@google.com7361f542012-04-19 19:15:35 +00002402 Iter iter;
2403 GM* gm;
reed@android.com00dae862009-06-10 15:38:48 +00002404 while ((gm = iter.next()) != NULL) {
commit-bot@chromium.orgf4f9df42013-09-26 20:44:24 +00002405 if (FLAGS_forcePerspectiveMatrix) {
2406 SkMatrix perspective;
2407 perspective.setIdentity();
2408 perspective.setPerspY(SkScalarDiv(SK_Scalar1, SkIntToScalar(1000)));
2409 perspective.setSkewX(SkScalarDiv(SkIntToScalar(8),
2410 SkIntToScalar(25)));
2411
2412 gm->setStarterMatrix(perspective);
skia.committer@gmail.com65caeaf2013-09-27 07:01:29 +00002413 }
scroggo@google.com7fd2d702013-04-16 19:11:14 +00002414 SkAutoTDelete<GM> adgm(gm);
reed@google.comae7b8f32012-10-18 21:30:57 +00002415 ++gmIndex;
epoger@google.com82cb65b2012-10-29 18:59:17 +00002416 if (moduloRemainder >= 0) {
2417 if ((gmIndex % moduloDivisor) != moduloRemainder) {
reed@google.comae7b8f32012-10-18 21:30:57 +00002418 continue;
2419 }
epoger@google.com82cb65b2012-10-29 18:59:17 +00002420 moduloStr.printf("[%d.%d] ", gmIndex, moduloDivisor);
reed@google.comae7b8f32012-10-18 21:30:57 +00002421 }
2422
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00002423 const char* shortName = gm->getName();
sglez@google.com586db932013-07-24 17:24:23 +00002424
commit-bot@chromium.orga6f37e72013-08-30 15:52:46 +00002425 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, shortName)) {
reed@google.comece2b022011-07-25 14:28:57 +00002426 continue;
2427 }
2428
epoger@google.com310478e2013-04-03 18:00:39 +00002429 gmsRun++;
tomhudson@google.com9875dd12011-04-25 15:49:53 +00002430 SkISize size = gm->getISize();
mtkleinafb43792014-08-19 15:55:55 -07002431 SkDebugf("%4dM %sdrawing... %s [%d %d]\n",
2432 sk_tools::getMaxResidentSetSizeMB(), moduloStr.c_str(), shortName,
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002433 size.width(), size.height());
commit-bot@chromium.orgb17ccc92014-03-13 16:16:36 +00002434 if (!FLAGS_dryRun)
mtkleinafb43792014-08-19 15:55:55 -07002435 run_multiple_configs(gmmain, gm, configs, pdfRasterizers, tileGridReplayScales,
kkinnunen80549fc2014-06-30 06:36:31 -07002436 grFactory, gpuAPI);
reed@android.com00dae862009-06-10 15:38:48 +00002437 }
epoger@google.com310478e2013-04-03 18:00:39 +00002438
commit-bot@chromium.orgb17ccc92014-03-13 16:16:36 +00002439 if (FLAGS_dryRun)
2440 return 0;
2441
epoger@google.com310478e2013-04-03 18:00:39 +00002442 SkTArray<SkString> modes;
2443 gmmain.GetRenderModesEncountered(modes);
commit-bot@chromium.org85195482014-01-13 18:27:59 +00002444 int modeCount = modes.count();
2445
2446 // Now that we have run all the tests and thus know the full set of renderModes that we
2447 // tried to run, we can call RecordTestResults() to record the cases in which we skipped
2448 // ALL renderModes.
2449 // See http://skbug.com/1994 and https://codereview.chromium.org/129203002/
2450 int testCount = gmmain.fTestsSkippedOnAllRenderModes.count();
2451 for (int testNum = 0; testNum < testCount; ++testNum) {
2452 const SkString &shortNamePlusConfig = gmmain.fTestsSkippedOnAllRenderModes[testNum];
2453 for (int modeNum = 0; modeNum < modeCount; ++modeNum) {
2454 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
2455 modes[modeNum].c_str());
2456 }
2457 }
2458
epoger@google.comc8263e72013-04-10 12:17:34 +00002459 bool reportError = false;
2460 if (gmmain.NumSignificantErrors() > 0) {
2461 reportError = true;
2462 }
commit-bot@chromium.org85195482014-01-13 18:27:59 +00002463
2464 // We test every GM against every config, and for every raster config also test every mode.
2465 int rasterConfigs = 0;
2466 for (int i = 0; i < configs.count(); i++) {
2467 if (gRec[configs[i]].fBackend == kRaster_Backend) {
2468 rasterConfigs++;
2469 }
2470 }
2471 // For raster configs, we run all renderModes; for non-raster configs, just default renderMode
2472 const int expectedNumberOfTests = rasterConfigs * gmsRun * modeCount
2473 + (configs.count() - rasterConfigs) * gmsRun;
epoger@google.com310478e2013-04-03 18:00:39 +00002474
2475 // Output summary to stdout.
epoger@google.com51dbabe2013-04-10 15:24:53 +00002476 if (FLAGS_verbose) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002477 SkDebugf("Ran %d GMs\n", gmsRun);
2478 SkDebugf("... over %2d configs [%s]\n", configs.count(),
2479 list_all_config_names(configs).c_str());
2480 SkDebugf("... and %2d modes [%s]\n", modeCount, list_all(modes).c_str());
2481 SkDebugf("... so there should be a total of %d tests.\n", expectedNumberOfTests);
epoger@google.com51dbabe2013-04-10 15:24:53 +00002482 }
2483 gmmain.ListErrors(FLAGS_verbose);
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00002484
epoger@google.com07947d92013-04-11 15:41:02 +00002485 // TODO(epoger): Enable this check for Android, too, once we resolve
2486 // https://code.google.com/p/skia/issues/detail?id=1222
2487 // ('GM is unexpectedly skipping tests on Android')
2488#ifndef SK_BUILD_FOR_ANDROID
epoger@google.comc8263e72013-04-10 12:17:34 +00002489 if (expectedNumberOfTests != gmmain.fTestsRun) {
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002490 SkDebugf("expected %d tests, but ran or skipped %d tests\n",
2491 expectedNumberOfTests, gmmain.fTestsRun);
epoger@google.comc8263e72013-04-10 12:17:34 +00002492 reportError = true;
2493 }
2494#endif
2495
scroggo@google.com09fd4d22013-03-20 14:20:18 +00002496 if (FLAGS_writeJsonSummaryPath.count() == 1) {
epoger@google.com76c913d2013-04-26 15:06:44 +00002497 Json::Value root = CreateJsonTree(
2498 gmmain.fJsonExpectedResults,
2499 gmmain.fJsonActualResults_Failed, gmmain.fJsonActualResults_FailureIgnored,
2500 gmmain.fJsonActualResults_NoComparison, gmmain.fJsonActualResults_Succeeded);
epoger@google.comee8a8e32012-12-18 19:13:49 +00002501 std::string jsonStdString = root.toStyledString();
scroggo@google.com09fd4d22013-03-20 14:20:18 +00002502 SkFILEWStream stream(FLAGS_writeJsonSummaryPath[0]);
epoger@google.comee8a8e32012-12-18 19:13:49 +00002503 stream.write(jsonStdString.c_str(), jsonStdString.length());
2504 }
2505
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00002506#if SK_SUPPORT_GPU
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00002507
robertphillips@google.com59552022012-08-31 13:07:37 +00002508#if GR_CACHE_STATS
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00002509 for (int i = 0; i < configs.count(); i++) {
2510 ConfigData config = gRec[configs[i]];
2511
epoger@google.comb0f8b432013-04-10 18:46:25 +00002512 if (FLAGS_verbose && (kGPU_Backend == config.fBackend)) {
kkinnunen80549fc2014-06-30 06:36:31 -07002513 GrContext* gr = grFactory->get(config.fGLContextType, gpuAPI);
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00002514
commit-bot@chromium.org2b3a2042014-02-27 18:45:26 +00002515 SkDebugf("config: %s %x\n", config.fName, gr);
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00002516 gr->printCacheStats();
2517 }
2518 }
2519#endif
2520
commit-bot@chromium.org8065ec52014-03-11 15:57:40 +00002521#if GR_DUMP_FONT_CACHE
2522 for (int i = 0; i < configs.count(); i++) {
2523 ConfigData config = gRec[configs[i]];
2524
2525 if (kGPU_Backend == config.fBackend) {
kkinnunen80549fc2014-06-30 06:36:31 -07002526 GrContext* gr = grFactory->get(config.fGLContextType, gpuAPI);
commit-bot@chromium.org8065ec52014-03-11 15:57:40 +00002527
2528 gr->dumpFontCache();
2529 }
2530 }
2531#endif
2532
robertphillips@google.com977b9c82012-06-05 19:35:09 +00002533 delete grFactory;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00002534#endif
robertphillips@google.com977b9c82012-06-05 19:35:09 +00002535
epoger@google.comc8263e72013-04-10 12:17:34 +00002536 return (reportError) ? -1 : 0;
reed@android.com00dae862009-06-10 15:38:48 +00002537}
caryclark@google.com5987f582012-10-02 18:33:14 +00002538
robertphillips8c508b42014-12-11 13:10:23 -08002539void GMMain::InstallFilter(SkCanvas* canvas) {
scroggo@google.com09fd4d22013-03-20 14:20:18 +00002540 if (FLAGS_forceBWtext) {
2541 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref();
2542 }
2543}
2544
borenet@google.com7158e6a2012-11-01 17:43:44 +00002545#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
caryclark@google.com5987f582012-10-02 18:33:14 +00002546int main(int argc, char * const argv[]) {
2547 return tool_main(argc, (char**) argv);
2548}
2549#endif