blob: 455f7fe88a9eddffcb13d64064f82fd1246b37fa [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);
junov@chromium.orgbf6c1e42012-01-30 14:53:22 +0000290 canvas->flush();
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000291 } else { // GPU
292 if (NULL == context) {
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000293 return ERROR_NO_GPU_CONTEXT;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000294 }
junov@google.com4370aed2012-01-18 16:21:08 +0000295 SkCanvas* gc;
296 if (deferred) {
297 gc = new SkDeferredCanvas;
298 } else {
299 gc = new SkGpuCanvas(context, rt);
300 }
301 SkAutoUnref gcUnref(gc);
302 gc->setDevice(new SkGpuDevice(context, rt))->unref();
303 invokeGM(gm, gc);
reed@google.comaf951c92011-06-16 19:10:39 +0000304 // the device is as large as the current rendertarget, so we explicitly
305 // only readback the amount we expect (in size)
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000306 // overwrite our previous allocation
bsalomon@google.comc6980972011-11-02 19:57:21 +0000307 bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth,
308 size.fHeight);
junov@google.com4370aed2012-01-18 16:21:08 +0000309 gc->readPixels(bitmap, 0, 0);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000310 }
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000311 return ERROR_NONE;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000312}
313
314static void generate_image_from_picture(GM* gm, const ConfigData& gRec,
315 SkPicture* pict, SkBitmap* bitmap) {
316 SkISize size = gm->getISize();
317 setup_bitmap(gRec, size, bitmap);
318 SkCanvas canvas(*bitmap);
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000319 installFilter(&canvas);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000320 canvas.drawPicture(*pict);
321}
322
323static void generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) {
324#ifdef SK_SUPPORT_PDF
325 SkISize size = gm->getISize();
326 SkMatrix identity;
327 identity.reset();
ctguil@chromium.org15261292011-04-29 17:54:16 +0000328 SkPDFDevice* dev = new SkPDFDevice(size, size, identity);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000329 SkAutoUnref aur(dev);
330
331 SkCanvas c(dev);
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000332 invokeGM(gm, &c);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000333
334 SkPDFDocument doc;
335 doc.appendPage(dev);
336 doc.emitPDF(&pdf);
337#endif
338}
339
bungeman@google.comb29c8832011-10-10 13:19:10 +0000340static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) {
341#ifdef SK_SUPPORT_XPS
342 SkISize size = gm->getISize();
343
344 SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()),
345 SkIntToScalar(size.height()));
bungeman@google.comdc9a6952012-01-05 16:56:29 +0000346 static const SkScalar inchesPerMeter = SkScalarDiv(10000, 254);
347 static const SkScalar upm = 72 * inchesPerMeter;
348 SkVector unitsPerMeter = SkPoint::Make(upm, upm);
349 static const SkScalar ppm = 200 * inchesPerMeter;
350 SkVector pixelsPerMeter = SkPoint::Make(ppm, ppm);
bungeman@google.comb29c8832011-10-10 13:19:10 +0000351
352 SkXPSDevice* dev = new SkXPSDevice();
353 SkAutoUnref aur(dev);
354
355 SkCanvas c(dev);
356 dev->beginPortfolio(&xps);
357 dev->beginSheet(unitsPerMeter, pixelsPerMeter, trimSize);
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000358 invokeGM(gm, &c);
bungeman@google.comb29c8832011-10-10 13:19:10 +0000359 dev->endSheet();
360 dev->endPortfolio();
361
362#endif
363}
364
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000365static ErrorBitfield write_reference_image(const ConfigData& gRec,
366 const char writePath [],
367 const char renderModeDescriptor [],
368 const SkString& name,
369 SkBitmap& bitmap,
370 SkDynamicMemoryWStream* document) {
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000371 SkString path;
372 bool success = false;
bungeman@google.comb29c8832011-10-10 13:19:10 +0000373 if (gRec.fBackend == kRaster_Backend ||
374 gRec.fBackend == kGPU_Backend ||
375 (gRec.fBackend == kPDF_Backend && CAN_IMAGE_PDF)) {
376
tomhudson@google.comea325432011-06-09 20:30:03 +0000377 path = make_filename(writePath, renderModeDescriptor, name, "png");
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000378 success = write_bitmap(path, bitmap);
reed@google.com46cce912011-06-29 12:54:46 +0000379 }
380 if (kPDF_Backend == gRec.fBackend) {
tomhudson@google.comea325432011-06-09 20:30:03 +0000381 path = make_filename(writePath, renderModeDescriptor, name, "pdf");
bungeman@google.comb29c8832011-10-10 13:19:10 +0000382 success = write_document(path, *document);
383 }
384 if (kXPS_Backend == gRec.fBackend) {
385 path = make_filename(writePath, renderModeDescriptor, name, "xps");
386 success = write_document(path, *document);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000387 }
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000388 if (success) {
389 return ERROR_NONE;
390 } else {
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000391 fprintf(stderr, "FAILED to write %s\n", path.c_str());
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000392 return ERROR_WRITING_REFERENCE_IMAGE;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000393 }
394}
395
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000396static ErrorBitfield compare_to_reference_image(const SkString& name,
397 SkBitmap &bitmap,
398 const SkBitmap& comparisonBitmap,
399 const char diffPath [],
400 const char renderModeDescriptor []) {
401 ErrorBitfield errors;
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000402 SkBitmap diffBitmap;
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000403 errors = compare(bitmap, comparisonBitmap, name, renderModeDescriptor,
404 diffPath ? &diffBitmap : NULL);
405 if ((ERROR_NONE == errors) && diffPath) {
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000406 SkString diffName = make_filename(diffPath, "", name, ".diff.png");
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000407 if (!write_bitmap(diffName, diffBitmap)) {
408 errors |= ERROR_WRITING_REFERENCE_IMAGE;
409 }
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000410 }
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000411 return errors;
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000412}
413
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000414static ErrorBitfield compare_to_reference_image(const char readPath [],
415 const SkString& name,
416 SkBitmap &bitmap,
417 const char diffPath [],
418 const char renderModeDescriptor []) {
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000419 SkString path = make_filename(readPath, "", name, "png");
420 SkBitmap orig;
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000421 if (SkImageDecoder::DecodeFile(path.c_str(), &orig,
422 SkBitmap::kARGB_8888_Config,
423 SkImageDecoder::kDecodePixels_Mode, NULL)) {
424 return compare_to_reference_image(name, bitmap,
425 orig, diffPath,
426 renderModeDescriptor);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000427 } else {
428 fprintf(stderr, "FAILED to read %s\n", path.c_str());
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000429 return ERROR_READING_REFERENCE_IMAGE;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000430 }
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000431}
432
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000433static ErrorBitfield handle_test_results(GM* gm,
434 const ConfigData& gRec,
435 const char writePath [],
436 const char readPath [],
437 const char diffPath [],
438 const char renderModeDescriptor [],
439 SkBitmap& bitmap,
440 SkDynamicMemoryWStream* pdf,
441 const SkBitmap* comparisonBitmap) {
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000442 SkString name = make_name(gm->shortName(), gRec.fName);
443
444 if (writePath) {
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000445 return write_reference_image(gRec, writePath, renderModeDescriptor,
446 name, bitmap, pdf);
bungeman@google.comb29c8832011-10-10 13:19:10 +0000447 } else if (readPath && (
448 gRec.fBackend == kRaster_Backend ||
449 gRec.fBackend == kGPU_Backend ||
450 (gRec.fBackend == kPDF_Backend && CAN_IMAGE_PDF))) {
tomhudson@google.com8e728d72011-04-26 20:22:57 +0000451 return compare_to_reference_image(readPath, name, bitmap,
tomhudson@google.comea325432011-06-09 20:30:03 +0000452 diffPath, renderModeDescriptor);
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000453 } else if (comparisonBitmap) {
454 return compare_to_reference_image(name, bitmap,
455 *comparisonBitmap, diffPath,
456 renderModeDescriptor);
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000457 } else {
458 return ERROR_NONE;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000459 }
460}
461
462static SkPicture* generate_new_picture(GM* gm) {
463 // Pictures are refcounted so must be on heap
464 SkPicture* pict = new SkPicture;
465 SkCanvas* cv = pict->beginRecording(1000, 1000);
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000466 invokeGM(gm, cv);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000467 pict->endRecording();
468
469 return pict;
470}
471
472static SkPicture* stream_to_new_picture(const SkPicture& src) {
473
474 // To do in-memory commiunications with a stream, we need to:
475 // * create a dynamic memory stream
476 // * copy it into a buffer
477 // * create a read stream from it
478 // ?!?!
479
480 SkDynamicMemoryWStream storage;
481 src.serialize(&storage);
482
483 int streamSize = storage.getOffset();
484 SkAutoMalloc dstStorage(streamSize);
485 void* dst = dstStorage.get();
486 //char* dst = new char [streamSize];
487 //@todo thudson 22 April 2011 when can we safely delete [] dst?
488 storage.copyTo(dst);
489 SkMemoryStream pictReadback(dst, streamSize);
490 SkPicture* retval = new SkPicture (&pictReadback);
491 return retval;
492}
493
494// Test: draw into a bitmap or pdf.
495// Depending on flags, possibly compare to an expected image
496// and possibly output a diff image if it fails to match.
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000497static ErrorBitfield test_drawing(GM* gm,
498 const ConfigData& gRec,
499 const char writePath [],
500 const char readPath [],
501 const char diffPath [],
502 GrContext* context,
503 GrRenderTarget* rt,
504 SkBitmap* bitmap) {
bungeman@google.comb29c8832011-10-10 13:19:10 +0000505 SkDynamicMemoryWStream document;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000506
507 if (gRec.fBackend == kRaster_Backend ||
bsalomon@google.com971d0c82011-08-19 17:22:05 +0000508 gRec.fBackend == kGPU_Backend) {
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000509 // Early exit if we can't generate the image.
junov@google.com4370aed2012-01-18 16:21:08 +0000510 ErrorBitfield errors = generate_image(gm, gRec, context, rt, bitmap,
511 false);
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000512 if (ERROR_NONE != errors) {
513 return errors;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000514 }
reed@google.com46cce912011-06-29 12:54:46 +0000515 } else if (gRec.fBackend == kPDF_Backend) {
bungeman@google.comb29c8832011-10-10 13:19:10 +0000516 generate_pdf(gm, document);
reed@google.com46cce912011-06-29 12:54:46 +0000517#if CAN_IMAGE_PDF
bungeman@google.com0f1541f2011-10-10 13:47:06 +0000518 SkAutoDataUnref data(document.copyToData());
reed@google.com46cce912011-06-29 12:54:46 +0000519 SkMemoryStream stream(data.data(), data.size());
520 SkPDFDocumentToBitmap(&stream, bitmap);
521#endif
bungeman@google.comb29c8832011-10-10 13:19:10 +0000522 } else if (gRec.fBackend == kXPS_Backend) {
523 generate_xps(gm, document);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000524 }
tomhudson@google.com8e728d72011-04-26 20:22:57 +0000525 return handle_test_results(gm, gRec, writePath, readPath, diffPath,
bungeman@google.comb29c8832011-10-10 13:19:10 +0000526 "", *bitmap, &document, NULL);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000527}
528
junov@google.com4370aed2012-01-18 16:21:08 +0000529static ErrorBitfield test_deferred_drawing(GM* gm,
530 const ConfigData& gRec,
531 const SkBitmap& comparisonBitmap,
532 const char diffPath [],
533 GrContext* context,
534 GrRenderTarget* rt) {
535 SkDynamicMemoryWStream document;
536
537 if (gRec.fBackend == kRaster_Backend ||
538 gRec.fBackend == kGPU_Backend) {
539 SkBitmap bitmap;
540 // Early exit if we can't generate the image, but this is
541 // expected in some cases, so don't report a test failure.
542 if (!generate_image(gm, gRec, context, rt, &bitmap, true)) {
543 return ERROR_NONE;
544 }
545 return handle_test_results(gm, gRec, NULL, NULL, diffPath,
546 "-deferred", bitmap, NULL, &comparisonBitmap);
547 }
548 return ERROR_NONE;
549}
550
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000551static ErrorBitfield test_picture_playback(GM* gm,
552 const ConfigData& gRec,
553 const SkBitmap& comparisonBitmap,
554 const char readPath [],
555 const char diffPath []) {
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000556 SkPicture* pict = generate_new_picture(gm);
557 SkAutoUnref aur(pict);
558
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000559 if (kRaster_Backend == gRec.fBackend) {
560 SkBitmap bitmap;
561 generate_image_from_picture(gm, gRec, pict, &bitmap);
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000562 return handle_test_results(gm, gRec, NULL, NULL, diffPath,
563 "-replay", bitmap, NULL, &comparisonBitmap);
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000564 } else {
565 return ERROR_NONE;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000566 }
567}
568
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000569static ErrorBitfield test_picture_serialization(GM* gm,
570 const ConfigData& gRec,
571 const SkBitmap& comparisonBitmap,
572 const char readPath [],
573 const char diffPath []) {
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000574 SkPicture* pict = generate_new_picture(gm);
575 SkAutoUnref aurp(pict);
576 SkPicture* repict = stream_to_new_picture(*pict);
577 SkAutoUnref aurr(repict);
578
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000579 if (kRaster_Backend == gRec.fBackend) {
580 SkBitmap bitmap;
581 generate_image_from_picture(gm, gRec, repict, &bitmap);
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000582 return handle_test_results(gm, gRec, NULL, NULL, diffPath,
583 "-serialize", bitmap, NULL, &comparisonBitmap);
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000584 } else {
585 return ERROR_NONE;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000586 }
587}
588
589static void usage(const char * argv0) {
junov@google.com77e498e2012-01-18 18:56:34 +0000590 SkDebugf(
591 "%s [-w writePath] [-r readPath] [-d diffPath] [--noreplay]\n"
592 " [--serialize] [--forceBWtext] [--nopdf] [--nodeferred]\n"
twiz@google.come24a0792012-01-31 18:35:30 +0000593 " [--match substring] [--notexturecache]"
junov@google.com77e498e2012-01-18 18:56:34 +0000594#if SK_MESA
595 " [--mesagl]"
596#endif
597 "\n\n", argv0);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000598 SkDebugf(" writePath: directory to write rendered images in.\n");
tomhudson@google.com73fb0422011-04-25 19:20:54 +0000599 SkDebugf(
600" readPath: directory to read reference images from;\n"
601" reports if any pixels mismatch between reference and new images\n");
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000602 SkDebugf(" diffPath: directory to write difference images in.\n");
junov@google.com77e498e2012-01-18 18:56:34 +0000603 SkDebugf(" --noreplay: do not exercise SkPicture replay.\n");
tomhudson@google.com73fb0422011-04-25 19:20:54 +0000604 SkDebugf(
605" --serialize: exercise SkPicture serialization & deserialization.\n");
junov@google.com77e498e2012-01-18 18:56:34 +0000606 SkDebugf(" --forceBWtext: disable text anti-aliasing.\n");
607 SkDebugf(" --nopdf: skip the pdf rendering test pass.\n");
608 SkDebugf(" --nodeferred: skip the deferred rendering test pass.\n");
reed@google.come6a5c4d2011-07-25 14:30:54 +0000609 SkDebugf(" --match foo will only run tests that substring match foo.\n");
bsalomon@google.com373a6632011-10-19 20:43:20 +0000610#if SK_MESA
611 SkDebugf(" --mesagl will run using the osmesa sw gl rasterizer.\n");
612#endif
twiz@google.come24a0792012-01-31 18:35:30 +0000613 SkDebugf(" --notexturecache: disable the gpu texture cache.\n");
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000614}
615
616static const ConfigData gRec[] = {
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000617 { SkBitmap::kARGB_8888_Config, kRaster_Backend, "8888" },
618 { SkBitmap::kARGB_4444_Config, kRaster_Backend, "4444" },
619 { SkBitmap::kRGB_565_Config, kRaster_Backend, "565" },
reed@google.com1a7e9462011-06-20 13:21:24 +0000620#ifdef SK_SCALAR_IS_FLOAT
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000621 { SkBitmap::kARGB_8888_Config, kGPU_Backend, "gpu" },
reed@google.com1a7e9462011-06-20 13:21:24 +0000622#endif
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000623#ifdef SK_SUPPORT_PDF
624 { SkBitmap::kARGB_8888_Config, kPDF_Backend, "pdf" },
625#endif
bungeman@google.comb29c8832011-10-10 13:19:10 +0000626#ifdef SK_SUPPORT_XPS
627 { SkBitmap::kARGB_8888_Config, kXPS_Backend, "xps" },
628#endif
reed@android.com00dae862009-06-10 15:38:48 +0000629};
630
reed@google.comb2a51622011-10-31 16:30:04 +0000631static bool skip_name(const SkTDArray<const char*> array, const char name[]) {
632 if (0 == array.count()) {
633 // no names, so don't skip anything
634 return false;
635 }
636 for (int i = 0; i < array.count(); ++i) {
637 if (strstr(name, array[i])) {
638 // found the name, so don't skip
639 return false;
640 }
641 }
642 return true;
643}
644
bsalomon@google.comd9f826c2011-07-18 15:25:04 +0000645namespace skiagm {
646static GrContext* gGrContext;
647GrContext* GetGr() {
648 return gGrContext;
649}
650}
651
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000652int main(int argc, char * const argv[]) {
reed@android.com00dae862009-06-10 15:38:48 +0000653 SkAutoGraphics ag;
reed@google.com8923c6c2011-11-08 14:59:38 +0000654 // we don't need to see this during a run
655 gSkSuppressFontCachePurgeSpew = true;
reed@google.comd4dfd102011-01-18 21:05:42 +0000656
reed@android.com8015dd82009-06-21 00:49:18 +0000657 const char* writePath = NULL; // if non-null, where we write the originals
658 const char* readPath = NULL; // if non-null, were we read from to compare
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000659 const char* diffPath = NULL; // if non-null, where we write our diffs (from compare)
reed@android.com8015dd82009-06-21 00:49:18 +0000660
reed@google.comb2a51622011-10-31 16:30:04 +0000661 SkTDArray<const char*> fMatches;
twiz@google.come24a0792012-01-31 18:35:30 +0000662
reed@google.comab973972011-09-19 19:01:38 +0000663 bool doPDF = true;
reed@google.comb8b09832011-05-26 15:57:56 +0000664 bool doReplay = true;
tomhudson@google.com6abfa492011-04-26 14:59:32 +0000665 bool doSerialize = false;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000666 bool useMesa = false;
junov@google.com4370aed2012-01-18 16:21:08 +0000667 bool doDeferred = true;
twiz@google.come24a0792012-01-31 18:35:30 +0000668 bool disableTextureCache = false;
669
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
twiz@google.come24a0792012-01-31 18:35:30 +0000708 } else if (strcmp(*argv, "--notexturecache") == 0) {
709 disableTextureCache = true;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000710 } else {
711 usage(commandName);
tomhudson@google.com8e728d72011-04-26 20:22:57 +0000712 return -1;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000713 }
714 }
715 if (argv != stop) {
716 usage(commandName);
tomhudson@google.com8e728d72011-04-26 20:22:57 +0000717 return -1;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000718 }
reed@google.com873cb1e2010-12-23 15:00:45 +0000719
bsalomon@google.com39149582011-06-13 21:55:32 +0000720 int maxW = -1;
721 int maxH = -1;
722 Iter iter;
723 GM* gm;
724 while ((gm = iter.next()) != NULL) {
725 SkISize size = gm->getISize();
726 maxW = SkMax32(size.width(), maxW);
727 maxH = SkMax32(size.height(), maxH);
728 }
reed@google.com873cb1e2010-12-23 15:00:45 +0000729 // setup a GL context for drawing offscreen
bsalomon@google.com373a6632011-10-19 20:43:20 +0000730 SkAutoTUnref<SkGLContext> glContext;
731#if SK_MESA
732 if (useMesa) {
733 glContext.reset(new SkMesaGLContext());
734 } else
735#endif
736 {
737 glContext.reset(new SkNativeGLContext());
738 }
739
bsalomon@google.com29d35012011-11-30 16:57:21 +0000740 GrPlatformRenderTargetDesc rtDesc;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000741 if (glContext.get()->init(maxW, maxH)) {
742 GrPlatform3DContext ctx =
743 reinterpret_cast<GrPlatform3DContext>(glContext.get()->gl());
744 gGrContext = GrContext::Create(kOpenGL_Shaders_GrEngine, ctx);
bsalomon@google.com971d0c82011-08-19 17:22:05 +0000745 if (NULL != gGrContext) {
bsalomon@google.com29d35012011-11-30 16:57:21 +0000746 rtDesc.fConfig = kSkia8888_PM_GrPixelConfig;
747 rtDesc.fStencilBits = 8;
748 rtDesc.fRenderTargetHandle = glContext.get()->getFBOID();
bsalomon@google.com971d0c82011-08-19 17:22:05 +0000749 }
bsalomon@google.com373a6632011-10-19 20:43:20 +0000750 } else {
751 fprintf(stderr, "could not create GL context.\n");
reed@google.com37df17d2010-12-23 20:20:51 +0000752 }
reed@google.com873cb1e2010-12-23 15:00:45 +0000753
reed@android.com00f883e2010-12-14 17:46:14 +0000754 if (readPath) {
755 fprintf(stderr, "reading from %s\n", readPath);
756 } else if (writePath) {
757 fprintf(stderr, "writing to %s\n", writePath);
758 }
759
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000760 // Accumulate success of all tests.
761 int testsRun = 0;
762 int testsPassed = 0;
763 int testsFailed = 0;
764 int testsMissingReferenceImages = 0;
765
twiz@google.come24a0792012-01-31 18:35:30 +0000766 if (disableTextureCache) {
767 skiagm::GetGr()->setTextureCacheLimits(0, 0);
768 }
769
bsalomon@google.com39149582011-06-13 21:55:32 +0000770 iter.reset();
reed@android.com00dae862009-06-10 15:38:48 +0000771 while ((gm = iter.next()) != NULL) {
reed@google.comece2b022011-07-25 14:28:57 +0000772 const char* shortName = gm->shortName();
reed@google.comb2a51622011-10-31 16:30:04 +0000773 if (skip_name(fMatches, shortName)) {
reed@google.comece2b022011-07-25 14:28:57 +0000774 SkDELETE(gm);
775 continue;
776 }
777
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000778 SkISize size = gm->getISize();
reed@google.comece2b022011-07-25 14:28:57 +0000779 SkDebugf("drawing... %s [%d %d]\n", shortName,
reed@android.com8015dd82009-06-21 00:49:18 +0000780 size.width(), size.height());
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000781 SkBitmap forwardRenderedBitmap;
reed@android.com8015dd82009-06-21 00:49:18 +0000782
bsalomon@google.com29d35012011-11-30 16:57:21 +0000783 // Above we created an fbo for the context at maxW x maxH size.
784 // Here we lie about the size of the rt. We claim it is the size
785 // desired by the test. The reason is that rasterization may change
786 // slightly when the viewport dimensions change. Previously, whenever
787 // a new test was checked in that bumped maxW or maxH several images
788 // would slightly change.
789 rtDesc.fWidth = size.width();
790 rtDesc.fHeight = size.height();
791 SkAutoTUnref<GrRenderTarget> rt;
792 if (gGrContext) {
793 rt.reset(gGrContext->createPlatformRenderTarget(rtDesc));
794 }
reed@google.comfbc21172011-09-19 19:08:33 +0000795
bsalomon@google.com29d35012011-11-30 16:57:21 +0000796 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000797 // Skip any tests that we don't even need to try.
bsalomon@google.com29d35012011-11-30 16:57:21 +0000798 uint32_t gmFlags = gm->getFlags();
twiz@google.come24a0792012-01-31 18:35:30 +0000799 if ((kPDF_Backend == gRec[i].fBackend) &&
bungeman@google.com64e011a2011-09-19 19:31:04 +0000800 (!doPDF || (gmFlags & GM::kSkipPDF_Flag)))
801 {
reed@google.comab973972011-09-19 19:01:38 +0000802 continue;
803 }
804
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000805 // Now we know that we want to run this test and record its
806 // success or failure.
807 ErrorBitfield testErrors = ERROR_NONE;
reed@android.com00dae862009-06-10 15:38:48 +0000808
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000809 if ((ERROR_NONE == testErrors) &&
810 (kGPU_Backend == gRec[i].fBackend) &&
811 (NULL == rt.get())) {
812 fprintf(stderr, "Could not create render target for gpu.\n");
813 testErrors |= ERROR_NO_GPU_CONTEXT;
tomhudson@google.com73fb0422011-04-25 19:20:54 +0000814 }
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000815
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000816 if (ERROR_NONE == testErrors) {
817 testErrors |= test_drawing(gm, gRec[i],
818 writePath, readPath, diffPath,
819 gGrContext,
820 rt.get(), &forwardRenderedBitmap);
821 }
822
junov@google.com4370aed2012-01-18 16:21:08 +0000823 if (doDeferred && !testErrors &&
twiz@google.come24a0792012-01-31 18:35:30 +0000824 (kGPU_Backend == gRec[i].fBackend ||
junov@google.com4370aed2012-01-18 16:21:08 +0000825 kRaster_Backend == gRec[i].fBackend)) {
826 testErrors |= test_deferred_drawing(gm, gRec[i],
827 forwardRenderedBitmap,
828 diffPath, gGrContext, rt.get());
829 }
830
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000831 if ((ERROR_NONE == testErrors) && doReplay &&
832 !(gmFlags & GM::kSkipPicture_Flag)) {
833 testErrors |= test_picture_playback(gm, gRec[i],
834 forwardRenderedBitmap,
835 readPath, diffPath);
836 }
837
838 if ((ERROR_NONE == testErrors) && doSerialize) {
839 testErrors |= test_picture_serialization(gm, gRec[i],
840 forwardRenderedBitmap,
841 readPath, diffPath);
842 }
843
844 // Update overall results.
845 // We only tabulate the particular error types that we currently
846 // care about (e.g., missing reference images). Later on, if we
847 // want to also tabulate pixel mismatches vs dimension mistmatches
848 // (or whatever else), we can do so.
849 testsRun++;
850 if (ERROR_NONE == testErrors) {
851 testsPassed++;
852 } else if (ERROR_READING_REFERENCE_IMAGE & testErrors) {
853 testsMissingReferenceImages++;
854 } else {
855 testsFailed++;
tomhudson@google.com73fb0422011-04-25 19:20:54 +0000856 }
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000857 }
reed@android.com00dae862009-06-10 15:38:48 +0000858 SkDELETE(gm);
859 }
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000860 printf("Ran %d tests: %d passed, %d failed, %d missing reference images\n",
861 testsRun, testsPassed, testsFailed, testsMissingReferenceImages);
862 return (0 == testsFailed) ? 0 : -1;
reed@android.com00dae862009-06-10 15:38:48 +0000863}