blob: 3958998b56838d85d164f35c75b47a11c3b1c0b7 [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"
epoger@google.com7bc13a62012-02-14 14:53:59 +00009#include "system_preferences.h"
bsalomon@google.com971d0c82011-08-19 17:22:05 +000010#include "GrContext.h"
11#include "GrRenderTarget.h"
12
reed@android.comb9b9a182009-07-08 02:54:47 +000013#include "SkColorPriv.h"
reed@google.com8a85d0c2011-06-24 19:12:12 +000014#include "SkData.h"
junov@google.com4370aed2012-01-18 16:21:08 +000015#include "SkDeferredCanvas.h"
bsalomon@google.com971d0c82011-08-19 17:22:05 +000016#include "SkDevice.h"
bsalomon@google.com971d0c82011-08-19 17:22:05 +000017#include "SkGpuCanvas.h"
18#include "SkGpuDevice.h"
reed@android.com8015dd82009-06-21 00:49:18 +000019#include "SkGraphics.h"
20#include "SkImageDecoder.h"
21#include "SkImageEncoder.h"
bsalomon@google.com373a6632011-10-19 20:43:20 +000022#include "SkNativeGLContext.h"
23#include "SkMesaGLContext.h"
tomhudson@google.com9875dd12011-04-25 15:49:53 +000024#include "SkPicture.h"
reed@google.com07700442010-12-20 19:46:07 +000025#include "SkStream.h"
26#include "SkRefCnt.h"
27
mike@reedtribe.org10afbef2011-12-30 16:02:53 +000028static bool gForceBWtext;
29
reed@google.com8923c6c2011-11-08 14:59:38 +000030extern bool gSkSuppressFontCachePurgeSpew;
31
reed@google.com07700442010-12-20 19:46:07 +000032#ifdef SK_SUPPORT_PDF
tomhudson@google.com9875dd12011-04-25 15:49:53 +000033 #include "SkPDFDevice.h"
34 #include "SkPDFDocument.h"
reed@google.com07700442010-12-20 19:46:07 +000035#endif
reed@android.com00dae862009-06-10 15:38:48 +000036
epoger@google.come3cc2eb2012-01-18 20:11:13 +000037// Until we resolve http://code.google.com/p/skia/issues/detail?id=455 ,
38// stop writing out XPS-format image baselines in gm.
39#undef SK_SUPPORT_XPS
bungeman@google.comb29c8832011-10-10 13:19:10 +000040#ifdef SK_SUPPORT_XPS
41 #include "SkXPSDevice.h"
42#endif
43
reed@google.com46cce912011-06-29 12:54:46 +000044#ifdef SK_BUILD_FOR_MAC
45 #include "SkCGUtils.h"
bsalomon@google.com0a09eef2011-06-29 19:42:58 +000046 #define CAN_IMAGE_PDF 1
reed@google.com46cce912011-06-29 12:54:46 +000047#else
bsalomon@google.com0a09eef2011-06-29 19:42:58 +000048 #define CAN_IMAGE_PDF 0
reed@google.com46cce912011-06-29 12:54:46 +000049#endif
50
epoger@google.comc7cf2b32011-12-28 19:31:01 +000051typedef int ErrorBitfield;
52const static ErrorBitfield ERROR_NONE = 0x00;
53const static ErrorBitfield ERROR_NO_GPU_CONTEXT = 0x01;
54const static ErrorBitfield ERROR_PIXEL_MISMATCH = 0x02;
55const static ErrorBitfield ERROR_DIMENSION_MISMATCH = 0x04;
56const static ErrorBitfield ERROR_READING_REFERENCE_IMAGE = 0x08;
57const static ErrorBitfield ERROR_WRITING_REFERENCE_IMAGE = 0x10;
58
reed@android.com00dae862009-06-10 15:38:48 +000059using namespace skiagm;
60
reed@android.com00dae862009-06-10 15:38:48 +000061class Iter {
62public:
63 Iter() {
bsalomon@google.com39149582011-06-13 21:55:32 +000064 this->reset();
65 }
66
67 void reset() {
reed@android.comdd0ac282009-06-20 02:38:16 +000068 fReg = GMRegistry::Head();
reed@android.com00dae862009-06-10 15:38:48 +000069 }
reed@google.comd4dfd102011-01-18 21:05:42 +000070
reed@android.comdd0ac282009-06-20 02:38:16 +000071 GM* next() {
reed@android.com00dae862009-06-10 15:38:48 +000072 if (fReg) {
reed@android.comdd0ac282009-06-20 02:38:16 +000073 GMRegistry::Factory fact = fReg->factory();
reed@android.com00dae862009-06-10 15:38:48 +000074 fReg = fReg->next();
reed@android.comdd0ac282009-06-20 02:38:16 +000075 return fact(0);
reed@android.com00dae862009-06-10 15:38:48 +000076 }
77 return NULL;
78 }
reed@google.comd4dfd102011-01-18 21:05:42 +000079
reed@android.com00dae862009-06-10 15:38:48 +000080 static int Count() {
reed@android.comdd0ac282009-06-20 02:38:16 +000081 const GMRegistry* reg = GMRegistry::Head();
reed@android.com00dae862009-06-10 15:38:48 +000082 int count = 0;
83 while (reg) {
84 count += 1;
85 reg = reg->next();
86 }
87 return count;
88 }
reed@google.comd4dfd102011-01-18 21:05:42 +000089
reed@android.com00dae862009-06-10 15:38:48 +000090private:
91 const GMRegistry* fReg;
92};
93
reed@android.com8015dd82009-06-21 00:49:18 +000094static SkString make_name(const char shortName[], const char configName[]) {
95 SkString name(shortName);
96 name.appendf("_%s", configName);
97 return name;
98}
99
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000100static SkString make_filename(const char path[],
101 const char pathSuffix[],
102 const SkString& name,
103 const char suffix[]) {
reed@android.com8015dd82009-06-21 00:49:18 +0000104 SkString filename(path);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000105 if (filename.endsWith("/")) {
106 filename.remove(filename.size() - 1, 1);
reed@android.com00dae862009-06-10 15:38:48 +0000107 }
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000108 filename.append(pathSuffix);
109 filename.append("/");
reed@google.com07700442010-12-20 19:46:07 +0000110 filename.appendf("%s.%s", name.c_str(), suffix);
reed@android.com8015dd82009-06-21 00:49:18 +0000111 return filename;
112}
113
reed@android.comb9b9a182009-07-08 02:54:47 +0000114/* since PNG insists on unpremultiplying our alpha, we take no precision chances
115 and force all pixels to be 100% opaque, otherwise on compare we may not get
116 a perfect match.
117 */
118static void force_all_opaque(const SkBitmap& bitmap) {
119 SkAutoLockPixels lock(bitmap);
120 for (int y = 0; y < bitmap.height(); y++) {
121 for (int x = 0; x < bitmap.width(); x++) {
122 *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT);
123 }
124 }
125}
126
127static bool write_bitmap(const SkString& path, const SkBitmap& bitmap) {
128 SkBitmap copy;
129 bitmap.copyTo(&copy, SkBitmap::kARGB_8888_Config);
130 force_all_opaque(copy);
131 return SkImageEncoder::EncodeFile(path.c_str(), copy,
132 SkImageEncoder::kPNG_Type, 100);
133}
134
reed@google.com3d3f0922010-12-20 21:10:29 +0000135static inline SkPMColor compute_diff_pmcolor(SkPMColor c0, SkPMColor c1) {
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000136 int dr = SkGetPackedR32(c0) - SkGetPackedR32(c1);
137 int dg = SkGetPackedG32(c0) - SkGetPackedG32(c1);
138 int db = SkGetPackedB32(c0) - SkGetPackedB32(c1);
139 return SkPackARGB32(0xFF, SkAbs32(dr), SkAbs32(dg), SkAbs32(db));
reed@google.com3d3f0922010-12-20 21:10:29 +0000140}
141
142static void compute_diff(const SkBitmap& target, const SkBitmap& base,
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000143 SkBitmap* diff) {
144 SkAutoLockPixels alp(*diff);
reed@google.com3d3f0922010-12-20 21:10:29 +0000145
146 const int w = target.width();
147 const int h = target.height();
148 for (int y = 0; y < h; y++) {
149 for (int x = 0; x < w; x++) {
150 SkPMColor c0 = *base.getAddr32(x, y);
151 SkPMColor c1 = *target.getAddr32(x, y);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000152 SkPMColor d = 0;
153 if (c0 != c1) {
154 d = compute_diff_pmcolor(c0, c1);
155 }
156 *diff->getAddr32(x, y) = d;
157 }
158 }
reed@google.com3d3f0922010-12-20 21:10:29 +0000159}
160
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000161static ErrorBitfield compare(const SkBitmap& target, const SkBitmap& base,
162 const SkString& name,
163 const char* renderModeDescriptor,
164 SkBitmap* diff) {
reed@android.comb9b9a182009-07-08 02:54:47 +0000165 SkBitmap copy;
166 const SkBitmap* bm = &target;
167 if (target.config() != SkBitmap::kARGB_8888_Config) {
168 target.copyTo(&copy, SkBitmap::kARGB_8888_Config);
169 bm = &copy;
170 }
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000171 SkBitmap baseCopy;
172 const SkBitmap* bp = &base;
173 if (base.config() != SkBitmap::kARGB_8888_Config) {
174 base.copyTo(&baseCopy, SkBitmap::kARGB_8888_Config);
175 bp = &baseCopy;
176 }
reed@android.comb9b9a182009-07-08 02:54:47 +0000177
178 force_all_opaque(*bm);
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000179 force_all_opaque(*bp);
reed@android.comb9b9a182009-07-08 02:54:47 +0000180
181 const int w = bm->width();
182 const int h = bm->height();
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000183 if (w != bp->width() || h != bp->height()) {
tomhudson@google.comea325432011-06-09 20:30:03 +0000184 SkDebugf(
185"---- %s dimensions mismatch for %s base [%d %d] current [%d %d]\n",
186 renderModeDescriptor, name.c_str(),
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000187 bp->width(), bp->height(), w, h);
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000188 return ERROR_DIMENSION_MISMATCH;
reed@android.comb9b9a182009-07-08 02:54:47 +0000189 }
190
191 SkAutoLockPixels bmLock(*bm);
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000192 SkAutoLockPixels baseLock(*bp);
reed@android.comb9b9a182009-07-08 02:54:47 +0000193
194 for (int y = 0; y < h; y++) {
195 for (int x = 0; x < w; x++) {
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000196 SkPMColor c0 = *bp->getAddr32(x, y);
reed@android.comb9b9a182009-07-08 02:54:47 +0000197 SkPMColor c1 = *bm->getAddr32(x, y);
198 if (c0 != c1) {
tomhudson@google.comea325432011-06-09 20:30:03 +0000199 SkDebugf(
200"----- %s pixel mismatch for %s at [%d %d] base 0x%08X current 0x%08X\n",
201 renderModeDescriptor, name.c_str(), x, y, c0, c1);
reed@google.com3d3f0922010-12-20 21:10:29 +0000202
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000203 if (diff) {
204 diff->setConfig(SkBitmap::kARGB_8888_Config, w, h);
205 diff->allocPixels();
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000206 compute_diff(*bm, *bp, diff);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000207 }
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000208 return ERROR_PIXEL_MISMATCH;
reed@android.comb9b9a182009-07-08 02:54:47 +0000209 }
210 }
211 }
reed@google.com3d3f0922010-12-20 21:10:29 +0000212
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000213 // they're equal
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000214 return ERROR_NONE;
reed@android.com8015dd82009-06-21 00:49:18 +0000215}
reed@android.com00dae862009-06-10 15:38:48 +0000216
bungeman@google.comb29c8832011-10-10 13:19:10 +0000217static bool write_document(const SkString& path,
218 const SkDynamicMemoryWStream& document) {
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000219 SkFILEWStream stream(path.c_str());
bungeman@google.comb29c8832011-10-10 13:19:10 +0000220 SkAutoDataUnref data(document.copyToData());
reed@google.com8a85d0c2011-06-24 19:12:12 +0000221 return stream.writeData(data.get());
reed@google.com07700442010-12-20 19:46:07 +0000222}
223
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000224enum Backend {
225 kRaster_Backend,
226 kGPU_Backend,
227 kPDF_Backend,
bungeman@google.comb29c8832011-10-10 13:19:10 +0000228 kXPS_Backend,
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000229};
230
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000231struct ConfigData {
232 SkBitmap::Config fConfig;
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000233 Backend fBackend;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000234 const char* fName;
235};
236
237/// Returns true if processing should continue, false to skip the
238/// remainder of this config for this GM.
239//@todo thudson 22 April 2011 - could refactor this to take in
240// a factory to generate the context, always call readPixels()
241// (logically a noop for rasters, if wasted time), and thus collapse the
242// GPU special case and also let this be used for SkPicture testing.
243static void setup_bitmap(const ConfigData& gRec, SkISize& size,
244 SkBitmap* bitmap) {
245 bitmap->setConfig(gRec.fConfig, size.width(), size.height());
246 bitmap->allocPixels();
247 bitmap->eraseColor(0);
248}
249
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000250#include "SkDrawFilter.h"
251class BWTextDrawFilter : public SkDrawFilter {
252public:
253 virtual void filter(SkPaint*, Type) SK_OVERRIDE;
254};
255void BWTextDrawFilter::filter(SkPaint* p, Type t) {
256 if (kText_Type == t) {
257 p->setAntiAlias(false);
258 }
259}
260
261static void installFilter(SkCanvas* canvas) {
262 if (gForceBWtext) {
263 canvas->setDrawFilter(new BWTextDrawFilter)->unref();
264 }
265}
266
267static void invokeGM(GM* gm, SkCanvas* canvas) {
268 installFilter(canvas);
269 gm->draw(canvas);
270 canvas->setDrawFilter(NULL);
271}
272
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000273static ErrorBitfield generate_image(GM* gm, const ConfigData& gRec,
274 GrContext* context,
275 GrRenderTarget* rt,
junov@google.com4370aed2012-01-18 16:21:08 +0000276 SkBitmap* bitmap,
277 bool deferred) {
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000278 SkISize size (gm->getISize());
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000279 setup_bitmap(gRec, size, bitmap);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000280
281 if (gRec.fBackend == kRaster_Backend) {
junov@google.com4370aed2012-01-18 16:21:08 +0000282 SkCanvas* canvas;
283 if (deferred) {
284 canvas = new SkDeferredCanvas;
285 canvas->setDevice(new SkDevice(*bitmap))->unref();
286 } else {
287 canvas = new SkCanvas(*bitmap);
288 }
289 SkAutoUnref canvasUnref(canvas);
290 invokeGM(gm, canvas);
junov@chromium.orgbf6c1e42012-01-30 14:53:22 +0000291 canvas->flush();
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000292 } else { // GPU
293 if (NULL == context) {
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000294 return ERROR_NO_GPU_CONTEXT;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000295 }
junov@google.com4370aed2012-01-18 16:21:08 +0000296 SkCanvas* gc;
297 if (deferred) {
298 gc = new SkDeferredCanvas;
299 } else {
300 gc = new SkGpuCanvas(context, rt);
301 }
302 SkAutoUnref gcUnref(gc);
303 gc->setDevice(new SkGpuDevice(context, rt))->unref();
304 invokeGM(gm, gc);
reed@google.comaf951c92011-06-16 19:10:39 +0000305 // the device is as large as the current rendertarget, so we explicitly
306 // only readback the amount we expect (in size)
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000307 // overwrite our previous allocation
bsalomon@google.comc6980972011-11-02 19:57:21 +0000308 bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth,
309 size.fHeight);
junov@google.com4370aed2012-01-18 16:21:08 +0000310 gc->readPixels(bitmap, 0, 0);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000311 }
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000312 return ERROR_NONE;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000313}
314
315static void generate_image_from_picture(GM* gm, const ConfigData& gRec,
316 SkPicture* pict, SkBitmap* bitmap) {
317 SkISize size = gm->getISize();
318 setup_bitmap(gRec, size, bitmap);
319 SkCanvas canvas(*bitmap);
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000320 installFilter(&canvas);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000321 canvas.drawPicture(*pict);
322}
323
324static void generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) {
325#ifdef SK_SUPPORT_PDF
326 SkISize size = gm->getISize();
327 SkMatrix identity;
328 identity.reset();
ctguil@chromium.org15261292011-04-29 17:54:16 +0000329 SkPDFDevice* dev = new SkPDFDevice(size, size, identity);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000330 SkAutoUnref aur(dev);
331
332 SkCanvas c(dev);
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000333 invokeGM(gm, &c);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000334
335 SkPDFDocument doc;
336 doc.appendPage(dev);
337 doc.emitPDF(&pdf);
338#endif
339}
340
bungeman@google.comb29c8832011-10-10 13:19:10 +0000341static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) {
342#ifdef SK_SUPPORT_XPS
343 SkISize size = gm->getISize();
344
345 SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()),
346 SkIntToScalar(size.height()));
bungeman@google.comdc9a6952012-01-05 16:56:29 +0000347 static const SkScalar inchesPerMeter = SkScalarDiv(10000, 254);
348 static const SkScalar upm = 72 * inchesPerMeter;
349 SkVector unitsPerMeter = SkPoint::Make(upm, upm);
350 static const SkScalar ppm = 200 * inchesPerMeter;
351 SkVector pixelsPerMeter = SkPoint::Make(ppm, ppm);
bungeman@google.comb29c8832011-10-10 13:19:10 +0000352
353 SkXPSDevice* dev = new SkXPSDevice();
354 SkAutoUnref aur(dev);
355
356 SkCanvas c(dev);
357 dev->beginPortfolio(&xps);
358 dev->beginSheet(unitsPerMeter, pixelsPerMeter, trimSize);
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000359 invokeGM(gm, &c);
bungeman@google.comb29c8832011-10-10 13:19:10 +0000360 dev->endSheet();
361 dev->endPortfolio();
362
363#endif
364}
365
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000366static ErrorBitfield write_reference_image(const ConfigData& gRec,
367 const char writePath [],
368 const char renderModeDescriptor [],
369 const SkString& name,
370 SkBitmap& bitmap,
371 SkDynamicMemoryWStream* document) {
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000372 SkString path;
373 bool success = false;
bungeman@google.comb29c8832011-10-10 13:19:10 +0000374 if (gRec.fBackend == kRaster_Backend ||
375 gRec.fBackend == kGPU_Backend ||
376 (gRec.fBackend == kPDF_Backend && CAN_IMAGE_PDF)) {
377
tomhudson@google.comea325432011-06-09 20:30:03 +0000378 path = make_filename(writePath, renderModeDescriptor, name, "png");
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000379 success = write_bitmap(path, bitmap);
reed@google.com46cce912011-06-29 12:54:46 +0000380 }
381 if (kPDF_Backend == gRec.fBackend) {
tomhudson@google.comea325432011-06-09 20:30:03 +0000382 path = make_filename(writePath, renderModeDescriptor, name, "pdf");
bungeman@google.comb29c8832011-10-10 13:19:10 +0000383 success = write_document(path, *document);
384 }
385 if (kXPS_Backend == gRec.fBackend) {
386 path = make_filename(writePath, renderModeDescriptor, name, "xps");
387 success = write_document(path, *document);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000388 }
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000389 if (success) {
390 return ERROR_NONE;
391 } else {
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000392 fprintf(stderr, "FAILED to write %s\n", path.c_str());
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000393 return ERROR_WRITING_REFERENCE_IMAGE;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000394 }
395}
396
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000397static ErrorBitfield compare_to_reference_image(const SkString& name,
398 SkBitmap &bitmap,
399 const SkBitmap& comparisonBitmap,
400 const char diffPath [],
401 const char renderModeDescriptor []) {
402 ErrorBitfield errors;
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000403 SkBitmap diffBitmap;
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000404 errors = compare(bitmap, comparisonBitmap, name, renderModeDescriptor,
405 diffPath ? &diffBitmap : NULL);
406 if ((ERROR_NONE == errors) && diffPath) {
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000407 SkString diffName = make_filename(diffPath, "", name, ".diff.png");
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000408 if (!write_bitmap(diffName, diffBitmap)) {
409 errors |= ERROR_WRITING_REFERENCE_IMAGE;
410 }
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000411 }
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000412 return errors;
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000413}
414
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000415static ErrorBitfield compare_to_reference_image(const char readPath [],
416 const SkString& name,
417 SkBitmap &bitmap,
418 const char diffPath [],
419 const char renderModeDescriptor []) {
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000420 SkString path = make_filename(readPath, "", name, "png");
421 SkBitmap orig;
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000422 if (SkImageDecoder::DecodeFile(path.c_str(), &orig,
423 SkBitmap::kARGB_8888_Config,
424 SkImageDecoder::kDecodePixels_Mode, NULL)) {
425 return compare_to_reference_image(name, bitmap,
426 orig, diffPath,
427 renderModeDescriptor);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000428 } else {
429 fprintf(stderr, "FAILED to read %s\n", path.c_str());
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000430 return ERROR_READING_REFERENCE_IMAGE;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000431 }
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000432}
433
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000434static ErrorBitfield handle_test_results(GM* gm,
435 const ConfigData& gRec,
436 const char writePath [],
437 const char readPath [],
438 const char diffPath [],
439 const char renderModeDescriptor [],
440 SkBitmap& bitmap,
441 SkDynamicMemoryWStream* pdf,
442 const SkBitmap* comparisonBitmap) {
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000443 SkString name = make_name(gm->shortName(), gRec.fName);
444
445 if (writePath) {
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000446 return write_reference_image(gRec, writePath, renderModeDescriptor,
447 name, bitmap, pdf);
bungeman@google.comb29c8832011-10-10 13:19:10 +0000448 } else if (readPath && (
449 gRec.fBackend == kRaster_Backend ||
450 gRec.fBackend == kGPU_Backend ||
451 (gRec.fBackend == kPDF_Backend && CAN_IMAGE_PDF))) {
tomhudson@google.com8e728d72011-04-26 20:22:57 +0000452 return compare_to_reference_image(readPath, name, bitmap,
tomhudson@google.comea325432011-06-09 20:30:03 +0000453 diffPath, renderModeDescriptor);
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000454 } else if (comparisonBitmap) {
455 return compare_to_reference_image(name, bitmap,
456 *comparisonBitmap, diffPath,
457 renderModeDescriptor);
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000458 } else {
459 return ERROR_NONE;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000460 }
461}
462
463static SkPicture* generate_new_picture(GM* gm) {
464 // Pictures are refcounted so must be on heap
465 SkPicture* pict = new SkPicture;
466 SkCanvas* cv = pict->beginRecording(1000, 1000);
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000467 invokeGM(gm, cv);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000468 pict->endRecording();
469
470 return pict;
471}
472
473static SkPicture* stream_to_new_picture(const SkPicture& src) {
474
475 // To do in-memory commiunications with a stream, we need to:
476 // * create a dynamic memory stream
477 // * copy it into a buffer
478 // * create a read stream from it
479 // ?!?!
480
481 SkDynamicMemoryWStream storage;
482 src.serialize(&storage);
483
484 int streamSize = storage.getOffset();
485 SkAutoMalloc dstStorage(streamSize);
486 void* dst = dstStorage.get();
487 //char* dst = new char [streamSize];
488 //@todo thudson 22 April 2011 when can we safely delete [] dst?
489 storage.copyTo(dst);
490 SkMemoryStream pictReadback(dst, streamSize);
491 SkPicture* retval = new SkPicture (&pictReadback);
492 return retval;
493}
494
495// Test: draw into a bitmap or pdf.
496// Depending on flags, possibly compare to an expected image
497// and possibly output a diff image if it fails to match.
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000498static ErrorBitfield test_drawing(GM* gm,
499 const ConfigData& gRec,
500 const char writePath [],
501 const char readPath [],
502 const char diffPath [],
503 GrContext* context,
504 GrRenderTarget* rt,
505 SkBitmap* bitmap) {
bungeman@google.comb29c8832011-10-10 13:19:10 +0000506 SkDynamicMemoryWStream document;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000507
508 if (gRec.fBackend == kRaster_Backend ||
bsalomon@google.com971d0c82011-08-19 17:22:05 +0000509 gRec.fBackend == kGPU_Backend) {
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000510 // Early exit if we can't generate the image.
junov@google.com4370aed2012-01-18 16:21:08 +0000511 ErrorBitfield errors = generate_image(gm, gRec, context, rt, bitmap,
512 false);
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000513 if (ERROR_NONE != errors) {
514 return errors;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000515 }
reed@google.com46cce912011-06-29 12:54:46 +0000516 } else if (gRec.fBackend == kPDF_Backend) {
bungeman@google.comb29c8832011-10-10 13:19:10 +0000517 generate_pdf(gm, document);
reed@google.com46cce912011-06-29 12:54:46 +0000518#if CAN_IMAGE_PDF
bungeman@google.com0f1541f2011-10-10 13:47:06 +0000519 SkAutoDataUnref data(document.copyToData());
reed@google.com46cce912011-06-29 12:54:46 +0000520 SkMemoryStream stream(data.data(), data.size());
521 SkPDFDocumentToBitmap(&stream, bitmap);
522#endif
bungeman@google.comb29c8832011-10-10 13:19:10 +0000523 } else if (gRec.fBackend == kXPS_Backend) {
524 generate_xps(gm, document);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000525 }
tomhudson@google.com8e728d72011-04-26 20:22:57 +0000526 return handle_test_results(gm, gRec, writePath, readPath, diffPath,
bungeman@google.comb29c8832011-10-10 13:19:10 +0000527 "", *bitmap, &document, NULL);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000528}
529
junov@google.com4370aed2012-01-18 16:21:08 +0000530static ErrorBitfield test_deferred_drawing(GM* gm,
531 const ConfigData& gRec,
532 const SkBitmap& comparisonBitmap,
533 const char diffPath [],
534 GrContext* context,
535 GrRenderTarget* rt) {
536 SkDynamicMemoryWStream document;
537
538 if (gRec.fBackend == kRaster_Backend ||
539 gRec.fBackend == kGPU_Backend) {
540 SkBitmap bitmap;
541 // Early exit if we can't generate the image, but this is
542 // expected in some cases, so don't report a test failure.
543 if (!generate_image(gm, gRec, context, rt, &bitmap, true)) {
544 return ERROR_NONE;
545 }
546 return handle_test_results(gm, gRec, NULL, NULL, diffPath,
547 "-deferred", bitmap, NULL, &comparisonBitmap);
548 }
549 return ERROR_NONE;
550}
551
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000552static ErrorBitfield test_picture_playback(GM* gm,
553 const ConfigData& gRec,
554 const SkBitmap& comparisonBitmap,
555 const char readPath [],
556 const char diffPath []) {
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000557 SkPicture* pict = generate_new_picture(gm);
558 SkAutoUnref aur(pict);
559
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000560 if (kRaster_Backend == gRec.fBackend) {
561 SkBitmap bitmap;
562 generate_image_from_picture(gm, gRec, pict, &bitmap);
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000563 return handle_test_results(gm, gRec, NULL, NULL, diffPath,
564 "-replay", bitmap, NULL, &comparisonBitmap);
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000565 } else {
566 return ERROR_NONE;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000567 }
568}
569
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000570static ErrorBitfield test_picture_serialization(GM* gm,
571 const ConfigData& gRec,
572 const SkBitmap& comparisonBitmap,
573 const char readPath [],
574 const char diffPath []) {
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000575 SkPicture* pict = generate_new_picture(gm);
576 SkAutoUnref aurp(pict);
577 SkPicture* repict = stream_to_new_picture(*pict);
578 SkAutoUnref aurr(repict);
579
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000580 if (kRaster_Backend == gRec.fBackend) {
581 SkBitmap bitmap;
582 generate_image_from_picture(gm, gRec, repict, &bitmap);
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000583 return handle_test_results(gm, gRec, NULL, NULL, diffPath,
584 "-serialize", bitmap, NULL, &comparisonBitmap);
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000585 } else {
586 return ERROR_NONE;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000587 }
588}
589
590static void usage(const char * argv0) {
junov@google.com77e498e2012-01-18 18:56:34 +0000591 SkDebugf(
592 "%s [-w writePath] [-r readPath] [-d diffPath] [--noreplay]\n"
593 " [--serialize] [--forceBWtext] [--nopdf] [--nodeferred]\n"
twiz@google.come24a0792012-01-31 18:35:30 +0000594 " [--match substring] [--notexturecache]"
junov@google.com77e498e2012-01-18 18:56:34 +0000595#if SK_MESA
596 " [--mesagl]"
597#endif
598 "\n\n", argv0);
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000599 SkDebugf(" writePath: directory to write rendered images in.\n");
tomhudson@google.com73fb0422011-04-25 19:20:54 +0000600 SkDebugf(
601" readPath: directory to read reference images from;\n"
602" reports if any pixels mismatch between reference and new images\n");
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000603 SkDebugf(" diffPath: directory to write difference images in.\n");
junov@google.com77e498e2012-01-18 18:56:34 +0000604 SkDebugf(" --noreplay: do not exercise SkPicture replay.\n");
tomhudson@google.com73fb0422011-04-25 19:20:54 +0000605 SkDebugf(
606" --serialize: exercise SkPicture serialization & deserialization.\n");
junov@google.com77e498e2012-01-18 18:56:34 +0000607 SkDebugf(" --forceBWtext: disable text anti-aliasing.\n");
608 SkDebugf(" --nopdf: skip the pdf rendering test pass.\n");
609 SkDebugf(" --nodeferred: skip the deferred rendering test pass.\n");
reed@google.come6a5c4d2011-07-25 14:30:54 +0000610 SkDebugf(" --match foo will only run tests that substring match foo.\n");
bsalomon@google.com373a6632011-10-19 20:43:20 +0000611#if SK_MESA
612 SkDebugf(" --mesagl will run using the osmesa sw gl rasterizer.\n");
613#endif
twiz@google.come24a0792012-01-31 18:35:30 +0000614 SkDebugf(" --notexturecache: disable the gpu texture cache.\n");
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
epoger@google.com7bc13a62012-02-14 14:53:59 +0000658 setSystemPreferences();
659
reed@android.com8015dd82009-06-21 00:49:18 +0000660 const char* writePath = NULL; // if non-null, where we write the originals
661 const char* readPath = NULL; // if non-null, were we read from to compare
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000662 const char* diffPath = NULL; // if non-null, where we write our diffs (from compare)
reed@android.com8015dd82009-06-21 00:49:18 +0000663
reed@google.comb2a51622011-10-31 16:30:04 +0000664 SkTDArray<const char*> fMatches;
twiz@google.come24a0792012-01-31 18:35:30 +0000665
reed@google.comab973972011-09-19 19:01:38 +0000666 bool doPDF = true;
reed@google.comb8b09832011-05-26 15:57:56 +0000667 bool doReplay = true;
tomhudson@google.com6abfa492011-04-26 14:59:32 +0000668 bool doSerialize = false;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000669 bool useMesa = false;
junov@google.com4370aed2012-01-18 16:21:08 +0000670 bool doDeferred = true;
twiz@google.come24a0792012-01-31 18:35:30 +0000671 bool disableTextureCache = false;
672
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000673 const char* const commandName = argv[0];
reed@android.com8015dd82009-06-21 00:49:18 +0000674 char* const* stop = argv + argc;
675 for (++argv; argv < stop; ++argv) {
676 if (strcmp(*argv, "-w") == 0) {
677 argv++;
678 if (argv < stop && **argv) {
679 writePath = *argv;
680 }
681 } else if (strcmp(*argv, "-r") == 0) {
682 argv++;
683 if (argv < stop && **argv) {
684 readPath = *argv;
685 }
reed@google.com3d3f0922010-12-20 21:10:29 +0000686 } else if (strcmp(*argv, "-d") == 0) {
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000687 argv++;
reed@google.com3d3f0922010-12-20 21:10:29 +0000688 if (argv < stop && **argv) {
689 diffPath = *argv;
690 }
mike@reedtribe.org10afbef2011-12-30 16:02:53 +0000691 } else if (strcmp(*argv, "--forceBWtext") == 0) {
692 gForceBWtext = true;
reed@google.comb8b09832011-05-26 15:57:56 +0000693 } else if (strcmp(*argv, "--noreplay") == 0) {
694 doReplay = false;
reed@google.comab973972011-09-19 19:01:38 +0000695 } else if (strcmp(*argv, "--nopdf") == 0) {
696 doPDF = false;
junov@google.com4370aed2012-01-18 16:21:08 +0000697 } else if (strcmp(*argv, "--nodeferred") == 0) {
698 doDeferred = false;
tomhudson@google.com73fb0422011-04-25 19:20:54 +0000699 } else if (strcmp(*argv, "--serialize") == 0) {
700 doSerialize = true;
reed@google.comece2b022011-07-25 14:28:57 +0000701 } else if (strcmp(*argv, "--match") == 0) {
702 ++argv;
703 if (argv < stop && **argv) {
reed@google.comb2a51622011-10-31 16:30:04 +0000704 // just record the ptr, no need for a deep copy
705 *fMatches.append() = *argv;
reed@google.comece2b022011-07-25 14:28:57 +0000706 }
bsalomon@google.com373a6632011-10-19 20:43:20 +0000707#if SK_MESA
708 } else if (strcmp(*argv, "--mesagl") == 0) {
709 useMesa = true;
710#endif
twiz@google.come24a0792012-01-31 18:35:30 +0000711 } else if (strcmp(*argv, "--notexturecache") == 0) {
712 disableTextureCache = true;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000713 } else {
714 usage(commandName);
tomhudson@google.com8e728d72011-04-26 20:22:57 +0000715 return -1;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000716 }
717 }
718 if (argv != stop) {
719 usage(commandName);
tomhudson@google.com8e728d72011-04-26 20:22:57 +0000720 return -1;
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000721 }
reed@google.com873cb1e2010-12-23 15:00:45 +0000722
bsalomon@google.com39149582011-06-13 21:55:32 +0000723 int maxW = -1;
724 int maxH = -1;
725 Iter iter;
726 GM* gm;
727 while ((gm = iter.next()) != NULL) {
728 SkISize size = gm->getISize();
729 maxW = SkMax32(size.width(), maxW);
730 maxH = SkMax32(size.height(), maxH);
731 }
reed@google.com873cb1e2010-12-23 15:00:45 +0000732 // setup a GL context for drawing offscreen
bsalomon@google.com373a6632011-10-19 20:43:20 +0000733 SkAutoTUnref<SkGLContext> glContext;
734#if SK_MESA
735 if (useMesa) {
736 glContext.reset(new SkMesaGLContext());
737 } else
738#endif
739 {
740 glContext.reset(new SkNativeGLContext());
741 }
742
bsalomon@google.com29d35012011-11-30 16:57:21 +0000743 GrPlatformRenderTargetDesc rtDesc;
bsalomon@google.com373a6632011-10-19 20:43:20 +0000744 if (glContext.get()->init(maxW, maxH)) {
745 GrPlatform3DContext ctx =
746 reinterpret_cast<GrPlatform3DContext>(glContext.get()->gl());
747 gGrContext = GrContext::Create(kOpenGL_Shaders_GrEngine, ctx);
bsalomon@google.com971d0c82011-08-19 17:22:05 +0000748 if (NULL != gGrContext) {
bsalomon@google.com29d35012011-11-30 16:57:21 +0000749 rtDesc.fConfig = kSkia8888_PM_GrPixelConfig;
750 rtDesc.fStencilBits = 8;
751 rtDesc.fRenderTargetHandle = glContext.get()->getFBOID();
bsalomon@google.com971d0c82011-08-19 17:22:05 +0000752 }
bsalomon@google.com373a6632011-10-19 20:43:20 +0000753 } else {
754 fprintf(stderr, "could not create GL context.\n");
reed@google.com37df17d2010-12-23 20:20:51 +0000755 }
reed@google.com873cb1e2010-12-23 15:00:45 +0000756
reed@android.com00f883e2010-12-14 17:46:14 +0000757 if (readPath) {
758 fprintf(stderr, "reading from %s\n", readPath);
759 } else if (writePath) {
760 fprintf(stderr, "writing to %s\n", writePath);
761 }
762
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000763 // Accumulate success of all tests.
764 int testsRun = 0;
765 int testsPassed = 0;
766 int testsFailed = 0;
767 int testsMissingReferenceImages = 0;
768
twiz@google.come24a0792012-01-31 18:35:30 +0000769 if (disableTextureCache) {
770 skiagm::GetGr()->setTextureCacheLimits(0, 0);
771 }
772
bsalomon@google.com39149582011-06-13 21:55:32 +0000773 iter.reset();
reed@android.com00dae862009-06-10 15:38:48 +0000774 while ((gm = iter.next()) != NULL) {
reed@google.comece2b022011-07-25 14:28:57 +0000775 const char* shortName = gm->shortName();
reed@google.comb2a51622011-10-31 16:30:04 +0000776 if (skip_name(fMatches, shortName)) {
reed@google.comece2b022011-07-25 14:28:57 +0000777 SkDELETE(gm);
778 continue;
779 }
780
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000781 SkISize size = gm->getISize();
reed@google.comece2b022011-07-25 14:28:57 +0000782 SkDebugf("drawing... %s [%d %d]\n", shortName,
reed@android.com8015dd82009-06-21 00:49:18 +0000783 size.width(), size.height());
tomhudson@google.comcae6b3f2011-06-17 13:11:45 +0000784 SkBitmap forwardRenderedBitmap;
reed@android.com8015dd82009-06-21 00:49:18 +0000785
bsalomon@google.com29d35012011-11-30 16:57:21 +0000786 // Above we created an fbo for the context at maxW x maxH size.
787 // Here we lie about the size of the rt. We claim it is the size
788 // desired by the test. The reason is that rasterization may change
789 // slightly when the viewport dimensions change. Previously, whenever
790 // a new test was checked in that bumped maxW or maxH several images
791 // would slightly change.
792 rtDesc.fWidth = size.width();
793 rtDesc.fHeight = size.height();
794 SkAutoTUnref<GrRenderTarget> rt;
795 if (gGrContext) {
796 rt.reset(gGrContext->createPlatformRenderTarget(rtDesc));
797 }
reed@google.comfbc21172011-09-19 19:08:33 +0000798
bsalomon@google.com29d35012011-11-30 16:57:21 +0000799 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000800 // Skip any tests that we don't even need to try.
bsalomon@google.com29d35012011-11-30 16:57:21 +0000801 uint32_t gmFlags = gm->getFlags();
twiz@google.come24a0792012-01-31 18:35:30 +0000802 if ((kPDF_Backend == gRec[i].fBackend) &&
bungeman@google.com64e011a2011-09-19 19:31:04 +0000803 (!doPDF || (gmFlags & GM::kSkipPDF_Flag)))
804 {
reed@google.comab973972011-09-19 19:01:38 +0000805 continue;
806 }
807
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000808 // Now we know that we want to run this test and record its
809 // success or failure.
810 ErrorBitfield testErrors = ERROR_NONE;
reed@android.com00dae862009-06-10 15:38:48 +0000811
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000812 if ((ERROR_NONE == testErrors) &&
813 (kGPU_Backend == gRec[i].fBackend) &&
814 (NULL == rt.get())) {
815 fprintf(stderr, "Could not create render target for gpu.\n");
816 testErrors |= ERROR_NO_GPU_CONTEXT;
tomhudson@google.com73fb0422011-04-25 19:20:54 +0000817 }
vandebo@chromium.org686abdf2011-02-03 23:00:40 +0000818
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000819 if (ERROR_NONE == testErrors) {
820 testErrors |= test_drawing(gm, gRec[i],
821 writePath, readPath, diffPath,
822 gGrContext,
823 rt.get(), &forwardRenderedBitmap);
824 }
825
junov@google.com4370aed2012-01-18 16:21:08 +0000826 if (doDeferred && !testErrors &&
twiz@google.come24a0792012-01-31 18:35:30 +0000827 (kGPU_Backend == gRec[i].fBackend ||
junov@google.com4370aed2012-01-18 16:21:08 +0000828 kRaster_Backend == gRec[i].fBackend)) {
829 testErrors |= test_deferred_drawing(gm, gRec[i],
830 forwardRenderedBitmap,
831 diffPath, gGrContext, rt.get());
832 }
833
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000834 if ((ERROR_NONE == testErrors) && doReplay &&
835 !(gmFlags & GM::kSkipPicture_Flag)) {
836 testErrors |= test_picture_playback(gm, gRec[i],
837 forwardRenderedBitmap,
838 readPath, diffPath);
839 }
840
841 if ((ERROR_NONE == testErrors) && doSerialize) {
842 testErrors |= test_picture_serialization(gm, gRec[i],
843 forwardRenderedBitmap,
844 readPath, diffPath);
845 }
846
847 // Update overall results.
848 // We only tabulate the particular error types that we currently
849 // care about (e.g., missing reference images). Later on, if we
850 // want to also tabulate pixel mismatches vs dimension mistmatches
851 // (or whatever else), we can do so.
852 testsRun++;
853 if (ERROR_NONE == testErrors) {
854 testsPassed++;
855 } else if (ERROR_READING_REFERENCE_IMAGE & testErrors) {
856 testsMissingReferenceImages++;
857 } else {
858 testsFailed++;
tomhudson@google.com73fb0422011-04-25 19:20:54 +0000859 }
tomhudson@google.com9875dd12011-04-25 15:49:53 +0000860 }
reed@android.com00dae862009-06-10 15:38:48 +0000861 SkDELETE(gm);
862 }
epoger@google.comc7cf2b32011-12-28 19:31:01 +0000863 printf("Ran %d tests: %d passed, %d failed, %d missing reference images\n",
864 testsRun, testsPassed, testsFailed, testsMissingReferenceImages);
865 return (0 == testsFailed) ? 0 : -1;
reed@android.com00dae862009-06-10 15:38:48 +0000866}