blob: 6719d67aa56d75e0a8b1306929229f21c3db0df4 [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"
epoger@google.come8ebeb12012-10-29 16:42:11 +000033#include "SkOSFile.h"
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +000034#include "SkPDFRasterizer.h"
tomhudson@google.com9875dd12011-04-25 15:49:53 +000035#include "SkPicture.h"
robertphillips@google.com977b9c82012-06-05 19:35:09 +000036#include "SkRefCnt.h"
commit-bot@chromium.org5e009892013-10-14 13:42:12 +000037#include "SkScalar.h"
scroggo@google.com72c96722012-06-06 21:07:10 +000038#include "SkStream.h"
epoger@google.comf711f322013-10-18 14:55:47 +000039#include "SkString.h"
bsalomon@google.com2a48c3a2012-08-03 14:54:45 +000040#include "SkTArray.h"
epoger@google.com310478e2013-04-03 18:00:39 +000041#include "SkTDict.h"
junov@chromium.org3cb834b2012-12-13 16:39:53 +000042#include "SkTileGridPicture.h"
scroggo@google.com72c96722012-06-06 21:07:10 +000043#include "SamplePipeControllers.h"
reed@google.com07700442010-12-20 19:46:07 +000044
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000045#ifdef SK_DEBUG
46static const bool kDebugOnly = true;
47#else
48static const bool kDebugOnly = false;
49#endif
50
epoger@google.comed5eb4e2013-07-23 17:56:20 +000051__SK_FORCE_IMAGE_DECODER_LINKING;
52
bsalomon@google.com50c79d82013-01-08 20:31:53 +000053#ifdef SK_BUILD_FOR_WIN
54 // json includes xlocale which generates warning 4530 because we're compiling without
epoger@google.com37269602013-01-19 04:21:27 +000055 // exceptions; see https://code.google.com/p/skia/issues/detail?id=1067
bsalomon@google.com50c79d82013-01-08 20:31:53 +000056 #pragma warning(push)
57 #pragma warning(disable : 4530)
58#endif
epoger@google.comee8a8e32012-12-18 19:13:49 +000059#include "json/value.h"
bsalomon@google.com50c79d82013-01-08 20:31:53 +000060#ifdef SK_BUILD_FOR_WIN
61 #pragma warning(pop)
62#endif
epoger@google.comee8a8e32012-12-18 19:13:49 +000063
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000064#if SK_SUPPORT_GPU
65#include "GrContextFactory.h"
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000066#include "SkGpuDevice.h"
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000067typedef GrContextFactory::GLContextType GLContextType;
epoger@google.com6f6568b2013-03-22 17:29:46 +000068#define DEFAULT_CACHE_VALUE -1
69static int gGpuCacheSizeBytes;
70static int gGpuCacheSizeCount;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000071#else
epoger@google.com80724df2013-03-21 13:49:54 +000072class GrContextFactory;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000073class GrContext;
bsalomon@google.com123ac1d2013-03-28 19:18:12 +000074class GrSurface;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000075typedef int GLContextType;
76#endif
77
epoger@google.com76c913d2013-04-26 15:06:44 +000078#define DEBUGFAIL_SEE_STDERR SkDEBUGFAIL("see stderr for message")
79
reed@google.com8923c6c2011-11-08 14:59:38 +000080extern bool gSkSuppressFontCachePurgeSpew;
commit-bot@chromium.org5e009892013-10-14 13:42:12 +000081DECLARE_bool(useDocumentInsteadOfDevice);
reed@google.com8923c6c2011-11-08 14:59:38 +000082
reed@google.com07700442010-12-20 19:46:07 +000083#ifdef SK_SUPPORT_PDF
tomhudson@google.com9875dd12011-04-25 15:49:53 +000084 #include "SkPDFDevice.h"
85 #include "SkPDFDocument.h"
reed@google.com07700442010-12-20 19:46:07 +000086#endif
reed@android.com00dae862009-06-10 15:38:48 +000087
epoger@google.come3cc2eb2012-01-18 20:11:13 +000088// Until we resolve http://code.google.com/p/skia/issues/detail?id=455 ,
89// stop writing out XPS-format image baselines in gm.
90#undef SK_SUPPORT_XPS
bungeman@google.comb29c8832011-10-10 13:19:10 +000091#ifdef SK_SUPPORT_XPS
92 #include "SkXPSDevice.h"
93#endif
94
reed@google.com46cce912011-06-29 12:54:46 +000095#ifdef SK_BUILD_FOR_MAC
96 #include "SkCGUtils.h"
reed@google.com46cce912011-06-29 12:54:46 +000097#endif
98
reed@android.com00dae862009-06-10 15:38:48 +000099using namespace skiagm;
100
reed@android.com00dae862009-06-10 15:38:48 +0000101class Iter {
102public:
103 Iter() {
bsalomon@google.com39149582011-06-13 21:55:32 +0000104 this->reset();
105 }
106
107 void reset() {
reed@android.comdd0ac282009-06-20 02:38:16 +0000108 fReg = GMRegistry::Head();
reed@android.com00dae862009-06-10 15:38:48 +0000109 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000110
reed@android.comdd0ac282009-06-20 02:38:16 +0000111 GM* next() {
reed@android.com00dae862009-06-10 15:38:48 +0000112 if (fReg) {
reed@android.comdd0ac282009-06-20 02:38:16 +0000113 GMRegistry::Factory fact = fReg->factory();
reed@android.com00dae862009-06-10 15:38:48 +0000114 fReg = fReg->next();
reed@android.comdd0ac282009-06-20 02:38:16 +0000115 return fact(0);
reed@android.com00dae862009-06-10 15:38:48 +0000116 }
117 return NULL;
118 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000119
reed@android.com00dae862009-06-10 15:38:48 +0000120 static int Count() {
reed@android.comdd0ac282009-06-20 02:38:16 +0000121 const GMRegistry* reg = GMRegistry::Head();
reed@android.com00dae862009-06-10 15:38:48 +0000122 int count = 0;
123 while (reg) {
124 count += 1;
125 reg = reg->next();
126 }
127 return count;
128 }
reed@google.comd4dfd102011-01-18 21:05:42 +0000129
reed@android.com00dae862009-06-10 15:38:48 +0000130private:
131 const GMRegistry* fReg;
132};
133
epoger@google.comce057fe2013-05-14 15:17:46 +0000134// TODO(epoger): Right now, various places in this code assume that all the
135// image files read/written by GM use this file extension.
136// Search for references to this constant to find these assumptions.
137const static char kPNG_FileExtension[] = "png";
138
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000139enum Backend {
junov@chromium.org3cb834b2012-12-13 16:39:53 +0000140 kRaster_Backend,
141 kGPU_Backend,
142 kPDF_Backend,
143 kXPS_Backend,
144};
145
146enum BbhType {
147 kNone_BbhType,
148 kRTree_BbhType,
149 kTileGrid_BbhType,
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000150};
151
bsalomon@google.com7361f542012-04-19 19:15:35 +0000152enum ConfigFlags {
153 kNone_ConfigFlag = 0x0,
154 /* Write GM images if a write path is provided. */
155 kWrite_ConfigFlag = 0x1,
epoger@google.comf28dd8a2012-10-25 16:27:34 +0000156 /* Read reference GM images if a read path is provided. */
bsalomon@google.com7361f542012-04-19 19:15:35 +0000157 kRead_ConfigFlag = 0x2,
158 kRW_ConfigFlag = (kWrite_ConfigFlag | kRead_ConfigFlag),
159};
160
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000161struct ConfigData {
bsalomon@google.com7361f542012-04-19 19:15:35 +0000162 SkBitmap::Config fConfig;
163 Backend fBackend;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000164 GLContextType fGLContextType; // GPU backend only
bsalomon@google.com7361f542012-04-19 19:15:35 +0000165 int fSampleCnt; // GPU backend only
166 ConfigFlags fFlags;
167 const char* fName;
bsalomon@google.com4c75f242013-03-19 18:58:43 +0000168 bool fRunByDefault;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000169};
170
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000171struct PDFRasterizerData {
172 bool (*fRasterizerFunction)(SkStream*, SkBitmap*);
173 const char* fName;
174 bool fRunByDefault;
175};
176
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000177class BWTextDrawFilter : public SkDrawFilter {
178public:
reed@google.com971aca72012-11-26 20:26:54 +0000179 virtual bool filter(SkPaint*, Type) SK_OVERRIDE;
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000180};
reed@google.com971aca72012-11-26 20:26:54 +0000181bool BWTextDrawFilter::filter(SkPaint* p, Type t) {
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000182 if (kText_Type == t) {
183 p->setAntiAlias(false);
184 }
reed@google.com971aca72012-11-26 20:26:54 +0000185 return true;
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000186}
187
scroggo@google.com565254b2012-06-28 15:41:32 +0000188struct PipeFlagComboData {
189 const char* name;
190 uint32_t flags;
191};
192
193static PipeFlagComboData gPipeWritingFlagCombos[] = {
194 { "", 0 },
195 { " cross-process", SkGPipeWriter::kCrossProcess_Flag },
scroggob3c0f482012-07-02 19:07:57 +0000196 { " cross-process, shared address", SkGPipeWriter::kCrossProcess_Flag
scroggo@google.com15011ee2012-07-26 20:03:32 +0000197 | SkGPipeWriter::kSharedAddressSpace_Flag }
scroggo@google.com565254b2012-06-28 15:41:32 +0000198};
199
commit-bot@chromium.org608ea652013-10-03 19:29:21 +0000200static SkData* encode_to_dct_data(size_t* pixelRefOffset, const SkBitmap& bitmap);
edisonn@google.comd9dfa182013-04-24 13:01:01 +0000201
epoger@google.com5079d2c2013-04-12 14:11:21 +0000202const static ErrorCombination kDefaultIgnorableErrorTypes = ErrorCombination()
203 .plus(kMissingExpectations_ErrorType)
204 .plus(kIntentionallySkipped_ErrorType);
205
epoger@google.comde961632012-10-26 18:56:36 +0000206class GMMain {
207public:
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000208 GMMain() : fUseFileHierarchy(false), fWriteChecksumBasedFilenames(false),
209 fIgnorableErrorTypes(kDefaultIgnorableErrorTypes),
epoger@google.com5f995452013-06-21 18:16:47 +0000210 fMismatchPath(NULL), fMissingExpectationsPath(NULL), fTestsRun(0),
211 fRenderModesEncountered(1) {}
epoger@google.come8ebeb12012-10-29 16:42:11 +0000212
epoger@google.com659c8c02013-05-21 15:45:45 +0000213 /**
214 * Assemble shortNamePlusConfig from (surprise!) shortName and configName.
215 *
216 * The method for doing so depends on whether we are using hierarchical naming.
217 * For example, shortName "selftest1" and configName "8888" could be assembled into
218 * either "selftest1_8888" or "8888/selftest1".
219 */
220 SkString make_shortname_plus_config(const char *shortName, const char *configName) {
epoger@google.come8ebeb12012-10-29 16:42:11 +0000221 SkString name;
epoger@google.com57f7abc2012-11-13 03:41:55 +0000222 if (0 == strlen(configName)) {
223 name.append(shortName);
224 } else if (fUseFileHierarchy) {
epoger@google.come8ebeb12012-10-29 16:42:11 +0000225 name.appendf("%s%c%s", configName, SkPATH_SEPARATOR, shortName);
226 } else {
227 name.appendf("%s_%s", shortName, configName);
228 }
epoger@google.comde961632012-10-26 18:56:36 +0000229 return name;
230 }
231
epoger@google.com659c8c02013-05-21 15:45:45 +0000232 /**
233 * Assemble filename, suitable for writing out the results of a particular test.
234 */
235 SkString make_filename(const char *path,
236 const char *shortName,
237 const char *configName,
238 const char *renderModeDescriptor,
239 const char *suffix) {
240 SkString filename = make_shortname_plus_config(shortName, configName);
241 filename.append(renderModeDescriptor);
242 filename.appendUnichar('.');
243 filename.append(suffix);
scroggo@google.comccd7afb2013-05-28 16:45:07 +0000244 return SkOSPath::SkPathJoin(path, filename.c_str());
epoger@google.com659c8c02013-05-21 15:45:45 +0000245 }
246
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000247 /**
248 * Assemble filename suitable for writing out an SkBitmap.
249 */
250 SkString make_bitmap_filename(const char *path,
251 const char *shortName,
252 const char *configName,
253 const char *renderModeDescriptor,
254 const GmResultDigest &bitmapDigest) {
255 if (fWriteChecksumBasedFilenames) {
256 SkString filename;
257 filename.append(bitmapDigest.getHashType());
258 filename.appendUnichar('_');
259 filename.append(shortName);
260 filename.appendUnichar('_');
261 filename.append(bitmapDigest.getDigestValue());
262 filename.appendUnichar('.');
263 filename.append(kPNG_FileExtension);
264 return SkOSPath::SkPathJoin(path, filename.c_str());
265 } else {
266 return make_filename(path, shortName, configName, renderModeDescriptor,
267 kPNG_FileExtension);
268 }
269 }
270
epoger@google.com5f6a0072013-01-31 16:30:55 +0000271 /* since PNG insists on unpremultiplying our alpha, we take no
272 precision chances and force all pixels to be 100% opaque,
273 otherwise on compare we may not get a perfect match.
274 */
275 static void force_all_opaque(const SkBitmap& bitmap) {
276 SkBitmap::Config config = bitmap.config();
277 switch (config) {
278 case SkBitmap::kARGB_8888_Config:
279 force_all_opaque_8888(bitmap);
280 break;
281 case SkBitmap::kRGB_565_Config:
282 // nothing to do here; 565 bitmaps are inherently opaque
283 break;
284 default:
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000285 gm_fprintf(stderr, "unsupported bitmap config %d\n", config);
286 DEBUGFAIL_SEE_STDERR;
epoger@google.com5f6a0072013-01-31 16:30:55 +0000287 }
288 }
289
290 static void force_all_opaque_8888(const SkBitmap& bitmap) {
291 SkAutoLockPixels lock(bitmap);
292 for (int y = 0; y < bitmap.height(); y++) {
293 for (int x = 0; x < bitmap.width(); x++) {
294 *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT);
295 }
296 }
297 }
298
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000299 static ErrorCombination write_bitmap(const SkString& path, const SkBitmap& bitmap) {
epoger@google.com5f6a0072013-01-31 16:30:55 +0000300 // TODO(epoger): Now that we have removed force_all_opaque()
301 // from this method, we should be able to get rid of the
302 // transformation to 8888 format also.
303 SkBitmap copy;
304 bitmap.copyTo(&copy, SkBitmap::kARGB_8888_Config);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000305 if (!SkImageEncoder::EncodeFile(path.c_str(), copy,
306 SkImageEncoder::kPNG_Type,
307 100)) {
308 gm_fprintf(stderr, "FAILED to write bitmap: %s\n", path.c_str());
309 return ErrorCombination(kWritingReferenceImage_ErrorType);
310 }
311 return kEmpty_ErrorCombination;
epoger@google.com5f6a0072013-01-31 16:30:55 +0000312 }
313
epoger@google.com6f6568b2013-03-22 17:29:46 +0000314 /**
epoger@google.com310478e2013-04-03 18:00:39 +0000315 * Add all render modes encountered thus far to the "modes" array.
epoger@google.com6f6568b2013-03-22 17:29:46 +0000316 */
epoger@google.com310478e2013-04-03 18:00:39 +0000317 void GetRenderModesEncountered(SkTArray<SkString> &modes) {
318 SkTDict<int>::Iter iter(this->fRenderModesEncountered);
319 const char* mode;
320 while ((mode = iter.next(NULL)) != NULL) {
321 SkString modeAsString = SkString(mode);
322 // TODO(epoger): It seems a bit silly that all of these modes were
323 // recorded with a leading "-" which we have to remove here
324 // (except for mode "", which means plain old original mode).
325 // But that's how renderModeDescriptor has been passed into
326 // compare_test_results_to_reference_bitmap() historically,
327 // and changing that now may affect other parts of our code.
328 if (modeAsString.startsWith("-")) {
329 modeAsString.remove(0, 1);
330 modes.push_back(modeAsString);
331 }
332 }
333 }
334
335 /**
epoger@google.com3a882dd2013-10-07 18:55:09 +0000336 * Returns true if failures on this test should be ignored.
337 */
338 bool ShouldIgnoreTest(const SkString &name) const {
339 for (int i = 0; i < fIgnorableTestSubstrings.count(); i++) {
340 if (name.contains(fIgnorableTestSubstrings[i].c_str())) {
341 return true;
342 }
343 }
344 return false;
345 }
346
347 /**
epoger@google.com310478e2013-04-03 18:00:39 +0000348 * Records the results of this test in fTestsRun and fFailedTests.
349 *
350 * We even record successes, and errors that we regard as
351 * "ignorable"; we can filter them out later.
352 */
epoger@google.com659c8c02013-05-21 15:45:45 +0000353 void RecordTestResults(const ErrorCombination& errorCombination,
354 const SkString& shortNamePlusConfig,
epoger@google.com310478e2013-04-03 18:00:39 +0000355 const char renderModeDescriptor []) {
356 // Things to do regardless of errorCombination.
357 fTestsRun++;
358 int renderModeCount = 0;
359 this->fRenderModesEncountered.find(renderModeDescriptor, &renderModeCount);
360 renderModeCount++;
361 this->fRenderModesEncountered.set(renderModeDescriptor, renderModeCount);
362
epoger@google.com6f6568b2013-03-22 17:29:46 +0000363 if (errorCombination.isEmpty()) {
epoger@google.com5f6a0072013-01-31 16:30:55 +0000364 return;
epoger@google.comeb066362013-03-08 09:39:36 +0000365 }
366
epoger@google.com310478e2013-04-03 18:00:39 +0000367 // Things to do only if there is some error condition.
epoger@google.com659c8c02013-05-21 15:45:45 +0000368 SkString fullName = shortNamePlusConfig;
epoger@google.comcaac3db2013-04-04 19:23:11 +0000369 fullName.append(renderModeDescriptor);
epoger@google.com310478e2013-04-03 18:00:39 +0000370 for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) {
371 ErrorType type = static_cast<ErrorType>(typeInt);
372 if (errorCombination.includes(type)) {
373 fFailedTests[type].push_back(fullName);
epoger@google.comf60494b2013-04-03 17:02:53 +0000374 }
epoger@google.comf60494b2013-04-03 17:02:53 +0000375 }
epoger@google.comf60494b2013-04-03 17:02:53 +0000376 }
377
epoger@google.com310478e2013-04-03 18:00:39 +0000378 /**
379 * Return the number of significant (non-ignorable) errors we have
380 * encountered so far.
381 */
382 int NumSignificantErrors() {
383 int significantErrors = 0;
384 for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) {
385 ErrorType type = static_cast<ErrorType>(typeInt);
epoger@google.com5079d2c2013-04-12 14:11:21 +0000386 if (!fIgnorableErrorTypes.includes(type)) {
epoger@google.com310478e2013-04-03 18:00:39 +0000387 significantErrors += fFailedTests[type].count();
388 }
389 }
390 return significantErrors;
391 }
392
393 /**
epoger@google.com51dbabe2013-04-10 15:24:53 +0000394 * Display the summary of results with this ErrorType.
395 *
396 * @param type which ErrorType
397 * @param verbose whether to be all verbose about it
epoger@google.com310478e2013-04-03 18:00:39 +0000398 */
epoger@google.com51dbabe2013-04-10 15:24:53 +0000399 void DisplayResultTypeSummary(ErrorType type, bool verbose) {
epoger@google.com5079d2c2013-04-12 14:11:21 +0000400 bool isIgnorableType = fIgnorableErrorTypes.includes(type);
epoger@google.com51dbabe2013-04-10 15:24:53 +0000401
402 SkString line;
403 if (isIgnorableType) {
404 line.append("[ ] ");
405 } else {
406 line.append("[*] ");
407 }
408
409 SkTArray<SkString> *failedTestsOfThisType = &fFailedTests[type];
410 int count = failedTestsOfThisType->count();
411 line.appendf("%d %s", count, getErrorTypeName(type));
412 if (!isIgnorableType || verbose) {
413 line.append(":");
414 for (int i = 0; i < count; ++i) {
415 line.append(" ");
416 line.append((*failedTestsOfThisType)[i]);
417 }
418 }
419 gm_fprintf(stdout, "%s\n", line.c_str());
420 }
421
422 /**
423 * List contents of fFailedTests to stdout.
424 *
425 * @param verbose whether to be all verbose about it
426 */
427 void ListErrors(bool verbose) {
epoger@google.com310478e2013-04-03 18:00:39 +0000428 // First, print a single summary line.
429 SkString summary;
430 summary.appendf("Ran %d tests:", fTestsRun);
431 for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) {
432 ErrorType type = static_cast<ErrorType>(typeInt);
433 summary.appendf(" %s=%d", getErrorTypeName(type), fFailedTests[type].count());
434 }
435 gm_fprintf(stdout, "%s\n", summary.c_str());
436
437 // Now, for each failure type, list the tests that failed that way.
438 for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) {
epoger@google.com51dbabe2013-04-10 15:24:53 +0000439 this->DisplayResultTypeSummary(static_cast<ErrorType>(typeInt), verbose);
epoger@google.com310478e2013-04-03 18:00:39 +0000440 }
441 gm_fprintf(stdout, "(results marked with [*] will cause nonzero return value)\n");
442 }
443
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000444 static ErrorCombination write_document(const SkString& path, SkStreamAsset* asset) {
epoger@google.com5f6a0072013-01-31 16:30:55 +0000445 SkFILEWStream stream(path.c_str());
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000446 if (!stream.writeStream(asset, asset->getLength())) {
447 gm_fprintf(stderr, "FAILED to write document: %s\n", path.c_str());
448 return ErrorCombination(kWritingReferenceImage_ErrorType);
449 }
450 return kEmpty_ErrorCombination;
epoger@google.com5f6a0072013-01-31 16:30:55 +0000451 }
452
epoger@google.com37269602013-01-19 04:21:27 +0000453 /**
epoger@google.com5f6a0072013-01-31 16:30:55 +0000454 * Prepare an SkBitmap to render a GM into.
455 *
456 * After you've rendered the GM into the SkBitmap, you must call
457 * complete_bitmap()!
458 *
459 * @todo thudson 22 April 2011 - could refactor this to take in
460 * a factory to generate the context, always call readPixels()
461 * (logically a noop for rasters, if wasted time), and thus collapse the
462 * GPU special case and also let this be used for SkPicture testing.
463 */
464 static void setup_bitmap(const ConfigData& gRec, SkISize& size,
465 SkBitmap* bitmap) {
466 bitmap->setConfig(gRec.fConfig, size.width(), size.height());
467 bitmap->allocPixels();
468 bitmap->eraseColor(SK_ColorTRANSPARENT);
469 }
470
471 /**
472 * Any finalization steps we need to perform on the SkBitmap after
473 * we have rendered the GM into it.
epoger@google.com37269602013-01-19 04:21:27 +0000474 *
475 * It's too bad that we are throwing away alpha channel data
476 * we could otherwise be examining, but this had always been happening
477 * before... it was buried within the compare() method at
478 * https://code.google.com/p/skia/source/browse/trunk/gm/gmmain.cpp?r=7289#305 .
479 *
480 * Apparently we need this, at least for bitmaps that are either:
481 * (a) destined to be written out as PNG files, or
482 * (b) compared against bitmaps read in from PNG files
483 * for the reasons described just above the force_all_opaque() method.
484 *
485 * Neglecting to do this led to the difficult-to-diagnose
486 * http://code.google.com/p/skia/issues/detail?id=1079 ('gm generating
487 * spurious pixel_error messages as of r7258')
488 *
489 * TODO(epoger): Come up with a better solution that allows us to
490 * compare full pixel data, including alpha channel, while still being
491 * robust in the face of transformations to/from PNG files.
492 * Options include:
493 *
494 * 1. Continue to call force_all_opaque(), but ONLY for bitmaps that
495 * will be written to, or compared against, PNG files.
496 * PRO: Preserve/compare alpha channel info for the non-PNG cases
497 * (comparing different renderModes in-memory)
epoger@google.com908f5832013-04-12 02:23:55 +0000498 * CON: The bitmaps (and hash digests) for these non-PNG cases would be
epoger@google.com37269602013-01-19 04:21:27 +0000499 * different than those for the PNG-compared cases, and in the
500 * case of a failed renderMode comparison, how would we write the
501 * image to disk for examination?
502 *
epoger@google.com908f5832013-04-12 02:23:55 +0000503 * 2. Always compute image hash digests from PNG format (either
epoger@google.com37269602013-01-19 04:21:27 +0000504 * directly from the the bytes of a PNG file, or capturing the
505 * bytes we would have written to disk if we were writing the
506 * bitmap out as a PNG).
507 * PRO: I think this would allow us to never force opaque, and to
508 * the extent that alpha channel data can be preserved in a PNG
509 * file, we could observe it.
epoger@google.com908f5832013-04-12 02:23:55 +0000510 * CON: If we read a bitmap from disk, we need to take its hash digest
epoger@google.com37269602013-01-19 04:21:27 +0000511 * from the source PNG (we can't compute it from the bitmap we
512 * read out of the PNG, because we will have already premultiplied
513 * the alpha).
514 * CON: Seems wasteful to convert a bitmap to PNG format just to take
epoger@google.com908f5832013-04-12 02:23:55 +0000515 * its hash digest. (Although we're wasting lots of effort already
epoger@google.com37269602013-01-19 04:21:27 +0000516 * calling force_all_opaque().)
517 *
518 * 3. Make the alpha premultiply/unpremultiply routines 100% consistent,
519 * so we can transform images back and forth without fear of off-by-one
520 * errors.
521 * CON: Math is hard.
522 *
523 * 4. Perform a "close enough" comparison of bitmaps (+/- 1 bit in each
524 * channel), rather than demanding absolute equality.
epoger@google.com908f5832013-04-12 02:23:55 +0000525 * CON: Can't do this with hash digests.
epoger@google.com37269602013-01-19 04:21:27 +0000526 */
epoger@google.com5f6a0072013-01-31 16:30:55 +0000527 static void complete_bitmap(SkBitmap* bitmap) {
528 force_all_opaque(*bitmap);
epoger@google.comde961632012-10-26 18:56:36 +0000529 }
530
scroggo@google.com09fd4d22013-03-20 14:20:18 +0000531 static void installFilter(SkCanvas* canvas);
epoger@google.comde961632012-10-26 18:56:36 +0000532
reed@google.comaef73612012-11-16 13:41:45 +0000533 static void invokeGM(GM* gm, SkCanvas* canvas, bool isPDF, bool isDeferred) {
epoger@google.comde961632012-10-26 18:56:36 +0000534 SkAutoCanvasRestore acr(canvas, true);
535
536 if (!isPDF) {
537 canvas->concat(gm->getInitialTransform());
538 }
539 installFilter(canvas);
reed@google.comaef73612012-11-16 13:41:45 +0000540 gm->setCanvasIsDeferred(isDeferred);
epoger@google.comde961632012-10-26 18:56:36 +0000541 gm->draw(canvas);
542 canvas->setDrawFilter(NULL);
543 }
544
epoger@google.com6f6568b2013-03-22 17:29:46 +0000545 static ErrorCombination generate_image(GM* gm, const ConfigData& gRec,
bsalomon@google.com123ac1d2013-03-28 19:18:12 +0000546 GrSurface* gpuTarget,
epoger@google.com6f6568b2013-03-22 17:29:46 +0000547 SkBitmap* bitmap,
548 bool deferred) {
epoger@google.comde961632012-10-26 18:56:36 +0000549 SkISize size (gm->getISize());
550 setup_bitmap(gRec, size, bitmap);
551
552 SkAutoTUnref<SkCanvas> canvas;
553
554 if (gRec.fBackend == kRaster_Backend) {
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000555 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (*bitmap)));
epoger@google.comde961632012-10-26 18:56:36 +0000556 if (deferred) {
junov@chromium.org66070a52013-05-28 17:39:08 +0000557 canvas.reset(SkDeferredCanvas::Create(device));
epoger@google.comde961632012-10-26 18:56:36 +0000558 } else {
junov@chromium.org66070a52013-05-28 17:39:08 +0000559 canvas.reset(SkNEW_ARGS(SkCanvas, (device)));
epoger@google.comde961632012-10-26 18:56:36 +0000560 }
reed@google.comaef73612012-11-16 13:41:45 +0000561 invokeGM(gm, canvas, false, deferred);
epoger@google.comde961632012-10-26 18:56:36 +0000562 canvas->flush();
563 }
564#if SK_SUPPORT_GPU
565 else { // GPU
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000566 SkAutoTUnref<SkBaseDevice> device(SkGpuDevice::Create(gpuTarget));
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 // the device is as large as the current rendertarget, so
574 // we explicitly only readback the amount we expect (in
575 // size) overwrite our previous allocation
576 bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth,
577 size.fHeight);
578 canvas->readPixels(bitmap, 0, 0);
579 }
580#endif
epoger@google.com5f6a0072013-01-31 16:30:55 +0000581 complete_bitmap(bitmap);
epoger@google.com6f6568b2013-03-22 17:29:46 +0000582 return kEmpty_ErrorCombination;
epoger@google.comde961632012-10-26 18:56:36 +0000583 }
584
585 static void generate_image_from_picture(GM* gm, const ConfigData& gRec,
junov@chromium.orgc938c482012-12-19 15:24:38 +0000586 SkPicture* pict, SkBitmap* bitmap,
robertphillips@google.com5a7d0292013-04-02 15:18:41 +0000587 SkScalar scale = SK_Scalar1,
588 bool tile = false) {
epoger@google.comde961632012-10-26 18:56:36 +0000589 SkISize size = gm->getISize();
590 setup_bitmap(gRec, size, bitmap);
robertphillips@google.com5a7d0292013-04-02 15:18:41 +0000591
592 if (tile) {
593 // Generate the result image by rendering to tiles and accumulating
594 // the results in 'bitmap'
595
skia.committer@gmail.com041e2db2013-04-03 07:01:14 +0000596 // This 16x16 tiling matches the settings applied to 'pict' in
robertphillips@google.com5a7d0292013-04-02 15:18:41 +0000597 // 'generate_new_picture'
598 SkISize tileSize = SkISize::Make(16, 16);
599
600 SkBitmap tileBM;
601 setup_bitmap(gRec, tileSize, &tileBM);
602 SkCanvas tileCanvas(tileBM);
603 installFilter(&tileCanvas);
604
605 SkCanvas bmpCanvas(*bitmap);
606 SkPaint bmpPaint;
607 bmpPaint.setXfermodeMode(SkXfermode::kSrc_Mode);
608
609 for (int yTile = 0; yTile < (size.height()+15)/16; ++yTile) {
610 for (int xTile = 0; xTile < (size.width()+15)/16; ++xTile) {
611 int saveCount = tileCanvas.save();
612 SkMatrix mat(tileCanvas.getTotalMatrix());
skia.committer@gmail.com041e2db2013-04-03 07:01:14 +0000613 mat.postTranslate(SkIntToScalar(-xTile*tileSize.width()),
robertphillips@google.com5a7d0292013-04-02 15:18:41 +0000614 SkIntToScalar(-yTile*tileSize.height()));
615 tileCanvas.setMatrix(mat);
616 pict->draw(&tileCanvas);
617 tileCanvas.flush();
618 tileCanvas.restoreToCount(saveCount);
skia.committer@gmail.com041e2db2013-04-03 07:01:14 +0000619 bmpCanvas.drawBitmap(tileBM,
620 SkIntToScalar(xTile * tileSize.width()),
robertphillips@google.com5a7d0292013-04-02 15:18:41 +0000621 SkIntToScalar(yTile * tileSize.height()),
622 &bmpPaint);
623 }
624 }
625 } else {
626 SkCanvas canvas(*bitmap);
627 installFilter(&canvas);
628 canvas.scale(scale, scale);
629 canvas.drawPicture(*pict);
630 complete_bitmap(bitmap);
631 }
epoger@google.comde961632012-10-26 18:56:36 +0000632 }
633
commit-bot@chromium.org5e009892013-10-14 13:42:12 +0000634 static bool generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) {
epoger@google.comde961632012-10-26 18:56:36 +0000635#ifdef SK_SUPPORT_PDF
636 SkMatrix initialTransform = gm->getInitialTransform();
commit-bot@chromium.org5e009892013-10-14 13:42:12 +0000637 if (FLAGS_useDocumentInsteadOfDevice) {
638 SkISize pageISize = gm->getISize();
639 SkAutoTUnref<SkDocument> pdfDoc(SkDocument::CreatePDF(&pdf, NULL, encode_to_dct_data));
640
641 if (!pdfDoc.get()) {
642 return false;
643 }
644
645 SkCanvas* canvas = NULL;
646 canvas = pdfDoc->beginPage(SkIntToScalar(pageISize.width()),
647 SkIntToScalar(pageISize.height()));
648 canvas->concat(initialTransform);
649
650 invokeGM(gm, canvas, true, false);
651
652 return pdfDoc->close();
epoger@google.comde961632012-10-26 18:56:36 +0000653 } else {
commit-bot@chromium.org5e009892013-10-14 13:42:12 +0000654 SkISize pageSize = gm->getISize();
655 SkPDFDevice* dev = NULL;
656 if (initialTransform.isIdentity()) {
657 dev = new SkPDFDevice(pageSize, pageSize, initialTransform);
658 } else {
659 SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()),
660 SkIntToScalar(pageSize.height()));
661 initialTransform.mapRect(&content);
662 content.intersect(0, 0, SkIntToScalar(pageSize.width()),
663 SkIntToScalar(pageSize.height()));
664 SkISize contentSize =
665 SkISize::Make(SkScalarRoundToInt(content.width()),
666 SkScalarRoundToInt(content.height()));
667 dev = new SkPDFDevice(pageSize, contentSize, initialTransform);
668 }
669 dev->setDCTEncoder(encode_to_dct_data);
670 SkAutoUnref aur(dev);
671 SkCanvas c(dev);
672 invokeGM(gm, &c, true, false);
673 SkPDFDocument doc;
674 doc.appendPage(dev);
675 doc.emitPDF(&pdf);
epoger@google.comde961632012-10-26 18:56:36 +0000676 }
commit-bot@chromium.org5e009892013-10-14 13:42:12 +0000677#endif // SK_SUPPORT_PDF
678 return true; // Do not report failure if pdf is not supported.
epoger@google.comde961632012-10-26 18:56:36 +0000679 }
680
681 static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) {
682#ifdef SK_SUPPORT_XPS
683 SkISize size = gm->getISize();
684
685 SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()),
686 SkIntToScalar(size.height()));
687 static const SkScalar inchesPerMeter = SkScalarDiv(10000, 254);
688 static const SkScalar upm = 72 * inchesPerMeter;
689 SkVector unitsPerMeter = SkPoint::Make(upm, upm);
690 static const SkScalar ppm = 200 * inchesPerMeter;
691 SkVector pixelsPerMeter = SkPoint::Make(ppm, ppm);
692
693 SkXPSDevice* dev = new SkXPSDevice();
694 SkAutoUnref aur(dev);
695
696 SkCanvas c(dev);
697 dev->beginPortfolio(&xps);
698 dev->beginSheet(unitsPerMeter, pixelsPerMeter, trimSize);
reed@google.comaef73612012-11-16 13:41:45 +0000699 invokeGM(gm, &c, false, false);
epoger@google.comde961632012-10-26 18:56:36 +0000700 dev->endSheet();
701 dev->endPortfolio();
702
703#endif
704 }
705
epoger@google.com37269602013-01-19 04:21:27 +0000706 /**
epoger@google.com84a18022013-02-01 20:39:15 +0000707 * Log more detail about the mistmatch between expectedBitmap and
708 * actualBitmap.
709 */
710 void report_bitmap_diffs(const SkBitmap& expectedBitmap, const SkBitmap& actualBitmap,
711 const char *testName) {
712 const int expectedWidth = expectedBitmap.width();
713 const int expectedHeight = expectedBitmap.height();
714 const int width = actualBitmap.width();
715 const int height = actualBitmap.height();
716 if ((expectedWidth != width) || (expectedHeight != height)) {
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000717 gm_fprintf(stderr, "---- %s: dimension mismatch --"
718 " expected [%d %d], actual [%d %d]\n",
719 testName, expectedWidth, expectedHeight, width, height);
epoger@google.com84a18022013-02-01 20:39:15 +0000720 return;
721 }
722
723 if ((SkBitmap::kARGB_8888_Config != expectedBitmap.config()) ||
724 (SkBitmap::kARGB_8888_Config != actualBitmap.config())) {
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000725 gm_fprintf(stderr, "---- %s: not computing max per-channel"
726 " pixel mismatch because non-8888\n", testName);
epoger@google.com84a18022013-02-01 20:39:15 +0000727 return;
728 }
729
730 SkAutoLockPixels alp0(expectedBitmap);
731 SkAutoLockPixels alp1(actualBitmap);
732 int errR = 0;
733 int errG = 0;
734 int errB = 0;
735 int errA = 0;
736 int differingPixels = 0;
737
738 for (int y = 0; y < height; ++y) {
739 const SkPMColor* expectedPixelPtr = expectedBitmap.getAddr32(0, y);
740 const SkPMColor* actualPixelPtr = actualBitmap.getAddr32(0, y);
741 for (int x = 0; x < width; ++x) {
742 SkPMColor expectedPixel = *expectedPixelPtr++;
743 SkPMColor actualPixel = *actualPixelPtr++;
744 if (expectedPixel != actualPixel) {
745 differingPixels++;
746 errR = SkMax32(errR, SkAbs32((int)SkGetPackedR32(expectedPixel) -
747 (int)SkGetPackedR32(actualPixel)));
748 errG = SkMax32(errG, SkAbs32((int)SkGetPackedG32(expectedPixel) -
749 (int)SkGetPackedG32(actualPixel)));
750 errB = SkMax32(errB, SkAbs32((int)SkGetPackedB32(expectedPixel) -
751 (int)SkGetPackedB32(actualPixel)));
752 errA = SkMax32(errA, SkAbs32((int)SkGetPackedA32(expectedPixel) -
753 (int)SkGetPackedA32(actualPixel)));
754 }
755 }
756 }
epoger@google.com5efdd0c2013-03-13 14:18:40 +0000757 gm_fprintf(stderr, "---- %s: %d (of %d) differing pixels,"
758 " max per-channel mismatch R=%d G=%d B=%d A=%d\n",
759 testName, differingPixels, width*height, errR, errG, errB, errA);
epoger@google.com84a18022013-02-01 20:39:15 +0000760 }
761
762 /**
epoger@google.com908f5832013-04-12 02:23:55 +0000763 * Compares actual hash digest to expectations, returning the set of errors
epoger@google.com6f6568b2013-03-22 17:29:46 +0000764 * (if any) that we saw along the way.
epoger@google.com37269602013-01-19 04:21:27 +0000765 *
766 * If fMismatchPath has been set, and there are pixel diffs, then the
767 * actual bitmap will be written out to a file within fMismatchPath.
epoger@google.com5f995452013-06-21 18:16:47 +0000768 * And similarly for fMissingExpectationsPath...
epoger@google.com37269602013-01-19 04:21:27 +0000769 *
770 * @param expectations what expectations to compare actualBitmap against
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000771 * @param actualBitmapAndDigest the SkBitmap we actually generated, and its GmResultDigest
epoger@google.com659c8c02013-05-21 15:45:45 +0000772 * @param shortName name of test, e.g. "selftest1"
773 * @param configName name of config, e.g. "8888"
epoger@google.com37269602013-01-19 04:21:27 +0000774 * @param renderModeDescriptor e.g., "-rtree", "-deferred"
775 * @param addToJsonSummary whether to add these results (both actual and
epoger@google.comcaac3db2013-04-04 19:23:11 +0000776 * expected) to the JSON summary. Regardless of this setting, if
777 * we find an image mismatch in this test, we will write these
778 * results to the JSON summary. (This is so that we will always
779 * report errors across rendering modes, such as pipe vs tiled.
780 * See https://codereview.chromium.org/13650002/ )
epoger@google.com37269602013-01-19 04:21:27 +0000781 */
epoger@google.com6f6568b2013-03-22 17:29:46 +0000782 ErrorCombination compare_to_expectations(Expectations expectations,
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000783 const BitmapAndDigest& actualBitmapAndDigest,
epoger@google.com659c8c02013-05-21 15:45:45 +0000784 const char *shortName, const char *configName,
785 const char *renderModeDescriptor,
epoger@google.comcaac3db2013-04-04 19:23:11 +0000786 bool addToJsonSummary) {
epoger@google.com6f6568b2013-03-22 17:29:46 +0000787 ErrorCombination errors;
epoger@google.com659c8c02013-05-21 15:45:45 +0000788 SkString shortNamePlusConfig = make_shortname_plus_config(shortName, configName);
789 SkString completeNameString(shortNamePlusConfig);
epoger@google.com37269602013-01-19 04:21:27 +0000790 completeNameString.append(renderModeDescriptor);
epoger@google.comce057fe2013-05-14 15:17:46 +0000791 completeNameString.append(".");
792 completeNameString.append(kPNG_FileExtension);
epoger@google.com37269602013-01-19 04:21:27 +0000793 const char* completeName = completeNameString.c_str();
epoger@google.comee8a8e32012-12-18 19:13:49 +0000794
epoger@google.com37269602013-01-19 04:21:27 +0000795 if (expectations.empty()) {
epoger@google.com6f6568b2013-03-22 17:29:46 +0000796 errors.add(kMissingExpectations_ErrorType);
epoger@google.com5f995452013-06-21 18:16:47 +0000797
798 // Write out the "actuals" for any tests without expectations, if we have
799 // been directed to do so.
800 if (fMissingExpectationsPath) {
801 SkString path = make_bitmap_filename(fMissingExpectationsPath, shortName,
802 configName, renderModeDescriptor,
803 actualBitmapAndDigest.fDigest);
804 write_bitmap(path, actualBitmapAndDigest.fBitmap);
805 }
806
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000807 } else if (!expectations.match(actualBitmapAndDigest.fDigest)) {
epoger@google.comcaac3db2013-04-04 19:23:11 +0000808 addToJsonSummary = true;
809 // The error mode we record depends on whether this was running
810 // in a non-standard renderMode.
811 if ('\0' == *renderModeDescriptor) {
812 errors.add(kExpectationsMismatch_ErrorType);
813 } else {
814 errors.add(kRenderModeMismatch_ErrorType);
815 }
epoger@google.com84a18022013-02-01 20:39:15 +0000816
817 // Write out the "actuals" for any mismatches, if we have
818 // been directed to do so.
epoger@google.com37269602013-01-19 04:21:27 +0000819 if (fMismatchPath) {
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000820 SkString path = make_bitmap_filename(fMismatchPath, shortName, configName,
821 renderModeDescriptor,
822 actualBitmapAndDigest.fDigest);
823 write_bitmap(path, actualBitmapAndDigest.fBitmap);
epoger@google.com37269602013-01-19 04:21:27 +0000824 }
epoger@google.com84a18022013-02-01 20:39:15 +0000825
826 // If we have access to a single expected bitmap, log more
827 // detail about the mismatch.
828 const SkBitmap *expectedBitmapPtr = expectations.asBitmap();
829 if (NULL != expectedBitmapPtr) {
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000830 report_bitmap_diffs(*expectedBitmapPtr, actualBitmapAndDigest.fBitmap,
831 completeName);
epoger@google.com84a18022013-02-01 20:39:15 +0000832 }
epoger@google.coma243b222013-01-17 17:54:28 +0000833 }
epoger@google.coma243b222013-01-17 17:54:28 +0000834
epoger@google.com37269602013-01-19 04:21:27 +0000835 if (addToJsonSummary) {
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000836 add_actual_results_to_json_summary(completeName, actualBitmapAndDigest.fDigest, errors,
epoger@google.com37269602013-01-19 04:21:27 +0000837 expectations.ignoreFailure());
838 add_expected_results_to_json_summary(completeName, expectations);
839 }
epoger@google.coma243b222013-01-17 17:54:28 +0000840
epoger@google.com6f6568b2013-03-22 17:29:46 +0000841 return errors;
epoger@google.com06b8a192013-01-15 19:10:16 +0000842 }
843
epoger@google.com37269602013-01-19 04:21:27 +0000844 /**
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000845 * Add this result to the appropriate JSON collection of actual results (but just ONE),
epoger@google.com76c913d2013-04-26 15:06:44 +0000846 * depending on errors encountered.
epoger@google.com37269602013-01-19 04:21:27 +0000847 */
848 void add_actual_results_to_json_summary(const char testName[],
epoger@google.comd4993ff2013-05-24 14:33:28 +0000849 const GmResultDigest &actualResultDigest,
epoger@google.com76c913d2013-04-26 15:06:44 +0000850 ErrorCombination errors,
epoger@google.com37269602013-01-19 04:21:27 +0000851 bool ignoreFailure) {
epoger@google.comd4993ff2013-05-24 14:33:28 +0000852 Json::Value jsonActualResults = actualResultDigest.asJsonTypeValuePair();
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000853 Json::Value *resultCollection = NULL;
854
epoger@google.com76c913d2013-04-26 15:06:44 +0000855 if (errors.isEmpty()) {
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000856 resultCollection = &this->fJsonActualResults_Succeeded;
857 } else if (errors.includes(kRenderModeMismatch_ErrorType)) {
858 resultCollection = &this->fJsonActualResults_Failed;
859 } else if (errors.includes(kExpectationsMismatch_ErrorType)) {
epoger@google.com37269602013-01-19 04:21:27 +0000860 if (ignoreFailure) {
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000861 resultCollection = &this->fJsonActualResults_FailureIgnored;
epoger@google.com37269602013-01-19 04:21:27 +0000862 } else {
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000863 resultCollection = &this->fJsonActualResults_Failed;
epoger@google.com37269602013-01-19 04:21:27 +0000864 }
epoger@google.com1ddfbc22013-10-10 17:24:20 +0000865 } else if (errors.includes(kMissingExpectations_ErrorType)) {
866 // TODO: What about the case where there IS an expected
867 // image hash digest, but that gm test doesn't actually
868 // run? For now, those cases will always be ignored,
869 // because gm only looks at expectations that correspond
870 // to gm tests that were actually run.
871 //
872 // Once we have the ability to express expectations as a
873 // JSON file, we should fix this (and add a test case for
874 // which an expectation is given but the test is never
875 // run).
876 resultCollection = &this->fJsonActualResults_NoComparison;
877 }
878
879 // If none of the above cases match, we don't add it to ANY tally of actual results.
880 if (resultCollection) {
881 (*resultCollection)[testName] = jsonActualResults;
epoger@google.com37269602013-01-19 04:21:27 +0000882 }
883 }
884
885 /**
886 * Add this test to the JSON collection of expected results.
887 */
888 void add_expected_results_to_json_summary(const char testName[],
889 Expectations expectations) {
epoger@google.com76c913d2013-04-26 15:06:44 +0000890 this->fJsonExpectedResults[testName] = expectations.asJsonValue();
epoger@google.com37269602013-01-19 04:21:27 +0000891 }
892
893 /**
894 * Compare actualBitmap to expectations stored in this->fExpectationsSource.
895 *
896 * @param gm which test generated the actualBitmap
897 * @param gRec
vandebo@chromium.org8fc37662013-08-21 18:04:09 +0000898 * @param configName The config name to look for in the expectation file.
epoger@google.come33e1372013-07-08 19:13:33 +0000899 * @param actualBitmapAndDigest ptr to bitmap generated by this run, or NULL
900 * if we don't have a usable bitmap representation
epoger@google.com37269602013-01-19 04:21:27 +0000901 */
epoger@google.com6f6568b2013-03-22 17:29:46 +0000902 ErrorCombination compare_test_results_to_stored_expectations(
vandebo@chromium.org8fc37662013-08-21 18:04:09 +0000903 GM* gm, const ConfigData& gRec, const char* configName,
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000904 const BitmapAndDigest* actualBitmapAndDigest) {
epoger@google.com37269602013-01-19 04:21:27 +0000905
vandebo@chromium.org8fc37662013-08-21 18:04:09 +0000906 SkString shortNamePlusConfig = make_shortname_plus_config(gm->shortName(), configName);
epoger@google.com9ef89ce2013-01-18 21:45:42 +0000907
epoger@google.com659c8c02013-05-21 15:45:45 +0000908 ErrorCombination errors;
epoger@google.come33e1372013-07-08 19:13:33 +0000909
910 if (NULL == actualBitmapAndDigest) {
911 // Note that we intentionally skipped validating the results for
912 // this test, because we don't know how to generate an SkBitmap
913 // version of the output.
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000914 errors.add(ErrorCombination(kIntentionallySkipped_ErrorType));
epoger@google.comc824c832013-07-12 15:52:59 +0000915 } else if (!(gRec.fFlags & kWrite_ConfigFlag)) {
916 // We don't record the results for this test or compare them
917 // against any expectations, because the output image isn't
918 // meaningful.
919 // See https://code.google.com/p/skia/issues/detail?id=1410 ('some
920 // GM result images not available for download from Google Storage')
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000921 errors.add(ErrorCombination(kIntentionallySkipped_ErrorType));
epoger@google.come33e1372013-07-08 19:13:33 +0000922 } else {
923 ExpectationsSource *expectationsSource = this->fExpectationsSource.get();
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000924 SkString nameWithExtension(shortNamePlusConfig);
925 nameWithExtension.append(".");
926 nameWithExtension.append(kPNG_FileExtension);
927
epoger@google.come33e1372013-07-08 19:13:33 +0000928 if (expectationsSource && (gRec.fFlags & kRead_ConfigFlag)) {
929 /*
930 * Get the expected results for this test, as one or more allowed
931 * hash digests. The current implementation of expectationsSource
932 * get this by computing the hash digest of a single PNG file on disk.
933 *
934 * TODO(epoger): This relies on the fact that
935 * force_all_opaque() was called on the bitmap before it
936 * was written to disk as a PNG in the first place. If
937 * not, the hash digest returned here may not match the
938 * hash digest of actualBitmap, which *has* been run through
939 * force_all_opaque().
940 * See comments above complete_bitmap() for more detail.
941 */
942 Expectations expectations = expectationsSource->get(nameWithExtension.c_str());
epoger@google.com3a882dd2013-10-07 18:55:09 +0000943 if (this->ShouldIgnoreTest(shortNamePlusConfig)) {
epoger@google.comdefc4872013-09-19 06:18:27 +0000944 expectations.setIgnoreFailure(true);
945 }
epoger@google.come33e1372013-07-08 19:13:33 +0000946 errors.add(compare_to_expectations(expectations, *actualBitmapAndDigest,
vandebo@chromium.org8fc37662013-08-21 18:04:09 +0000947 gm->shortName(), configName, "", true));
epoger@google.come33e1372013-07-08 19:13:33 +0000948 } else {
949 // If we are running without expectations, we still want to
950 // record the actual results.
951 add_actual_results_to_json_summary(nameWithExtension.c_str(),
952 actualBitmapAndDigest->fDigest,
953 ErrorCombination(kMissingExpectations_ErrorType),
954 false);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000955 errors.add(ErrorCombination(kMissingExpectations_ErrorType));
epoger@google.come33e1372013-07-08 19:13:33 +0000956 }
epoger@google.com9ef89ce2013-01-18 21:45:42 +0000957 }
epoger@google.com6f6568b2013-03-22 17:29:46 +0000958 return errors;
epoger@google.coma243b222013-01-17 17:54:28 +0000959 }
960
epoger@google.com37269602013-01-19 04:21:27 +0000961 /**
962 * Compare actualBitmap to referenceBitmap.
963 *
epoger@google.com659c8c02013-05-21 15:45:45 +0000964 * @param shortName test name, e.g. "selftest1"
965 * @param configName configuration name, e.g. "8888"
epoger@google.com37269602013-01-19 04:21:27 +0000966 * @param renderModeDescriptor
967 * @param actualBitmap actual bitmap generated by this run
968 * @param referenceBitmap bitmap we expected to be generated
969 */
epoger@google.com6f6568b2013-03-22 17:29:46 +0000970 ErrorCombination compare_test_results_to_reference_bitmap(
epoger@google.com659c8c02013-05-21 15:45:45 +0000971 const char *shortName, const char *configName, const char *renderModeDescriptor,
epoger@google.com37269602013-01-19 04:21:27 +0000972 SkBitmap& actualBitmap, const SkBitmap* referenceBitmap) {
973
974 SkASSERT(referenceBitmap);
epoger@google.com84a18022013-02-01 20:39:15 +0000975 Expectations expectations(*referenceBitmap);
epoger@google.com6f7f14d2013-06-19 18:28:31 +0000976 BitmapAndDigest actualBitmapAndDigest(actualBitmap);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +0000977
978 // TODO: Eliminate RecordTestResults from here.
979 // Results recording code for the test_drawing path has been refactored so that
980 // RecordTestResults is only called once, at the topmost level. However, the
981 // other paths have not yet been refactored, and RecordTestResults has been added
982 // here to maintain proper behavior for calls not coming from the test_drawing path.
983 ErrorCombination errors;
984 errors.add(compare_to_expectations(expectations, actualBitmapAndDigest, shortName,
985 configName, renderModeDescriptor, false));
986 SkString shortNamePlusConfig = make_shortname_plus_config(shortName, configName);
987 RecordTestResults(errors, shortNamePlusConfig, renderModeDescriptor);
988
989 return errors;
epoger@google.com37269602013-01-19 04:21:27 +0000990 }
991
junov@chromium.org20bd04e2013-01-16 18:43:36 +0000992 static SkPicture* generate_new_picture(GM* gm, BbhType bbhType, uint32_t recordFlags,
993 SkScalar scale = SK_Scalar1) {
epoger@google.comde961632012-10-26 18:56:36 +0000994 // Pictures are refcounted so must be on heap
junov@chromium.org3cb834b2012-12-13 16:39:53 +0000995 SkPicture* pict;
junov@chromium.org706ff2f2012-12-19 15:55:40 +0000996 int width = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().width()), scale));
997 int height = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().height()), scale));
skia.committer@gmail.comd8b27992012-12-20 02:01:41 +0000998
junov@chromium.org3cb834b2012-12-13 16:39:53 +0000999 if (kTileGrid_BbhType == bbhType) {
junov@chromium.org29b19e52013-02-27 18:35:16 +00001000 SkTileGridPicture::TileGridInfo info;
1001 info.fMargin.setEmpty();
1002 info.fOffset.setZero();
1003 info.fTileInterval.set(16, 16);
1004 pict = new SkTileGridPicture(width, height, info);
junov@chromium.org3cb834b2012-12-13 16:39:53 +00001005 } else {
1006 pict = new SkPicture;
1007 }
junov@chromium.org20bd04e2013-01-16 18:43:36 +00001008 if (kNone_BbhType != bbhType) {
1009 recordFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag;
1010 }
junov@chromium.org706ff2f2012-12-19 15:55:40 +00001011 SkCanvas* cv = pict->beginRecording(width, height, recordFlags);
junov@chromium.orgc938c482012-12-19 15:24:38 +00001012 cv->scale(scale, scale);
reed@google.comaef73612012-11-16 13:41:45 +00001013 invokeGM(gm, cv, false, false);
epoger@google.comde961632012-10-26 18:56:36 +00001014 pict->endRecording();
1015
1016 return pict;
1017 }
1018
commit-bot@chromium.org805df1a2013-08-16 19:18:12 +00001019 static SkData* bitmap_encoder(size_t* pixelRefOffset, const SkBitmap& bm) {
1020 SkPixelRef* pr = bm.pixelRef();
1021 if (pr != NULL) {
1022 SkData* data = pr->refEncodedData();
1023 if (data != NULL) {
1024 *pixelRefOffset = bm.pixelRefOffset();
1025 return data;
1026 }
1027 }
1028 return NULL;
1029 }
1030
epoger@google.comde961632012-10-26 18:56:36 +00001031 static SkPicture* stream_to_new_picture(const SkPicture& src) {
epoger@google.comde961632012-10-26 18:56:36 +00001032 SkDynamicMemoryWStream storage;
commit-bot@chromium.org805df1a2013-08-16 19:18:12 +00001033 src.serialize(&storage, &bitmap_encoder);
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;
1084 SkASSERT(documentStream->rewind());
1085 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;
epoger@google.com3a882dd2013-10-07 18:55:09 +00001253 SkTArray<SkString> fIgnorableTestSubstrings;
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];
1260 int fTestsRun;
1261 SkTDict<int> fRenderModesEncountered;
epoger@google.com57f7abc2012-11-13 03:41:55 +00001262
epoger@google.com908f5832013-04-12 02:23:55 +00001263 // Where to read expectations (expected image hash digests, etc.) from.
epoger@google.com37269602013-01-19 04:21:27 +00001264 // If unset, we don't do comparisons.
1265 SkAutoTUnref<ExpectationsSource> fExpectationsSource;
1266
1267 // JSON summaries that we generate as we go (just for output).
epoger@google.comee8a8e32012-12-18 19:13:49 +00001268 Json::Value fJsonExpectedResults;
1269 Json::Value fJsonActualResults_Failed;
1270 Json::Value fJsonActualResults_FailureIgnored;
epoger@google.com9c56a8d2012-12-20 18:34:29 +00001271 Json::Value fJsonActualResults_NoComparison;
epoger@google.comee8a8e32012-12-18 19:13:49 +00001272 Json::Value fJsonActualResults_Succeeded;
1273
epoger@google.comde961632012-10-26 18:56:36 +00001274}; // end of GMMain class definition
scroggo@google.com72c96722012-06-06 21:07:10 +00001275
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001276#if SK_SUPPORT_GPU
1277static const GLContextType kDontCare_GLContextType = GrContextFactory::kNative_GLContextType;
1278#else
1279static const GLContextType kDontCare_GLContextType = 0;
1280#endif
bsalomon@google.com7361f542012-04-19 19:15:35 +00001281
tomhudson@google.com9875dd12011-04-25 15:49:53 +00001282static const ConfigData gRec[] = {
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001283 { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "8888", true },
reed@google.com69dc4ff2012-11-29 21:21:54 +00001284#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 +00001285 { SkBitmap::kARGB_4444_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "4444", true },
reed@google.com69dc4ff2012-11-29 21:21:54 +00001286#endif
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001287 { SkBitmap::kRGB_565_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "565", true },
1288#if SK_SUPPORT_GPU
1289 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 0, kRW_ConfigFlag, "gpu", true },
robertphillips@google.com7bb28a12013-06-06 21:29:39 +00001290 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 16, kRW_ConfigFlag, "msaa16", false},
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001291 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 4, kRW_ConfigFlag, "msaa4", false},
epoger@google.comc824c832013-07-12 15:52:59 +00001292 /* The gpudebug context does not generate meaningful images, so don't record
1293 * the images it generates! We only run it to look for asserts. */
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +00001294 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kDebug_GLContextType, 0, kNone_ConfigFlag, "gpudebug", kDebugOnly},
robertphillips@google.comd6543e52013-07-18 17:39:14 +00001295 /* The gpunull context does the least amount of work possible and doesn't
1296 generate meaninful images, so don't record them!. It can be run to
1297 isolate the CPU-side processing expense from the GPU-side.
1298 */
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +00001299 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNull_GLContextType, 0, kNone_ConfigFlag, "gpunull", kDebugOnly},
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001300#if SK_ANGLE
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001301 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 0, kRW_ConfigFlag, "angle", true },
1302 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 16, kRW_ConfigFlag, "anglemsaa16", true },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001303#endif // SK_ANGLE
1304#ifdef SK_MESA
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001305 { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kMESA_GLContextType, 0, kRW_ConfigFlag, "mesa", true },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001306#endif // SK_MESA
bsalomon@google.com4c75f242013-03-19 18:58:43 +00001307#endif // SK_SUPPORT_GPU
bungeman@google.comb29c8832011-10-10 13:19:10 +00001308#ifdef SK_SUPPORT_XPS
bsalomon@google.com7361f542012-04-19 19:15:35 +00001309 /* 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 +00001310 { SkBitmap::kARGB_8888_Config, kXPS_Backend, kDontCare_GLContextType, 0, kWrite_ConfigFlag, "xps", true },
robertphillips@google.coma73e8602012-08-02 17:56:02 +00001311#endif // SK_SUPPORT_XPS
bsalomon@google.com7361f542012-04-19 19:15:35 +00001312#ifdef SK_SUPPORT_PDF
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001313 { SkBitmap::kARGB_8888_Config, kPDF_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "pdf", true },
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00001314#endif // SK_SUPPORT_PDF
reed@android.com00dae862009-06-10 15:38:48 +00001315};
1316
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001317static const PDFRasterizerData kPDFRasterizers[] = {
1318#ifdef SK_BUILD_FOR_MAC
1319 { &SkPDFDocumentToBitmap, "mac", true },
1320#endif
1321#ifdef SK_BUILD_POPPLER
1322 { &SkPopplerRasterizePDF, "poppler", true },
1323#endif
1324};
1325
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001326static const char kDefaultsConfigStr[] = "defaults";
1327static const char kExcludeConfigChar = '~';
1328
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001329static SkString configUsage() {
scroggo@google.com0f567c62013-03-20 15:35:08 +00001330 SkString result;
1331 result.appendf("Space delimited list of which configs to run. Possible options: [");
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001332 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001333 SkASSERT(gRec[i].fName != kDefaultsConfigStr);
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001334 if (i > 0) {
scroggo@google.com0f567c62013-03-20 15:35:08 +00001335 result.append("|");
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001336 }
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001337 result.appendf("%s", gRec[i].fName);
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001338 }
scroggo@google.com0f567c62013-03-20 15:35:08 +00001339 result.append("]\n");
1340 result.appendf("The default value is: \"");
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001341 SkString firstDefault;
1342 SkString allButFirstDefaults;
1343 SkString nonDefault;
scroggo@google.com0f567c62013-03-20 15:35:08 +00001344 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
1345 if (gRec[i].fRunByDefault) {
1346 if (i > 0) {
1347 result.append(" ");
1348 }
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001349 result.append(gRec[i].fName);
1350 if (firstDefault.isEmpty()) {
1351 firstDefault = gRec[i].fName;
1352 } else {
1353 if (!allButFirstDefaults.isEmpty()) {
1354 allButFirstDefaults.append(" ");
1355 }
1356 allButFirstDefaults.append(gRec[i].fName);
1357 }
1358 } else {
1359 nonDefault = gRec[i].fName;
scroggo@google.com0f567c62013-03-20 15:35:08 +00001360 }
1361 }
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00001362 result.append("\"\n");
1363 result.appendf("\"%s\" evaluates to the default set of configs.\n", kDefaultsConfigStr);
1364 result.appendf("Prepending \"%c\" on a config name excludes it from the set of configs to run.\n"
1365 "Exclusions always override inclusions regardless of order.\n",
1366 kExcludeConfigChar);
1367 result.appendf("E.g. \"--config %s %c%s %s\" will run these configs:\n\t%s %s",
1368 kDefaultsConfigStr,
1369 kExcludeConfigChar,
1370 firstDefault.c_str(),
1371 nonDefault.c_str(),
1372 allButFirstDefaults.c_str(),
1373 nonDefault.c_str());
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001374 return result;
scroggo@google.com0b735632013-03-19 17:38:50 +00001375}
scroggo@google.com7d519302013-03-19 17:28:10 +00001376
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001377static SkString pdfRasterizerUsage() {
1378 SkString result;
1379 result.appendf("Space delimited list of which PDF rasterizers to run. Possible options: [");
1380 // For this (and further) loops through kPDFRasterizers, there is a typecast to int to avoid
1381 // the compiler giving an "comparison of unsigned expression < 0 is always false" warning
1382 // and turning it into a build-breaking error.
1383 for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); ++i) {
1384 if (i > 0) {
1385 result.append(" ");
1386 }
1387 result.append(kPDFRasterizers[i].fName);
1388 }
1389 result.append("]\n");
1390 result.append("The default value is: \"");
1391 for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); ++i) {
1392 if (kPDFRasterizers[i].fRunByDefault) {
1393 if (i > 0) {
1394 result.append(" ");
1395 }
1396 result.append(kPDFRasterizers[i].fName);
1397 }
1398 }
1399 result.append("\"");
1400 return result;
1401}
1402
epoger@google.com6f6568b2013-03-22 17:29:46 +00001403// Macro magic to convert a numeric preprocessor token into a string.
1404// Adapted from http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
1405// This should probably be moved into one of our common headers...
1406#define TOSTRING_INTERNAL(x) #x
1407#define TOSTRING(x) TOSTRING_INTERNAL(x)
1408
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001409// Alphabetized ignoring "no" prefix ("readPath", "noreplay", "resourcePath").
scroggo@google.com0f567c62013-03-20 15:35:08 +00001410DEFINE_string(config, "", configUsage().c_str());
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001411DEFINE_string(pdfRasterizers, "", pdfRasterizerUsage().c_str());
epoger@google.com5e497382013-09-30 07:01:55 +00001412DEFINE_bool(deferred, false, "Exercise the deferred rendering test pass.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001413DEFINE_string(excludeConfig, "", "Space delimited list of configs to skip.");
1414DEFINE_bool(forceBWtext, false, "Disable text anti-aliasing.");
1415#if SK_SUPPORT_GPU
1416DEFINE_string(gpuCacheSize, "", "<bytes> <count>: Limit the gpu cache to byte size or "
epoger@google.com6f6568b2013-03-22 17:29:46 +00001417 "object count. " TOSTRING(DEFAULT_CACHE_VALUE) " for either value means "
1418 "use the default. 0 for either disables the cache.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001419#endif
1420DEFINE_bool(hierarchy, false, "Whether to use multilevel directory structure "
1421 "when reading/writing files.");
epoger@google.com5079d2c2013-04-12 14:11:21 +00001422DEFINE_string(ignoreErrorTypes, kDefaultIgnorableErrorTypes.asString(" ").c_str(),
1423 "Space-separated list of ErrorTypes that should be ignored. If any *other* error "
1424 "types are encountered, the tool will exit with a nonzero return value.");
epoger@google.comf711f322013-10-18 14:55:47 +00001425DEFINE_string(ignoreFailuresFile, "", "Path to file containing a list of tests for which we "
1426 "should ignore failures.\n"
1427 "The file should list one test per line, except for comment lines starting with #");
caryclark@google.com512c9b62013-05-10 15:16:13 +00001428DEFINE_string(match, "", "[~][^]substring[$] [...] of test name to run.\n"
1429 "Multiple matches may be separated by spaces.\n"
1430 "~ causes a matching test to always be skipped\n"
1431 "^ requires the start of the test to match\n"
1432 "$ requires the end of the test to match\n"
1433 "^ and $ requires an exact match\n"
1434 "If a test does not match any list entry,\n"
1435 "it is skipped unless some list entry starts with ~");
epoger@google.com5f995452013-06-21 18:16:47 +00001436DEFINE_string(missingExpectationsPath, "", "Write images for tests without expectations "
1437 "into this directory.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001438DEFINE_string(mismatchPath, "", "Write images for tests that failed due to "
1439 "pixel mismatches into this directory.");
1440DEFINE_string(modulo, "", "[--modulo <remainder> <divisor>]: only run tests for which "
1441 "testIndex %% divisor == remainder.");
epoger@google.com5e497382013-09-30 07:01:55 +00001442DEFINE_bool(pipe, false, "Exercise the SkGPipe replay test pass.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001443DEFINE_string2(readPath, r, "", "Read reference images from this dir, and report "
1444 "any differences between those and the newly generated ones.");
epoger@google.com5e497382013-09-30 07:01:55 +00001445DEFINE_bool(replay, false, "Exercise the SkPicture replay test pass.");
djsollen@google.comac8f3a42013-10-04 14:57:00 +00001446#if SK_SUPPORT_GPU
1447DEFINE_bool(resetGpuContext, false, "Reset the GrContext prior to running each GM.");
1448#endif
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001449DEFINE_string2(resourcePath, i, "", "Directory that stores image resources.");
epoger@google.com5e497382013-09-30 07:01:55 +00001450DEFINE_bool(rtree, false, "Exercise the R-Tree variant of SkPicture test pass.");
1451DEFINE_bool(serialize, false, "Exercise the SkPicture serialization & deserialization test pass.");
epoger@google.comcaac3db2013-04-04 19:23:11 +00001452DEFINE_bool(simulatePipePlaybackFailure, false, "Simulate a rendering failure in pipe mode only.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001453DEFINE_bool(tiledPipe, false, "Exercise tiled SkGPipe replay.");
epoger@google.com5e497382013-09-30 07:01:55 +00001454DEFINE_bool(tileGrid, false, "Exercise the tile grid variant of SkPicture.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001455DEFINE_string(tileGridReplayScales, "", "Space separated list of floating-point scale "
1456 "factors to be used for tileGrid playback testing. Default value: 1.0");
epoger@google.comb0f8b432013-04-10 18:46:25 +00001457DEFINE_bool2(verbose, v, false, "Give more detail (e.g. list all GMs run, more info about "
1458 "each test).");
epoger@google.com6f7f14d2013-06-19 18:28:31 +00001459DEFINE_bool(writeChecksumBasedFilenames, false, "When writing out actual images, use checksum-"
1460 "based filenames, as rebaseline.py will use when downloading them from Google Storage");
1461DEFINE_string(writeJsonSummaryPath, "", "Write a JSON-formatted result summary to this file.");
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001462DEFINE_string2(writePath, w, "", "Write rendered images into this directory.");
scroggo@google.com604e0c22013-04-09 21:25:46 +00001463DEFINE_string2(writePicturePath, p, "", "Write .skp files into this directory.");
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001464DEFINE_int32(pdfJpegQuality, -1, "Encodes images in JPEG at quality level N, "
1465 "which can be in range 0-100). N = -1 will disable JPEG compression. "
1466 "Default is N = 100, maximum quality.");
commit-bot@chromium.orgf4f9df42013-09-26 20:44:24 +00001467// TODO(edisonn): pass a matrix instead of forcePerspectiveMatrix
1468// Either the 9 numbers defining the matrix
1469// or probably more readable would be to replace it with a set of a few predicates
1470// Like --prerotate 100 200 10 --posttranslate 10, 10
1471// Probably define spacial names like centerx, centery, top, bottom, left, right
1472// then we can write something reabable like --rotate centerx centery 90
1473DEFINE_bool(forcePerspectiveMatrix, false, "Force a perspective matrix.");
commit-bot@chromium.org5e009892013-10-14 13:42:12 +00001474DEFINE_bool(useDocumentInsteadOfDevice, false, "Use SkDocument::CreateFoo instead of SkFooDevice.");
commit-bot@chromium.orgf4f9df42013-09-26 20:44:24 +00001475
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001476static SkData* encode_to_dct_data(size_t* pixelRefOffset, const SkBitmap& bitmap) {
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001477 // Filter output of warnings that JPEG is not available for the image.
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001478 if (bitmap.width() >= 65500 || bitmap.height() >= 65500) return NULL;
1479 if (FLAGS_pdfJpegQuality == -1) return NULL;
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001480
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001481 SkBitmap bm = bitmap;
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001482#if defined(SK_BUILD_FOR_MAC)
1483 // Workaround bug #1043 where bitmaps with referenced pixels cause
1484 // CGImageDestinationFinalize to crash
1485 SkBitmap copy;
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001486 bitmap.deepCopyTo(&copy, bitmap.config());
1487 bm = copy;
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001488#endif
1489
commit-bot@chromium.org608ea652013-10-03 19:29:21 +00001490 SkPixelRef* pr = bm.pixelRef();
1491 if (pr != NULL) {
1492 SkData* data = pr->refEncodedData();
1493 if (data != NULL) {
1494 *pixelRefOffset = bm.pixelRefOffset();
1495 return data;
1496 }
1497 }
1498
1499 *pixelRefOffset = 0;
1500 return SkImageEncoder::EncodeData(bm,
1501 SkImageEncoder::kJPEG_Type,
1502 FLAGS_pdfJpegQuality);
edisonn@google.comd9dfa182013-04-24 13:01:01 +00001503}
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001504
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001505static int findConfig(const char config[]) {
1506 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
1507 if (!strcmp(config, gRec[i].fName)) {
scroggo@google.com09fd4d22013-03-20 14:20:18 +00001508 return (int) i;
scroggo@google.com5867c0f2012-06-07 17:39:48 +00001509 }
1510 }
1511 return -1;
1512}
1513
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001514static const PDFRasterizerData* findPDFRasterizer(const char rasterizer[]) {
1515 for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); i++) {
1516 if (!strcmp(rasterizer, kPDFRasterizers[i].fName)) {
1517 return &kPDFRasterizers[i];
1518 }
1519 }
1520 return NULL;
1521}
1522
reed@google.comfb2cd422013-01-04 14:43:03 +00001523template <typename T> void appendUnique(SkTDArray<T>* array, const T& value) {
1524 int index = array->find(value);
1525 if (index < 0) {
1526 *array->append() = value;
1527 }
1528}
1529
epoger@google.com80724df2013-03-21 13:49:54 +00001530/**
1531 * Run this test in a number of different configs (8888, 565, PDF,
1532 * etc.), confirming that the resulting bitmaps match expectations
1533 * (which may be different for each config).
1534 *
1535 * Returns all errors encountered while doing so.
1536 */
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001537ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm,
1538 const SkTDArray<size_t> &configs,
1539 const SkTDArray<const PDFRasterizerData*> &pdfRasterizers,
epoger@google.com6f6568b2013-03-22 17:29:46 +00001540 GrContextFactory *grFactory);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001541ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm,
1542 const SkTDArray<size_t> &configs,
1543 const SkTDArray<const PDFRasterizerData*> &pdfRasterizers,
epoger@google.com6f6568b2013-03-22 17:29:46 +00001544 GrContextFactory *grFactory) {
epoger@google.comc8263e72013-04-10 12:17:34 +00001545 const char renderModeDescriptor[] = "";
epoger@google.com6f6568b2013-03-22 17:29:46 +00001546 ErrorCombination errorsForAllConfigs;
epoger@google.com80724df2013-03-21 13:49:54 +00001547 uint32_t gmFlags = gm->getFlags();
1548
epoger@google.com80724df2013-03-21 13:49:54 +00001549 for (int i = 0; i < configs.count(); i++) {
1550 ConfigData config = gRec[configs[i]];
epoger@google.com659c8c02013-05-21 15:45:45 +00001551 const SkString shortNamePlusConfig = gmmain.make_shortname_plus_config(gm->shortName(),
1552 config.fName);
epoger@google.com80724df2013-03-21 13:49:54 +00001553
1554 // Skip any tests that we don't even need to try.
epoger@google.comc8263e72013-04-10 12:17:34 +00001555 // If any of these were skipped on a per-GM basis, record them as
1556 // kIntentionallySkipped.
1557 if (kPDF_Backend == config.fBackend) {
epoger@google.comc8263e72013-04-10 12:17:34 +00001558 if (gmFlags & GM::kSkipPDF_Flag) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001559 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
epoger@google.comc8263e72013-04-10 12:17:34 +00001560 renderModeDescriptor);
1561 errorsForAllConfigs.add(kIntentionallySkipped_ErrorType);
1562 continue;
1563 }
1564 }
epoger@google.com80724df2013-03-21 13:49:54 +00001565 if ((gmFlags & GM::kSkip565_Flag) &&
1566 (kRaster_Backend == config.fBackend) &&
1567 (SkBitmap::kRGB_565_Config == config.fConfig)) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001568 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
epoger@google.comc8263e72013-04-10 12:17:34 +00001569 renderModeDescriptor);
1570 errorsForAllConfigs.add(kIntentionallySkipped_ErrorType);
epoger@google.com80724df2013-03-21 13:49:54 +00001571 continue;
1572 }
commit-bot@chromium.org78a10782013-08-21 19:27:48 +00001573 if (((gmFlags & GM::kSkipGPU_Flag) && kGPU_Backend == config.fBackend) ||
1574 ((gmFlags & GM::kGPUOnly_Flag) && kGPU_Backend != config.fBackend)) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001575 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
epoger@google.comc8263e72013-04-10 12:17:34 +00001576 renderModeDescriptor);
1577 errorsForAllConfigs.add(kIntentionallySkipped_ErrorType);
epoger@google.com80724df2013-03-21 13:49:54 +00001578 continue;
1579 }
1580
1581 // Now we know that we want to run this test and record its
1582 // success or failure.
epoger@google.com6f6568b2013-03-22 17:29:46 +00001583 ErrorCombination errorsForThisConfig;
bsalomon@google.com123ac1d2013-03-28 19:18:12 +00001584 GrSurface* gpuTarget = NULL;
epoger@google.com80724df2013-03-21 13:49:54 +00001585#if SK_SUPPORT_GPU
bsalomon@google.com123ac1d2013-03-28 19:18:12 +00001586 SkAutoTUnref<GrSurface> auGpuTarget;
epoger@google.com6f6568b2013-03-22 17:29:46 +00001587 if ((errorsForThisConfig.isEmpty()) && (kGPU_Backend == config.fBackend)) {
djsollen@google.comac8f3a42013-10-04 14:57:00 +00001588 if (FLAGS_resetGpuContext) {
1589 grFactory->destroyContexts();
1590 }
epoger@google.com80724df2013-03-21 13:49:54 +00001591 GrContext* gr = grFactory->get(config.fGLContextType);
1592 bool grSuccess = false;
1593 if (gr) {
1594 // create a render target to back the device
1595 GrTextureDesc desc;
1596 desc.fConfig = kSkia8888_GrPixelConfig;
1597 desc.fFlags = kRenderTarget_GrTextureFlagBit;
1598 desc.fWidth = gm->getISize().width();
1599 desc.fHeight = gm->getISize().height();
1600 desc.fSampleCnt = config.fSampleCnt;
bsalomon@google.com123ac1d2013-03-28 19:18:12 +00001601 auGpuTarget.reset(gr->createUncachedTexture(desc, NULL, 0));
1602 if (NULL != auGpuTarget) {
1603 gpuTarget = auGpuTarget;
1604 grSuccess = true;
bsalomon@google.com123ac1d2013-03-28 19:18:12 +00001605 // Set the user specified cache limits if non-default.
1606 size_t bytes;
1607 int count;
1608 gr->getTextureCacheLimits(&count, &bytes);
1609 if (DEFAULT_CACHE_VALUE != gGpuCacheSizeBytes) {
1610 bytes = static_cast<size_t>(gGpuCacheSizeBytes);
1611 }
1612 if (DEFAULT_CACHE_VALUE != gGpuCacheSizeCount) {
1613 count = gGpuCacheSizeCount;
1614 }
1615 gr->setTextureCacheLimits(count, bytes);
epoger@google.com80724df2013-03-21 13:49:54 +00001616 }
epoger@google.com80724df2013-03-21 13:49:54 +00001617 }
1618 if (!grSuccess) {
epoger@google.com6f6568b2013-03-22 17:29:46 +00001619 errorsForThisConfig.add(kNoGpuContext_ErrorType);
epoger@google.com80724df2013-03-21 13:49:54 +00001620 }
1621 }
1622#endif
1623
1624 SkBitmap comparisonBitmap;
1625
1626 const char* writePath;
1627 if (FLAGS_writePath.count() == 1) {
1628 writePath = FLAGS_writePath[0];
1629 } else {
1630 writePath = NULL;
1631 }
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001632
epoger@google.com6f6568b2013-03-22 17:29:46 +00001633 if (errorsForThisConfig.isEmpty()) {
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001634 errorsForThisConfig.add(gmmain.test_drawing(gm, config, pdfRasterizers,
1635 writePath, gpuTarget,
bsalomon@google.com123ac1d2013-03-28 19:18:12 +00001636 &comparisonBitmap));
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001637 gmmain.RecordTestResults(errorsForThisConfig, shortNamePlusConfig, "");
epoger@google.com80724df2013-03-21 13:49:54 +00001638 }
1639
epoger@google.com6f6568b2013-03-22 17:29:46 +00001640 if (FLAGS_deferred && errorsForThisConfig.isEmpty() &&
1641 (kGPU_Backend == config.fBackend || kRaster_Backend == config.fBackend)) {
1642 errorsForThisConfig.add(gmmain.test_deferred_drawing(gm, config, comparisonBitmap,
bsalomon@google.com123ac1d2013-03-28 19:18:12 +00001643 gpuTarget));
epoger@google.com80724df2013-03-21 13:49:54 +00001644 }
1645
epoger@google.com6f6568b2013-03-22 17:29:46 +00001646 errorsForAllConfigs.add(errorsForThisConfig);
epoger@google.com80724df2013-03-21 13:49:54 +00001647 }
1648 return errorsForAllConfigs;
1649}
1650
1651/**
1652 * Run this test in a number of different drawing modes (pipe,
1653 * deferred, tiled, etc.), confirming that the resulting bitmaps all
1654 * *exactly* match comparisonBitmap.
1655 *
1656 * Returns all errors encountered while doing so.
1657 */
epoger@google.com6f6568b2013-03-22 17:29:46 +00001658ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm, const ConfigData &compareConfig,
1659 const SkBitmap &comparisonBitmap,
1660 const SkTDArray<SkScalar> &tileGridReplayScales);
1661ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm, const ConfigData &compareConfig,
1662 const SkBitmap &comparisonBitmap,
1663 const SkTDArray<SkScalar> &tileGridReplayScales) {
1664 ErrorCombination errorsForAllModes;
epoger@google.com80724df2013-03-21 13:49:54 +00001665 uint32_t gmFlags = gm->getFlags();
epoger@google.com659c8c02013-05-21 15:45:45 +00001666 const SkString shortNamePlusConfig = gmmain.make_shortname_plus_config(gm->shortName(),
1667 compareConfig.fName);
epoger@google.com80724df2013-03-21 13:49:54 +00001668
epoger@google.comc8263e72013-04-10 12:17:34 +00001669 SkPicture* pict = gmmain.generate_new_picture(gm, kNone_BbhType, 0);
1670 SkAutoUnref aur(pict);
1671 if (FLAGS_replay) {
1672 const char renderModeDescriptor[] = "-replay";
1673 if (gmFlags & GM::kSkipPicture_Flag) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001674 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
1675 renderModeDescriptor);
epoger@google.comc8263e72013-04-10 12:17:34 +00001676 errorsForAllModes.add(kIntentionallySkipped_ErrorType);
1677 } else {
epoger@google.com80724df2013-03-21 13:49:54 +00001678 SkBitmap bitmap;
1679 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap);
epoger@google.comc8263e72013-04-10 12:17:34 +00001680 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap(
epoger@google.com659c8c02013-05-21 15:45:45 +00001681 gm->shortName(), compareConfig.fName, renderModeDescriptor, bitmap,
1682 &comparisonBitmap));
epoger@google.com80724df2013-03-21 13:49:54 +00001683 }
epoger@google.comc8263e72013-04-10 12:17:34 +00001684 }
epoger@google.com80724df2013-03-21 13:49:54 +00001685
epoger@google.comc8263e72013-04-10 12:17:34 +00001686 if (FLAGS_serialize) {
1687 const char renderModeDescriptor[] = "-serialize";
1688 if (gmFlags & GM::kSkipPicture_Flag) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001689 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
1690 renderModeDescriptor);
epoger@google.comc8263e72013-04-10 12:17:34 +00001691 errorsForAllModes.add(kIntentionallySkipped_ErrorType);
1692 } else {
epoger@google.com80724df2013-03-21 13:49:54 +00001693 SkPicture* repict = gmmain.stream_to_new_picture(*pict);
1694 SkAutoUnref aurr(repict);
epoger@google.com80724df2013-03-21 13:49:54 +00001695 SkBitmap bitmap;
1696 gmmain.generate_image_from_picture(gm, compareConfig, repict, &bitmap);
epoger@google.comc8263e72013-04-10 12:17:34 +00001697 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap(
epoger@google.com659c8c02013-05-21 15:45:45 +00001698 gm->shortName(), compareConfig.fName, renderModeDescriptor, bitmap,
1699 &comparisonBitmap));
epoger@google.com80724df2013-03-21 13:49:54 +00001700 }
epoger@google.com80724df2013-03-21 13:49:54 +00001701 }
1702
epoger@google.comc8263e72013-04-10 12:17:34 +00001703 if ((1 == FLAGS_writePicturePath.count()) &&
1704 !(gmFlags & GM::kSkipPicture_Flag)) {
1705 const char* pictureSuffix = "skp";
epoger@google.com659c8c02013-05-21 15:45:45 +00001706 // TODO(epoger): Make sure this still works even though the
1707 // filename now contains the config name (it used to contain
1708 // just the shortName). I think this is actually an
1709 // *improvement*, because now runs with different configs will
1710 // write out their SkPictures to separate files rather than
1711 // overwriting each other. But we should make sure it doesn't
1712 // break anybody.
1713 SkString path = gmmain.make_filename(FLAGS_writePicturePath[0], gm->shortName(),
1714 compareConfig.fName, "", pictureSuffix);
epoger@google.comc8263e72013-04-10 12:17:34 +00001715 SkFILEWStream stream(path.c_str());
1716 pict->serialize(&stream);
epoger@google.com80724df2013-03-21 13:49:54 +00001717 }
1718
epoger@google.comc8263e72013-04-10 12:17:34 +00001719 if (FLAGS_rtree) {
1720 const char renderModeDescriptor[] = "-rtree";
1721 if (gmFlags & GM::kSkipPicture_Flag) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001722 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
1723 renderModeDescriptor);
epoger@google.comc8263e72013-04-10 12:17:34 +00001724 errorsForAllModes.add(kIntentionallySkipped_ErrorType);
1725 } else {
epoger@google.com80724df2013-03-21 13:49:54 +00001726 SkPicture* pict = gmmain.generate_new_picture(
epoger@google.comc8263e72013-04-10 12:17:34 +00001727 gm, kRTree_BbhType, SkPicture::kUsePathBoundsForClip_RecordingFlag);
epoger@google.com80724df2013-03-21 13:49:54 +00001728 SkAutoUnref aur(pict);
1729 SkBitmap bitmap;
epoger@google.comc8263e72013-04-10 12:17:34 +00001730 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap);
epoger@google.com6f6568b2013-03-22 17:29:46 +00001731 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap(
epoger@google.com659c8c02013-05-21 15:45:45 +00001732 gm->shortName(), compareConfig.fName, renderModeDescriptor, bitmap,
1733 &comparisonBitmap));
epoger@google.comc8263e72013-04-10 12:17:34 +00001734 }
1735 }
1736
1737 if (FLAGS_tileGrid) {
1738 for(int scaleIndex = 0; scaleIndex < tileGridReplayScales.count(); ++scaleIndex) {
1739 SkScalar replayScale = tileGridReplayScales[scaleIndex];
1740 SkString renderModeDescriptor("-tilegrid");
1741 if (SK_Scalar1 != replayScale) {
1742 renderModeDescriptor += "-scale-";
1743 renderModeDescriptor.appendScalar(replayScale);
1744 }
1745
1746 if ((gmFlags & GM::kSkipPicture_Flag) ||
1747 ((gmFlags & GM::kSkipScaledReplay_Flag) && replayScale != 1)) {
epoger@google.com659c8c02013-05-21 15:45:45 +00001748 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig,
epoger@google.comc8263e72013-04-10 12:17:34 +00001749 renderModeDescriptor.c_str());
1750 errorsForAllModes.add(kIntentionallySkipped_ErrorType);
1751 } else {
1752 // We record with the reciprocal scale to obtain a replay
1753 // result that can be validated against comparisonBitmap.
1754 SkScalar recordScale = SkScalarInvert(replayScale);
1755 SkPicture* pict = gmmain.generate_new_picture(
1756 gm, kTileGrid_BbhType, SkPicture::kUsePathBoundsForClip_RecordingFlag,
1757 recordScale);
1758 SkAutoUnref aur(pict);
1759 SkBitmap bitmap;
1760 // We cannot yet pass 'true' to generate_image_from_picture to
1761 // perform actual tiled rendering (see Issue 1198 -
1762 // https://code.google.com/p/skia/issues/detail?id=1198)
1763 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap,
1764 replayScale /*, true */);
1765 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap(
epoger@google.com659c8c02013-05-21 15:45:45 +00001766 gm->shortName(), compareConfig.fName, renderModeDescriptor.c_str(), bitmap,
1767 &comparisonBitmap));
epoger@google.comc8263e72013-04-10 12:17:34 +00001768 }
epoger@google.com80724df2013-03-21 13:49:54 +00001769 }
1770 }
1771
1772 // run the pipe centric GM steps
epoger@google.comc8263e72013-04-10 12:17:34 +00001773 if (FLAGS_pipe) {
1774 errorsForAllModes.add(gmmain.test_pipe_playback(gm, compareConfig, comparisonBitmap,
1775 FLAGS_simulatePipePlaybackFailure));
1776 if (FLAGS_tiledPipe) {
1777 errorsForAllModes.add(gmmain.test_tiled_pipe_playback(gm, compareConfig,
1778 comparisonBitmap));
epoger@google.com80724df2013-03-21 13:49:54 +00001779 }
epoger@google.com80724df2013-03-21 13:49:54 +00001780 }
1781 return errorsForAllModes;
1782}
1783
epoger@google.com310478e2013-04-03 18:00:39 +00001784/**
epoger@google.comf711f322013-10-18 14:55:47 +00001785 * Read individual lines from a file, pushing them into the given array.
1786 *
1787 * @param filename path to the file to read
1788 * @param lines array of strings to add the lines to
1789 * @returns true if able to read lines from the file
1790 */
1791static bool read_lines_from_file(const char* filename, SkTArray<SkString> &lines) {
1792 SkAutoTUnref<SkStream> streamWrapper(SkStream::NewFromFile(filename));
1793 SkStream *stream = streamWrapper.get();
1794 if (!stream) {
1795 gm_fprintf(stderr, "unable to read file '%s'\n", filename);
1796 return false;
1797 }
1798
1799 char c;
1800 SkString line;
1801 while (1 == stream->read(&c, 1)) {
1802 // If we hit either CR or LF, we've completed a line.
1803 //
1804 // TODO: If the file uses both CR and LF, this will return an extra blank
1805 // line for each line of the file. Which is OK for current purposes...
1806 //
1807 // TODO: Does this properly handle unicode? It doesn't matter for
1808 // current purposes...
1809 if ((c == 0x0d) || (c == 0x0a)) {
1810 lines.push_back(line);
1811 line.reset();
1812 } else {
1813 line.append(&c, 1);
1814 }
1815 }
1816 lines.push_back(line);
1817 return true;
1818}
1819
1820/**
epoger@google.com310478e2013-04-03 18:00:39 +00001821 * Return a list of all entries in an array of strings as a single string
1822 * of this form:
1823 * "item1", "item2", "item3"
1824 */
1825SkString list_all(const SkTArray<SkString> &stringArray);
1826SkString list_all(const SkTArray<SkString> &stringArray) {
1827 SkString total;
1828 for (int i = 0; i < stringArray.count(); i++) {
1829 if (i > 0) {
1830 total.append(", ");
1831 }
1832 total.append("\"");
1833 total.append(stringArray[i]);
1834 total.append("\"");
1835 }
1836 return total;
1837}
1838
1839/**
1840 * Return a list of configuration names, as a single string of this form:
1841 * "item1", "item2", "item3"
1842 *
1843 * @param configs configurations, as a list of indices into gRec
1844 */
1845SkString list_all_config_names(const SkTDArray<size_t> &configs);
1846SkString list_all_config_names(const SkTDArray<size_t> &configs) {
1847 SkString total;
1848 for (int i = 0; i < configs.count(); i++) {
1849 if (i > 0) {
1850 total.append(", ");
1851 }
1852 total.append("\"");
1853 total.append(gRec[configs[i]].fName);
1854 total.append("\"");
1855 }
1856 return total;
1857}
1858
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001859static bool prepare_subdirectories(const char *root, bool useFileHierarchy,
1860 const SkTDArray<size_t> &configs,
1861 const SkTDArray<const PDFRasterizerData*>& pdfRasterizers) {
epoger@google.comfdea3252013-05-02 18:24:03 +00001862 if (!sk_mkdir(root)) {
1863 return false;
1864 }
1865 if (useFileHierarchy) {
1866 for (int i = 0; i < configs.count(); i++) {
1867 ConfigData config = gRec[configs[i]];
1868 SkString subdir;
1869 subdir.appendf("%s%c%s", root, SkPATH_SEPARATOR, config.fName);
1870 if (!sk_mkdir(subdir.c_str())) {
1871 return false;
1872 }
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001873
1874 if (config.fBackend == kPDF_Backend) {
1875 for (int j = 0; j < pdfRasterizers.count(); j++) {
1876 SkString pdfSubdir = subdir;
vandebo@chromium.org8fc37662013-08-21 18:04:09 +00001877 pdfSubdir.appendf("-%s", pdfRasterizers[j]->fName);
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001878 if (!sk_mkdir(pdfSubdir.c_str())) {
1879 return false;
1880 }
1881 }
1882 }
epoger@google.comfdea3252013-05-02 18:24:03 +00001883 }
1884 }
1885 return true;
1886}
1887
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00001888static bool parse_flags_configs(SkTDArray<size_t>* outConfigs,
1889 GrContextFactory* grFactory) {
1890 SkTDArray<size_t> excludeConfigs;
1891
1892 for (int i = 0; i < FLAGS_config.count(); i++) {
1893 const char* config = FLAGS_config[i];
1894 bool exclude = false;
1895 if (*config == kExcludeConfigChar) {
1896 exclude = true;
1897 config += 1;
1898 }
1899 int index = findConfig(config);
1900 if (index >= 0) {
1901 if (exclude) {
1902 *excludeConfigs.append() = index;
1903 } else {
1904 appendUnique<size_t>(outConfigs, index);
1905 }
1906 } else if (0 == strcmp(kDefaultsConfigStr, config)) {
1907 if (exclude) {
1908 gm_fprintf(stderr, "%c%s is not allowed.\n",
1909 kExcludeConfigChar, kDefaultsConfigStr);
1910 return false;
1911 }
1912 for (size_t c = 0; c < SK_ARRAY_COUNT(gRec); ++c) {
1913 if (gRec[c].fRunByDefault) {
1914 appendUnique<size_t>(outConfigs, c);
1915 }
1916 }
1917 } else {
1918 gm_fprintf(stderr, "unrecognized config %s\n", config);
1919 return false;
1920 }
1921 }
1922
1923 for (int i = 0; i < FLAGS_excludeConfig.count(); i++) {
1924 int index = findConfig(FLAGS_excludeConfig[i]);
1925 if (index >= 0) {
1926 *excludeConfigs.append() = index;
1927 } else {
1928 gm_fprintf(stderr, "unrecognized excludeConfig %s\n", FLAGS_excludeConfig[i]);
1929 return false;
1930 }
1931 }
1932
1933 if (outConfigs->count() == 0) {
1934 // if no config is specified by user, add the defaults
1935 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
1936 if (gRec[i].fRunByDefault) {
1937 *outConfigs->append() = i;
1938 }
1939 }
1940 }
1941 // now remove any explicitly excluded configs
1942 for (int i = 0; i < excludeConfigs.count(); ++i) {
1943 int index = outConfigs->find(excludeConfigs[i]);
1944 if (index >= 0) {
1945 outConfigs->remove(index);
1946 // now assert that there was only one copy in configs[]
1947 SkASSERT(outConfigs->find(excludeConfigs[i]) < 0);
1948 }
1949 }
1950
1951#if SK_SUPPORT_GPU
1952 SkASSERT(grFactory != NULL);
1953 for (int i = 0; i < outConfigs->count(); ++i) {
1954 size_t index = (*outConfigs)[i];
1955 if (kGPU_Backend == gRec[index].fBackend) {
1956 GrContext* ctx = grFactory->get(gRec[index].fGLContextType);
1957 if (NULL == ctx) {
1958 gm_fprintf(stderr, "GrContext could not be created for config %s."
1959 " Config will be skipped.\n", gRec[index].fName);
1960 outConfigs->remove(i);
1961 --i;
1962 continue;
1963 }
1964 if (gRec[index].fSampleCnt > ctx->getMaxSampleCount()) {
1965 gm_fprintf(stderr, "Sample count (%d) of config %s is not supported."
1966 " Config will be skipped.\n",
1967 gRec[index].fSampleCnt, gRec[index].fName);
1968 outConfigs->remove(i);
1969 --i;
1970 }
1971 }
1972 }
1973#endif
1974
1975 if (outConfigs->isEmpty()) {
1976 gm_fprintf(stderr, "No configs to run.");
1977 return false;
1978 }
1979
1980 // now show the user the set of configs that will be run.
1981 SkString configStr("These configs will be run:");
1982 // show the user the config that will run.
1983 for (int i = 0; i < outConfigs->count(); ++i) {
1984 configStr.appendf(" %s", gRec[(*outConfigs)[i]].fName);
1985 }
1986 gm_fprintf(stdout, "%s\n", configStr.c_str());
1987
1988 return true;
1989}
1990
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00001991static bool parse_flags_pdf_rasterizers(const SkTDArray<size_t>& configs,
1992 SkTDArray<const PDFRasterizerData*>* outRasterizers) {
1993 // No need to run this check (and display the PDF rasterizers message)
1994 // if no PDF backends are in the configs.
1995 bool configHasPDF = false;
1996 for (int i = 0; i < configs.count(); i++) {
1997 if (gRec[configs[i]].fBackend == kPDF_Backend) {
1998 configHasPDF = true;
1999 break;
2000 }
2001 }
2002 if (!configHasPDF) {
2003 return true;
2004 }
2005
2006 for (int i = 0; i < FLAGS_pdfRasterizers.count(); i++) {
2007 const char* rasterizer = FLAGS_pdfRasterizers[i];
2008 const PDFRasterizerData* rasterizerPtr = findPDFRasterizer(rasterizer);
2009
2010 if (rasterizerPtr == NULL) {
2011 gm_fprintf(stderr, "unrecognized rasterizer %s\n", rasterizer);
2012 return false;
2013 }
2014 appendUnique<const PDFRasterizerData*>(outRasterizers,
2015 rasterizerPtr);
2016 }
2017
2018 if (outRasterizers->count() == 0) {
2019 // if no config is specified by user, add the defaults
2020 for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); ++i) {
2021 if (kPDFRasterizers[i].fRunByDefault) {
2022 *outRasterizers->append() = &kPDFRasterizers[i];
2023 }
2024 }
2025 }
2026
2027 // now show the user the set of configs that will be run.
2028 SkString configStr("These PDF rasterizers will be run:");
2029 // show the user the config that will run.
2030 for (int i = 0; i < outRasterizers->count(); ++i) {
2031 configStr.appendf(" %s", (*outRasterizers)[i]->fName);
2032 }
2033 gm_fprintf(stdout, "%s\n", configStr.c_str());
2034
2035 return true;
2036}
2037
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002038static bool parse_flags_ignore_error_types(ErrorCombination* outErrorTypes) {
2039 if (FLAGS_ignoreErrorTypes.count() > 0) {
2040 *outErrorTypes = ErrorCombination();
2041 for (int i = 0; i < FLAGS_ignoreErrorTypes.count(); i++) {
2042 ErrorType type;
2043 const char *name = FLAGS_ignoreErrorTypes[i];
2044 if (!getErrorTypeByName(name, &type)) {
2045 gm_fprintf(stderr, "cannot find ErrorType with name '%s'\n", name);
2046 return false;
2047 } else {
2048 outErrorTypes->add(type);
2049 }
2050 }
2051 }
2052 return true;
2053}
2054
epoger@google.com3a882dd2013-10-07 18:55:09 +00002055/**
2056 * Replace contents of ignoreTestSubstrings with a list of testname/config substrings, indicating
2057 * which tests' failures should be ignored.
2058 */
2059static bool parse_flags_ignore_tests(SkTArray<SkString> &ignoreTestSubstrings) {
2060 ignoreTestSubstrings.reset();
epoger@google.comf711f322013-10-18 14:55:47 +00002061
epoger@google.comf711f322013-10-18 14:55:47 +00002062 // Parse --ignoreFailuresFile
2063 for (int i = 0; i < FLAGS_ignoreFailuresFile.count(); i++) {
2064 SkTArray<SkString> linesFromFile;
2065 if (!read_lines_from_file(FLAGS_ignoreFailuresFile[i], linesFromFile)) {
2066 return false;
2067 } else {
2068 for (int j = 0; j < linesFromFile.count(); j++) {
2069 SkString thisLine = linesFromFile[j];
2070 if (thisLine.isEmpty() || thisLine.startsWith('#')) {
2071 // skip this line
2072 } else {
2073 ignoreTestSubstrings.push_back(thisLine);
2074 }
2075 }
2076 }
2077 }
2078
epoger@google.com3a882dd2013-10-07 18:55:09 +00002079 return true;
2080}
2081
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002082static bool parse_flags_modulo(int* moduloRemainder, int* moduloDivisor) {
2083 if (FLAGS_modulo.count() == 2) {
2084 *moduloRemainder = atoi(FLAGS_modulo[0]);
2085 *moduloDivisor = atoi(FLAGS_modulo[1]);
2086 if (*moduloRemainder < 0 || *moduloDivisor <= 0 ||
2087 *moduloRemainder >= *moduloDivisor) {
2088 gm_fprintf(stderr, "invalid modulo values.");
2089 return false;
2090 }
2091 }
2092 return true;
2093}
2094
2095#if SK_SUPPORT_GPU
2096static bool parse_flags_gpu_cache(int* sizeBytes, int* sizeCount) {
2097 if (FLAGS_gpuCacheSize.count() > 0) {
2098 if (FLAGS_gpuCacheSize.count() != 2) {
2099 gm_fprintf(stderr, "--gpuCacheSize requires two arguments\n");
2100 return false;
2101 }
2102 *sizeBytes = atoi(FLAGS_gpuCacheSize[0]);
2103 *sizeCount = atoi(FLAGS_gpuCacheSize[1]);
2104 } else {
2105 *sizeBytes = DEFAULT_CACHE_VALUE;
2106 *sizeCount = DEFAULT_CACHE_VALUE;
2107 }
2108 return true;
2109}
2110#endif
2111
2112static bool parse_flags_tile_grid_replay_scales(SkTDArray<SkScalar>* outScales) {
2113 *outScales->append() = SK_Scalar1; // By default only test at scale 1.0
2114 if (FLAGS_tileGridReplayScales.count() > 0) {
2115 outScales->reset();
2116 for (int i = 0; i < FLAGS_tileGridReplayScales.count(); i++) {
2117 double val = atof(FLAGS_tileGridReplayScales[i]);
2118 if (0 < val) {
2119 *outScales->append() = SkDoubleToScalar(val);
2120 }
2121 }
2122 if (0 == outScales->count()) {
2123 // Should have at least one scale
2124 gm_fprintf(stderr, "--tileGridReplayScales requires at least one scale.\n");
2125 return false;
2126 }
2127 }
2128 return true;
2129}
2130
2131static bool parse_flags_gmmain_paths(GMMain* gmmain) {
2132 gmmain->fUseFileHierarchy = FLAGS_hierarchy;
2133 gmmain->fWriteChecksumBasedFilenames = FLAGS_writeChecksumBasedFilenames;
2134
2135 if (FLAGS_mismatchPath.count() == 1) {
2136 gmmain->fMismatchPath = FLAGS_mismatchPath[0];
2137 }
2138
2139 if (FLAGS_missingExpectationsPath.count() == 1) {
2140 gmmain->fMissingExpectationsPath = FLAGS_missingExpectationsPath[0];
2141 }
2142
2143 if (FLAGS_readPath.count() == 1) {
2144 const char* readPath = FLAGS_readPath[0];
2145 if (!sk_exists(readPath)) {
2146 gm_fprintf(stderr, "readPath %s does not exist!\n", readPath);
2147 return false;
2148 }
2149 if (sk_isdir(readPath)) {
2150 if (FLAGS_verbose) {
2151 gm_fprintf(stdout, "reading from %s\n", readPath);
2152 }
2153 gmmain->fExpectationsSource.reset(SkNEW_ARGS(
2154 IndividualImageExpectationsSource, (readPath)));
2155 } else {
2156 if (FLAGS_verbose) {
2157 gm_fprintf(stdout, "reading expectations from JSON summary file %s\n", readPath);
2158 }
2159 gmmain->fExpectationsSource.reset(SkNEW_ARGS(JsonExpectationsSource, (readPath)));
2160 }
2161 }
2162 return true;
2163}
2164
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002165static bool parse_flags_resource_path() {
2166 if (FLAGS_resourcePath.count() == 1) {
2167 GM::SetResourcePath(FLAGS_resourcePath[0]);
2168 }
2169 return true;
2170}
2171
2172static bool parse_flags_jpeg_quality() {
2173 if (FLAGS_pdfJpegQuality < -1 || FLAGS_pdfJpegQuality > 100) {
2174 gm_fprintf(stderr, "%s\n", "pdfJpegQuality must be in [-1 .. 100] range.");
2175 return false;
2176 }
2177 return true;
2178}
2179
epoger@google.com0b62b3d2013-03-20 17:59:28 +00002180int tool_main(int argc, char** argv);
2181int tool_main(int argc, char** argv) {
2182
2183#if SK_ENABLE_INST_COUNT
2184 gPrintInstCount = true;
2185#endif
2186
2187 SkGraphics::Init();
2188 // we don't need to see this during a run
2189 gSkSuppressFontCachePurgeSpew = true;
2190
2191 setSystemPreferences();
2192 GMMain gmmain;
2193
epoger@google.com0b62b3d2013-03-20 17:59:28 +00002194 SkString usage;
2195 usage.printf("Run the golden master tests.\n");
scroggo@google.comd9ba9a02013-03-21 19:43:15 +00002196 SkCommandLineFlags::SetUsage(usage.c_str());
2197 SkCommandLineFlags::Parse(argc, argv);
epoger@google.com0b62b3d2013-03-20 17:59:28 +00002198
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002199 SkTDArray<size_t> configs;
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002200
scroggo@google.com09fd4d22013-03-20 14:20:18 +00002201 int moduloRemainder = -1;
2202 int moduloDivisor = -1;
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002203 SkTDArray<const PDFRasterizerData*> pdfRasterizers;
epoger@google.com6f6568b2013-03-22 17:29:46 +00002204 SkTDArray<SkScalar> tileGridReplayScales;
bsalomon@google.com4c75f242013-03-19 18:58:43 +00002205#if SK_SUPPORT_GPU
2206 GrContextFactory* grFactory = new GrContextFactory;
epoger@google.com80724df2013-03-21 13:49:54 +00002207#else
2208 GrContextFactory* grFactory = NULL;
bsalomon@google.com4c75f242013-03-19 18:58:43 +00002209#endif
2210
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002211 if (!parse_flags_modulo(&moduloRemainder, &moduloDivisor) ||
2212 !parse_flags_ignore_error_types(&gmmain.fIgnorableErrorTypes) ||
epoger@google.com3a882dd2013-10-07 18:55:09 +00002213 !parse_flags_ignore_tests(gmmain.fIgnorableTestSubstrings) ||
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002214#if SK_SUPPORT_GPU
2215 !parse_flags_gpu_cache(&gGpuCacheSizeBytes, &gGpuCacheSizeCount) ||
2216#endif
2217 !parse_flags_tile_grid_replay_scales(&tileGridReplayScales) ||
2218 !parse_flags_resource_path() ||
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002219 !parse_flags_jpeg_quality() ||
2220 !parse_flags_configs(&configs, grFactory) ||
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002221 !parse_flags_pdf_rasterizers(configs, &pdfRasterizers) ||
commit-bot@chromium.orgab882bf2013-08-14 21:56:47 +00002222 !parse_flags_gmmain_paths(&gmmain)) {
bsalomon@google.comdd8e3532013-04-24 18:07:11 +00002223 return -1;
2224 }
2225
epoger@google.comb0f8b432013-04-10 18:46:25 +00002226 if (FLAGS_verbose) {
2227 if (FLAGS_writePath.count() == 1) {
2228 gm_fprintf(stdout, "writing to %s\n", FLAGS_writePath[0]);
2229 }
epoger@google.comfdea3252013-05-02 18:24:03 +00002230 if (NULL != gmmain.fMismatchPath) {
2231 gm_fprintf(stdout, "writing mismatches to %s\n", gmmain.fMismatchPath);
2232 }
epoger@google.com5f995452013-06-21 18:16:47 +00002233 if (NULL != gmmain.fMissingExpectationsPath) {
2234 gm_fprintf(stdout, "writing images without expectations to %s\n",
2235 gmmain.fMissingExpectationsPath);
2236 }
epoger@google.comb0f8b432013-04-10 18:46:25 +00002237 if (FLAGS_writePicturePath.count() == 1) {
2238 gm_fprintf(stdout, "writing pictures to %s\n", FLAGS_writePicturePath[0]);
2239 }
2240 if (FLAGS_resourcePath.count() == 1) {
2241 gm_fprintf(stdout, "reading resources from %s\n", FLAGS_resourcePath[0]);
2242 }
robertphillips@google.com8570b5c2012-03-20 17:40:58 +00002243 }
2244
epoger@google.com310478e2013-04-03 18:00:39 +00002245 int gmsRun = 0;
reed@google.comae7b8f32012-10-18 21:30:57 +00002246 int gmIndex = -1;
2247 SkString moduloStr;
2248
epoger@google.come8ebeb12012-10-29 16:42:11 +00002249 // If we will be writing out files, prepare subdirectories.
scroggo@google.com09fd4d22013-03-20 14:20:18 +00002250 if (FLAGS_writePath.count() == 1) {
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002251 if (!prepare_subdirectories(FLAGS_writePath[0], gmmain.fUseFileHierarchy,
2252 configs, pdfRasterizers)) {
epoger@google.come8ebeb12012-10-29 16:42:11 +00002253 return -1;
2254 }
epoger@google.comfdea3252013-05-02 18:24:03 +00002255 }
2256 if (NULL != gmmain.fMismatchPath) {
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002257 if (!prepare_subdirectories(gmmain.fMismatchPath, gmmain.fUseFileHierarchy,
2258 configs, pdfRasterizers)) {
epoger@google.comfdea3252013-05-02 18:24:03 +00002259 return -1;
epoger@google.come8ebeb12012-10-29 16:42:11 +00002260 }
2261 }
epoger@google.com5f995452013-06-21 18:16:47 +00002262 if (NULL != gmmain.fMissingExpectationsPath) {
2263 if (!prepare_subdirectories(gmmain.fMissingExpectationsPath, gmmain.fUseFileHierarchy,
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002264 configs, pdfRasterizers)) {
epoger@google.com5f995452013-06-21 18:16:47 +00002265 return -1;
2266 }
2267 }
epoger@google.come8ebeb12012-10-29 16:42:11 +00002268
bsalomon@google.com7361f542012-04-19 19:15:35 +00002269 Iter iter;
2270 GM* gm;
reed@android.com00dae862009-06-10 15:38:48 +00002271 while ((gm = iter.next()) != NULL) {
commit-bot@chromium.orgf4f9df42013-09-26 20:44:24 +00002272 if (FLAGS_forcePerspectiveMatrix) {
2273 SkMatrix perspective;
2274 perspective.setIdentity();
2275 perspective.setPerspY(SkScalarDiv(SK_Scalar1, SkIntToScalar(1000)));
2276 perspective.setSkewX(SkScalarDiv(SkIntToScalar(8),
2277 SkIntToScalar(25)));
2278
2279 gm->setStarterMatrix(perspective);
skia.committer@gmail.com65caeaf2013-09-27 07:01:29 +00002280 }
scroggo@google.com7fd2d702013-04-16 19:11:14 +00002281 SkAutoTDelete<GM> adgm(gm);
reed@google.comae7b8f32012-10-18 21:30:57 +00002282 ++gmIndex;
epoger@google.com82cb65b2012-10-29 18:59:17 +00002283 if (moduloRemainder >= 0) {
2284 if ((gmIndex % moduloDivisor) != moduloRemainder) {
reed@google.comae7b8f32012-10-18 21:30:57 +00002285 continue;
2286 }
epoger@google.com82cb65b2012-10-29 18:59:17 +00002287 moduloStr.printf("[%d.%d] ", gmIndex, moduloDivisor);
reed@google.comae7b8f32012-10-18 21:30:57 +00002288 }
2289
reed@google.comece2b022011-07-25 14:28:57 +00002290 const char* shortName = gm->shortName();
sglez@google.com586db932013-07-24 17:24:23 +00002291
commit-bot@chromium.orga6f37e72013-08-30 15:52:46 +00002292 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, shortName)) {
reed@google.comece2b022011-07-25 14:28:57 +00002293 continue;
2294 }
2295
epoger@google.com310478e2013-04-03 18:00:39 +00002296 gmsRun++;
tomhudson@google.com9875dd12011-04-25 15:49:53 +00002297 SkISize size = gm->getISize();
epoger@google.combcbf5aa2013-04-12 02:11:54 +00002298 gm_fprintf(stdout, "%sdrawing... %s [%d %d]\n", moduloStr.c_str(), shortName,
2299 size.width(), size.height());
djsollen@google.comebce16d2012-10-26 14:07:13 +00002300
vandebo@chromium.org0dcbece2013-08-20 23:08:40 +00002301 run_multiple_configs(gmmain, gm, configs, pdfRasterizers, grFactory);
djsollen@google.comebce16d2012-10-26 14:07:13 +00002302
2303 SkBitmap comparisonBitmap;
2304 const ConfigData compareConfig =
bsalomon@google.com4c75f242013-03-19 18:58:43 +00002305 { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "comparison", false };
epoger@google.com310478e2013-04-03 18:00:39 +00002306 gmmain.generate_image(gm, compareConfig, NULL, &comparisonBitmap, false);
djsollen@google.comebce16d2012-10-26 14:07:13 +00002307
epoger@google.com80724df2013-03-21 13:49:54 +00002308 // TODO(epoger): only run this if gmmain.generate_image() succeeded?
2309 // Otherwise, what are we comparing against?
epoger@google.com310478e2013-04-03 18:00:39 +00002310 run_multiple_modes(gmmain, gm, compareConfig, comparisonBitmap, tileGridReplayScales);
reed@android.com00dae862009-06-10 15:38:48 +00002311 }
epoger@google.com310478e2013-04-03 18:00:39 +00002312
2313 SkTArray<SkString> modes;
2314 gmmain.GetRenderModesEncountered(modes);
epoger@google.comc8263e72013-04-10 12:17:34 +00002315 bool reportError = false;
2316 if (gmmain.NumSignificantErrors() > 0) {
2317 reportError = true;
2318 }
epoger@google.com51dbabe2013-04-10 15:24:53 +00002319 int expectedNumberOfTests = gmsRun * (configs.count() + modes.count());
epoger@google.com310478e2013-04-03 18:00:39 +00002320
2321 // Output summary to stdout.
epoger@google.com51dbabe2013-04-10 15:24:53 +00002322 if (FLAGS_verbose) {
2323 gm_fprintf(stdout, "Ran %d GMs\n", gmsRun);
2324 gm_fprintf(stdout, "... over %2d configs [%s]\n", configs.count(),
2325 list_all_config_names(configs).c_str());
2326 gm_fprintf(stdout, "... and %2d modes [%s]\n", modes.count(), list_all(modes).c_str());
2327 gm_fprintf(stdout, "... so there should be a total of %d tests.\n", expectedNumberOfTests);
2328 }
2329 gmmain.ListErrors(FLAGS_verbose);
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00002330
epoger@google.com07947d92013-04-11 15:41:02 +00002331 // TODO(epoger): Enable this check for Android, too, once we resolve
2332 // https://code.google.com/p/skia/issues/detail?id=1222
2333 // ('GM is unexpectedly skipping tests on Android')
2334#ifndef SK_BUILD_FOR_ANDROID
epoger@google.comc8263e72013-04-10 12:17:34 +00002335 if (expectedNumberOfTests != gmmain.fTestsRun) {
2336 gm_fprintf(stderr, "expected %d tests, but ran or skipped %d tests\n",
2337 expectedNumberOfTests, gmmain.fTestsRun);
2338 reportError = true;
2339 }
2340#endif
2341
scroggo@google.com09fd4d22013-03-20 14:20:18 +00002342 if (FLAGS_writeJsonSummaryPath.count() == 1) {
epoger@google.com76c913d2013-04-26 15:06:44 +00002343 Json::Value root = CreateJsonTree(
2344 gmmain.fJsonExpectedResults,
2345 gmmain.fJsonActualResults_Failed, gmmain.fJsonActualResults_FailureIgnored,
2346 gmmain.fJsonActualResults_NoComparison, gmmain.fJsonActualResults_Succeeded);
epoger@google.comee8a8e32012-12-18 19:13:49 +00002347 std::string jsonStdString = root.toStyledString();
scroggo@google.com09fd4d22013-03-20 14:20:18 +00002348 SkFILEWStream stream(FLAGS_writeJsonSummaryPath[0]);
epoger@google.comee8a8e32012-12-18 19:13:49 +00002349 stream.write(jsonStdString.c_str(), jsonStdString.length());
2350 }
2351
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00002352#if SK_SUPPORT_GPU
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00002353
robertphillips@google.com59552022012-08-31 13:07:37 +00002354#if GR_CACHE_STATS
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00002355 for (int i = 0; i < configs.count(); i++) {
2356 ConfigData config = gRec[configs[i]];
2357
epoger@google.comb0f8b432013-04-10 18:46:25 +00002358 if (FLAGS_verbose && (kGPU_Backend == config.fBackend)) {
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00002359 GrContext* gr = grFactory->get(config.fGLContextType);
2360
epoger@google.com5efdd0c2013-03-13 14:18:40 +00002361 gm_fprintf(stdout, "config: %s %x\n", config.fName, gr);
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +00002362 gr->printCacheStats();
2363 }
2364 }
2365#endif
2366
robertphillips@google.com977b9c82012-06-05 19:35:09 +00002367 delete grFactory;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +00002368#endif
robertphillips@google.com977b9c82012-06-05 19:35:09 +00002369 SkGraphics::Term();
2370
epoger@google.comc8263e72013-04-10 12:17:34 +00002371 return (reportError) ? -1 : 0;
reed@android.com00dae862009-06-10 15:38:48 +00002372}
caryclark@google.com5987f582012-10-02 18:33:14 +00002373
scroggo@google.com09fd4d22013-03-20 14:20:18 +00002374void GMMain::installFilter(SkCanvas* canvas) {
2375 if (FLAGS_forceBWtext) {
2376 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref();
2377 }
2378}
2379
borenet@google.com7158e6a2012-11-01 17:43:44 +00002380#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
caryclark@google.com5987f582012-10-02 18:33:14 +00002381int main(int argc, char * const argv[]) {
2382 return tool_main(argc, (char**) argv);
2383}
2384#endif