blob: c1304a2b35a1a0d9d53cf29375654fe1db15f52f [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
bungeman@google.comb29c8832011-10-10 13:19:10 +00008#include "gm.h"
bsalomon@google.com971d0c82011-08-19 17:22:05 +00009#include "GrContext.h"
10#include "GrRenderTarget.h"
11
reed@android.comb9b9a182009-07-08 02:54:47 +000012#include "SkColorPriv.h"
reed@google.com8a85d0c2011-06-24 19:12:12 +000013#include "SkData.h"
junov@google.com4370aed2012-01-18 16:21:08 +000014#include "SkDeferredCanvas.h"
bsalomon@google.com971d0c82011-08-19 17:22:05 +000015#include "SkDevice.h"
bsalomon@google.com971d0c82011-08-19 17:22:05 +000016#include "SkGpuCanvas.h"
17#include "SkGpuDevice.h"
reed@android.com8015dd82009-06-21 00:49:18 +000018#include "SkGraphics.h"
19#include "SkImageDecoder.h"
20#include "SkImageEncoder.h"
bsalomon@google.com373a6632011-10-19 20:43:20 +000021#include "SkNativeGLContext.h"
22#include "SkMesaGLContext.h"
tomhudson@google.com9875dd12011-04-25 15:49:53 +000023#include "SkPicture.h"
reed@google.com07700442010-12-20 19:46:07 +000024#include "SkStream.h"
25#include "SkRefCnt.h"
26
mike@reedtribe.org10afbef2011-12-30 16:02:53 +000027static bool gForceBWtext;
28
reed@google.com8923c6c2011-11-08 14:59:38 +000029extern bool gSkSuppressFontCachePurgeSpew;
30
reed@google.com07700442010-12-20 19:46:07 +000031#ifdef SK_SUPPORT_PDF
tomhudson@google.com9875dd12011-04-25 15:49:53 +000032 #include "SkPDFDevice.h"
33 #include "SkPDFDocument.h"
reed@google.com07700442010-12-20 19:46:07 +000034#endif
reed@android.com00dae862009-06-10 15:38:48 +000035
epoger@google.come3cc2eb2012-01-18 20:11:13 +000036// Until we resolve http://code.google.com/p/skia/issues/detail?id=455 ,
37// stop writing out XPS-format image baselines in gm.
38#undef SK_SUPPORT_XPS
bungeman@google.comb29c8832011-10-10 13:19:10 +000039#ifdef SK_SUPPORT_XPS
40 #include "SkXPSDevice.h"
41#endif
42
reed@google.com46cce912011-06-29 12:54:46 +000043#ifdef SK_BUILD_FOR_MAC
44 #include "SkCGUtils.h"
bsalomon@google.com0a09eef2011-06-29 19:42:58 +000045 #define CAN_IMAGE_PDF 1
reed@google.com46cce912011-06-29 12:54:46 +000046#else
bsalomon@google.com0a09eef2011-06-29 19:42:58 +000047 #define CAN_IMAGE_PDF 0
reed@google.com46cce912011-06-29 12:54:46 +000048#endif
49
epoger@google.comc7cf2b32011-12-28 19:31:01 +000050typedef int ErrorBitfield;
51const static ErrorBitfield ERROR_NONE = 0x00;
52const static ErrorBitfield ERROR_NO_GPU_CONTEXT = 0x01;
53const static ErrorBitfield ERROR_PIXEL_MISMATCH = 0x02;
54const static ErrorBitfield ERROR_DIMENSION_MISMATCH = 0x04;
55const static ErrorBitfield ERROR_READING_REFERENCE_IMAGE = 0x08;
56const static ErrorBitfield ERROR_WRITING_REFERENCE_IMAGE = 0x10;
57
reed@android.com00dae862009-06-10 15:38:48 +000058using namespace skiagm;
59
reed@android.com00dae862009-06-10 15:38:48 +000060class Iter {
61public:
62 Iter() {
bsalomon@google.com39149582011-06-13 21:55:32 +000063 this->reset();
64 }
65
66 void reset() {
reed@android.comdd0ac282009-06-20 02:38:16 +000067 fReg = GMRegistry::Head();
reed@android.com00dae862009-06-10 15:38:48 +000068 }
reed@google.comd4dfd102011-01-18 21:05:42 +000069
reed@android.comdd0ac282009-06-20 02:38:16 +000070 GM* next() {
reed@android.com00dae862009-06-10 15:38:48 +000071 if (fReg) {
reed@android.comdd0ac282009-06-20 02:38:16 +000072 GMRegistry::Factory fact = fReg->factory();
reed@android.com00dae862009-06-10 15:38:48 +000073 fReg = fReg->next();
reed@android.comdd0ac282009-06-20 02:38:16 +000074 return fact(0);
reed@android.com00dae862009-06-10 15:38:48 +000075 }
76 return NULL;
77 }
reed@google.comd4dfd102011-01-18 21:05:42 +000078
reed@android.com00dae862009-06-10 15:38:48 +000079 static int Count() {
reed@android.comdd0ac282009-06-20 02:38:16 +000080 const GMRegistry* reg = GMRegistry::Head();
reed@android.com00dae862009-06-10 15:38:48 +000081 int count = 0;
82 while (reg) {
83 count += 1;
84 reg = reg->next();
85 }
86 return count;
87 }
reed@google.comd4dfd102011-01-18 21:05:42 +000088
reed@android.com00dae862009-06-10 15:38:48 +000089private:
90 const GMRegistry* fReg;
91};
92
reed@android.com8015dd82009-06-21 00:49:18 +000093static SkString make_name(const char shortName[], const char configName[]) {
94 SkString name(shortName);
95 name.appendf("_%s", configName);
96 return name;
97}
98
tomhudson@google.com9875dd12011-04-25 15:49:53 +000099static SkString make_filename(const char path[],
100 const char pathSuffix[],
101 const SkString& name,
102 const char suffix[]) {
reed@android.com8015dd82009-06-21 00:49:18 +0000103 SkString filename(path);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000104 if (filename.endsWith("/")) {
105 filename.remove(filename.size() - 1, 1);
reed@android.com00dae862009-06-10 15:38:48 +0000106 }
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000107 filename.append(pathSuffix);
108 filename.append("/");
reed@google.com07700442010-12-20 19:46:07 +0000109 filename.appendf("%s.%s", name.c_str(), suffix);
reed@android.com8015dd82009-06-21 00:49:18 +0000110 return filename;
111}
112
reed@android.comb9b9a182009-07-08 02:54:47 +0000113/* since PNG insists on unpremultiplying our alpha, we take no precision chances
114 and force all pixels to be 100% opaque, otherwise on compare we may not get
115 a perfect match.
116 */
117static void force_all_opaque(const SkBitmap& bitmap) {
118 SkAutoLockPixels lock(bitmap);
119 for (int y = 0; y < bitmap.height(); y++) {
120 for (int x = 0; x < bitmap.width(); x++) {
121 *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT);
122 }
123 }
124}
125
126static bool write_bitmap(const SkString& path, const SkBitmap& bitmap) {
127 SkBitmap copy;
128 bitmap.copyTo(&copy, SkBitmap::kARGB_8888_Config);
129 force_all_opaque(copy);
130 return SkImageEncoder::EncodeFile(path.c_str(), copy,
131 SkImageEncoder::kPNG_Type, 100);
132}
133
reed@google.com3d3f0922010-12-20 21:10:29 +0000134static inline SkPMColor compute_diff_pmcolor(SkPMColor c0, SkPMColor c1) {
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000135 int dr = SkGetPackedR32(c0) - SkGetPackedR32(c1);
136 int dg = SkGetPackedG32(c0) - SkGetPackedG32(c1);
137 int db = SkGetPackedB32(c0) - SkGetPackedB32(c1);
138 return SkPackARGB32(0xFF, SkAbs32(dr), SkAbs32(dg), SkAbs32(db));
reed@google.com3d3f0922010-12-20 21:10:29 +0000139}
140
141static void compute_diff(const SkBitmap& target, const SkBitmap& base,
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000142 SkBitmap* diff) {
143 SkAutoLockPixels alp(*diff);
reed@google.com3d3f0922010-12-20 21:10:29 +0000144
145 const int w = target.width();
146 const int h = target.height();
147 for (int y = 0; y < h; y++) {
148 for (int x = 0; x < w; x++) {
149 SkPMColor c0 = *base.getAddr32(x, y);
150 SkPMColor c1 = *target.getAddr32(x, y);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000151 SkPMColor d = 0;
152 if (c0 != c1) {
153 d = compute_diff_pmcolor(c0, c1);
154 }
155 *diff->getAddr32(x, y) = d;
156 }
157 }
reed@google.com3d3f0922010-12-20 21:10:29 +0000158}
159
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000160static ErrorBitfield compare(const SkBitmap& target, const SkBitmap& base,
161 const SkString& name,
162 const char* renderModeDescriptor,
163 SkBitmap* diff) {
reed@android.comb9b9a182009-07-08 02:54:47 +0000164 SkBitmap copy;
165 const SkBitmap* bm = &target;
166 if (target.config() != SkBitmap::kARGB_8888_Config) {
167 target.copyTo(&copy, SkBitmap::kARGB_8888_Config);
168 bm = &copy;
169 }
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000170 SkBitmap baseCopy;
171 const SkBitmap* bp = &base;
172 if (base.config() != SkBitmap::kARGB_8888_Config) {
173 base.copyTo(&baseCopy, SkBitmap::kARGB_8888_Config);
174 bp = &baseCopy;
175 }
reed@android.comb9b9a182009-07-08 02:54:47 +0000176
177 force_all_opaque(*bm);
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000178 force_all_opaque(*bp);
reed@android.comb9b9a182009-07-08 02:54:47 +0000179
180 const int w = bm->width();
181 const int h = bm->height();
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000182 if (w != bp->width() || h != bp->height()) {
tomhudson@google.comea325432011-06-09 20:30:03 +0000183 SkDebugf(
184"---- %s dimensions mismatch for %s base [%d %d] current [%d %d]\n",
185 renderModeDescriptor, name.c_str(),
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000186 bp->width(), bp->height(), w, h);
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000187 return ERROR_DIMENSION_MISMATCH;
reed@android.comb9b9a182009-07-08 02:54:47 +0000188 }
189
190 SkAutoLockPixels bmLock(*bm);
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000191 SkAutoLockPixels baseLock(*bp);
reed@android.comb9b9a182009-07-08 02:54:47 +0000192
193 for (int y = 0; y < h; y++) {
194 for (int x = 0; x < w; x++) {
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000195 SkPMColor c0 = *bp->getAddr32(x, y);
reed@android.comb9b9a182009-07-08 02:54:47 +0000196 SkPMColor c1 = *bm->getAddr32(x, y);
197 if (c0 != c1) {
tomhudson@google.comea325432011-06-09 20:30:03 +0000198 SkDebugf(
199"----- %s pixel mismatch for %s at [%d %d] base 0x%08X current 0x%08X\n",
200 renderModeDescriptor, name.c_str(), x, y, c0, c1);
reed@google.com3d3f0922010-12-20 21:10:29 +0000201
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000202 if (diff) {
203 diff->setConfig(SkBitmap::kARGB_8888_Config, w, h);
204 diff->allocPixels();
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000205 compute_diff(*bm, *bp, diff);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000206 }
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000207 return ERROR_PIXEL_MISMATCH;
reed@android.comb9b9a182009-07-08 02:54:47 +0000208 }
209 }
210 }
reed@google.com3d3f0922010-12-20 21:10:29 +0000211
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000212 // they're equal
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000213 return ERROR_NONE;
reed@android.com8015dd82009-06-21 00:49:18 +0000214}
reed@android.com00dae862009-06-10 15:38:48 +0000215
bungeman@google.comb29c8832011-10-10 13:19:10 +0000216static bool write_document(const SkString& path,
217 const SkDynamicMemoryWStream& document) {
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000218 SkFILEWStream stream(path.c_str());
bungeman@google.comb29c8832011-10-10 13:19:10 +0000219 SkAutoDataUnref data(document.copyToData());
reed@google.com8a85d0c2011-06-24 19:12:12 +0000220 return stream.writeData(data.get());
reed@google.com07700442010-12-20 19:46:07 +0000221}
222
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000223enum Backend {
224 kRaster_Backend,
225 kGPU_Backend,
226 kPDF_Backend,
bungeman@google.comb29c8832011-10-10 13:19:10 +0000227 kXPS_Backend,
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000228};
229
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000230struct ConfigData {
231 SkBitmap::Config fConfig;
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000232 Backend fBackend;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000233 const char* fName;
234};
235
236/// Returns true if processing should continue, false to skip the
237/// remainder of this config for this GM.
238//@todo thudson 22 April 2011 - could refactor this to take in
239// a factory to generate the context, always call readPixels()
240// (logically a noop for rasters, if wasted time), and thus collapse the
241// GPU special case and also let this be used for SkPicture testing.
242static void setup_bitmap(const ConfigData& gRec, SkISize& size,
243 SkBitmap* bitmap) {
244 bitmap->setConfig(gRec.fConfig, size.width(), size.height());
245 bitmap->allocPixels();
246 bitmap->eraseColor(0);
247}
248
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000249#include "SkDrawFilter.h"
250class BWTextDrawFilter : public SkDrawFilter {
251public:
252 virtual void filter(SkPaint*, Type) SK_OVERRIDE;
253};
254void BWTextDrawFilter::filter(SkPaint* p, Type t) {
255 if (kText_Type == t) {
256 p->setAntiAlias(false);
257 }
258}
259
260static void installFilter(SkCanvas* canvas) {
261 if (gForceBWtext) {
262 canvas->setDrawFilter(new BWTextDrawFilter)->unref();
263 }
264}
265
266static void invokeGM(GM* gm, SkCanvas* canvas) {
267 installFilter(canvas);
268 gm->draw(canvas);
269 canvas->setDrawFilter(NULL);
270}
271
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000272static ErrorBitfield generate_image(GM* gm, const ConfigData& gRec,
273 GrContext* context,
274 GrRenderTarget* rt,
junov@google.com4370aed2012-01-18 16:21:08 +0000275 SkBitmap* bitmap,
276 bool deferred) {
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000277 SkISize size (gm->getISize());
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000278 setup_bitmap(gRec, size, bitmap);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000279
280 if (gRec.fBackend == kRaster_Backend) {
junov@google.com4370aed2012-01-18 16:21:08 +0000281 SkCanvas* canvas;
282 if (deferred) {
283 canvas = new SkDeferredCanvas;
284 canvas->setDevice(new SkDevice(*bitmap))->unref();
285 } else {
286 canvas = new SkCanvas(*bitmap);
287 }
288 SkAutoUnref canvasUnref(canvas);
289 invokeGM(gm, canvas);
290 if (deferred) {
291 canvas->getDevice()->accessBitmap(false); // trigger a flush
292 }
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000293 } else { // GPU
294 if (NULL == context) {
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000295 return ERROR_NO_GPU_CONTEXT;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000296 }
junov@google.com4370aed2012-01-18 16:21:08 +0000297 SkCanvas* gc;
298 if (deferred) {
299 gc = new SkDeferredCanvas;
300 } else {
301 gc = new SkGpuCanvas(context, rt);
302 }
303 SkAutoUnref gcUnref(gc);
304 gc->setDevice(new SkGpuDevice(context, rt))->unref();
305 invokeGM(gm, gc);
reed@google.comaf951c92011-06-16 19:10:39 +0000306 // the device is as large as the current rendertarget, so we explicitly
307 // only readback the amount we expect (in size)
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000308 // overwrite our previous allocation
bsalomon@google.comc6980972011-11-02 19:57:21 +0000309 bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth,
310 size.fHeight);
junov@google.com4370aed2012-01-18 16:21:08 +0000311 gc->readPixels(bitmap, 0, 0);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000312 }
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000313 return ERROR_NONE;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000314}
315
316static void generate_image_from_picture(GM* gm, const ConfigData& gRec,
317 SkPicture* pict, SkBitmap* bitmap) {
318 SkISize size = gm->getISize();
319 setup_bitmap(gRec, size, bitmap);
320 SkCanvas canvas(*bitmap);
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000321 installFilter(&canvas);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000322 canvas.drawPicture(*pict);
323}
324
325static void generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) {
326#ifdef SK_SUPPORT_PDF
327 SkISize size = gm->getISize();
328 SkMatrix identity;
329 identity.reset();
ctguil@chromium.org15261292011-04-29 17:54:16 +0000330 SkPDFDevice* dev = new SkPDFDevice(size, size, identity);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000331 SkAutoUnref aur(dev);
332
333 SkCanvas c(dev);
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000334 invokeGM(gm, &c);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000335
336 SkPDFDocument doc;
337 doc.appendPage(dev);
338 doc.emitPDF(&pdf);
339#endif
340}
341
bungeman@google.comb29c8832011-10-10 13:19:10 +0000342static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) {
343#ifdef SK_SUPPORT_XPS
344 SkISize size = gm->getISize();
345
346 SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()),
347 SkIntToScalar(size.height()));
bungeman@google.comdc9a6952012-01-05 16:56:29 +0000348 static const SkScalar inchesPerMeter = SkScalarDiv(10000, 254);
349 static const SkScalar upm = 72 * inchesPerMeter;
350 SkVector unitsPerMeter = SkPoint::Make(upm, upm);
351 static const SkScalar ppm = 200 * inchesPerMeter;
352 SkVector pixelsPerMeter = SkPoint::Make(ppm, ppm);
bungeman@google.comb29c8832011-10-10 13:19:10 +0000353
354 SkXPSDevice* dev = new SkXPSDevice();
355 SkAutoUnref aur(dev);
356
357 SkCanvas c(dev);
358 dev->beginPortfolio(&xps);
359 dev->beginSheet(unitsPerMeter, pixelsPerMeter, trimSize);
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000360 invokeGM(gm, &c);
bungeman@google.comb29c8832011-10-10 13:19:10 +0000361 dev->endSheet();
362 dev->endPortfolio();
363
364#endif
365}
366
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000367static ErrorBitfield write_reference_image(const ConfigData& gRec,
368 const char writePath [],
369 const char renderModeDescriptor [],
370 const SkString& name,
371 SkBitmap& bitmap,
372 SkDynamicMemoryWStream* document) {
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000373 SkString path;
374 bool success = false;
bungeman@google.comb29c8832011-10-10 13:19:10 +0000375 if (gRec.fBackend == kRaster_Backend ||
376 gRec.fBackend == kGPU_Backend ||
377 (gRec.fBackend == kPDF_Backend && CAN_IMAGE_PDF)) {
378
tomhudson@google.comea325432011-06-09 20:30:03 +0000379 path = make_filename(writePath, renderModeDescriptor, name, "png");
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000380 success = write_bitmap(path, bitmap);
reed@google.com46cce912011-06-29 12:54:46 +0000381 }
382 if (kPDF_Backend == gRec.fBackend) {
tomhudson@google.comea325432011-06-09 20:30:03 +0000383 path = make_filename(writePath, renderModeDescriptor, name, "pdf");
bungeman@google.comb29c8832011-10-10 13:19:10 +0000384 success = write_document(path, *document);
385 }
386 if (kXPS_Backend == gRec.fBackend) {
387 path = make_filename(writePath, renderModeDescriptor, name, "xps");
388 success = write_document(path, *document);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000389 }
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000390 if (success) {
391 return ERROR_NONE;
392 } else {
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000393 fprintf(stderr, "FAILED to write %s\n", path.c_str());
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000394 return ERROR_WRITING_REFERENCE_IMAGE;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000395 }
396}
397
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000398static ErrorBitfield compare_to_reference_image(const SkString& name,
399 SkBitmap &bitmap,
400 const SkBitmap& comparisonBitmap,
401 const char diffPath [],
402 const char renderModeDescriptor []) {
403 ErrorBitfield errors;
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000404 SkBitmap diffBitmap;
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000405 errors = compare(bitmap, comparisonBitmap, name, renderModeDescriptor,
406 diffPath ? &diffBitmap : NULL);
407 if ((ERROR_NONE == errors) && diffPath) {
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000408 SkString diffName = make_filename(diffPath, "", name, ".diff.png");
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000409 if (!write_bitmap(diffName, diffBitmap)) {
410 errors |= ERROR_WRITING_REFERENCE_IMAGE;
411 }
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000412 }
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000413 return errors;
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000414}
415
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000416static ErrorBitfield compare_to_reference_image(const char readPath [],
417 const SkString& name,
418 SkBitmap &bitmap,
419 const char diffPath [],
420 const char renderModeDescriptor []) {
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000421 SkString path = make_filename(readPath, "", name, "png");
422 SkBitmap orig;
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000423 if (SkImageDecoder::DecodeFile(path.c_str(), &orig,
424 SkBitmap::kARGB_8888_Config,
425 SkImageDecoder::kDecodePixels_Mode, NULL)) {
426 return compare_to_reference_image(name, bitmap,
427 orig, diffPath,
428 renderModeDescriptor);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000429 } else {
430 fprintf(stderr, "FAILED to read %s\n", path.c_str());
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000431 return ERROR_READING_REFERENCE_IMAGE;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000432 }
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000433}
434
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000435static ErrorBitfield handle_test_results(GM* gm,
436 const ConfigData& gRec,
437 const char writePath [],
438 const char readPath [],
439 const char diffPath [],
440 const char renderModeDescriptor [],
441 SkBitmap& bitmap,
442 SkDynamicMemoryWStream* pdf,
443 const SkBitmap* comparisonBitmap) {
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000444 SkString name = make_name(gm->shortName(), gRec.fName);
445
446 if (writePath) {
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000447 return write_reference_image(gRec, writePath, renderModeDescriptor,
448 name, bitmap, pdf);
bungeman@google.comb29c8832011-10-10 13:19:10 +0000449 } else if (readPath && (
450 gRec.fBackend == kRaster_Backend ||
451 gRec.fBackend == kGPU_Backend ||
452 (gRec.fBackend == kPDF_Backend && CAN_IMAGE_PDF))) {
tomhudson@google.com8e728d72011-04-26 20:22:57 +0000453 return compare_to_reference_image(readPath, name, bitmap,
tomhudson@google.comea325432011-06-09 20:30:03 +0000454 diffPath, renderModeDescriptor);
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000455 } else if (comparisonBitmap) {
456 return compare_to_reference_image(name, bitmap,
457 *comparisonBitmap, diffPath,
458 renderModeDescriptor);
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000459 } else {
460 return ERROR_NONE;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000461 }
462}
463
464static SkPicture* generate_new_picture(GM* gm) {
465 // Pictures are refcounted so must be on heap
466 SkPicture* pict = new SkPicture;
467 SkCanvas* cv = pict->beginRecording(1000, 1000);
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000468 invokeGM(gm, cv);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000469 pict->endRecording();
470
471 return pict;
472}
473
474static SkPicture* stream_to_new_picture(const SkPicture& src) {
475
476 // To do in-memory commiunications with a stream, we need to:
477 // * create a dynamic memory stream
478 // * copy it into a buffer
479 // * create a read stream from it
480 // ?!?!
481
482 SkDynamicMemoryWStream storage;
483 src.serialize(&storage);
484
485 int streamSize = storage.getOffset();
486 SkAutoMalloc dstStorage(streamSize);
487 void* dst = dstStorage.get();
488 //char* dst = new char [streamSize];
489 //@todo thudson 22 April 2011 when can we safely delete [] dst?
490 storage.copyTo(dst);
491 SkMemoryStream pictReadback(dst, streamSize);
492 SkPicture* retval = new SkPicture (&pictReadback);
493 return retval;
494}
495
496// Test: draw into a bitmap or pdf.
497// Depending on flags, possibly compare to an expected image
498// and possibly output a diff image if it fails to match.
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000499static ErrorBitfield test_drawing(GM* gm,
500 const ConfigData& gRec,
501 const char writePath [],
502 const char readPath [],
503 const char diffPath [],
504 GrContext* context,
505 GrRenderTarget* rt,
506 SkBitmap* bitmap) {
bungeman@google.comb29c8832011-10-10 13:19:10 +0000507 SkDynamicMemoryWStream document;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000508
509 if (gRec.fBackend == kRaster_Backend ||
bsalomon@google.com971d0c82011-08-19 17:22:05 +0000510 gRec.fBackend == kGPU_Backend) {
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000511 // Early exit if we can't generate the image.
junov@google.com4370aed2012-01-18 16:21:08 +0000512 ErrorBitfield errors = generate_image(gm, gRec, context, rt, bitmap,
513 false);
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000514 if (ERROR_NONE != errors) {
515 return errors;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000516 }
reed@google.com46cce912011-06-29 12:54:46 +0000517 } else if (gRec.fBackend == kPDF_Backend) {
bungeman@google.comb29c8832011-10-10 13:19:10 +0000518 generate_pdf(gm, document);
reed@google.com46cce912011-06-29 12:54:46 +0000519#if CAN_IMAGE_PDF
bungeman@google.com0f1541f2011-10-10 13:47:06 +0000520 SkAutoDataUnref data(document.copyToData());
reed@google.com46cce912011-06-29 12:54:46 +0000521 SkMemoryStream stream(data.data(), data.size());
522 SkPDFDocumentToBitmap(&stream, bitmap);
523#endif
bungeman@google.comb29c8832011-10-10 13:19:10 +0000524 } else if (gRec.fBackend == kXPS_Backend) {
525 generate_xps(gm, document);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000526 }
tomhudson@google.com8e728d72011-04-26 20:22:57 +0000527 return handle_test_results(gm, gRec, writePath, readPath, diffPath,
bungeman@google.comb29c8832011-10-10 13:19:10 +0000528 "", *bitmap, &document, NULL);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000529}
530
junov@google.com4370aed2012-01-18 16:21:08 +0000531static ErrorBitfield test_deferred_drawing(GM* gm,
532 const ConfigData& gRec,
533 const SkBitmap& comparisonBitmap,
534 const char diffPath [],
535 GrContext* context,
536 GrRenderTarget* rt) {
537 SkDynamicMemoryWStream document;
538
539 if (gRec.fBackend == kRaster_Backend ||
540 gRec.fBackend == kGPU_Backend) {
541 SkBitmap bitmap;
542 // Early exit if we can't generate the image, but this is
543 // expected in some cases, so don't report a test failure.
544 if (!generate_image(gm, gRec, context, rt, &bitmap, true)) {
545 return ERROR_NONE;
546 }
547 return handle_test_results(gm, gRec, NULL, NULL, diffPath,
548 "-deferred", bitmap, NULL, &comparisonBitmap);
549 }
550 return ERROR_NONE;
551}
552
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000553static ErrorBitfield test_picture_playback(GM* gm,
554 const ConfigData& gRec,
555 const SkBitmap& comparisonBitmap,
556 const char readPath [],
557 const char diffPath []) {
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000558 SkPicture* pict = generate_new_picture(gm);
559 SkAutoUnref aur(pict);
560
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000561 if (kRaster_Backend == gRec.fBackend) {
562 SkBitmap bitmap;
563 generate_image_from_picture(gm, gRec, pict, &bitmap);
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000564 return handle_test_results(gm, gRec, NULL, NULL, diffPath,
565 "-replay", bitmap, NULL, &comparisonBitmap);
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000566 } else {
567 return ERROR_NONE;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000568 }
569}
570
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000571static ErrorBitfield test_picture_serialization(GM* gm,
572 const ConfigData& gRec,
573 const SkBitmap& comparisonBitmap,
574 const char readPath [],
575 const char diffPath []) {
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000576 SkPicture* pict = generate_new_picture(gm);
577 SkAutoUnref aurp(pict);
578 SkPicture* repict = stream_to_new_picture(*pict);
579 SkAutoUnref aurr(repict);
580
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000581 if (kRaster_Backend == gRec.fBackend) {
582 SkBitmap bitmap;
583 generate_image_from_picture(gm, gRec, repict, &bitmap);
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000584 return handle_test_results(gm, gRec, NULL, NULL, diffPath,
585 "-serialize", bitmap, NULL, &comparisonBitmap);
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000586 } else {
587 return ERROR_NONE;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000588 }
589}
590
591static void usage(const char * argv0) {
junov@google.com77e498e2012-01-18 18:56:34 +0000592 SkDebugf(
593 "%s [-w writePath] [-r readPath] [-d diffPath] [--noreplay]\n"
594 " [--serialize] [--forceBWtext] [--nopdf] [--nodeferred]\n"
595 " [--match substring]"
596#if SK_MESA
597 " [--mesagl]"
598#endif
599 "\n\n", argv0);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000600 SkDebugf(" writePath: directory to write rendered images in.\n");
tomhudson@google.com73fb0422011-04-25 19:20:54 +0000601 SkDebugf(
602" readPath: directory to read reference images from;\n"
603" reports if any pixels mismatch between reference and new images\n");
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000604 SkDebugf(" diffPath: directory to write difference images in.\n");
junov@google.com77e498e2012-01-18 18:56:34 +0000605 SkDebugf(" --noreplay: do not exercise SkPicture replay.\n");
tomhudson@google.com73fb0422011-04-25 19:20:54 +0000606 SkDebugf(
607" --serialize: exercise SkPicture serialization & deserialization.\n");
junov@google.com77e498e2012-01-18 18:56:34 +0000608 SkDebugf(" --forceBWtext: disable text anti-aliasing.\n");
609 SkDebugf(" --nopdf: skip the pdf rendering test pass.\n");
610 SkDebugf(" --nodeferred: skip the deferred rendering test pass.\n");
reed@google.come6a5c4d2011-07-25 14:30:54 +0000611 SkDebugf(" --match foo will only run tests that substring match foo.\n");
bsalomon@google.com373a6632011-10-19 20:43:20 +0000612#if SK_MESA
613 SkDebugf(" --mesagl will run using the osmesa sw gl rasterizer.\n");
614#endif
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000615}
616
617static const ConfigData gRec[] = {
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000618 { SkBitmap::kARGB_8888_Config, kRaster_Backend, "8888" },
619 { SkBitmap::kARGB_4444_Config, kRaster_Backend, "4444" },
620 { SkBitmap::kRGB_565_Config, kRaster_Backend, "565" },
reed@google.com1a7e9462011-06-20 13:21:24 +0000621#ifdef SK_SCALAR_IS_FLOAT
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000622 { SkBitmap::kARGB_8888_Config, kGPU_Backend, "gpu" },
reed@google.com1a7e9462011-06-20 13:21:24 +0000623#endif
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000624#ifdef SK_SUPPORT_PDF
625 { SkBitmap::kARGB_8888_Config, kPDF_Backend, "pdf" },
626#endif
bungeman@google.comb29c8832011-10-10 13:19:10 +0000627#ifdef SK_SUPPORT_XPS
628 { SkBitmap::kARGB_8888_Config, kXPS_Backend, "xps" },
629#endif
reed@android.com00dae862009-06-10 15:38:48 +0000630};
631
reed@google.comb2a51622011-10-31 16:30:04 +0000632static bool skip_name(const SkTDArray<const char*> array, const char name[]) {
633 if (0 == array.count()) {
634 // no names, so don't skip anything
635 return false;
636 }
637 for (int i = 0; i < array.count(); ++i) {
638 if (strstr(name, array[i])) {
639 // found the name, so don't skip
640 return false;
641 }
642 }
643 return true;
644}
645
bsalomon@google.comd9f826c2011-07-18 15:25:04 +0000646namespace skiagm {
647static GrContext* gGrContext;
648GrContext* GetGr() {
649 return gGrContext;
650}
651}
652
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000653int main(int argc, char * const argv[]) {
reed@android.com00dae862009-06-10 15:38:48 +0000654 SkAutoGraphics ag;
reed@google.com8923c6c2011-11-08 14:59:38 +0000655 // we don't need to see this during a run
656 gSkSuppressFontCachePurgeSpew = true;
reed@google.comd4dfd102011-01-18 21:05:42 +0000657
reed@android.com8015dd82009-06-21 00:49:18 +0000658 const char* writePath = NULL; // if non-null, where we write the originals
659 const char* readPath = NULL; // if non-null, were we read from to compare
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000660 const char* diffPath = NULL; // if non-null, where we write our diffs (from compare)
reed@android.com8015dd82009-06-21 00:49:18 +0000661
reed@google.comb2a51622011-10-31 16:30:04 +0000662 SkTDArray<const char*> fMatches;
663
reed@google.comab973972011-09-19 19:01:38 +0000664 bool doPDF = true;
reed@google.comb8b09832011-05-26 15:57:56 +0000665 bool doReplay = true;
tomhudson@google.com6abfa492011-04-26 14:59:32 +0000666 bool doSerialize = false;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000667 bool useMesa = false;
junov@google.com4370aed2012-01-18 16:21:08 +0000668 bool doDeferred = true;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000669
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000670 const char* const commandName = argv[0];
reed@android.com8015dd82009-06-21 00:49:18 +0000671 char* const* stop = argv + argc;
672 for (++argv; argv < stop; ++argv) {
673 if (strcmp(*argv, "-w") == 0) {
674 argv++;
675 if (argv < stop && **argv) {
676 writePath = *argv;
677 }
678 } else if (strcmp(*argv, "-r") == 0) {
679 argv++;
680 if (argv < stop && **argv) {
681 readPath = *argv;
682 }
reed@google.com3d3f0922010-12-20 21:10:29 +0000683 } else if (strcmp(*argv, "-d") == 0) {
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000684 argv++;
reed@google.com3d3f0922010-12-20 21:10:29 +0000685 if (argv < stop && **argv) {
686 diffPath = *argv;
687 }
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000688 } else if (strcmp(*argv, "--forceBWtext") == 0) {
689 gForceBWtext = true;
reed@google.comb8b09832011-05-26 15:57:56 +0000690 } else if (strcmp(*argv, "--noreplay") == 0) {
691 doReplay = false;
reed@google.comab973972011-09-19 19:01:38 +0000692 } else if (strcmp(*argv, "--nopdf") == 0) {
693 doPDF = false;
junov@google.com4370aed2012-01-18 16:21:08 +0000694 } else if (strcmp(*argv, "--nodeferred") == 0) {
695 doDeferred = false;
tomhudson@google.com73fb0422011-04-25 19:20:54 +0000696 } else if (strcmp(*argv, "--serialize") == 0) {
697 doSerialize = true;
reed@google.comece2b022011-07-25 14:28:57 +0000698 } else if (strcmp(*argv, "--match") == 0) {
699 ++argv;
700 if (argv < stop && **argv) {
reed@google.comb2a51622011-10-31 16:30:04 +0000701 // just record the ptr, no need for a deep copy
702 *fMatches.append() = *argv;
reed@google.comece2b022011-07-25 14:28:57 +0000703 }
bsalomon@google.com373a6632011-10-19 20:43:20 +0000704#if SK_MESA
705 } else if (strcmp(*argv, "--mesagl") == 0) {
706 useMesa = true;
707#endif
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000708 } else {
709 usage(commandName);
tomhudson@google.com8e728d72011-04-26 20:22:57 +0000710 return -1;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000711 }
712 }
713 if (argv != stop) {
714 usage(commandName);
tomhudson@google.com8e728d72011-04-26 20:22:57 +0000715 return -1;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000716 }
reed@google.com873cb1e2010-12-23 15:00:45 +0000717
bsalomon@google.com39149582011-06-13 21:55:32 +0000718 int maxW = -1;
719 int maxH = -1;
720 Iter iter;
721 GM* gm;
722 while ((gm = iter.next()) != NULL) {
723 SkISize size = gm->getISize();
724 maxW = SkMax32(size.width(), maxW);
725 maxH = SkMax32(size.height(), maxH);
726 }
reed@google.com873cb1e2010-12-23 15:00:45 +0000727 // setup a GL context for drawing offscreen
bsalomon@google.com373a6632011-10-19 20:43:20 +0000728 SkAutoTUnref<SkGLContext> glContext;
729#if SK_MESA
730 if (useMesa) {
731 glContext.reset(new SkMesaGLContext());
732 } else
733#endif
734 {
735 glContext.reset(new SkNativeGLContext());
736 }
737
bsalomon@google.com29d35012011-11-30 16:57:21 +0000738 GrPlatformRenderTargetDesc rtDesc;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000739 if (glContext.get()->init(maxW, maxH)) {
740 GrPlatform3DContext ctx =
741 reinterpret_cast<GrPlatform3DContext>(glContext.get()->gl());
742 gGrContext = GrContext::Create(kOpenGL_Shaders_GrEngine, ctx);
bsalomon@google.com971d0c82011-08-19 17:22:05 +0000743 if (NULL != gGrContext) {
bsalomon@google.com29d35012011-11-30 16:57:21 +0000744 rtDesc.fConfig = kSkia8888_PM_GrPixelConfig;
745 rtDesc.fStencilBits = 8;
746 rtDesc.fRenderTargetHandle = glContext.get()->getFBOID();
bsalomon@google.com971d0c82011-08-19 17:22:05 +0000747 }
bsalomon@google.com373a6632011-10-19 20:43:20 +0000748 } else {
749 fprintf(stderr, "could not create GL context.\n");
reed@google.com37df17d2010-12-23 20:20:51 +0000750 }
reed@google.com873cb1e2010-12-23 15:00:45 +0000751
reed@android.com00f883e2010-12-14 17:46:14 +0000752 if (readPath) {
753 fprintf(stderr, "reading from %s\n", readPath);
754 } else if (writePath) {
755 fprintf(stderr, "writing to %s\n", writePath);
756 }
757
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000758 // Accumulate success of all tests.
759 int testsRun = 0;
760 int testsPassed = 0;
761 int testsFailed = 0;
762 int testsMissingReferenceImages = 0;
763
bsalomon@google.com39149582011-06-13 21:55:32 +0000764 iter.reset();
reed@android.com00dae862009-06-10 15:38:48 +0000765 while ((gm = iter.next()) != NULL) {
reed@google.comece2b022011-07-25 14:28:57 +0000766 const char* shortName = gm->shortName();
reed@google.comb2a51622011-10-31 16:30:04 +0000767 if (skip_name(fMatches, shortName)) {
reed@google.comece2b022011-07-25 14:28:57 +0000768 SkDELETE(gm);
769 continue;
770 }
771
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000772 SkISize size = gm->getISize();
reed@google.comece2b022011-07-25 14:28:57 +0000773 SkDebugf("drawing... %s [%d %d]\n", shortName,
reed@android.com8015dd82009-06-21 00:49:18 +0000774 size.width(), size.height());
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000775 SkBitmap forwardRenderedBitmap;
reed@android.com8015dd82009-06-21 00:49:18 +0000776
bsalomon@google.com29d35012011-11-30 16:57:21 +0000777 // Above we created an fbo for the context at maxW x maxH size.
778 // Here we lie about the size of the rt. We claim it is the size
779 // desired by the test. The reason is that rasterization may change
780 // slightly when the viewport dimensions change. Previously, whenever
781 // a new test was checked in that bumped maxW or maxH several images
782 // would slightly change.
783 rtDesc.fWidth = size.width();
784 rtDesc.fHeight = size.height();
785 SkAutoTUnref<GrRenderTarget> rt;
786 if (gGrContext) {
787 rt.reset(gGrContext->createPlatformRenderTarget(rtDesc));
788 }
reed@google.comfbc21172011-09-19 19:08:33 +0000789
bsalomon@google.com29d35012011-11-30 16:57:21 +0000790 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000791 // Skip any tests that we don't even need to try.
bsalomon@google.com29d35012011-11-30 16:57:21 +0000792 uint32_t gmFlags = gm->getFlags();
bungeman@google.com64e011a2011-09-19 19:31:04 +0000793 if ((kPDF_Backend == gRec[i].fBackend) &&
794 (!doPDF || (gmFlags & GM::kSkipPDF_Flag)))
795 {
reed@google.comab973972011-09-19 19:01:38 +0000796 continue;
797 }
798
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000799 // Now we know that we want to run this test and record its
800 // success or failure.
801 ErrorBitfield testErrors = ERROR_NONE;
reed@android.com00dae862009-06-10 15:38:48 +0000802
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000803 if ((ERROR_NONE == testErrors) &&
804 (kGPU_Backend == gRec[i].fBackend) &&
805 (NULL == rt.get())) {
806 fprintf(stderr, "Could not create render target for gpu.\n");
807 testErrors |= ERROR_NO_GPU_CONTEXT;
tomhudson@google.com73fb0422011-04-25 19:20:54 +0000808 }
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000809
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000810 if (ERROR_NONE == testErrors) {
811 testErrors |= test_drawing(gm, gRec[i],
812 writePath, readPath, diffPath,
813 gGrContext,
814 rt.get(), &forwardRenderedBitmap);
815 }
816
junov@google.com4370aed2012-01-18 16:21:08 +0000817 if (doDeferred && !testErrors &&
818 (kGPU_Backend == gRec[i].fBackend ||
819 kRaster_Backend == gRec[i].fBackend)) {
820 testErrors |= test_deferred_drawing(gm, gRec[i],
821 forwardRenderedBitmap,
822 diffPath, gGrContext, rt.get());
823 }
824
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000825 if ((ERROR_NONE == testErrors) && doReplay &&
826 !(gmFlags & GM::kSkipPicture_Flag)) {
827 testErrors |= test_picture_playback(gm, gRec[i],
828 forwardRenderedBitmap,
829 readPath, diffPath);
830 }
831
832 if ((ERROR_NONE == testErrors) && doSerialize) {
833 testErrors |= test_picture_serialization(gm, gRec[i],
834 forwardRenderedBitmap,
835 readPath, diffPath);
836 }
837
838 // Update overall results.
839 // We only tabulate the particular error types that we currently
840 // care about (e.g., missing reference images). Later on, if we
841 // want to also tabulate pixel mismatches vs dimension mistmatches
842 // (or whatever else), we can do so.
843 testsRun++;
844 if (ERROR_NONE == testErrors) {
845 testsPassed++;
846 } else if (ERROR_READING_REFERENCE_IMAGE & testErrors) {
847 testsMissingReferenceImages++;
848 } else {
849 testsFailed++;
tomhudson@google.com73fb0422011-04-25 19:20:54 +0000850 }
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000851 }
reed@android.com00dae862009-06-10 15:38:48 +0000852 SkDELETE(gm);
853 }
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000854 printf("Ran %d tests: %d passed, %d failed, %d missing reference images\n",
855 testsRun, testsPassed, testsFailed, testsMissingReferenceImages);
856 return (0 == testsFailed) ? 0 : -1;
reed@android.com00dae862009-06-10 15:38:48 +0000857}