blob: e7f23655da88be898b2aeab8c64c0b4543180e85 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
bsalomon@google.com971d0c82011-08-19 17:22:05 +00007
epoger@google.com57f7abc2012-11-13 03:41:55 +00008/*
9 * Code for the "gm" (Golden Master) rendering comparison tool.
10 *
11 * If you make changes to this, re-run the self-tests at gm/tests/run.sh
12 * to make sure they still pass... you may need to change the expected
13 * results of the self-test.
14 */
15
bungeman@google.comb29c8832011-10-10 13:19:10 +000016#include "gm.h"
epoger@google.com6f6568b2013-03-22 17:29:46 +000017#include "gm_error.h"
epoger@google.com37269602013-01-19 04:21:27 +000018#include "gm_expectations.h"
epoger@google.com7bc13a62012-02-14 14:53:59 +000019#include "system_preferences.h"
epoger@google.com5f6a0072013-01-31 16:30:55 +000020#include "SkBitmap.h"
reed@android.comb9b9a182009-07-08 02:54:47 +000021#include "SkColorPriv.h"
scroggo@google.comd9ba9a02013-03-21 19:43:15 +000022#include "SkCommandLineFlags.h"
reed@google.com8a85d0c2011-06-24 19:12:12 +000023#include "SkData.h"
junov@google.com4370aed2012-01-18 16:21:08 +000024#include "SkDeferredCanvas.h"
bsalomon@google.com971d0c82011-08-19 17:22:05 +000025#include "SkDevice.h"
commit-bot@chromium.org5e009892013-10-14 13:42:12 +000026#include "SkDocument.h"
epoger@google.comde961632012-10-26 18:56:36 +000027#include "SkDrawFilter.h"
commit-bot@chromium.orgc41295d2013-06-18 20:06:36 +000028#include "SkForceLinking.h"
scroggo@google.com5af9b202012-06-04 17:17:36 +000029#include "SkGPipe.h"
reed@android.com8015dd82009-06-21 00:49:18 +000030#include "SkGraphics.h"
31#include "SkImageDecoder.h"
32#include "SkImageEncoder.h"
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +000033#include "SkJSONCPP.h"
epoger@google.come8ebeb12012-10-29 16:42:11 +000034#include "SkOSFile.h"
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +000035#include "SkPDFRasterizer.h"
tomhudson@google.com9875dd12011-04-25 15:49:53 +000036#include "SkPicture.h"
robertphillips@google.com977b9c82012-06-05 19:35:09 +000037#include "SkRefCnt.h"
commit-bot@chromium.org5e009892013-10-14 13:42:12 +000038#include "SkScalar.h"
scroggo@google.com72c96722012-06-06 21:07:10 +000039#include "SkStream.h"
epoger@google.comf711f322013-10-18 14:55:47 +000040#include "SkString.h"
bsalomon@google.com2a48c3a2012-08-03 14:54:45 +000041#include "SkTArray.h"
epoger@google.com310478e2013-04-03 18:00:39 +000042#include "SkTDict.h"
junov@chromium.org3cb834b2012-12-13 16:39:53 +000043#include "SkTileGridPicture.h"
scroggo@google.com72c96722012-06-06 21:07:10 +000044#include "SamplePipeControllers.h"
reed@google.com07700442010-12-20 19:46:07 +000045
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000046#ifdef SK_DEBUG
47static const bool kDebugOnly = true;
48#else
49static const bool kDebugOnly = false;
50#endif
51
epoger@google.comed5eb4e2013-07-23 17:56:20 +000052__SK_FORCE_IMAGE_DECODER_LINKING;
53
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000054#if SK_SUPPORT_GPU
55#include "GrContextFactory.h"
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000056#include "SkGpuDevice.h"
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000057typedef GrContextFactory::GLContextType GLContextType;
epoger@google.com6f6568b2013-03-22 17:29:46 +000058#define DEFAULT_CACHE_VALUE -1
59static int gGpuCacheSizeBytes;
60static int gGpuCacheSizeCount;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000061#else
epoger@google.com80724df2013-03-21 13:49:54 +000062class GrContextFactory;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000063class GrContext;
bsalomon@google.com123ac1d2013-03-28 19:18:12 +000064class GrSurface;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000065typedef int GLContextType;
66#endif
67
epoger@google.com76c913d2013-04-26 15:06:44 +000068#define DEBUGFAIL_SEE_STDERR SkDEBUGFAIL("see stderr for message")
69
reed@google.com8923c6c2011-11-08 14:59:38 +000070extern bool gSkSuppressFontCachePurgeSpew;
commit-bot@chromium.org5e009892013-10-14 13:42:12 +000071DECLARE_bool(useDocumentInsteadOfDevice);
reed@google.com8923c6c2011-11-08 14:59:38 +000072
reed@google.com07700442010-12-20 19:46:07 +000073#ifdef SK_SUPPORT_PDF
tomhudson@google.com9875dd12011-04-25 15:49:53 +000074 #include "SkPDFDevice.h"
75 #include "SkPDFDocument.h"
reed@google.com07700442010-12-20 19:46:07 +000076#endif
reed@android.com00dae862009-06-10 15:38:48 +000077
epoger@google.come3cc2eb2012-01-18 20:11:13 +000078// Until we resolve http://code.google.com/p/skia/issues/detail?id=455 ,
79// stop writing out XPS-format image baselines in gm.
80#undef SK_SUPPORT_XPS
bungeman@google.comb29c8832011-10-10 13:19:10 +000081#ifdef SK_SUPPORT_XPS
82 #include "SkXPSDevice.h"
83#endif
84
reed@google.com46cce912011-06-29 12:54:46 +000085#ifdef SK_BUILD_FOR_MAC
86 #include "SkCGUtils.h"
reed@google.com46cce912011-06-29 12:54:46 +000087#endif
88
reed@android.com00dae862009-06-10 15:38:48 +000089using namespace skiagm;
90
reed@android.com00dae862009-06-10 15:38:48 +000091class Iter {
92public:
93 Iter() {
bsalomon@google.com39149582011-06-13 21:55:32 +000094 this->reset();
95 }
96
97 void reset() {
reed@android.comdd0ac282009-06-20 02:38:16 +000098 fReg = GMRegistry::Head();
reed@android.com00dae862009-06-10 15:38:48 +000099 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000100
reed@android.comdd0ac282009-06-20 02:38:16 +0000101 GM* next() {
reed@android.com00dae862009-06-10 15:38:48 +0000102 if (fReg) {
reed@android.comdd0ac282009-06-20 02:38:16 +0000103 GMRegistry::Factory fact = fReg->factory();
reed@android.com00dae862009-06-10 15:38:48 +0000104 fReg = fReg->next();
reed@android.comdd0ac282009-06-20 02:38:16 +0000105 return fact(0);
reed@android.com00dae862009-06-10 15:38:48 +0000106 }
107 return NULL;
108 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000109
reed@android.com00dae862009-06-10 15:38:48 +0000110 static int Count() {
reed@android.comdd0ac282009-06-20 02:38:16 +0000111 const GMRegistry* reg = GMRegistry::Head();
reed@android.com00dae862009-06-10 15:38:48 +0000112 int count = 0;
113 while (reg) {
114 count += 1;
115 reg = reg->next();
116 }
117 return count;
118 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000119
reed@android.com00dae862009-06-10 15:38:48 +0000120private:
121 const GMRegistry* fReg;
122};
123
epoger@google.comce057fe2013-05-14 15:17:46 +0000124// TODO(epoger): Right now, various places in this code assume that all the
125// image files read/written by GM use this file extension.
126// Search for references to this constant to find these assumptions.
127const static char kPNG_FileExtension[] = "png";
128
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000129enum Backend {
junov@chromium.org3cb834b2012-12-13 16:39:53 +0000130 kRaster_Backend,
131 kGPU_Backend,
132 kPDF_Backend,
133 kXPS_Backend,
134};
135
136enum BbhType {
137 kNone_BbhType,
138 kRTree_BbhType,
139 kTileGrid_BbhType,
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000140};
141
bsalomon@google.com7361f542012-04-19 19:15:35 +0000142enum ConfigFlags {
143 kNone_ConfigFlag = 0x0,
144 /* Write GM images if a write path is provided. */
145 kWrite_ConfigFlag = 0x1,
epoger@google.comf28dd8a2012-10-25 16:27:34 +0000146 /* Read reference GM images if a read path is provided. */
bsalomon@google.com7361f542012-04-19 19:15:35 +0000147 kRead_ConfigFlag = 0x2,
148 kRW_ConfigFlag = (kWrite_ConfigFlag | kRead_ConfigFlag),
149};
150
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000151struct ConfigData {
bsalomon@google.com7361f542012-04-19 19:15:35 +0000152 SkBitmap::Config fConfig;
153 Backend fBackend;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000154 GLContextType fGLContextType; // GPU backend only
bsalomon@google.com7361f542012-04-19 19:15:35 +0000155 int fSampleCnt; // GPU backend only
156 ConfigFlags fFlags;
157 const char* fName;
bsalomon@google.com4c75f242013-03-19 18:58:43 +0000158 bool fRunByDefault;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000159};
160
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000161struct PDFRasterizerData {
162 bool (*fRasterizerFunction)(SkStream*, SkBitmap*);
163 const char* fName;
164 bool fRunByDefault;
165};
166
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000167class BWTextDrawFilter : public SkDrawFilter {
168public:
reed@google.com971aca72012-11-26 20:26:54 +0000169 virtual bool filter(SkPaint*, Type) SK_OVERRIDE;
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000170};
reed@google.com971aca72012-11-26 20:26:54 +0000171bool BWTextDrawFilter::filter(SkPaint* p, Type t) {
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000172 if (kText_Type == t) {
173 p->setAntiAlias(false);
174 }
reed@google.com971aca72012-11-26 20:26:54 +0000175 return true;
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000176}
177
scroggo@google.com565254b2012-06-28 15:41:32 +0000178struct PipeFlagComboData {
179 const char* name;
180 uint32_t flags;
181};
182
183static PipeFlagComboData gPipeWritingFlagCombos[] = {
184 { "", 0 },
185 { " cross-process", SkGPipeWriter::kCrossProcess_Flag },
scroggob3c0f482012-07-02 19:07:57 +0000186 { " cross-process, shared address", SkGPipeWriter::kCrossProcess_Flag
scroggo@google.com15011ee2012-07-26 20:03:32 +0000187 | SkGPipeWriter::kSharedAddressSpace_Flag }
scroggo@google.com565254b2012-06-28 15:41:32 +0000188};
189
commit-bot@chromium.org608ea652013-10-03 19:29:21 +0000190static SkData* encode_to_dct_data(size_t* pixelRefOffset, const SkBitmap& bitmap);
edisonn@google.com73a7ea32013-11-11 20:55:15 +0000191DECLARE_int32(pdfRasterDpi);
edisonn@google.comd9dfa182013-04-24 13:01:01 +0000192
epoger@google.com5079d2c2013-04-12 14:11:21 +0000193const static ErrorCombination kDefaultIgnorableErrorTypes = ErrorCombination()
194 .plus(kMissingExpectations_ErrorType)
195 .plus(kIntentionallySkipped_ErrorType);
196
epoger@google.comde961632012-10-26 18:56:36 +0000197class GMMain {
198public:
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000199 GMMain() : fUseFileHierarchy(false), fWriteChecksumBasedFilenames(false),
200 fIgnorableErrorTypes(kDefaultIgnorableErrorTypes),
epoger@google.com5f995452013-06-21 18:16:47 +0000201 fMismatchPath(NULL), fMissingExpectationsPath(NULL), fTestsRun(0),
202 fRenderModesEncountered(1) {}
epoger@google.come8ebeb12012-10-29 16:42:11 +0000203
epoger@google.com659c8c02013-05-21 15:45:45 +0000204 /**
205 * Assemble shortNamePlusConfig from (surprise!) shortName and configName.
206 *
207 * The method for doing so depends on whether we are using hierarchical naming.
208 * For example, shortName "selftest1" and configName "8888" could be assembled into
209 * either "selftest1_8888" or "8888/selftest1".
210 */
211 SkString make_shortname_plus_config(const char *shortName, const char *configName) {
epoger@google.come8ebeb12012-10-29 16:42:11 +0000212 SkString name;
epoger@google.com57f7abc2012-11-13 03:41:55 +0000213 if (0 == strlen(configName)) {
214 name.append(shortName);
215 } else if (fUseFileHierarchy) {
epoger@google.come8ebeb12012-10-29 16:42:11 +0000216 name.appendf("%s%c%s", configName, SkPATH_SEPARATOR, shortName);
217 } else {
218 name.appendf("%s_%s", shortName, configName);
219 }
epoger@google.comde961632012-10-26 18:56:36 +0000220 return name;
221 }
222
epoger@google.com659c8c02013-05-21 15:45:45 +0000223 /**
224 * Assemble filename, suitable for writing out the results of a particular test.
225 */
226 SkString make_filename(const char *path,
227 const char *shortName,
228 const char *configName,
229 const char *renderModeDescriptor,
230 const char *suffix) {
231 SkString filename = make_shortname_plus_config(shortName, configName);
232 filename.append(renderModeDescriptor);
233 filename.appendUnichar('.');
234 filename.append(suffix);
scroggo@google.comccd7afb2013-05-28 16:45:07 +0000235 return SkOSPath::SkPathJoin(path, filename.c_str());
epoger@google.com659c8c02013-05-21 15:45:45 +0000236 }
237
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000238 /**
239 * Assemble filename suitable for writing out an SkBitmap.
240 */
241 SkString make_bitmap_filename(const char *path,
242 const char *shortName,
243 const char *configName,
244 const char *renderModeDescriptor,
245 const GmResultDigest &bitmapDigest) {
246 if (fWriteChecksumBasedFilenames) {
247 SkString filename;
248 filename.append(bitmapDigest.getHashType());
249 filename.appendUnichar('_');
250 filename.append(shortName);
251 filename.appendUnichar('_');
252 filename.append(bitmapDigest.getDigestValue());
253 filename.appendUnichar('.');
254 filename.append(kPNG_FileExtension);
255 return SkOSPath::SkPathJoin(path, filename.c_str());
256 } else {
257 return make_filename(path, shortName, configName, renderModeDescriptor,
258 kPNG_FileExtension);
259 }
260 }
261
epoger@google.com5f6a0072013-01-31 16:30:55 +0000262 /* since PNG insists on unpremultiplying our alpha, we take no
263 precision chances and force all pixels to be 100% opaque,
264 otherwise on compare we may not get a perfect match.
265 */
266 static void force_all_opaque(const SkBitmap& bitmap) {
267 SkBitmap::Config config = bitmap.config();
268 switch (config) {
269 case SkBitmap::kARGB_8888_Config:
270 force_all_opaque_8888(bitmap);
271 break;
272 case SkBitmap::kRGB_565_Config:
273 // nothing to do here; 565 bitmaps are inherently opaque
274 break;
275 default:
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000276 gm_fprintf(stderr, "unsupported bitmap config %d\n", config);
277 DEBUGFAIL_SEE_STDERR;
epoger@google.com5f6a0072013-01-31 16:30:55 +0000278 }
279 }
280
281 static void force_all_opaque_8888(const SkBitmap& bitmap) {
282 SkAutoLockPixels lock(bitmap);
283 for (int y = 0; y < bitmap.height(); y++) {
284 for (int x = 0; x < bitmap.width(); x++) {
285 *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT);
286 }
287 }
288 }
289
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000290 static ErrorCombination write_bitmap(const SkString& path, const SkBitmap& bitmap) {
epoger@google.com5f6a0072013-01-31 16:30:55 +0000291 // TODO(epoger): Now that we have removed force_all_opaque()
292 // from this method, we should be able to get rid of the
293 // transformation to 8888 format also.
294 SkBitmap copy;
295 bitmap.copyTo(&copy, SkBitmap::kARGB_8888_Config);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000296 if (!SkImageEncoder::EncodeFile(path.c_str(), copy,
297 SkImageEncoder::kPNG_Type,
298 100)) {
299 gm_fprintf(stderr, "FAILED to write bitmap: %s\n", path.c_str());
300 return ErrorCombination(kWritingReferenceImage_ErrorType);
301 }
302 return kEmpty_ErrorCombination;
epoger@google.com5f6a0072013-01-31 16:30:55 +0000303 }
304
epoger@google.com6f6568b2013-03-22 17:29:46 +0000305 /**
epoger@google.com310478e2013-04-03 18:00:39 +0000306 * Add all render modes encountered thus far to the "modes" array.
epoger@google.com6f6568b2013-03-22 17:29:46 +0000307 */
epoger@google.com310478e2013-04-03 18:00:39 +0000308 void GetRenderModesEncountered(SkTArray<SkString> &modes) {
309 SkTDict<int>::Iter iter(this->fRenderModesEncountered);
310 const char* mode;
311 while ((mode = iter.next(NULL)) != NULL) {
312 SkString modeAsString = SkString(mode);
313 // TODO(epoger): It seems a bit silly that all of these modes were
314 // recorded with a leading "-" which we have to remove here
315 // (except for mode "", which means plain old original mode).
316 // But that's how renderModeDescriptor has been passed into
317 // compare_test_results_to_reference_bitmap() historically,
318 // and changing that now may affect other parts of our code.
319 if (modeAsString.startsWith("-")) {
320 modeAsString.remove(0, 1);
epoger@google.com310478e2013-04-03 18:00:39 +0000321 }
commit-bot@chromium.org85195482014-01-13 18:27:59 +0000322 modes.push_back(modeAsString);
epoger@google.com310478e2013-04-03 18:00:39 +0000323 }
324 }
325
326 /**
epoger@google.com3a882dd2013-10-07 18:55:09 +0000327 * Returns true if failures on this test should be ignored.
328 */
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +0000329 bool ShouldIgnoreTest(const char *name) const {
330 for (int i = 0; i < fIgnorableTestNames.count(); i++) {
331 if (fIgnorableTestNames[i].equals(name)) {
epoger@google.com3a882dd2013-10-07 18:55:09 +0000332 return true;
333 }
334 }
335 return false;
336 }
337
338 /**
commit-bot@chromium.org85195482014-01-13 18:27:59 +0000339 * Calls RecordTestResults to record that we skipped a test.
340 *
341 * Depending on the backend, this may mean that we skipped a single rendermode, or all
342 * rendermodes; see http://skbug.com/1994 and https://codereview.chromium.org/129203002/
343 */
344 void RecordSkippedTest(const SkString& shortNamePlusConfig,
345 const char renderModeDescriptor [], Backend backend) {
346 if (kRaster_Backend == backend) {
347 // Skipping a test on kRaster_Backend means that we will skip ALL renderModes
348 // (as opposed to other backends, on which we only run the default renderMode).
349 //
350 // We cannot call RecordTestResults yet, because we won't know the full set of
351 // renderModes until we have run all tests.
352 fTestsSkippedOnAllRenderModes.push_back(shortNamePlusConfig);
353 } else {
354 this->RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
355 renderModeDescriptor);
356 }
357 }
358
359 /**
epoger@google.com310478e2013-04-03 18:00:39 +0000360 * Records the results of this test in fTestsRun and fFailedTests.
361 *
362 * We even record successes, and errors that we regard as
363 * "ignorable"; we can filter them out later.
364 */
epoger@google.com659c8c02013-05-21 15:45:45 +0000365 void RecordTestResults(const ErrorCombination& errorCombination,
366 const SkString& shortNamePlusConfig,
epoger@google.com310478e2013-04-03 18:00:39 +0000367 const char renderModeDescriptor []) {
368 // Things to do regardless of errorCombination.
369 fTestsRun++;
370 int renderModeCount = 0;
371 this->fRenderModesEncountered.find(renderModeDescriptor, &renderModeCount);
372 renderModeCount++;
373 this->fRenderModesEncountered.set(renderModeDescriptor, renderModeCount);
374
epoger@google.com6f6568b2013-03-22 17:29:46 +0000375 if (errorCombination.isEmpty()) {
epoger@google.com5f6a0072013-01-31 16:30:55 +0000376 return;
epoger@google.comeb066362013-03-08 09:39:36 +0000377 }
378
epoger@google.com310478e2013-04-03 18:00:39 +0000379 // Things to do only if there is some error condition.
epoger@google.com659c8c02013-05-21 15:45:45 +0000380 SkString fullName = shortNamePlusConfig;
epoger@google.comcaac3db2013-04-04 19:23:11 +0000381 fullName.append(renderModeDescriptor);
epoger@google.com310478e2013-04-03 18:00:39 +0000382 for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) {
383 ErrorType type = static_cast<ErrorType>(typeInt);
384 if (errorCombination.includes(type)) {
385 fFailedTests[type].push_back(fullName);
epoger@google.comf60494b2013-04-03 17:02:53 +0000386 }
epoger@google.comf60494b2013-04-03 17:02:53 +0000387 }
epoger@google.comf60494b2013-04-03 17:02:53 +0000388 }
389
epoger@google.com310478e2013-04-03 18:00:39 +0000390 /**
391 * Return the number of significant (non-ignorable) errors we have
392 * encountered so far.
393 */
394 int NumSignificantErrors() {
395 int significantErrors = 0;
396 for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) {
397 ErrorType type = static_cast<ErrorType>(typeInt);
epoger@google.com5079d2c2013-04-12 14:11:21 +0000398 if (!fIgnorableErrorTypes.includes(type)) {
epoger@google.com310478e2013-04-03 18:00:39 +0000399 significantErrors += fFailedTests[type].count();
400 }
401 }
402 return significantErrors;
403 }
404
405 /**
epoger@google.com51dbabe2013-04-10 15:24:53 +0000406 * Display the summary of results with this ErrorType.
407 *
408 * @param type which ErrorType
409 * @param verbose whether to be all verbose about it
epoger@google.com310478e2013-04-03 18:00:39 +0000410 */
epoger@google.com51dbabe2013-04-10 15:24:53 +0000411 void DisplayResultTypeSummary(ErrorType type, bool verbose) {
epoger@google.com5079d2c2013-04-12 14:11:21 +0000412 bool isIgnorableType = fIgnorableErrorTypes.includes(type);
epoger@google.com51dbabe2013-04-10 15:24:53 +0000413
414 SkString line;
415 if (isIgnorableType) {
416 line.append("[ ] ");
417 } else {
418 line.append("[*] ");
419 }
420
421 SkTArray<SkString> *failedTestsOfThisType = &fFailedTests[type];
422 int count = failedTestsOfThisType->count();
423 line.appendf("%d %s", count, getErrorTypeName(type));
424 if (!isIgnorableType || verbose) {
425 line.append(":");
426 for (int i = 0; i < count; ++i) {
427 line.append(" ");
428 line.append((*failedTestsOfThisType)[i]);
429 }
430 }
431 gm_fprintf(stdout, "%s\n", line.c_str());
432 }
433
434 /**
435 * List contents of fFailedTests to stdout.
436 *
437 * @param verbose whether to be all verbose about it
438 */
439 void ListErrors(bool verbose) {
epoger@google.com310478e2013-04-03 18:00:39 +0000440 // First, print a single summary line.
441 SkString summary;
442 summary.appendf("Ran %d tests:", fTestsRun);
443 for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) {
444 ErrorType type = static_cast<ErrorType>(typeInt);
445 summary.appendf(" %s=%d", getErrorTypeName(type), fFailedTests[type].count());
446 }
447 gm_fprintf(stdout, "%s\n", summary.c_str());
448
449 // Now, for each failure type, list the tests that failed that way.
450 for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) {
epoger@google.com51dbabe2013-04-10 15:24:53 +0000451 this->DisplayResultTypeSummary(static_cast<ErrorType>(typeInt), verbose);
epoger@google.com310478e2013-04-03 18:00:39 +0000452 }
453 gm_fprintf(stdout, "(results marked with [*] will cause nonzero return value)\n");
454 }
455
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000456 static ErrorCombination write_document(const SkString& path, SkStreamAsset* asset) {
epoger@google.com5f6a0072013-01-31 16:30:55 +0000457 SkFILEWStream stream(path.c_str());
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000458 if (!stream.writeStream(asset, asset->getLength())) {
459 gm_fprintf(stderr, "FAILED to write document: %s\n", path.c_str());
460 return ErrorCombination(kWritingReferenceImage_ErrorType);
461 }
462 return kEmpty_ErrorCombination;
epoger@google.com5f6a0072013-01-31 16:30:55 +0000463 }
464
epoger@google.com37269602013-01-19 04:21:27 +0000465 /**
epoger@google.com5f6a0072013-01-31 16:30:55 +0000466 * Prepare an SkBitmap to render a GM into.
467 *
468 * After you've rendered the GM into the SkBitmap, you must call
469 * complete_bitmap()!
470 *
471 * @todo thudson 22 April 2011 - could refactor this to take in
472 * a factory to generate the context, always call readPixels()
473 * (logically a noop for rasters, if wasted time), and thus collapse the
474 * GPU special case and also let this be used for SkPicture testing.
475 */
476 static void setup_bitmap(const ConfigData& gRec, SkISize& size,
477 SkBitmap* bitmap) {
reed@google.comeb9a46c2014-01-25 16:46:20 +0000478 bitmap->allocConfigPixels(gRec.fConfig, size.width(), size.height());
epoger@google.com5f6a0072013-01-31 16:30:55 +0000479 bitmap->eraseColor(SK_ColorTRANSPARENT);
480 }
481
482 /**
483 * Any finalization steps we need to perform on the SkBitmap after
484 * we have rendered the GM into it.
epoger@google.com37269602013-01-19 04:21:27 +0000485 *
486 * It's too bad that we are throwing away alpha channel data
487 * we could otherwise be examining, but this had always been happening
488 * before... it was buried within the compare() method at
489 * https://code.google.com/p/skia/source/browse/trunk/gm/gmmain.cpp?r=7289#305 .
490 *
491 * Apparently we need this, at least for bitmaps that are either:
492 * (a) destined to be written out as PNG files, or
493 * (b) compared against bitmaps read in from PNG files
494 * for the reasons described just above the force_all_opaque() method.
495 *
496 * Neglecting to do this led to the difficult-to-diagnose
497 * http://code.google.com/p/skia/issues/detail?id=1079 ('gm generating
498 * spurious pixel_error messages as of r7258')
499 *
500 * TODO(epoger): Come up with a better solution that allows us to
501 * compare full pixel data, including alpha channel, while still being
502 * robust in the face of transformations to/from PNG files.
503 * Options include:
504 *
505 * 1. Continue to call force_all_opaque(), but ONLY for bitmaps that
506 * will be written to, or compared against, PNG files.
507 * PRO: Preserve/compare alpha channel info for the non-PNG cases
508 * (comparing different renderModes in-memory)
epoger@google.com908f5832013-04-12 02:23:55 +0000509 * CON: The bitmaps (and hash digests) for these non-PNG cases would be
epoger@google.com37269602013-01-19 04:21:27 +0000510 * different than those for the PNG-compared cases, and in the
511 * case of a failed renderMode comparison, how would we write the
512 * image to disk for examination?
513 *
epoger@google.com908f5832013-04-12 02:23:55 +0000514 * 2. Always compute image hash digests from PNG format (either
epoger@google.com37269602013-01-19 04:21:27 +0000515 * directly from the the bytes of a PNG file, or capturing the
516 * bytes we would have written to disk if we were writing the
517 * bitmap out as a PNG).
518 * PRO: I think this would allow us to never force opaque, and to
519 * the extent that alpha channel data can be preserved in a PNG
520 * file, we could observe it.
epoger@google.com908f5832013-04-12 02:23:55 +0000521 * CON: If we read a bitmap from disk, we need to take its hash digest
epoger@google.com37269602013-01-19 04:21:27 +0000522 * from the source PNG (we can't compute it from the bitmap we
523 * read out of the PNG, because we will have already premultiplied
524 * the alpha).
525 * CON: Seems wasteful to convert a bitmap to PNG format just to take
epoger@google.com908f5832013-04-12 02:23:55 +0000526 * its hash digest. (Although we're wasting lots of effort already
epoger@google.com37269602013-01-19 04:21:27 +0000527 * calling force_all_opaque().)
528 *
529 * 3. Make the alpha premultiply/unpremultiply routines 100% consistent,
530 * so we can transform images back and forth without fear of off-by-one
531 * errors.
532 * CON: Math is hard.
533 *
534 * 4. Perform a "close enough" comparison of bitmaps (+/- 1 bit in each
535 * channel), rather than demanding absolute equality.
epoger@google.com908f5832013-04-12 02:23:55 +0000536 * CON: Can't do this with hash digests.
epoger@google.com37269602013-01-19 04:21:27 +0000537 */
epoger@google.com5f6a0072013-01-31 16:30:55 +0000538 static void complete_bitmap(SkBitmap* bitmap) {
539 force_all_opaque(*bitmap);
epoger@google.comde961632012-10-26 18:56:36 +0000540 }
541
scroggo@google.com09fd4d22013-03-20 14:20:18 +0000542 static void installFilter(SkCanvas* canvas);
epoger@google.comde961632012-10-26 18:56:36 +0000543
reed@google.comaef73612012-11-16 13:41:45 +0000544 static void invokeGM(GM* gm, SkCanvas* canvas, bool isPDF, bool isDeferred) {
epoger@google.comde961632012-10-26 18:56:36 +0000545 SkAutoCanvasRestore acr(canvas, true);
546
547 if (!isPDF) {
548 canvas->concat(gm->getInitialTransform());
549 }
550 installFilter(canvas);
reed@google.comaef73612012-11-16 13:41:45 +0000551 gm->setCanvasIsDeferred(isDeferred);
epoger@google.comde961632012-10-26 18:56:36 +0000552 gm->draw(canvas);
553 canvas->setDrawFilter(NULL);
554 }
555
epoger@google.com6f6568b2013-03-22 17:29:46 +0000556 static ErrorCombination generate_image(GM* gm, const ConfigData& gRec,
bsalomon@google.com123ac1d2013-03-28 19:18:12 +0000557 GrSurface* gpuTarget,
epoger@google.com6f6568b2013-03-22 17:29:46 +0000558 SkBitmap* bitmap,
559 bool deferred) {
epoger@google.comde961632012-10-26 18:56:36 +0000560 SkISize size (gm->getISize());
561 setup_bitmap(gRec, size, bitmap);
562
563 SkAutoTUnref<SkCanvas> canvas;
564
565 if (gRec.fBackend == kRaster_Backend) {
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000566 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (*bitmap)));
epoger@google.comde961632012-10-26 18:56:36 +0000567 if (deferred) {
junov@chromium.org66070a52013-05-28 17:39:08 +0000568 canvas.reset(SkDeferredCanvas::Create(device));
epoger@google.comde961632012-10-26 18:56:36 +0000569 } else {
junov@chromium.org66070a52013-05-28 17:39:08 +0000570 canvas.reset(SkNEW_ARGS(SkCanvas, (device)));
epoger@google.comde961632012-10-26 18:56:36 +0000571 }
reed@google.comaef73612012-11-16 13:41:45 +0000572 invokeGM(gm, canvas, false, deferred);
epoger@google.comde961632012-10-26 18:56:36 +0000573 canvas->flush();
574 }
575#if SK_SUPPORT_GPU
576 else { // GPU
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000577 SkAutoTUnref<SkBaseDevice> device(SkGpuDevice::Create(gpuTarget));
epoger@google.comde961632012-10-26 18:56:36 +0000578 if (deferred) {
junov@chromium.org66070a52013-05-28 17:39:08 +0000579 canvas.reset(SkDeferredCanvas::Create(device));
epoger@google.comde961632012-10-26 18:56:36 +0000580 } else {
junov@chromium.org66070a52013-05-28 17:39:08 +0000581 canvas.reset(SkNEW_ARGS(SkCanvas, (device)));
epoger@google.comde961632012-10-26 18:56:36 +0000582 }
reed@google.comaef73612012-11-16 13:41:45 +0000583 invokeGM(gm, canvas, false, deferred);
epoger@google.comde961632012-10-26 18:56:36 +0000584 // the device is as large as the current rendertarget, so
585 // we explicitly only readback the amount we expect (in
586 // size) overwrite our previous allocation
587 bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth,
588 size.fHeight);
589 canvas->readPixels(bitmap, 0, 0);
590 }
591#endif
epoger@google.com5f6a0072013-01-31 16:30:55 +0000592 complete_bitmap(bitmap);
epoger@google.com6f6568b2013-03-22 17:29:46 +0000593 return kEmpty_ErrorCombination;
epoger@google.comde961632012-10-26 18:56:36 +0000594 }
595
596 static void generate_image_from_picture(GM* gm, const ConfigData& gRec,
junov@chromium.orgc938c482012-12-19 15:24:38 +0000597 SkPicture* pict, SkBitmap* bitmap,
robertphillips@google.com5a7d0292013-04-02 15:18:41 +0000598 SkScalar scale = SK_Scalar1,
599 bool tile = false) {
epoger@google.comde961632012-10-26 18:56:36 +0000600 SkISize size = gm->getISize();
601 setup_bitmap(gRec, size, bitmap);
robertphillips@google.com5a7d0292013-04-02 15:18:41 +0000602
603 if (tile) {
604 // Generate the result image by rendering to tiles and accumulating
605 // the results in 'bitmap'
606
skia.committer@gmail.com041e2db2013-04-03 07:01:14 +0000607 // This 16x16 tiling matches the settings applied to 'pict' in
robertphillips@google.com5a7d0292013-04-02 15:18:41 +0000608 // 'generate_new_picture'
609 SkISize tileSize = SkISize::Make(16, 16);
610
611 SkBitmap tileBM;
612 setup_bitmap(gRec, tileSize, &tileBM);
613 SkCanvas tileCanvas(tileBM);
614 installFilter(&tileCanvas);
615
616 SkCanvas bmpCanvas(*bitmap);
617 SkPaint bmpPaint;
618 bmpPaint.setXfermodeMode(SkXfermode::kSrc_Mode);
619
620 for (int yTile = 0; yTile < (size.height()+15)/16; ++yTile) {
621 for (int xTile = 0; xTile < (size.width()+15)/16; ++xTile) {
622 int saveCount = tileCanvas.save();
623 SkMatrix mat(tileCanvas.getTotalMatrix());
skia.committer@gmail.com041e2db2013-04-03 07:01:14 +0000624 mat.postTranslate(SkIntToScalar(-xTile*tileSize.width()),
robertphillips@google.com5a7d0292013-04-02 15:18:41 +0000625 SkIntToScalar(-yTile*tileSize.height()));
626 tileCanvas.setMatrix(mat);
627 pict->draw(&tileCanvas);
628 tileCanvas.flush();
629 tileCanvas.restoreToCount(saveCount);
skia.committer@gmail.com041e2db2013-04-03 07:01:14 +0000630 bmpCanvas.drawBitmap(tileBM,
631 SkIntToScalar(xTile * tileSize.width()),
robertphillips@google.com5a7d0292013-04-02 15:18:41 +0000632 SkIntToScalar(yTile * tileSize.height()),
633 &bmpPaint);
634 }
635 }
636 } else {
637 SkCanvas canvas(*bitmap);
638 installFilter(&canvas);
639 canvas.scale(scale, scale);
640 canvas.drawPicture(*pict);
641 complete_bitmap(bitmap);
642 }
epoger@google.comde961632012-10-26 18:56:36 +0000643 }
644
commit-bot@chromium.org5e009892013-10-14 13:42:12 +0000645 static bool generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) {
epoger@google.comde961632012-10-26 18:56:36 +0000646#ifdef SK_SUPPORT_PDF
647 SkMatrix initialTransform = gm->getInitialTransform();
commit-bot@chromium.org5e009892013-10-14 13:42:12 +0000648 if (FLAGS_useDocumentInsteadOfDevice) {
649 SkISize pageISize = gm->getISize();
edisonn@google.com73a7ea32013-11-11 20:55:15 +0000650 SkAutoTUnref<SkDocument> pdfDoc(
651 SkDocument::CreatePDF(&pdf, NULL,
652 encode_to_dct_data,
653 SkIntToScalar(FLAGS_pdfRasterDpi)));
commit-bot@chromium.org5e009892013-10-14 13:42:12 +0000654
655 if (!pdfDoc.get()) {
656 return false;
657 }
658
659 SkCanvas* canvas = NULL;
660 canvas = pdfDoc->beginPage(SkIntToScalar(pageISize.width()),
661 SkIntToScalar(pageISize.height()));
662 canvas->concat(initialTransform);
663
664 invokeGM(gm, canvas, true, false);
665
666 return pdfDoc->close();
epoger@google.comde961632012-10-26 18:56:36 +0000667 } else {
commit-bot@chromium.org5e009892013-10-14 13:42:12 +0000668 SkISize pageSize = gm->getISize();
669 SkPDFDevice* dev = NULL;
670 if (initialTransform.isIdentity()) {
671 dev = new SkPDFDevice(pageSize, pageSize, initialTransform);
672 } else {
673 SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()),
674 SkIntToScalar(pageSize.height()));
675 initialTransform.mapRect(&content);
676 content.intersect(0, 0, SkIntToScalar(pageSize.width()),
677 SkIntToScalar(pageSize.height()));
678 SkISize contentSize =
679 SkISize::Make(SkScalarRoundToInt(content.width()),
680 SkScalarRoundToInt(content.height()));
681 dev = new SkPDFDevice(pageSize, contentSize, initialTransform);
682 }
683 dev->setDCTEncoder(encode_to_dct_data);
edisonn@google.com73a7ea32013-11-11 20:55:15 +0000684 dev->setRasterDpi(SkIntToScalar(FLAGS_pdfRasterDpi));
commit-bot@chromium.org5e009892013-10-14 13:42:12 +0000685 SkAutoUnref aur(dev);
686 SkCanvas c(dev);
687 invokeGM(gm, &c, true, false);
688 SkPDFDocument doc;
689 doc.appendPage(dev);
690 doc.emitPDF(&pdf);
epoger@google.comde961632012-10-26 18:56:36 +0000691 }
commit-bot@chromium.org5e009892013-10-14 13:42:12 +0000692#endif // SK_SUPPORT_PDF
693 return true; // Do not report failure if pdf is not supported.
epoger@google.comde961632012-10-26 18:56:36 +0000694 }
695
696 static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) {
697#ifdef SK_SUPPORT_XPS
698 SkISize size = gm->getISize();
699
700 SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()),
701 SkIntToScalar(size.height()));
702 static const SkScalar inchesPerMeter = SkScalarDiv(10000, 254);
703 static const SkScalar upm = 72 * inchesPerMeter;
704 SkVector unitsPerMeter = SkPoint::Make(upm, upm);
705 static const SkScalar ppm = 200 * inchesPerMeter;
706 SkVector pixelsPerMeter = SkPoint::Make(ppm, ppm);
707
708 SkXPSDevice* dev = new SkXPSDevice();
709 SkAutoUnref aur(dev);
710
711 SkCanvas c(dev);
712 dev->beginPortfolio(&xps);
713 dev->beginSheet(unitsPerMeter, pixelsPerMeter, trimSize);
reed@google.comaef73612012-11-16 13:41:45 +0000714 invokeGM(gm, &c, false, false);
epoger@google.comde961632012-10-26 18:56:36 +0000715 dev->endSheet();
716 dev->endPortfolio();
717
718#endif
719 }
720
epoger@google.com37269602013-01-19 04:21:27 +0000721 /**
epoger@google.com84a18022013-02-01 20:39:15 +0000722 * Log more detail about the mistmatch between expectedBitmap and
723 * actualBitmap.
724 */
725 void report_bitmap_diffs(const SkBitmap& expectedBitmap, const SkBitmap& actualBitmap,
726 const char *testName) {
727 const int expectedWidth = expectedBitmap.width();
728 const int expectedHeight = expectedBitmap.height();
729 const int width = actualBitmap.width();
730 const int height = actualBitmap.height();
731 if ((expectedWidth != width) || (expectedHeight != height)) {
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000732 gm_fprintf(stderr, "---- %s: dimension mismatch --"
733 " expected [%d %d], actual [%d %d]\n",
734 testName, expectedWidth, expectedHeight, width, height);
epoger@google.com84a18022013-02-01 20:39:15 +0000735 return;
736 }
737
738 if ((SkBitmap::kARGB_8888_Config != expectedBitmap.config()) ||
739 (SkBitmap::kARGB_8888_Config != actualBitmap.config())) {
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000740 gm_fprintf(stderr, "---- %s: not computing max per-channel"
741 " pixel mismatch because non-8888\n", testName);
epoger@google.com84a18022013-02-01 20:39:15 +0000742 return;
743 }
744
745 SkAutoLockPixels alp0(expectedBitmap);
746 SkAutoLockPixels alp1(actualBitmap);
747 int errR = 0;
748 int errG = 0;
749 int errB = 0;
750 int errA = 0;
751 int differingPixels = 0;
752
753 for (int y = 0; y < height; ++y) {
754 const SkPMColor* expectedPixelPtr = expectedBitmap.getAddr32(0, y);
755 const SkPMColor* actualPixelPtr = actualBitmap.getAddr32(0, y);
756 for (int x = 0; x < width; ++x) {
757 SkPMColor expectedPixel = *expectedPixelPtr++;
758 SkPMColor actualPixel = *actualPixelPtr++;
759 if (expectedPixel != actualPixel) {
760 differingPixels++;
761 errR = SkMax32(errR, SkAbs32((int)SkGetPackedR32(expectedPixel) -
762 (int)SkGetPackedR32(actualPixel)));
763 errG = SkMax32(errG, SkAbs32((int)SkGetPackedG32(expectedPixel) -
764 (int)SkGetPackedG32(actualPixel)));
765 errB = SkMax32(errB, SkAbs32((int)SkGetPackedB32(expectedPixel) -
766 (int)SkGetPackedB32(actualPixel)));
767 errA = SkMax32(errA, SkAbs32((int)SkGetPackedA32(expectedPixel) -
768 (int)SkGetPackedA32(actualPixel)));
769 }
770 }
771 }
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000772 gm_fprintf(stderr, "---- %s: %d (of %d) differing pixels,"
773 " max per-channel mismatch R=%d G=%d B=%d A=%d\n",
774 testName, differingPixels, width*height, errR, errG, errB, errA);
epoger@google.com84a18022013-02-01 20:39:15 +0000775 }
776
777 /**
epoger@google.com908f5832013-04-12 02:23:55 +0000778 * Compares actual hash digest to expectations, returning the set of errors
epoger@google.com6f6568b2013-03-22 17:29:46 +0000779 * (if any) that we saw along the way.
epoger@google.com37269602013-01-19 04:21:27 +0000780 *
781 * If fMismatchPath has been set, and there are pixel diffs, then the
782 * actual bitmap will be written out to a file within fMismatchPath.
epoger@google.com5f995452013-06-21 18:16:47 +0000783 * And similarly for fMissingExpectationsPath...
epoger@google.com37269602013-01-19 04:21:27 +0000784 *
785 * @param expectations what expectations to compare actualBitmap against
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000786 * @param actualBitmapAndDigest the SkBitmap we actually generated, and its GmResultDigest
epoger@google.com659c8c02013-05-21 15:45:45 +0000787 * @param shortName name of test, e.g. "selftest1"
788 * @param configName name of config, e.g. "8888"
epoger@google.com37269602013-01-19 04:21:27 +0000789 * @param renderModeDescriptor e.g., "-rtree", "-deferred"
790 * @param addToJsonSummary whether to add these results (both actual and
epoger@google.comcaac3db2013-04-04 19:23:11 +0000791 * expected) to the JSON summary. Regardless of this setting, if
792 * we find an image mismatch in this test, we will write these
793 * results to the JSON summary. (This is so that we will always
794 * report errors across rendering modes, such as pipe vs tiled.
795 * See https://codereview.chromium.org/13650002/ )
epoger@google.com37269602013-01-19 04:21:27 +0000796 */
epoger@google.com6f6568b2013-03-22 17:29:46 +0000797 ErrorCombination compare_to_expectations(Expectations expectations,
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000798 const BitmapAndDigest& actualBitmapAndDigest,
epoger@google.com659c8c02013-05-21 15:45:45 +0000799 const char *shortName, const char *configName,
800 const char *renderModeDescriptor,
epoger@google.comcaac3db2013-04-04 19:23:11 +0000801 bool addToJsonSummary) {
epoger@google.com6f6568b2013-03-22 17:29:46 +0000802 ErrorCombination errors;
epoger@google.com659c8c02013-05-21 15:45:45 +0000803 SkString shortNamePlusConfig = make_shortname_plus_config(shortName, configName);
804 SkString completeNameString(shortNamePlusConfig);
epoger@google.com37269602013-01-19 04:21:27 +0000805 completeNameString.append(renderModeDescriptor);
epoger@google.comce057fe2013-05-14 15:17:46 +0000806 completeNameString.append(".");
807 completeNameString.append(kPNG_FileExtension);
epoger@google.com37269602013-01-19 04:21:27 +0000808 const char* completeName = completeNameString.c_str();
epoger@google.comee8a8e32012-12-18 19:13:49 +0000809
epoger@google.com37269602013-01-19 04:21:27 +0000810 if (expectations.empty()) {
epoger@google.com6f6568b2013-03-22 17:29:46 +0000811 errors.add(kMissingExpectations_ErrorType);
epoger@google.com5f995452013-06-21 18:16:47 +0000812
813 // Write out the "actuals" for any tests without expectations, if we have
814 // been directed to do so.
815 if (fMissingExpectationsPath) {
816 SkString path = make_bitmap_filename(fMissingExpectationsPath, shortName,
817 configName, renderModeDescriptor,
818 actualBitmapAndDigest.fDigest);
819 write_bitmap(path, actualBitmapAndDigest.fBitmap);
820 }
821
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000822 } else if (!expectations.match(actualBitmapAndDigest.fDigest)) {
epoger@google.comcaac3db2013-04-04 19:23:11 +0000823 addToJsonSummary = true;
824 // The error mode we record depends on whether this was running
825 // in a non-standard renderMode.
826 if ('\0' == *renderModeDescriptor) {
827 errors.add(kExpectationsMismatch_ErrorType);
828 } else {
829 errors.add(kRenderModeMismatch_ErrorType);
830 }
epoger@google.com84a18022013-02-01 20:39:15 +0000831
832 // Write out the "actuals" for any mismatches, if we have
833 // been directed to do so.
epoger@google.com37269602013-01-19 04:21:27 +0000834 if (fMismatchPath) {
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000835 SkString path = make_bitmap_filename(fMismatchPath, shortName, configName,
836 renderModeDescriptor,
837 actualBitmapAndDigest.fDigest);
838 write_bitmap(path, actualBitmapAndDigest.fBitmap);
epoger@google.com37269602013-01-19 04:21:27 +0000839 }
epoger@google.com84a18022013-02-01 20:39:15 +0000840
841 // If we have access to a single expected bitmap, log more
842 // detail about the mismatch.
843 const SkBitmap *expectedBitmapPtr = expectations.asBitmap();
844 if (NULL != expectedBitmapPtr) {
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000845 report_bitmap_diffs(*expectedBitmapPtr, actualBitmapAndDigest.fBitmap,
846 completeName);
epoger@google.com84a18022013-02-01 20:39:15 +0000847 }
epoger@google.coma243b222013-01-17 17:54:28 +0000848 }
epoger@google.coma243b222013-01-17 17:54:28 +0000849
epoger@google.com37269602013-01-19 04:21:27 +0000850 if (addToJsonSummary) {
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000851 add_actual_results_to_json_summary(completeName, actualBitmapAndDigest.fDigest, errors,
epoger@google.com37269602013-01-19 04:21:27 +0000852 expectations.ignoreFailure());
853 add_expected_results_to_json_summary(completeName, expectations);
854 }
epoger@google.coma243b222013-01-17 17:54:28 +0000855
epoger@google.com6f6568b2013-03-22 17:29:46 +0000856 return errors;
epoger@google.com06b8a192013-01-15 19:10:16 +0000857 }
858
epoger@google.com37269602013-01-19 04:21:27 +0000859 /**
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000860 * Add this result to the appropriate JSON collection of actual results (but just ONE),
epoger@google.com76c913d2013-04-26 15:06:44 +0000861 * depending on errors encountered.
epoger@google.com37269602013-01-19 04:21:27 +0000862 */
863 void add_actual_results_to_json_summary(const char testName[],
epoger@google.comd4993ff2013-05-24 14:33:28 +0000864 const GmResultDigest &actualResultDigest,
epoger@google.com76c913d2013-04-26 15:06:44 +0000865 ErrorCombination errors,
epoger@google.com37269602013-01-19 04:21:27 +0000866 bool ignoreFailure) {
epoger@google.comd4993ff2013-05-24 14:33:28 +0000867 Json::Value jsonActualResults = actualResultDigest.asJsonTypeValuePair();
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000868 Json::Value *resultCollection = NULL;
869
epoger@google.com76c913d2013-04-26 15:06:44 +0000870 if (errors.isEmpty()) {
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000871 resultCollection = &this->fJsonActualResults_Succeeded;
872 } else if (errors.includes(kRenderModeMismatch_ErrorType)) {
873 resultCollection = &this->fJsonActualResults_Failed;
874 } else if (errors.includes(kExpectationsMismatch_ErrorType)) {
epoger@google.com37269602013-01-19 04:21:27 +0000875 if (ignoreFailure) {
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000876 resultCollection = &this->fJsonActualResults_FailureIgnored;
epoger@google.com37269602013-01-19 04:21:27 +0000877 } else {
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000878 resultCollection = &this->fJsonActualResults_Failed;
epoger@google.com37269602013-01-19 04:21:27 +0000879 }
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000880 } else if (errors.includes(kMissingExpectations_ErrorType)) {
881 // TODO: What about the case where there IS an expected
882 // image hash digest, but that gm test doesn't actually
883 // run? For now, those cases will always be ignored,
884 // because gm only looks at expectations that correspond
885 // to gm tests that were actually run.
886 //
887 // Once we have the ability to express expectations as a
888 // JSON file, we should fix this (and add a test case for
889 // which an expectation is given but the test is never
890 // run).
891 resultCollection = &this->fJsonActualResults_NoComparison;
892 }
893
894 // If none of the above cases match, we don't add it to ANY tally of actual results.
895 if (resultCollection) {
896 (*resultCollection)[testName] = jsonActualResults;
epoger@google.com37269602013-01-19 04:21:27 +0000897 }
898 }
899
900 /**
901 * Add this test to the JSON collection of expected results.
902 */
903 void add_expected_results_to_json_summary(const char testName[],
904 Expectations expectations) {
epoger@google.com76c913d2013-04-26 15:06:44 +0000905 this->fJsonExpectedResults[testName] = expectations.asJsonValue();
epoger@google.com37269602013-01-19 04:21:27 +0000906 }
907
908 /**
909 * Compare actualBitmap to expectations stored in this->fExpectationsSource.
910 *
911 * @param gm which test generated the actualBitmap
912 * @param gRec
vandebo@chromium.org8fc37662013-08-21 18:04:09 +0000913 * @param configName The config name to look for in the expectation file.
epoger@google.come33e1372013-07-08 19:13:33 +0000914 * @param actualBitmapAndDigest ptr to bitmap generated by this run, or NULL
915 * if we don't have a usable bitmap representation
epoger@google.com37269602013-01-19 04:21:27 +0000916 */
epoger@google.com6f6568b2013-03-22 17:29:46 +0000917 ErrorCombination compare_test_results_to_stored_expectations(
vandebo@chromium.org8fc37662013-08-21 18:04:09 +0000918 GM* gm, const ConfigData& gRec, const char* configName,
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000919 const BitmapAndDigest* actualBitmapAndDigest) {
epoger@google.com659c8c02013-05-21 15:45:45 +0000920 ErrorCombination errors;
epoger@google.come33e1372013-07-08 19:13:33 +0000921
922 if (NULL == actualBitmapAndDigest) {
923 // Note that we intentionally skipped validating the results for
924 // this test, because we don't know how to generate an SkBitmap
925 // version of the output.
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000926 errors.add(ErrorCombination(kIntentionallySkipped_ErrorType));
epoger@google.comc824c832013-07-12 15:52:59 +0000927 } else if (!(gRec.fFlags & kWrite_ConfigFlag)) {
928 // We don't record the results for this test or compare them
929 // against any expectations, because the output image isn't
930 // meaningful.
931 // See https://code.google.com/p/skia/issues/detail?id=1410 ('some
932 // GM result images not available for download from Google Storage')
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000933 errors.add(ErrorCombination(kIntentionallySkipped_ErrorType));
epoger@google.come33e1372013-07-08 19:13:33 +0000934 } else {
935 ExpectationsSource *expectationsSource = this->fExpectationsSource.get();
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +0000936 SkString nameWithExtension = make_shortname_plus_config(gm->shortName(), configName);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000937 nameWithExtension.append(".");
938 nameWithExtension.append(kPNG_FileExtension);
939
epoger@google.come33e1372013-07-08 19:13:33 +0000940 if (expectationsSource && (gRec.fFlags & kRead_ConfigFlag)) {
941 /*
942 * Get the expected results for this test, as one or more allowed
943 * hash digests. The current implementation of expectationsSource
944 * get this by computing the hash digest of a single PNG file on disk.
945 *
946 * TODO(epoger): This relies on the fact that
947 * force_all_opaque() was called on the bitmap before it
948 * was written to disk as a PNG in the first place. If
949 * not, the hash digest returned here may not match the
950 * hash digest of actualBitmap, which *has* been run through
951 * force_all_opaque().
952 * See comments above complete_bitmap() for more detail.
953 */
954 Expectations expectations = expectationsSource->get(nameWithExtension.c_str());
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +0000955 if (this->ShouldIgnoreTest(gm->shortName())) {
epoger@google.comdefc4872013-09-19 06:18:27 +0000956 expectations.setIgnoreFailure(true);
957 }
epoger@google.come33e1372013-07-08 19:13:33 +0000958 errors.add(compare_to_expectations(expectations, *actualBitmapAndDigest,
vandebo@chromium.org8fc37662013-08-21 18:04:09 +0000959 gm->shortName(), configName, "", true));
epoger@google.come33e1372013-07-08 19:13:33 +0000960 } else {
961 // If we are running without expectations, we still want to
962 // record the actual results.
963 add_actual_results_to_json_summary(nameWithExtension.c_str(),
964 actualBitmapAndDigest->fDigest,
965 ErrorCombination(kMissingExpectations_ErrorType),
966 false);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000967 errors.add(ErrorCombination(kMissingExpectations_ErrorType));
epoger@google.come33e1372013-07-08 19:13:33 +0000968 }
epoger@google.com9ef89ce2013-01-18 21:45:42 +0000969 }
epoger@google.com6f6568b2013-03-22 17:29:46 +0000970 return errors;
epoger@google.coma243b222013-01-17 17:54:28 +0000971 }
972
epoger@google.com37269602013-01-19 04:21:27 +0000973 /**
974 * Compare actualBitmap to referenceBitmap.
975 *
epoger@google.com659c8c02013-05-21 15:45:45 +0000976 * @param shortName test name, e.g. "selftest1"
977 * @param configName configuration name, e.g. "8888"
epoger@google.com37269602013-01-19 04:21:27 +0000978 * @param renderModeDescriptor
979 * @param actualBitmap actual bitmap generated by this run
980 * @param referenceBitmap bitmap we expected to be generated
981 */
epoger@google.com6f6568b2013-03-22 17:29:46 +0000982 ErrorCombination compare_test_results_to_reference_bitmap(
epoger@google.com659c8c02013-05-21 15:45:45 +0000983 const char *shortName, const char *configName, const char *renderModeDescriptor,
epoger@google.com37269602013-01-19 04:21:27 +0000984 SkBitmap& actualBitmap, const SkBitmap* referenceBitmap) {
985
986 SkASSERT(referenceBitmap);
epoger@google.com84a18022013-02-01 20:39:15 +0000987 Expectations expectations(*referenceBitmap);
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000988 BitmapAndDigest actualBitmapAndDigest(actualBitmap);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000989
990 // TODO: Eliminate RecordTestResults from here.
991 // Results recording code for the test_drawing path has been refactored so that
992 // RecordTestResults is only called once, at the topmost level. However, the
993 // other paths have not yet been refactored, and RecordTestResults has been added
994 // here to maintain proper behavior for calls not coming from the test_drawing path.
995 ErrorCombination errors;
996 errors.add(compare_to_expectations(expectations, actualBitmapAndDigest, shortName,
997 configName, renderModeDescriptor, false));
998 SkString shortNamePlusConfig = make_shortname_plus_config(shortName, configName);
999 RecordTestResults(errors, shortNamePlusConfig, renderModeDescriptor);
1000
1001 return errors;
epoger@google.com37269602013-01-19 04:21:27 +00001002 }
1003
junov@chromium.org20bd04e2013-01-16 18:43:36 +00001004 static SkPicture* generate_new_picture(GM* gm, BbhType bbhType, uint32_t recordFlags,
1005 SkScalar scale = SK_Scalar1) {
epoger@google.comde961632012-10-26 18:56:36 +00001006 // Pictures are refcounted so must be on heap
junov@chromium.org3cb834b2012-12-13 16:39:53 +00001007 SkPicture* pict;
junov@chromium.org706ff2f2012-12-19 15:55:40 +00001008 int width = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().width()), scale));
1009 int height = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().height()), scale));
skia.committer@gmail.comd8b27992012-12-20 02:01:41 +00001010
junov@chromium.org3cb834b2012-12-13 16:39:53 +00001011 if (kTileGrid_BbhType == bbhType) {
junov@chromium.org29b19e52013-02-27 18:35:16 +00001012 SkTileGridPicture::TileGridInfo info;
1013 info.fMargin.setEmpty();
1014 info.fOffset.setZero();
1015 info.fTileInterval.set(16, 16);
1016 pict = new SkTileGridPicture(width, height, info);
junov@chromium.org3cb834b2012-12-13 16:39:53 +00001017 } else {
1018 pict = new SkPicture;
1019 }
junov@chromium.org20bd04e2013-01-16 18:43:36 +00001020 if (kNone_BbhType != bbhType) {
1021 recordFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag;
1022 }
junov@chromium.org706ff2f2012-12-19 15:55:40 +00001023 SkCanvas* cv = pict->beginRecording(width, height, recordFlags);
junov@chromium.orgc938c482012-12-19 15:24:38 +00001024 cv->scale(scale, scale);
reed@google.comaef73612012-11-16 13:41:45 +00001025 invokeGM(gm, cv, false, false);
epoger@google.comde961632012-10-26 18:56:36 +00001026 pict->endRecording();
1027
1028 return pict;
1029 }
1030
1031 static SkPicture* stream_to_new_picture(const SkPicture& src) {
epoger@google.comde961632012-10-26 18:56:36 +00001032 SkDynamicMemoryWStream storage;
reed@google.com672588b2014-01-08 15:42:01 +00001033 src.serialize(&storage, NULL);
bungeman@google.comc29f3d82013-07-19 22:32:11 +00001034 SkAutoTUnref<SkStreamAsset> pictReadback(storage.detachAsStream());
commit-bot@chromium.org805df1a2013-08-16 19:18:12 +00001035 SkPicture* retval = SkPicture::CreateFromStream(pictReadback,
1036 &SkImageDecoder::DecodeMemory);
epoger@google.comde961632012-10-26 18:56:36 +00001037 return retval;
1038 }
1039
1040 // Test: draw into a bitmap or pdf.
epoger@google.com15655b22013-01-08 18:47:31 +00001041 // Depending on flags, possibly compare to an expected image.
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001042 // If writePath is not NULL, also write images (or documents) to the specified path.
1043 ErrorCombination test_drawing(GM* gm, const ConfigData& gRec,
1044 const SkTDArray<const PDFRasterizerData*> &pdfRasterizers,
epoger@google.com6f6568b2013-03-22 17:29:46 +00001045 const char writePath [],
bsalomon@google.com123ac1d2013-03-28 19:18:12 +00001046 GrSurface* gpuTarget,
epoger@google.com6f6568b2013-03-22 17:29:46 +00001047 SkBitmap* bitmap) {
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001048 ErrorCombination errors;
epoger@google.comde961632012-10-26 18:56:36 +00001049 SkDynamicMemoryWStream document;
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001050 SkString path;
epoger@google.comde961632012-10-26 18:56:36 +00001051
1052 if (gRec.fBackend == kRaster_Backend ||
1053 gRec.fBackend == kGPU_Backend) {
1054 // Early exit if we can't generate the image.
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001055 errors.add(generate_image(gm, gRec, gpuTarget, bitmap, false));
epoger@google.com6f6568b2013-03-22 17:29:46 +00001056 if (!errors.isEmpty()) {
epoger@google.com37269602013-01-19 04:21:27 +00001057 // TODO: Add a test to exercise what the stdout and
1058 // JSON look like if we get an "early error" while
1059 // trying to generate the image.
epoger@google.comde961632012-10-26 18:56:36 +00001060 return errors;
1061 }
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001062 BitmapAndDigest bitmapAndDigest(*bitmap);
1063 errors.add(compare_test_results_to_stored_expectations(
vandebo@chromium.org8fc37662013-08-21 18:04:09 +00001064 gm, gRec, gRec.fName, &bitmapAndDigest));
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001065
1066 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) {
1067 path = make_bitmap_filename(writePath, gm->shortName(), gRec.fName,
1068 "", bitmapAndDigest.fDigest);
1069 errors.add(write_bitmap(path, bitmapAndDigest.fBitmap));
1070 }
epoger@google.comde961632012-10-26 18:56:36 +00001071 } else if (gRec.fBackend == kPDF_Backend) {
commit-bot@chromium.org5e009892013-10-14 13:42:12 +00001072 if (!generate_pdf(gm, document)) {
1073 errors.add(kGeneratePdfFailed_ErrorType);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001074 } else {
commit-bot@chromium.org5e009892013-10-14 13:42:12 +00001075 SkAutoTUnref<SkStreamAsset> documentStream(document.detachAsStream());
1076 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) {
1077 path = make_filename(writePath, gm->shortName(), gRec.fName, "", "pdf");
1078 errors.add(write_document(path, documentStream));
1079 }
1080
1081 if (!(gm->getFlags() & GM::kSkipPDFRasterization_Flag)) {
1082 for (int i = 0; i < pdfRasterizers.count(); i++) {
1083 SkBitmap pdfBitmap;
vandebo@chromium.org969967e2013-12-09 23:22:15 +00001084 documentStream->rewind();
commit-bot@chromium.org5e009892013-10-14 13:42:12 +00001085 bool success = (*pdfRasterizers[i]->fRasterizerFunction)(
1086 documentStream.get(), &pdfBitmap);
1087 if (!success) {
1088 gm_fprintf(stderr, "FAILED to render PDF for %s using renderer %s\n",
1089 gm->shortName(),
1090 pdfRasterizers[i]->fName);
1091 continue;
1092 }
1093
1094 SkString configName(gRec.fName);
1095 configName.append("-");
1096 configName.append(pdfRasterizers[i]->fName);
1097
1098 BitmapAndDigest bitmapAndDigest(pdfBitmap);
1099 errors.add(compare_test_results_to_stored_expectations(
1100 gm, gRec, configName.c_str(), &bitmapAndDigest));
1101
1102 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) {
1103 path = make_bitmap_filename(writePath, gm->shortName(),
1104 configName.c_str(),
1105 "", bitmapAndDigest.fDigest);
1106 errors.add(write_bitmap(path, bitmapAndDigest.fBitmap));
1107 }
1108 }
1109 } else {
1110 errors.add(kIntentionallySkipped_ErrorType);
1111 }
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001112 }
epoger@google.comde961632012-10-26 18:56:36 +00001113 } else if (gRec.fBackend == kXPS_Backend) {
1114 generate_xps(gm, document);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001115 SkAutoTUnref<SkStreamAsset> documentStream(document.detachAsStream());
epoger@google.come33e1372013-07-08 19:13:33 +00001116
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001117 errors.add(compare_test_results_to_stored_expectations(
vandebo@chromium.org8fc37662013-08-21 18:04:09 +00001118 gm, gRec, gRec.fName, NULL));
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001119
1120 if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) {
1121 path = make_filename(writePath, gm->shortName(), gRec.fName, "", "xps");
1122 errors.add(write_document(path, documentStream));
1123 }
epoger@google.come33e1372013-07-08 19:13:33 +00001124 } else {
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001125 SkASSERT(false);
epoger@google.come33e1372013-07-08 19:13:33 +00001126 }
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001127 return errors;
epoger@google.comde961632012-10-26 18:56:36 +00001128 }
1129
epoger@google.com6f6568b2013-03-22 17:29:46 +00001130 ErrorCombination test_deferred_drawing(GM* gm,
1131 const ConfigData& gRec,
1132 const SkBitmap& referenceBitmap,
bsalomon@google.com123ac1d2013-03-28 19:18:12 +00001133 GrSurface* gpuTarget) {
epoger@google.comde961632012-10-26 18:56:36 +00001134 if (gRec.fBackend == kRaster_Backend ||
1135 gRec.fBackend == kGPU_Backend) {
epoger@google.comc8263e72013-04-10 12:17:34 +00001136 const char renderModeDescriptor[] = "-deferred";
epoger@google.comde961632012-10-26 18:56:36 +00001137 SkBitmap bitmap;
1138 // Early exit if we can't generate the image, but this is
1139 // expected in some cases, so don't report a test failure.
bsalomon@google.com123ac1d2013-03-28 19:18:12 +00001140 ErrorCombination errors = generate_image(gm, gRec, gpuTarget, &bitmap, true);
epoger@google.com6f6568b2013-03-22 17:29:46 +00001141 // TODO(epoger): This logic is the opposite of what is
1142 // described above... if we succeeded in generating the
1143 // -deferred image, we exit early! We should fix this
1144 // ASAP, because it is hiding -deferred errors... but for
1145 // now, I'm leaving the logic as it is so that the
1146 // refactoring change
1147 // https://codereview.chromium.org/12992003/ is unblocked.
1148 //
1149 // Filed as https://code.google.com/p/skia/issues/detail?id=1180
1150 // ('image-surface gm test is failing in "deferred" mode,
1151 // and gm is not reporting the failure')
1152 if (errors.isEmpty()) {
epoger@google.com310478e2013-04-03 18:00:39 +00001153 // TODO(epoger): Report this as a new ErrorType,
1154 // something like kImageGeneration_ErrorType?
epoger@google.com6f6568b2013-03-22 17:29:46 +00001155 return kEmpty_ErrorCombination;
epoger@google.comde961632012-10-26 18:56:36 +00001156 }
epoger@google.com37269602013-01-19 04:21:27 +00001157 return compare_test_results_to_reference_bitmap(
epoger@google.com659c8c02013-05-21 15:45:45 +00001158 gm->shortName(), gRec.fName, renderModeDescriptor, bitmap, &referenceBitmap);
epoger@google.comde961632012-10-26 18:56:36 +00001159 }
epoger@google.com6f6568b2013-03-22 17:29:46 +00001160 return kEmpty_ErrorCombination;
epoger@google.comde961632012-10-26 18:56:36 +00001161 }
1162
epoger@google.comcaac3db2013-04-04 19:23:11 +00001163 ErrorCombination test_pipe_playback(GM* gm, const ConfigData& gRec,
1164 const SkBitmap& referenceBitmap, bool simulateFailure) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001165 const SkString shortNamePlusConfig = make_shortname_plus_config(gm->shortName(),
1166 gRec.fName);
epoger@google.com6f6568b2013-03-22 17:29:46 +00001167 ErrorCombination errors;
epoger@google.comde961632012-10-26 18:56:36 +00001168 for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) {
epoger@google.comc8263e72013-04-10 12:17:34 +00001169 SkString renderModeDescriptor("-pipe");
1170 renderModeDescriptor.append(gPipeWritingFlagCombos[i].name);
1171
commit-bot@chromium.org805df1a2013-08-16 19:18:12 +00001172 if (gm->getFlags() & GM::kSkipPipe_Flag
1173 || (gPipeWritingFlagCombos[i].flags == SkGPipeWriter::kCrossProcess_Flag
1174 && gm->getFlags() & GM::kSkipPipeCrossProcess_Flag)) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001175 RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
epoger@google.comc8263e72013-04-10 12:17:34 +00001176 renderModeDescriptor.c_str());
1177 errors.add(kIntentionallySkipped_ErrorType);
1178 } else {
1179 SkBitmap bitmap;
1180 SkISize size = gm->getISize();
1181 setup_bitmap(gRec, size, &bitmap);
1182 SkCanvas canvas(bitmap);
1183 installFilter(&canvas);
scroggo@google.com74b7ffd2013-04-30 02:32:41 +00001184 // Pass a decoding function so the factory GM (which has an SkBitmap
1185 // with encoded data) will not fail playback.
1186 PipeController pipeController(&canvas, &SkImageDecoder::DecodeMemory);
epoger@google.comc8263e72013-04-10 12:17:34 +00001187 SkGPipeWriter writer;
1188 SkCanvas* pipeCanvas = writer.startRecording(&pipeController,
scroggo@google.comaef2d3b2013-04-10 18:10:41 +00001189 gPipeWritingFlagCombos[i].flags,
1190 size.width(), size.height());
epoger@google.comc8263e72013-04-10 12:17:34 +00001191 if (!simulateFailure) {
1192 invokeGM(gm, pipeCanvas, false, false);
1193 }
1194 complete_bitmap(&bitmap);
1195 writer.endRecording();
1196 errors.add(compare_test_results_to_reference_bitmap(
epoger@google.com659c8c02013-05-21 15:45:45 +00001197 gm->shortName(), gRec.fName, renderModeDescriptor.c_str(), bitmap,
1198 &referenceBitmap));
epoger@google.comc8263e72013-04-10 12:17:34 +00001199 if (!errors.isEmpty()) {
1200 break;
1201 }
epoger@google.comde961632012-10-26 18:56:36 +00001202 }
1203 }
1204 return errors;
1205 }
1206
epoger@google.com6f6568b2013-03-22 17:29:46 +00001207 ErrorCombination test_tiled_pipe_playback(GM* gm, const ConfigData& gRec,
1208 const SkBitmap& referenceBitmap) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001209 const SkString shortNamePlusConfig = make_shortname_plus_config(gm->shortName(),
1210 gRec.fName);
epoger@google.com6f6568b2013-03-22 17:29:46 +00001211 ErrorCombination errors;
epoger@google.comde961632012-10-26 18:56:36 +00001212 for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) {
epoger@google.comc8263e72013-04-10 12:17:34 +00001213 SkString renderModeDescriptor("-tiled pipe");
1214 renderModeDescriptor.append(gPipeWritingFlagCombos[i].name);
1215
1216 if ((gm->getFlags() & GM::kSkipPipe_Flag) ||
1217 (gm->getFlags() & GM::kSkipTiled_Flag)) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001218 RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
epoger@google.comc8263e72013-04-10 12:17:34 +00001219 renderModeDescriptor.c_str());
1220 errors.add(kIntentionallySkipped_ErrorType);
1221 } else {
1222 SkBitmap bitmap;
1223 SkISize size = gm->getISize();
1224 setup_bitmap(gRec, size, &bitmap);
1225 SkCanvas canvas(bitmap);
1226 installFilter(&canvas);
scroggo@google.com74b7ffd2013-04-30 02:32:41 +00001227 TiledPipeController pipeController(bitmap, &SkImageDecoder::DecodeMemory);
epoger@google.comc8263e72013-04-10 12:17:34 +00001228 SkGPipeWriter writer;
1229 SkCanvas* pipeCanvas = writer.startRecording(&pipeController,
scroggo@google.comaef2d3b2013-04-10 18:10:41 +00001230 gPipeWritingFlagCombos[i].flags,
1231 size.width(), size.height());
epoger@google.comc8263e72013-04-10 12:17:34 +00001232 invokeGM(gm, pipeCanvas, false, false);
1233 complete_bitmap(&bitmap);
1234 writer.endRecording();
epoger@google.com659c8c02013-05-21 15:45:45 +00001235 errors.add(compare_test_results_to_reference_bitmap(gm->shortName(), gRec.fName,
epoger@google.comc8263e72013-04-10 12:17:34 +00001236 renderModeDescriptor.c_str(),
1237 bitmap, &referenceBitmap));
1238 if (!errors.isEmpty()) {
1239 break;
1240 }
epoger@google.comde961632012-10-26 18:56:36 +00001241 }
1242 }
1243 return errors;
1244 }
epoger@google.come8ebeb12012-10-29 16:42:11 +00001245
1246 //
1247 // member variables.
1248 // They are public for now, to allow easier setting by tool_main().
1249 //
1250
epoger@google.com6f7f14d2013-06-19 18:28:31 +00001251 bool fUseFileHierarchy, fWriteChecksumBasedFilenames;
epoger@google.com5079d2c2013-04-12 14:11:21 +00001252 ErrorCombination fIgnorableErrorTypes;
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +00001253 SkTArray<SkString> fIgnorableTestNames;
epoger@google.come8ebeb12012-10-29 16:42:11 +00001254
junov@chromium.org95146eb2013-01-11 21:04:40 +00001255 const char* fMismatchPath;
epoger@google.com5f995452013-06-21 18:16:47 +00001256 const char* fMissingExpectationsPath;
junov@chromium.org95146eb2013-01-11 21:04:40 +00001257
epoger@google.com310478e2013-04-03 18:00:39 +00001258 // collection of tests that have failed with each ErrorType
1259 SkTArray<SkString> fFailedTests[kLast_ErrorType+1];
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001260 SkTArray<SkString> fTestsSkippedOnAllRenderModes;
epoger@google.com310478e2013-04-03 18:00:39 +00001261 int fTestsRun;
1262 SkTDict<int> fRenderModesEncountered;
epoger@google.com57f7abc2012-11-13 03:41:55 +00001263
epoger@google.com908f5832013-04-12 02:23:55 +00001264 // Where to read expectations (expected image hash digests, etc.) from.
epoger@google.com37269602013-01-19 04:21:27 +00001265 // If unset, we don't do comparisons.
1266 SkAutoTUnref<ExpectationsSource> fExpectationsSource;
1267
1268 // JSON summaries that we generate as we go (just for output).
epoger@google.comee8a8e32012-12-18 19:13:49 +00001269 Json::Value fJsonExpectedResults;
1270 Json::Value fJsonActualResults_Failed;
1271 Json::Value fJsonActualResults_FailureIgnored;
epoger@google.com9c56a8d2012-12-20 18:34:29 +00001272 Json::Value fJsonActualResults_NoComparison;
epoger@google.comee8a8e32012-12-18 19:13:49 +00001273 Json::Value fJsonActualResults_Succeeded;
1274
epoger@google.comde961632012-10-26 18:56:36 +00001275}; // end of GMMain class definition
scroggo@google.com72c96722012-06-06 21:07:10 +00001276
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001277#if SK_SUPPORT_GPU
1278static const GLContextType kDontCare_GLContextType = GrContextFactory::kNative_GLContextType;
1279#else
1280static const GLContextType kDontCare_GLContextType = 0;
1281#endif
bsalomon@google.com7361f542012-04-19 19:15:35 +00001282
tomhudson@google.com9875dd12011-04-25 15:49:53 +00001283static const ConfigData gRec[] = {
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001284 { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "8888", true },
reed@google.com69dc4ff2012-11-29 21:21:54 +00001285#if 0 // stop testing this (for now at least) since we want to remove support for it (soon please!!!)
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001286 { SkBitmap::kARGB_4444_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "4444", true },
reed@google.com69dc4ff2012-11-29 21:21:54 +00001287#endif
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001288 { SkBitmap::kRGB_565_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "565", true },
1289#if SK_SUPPORT_GPU
1290 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 0, kRW_ConfigFlag, "gpu", true },
robertphillips@google.com7bb28a12013-06-06 21:29:39 +00001291 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 16, kRW_ConfigFlag, "msaa16", false},
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001292 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 4, kRW_ConfigFlag, "msaa4", false},
epoger@google.comc824c832013-07-12 15:52:59 +00001293 /* The gpudebug context does not generate meaningful images, so don't record
1294 * the images it generates! We only run it to look for asserts. */
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +00001295 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kDebug_GLContextType, 0, kNone_ConfigFlag, "gpudebug", kDebugOnly},
robertphillips@google.comd6543e52013-07-18 17:39:14 +00001296 /* The gpunull context does the least amount of work possible and doesn't
1297 generate meaninful images, so don't record them!. It can be run to
1298 isolate the CPU-side processing expense from the GPU-side.
1299 */
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +00001300 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNull_GLContextType, 0, kNone_ConfigFlag, "gpunull", kDebugOnly},
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001301#if SK_ANGLE
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001302 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 0, kRW_ConfigFlag, "angle", true },
1303 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 16, kRW_ConfigFlag, "anglemsaa16", true },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001304#endif // SK_ANGLE
1305#ifdef SK_MESA
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001306 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kMESA_GLContextType, 0, kRW_ConfigFlag, "mesa", true },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001307#endif // SK_MESA
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001308#endif // SK_SUPPORT_GPU
bungeman@google.comb29c8832011-10-10 13:19:10 +00001309#ifdef SK_SUPPORT_XPS
bsalomon@google.com7361f542012-04-19 19:15:35 +00001310 /* At present we have no way of comparing XPS files (either natively or by converting to PNG). */
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001311 { SkBitmap::kARGB_8888_Config, kXPS_Backend, kDontCare_GLContextType, 0, kWrite_ConfigFlag, "xps", true },
robertphillips@google.coma73e8602012-08-02 17:56:02 +00001312#endif // SK_SUPPORT_XPS
bsalomon@google.com7361f542012-04-19 19:15:35 +00001313#ifdef SK_SUPPORT_PDF
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001314 { SkBitmap::kARGB_8888_Config, kPDF_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "pdf", true },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001315#endif // SK_SUPPORT_PDF
reed@android.com00dae862009-06-10 15:38:48 +00001316};
1317
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001318static const PDFRasterizerData kPDFRasterizers[] = {
1319#ifdef SK_BUILD_FOR_MAC
1320 { &SkPDFDocumentToBitmap, "mac", true },
1321#endif
1322#ifdef SK_BUILD_POPPLER
1323 { &SkPopplerRasterizePDF, "poppler", true },
1324#endif
commit-bot@chromium.orgffd178c2013-11-11 15:10:47 +00001325#ifdef SK_BUILD_NATIVE_PDF_RENDERER
1326 { &SkNativeRasterizePDF, "native", true },
1327#endif // SK_BUILD_NATIVE_PDF_RENDERER
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001328};
1329
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001330static const char kDefaultsConfigStr[] = "defaults";
1331static const char kExcludeConfigChar = '~';
1332
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001333static SkString configUsage() {
scroggo@google.com0f567c62013-03-20 15:35:08 +00001334 SkString result;
1335 result.appendf("Space delimited list of which configs to run. Possible options: [");
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001336 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001337 SkASSERT(gRec[i].fName != kDefaultsConfigStr);
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001338 if (i > 0) {
scroggo@google.com0f567c62013-03-20 15:35:08 +00001339 result.append("|");
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001340 }
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001341 result.appendf("%s", gRec[i].fName);
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001342 }
scroggo@google.com0f567c62013-03-20 15:35:08 +00001343 result.append("]\n");
1344 result.appendf("The default value is: \"");
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001345 SkString firstDefault;
1346 SkString allButFirstDefaults;
1347 SkString nonDefault;
scroggo@google.com0f567c62013-03-20 15:35:08 +00001348 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
1349 if (gRec[i].fRunByDefault) {
1350 if (i > 0) {
1351 result.append(" ");
1352 }
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001353 result.append(gRec[i].fName);
1354 if (firstDefault.isEmpty()) {
1355 firstDefault = gRec[i].fName;
1356 } else {
1357 if (!allButFirstDefaults.isEmpty()) {
1358 allButFirstDefaults.append(" ");
1359 }
1360 allButFirstDefaults.append(gRec[i].fName);
1361 }
1362 } else {
1363 nonDefault = gRec[i].fName;
scroggo@google.com0f567c62013-03-20 15:35:08 +00001364 }
1365 }
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001366 result.append("\"\n");
1367 result.appendf("\"%s\" evaluates to the default set of configs.\n", kDefaultsConfigStr);
1368 result.appendf("Prepending \"%c\" on a config name excludes it from the set of configs to run.\n"
1369 "Exclusions always override inclusions regardless of order.\n",
1370 kExcludeConfigChar);
1371 result.appendf("E.g. \"--config %s %c%s %s\" will run these configs:\n\t%s %s",
1372 kDefaultsConfigStr,
1373 kExcludeConfigChar,
1374 firstDefault.c_str(),
1375 nonDefault.c_str(),
1376 allButFirstDefaults.c_str(),
1377 nonDefault.c_str());
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001378 return result;
scroggo@google.com0b735632013-03-19 17:38:50 +00001379}
scroggo@google.com7d519302013-03-19 17:28:10 +00001380
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001381static SkString pdfRasterizerUsage() {
1382 SkString result;
1383 result.appendf("Space delimited list of which PDF rasterizers to run. Possible options: [");
1384 // For this (and further) loops through kPDFRasterizers, there is a typecast to int to avoid
1385 // the compiler giving an "comparison of unsigned expression < 0 is always false" warning
1386 // and turning it into a build-breaking error.
1387 for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); ++i) {
1388 if (i > 0) {
1389 result.append(" ");
1390 }
1391 result.append(kPDFRasterizers[i].fName);
1392 }
1393 result.append("]\n");
1394 result.append("The default value is: \"");
1395 for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); ++i) {
1396 if (kPDFRasterizers[i].fRunByDefault) {
1397 if (i > 0) {
1398 result.append(" ");
1399 }
1400 result.append(kPDFRasterizers[i].fName);
1401 }
1402 }
1403 result.append("\"");
1404 return result;
1405}
1406
epoger@google.com6f6568b2013-03-22 17:29:46 +00001407// Macro magic to convert a numeric preprocessor token into a string.
1408// Adapted from http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
1409// This should probably be moved into one of our common headers...
1410#define TOSTRING_INTERNAL(x) #x
1411#define TOSTRING(x) TOSTRING_INTERNAL(x)
1412
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001413// Alphabetized ignoring "no" prefix ("readPath", "noreplay", "resourcePath").
scroggo@google.com0f567c62013-03-20 15:35:08 +00001414DEFINE_string(config, "", configUsage().c_str());
vandebo@chromium.orgf8afb2b2013-11-06 16:32:15 +00001415DEFINE_string(pdfRasterizers, "default", pdfRasterizerUsage().c_str());
epoger@google.com5e497382013-09-30 07:01:55 +00001416DEFINE_bool(deferred, false, "Exercise the deferred rendering test pass.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001417DEFINE_string(excludeConfig, "", "Space delimited list of configs to skip.");
1418DEFINE_bool(forceBWtext, false, "Disable text anti-aliasing.");
1419#if SK_SUPPORT_GPU
1420DEFINE_string(gpuCacheSize, "", "<bytes> <count>: Limit the gpu cache to byte size or "
epoger@google.com6f6568b2013-03-22 17:29:46 +00001421 "object count. " TOSTRING(DEFAULT_CACHE_VALUE) " for either value means "
1422 "use the default. 0 for either disables the cache.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001423#endif
1424DEFINE_bool(hierarchy, false, "Whether to use multilevel directory structure "
1425 "when reading/writing files.");
epoger@google.com5079d2c2013-04-12 14:11:21 +00001426DEFINE_string(ignoreErrorTypes, kDefaultIgnorableErrorTypes.asString(" ").c_str(),
1427 "Space-separated list of ErrorTypes that should be ignored. If any *other* error "
1428 "types are encountered, the tool will exit with a nonzero return value.");
epoger@google.comf711f322013-10-18 14:55:47 +00001429DEFINE_string(ignoreFailuresFile, "", "Path to file containing a list of tests for which we "
1430 "should ignore failures.\n"
1431 "The file should list one test per line, except for comment lines starting with #");
commit-bot@chromium.org6dda8272014-01-23 17:21:19 +00001432DEFINE_bool2(leaks, l, false, "show leaked ref cnt'd objects.");
caryclark@google.com512c9b62013-05-10 15:16:13 +00001433DEFINE_string(match, "", "[~][^]substring[$] [...] of test name to run.\n"
1434 "Multiple matches may be separated by spaces.\n"
1435 "~ causes a matching test to always be skipped\n"
1436 "^ requires the start of the test to match\n"
1437 "$ requires the end of the test to match\n"
1438 "^ and $ requires an exact match\n"
1439 "If a test does not match any list entry,\n"
1440 "it is skipped unless some list entry starts with ~");
epoger@google.com5f995452013-06-21 18:16:47 +00001441DEFINE_string(missingExpectationsPath, "", "Write images for tests without expectations "
1442 "into this directory.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001443DEFINE_string(mismatchPath, "", "Write images for tests that failed due to "
1444 "pixel mismatches into this directory.");
1445DEFINE_string(modulo, "", "[--modulo <remainder> <divisor>]: only run tests for which "
1446 "testIndex %% divisor == remainder.");
epoger@google.com5e497382013-09-30 07:01:55 +00001447DEFINE_bool(pipe, false, "Exercise the SkGPipe replay test pass.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001448DEFINE_string2(readPath, r, "", "Read reference images from this dir, and report "
1449 "any differences between those and the newly generated ones.");
epoger@google.com5e497382013-09-30 07:01:55 +00001450DEFINE_bool(replay, false, "Exercise the SkPicture replay test pass.");
djsollen@google.comac8f3a42013-10-04 14:57:00 +00001451#if SK_SUPPORT_GPU
1452DEFINE_bool(resetGpuContext, false, "Reset the GrContext prior to running each GM.");
1453#endif
tfarina@chromium.org725a64c2013-12-31 14:29:52 +00001454DEFINE_string2(resourcePath, i, "resources", "Directory that stores image resources.");
epoger@google.com5e497382013-09-30 07:01:55 +00001455DEFINE_bool(rtree, false, "Exercise the R-Tree variant of SkPicture test pass.");
1456DEFINE_bool(serialize, false, "Exercise the SkPicture serialization & deserialization test pass.");
epoger@google.comcaac3db2013-04-04 19:23:11 +00001457DEFINE_bool(simulatePipePlaybackFailure, false, "Simulate a rendering failure in pipe mode only.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001458DEFINE_bool(tiledPipe, false, "Exercise tiled SkGPipe replay.");
epoger@google.com5e497382013-09-30 07:01:55 +00001459DEFINE_bool(tileGrid, false, "Exercise the tile grid variant of SkPicture.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001460DEFINE_string(tileGridReplayScales, "", "Space separated list of floating-point scale "
1461 "factors to be used for tileGrid playback testing. Default value: 1.0");
epoger@google.comb0f8b432013-04-10 18:46:25 +00001462DEFINE_bool2(verbose, v, false, "Give more detail (e.g. list all GMs run, more info about "
1463 "each test).");
epoger@google.com6f7f14d2013-06-19 18:28:31 +00001464DEFINE_bool(writeChecksumBasedFilenames, false, "When writing out actual images, use checksum-"
1465 "based filenames, as rebaseline.py will use when downloading them from Google Storage");
1466DEFINE_string(writeJsonSummaryPath, "", "Write a JSON-formatted result summary to this file.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001467DEFINE_string2(writePath, w, "", "Write rendered images into this directory.");
scroggo@google.com604e0c22013-04-09 21:25:46 +00001468DEFINE_string2(writePicturePath, p, "", "Write .skp files into this directory.");
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001469DEFINE_int32(pdfJpegQuality, -1, "Encodes images in JPEG at quality level N, "
1470 "which can be in range 0-100). N = -1 will disable JPEG compression. "
1471 "Default is N = 100, maximum quality.");
commit-bot@chromium.orgf4f9df42013-09-26 20:44:24 +00001472// TODO(edisonn): pass a matrix instead of forcePerspectiveMatrix
1473// Either the 9 numbers defining the matrix
1474// or probably more readable would be to replace it with a set of a few predicates
1475// Like --prerotate 100 200 10 --posttranslate 10, 10
1476// Probably define spacial names like centerx, centery, top, bottom, left, right
1477// then we can write something reabable like --rotate centerx centery 90
1478DEFINE_bool(forcePerspectiveMatrix, false, "Force a perspective matrix.");
commit-bot@chromium.org5e009892013-10-14 13:42:12 +00001479DEFINE_bool(useDocumentInsteadOfDevice, false, "Use SkDocument::CreateFoo instead of SkFooDevice.");
edisonn@google.com73a7ea32013-11-11 20:55:15 +00001480DEFINE_int32(pdfRasterDpi, 72, "Scale at which at which the non suported "
1481 "features in PDF are rasterized. Must be be in range 0-10000. "
1482 "Default is 72. N = 0 will disable rasterizing features like "
1483 "text shadows or perspective bitmaps.");
reed@google.com672588b2014-01-08 15:42:01 +00001484static SkData* encode_to_dct_data(size_t*, const SkBitmap& bitmap) {
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001485 // Filter output of warnings that JPEG is not available for the image.
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001486 if (bitmap.width() >= 65500 || bitmap.height() >= 65500) return NULL;
1487 if (FLAGS_pdfJpegQuality == -1) return NULL;
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001488
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001489 SkBitmap bm = bitmap;
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001490#if defined(SK_BUILD_FOR_MAC)
1491 // Workaround bug #1043 where bitmaps with referenced pixels cause
1492 // CGImageDestinationFinalize to crash
1493 SkBitmap copy;
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001494 bitmap.deepCopyTo(&copy, bitmap.config());
1495 bm = copy;
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001496#endif
1497
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001498 SkPixelRef* pr = bm.pixelRef();
1499 if (pr != NULL) {
1500 SkData* data = pr->refEncodedData();
1501 if (data != NULL) {
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001502 return data;
1503 }
1504 }
1505
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001506 return SkImageEncoder::EncodeData(bm,
1507 SkImageEncoder::kJPEG_Type,
1508 FLAGS_pdfJpegQuality);
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001509}
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001510
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001511static int findConfig(const char config[]) {
1512 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
1513 if (!strcmp(config, gRec[i].fName)) {
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001514 return (int) i;
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001515 }
1516 }
1517 return -1;
1518}
1519
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001520static const PDFRasterizerData* findPDFRasterizer(const char rasterizer[]) {
1521 for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); i++) {
1522 if (!strcmp(rasterizer, kPDFRasterizers[i].fName)) {
1523 return &kPDFRasterizers[i];
1524 }
1525 }
1526 return NULL;
1527}
1528
reed@google.comfb2cd422013-01-04 14:43:03 +00001529template <typename T> void appendUnique(SkTDArray<T>* array, const T& value) {
1530 int index = array->find(value);
1531 if (index < 0) {
1532 *array->append() = value;
1533 }
1534}
1535
epoger@google.com80724df2013-03-21 13:49:54 +00001536/**
epoger@google.com80724df2013-03-21 13:49:54 +00001537 * Run this test in a number of different drawing modes (pipe,
1538 * deferred, tiled, etc.), confirming that the resulting bitmaps all
1539 * *exactly* match comparisonBitmap.
1540 *
1541 * Returns all errors encountered while doing so.
1542 */
epoger@google.com6f6568b2013-03-22 17:29:46 +00001543ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm, const ConfigData &compareConfig,
1544 const SkBitmap &comparisonBitmap,
1545 const SkTDArray<SkScalar> &tileGridReplayScales);
1546ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm, const ConfigData &compareConfig,
1547 const SkBitmap &comparisonBitmap,
1548 const SkTDArray<SkScalar> &tileGridReplayScales) {
1549 ErrorCombination errorsForAllModes;
epoger@google.com80724df2013-03-21 13:49:54 +00001550 uint32_t gmFlags = gm->getFlags();
epoger@google.com659c8c02013-05-21 15:45:45 +00001551 const SkString shortNamePlusConfig = gmmain.make_shortname_plus_config(gm->shortName(),
1552 compareConfig.fName);
epoger@google.com80724df2013-03-21 13:49:54 +00001553
epoger@google.comc8263e72013-04-10 12:17:34 +00001554 SkPicture* pict = gmmain.generate_new_picture(gm, kNone_BbhType, 0);
1555 SkAutoUnref aur(pict);
1556 if (FLAGS_replay) {
1557 const char renderModeDescriptor[] = "-replay";
1558 if (gmFlags & GM::kSkipPicture_Flag) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001559 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
1560 renderModeDescriptor);
epoger@google.comc8263e72013-04-10 12:17:34 +00001561 errorsForAllModes.add(kIntentionallySkipped_ErrorType);
1562 } else {
epoger@google.com80724df2013-03-21 13:49:54 +00001563 SkBitmap bitmap;
1564 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap);
epoger@google.comc8263e72013-04-10 12:17:34 +00001565 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap(
epoger@google.com659c8c02013-05-21 15:45:45 +00001566 gm->shortName(), compareConfig.fName, renderModeDescriptor, bitmap,
1567 &comparisonBitmap));
epoger@google.com80724df2013-03-21 13:49:54 +00001568 }
epoger@google.comc8263e72013-04-10 12:17:34 +00001569 }
epoger@google.com80724df2013-03-21 13:49:54 +00001570
epoger@google.comc8263e72013-04-10 12:17:34 +00001571 if (FLAGS_serialize) {
1572 const char renderModeDescriptor[] = "-serialize";
1573 if (gmFlags & GM::kSkipPicture_Flag) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001574 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
1575 renderModeDescriptor);
epoger@google.comc8263e72013-04-10 12:17:34 +00001576 errorsForAllModes.add(kIntentionallySkipped_ErrorType);
1577 } else {
epoger@google.com80724df2013-03-21 13:49:54 +00001578 SkPicture* repict = gmmain.stream_to_new_picture(*pict);
1579 SkAutoUnref aurr(repict);
epoger@google.com80724df2013-03-21 13:49:54 +00001580 SkBitmap bitmap;
1581 gmmain.generate_image_from_picture(gm, compareConfig, repict, &bitmap);
epoger@google.comc8263e72013-04-10 12:17:34 +00001582 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap(
epoger@google.com659c8c02013-05-21 15:45:45 +00001583 gm->shortName(), compareConfig.fName, renderModeDescriptor, bitmap,
1584 &comparisonBitmap));
epoger@google.com80724df2013-03-21 13:49:54 +00001585 }
epoger@google.com80724df2013-03-21 13:49:54 +00001586 }
1587
epoger@google.comc8263e72013-04-10 12:17:34 +00001588 if ((1 == FLAGS_writePicturePath.count()) &&
1589 !(gmFlags & GM::kSkipPicture_Flag)) {
1590 const char* pictureSuffix = "skp";
epoger@google.com659c8c02013-05-21 15:45:45 +00001591 // TODO(epoger): Make sure this still works even though the
1592 // filename now contains the config name (it used to contain
1593 // just the shortName). I think this is actually an
1594 // *improvement*, because now runs with different configs will
1595 // write out their SkPictures to separate files rather than
1596 // overwriting each other. But we should make sure it doesn't
1597 // break anybody.
1598 SkString path = gmmain.make_filename(FLAGS_writePicturePath[0], gm->shortName(),
1599 compareConfig.fName, "", pictureSuffix);
epoger@google.comc8263e72013-04-10 12:17:34 +00001600 SkFILEWStream stream(path.c_str());
1601 pict->serialize(&stream);
epoger@google.com80724df2013-03-21 13:49:54 +00001602 }
1603
epoger@google.comc8263e72013-04-10 12:17:34 +00001604 if (FLAGS_rtree) {
1605 const char renderModeDescriptor[] = "-rtree";
1606 if (gmFlags & GM::kSkipPicture_Flag) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001607 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
1608 renderModeDescriptor);
epoger@google.comc8263e72013-04-10 12:17:34 +00001609 errorsForAllModes.add(kIntentionallySkipped_ErrorType);
1610 } else {
epoger@google.com80724df2013-03-21 13:49:54 +00001611 SkPicture* pict = gmmain.generate_new_picture(
commit-bot@chromium.orgaf94d9a2013-10-29 21:38:54 +00001612 gm, kRTree_BbhType, SkPicture::kOptimizeForClippedPlayback_RecordingFlag);
epoger@google.com80724df2013-03-21 13:49:54 +00001613 SkAutoUnref aur(pict);
1614 SkBitmap bitmap;
epoger@google.comc8263e72013-04-10 12:17:34 +00001615 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap);
epoger@google.com6f6568b2013-03-22 17:29:46 +00001616 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap(
epoger@google.com659c8c02013-05-21 15:45:45 +00001617 gm->shortName(), compareConfig.fName, renderModeDescriptor, bitmap,
1618 &comparisonBitmap));
epoger@google.comc8263e72013-04-10 12:17:34 +00001619 }
1620 }
1621
1622 if (FLAGS_tileGrid) {
1623 for(int scaleIndex = 0; scaleIndex < tileGridReplayScales.count(); ++scaleIndex) {
1624 SkScalar replayScale = tileGridReplayScales[scaleIndex];
1625 SkString renderModeDescriptor("-tilegrid");
1626 if (SK_Scalar1 != replayScale) {
1627 renderModeDescriptor += "-scale-";
1628 renderModeDescriptor.appendScalar(replayScale);
1629 }
1630
1631 if ((gmFlags & GM::kSkipPicture_Flag) ||
1632 ((gmFlags & GM::kSkipScaledReplay_Flag) && replayScale != 1)) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001633 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
epoger@google.comc8263e72013-04-10 12:17:34 +00001634 renderModeDescriptor.c_str());
1635 errorsForAllModes.add(kIntentionallySkipped_ErrorType);
1636 } else {
1637 // We record with the reciprocal scale to obtain a replay
1638 // result that can be validated against comparisonBitmap.
1639 SkScalar recordScale = SkScalarInvert(replayScale);
1640 SkPicture* pict = gmmain.generate_new_picture(
1641 gm, kTileGrid_BbhType, SkPicture::kUsePathBoundsForClip_RecordingFlag,
1642 recordScale);
1643 SkAutoUnref aur(pict);
1644 SkBitmap bitmap;
1645 // We cannot yet pass 'true' to generate_image_from_picture to
1646 // perform actual tiled rendering (see Issue 1198 -
1647 // https://code.google.com/p/skia/issues/detail?id=1198)
1648 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap,
1649 replayScale /*, true */);
1650 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap(
epoger@google.com659c8c02013-05-21 15:45:45 +00001651 gm->shortName(), compareConfig.fName, renderModeDescriptor.c_str(), bitmap,
1652 &comparisonBitmap));
epoger@google.comc8263e72013-04-10 12:17:34 +00001653 }
epoger@google.com80724df2013-03-21 13:49:54 +00001654 }
1655 }
1656
1657 // run the pipe centric GM steps
epoger@google.comc8263e72013-04-10 12:17:34 +00001658 if (FLAGS_pipe) {
1659 errorsForAllModes.add(gmmain.test_pipe_playback(gm, compareConfig, comparisonBitmap,
1660 FLAGS_simulatePipePlaybackFailure));
1661 if (FLAGS_tiledPipe) {
1662 errorsForAllModes.add(gmmain.test_tiled_pipe_playback(gm, compareConfig,
1663 comparisonBitmap));
epoger@google.com80724df2013-03-21 13:49:54 +00001664 }
epoger@google.com80724df2013-03-21 13:49:54 +00001665 }
1666 return errorsForAllModes;
1667}
1668
commit-bot@chromium.org85195482014-01-13 18:27:59 +00001669
1670/**
1671 * Run this test in a number of different configs (8888, 565, PDF,
1672 * etc.), confirming that the resulting bitmaps match expectations
1673 * (which may be different for each config).
1674 *
1675 * Returns all errors encountered while doing so.
1676 */
1677ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm,
1678 const SkTDArray<size_t> &configs,
1679 const SkTDArray<const PDFRasterizerData*> &pdfRasterizers,
1680 const SkTDArray<SkScalar> &tileGridReplayScales,
1681 GrContextFactory *grFactory);
1682ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm,
1683 const SkTDArray<size_t> &configs,
1684 const SkTDArray<const PDFRasterizerData*> &pdfRasterizers,
1685 const SkTDArray<SkScalar> &tileGridReplayScales,
1686 GrContextFactory *grFactory) {
1687 const char renderModeDescriptor[] = "";
1688 ErrorCombination errorsForAllConfigs;
1689 uint32_t gmFlags = gm->getFlags();
1690
1691 for (int i = 0; i < configs.count(); i++) {
1692 ConfigData config = gRec[configs[i]];
1693 const SkString shortNamePlusConfig = gmmain.make_shortname_plus_config(gm->shortName(),
1694 config.fName);
1695
1696 // Skip any tests that we don't even need to try.
1697 // If any of these were skipped on a per-GM basis, record them as
1698 // kIntentionallySkipped.
1699 if (kPDF_Backend == config.fBackend) {
1700 if (gmFlags & GM::kSkipPDF_Flag) {
1701 gmmain.RecordSkippedTest(shortNamePlusConfig,
1702 renderModeDescriptor,
1703 config.fBackend);
1704 errorsForAllConfigs.add(kIntentionallySkipped_ErrorType);
1705 continue;
1706 }
1707 }
1708 if ((gmFlags & GM::kSkip565_Flag) &&
1709 (kRaster_Backend == config.fBackend) &&
1710 (SkBitmap::kRGB_565_Config == config.fConfig)) {
1711 gmmain.RecordSkippedTest(shortNamePlusConfig,
1712 renderModeDescriptor,
1713 config.fBackend);
1714 errorsForAllConfigs.add(kIntentionallySkipped_ErrorType);
1715 continue;
1716 }
1717 if (((gmFlags & GM::kSkipGPU_Flag) && kGPU_Backend == config.fBackend) ||
1718 ((gmFlags & GM::kGPUOnly_Flag) && kGPU_Backend != config.fBackend)) {
1719 gmmain.RecordSkippedTest(shortNamePlusConfig,
1720 renderModeDescriptor,
1721 config.fBackend);
1722 errorsForAllConfigs.add(kIntentionallySkipped_ErrorType);
1723 continue;
1724 }
1725
1726 // Now we know that we want to run this test and record its
1727 // success or failure.
1728 ErrorCombination errorsForThisConfig;
1729 GrSurface* gpuTarget = NULL;
1730#if SK_SUPPORT_GPU
1731 SkAutoTUnref<GrSurface> auGpuTarget;
1732 if ((errorsForThisConfig.isEmpty()) && (kGPU_Backend == config.fBackend)) {
1733 if (FLAGS_resetGpuContext) {
1734 grFactory->destroyContexts();
1735 }
1736 GrContext* gr = grFactory->get(config.fGLContextType);
1737 bool grSuccess = false;
1738 if (gr) {
1739 // create a render target to back the device
1740 GrTextureDesc desc;
1741 desc.fConfig = kSkia8888_GrPixelConfig;
1742 desc.fFlags = kRenderTarget_GrTextureFlagBit;
1743 desc.fWidth = gm->getISize().width();
1744 desc.fHeight = gm->getISize().height();
1745 desc.fSampleCnt = config.fSampleCnt;
1746 auGpuTarget.reset(gr->createUncachedTexture(desc, NULL, 0));
1747 if (NULL != auGpuTarget) {
1748 gpuTarget = auGpuTarget;
1749 grSuccess = true;
1750 // Set the user specified cache limits if non-default.
1751 size_t bytes;
1752 int count;
1753 gr->getTextureCacheLimits(&count, &bytes);
1754 if (DEFAULT_CACHE_VALUE != gGpuCacheSizeBytes) {
1755 bytes = static_cast<size_t>(gGpuCacheSizeBytes);
1756 }
1757 if (DEFAULT_CACHE_VALUE != gGpuCacheSizeCount) {
1758 count = gGpuCacheSizeCount;
1759 }
1760 gr->setTextureCacheLimits(count, bytes);
1761 }
1762 }
1763 if (!grSuccess) {
1764 errorsForThisConfig.add(kNoGpuContext_ErrorType);
1765 }
1766 }
1767#endif
1768
1769 SkBitmap comparisonBitmap;
1770
1771 const char* writePath;
1772 if (FLAGS_writePath.count() == 1) {
1773 writePath = FLAGS_writePath[0];
1774 } else {
1775 writePath = NULL;
1776 }
1777
1778 if (errorsForThisConfig.isEmpty()) {
1779 errorsForThisConfig.add(gmmain.test_drawing(gm, config, pdfRasterizers,
1780 writePath, gpuTarget,
1781 &comparisonBitmap));
1782 gmmain.RecordTestResults(errorsForThisConfig, shortNamePlusConfig, "");
1783 }
1784
1785 // TODO: run only if gmmain.test_drawing succeeded.
1786 if (kRaster_Backend == config.fBackend) {
1787 run_multiple_modes(gmmain, gm, config, comparisonBitmap, tileGridReplayScales);
1788 }
1789
1790 if (FLAGS_deferred && errorsForThisConfig.isEmpty() &&
1791 (kGPU_Backend == config.fBackend || kRaster_Backend == config.fBackend)) {
1792 errorsForThisConfig.add(gmmain.test_deferred_drawing(gm, config, comparisonBitmap,
1793 gpuTarget));
1794 }
1795
1796 errorsForAllConfigs.add(errorsForThisConfig);
1797 }
1798 return errorsForAllConfigs;
1799}
1800
1801
epoger@google.com310478e2013-04-03 18:00:39 +00001802/**
epoger@google.comf711f322013-10-18 14:55:47 +00001803 * Read individual lines from a file, pushing them into the given array.
1804 *
1805 * @param filename path to the file to read
1806 * @param lines array of strings to add the lines to
1807 * @returns true if able to read lines from the file
1808 */
1809static bool read_lines_from_file(const char* filename, SkTArray<SkString> &lines) {
1810 SkAutoTUnref<SkStream> streamWrapper(SkStream::NewFromFile(filename));
1811 SkStream *stream = streamWrapper.get();
1812 if (!stream) {
1813 gm_fprintf(stderr, "unable to read file '%s'\n", filename);
1814 return false;
1815 }
1816
1817 char c;
1818 SkString line;
1819 while (1 == stream->read(&c, 1)) {
1820 // If we hit either CR or LF, we've completed a line.
1821 //
1822 // TODO: If the file uses both CR and LF, this will return an extra blank
1823 // line for each line of the file. Which is OK for current purposes...
1824 //
1825 // TODO: Does this properly handle unicode? It doesn't matter for
1826 // current purposes...
1827 if ((c == 0x0d) || (c == 0x0a)) {
1828 lines.push_back(line);
1829 line.reset();
1830 } else {
1831 line.append(&c, 1);
1832 }
1833 }
1834 lines.push_back(line);
1835 return true;
1836}
1837
1838/**
epoger@google.com310478e2013-04-03 18:00:39 +00001839 * Return a list of all entries in an array of strings as a single string
1840 * of this form:
1841 * "item1", "item2", "item3"
1842 */
1843SkString list_all(const SkTArray<SkString> &stringArray);
1844SkString list_all(const SkTArray<SkString> &stringArray) {
1845 SkString total;
1846 for (int i = 0; i < stringArray.count(); i++) {
1847 if (i > 0) {
1848 total.append(", ");
1849 }
1850 total.append("\"");
1851 total.append(stringArray[i]);
1852 total.append("\"");
1853 }
1854 return total;
1855}
1856
1857/**
1858 * Return a list of configuration names, as a single string of this form:
1859 * "item1", "item2", "item3"
1860 *
1861 * @param configs configurations, as a list of indices into gRec
1862 */
1863SkString list_all_config_names(const SkTDArray<size_t> &configs);
1864SkString list_all_config_names(const SkTDArray<size_t> &configs) {
1865 SkString total;
1866 for (int i = 0; i < configs.count(); i++) {
1867 if (i > 0) {
1868 total.append(", ");
1869 }
1870 total.append("\"");
1871 total.append(gRec[configs[i]].fName);
1872 total.append("\"");
1873 }
1874 return total;
1875}
1876
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001877static bool prepare_subdirectories(const char *root, bool useFileHierarchy,
1878 const SkTDArray<size_t> &configs,
1879 const SkTDArray<const PDFRasterizerData*>& pdfRasterizers) {
epoger@google.comfdea3252013-05-02 18:24:03 +00001880 if (!sk_mkdir(root)) {
1881 return false;
1882 }
1883 if (useFileHierarchy) {
1884 for (int i = 0; i < configs.count(); i++) {
1885 ConfigData config = gRec[configs[i]];
1886 SkString subdir;
1887 subdir.appendf("%s%c%s", root, SkPATH_SEPARATOR, config.fName);
1888 if (!sk_mkdir(subdir.c_str())) {
1889 return false;
1890 }
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001891
1892 if (config.fBackend == kPDF_Backend) {
1893 for (int j = 0; j < pdfRasterizers.count(); j++) {
1894 SkString pdfSubdir = subdir;
vandebo@chromium.org8fc37662013-08-21 18:04:09 +00001895 pdfSubdir.appendf("-%s", pdfRasterizers[j]->fName);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001896 if (!sk_mkdir(pdfSubdir.c_str())) {
1897 return false;
1898 }
1899 }
1900 }
epoger@google.comfdea3252013-05-02 18:24:03 +00001901 }
1902 }
1903 return true;
1904}
1905
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00001906static bool parse_flags_configs(SkTDArray<size_t>* outConfigs,
1907 GrContextFactory* grFactory) {
1908 SkTDArray<size_t> excludeConfigs;
1909
1910 for (int i = 0; i < FLAGS_config.count(); i++) {
1911 const char* config = FLAGS_config[i];
1912 bool exclude = false;
1913 if (*config == kExcludeConfigChar) {
1914 exclude = true;
1915 config += 1;
1916 }
1917 int index = findConfig(config);
1918 if (index >= 0) {
1919 if (exclude) {
1920 *excludeConfigs.append() = index;
1921 } else {
1922 appendUnique<size_t>(outConfigs, index);
1923 }
1924 } else if (0 == strcmp(kDefaultsConfigStr, config)) {
1925 if (exclude) {
1926 gm_fprintf(stderr, "%c%s is not allowed.\n",
1927 kExcludeConfigChar, kDefaultsConfigStr);
1928 return false;
1929 }
1930 for (size_t c = 0; c < SK_ARRAY_COUNT(gRec); ++c) {
1931 if (gRec[c].fRunByDefault) {
1932 appendUnique<size_t>(outConfigs, c);
1933 }
1934 }
1935 } else {
1936 gm_fprintf(stderr, "unrecognized config %s\n", config);
1937 return false;
1938 }
1939 }
1940
1941 for (int i = 0; i < FLAGS_excludeConfig.count(); i++) {
1942 int index = findConfig(FLAGS_excludeConfig[i]);
1943 if (index >= 0) {
1944 *excludeConfigs.append() = index;
1945 } else {
1946 gm_fprintf(stderr, "unrecognized excludeConfig %s\n", FLAGS_excludeConfig[i]);
1947 return false;
1948 }
1949 }
1950
1951 if (outConfigs->count() == 0) {
1952 // if no config is specified by user, add the defaults
1953 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
1954 if (gRec[i].fRunByDefault) {
1955 *outConfigs->append() = i;
1956 }
1957 }
1958 }
1959 // now remove any explicitly excluded configs
1960 for (int i = 0; i < excludeConfigs.count(); ++i) {
1961 int index = outConfigs->find(excludeConfigs[i]);
1962 if (index >= 0) {
1963 outConfigs->remove(index);
1964 // now assert that there was only one copy in configs[]
1965 SkASSERT(outConfigs->find(excludeConfigs[i]) < 0);
1966 }
1967 }
1968
1969#if SK_SUPPORT_GPU
1970 SkASSERT(grFactory != NULL);
1971 for (int i = 0; i < outConfigs->count(); ++i) {
1972 size_t index = (*outConfigs)[i];
1973 if (kGPU_Backend == gRec[index].fBackend) {
1974 GrContext* ctx = grFactory->get(gRec[index].fGLContextType);
1975 if (NULL == ctx) {
1976 gm_fprintf(stderr, "GrContext could not be created for config %s."
1977 " Config will be skipped.\n", gRec[index].fName);
1978 outConfigs->remove(i);
1979 --i;
1980 continue;
1981 }
1982 if (gRec[index].fSampleCnt > ctx->getMaxSampleCount()) {
1983 gm_fprintf(stderr, "Sample count (%d) of config %s is not supported."
1984 " Config will be skipped.\n",
1985 gRec[index].fSampleCnt, gRec[index].fName);
1986 outConfigs->remove(i);
1987 --i;
1988 }
1989 }
1990 }
1991#endif
1992
1993 if (outConfigs->isEmpty()) {
1994 gm_fprintf(stderr, "No configs to run.");
1995 return false;
1996 }
1997
1998 // now show the user the set of configs that will be run.
1999 SkString configStr("These configs will be run:");
2000 // show the user the config that will run.
2001 for (int i = 0; i < outConfigs->count(); ++i) {
2002 configStr.appendf(" %s", gRec[(*outConfigs)[i]].fName);
2003 }
2004 gm_fprintf(stdout, "%s\n", configStr.c_str());
2005
2006 return true;
2007}
2008
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002009static bool parse_flags_pdf_rasterizers(const SkTDArray<size_t>& configs,
2010 SkTDArray<const PDFRasterizerData*>* outRasterizers) {
2011 // No need to run this check (and display the PDF rasterizers message)
2012 // if no PDF backends are in the configs.
2013 bool configHasPDF = false;
2014 for (int i = 0; i < configs.count(); i++) {
2015 if (gRec[configs[i]].fBackend == kPDF_Backend) {
2016 configHasPDF = true;
2017 break;
2018 }
2019 }
2020 if (!configHasPDF) {
2021 return true;
2022 }
2023
vandebo@chromium.orgf8afb2b2013-11-06 16:32:15 +00002024 if (FLAGS_pdfRasterizers.count() == 1 &&
2025 !strcmp(FLAGS_pdfRasterizers[0], "default")) {
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002026 for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); ++i) {
2027 if (kPDFRasterizers[i].fRunByDefault) {
2028 *outRasterizers->append() = &kPDFRasterizers[i];
2029 }
2030 }
vandebo@chromium.orgf8afb2b2013-11-06 16:32:15 +00002031 } else {
2032 for (int i = 0; i < FLAGS_pdfRasterizers.count(); i++) {
2033 const char* rasterizer = FLAGS_pdfRasterizers[i];
2034 const PDFRasterizerData* rasterizerPtr =
2035 findPDFRasterizer(rasterizer);
2036 if (rasterizerPtr == NULL) {
2037 gm_fprintf(stderr, "unrecognized rasterizer %s\n", rasterizer);
2038 return false;
2039 }
2040 appendUnique<const PDFRasterizerData*>(outRasterizers,
2041 rasterizerPtr);
2042 }
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002043 }
2044
2045 // now show the user the set of configs that will be run.
2046 SkString configStr("These PDF rasterizers will be run:");
2047 // show the user the config that will run.
2048 for (int i = 0; i < outRasterizers->count(); ++i) {
2049 configStr.appendf(" %s", (*outRasterizers)[i]->fName);
2050 }
2051 gm_fprintf(stdout, "%s\n", configStr.c_str());
2052
2053 return true;
2054}
2055
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002056static bool parse_flags_ignore_error_types(ErrorCombination* outErrorTypes) {
2057 if (FLAGS_ignoreErrorTypes.count() > 0) {
2058 *outErrorTypes = ErrorCombination();
2059 for (int i = 0; i < FLAGS_ignoreErrorTypes.count(); i++) {
2060 ErrorType type;
2061 const char *name = FLAGS_ignoreErrorTypes[i];
2062 if (!getErrorTypeByName(name, &type)) {
2063 gm_fprintf(stderr, "cannot find ErrorType with name '%s'\n", name);
2064 return false;
2065 } else {
2066 outErrorTypes->add(type);
2067 }
2068 }
2069 }
2070 return true;
2071}
2072
epoger@google.com3a882dd2013-10-07 18:55:09 +00002073/**
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +00002074 * Replace contents of ignoreTestNames with a list of test names, indicating
epoger@google.com3a882dd2013-10-07 18:55:09 +00002075 * which tests' failures should be ignored.
2076 */
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +00002077static bool parse_flags_ignore_tests(SkTArray<SkString> &ignoreTestNames) {
2078 ignoreTestNames.reset();
epoger@google.comf711f322013-10-18 14:55:47 +00002079
epoger@google.comf711f322013-10-18 14:55:47 +00002080 // Parse --ignoreFailuresFile
2081 for (int i = 0; i < FLAGS_ignoreFailuresFile.count(); i++) {
2082 SkTArray<SkString> linesFromFile;
2083 if (!read_lines_from_file(FLAGS_ignoreFailuresFile[i], linesFromFile)) {
2084 return false;
2085 } else {
2086 for (int j = 0; j < linesFromFile.count(); j++) {
2087 SkString thisLine = linesFromFile[j];
2088 if (thisLine.isEmpty() || thisLine.startsWith('#')) {
2089 // skip this line
2090 } else {
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +00002091 ignoreTestNames.push_back(thisLine);
epoger@google.comf711f322013-10-18 14:55:47 +00002092 }
2093 }
2094 }
2095 }
2096
epoger@google.com3a882dd2013-10-07 18:55:09 +00002097 return true;
2098}
2099
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002100static bool parse_flags_modulo(int* moduloRemainder, int* moduloDivisor) {
2101 if (FLAGS_modulo.count() == 2) {
2102 *moduloRemainder = atoi(FLAGS_modulo[0]);
2103 *moduloDivisor = atoi(FLAGS_modulo[1]);
2104 if (*moduloRemainder < 0 || *moduloDivisor <= 0 ||
2105 *moduloRemainder >= *moduloDivisor) {
2106 gm_fprintf(stderr, "invalid modulo values.");
2107 return false;
2108 }
2109 }
2110 return true;
2111}
2112
2113#if SK_SUPPORT_GPU
2114static bool parse_flags_gpu_cache(int* sizeBytes, int* sizeCount) {
2115 if (FLAGS_gpuCacheSize.count() > 0) {
2116 if (FLAGS_gpuCacheSize.count() != 2) {
2117 gm_fprintf(stderr, "--gpuCacheSize requires two arguments\n");
2118 return false;
2119 }
2120 *sizeBytes = atoi(FLAGS_gpuCacheSize[0]);
2121 *sizeCount = atoi(FLAGS_gpuCacheSize[1]);
2122 } else {
2123 *sizeBytes = DEFAULT_CACHE_VALUE;
2124 *sizeCount = DEFAULT_CACHE_VALUE;
2125 }
2126 return true;
2127}
2128#endif
2129
2130static bool parse_flags_tile_grid_replay_scales(SkTDArray<SkScalar>* outScales) {
2131 *outScales->append() = SK_Scalar1; // By default only test at scale 1.0
2132 if (FLAGS_tileGridReplayScales.count() > 0) {
2133 outScales->reset();
2134 for (int i = 0; i < FLAGS_tileGridReplayScales.count(); i++) {
2135 double val = atof(FLAGS_tileGridReplayScales[i]);
2136 if (0 < val) {
2137 *outScales->append() = SkDoubleToScalar(val);
2138 }
2139 }
2140 if (0 == outScales->count()) {
2141 // Should have at least one scale
2142 gm_fprintf(stderr, "--tileGridReplayScales requires at least one scale.\n");
2143 return false;
2144 }
2145 }
2146 return true;
2147}
2148
2149static bool parse_flags_gmmain_paths(GMMain* gmmain) {
2150 gmmain->fUseFileHierarchy = FLAGS_hierarchy;
2151 gmmain->fWriteChecksumBasedFilenames = FLAGS_writeChecksumBasedFilenames;
2152
2153 if (FLAGS_mismatchPath.count() == 1) {
2154 gmmain->fMismatchPath = FLAGS_mismatchPath[0];
2155 }
2156
2157 if (FLAGS_missingExpectationsPath.count() == 1) {
2158 gmmain->fMissingExpectationsPath = FLAGS_missingExpectationsPath[0];
2159 }
2160
2161 if (FLAGS_readPath.count() == 1) {
2162 const char* readPath = FLAGS_readPath[0];
2163 if (!sk_exists(readPath)) {
2164 gm_fprintf(stderr, "readPath %s does not exist!\n", readPath);
2165 return false;
2166 }
2167 if (sk_isdir(readPath)) {
2168 if (FLAGS_verbose) {
2169 gm_fprintf(stdout, "reading from %s\n", readPath);
2170 }
2171 gmmain->fExpectationsSource.reset(SkNEW_ARGS(
2172 IndividualImageExpectationsSource, (readPath)));
2173 } else {
2174 if (FLAGS_verbose) {
2175 gm_fprintf(stdout, "reading expectations from JSON summary file %s\n", readPath);
2176 }
2177 gmmain->fExpectationsSource.reset(SkNEW_ARGS(JsonExpectationsSource, (readPath)));
2178 }
2179 }
2180 return true;
2181}
2182
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002183static bool parse_flags_resource_path() {
2184 if (FLAGS_resourcePath.count() == 1) {
2185 GM::SetResourcePath(FLAGS_resourcePath[0]);
2186 }
2187 return true;
2188}
2189
2190static bool parse_flags_jpeg_quality() {
2191 if (FLAGS_pdfJpegQuality < -1 || FLAGS_pdfJpegQuality > 100) {
2192 gm_fprintf(stderr, "%s\n", "pdfJpegQuality must be in [-1 .. 100] range.");
2193 return false;
2194 }
2195 return true;
2196}
2197
epoger@google.com0b62b3d2013-03-20 17:59:28 +00002198int tool_main(int argc, char** argv);
2199int tool_main(int argc, char** argv) {
2200
commit-bot@chromium.org6dda8272014-01-23 17:21:19 +00002201 SkString usage;
2202 usage.printf("Run the golden master tests.\n");
2203 SkCommandLineFlags::SetUsage(usage.c_str());
2204 SkCommandLineFlags::Parse(argc, argv);
2205
epoger@google.com0b62b3d2013-03-20 17:59:28 +00002206#if SK_ENABLE_INST_COUNT
commit-bot@chromium.org6dda8272014-01-23 17:21:19 +00002207 if (FLAGS_leaks) {
2208 gPrintInstCount = true;
2209 }
epoger@google.com0b62b3d2013-03-20 17:59:28 +00002210#endif
2211
2212 SkGraphics::Init();
2213 // we don't need to see this during a run
2214 gSkSuppressFontCachePurgeSpew = true;
2215
2216 setSystemPreferences();
2217 GMMain gmmain;
2218
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002219 SkTDArray<size_t> configs;
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002220
scroggo@google.com09fd4d22013-03-20 14:20:18 +00002221 int moduloRemainder = -1;
2222 int moduloDivisor = -1;
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002223 SkTDArray<const PDFRasterizerData*> pdfRasterizers;
epoger@google.com6f6568b2013-03-22 17:29:46 +00002224 SkTDArray<SkScalar> tileGridReplayScales;
bsalomon@google.com4c75f242013-03-19 18:58:43 +00002225#if SK_SUPPORT_GPU
2226 GrContextFactory* grFactory = new GrContextFactory;
epoger@google.com80724df2013-03-21 13:49:54 +00002227#else
2228 GrContextFactory* grFactory = NULL;
bsalomon@google.com4c75f242013-03-19 18:58:43 +00002229#endif
2230
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002231 if (!parse_flags_modulo(&moduloRemainder, &moduloDivisor) ||
2232 !parse_flags_ignore_error_types(&gmmain.fIgnorableErrorTypes) ||
commit-bot@chromium.org3e62ebf2014-01-14 02:54:11 +00002233 !parse_flags_ignore_tests(gmmain.fIgnorableTestNames) ||
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002234#if SK_SUPPORT_GPU
2235 !parse_flags_gpu_cache(&gGpuCacheSizeBytes, &gGpuCacheSizeCount) ||
2236#endif
2237 !parse_flags_tile_grid_replay_scales(&tileGridReplayScales) ||
2238 !parse_flags_resource_path() ||
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002239 !parse_flags_jpeg_quality() ||
2240 !parse_flags_configs(&configs, grFactory) ||
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002241 !parse_flags_pdf_rasterizers(configs, &pdfRasterizers) ||
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002242 !parse_flags_gmmain_paths(&gmmain)) {
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00002243 return -1;
2244 }
2245
epoger@google.comb0f8b432013-04-10 18:46:25 +00002246 if (FLAGS_verbose) {
2247 if (FLAGS_writePath.count() == 1) {
2248 gm_fprintf(stdout, "writing to %s\n", FLAGS_writePath[0]);
2249 }
epoger@google.comfdea3252013-05-02 18:24:03 +00002250 if (NULL != gmmain.fMismatchPath) {
2251 gm_fprintf(stdout, "writing mismatches to %s\n", gmmain.fMismatchPath);
2252 }
epoger@google.com5f995452013-06-21 18:16:47 +00002253 if (NULL != gmmain.fMissingExpectationsPath) {
2254 gm_fprintf(stdout, "writing images without expectations to %s\n",
2255 gmmain.fMissingExpectationsPath);
2256 }
epoger@google.comb0f8b432013-04-10 18:46:25 +00002257 if (FLAGS_writePicturePath.count() == 1) {
2258 gm_fprintf(stdout, "writing pictures to %s\n", FLAGS_writePicturePath[0]);
2259 }
2260 if (FLAGS_resourcePath.count() == 1) {
2261 gm_fprintf(stdout, "reading resources from %s\n", FLAGS_resourcePath[0]);
2262 }
robertphillips@google.com8570b5c2012-03-20 17:40:58 +00002263 }
2264
epoger@google.com310478e2013-04-03 18:00:39 +00002265 int gmsRun = 0;
reed@google.comae7b8f32012-10-18 21:30:57 +00002266 int gmIndex = -1;
2267 SkString moduloStr;
2268
epoger@google.come8ebeb12012-10-29 16:42:11 +00002269 // If we will be writing out files, prepare subdirectories.
scroggo@google.com09fd4d22013-03-20 14:20:18 +00002270 if (FLAGS_writePath.count() == 1) {
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002271 if (!prepare_subdirectories(FLAGS_writePath[0], gmmain.fUseFileHierarchy,
2272 configs, pdfRasterizers)) {
epoger@google.come8ebeb12012-10-29 16:42:11 +00002273 return -1;
2274 }
epoger@google.comfdea3252013-05-02 18:24:03 +00002275 }
2276 if (NULL != gmmain.fMismatchPath) {
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002277 if (!prepare_subdirectories(gmmain.fMismatchPath, gmmain.fUseFileHierarchy,
2278 configs, pdfRasterizers)) {
epoger@google.comfdea3252013-05-02 18:24:03 +00002279 return -1;
epoger@google.come8ebeb12012-10-29 16:42:11 +00002280 }
2281 }
epoger@google.com5f995452013-06-21 18:16:47 +00002282 if (NULL != gmmain.fMissingExpectationsPath) {
2283 if (!prepare_subdirectories(gmmain.fMissingExpectationsPath, gmmain.fUseFileHierarchy,
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002284 configs, pdfRasterizers)) {
epoger@google.com5f995452013-06-21 18:16:47 +00002285 return -1;
2286 }
2287 }
epoger@google.come8ebeb12012-10-29 16:42:11 +00002288
bsalomon@google.com7361f542012-04-19 19:15:35 +00002289 Iter iter;
2290 GM* gm;
reed@android.com00dae862009-06-10 15:38:48 +00002291 while ((gm = iter.next()) != NULL) {
commit-bot@chromium.orgf4f9df42013-09-26 20:44:24 +00002292 if (FLAGS_forcePerspectiveMatrix) {
2293 SkMatrix perspective;
2294 perspective.setIdentity();
2295 perspective.setPerspY(SkScalarDiv(SK_Scalar1, SkIntToScalar(1000)));
2296 perspective.setSkewX(SkScalarDiv(SkIntToScalar(8),
2297 SkIntToScalar(25)));
2298
2299 gm->setStarterMatrix(perspective);
skia.committer@gmail.com65caeaf2013-09-27 07:01:29 +00002300 }
scroggo@google.com7fd2d702013-04-16 19:11:14 +00002301 SkAutoTDelete<GM> adgm(gm);
reed@google.comae7b8f32012-10-18 21:30:57 +00002302 ++gmIndex;
epoger@google.com82cb65b2012-10-29 18:59:17 +00002303 if (moduloRemainder >= 0) {
2304 if ((gmIndex % moduloDivisor) != moduloRemainder) {
reed@google.comae7b8f32012-10-18 21:30:57 +00002305 continue;
2306 }
epoger@google.com82cb65b2012-10-29 18:59:17 +00002307 moduloStr.printf("[%d.%d] ", gmIndex, moduloDivisor);
reed@google.comae7b8f32012-10-18 21:30:57 +00002308 }
2309
reed@google.comece2b022011-07-25 14:28:57 +00002310 const char* shortName = gm->shortName();
sglez@google.com586db932013-07-24 17:24:23 +00002311
commit-bot@chromium.orga6f37e72013-08-30 15:52:46 +00002312 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, shortName)) {
reed@google.comece2b022011-07-25 14:28:57 +00002313 continue;
2314 }
2315
epoger@google.com310478e2013-04-03 18:00:39 +00002316 gmsRun++;
tomhudson@google.com9875dd12011-04-25 15:49:53 +00002317 SkISize size = gm->getISize();
epoger@google.combcbf5aa2013-04-12 02:11:54 +00002318 gm_fprintf(stdout, "%sdrawing... %s [%d %d]\n", moduloStr.c_str(), shortName,
2319 size.width(), size.height());
djsollen@google.comebce16d2012-10-26 14:07:13 +00002320
commit-bot@chromium.org85195482014-01-13 18:27:59 +00002321 run_multiple_configs(gmmain, gm, configs, pdfRasterizers, tileGridReplayScales, grFactory);
reed@android.com00dae862009-06-10 15:38:48 +00002322 }
epoger@google.com310478e2013-04-03 18:00:39 +00002323
2324 SkTArray<SkString> modes;
2325 gmmain.GetRenderModesEncountered(modes);
commit-bot@chromium.org85195482014-01-13 18:27:59 +00002326 int modeCount = modes.count();
2327
2328 // Now that we have run all the tests and thus know the full set of renderModes that we
2329 // tried to run, we can call RecordTestResults() to record the cases in which we skipped
2330 // ALL renderModes.
2331 // See http://skbug.com/1994 and https://codereview.chromium.org/129203002/
2332 int testCount = gmmain.fTestsSkippedOnAllRenderModes.count();
2333 for (int testNum = 0; testNum < testCount; ++testNum) {
2334 const SkString &shortNamePlusConfig = gmmain.fTestsSkippedOnAllRenderModes[testNum];
2335 for (int modeNum = 0; modeNum < modeCount; ++modeNum) {
2336 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
2337 modes[modeNum].c_str());
2338 }
2339 }
2340
epoger@google.comc8263e72013-04-10 12:17:34 +00002341 bool reportError = false;
2342 if (gmmain.NumSignificantErrors() > 0) {
2343 reportError = true;
2344 }
commit-bot@chromium.org85195482014-01-13 18:27:59 +00002345
2346 // We test every GM against every config, and for every raster config also test every mode.
2347 int rasterConfigs = 0;
2348 for (int i = 0; i < configs.count(); i++) {
2349 if (gRec[configs[i]].fBackend == kRaster_Backend) {
2350 rasterConfigs++;
2351 }
2352 }
2353 // For raster configs, we run all renderModes; for non-raster configs, just default renderMode
2354 const int expectedNumberOfTests = rasterConfigs * gmsRun * modeCount
2355 + (configs.count() - rasterConfigs) * gmsRun;
epoger@google.com310478e2013-04-03 18:00:39 +00002356
2357 // Output summary to stdout.
epoger@google.com51dbabe2013-04-10 15:24:53 +00002358 if (FLAGS_verbose) {
2359 gm_fprintf(stdout, "Ran %d GMs\n", gmsRun);
2360 gm_fprintf(stdout, "... over %2d configs [%s]\n", configs.count(),
2361 list_all_config_names(configs).c_str());
commit-bot@chromium.org85195482014-01-13 18:27:59 +00002362 gm_fprintf(stdout, "... and %2d modes [%s]\n", modeCount, list_all(modes).c_str());
epoger@google.com51dbabe2013-04-10 15:24:53 +00002363 gm_fprintf(stdout, "... so there should be a total of %d tests.\n", expectedNumberOfTests);
2364 }
2365 gmmain.ListErrors(FLAGS_verbose);
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00002366
epoger@google.com07947d92013-04-11 15:41:02 +00002367 // TODO(epoger): Enable this check for Android, too, once we resolve
2368 // https://code.google.com/p/skia/issues/detail?id=1222
2369 // ('GM is unexpectedly skipping tests on Android')
2370#ifndef SK_BUILD_FOR_ANDROID
epoger@google.comc8263e72013-04-10 12:17:34 +00002371 if (expectedNumberOfTests != gmmain.fTestsRun) {
2372 gm_fprintf(stderr, "expected %d tests, but ran or skipped %d tests\n",
2373 expectedNumberOfTests, gmmain.fTestsRun);
2374 reportError = true;
2375 }
2376#endif
2377
scroggo@google.com09fd4d22013-03-20 14:20:18 +00002378 if (FLAGS_writeJsonSummaryPath.count() == 1) {
epoger@google.com76c913d2013-04-26 15:06:44 +00002379 Json::Value root = CreateJsonTree(
2380 gmmain.fJsonExpectedResults,
2381 gmmain.fJsonActualResults_Failed, gmmain.fJsonActualResults_FailureIgnored,
2382 gmmain.fJsonActualResults_NoComparison, gmmain.fJsonActualResults_Succeeded);
epoger@google.comee8a8e32012-12-18 19:13:49 +00002383 std::string jsonStdString = root.toStyledString();
scroggo@google.com09fd4d22013-03-20 14:20:18 +00002384 SkFILEWStream stream(FLAGS_writeJsonSummaryPath[0]);
epoger@google.comee8a8e32012-12-18 19:13:49 +00002385 stream.write(jsonStdString.c_str(), jsonStdString.length());
2386 }
2387
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00002388#if SK_SUPPORT_GPU
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00002389
robertphillips@google.com59552022012-08-31 13:07:37 +00002390#if GR_CACHE_STATS
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00002391 for (int i = 0; i < configs.count(); i++) {
2392 ConfigData config = gRec[configs[i]];
2393
epoger@google.comb0f8b432013-04-10 18:46:25 +00002394 if (FLAGS_verbose && (kGPU_Backend == config.fBackend)) {
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00002395 GrContext* gr = grFactory->get(config.fGLContextType);
2396
epoger@google.com5efdd0c2013-03-13 14:18:40 +00002397 gm_fprintf(stdout, "config: %s %x\n", config.fName, gr);
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00002398 gr->printCacheStats();
2399 }
2400 }
2401#endif
2402
robertphillips@google.com977b9c82012-06-05 19:35:09 +00002403 delete grFactory;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00002404#endif
robertphillips@google.com977b9c82012-06-05 19:35:09 +00002405 SkGraphics::Term();
2406
epoger@google.comc8263e72013-04-10 12:17:34 +00002407 return (reportError) ? -1 : 0;
reed@android.com00dae862009-06-10 15:38:48 +00002408}
caryclark@google.com5987f582012-10-02 18:33:14 +00002409
scroggo@google.com09fd4d22013-03-20 14:20:18 +00002410void GMMain::installFilter(SkCanvas* canvas) {
2411 if (FLAGS_forceBWtext) {
2412 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref();
2413 }
2414}
2415
borenet@google.com7158e6a2012-11-01 17:43:44 +00002416#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
caryclark@google.com5987f582012-10-02 18:33:14 +00002417int main(int argc, char * const argv[]) {
2418 return tool_main(argc, (char**) argv);
2419}
2420#endif