epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 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.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 7 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 8 | #include "gm.h" |
epoger@google.com | 7bc13a6 | 2012-02-14 14:53:59 +0000 | [diff] [blame] | 9 | #include "system_preferences.h" |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 10 | #include "GrContext.h" |
| 11 | #include "GrRenderTarget.h" |
| 12 | |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 13 | #include "SkColorPriv.h" |
reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 14 | #include "SkData.h" |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 15 | #include "SkDeferredCanvas.h" |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 16 | #include "SkDevice.h" |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 17 | #include "SkGpuCanvas.h" |
| 18 | #include "SkGpuDevice.h" |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 19 | #include "SkGraphics.h" |
| 20 | #include "SkImageDecoder.h" |
| 21 | #include "SkImageEncoder.h" |
tomhudson@google.com | 6bf38b5 | 2012-02-14 15:11:59 +0000 | [diff] [blame] | 22 | #include "gl/SkNativeGLContext.h" |
| 23 | #include "gl/SkMesaGLContext.h" |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame^] | 24 | #include "gl/SkDebugGLContext.h" |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 25 | #include "SkPicture.h" |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 26 | #include "SkStream.h" |
| 27 | #include "SkRefCnt.h" |
| 28 | |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 29 | static bool gForceBWtext; |
| 30 | |
reed@google.com | 8923c6c | 2011-11-08 14:59:38 +0000 | [diff] [blame] | 31 | extern bool gSkSuppressFontCachePurgeSpew; |
| 32 | |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 33 | #ifdef SK_SUPPORT_PDF |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 34 | #include "SkPDFDevice.h" |
| 35 | #include "SkPDFDocument.h" |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 36 | #endif |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 37 | |
epoger@google.com | e3cc2eb | 2012-01-18 20:11:13 +0000 | [diff] [blame] | 38 | // Until we resolve http://code.google.com/p/skia/issues/detail?id=455 , |
| 39 | // stop writing out XPS-format image baselines in gm. |
| 40 | #undef SK_SUPPORT_XPS |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 41 | #ifdef SK_SUPPORT_XPS |
| 42 | #include "SkXPSDevice.h" |
| 43 | #endif |
| 44 | |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 45 | #ifdef SK_BUILD_FOR_MAC |
| 46 | #include "SkCGUtils.h" |
bsalomon@google.com | 0a09eef | 2011-06-29 19:42:58 +0000 | [diff] [blame] | 47 | #define CAN_IMAGE_PDF 1 |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 48 | #else |
bsalomon@google.com | 0a09eef | 2011-06-29 19:42:58 +0000 | [diff] [blame] | 49 | #define CAN_IMAGE_PDF 0 |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 50 | #endif |
| 51 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 52 | typedef int ErrorBitfield; |
| 53 | const static ErrorBitfield ERROR_NONE = 0x00; |
| 54 | const static ErrorBitfield ERROR_NO_GPU_CONTEXT = 0x01; |
| 55 | const static ErrorBitfield ERROR_PIXEL_MISMATCH = 0x02; |
| 56 | const static ErrorBitfield ERROR_DIMENSION_MISMATCH = 0x04; |
| 57 | const static ErrorBitfield ERROR_READING_REFERENCE_IMAGE = 0x08; |
| 58 | const static ErrorBitfield ERROR_WRITING_REFERENCE_IMAGE = 0x10; |
| 59 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 60 | using namespace skiagm; |
| 61 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 62 | class Iter { |
| 63 | public: |
| 64 | Iter() { |
bsalomon@google.com | 3914958 | 2011-06-13 21:55:32 +0000 | [diff] [blame] | 65 | this->reset(); |
| 66 | } |
| 67 | |
| 68 | void reset() { |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 69 | fReg = GMRegistry::Head(); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 70 | } |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 71 | |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 72 | GM* next() { |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 73 | if (fReg) { |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 74 | GMRegistry::Factory fact = fReg->factory(); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 75 | fReg = fReg->next(); |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 76 | return fact(0); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 77 | } |
| 78 | return NULL; |
| 79 | } |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 80 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 81 | static int Count() { |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 82 | const GMRegistry* reg = GMRegistry::Head(); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 83 | int count = 0; |
| 84 | while (reg) { |
| 85 | count += 1; |
| 86 | reg = reg->next(); |
| 87 | } |
| 88 | return count; |
| 89 | } |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 90 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 91 | private: |
| 92 | const GMRegistry* fReg; |
| 93 | }; |
| 94 | |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 95 | static SkString make_name(const char shortName[], const char configName[]) { |
| 96 | SkString name(shortName); |
| 97 | name.appendf("_%s", configName); |
| 98 | return name; |
| 99 | } |
| 100 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 101 | static SkString make_filename(const char path[], |
| 102 | const char pathSuffix[], |
| 103 | const SkString& name, |
| 104 | const char suffix[]) { |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 105 | SkString filename(path); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 106 | if (filename.endsWith("/")) { |
| 107 | filename.remove(filename.size() - 1, 1); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 108 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 109 | filename.append(pathSuffix); |
| 110 | filename.append("/"); |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 111 | filename.appendf("%s.%s", name.c_str(), suffix); |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 112 | return filename; |
| 113 | } |
| 114 | |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 115 | /* since PNG insists on unpremultiplying our alpha, we take no precision chances |
| 116 | and force all pixels to be 100% opaque, otherwise on compare we may not get |
| 117 | a perfect match. |
| 118 | */ |
| 119 | static void force_all_opaque(const SkBitmap& bitmap) { |
| 120 | SkAutoLockPixels lock(bitmap); |
| 121 | for (int y = 0; y < bitmap.height(); y++) { |
| 122 | for (int x = 0; x < bitmap.width(); x++) { |
| 123 | *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT); |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | static bool write_bitmap(const SkString& path, const SkBitmap& bitmap) { |
| 129 | SkBitmap copy; |
| 130 | bitmap.copyTo(©, SkBitmap::kARGB_8888_Config); |
| 131 | force_all_opaque(copy); |
| 132 | return SkImageEncoder::EncodeFile(path.c_str(), copy, |
| 133 | SkImageEncoder::kPNG_Type, 100); |
| 134 | } |
| 135 | |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 136 | static inline SkPMColor compute_diff_pmcolor(SkPMColor c0, SkPMColor c1) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 137 | int dr = SkGetPackedR32(c0) - SkGetPackedR32(c1); |
| 138 | int dg = SkGetPackedG32(c0) - SkGetPackedG32(c1); |
| 139 | int db = SkGetPackedB32(c0) - SkGetPackedB32(c1); |
| 140 | return SkPackARGB32(0xFF, SkAbs32(dr), SkAbs32(dg), SkAbs32(db)); |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | static void compute_diff(const SkBitmap& target, const SkBitmap& base, |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 144 | SkBitmap* diff) { |
| 145 | SkAutoLockPixels alp(*diff); |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 146 | |
| 147 | const int w = target.width(); |
| 148 | const int h = target.height(); |
| 149 | for (int y = 0; y < h; y++) { |
| 150 | for (int x = 0; x < w; x++) { |
| 151 | SkPMColor c0 = *base.getAddr32(x, y); |
| 152 | SkPMColor c1 = *target.getAddr32(x, y); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 153 | SkPMColor d = 0; |
| 154 | if (c0 != c1) { |
| 155 | d = compute_diff_pmcolor(c0, c1); |
| 156 | } |
| 157 | *diff->getAddr32(x, y) = d; |
| 158 | } |
| 159 | } |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 160 | } |
| 161 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 162 | static ErrorBitfield compare(const SkBitmap& target, const SkBitmap& base, |
| 163 | const SkString& name, |
| 164 | const char* renderModeDescriptor, |
| 165 | SkBitmap* diff) { |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 166 | SkBitmap copy; |
| 167 | const SkBitmap* bm = ⌖ |
| 168 | if (target.config() != SkBitmap::kARGB_8888_Config) { |
| 169 | target.copyTo(©, SkBitmap::kARGB_8888_Config); |
| 170 | bm = © |
| 171 | } |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 172 | SkBitmap baseCopy; |
| 173 | const SkBitmap* bp = &base; |
| 174 | if (base.config() != SkBitmap::kARGB_8888_Config) { |
| 175 | base.copyTo(&baseCopy, SkBitmap::kARGB_8888_Config); |
| 176 | bp = &baseCopy; |
| 177 | } |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 178 | |
| 179 | force_all_opaque(*bm); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 180 | force_all_opaque(*bp); |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 181 | |
| 182 | const int w = bm->width(); |
| 183 | const int h = bm->height(); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 184 | if (w != bp->width() || h != bp->height()) { |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 185 | SkDebugf( |
| 186 | "---- %s dimensions mismatch for %s base [%d %d] current [%d %d]\n", |
| 187 | renderModeDescriptor, name.c_str(), |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 188 | bp->width(), bp->height(), w, h); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 189 | return ERROR_DIMENSION_MISMATCH; |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | SkAutoLockPixels bmLock(*bm); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 193 | SkAutoLockPixels baseLock(*bp); |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 194 | |
| 195 | for (int y = 0; y < h; y++) { |
| 196 | for (int x = 0; x < w; x++) { |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 197 | SkPMColor c0 = *bp->getAddr32(x, y); |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 198 | SkPMColor c1 = *bm->getAddr32(x, y); |
| 199 | if (c0 != c1) { |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 200 | SkDebugf( |
| 201 | "----- %s pixel mismatch for %s at [%d %d] base 0x%08X current 0x%08X\n", |
| 202 | renderModeDescriptor, name.c_str(), x, y, c0, c1); |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 203 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 204 | if (diff) { |
| 205 | diff->setConfig(SkBitmap::kARGB_8888_Config, w, h); |
| 206 | diff->allocPixels(); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 207 | compute_diff(*bm, *bp, diff); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 208 | } |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 209 | return ERROR_PIXEL_MISMATCH; |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | } |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 213 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 214 | // they're equal |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 215 | return ERROR_NONE; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 216 | } |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 217 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 218 | static bool write_document(const SkString& path, |
| 219 | const SkDynamicMemoryWStream& document) { |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 220 | SkFILEWStream stream(path.c_str()); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 221 | SkAutoDataUnref data(document.copyToData()); |
reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 222 | return stream.writeData(data.get()); |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 223 | } |
| 224 | |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 225 | enum Backend { |
| 226 | kRaster_Backend, |
| 227 | kGPU_Backend, |
| 228 | kPDF_Backend, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 229 | kXPS_Backend, |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 230 | }; |
| 231 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 232 | struct ConfigData { |
| 233 | SkBitmap::Config fConfig; |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 234 | Backend fBackend; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 235 | const char* fName; |
| 236 | }; |
| 237 | |
| 238 | /// Returns true if processing should continue, false to skip the |
| 239 | /// remainder of this config for this GM. |
| 240 | //@todo thudson 22 April 2011 - could refactor this to take in |
| 241 | // a factory to generate the context, always call readPixels() |
| 242 | // (logically a noop for rasters, if wasted time), and thus collapse the |
| 243 | // GPU special case and also let this be used for SkPicture testing. |
| 244 | static void setup_bitmap(const ConfigData& gRec, SkISize& size, |
| 245 | SkBitmap* bitmap) { |
| 246 | bitmap->setConfig(gRec.fConfig, size.width(), size.height()); |
| 247 | bitmap->allocPixels(); |
| 248 | bitmap->eraseColor(0); |
| 249 | } |
| 250 | |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 251 | #include "SkDrawFilter.h" |
| 252 | class BWTextDrawFilter : public SkDrawFilter { |
| 253 | public: |
| 254 | virtual void filter(SkPaint*, Type) SK_OVERRIDE; |
| 255 | }; |
| 256 | void BWTextDrawFilter::filter(SkPaint* p, Type t) { |
| 257 | if (kText_Type == t) { |
| 258 | p->setAntiAlias(false); |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | static void installFilter(SkCanvas* canvas) { |
| 263 | if (gForceBWtext) { |
| 264 | canvas->setDrawFilter(new BWTextDrawFilter)->unref(); |
| 265 | } |
| 266 | } |
| 267 | |
vandebo@chromium.org | 79d3cb4 | 2012-03-21 17:34:30 +0000 | [diff] [blame] | 268 | static void invokeGM(GM* gm, SkCanvas* canvas, bool isPDF = false) { |
| 269 | if (!isPDF) { |
| 270 | canvas->setMatrix(gm->getInitialTransform()); |
| 271 | } |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 272 | installFilter(canvas); |
| 273 | gm->draw(canvas); |
| 274 | canvas->setDrawFilter(NULL); |
| 275 | } |
| 276 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 277 | static ErrorBitfield generate_image(GM* gm, const ConfigData& gRec, |
| 278 | GrContext* context, |
| 279 | GrRenderTarget* rt, |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 280 | SkBitmap* bitmap, |
| 281 | bool deferred) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 282 | SkISize size (gm->getISize()); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 283 | setup_bitmap(gRec, size, bitmap); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 284 | |
| 285 | if (gRec.fBackend == kRaster_Backend) { |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 286 | SkCanvas* canvas; |
| 287 | if (deferred) { |
| 288 | canvas = new SkDeferredCanvas; |
| 289 | canvas->setDevice(new SkDevice(*bitmap))->unref(); |
| 290 | } else { |
| 291 | canvas = new SkCanvas(*bitmap); |
| 292 | } |
| 293 | SkAutoUnref canvasUnref(canvas); |
| 294 | invokeGM(gm, canvas); |
junov@chromium.org | bf6c1e4 | 2012-01-30 14:53:22 +0000 | [diff] [blame] | 295 | canvas->flush(); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 296 | } else { // GPU |
| 297 | if (NULL == context) { |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 298 | return ERROR_NO_GPU_CONTEXT; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 299 | } |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 300 | SkCanvas* gc; |
| 301 | if (deferred) { |
| 302 | gc = new SkDeferredCanvas; |
| 303 | } else { |
| 304 | gc = new SkGpuCanvas(context, rt); |
| 305 | } |
| 306 | SkAutoUnref gcUnref(gc); |
| 307 | gc->setDevice(new SkGpuDevice(context, rt))->unref(); |
| 308 | invokeGM(gm, gc); |
reed@google.com | af951c9 | 2011-06-16 19:10:39 +0000 | [diff] [blame] | 309 | // the device is as large as the current rendertarget, so we explicitly |
| 310 | // only readback the amount we expect (in size) |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 311 | // overwrite our previous allocation |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 312 | bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth, |
| 313 | size.fHeight); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 314 | gc->readPixels(bitmap, 0, 0); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 315 | } |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 316 | return ERROR_NONE; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | static void generate_image_from_picture(GM* gm, const ConfigData& gRec, |
| 320 | SkPicture* pict, SkBitmap* bitmap) { |
| 321 | SkISize size = gm->getISize(); |
| 322 | setup_bitmap(gRec, size, bitmap); |
| 323 | SkCanvas canvas(*bitmap); |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 324 | installFilter(&canvas); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 325 | canvas.drawPicture(*pict); |
| 326 | } |
| 327 | |
| 328 | static void generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) { |
| 329 | #ifdef SK_SUPPORT_PDF |
vandebo@chromium.org | 79d3cb4 | 2012-03-21 17:34:30 +0000 | [diff] [blame] | 330 | SkMatrix initialTransform = gm->getInitialTransform(); |
| 331 | SkISize pageSize = gm->getISize(); |
| 332 | SkPDFDevice* dev = NULL; |
| 333 | if (initialTransform.isIdentity()) { |
| 334 | dev = new SkPDFDevice(pageSize, pageSize, initialTransform); |
| 335 | } else { |
| 336 | SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()), |
| 337 | SkIntToScalar(pageSize.height())); |
| 338 | initialTransform.mapRect(&content); |
| 339 | content.intersect(0, 0, SkIntToScalar(pageSize.width()), |
| 340 | SkIntToScalar(pageSize.height())); |
| 341 | SkISize contentSize = |
| 342 | SkISize::Make(SkScalarRoundToInt(content.width()), |
| 343 | SkScalarRoundToInt(content.height())); |
| 344 | dev = new SkPDFDevice(pageSize, contentSize, initialTransform); |
| 345 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 346 | SkAutoUnref aur(dev); |
| 347 | |
| 348 | SkCanvas c(dev); |
vandebo@chromium.org | 79d3cb4 | 2012-03-21 17:34:30 +0000 | [diff] [blame] | 349 | invokeGM(gm, &c, true); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 350 | |
| 351 | SkPDFDocument doc; |
| 352 | doc.appendPage(dev); |
| 353 | doc.emitPDF(&pdf); |
| 354 | #endif |
| 355 | } |
| 356 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 357 | static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) { |
| 358 | #ifdef SK_SUPPORT_XPS |
| 359 | SkISize size = gm->getISize(); |
| 360 | |
| 361 | SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()), |
| 362 | SkIntToScalar(size.height())); |
bungeman@google.com | dc9a695 | 2012-01-05 16:56:29 +0000 | [diff] [blame] | 363 | static const SkScalar inchesPerMeter = SkScalarDiv(10000, 254); |
| 364 | static const SkScalar upm = 72 * inchesPerMeter; |
| 365 | SkVector unitsPerMeter = SkPoint::Make(upm, upm); |
| 366 | static const SkScalar ppm = 200 * inchesPerMeter; |
| 367 | SkVector pixelsPerMeter = SkPoint::Make(ppm, ppm); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 368 | |
| 369 | SkXPSDevice* dev = new SkXPSDevice(); |
| 370 | SkAutoUnref aur(dev); |
| 371 | |
| 372 | SkCanvas c(dev); |
| 373 | dev->beginPortfolio(&xps); |
| 374 | dev->beginSheet(unitsPerMeter, pixelsPerMeter, trimSize); |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 375 | invokeGM(gm, &c); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 376 | dev->endSheet(); |
| 377 | dev->endPortfolio(); |
| 378 | |
| 379 | #endif |
| 380 | } |
| 381 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 382 | static ErrorBitfield write_reference_image(const ConfigData& gRec, |
| 383 | const char writePath [], |
| 384 | const char renderModeDescriptor [], |
| 385 | const SkString& name, |
| 386 | SkBitmap& bitmap, |
| 387 | SkDynamicMemoryWStream* document) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 388 | SkString path; |
| 389 | bool success = false; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 390 | if (gRec.fBackend == kRaster_Backend || |
| 391 | gRec.fBackend == kGPU_Backend || |
| 392 | (gRec.fBackend == kPDF_Backend && CAN_IMAGE_PDF)) { |
| 393 | |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 394 | path = make_filename(writePath, renderModeDescriptor, name, "png"); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 395 | success = write_bitmap(path, bitmap); |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 396 | } |
| 397 | if (kPDF_Backend == gRec.fBackend) { |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 398 | path = make_filename(writePath, renderModeDescriptor, name, "pdf"); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 399 | success = write_document(path, *document); |
| 400 | } |
| 401 | if (kXPS_Backend == gRec.fBackend) { |
| 402 | path = make_filename(writePath, renderModeDescriptor, name, "xps"); |
| 403 | success = write_document(path, *document); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 404 | } |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 405 | if (success) { |
| 406 | return ERROR_NONE; |
| 407 | } else { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 408 | fprintf(stderr, "FAILED to write %s\n", path.c_str()); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 409 | return ERROR_WRITING_REFERENCE_IMAGE; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 413 | static ErrorBitfield compare_to_reference_image(const SkString& name, |
| 414 | SkBitmap &bitmap, |
| 415 | const SkBitmap& comparisonBitmap, |
| 416 | const char diffPath [], |
| 417 | const char renderModeDescriptor []) { |
| 418 | ErrorBitfield errors; |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 419 | SkBitmap diffBitmap; |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 420 | errors = compare(bitmap, comparisonBitmap, name, renderModeDescriptor, |
| 421 | diffPath ? &diffBitmap : NULL); |
| 422 | if ((ERROR_NONE == errors) && diffPath) { |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 423 | SkString diffName = make_filename(diffPath, "", name, ".diff.png"); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 424 | if (!write_bitmap(diffName, diffBitmap)) { |
| 425 | errors |= ERROR_WRITING_REFERENCE_IMAGE; |
| 426 | } |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 427 | } |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 428 | return errors; |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 429 | } |
| 430 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 431 | static ErrorBitfield compare_to_reference_image(const char readPath [], |
| 432 | const SkString& name, |
| 433 | SkBitmap &bitmap, |
| 434 | const char diffPath [], |
| 435 | const char renderModeDescriptor []) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 436 | SkString path = make_filename(readPath, "", name, "png"); |
| 437 | SkBitmap orig; |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 438 | if (SkImageDecoder::DecodeFile(path.c_str(), &orig, |
| 439 | SkBitmap::kARGB_8888_Config, |
| 440 | SkImageDecoder::kDecodePixels_Mode, NULL)) { |
| 441 | return compare_to_reference_image(name, bitmap, |
| 442 | orig, diffPath, |
| 443 | renderModeDescriptor); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 444 | } else { |
| 445 | fprintf(stderr, "FAILED to read %s\n", path.c_str()); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 446 | return ERROR_READING_REFERENCE_IMAGE; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 447 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 448 | } |
| 449 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 450 | static ErrorBitfield handle_test_results(GM* gm, |
| 451 | const ConfigData& gRec, |
| 452 | const char writePath [], |
| 453 | const char readPath [], |
| 454 | const char diffPath [], |
| 455 | const char renderModeDescriptor [], |
| 456 | SkBitmap& bitmap, |
| 457 | SkDynamicMemoryWStream* pdf, |
| 458 | const SkBitmap* comparisonBitmap) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 459 | SkString name = make_name(gm->shortName(), gRec.fName); |
| 460 | |
| 461 | if (writePath) { |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 462 | return write_reference_image(gRec, writePath, renderModeDescriptor, |
| 463 | name, bitmap, pdf); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 464 | } else if (readPath && ( |
| 465 | gRec.fBackend == kRaster_Backend || |
| 466 | gRec.fBackend == kGPU_Backend || |
| 467 | (gRec.fBackend == kPDF_Backend && CAN_IMAGE_PDF))) { |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 468 | return compare_to_reference_image(readPath, name, bitmap, |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 469 | diffPath, renderModeDescriptor); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 470 | } else if (comparisonBitmap) { |
| 471 | return compare_to_reference_image(name, bitmap, |
| 472 | *comparisonBitmap, diffPath, |
| 473 | renderModeDescriptor); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 474 | } else { |
| 475 | return ERROR_NONE; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 476 | } |
| 477 | } |
| 478 | |
| 479 | static SkPicture* generate_new_picture(GM* gm) { |
| 480 | // Pictures are refcounted so must be on heap |
| 481 | SkPicture* pict = new SkPicture; |
| 482 | SkCanvas* cv = pict->beginRecording(1000, 1000); |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 483 | invokeGM(gm, cv); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 484 | pict->endRecording(); |
| 485 | |
| 486 | return pict; |
| 487 | } |
| 488 | |
| 489 | static SkPicture* stream_to_new_picture(const SkPicture& src) { |
| 490 | |
| 491 | // To do in-memory commiunications with a stream, we need to: |
| 492 | // * create a dynamic memory stream |
| 493 | // * copy it into a buffer |
| 494 | // * create a read stream from it |
| 495 | // ?!?! |
| 496 | |
| 497 | SkDynamicMemoryWStream storage; |
| 498 | src.serialize(&storage); |
| 499 | |
| 500 | int streamSize = storage.getOffset(); |
| 501 | SkAutoMalloc dstStorage(streamSize); |
| 502 | void* dst = dstStorage.get(); |
| 503 | //char* dst = new char [streamSize]; |
| 504 | //@todo thudson 22 April 2011 when can we safely delete [] dst? |
| 505 | storage.copyTo(dst); |
| 506 | SkMemoryStream pictReadback(dst, streamSize); |
| 507 | SkPicture* retval = new SkPicture (&pictReadback); |
| 508 | return retval; |
| 509 | } |
| 510 | |
| 511 | // Test: draw into a bitmap or pdf. |
| 512 | // Depending on flags, possibly compare to an expected image |
| 513 | // and possibly output a diff image if it fails to match. |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 514 | static ErrorBitfield test_drawing(GM* gm, |
| 515 | const ConfigData& gRec, |
| 516 | const char writePath [], |
| 517 | const char readPath [], |
| 518 | const char diffPath [], |
| 519 | GrContext* context, |
| 520 | GrRenderTarget* rt, |
| 521 | SkBitmap* bitmap) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 522 | SkDynamicMemoryWStream document; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 523 | |
| 524 | if (gRec.fBackend == kRaster_Backend || |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 525 | gRec.fBackend == kGPU_Backend) { |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 526 | // Early exit if we can't generate the image. |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 527 | ErrorBitfield errors = generate_image(gm, gRec, context, rt, bitmap, |
| 528 | false); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 529 | if (ERROR_NONE != errors) { |
| 530 | return errors; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 531 | } |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 532 | } else if (gRec.fBackend == kPDF_Backend) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 533 | generate_pdf(gm, document); |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 534 | #if CAN_IMAGE_PDF |
bungeman@google.com | 0f1541f | 2011-10-10 13:47:06 +0000 | [diff] [blame] | 535 | SkAutoDataUnref data(document.copyToData()); |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 536 | SkMemoryStream stream(data.data(), data.size()); |
| 537 | SkPDFDocumentToBitmap(&stream, bitmap); |
| 538 | #endif |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 539 | } else if (gRec.fBackend == kXPS_Backend) { |
| 540 | generate_xps(gm, document); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 541 | } |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 542 | return handle_test_results(gm, gRec, writePath, readPath, diffPath, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 543 | "", *bitmap, &document, NULL); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 544 | } |
| 545 | |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 546 | static ErrorBitfield test_deferred_drawing(GM* gm, |
| 547 | const ConfigData& gRec, |
| 548 | const SkBitmap& comparisonBitmap, |
| 549 | const char diffPath [], |
| 550 | GrContext* context, |
| 551 | GrRenderTarget* rt) { |
| 552 | SkDynamicMemoryWStream document; |
| 553 | |
| 554 | if (gRec.fBackend == kRaster_Backend || |
| 555 | gRec.fBackend == kGPU_Backend) { |
| 556 | SkBitmap bitmap; |
| 557 | // Early exit if we can't generate the image, but this is |
| 558 | // expected in some cases, so don't report a test failure. |
| 559 | if (!generate_image(gm, gRec, context, rt, &bitmap, true)) { |
| 560 | return ERROR_NONE; |
| 561 | } |
| 562 | return handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 563 | "-deferred", bitmap, NULL, &comparisonBitmap); |
| 564 | } |
| 565 | return ERROR_NONE; |
| 566 | } |
| 567 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 568 | static ErrorBitfield test_picture_playback(GM* gm, |
| 569 | const ConfigData& gRec, |
| 570 | const SkBitmap& comparisonBitmap, |
| 571 | const char readPath [], |
| 572 | const char diffPath []) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 573 | SkPicture* pict = generate_new_picture(gm); |
| 574 | SkAutoUnref aur(pict); |
| 575 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 576 | if (kRaster_Backend == gRec.fBackend) { |
| 577 | SkBitmap bitmap; |
| 578 | generate_image_from_picture(gm, gRec, pict, &bitmap); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 579 | return handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 580 | "-replay", bitmap, NULL, &comparisonBitmap); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 581 | } else { |
| 582 | return ERROR_NONE; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 583 | } |
| 584 | } |
| 585 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 586 | static ErrorBitfield test_picture_serialization(GM* gm, |
| 587 | const ConfigData& gRec, |
| 588 | const SkBitmap& comparisonBitmap, |
| 589 | const char readPath [], |
| 590 | const char diffPath []) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 591 | SkPicture* pict = generate_new_picture(gm); |
| 592 | SkAutoUnref aurp(pict); |
| 593 | SkPicture* repict = stream_to_new_picture(*pict); |
| 594 | SkAutoUnref aurr(repict); |
| 595 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 596 | if (kRaster_Backend == gRec.fBackend) { |
| 597 | SkBitmap bitmap; |
| 598 | generate_image_from_picture(gm, gRec, repict, &bitmap); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 599 | return handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 600 | "-serialize", bitmap, NULL, &comparisonBitmap); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 601 | } else { |
| 602 | return ERROR_NONE; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 603 | } |
| 604 | } |
| 605 | |
| 606 | static void usage(const char * argv0) { |
junov@google.com | 77e498e | 2012-01-18 18:56:34 +0000 | [diff] [blame] | 607 | SkDebugf( |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 608 | "%s [-w writePath] [-r readPath] [-d diffPath] [-i resourcePath]\n" |
| 609 | " [--noreplay] [--serialize] [--forceBWtext] [--nopdf] \n" |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame^] | 610 | " [--nodeferred] [--match substring] [--notexturecache]\n" |
| 611 | " " |
junov@google.com | 77e498e | 2012-01-18 18:56:34 +0000 | [diff] [blame] | 612 | #if SK_MESA |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame^] | 613 | "[--mesagl]" |
junov@google.com | 77e498e | 2012-01-18 18:56:34 +0000 | [diff] [blame] | 614 | #endif |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame^] | 615 | " [--debuggl]\n\n", argv0); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 616 | SkDebugf(" writePath: directory to write rendered images in.\n"); |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 617 | SkDebugf( |
| 618 | " readPath: directory to read reference images from;\n" |
| 619 | " reports if any pixels mismatch between reference and new images\n"); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 620 | SkDebugf(" diffPath: directory to write difference images in.\n"); |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 621 | SkDebugf(" resourcePath: directory that stores image resources.\n"); |
junov@google.com | 77e498e | 2012-01-18 18:56:34 +0000 | [diff] [blame] | 622 | SkDebugf(" --noreplay: do not exercise SkPicture replay.\n"); |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 623 | SkDebugf( |
| 624 | " --serialize: exercise SkPicture serialization & deserialization.\n"); |
junov@google.com | 77e498e | 2012-01-18 18:56:34 +0000 | [diff] [blame] | 625 | SkDebugf(" --forceBWtext: disable text anti-aliasing.\n"); |
| 626 | SkDebugf(" --nopdf: skip the pdf rendering test pass.\n"); |
| 627 | SkDebugf(" --nodeferred: skip the deferred rendering test pass.\n"); |
reed@google.com | e6a5c4d | 2011-07-25 14:30:54 +0000 | [diff] [blame] | 628 | SkDebugf(" --match foo will only run tests that substring match foo.\n"); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 629 | #if SK_MESA |
| 630 | SkDebugf(" --mesagl will run using the osmesa sw gl rasterizer.\n"); |
| 631 | #endif |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame^] | 632 | SkDebugf(" --debuggl will run using the debugging gl utility.\n"); |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 633 | SkDebugf(" --notexturecache: disable the gpu texture cache.\n"); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | static const ConfigData gRec[] = { |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 637 | { SkBitmap::kARGB_8888_Config, kRaster_Backend, "8888" }, |
| 638 | { SkBitmap::kARGB_4444_Config, kRaster_Backend, "4444" }, |
| 639 | { SkBitmap::kRGB_565_Config, kRaster_Backend, "565" }, |
reed@google.com | 1a7e946 | 2011-06-20 13:21:24 +0000 | [diff] [blame] | 640 | #ifdef SK_SCALAR_IS_FLOAT |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 641 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, "gpu" }, |
reed@google.com | 1a7e946 | 2011-06-20 13:21:24 +0000 | [diff] [blame] | 642 | #endif |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 643 | #ifdef SK_SUPPORT_PDF |
| 644 | { SkBitmap::kARGB_8888_Config, kPDF_Backend, "pdf" }, |
| 645 | #endif |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 646 | #ifdef SK_SUPPORT_XPS |
| 647 | { SkBitmap::kARGB_8888_Config, kXPS_Backend, "xps" }, |
| 648 | #endif |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 649 | }; |
| 650 | |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 651 | static bool skip_name(const SkTDArray<const char*> array, const char name[]) { |
| 652 | if (0 == array.count()) { |
| 653 | // no names, so don't skip anything |
| 654 | return false; |
| 655 | } |
| 656 | for (int i = 0; i < array.count(); ++i) { |
| 657 | if (strstr(name, array[i])) { |
| 658 | // found the name, so don't skip |
| 659 | return false; |
| 660 | } |
| 661 | } |
| 662 | return true; |
| 663 | } |
| 664 | |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 665 | namespace skiagm { |
| 666 | static GrContext* gGrContext; |
| 667 | GrContext* GetGr() { |
| 668 | return gGrContext; |
| 669 | } |
| 670 | } |
| 671 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 672 | int main(int argc, char * const argv[]) { |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 673 | SkAutoGraphics ag; |
reed@google.com | 8923c6c | 2011-11-08 14:59:38 +0000 | [diff] [blame] | 674 | // we don't need to see this during a run |
| 675 | gSkSuppressFontCachePurgeSpew = true; |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 676 | |
epoger@google.com | 7bc13a6 | 2012-02-14 14:53:59 +0000 | [diff] [blame] | 677 | setSystemPreferences(); |
| 678 | |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 679 | const char* writePath = NULL; // if non-null, where we write the originals |
| 680 | const char* readPath = NULL; // if non-null, were we read from to compare |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 681 | const char* diffPath = NULL; // if non-null, where we write our diffs (from compare) |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 682 | const char* resourcePath = NULL;// if non-null, where we read from for image resources |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 683 | |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 684 | SkTDArray<const char*> fMatches; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 685 | |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 686 | bool doPDF = true; |
reed@google.com | b8b0983 | 2011-05-26 15:57:56 +0000 | [diff] [blame] | 687 | bool doReplay = true; |
tomhudson@google.com | 6abfa49 | 2011-04-26 14:59:32 +0000 | [diff] [blame] | 688 | bool doSerialize = false; |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 689 | bool useMesa = false; |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame^] | 690 | bool useDebugGL = false; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 691 | bool doDeferred = true; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 692 | bool disableTextureCache = false; |
| 693 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 694 | const char* const commandName = argv[0]; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 695 | char* const* stop = argv + argc; |
| 696 | for (++argv; argv < stop; ++argv) { |
| 697 | if (strcmp(*argv, "-w") == 0) { |
| 698 | argv++; |
| 699 | if (argv < stop && **argv) { |
| 700 | writePath = *argv; |
| 701 | } |
| 702 | } else if (strcmp(*argv, "-r") == 0) { |
| 703 | argv++; |
| 704 | if (argv < stop && **argv) { |
| 705 | readPath = *argv; |
| 706 | } |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 707 | } else if (strcmp(*argv, "-d") == 0) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 708 | argv++; |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 709 | if (argv < stop && **argv) { |
| 710 | diffPath = *argv; |
| 711 | } |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 712 | } else if (strcmp(*argv, "-i") == 0) { |
| 713 | argv++; |
| 714 | if (argv < stop && **argv) { |
| 715 | resourcePath = *argv; |
| 716 | } |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 717 | } else if (strcmp(*argv, "--forceBWtext") == 0) { |
| 718 | gForceBWtext = true; |
reed@google.com | b8b0983 | 2011-05-26 15:57:56 +0000 | [diff] [blame] | 719 | } else if (strcmp(*argv, "--noreplay") == 0) { |
| 720 | doReplay = false; |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 721 | } else if (strcmp(*argv, "--nopdf") == 0) { |
| 722 | doPDF = false; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 723 | } else if (strcmp(*argv, "--nodeferred") == 0) { |
| 724 | doDeferred = false; |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 725 | } else if (strcmp(*argv, "--serialize") == 0) { |
| 726 | doSerialize = true; |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 727 | } else if (strcmp(*argv, "--match") == 0) { |
| 728 | ++argv; |
| 729 | if (argv < stop && **argv) { |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 730 | // just record the ptr, no need for a deep copy |
| 731 | *fMatches.append() = *argv; |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 732 | } |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 733 | #if SK_MESA |
| 734 | } else if (strcmp(*argv, "--mesagl") == 0) { |
| 735 | useMesa = true; |
| 736 | #endif |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame^] | 737 | } else if (strcmp(*argv, "--debuggl") == 0) { |
| 738 | useDebugGL = true; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 739 | } else if (strcmp(*argv, "--notexturecache") == 0) { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 740 | disableTextureCache = true; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 741 | } else { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 742 | usage(commandName); |
| 743 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 744 | } |
| 745 | } |
| 746 | if (argv != stop) { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 747 | usage(commandName); |
| 748 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 749 | } |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 750 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 751 | GM::SetResourcePath(resourcePath); |
| 752 | |
bsalomon@google.com | 3914958 | 2011-06-13 21:55:32 +0000 | [diff] [blame] | 753 | int maxW = -1; |
| 754 | int maxH = -1; |
| 755 | Iter iter; |
| 756 | GM* gm; |
| 757 | while ((gm = iter.next()) != NULL) { |
| 758 | SkISize size = gm->getISize(); |
| 759 | maxW = SkMax32(size.width(), maxW); |
| 760 | maxH = SkMax32(size.height(), maxH); |
tomhudson@google.com | 7816a4e | 2012-03-15 13:39:51 +0000 | [diff] [blame] | 761 | // This fixes a memory leak, but we are churning gms; we could |
| 762 | // instead cache them if we have constructors with side-effects. |
| 763 | SkDELETE(gm); |
bsalomon@google.com | 3914958 | 2011-06-13 21:55:32 +0000 | [diff] [blame] | 764 | } |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 765 | // setup a GL context for drawing offscreen |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 766 | SkAutoTUnref<SkGLContext> glContext; |
| 767 | #if SK_MESA |
| 768 | if (useMesa) { |
| 769 | glContext.reset(new SkMesaGLContext()); |
| 770 | } else |
| 771 | #endif |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame^] | 772 | if (useDebugGL) { |
| 773 | glContext.reset(new SkDebugGLContext()); |
| 774 | } else { |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 775 | glContext.reset(new SkNativeGLContext()); |
| 776 | } |
| 777 | |
bsalomon@google.com | 29d3501 | 2011-11-30 16:57:21 +0000 | [diff] [blame] | 778 | GrPlatformRenderTargetDesc rtDesc; |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 779 | if (glContext.get()->init(maxW, maxH)) { |
| 780 | GrPlatform3DContext ctx = |
| 781 | reinterpret_cast<GrPlatform3DContext>(glContext.get()->gl()); |
| 782 | gGrContext = GrContext::Create(kOpenGL_Shaders_GrEngine, ctx); |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 783 | if (NULL != gGrContext) { |
bsalomon@google.com | 29d3501 | 2011-11-30 16:57:21 +0000 | [diff] [blame] | 784 | rtDesc.fConfig = kSkia8888_PM_GrPixelConfig; |
| 785 | rtDesc.fStencilBits = 8; |
| 786 | rtDesc.fRenderTargetHandle = glContext.get()->getFBOID(); |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 787 | } |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 788 | } else { |
| 789 | fprintf(stderr, "could not create GL context.\n"); |
reed@google.com | 37df17d | 2010-12-23 20:20:51 +0000 | [diff] [blame] | 790 | } |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 791 | |
reed@android.com | 00f883e | 2010-12-14 17:46:14 +0000 | [diff] [blame] | 792 | if (readPath) { |
| 793 | fprintf(stderr, "reading from %s\n", readPath); |
| 794 | } else if (writePath) { |
| 795 | fprintf(stderr, "writing to %s\n", writePath); |
| 796 | } |
| 797 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 798 | if (resourcePath) { |
| 799 | fprintf(stderr, "reading resources from %s\n", resourcePath); |
| 800 | } |
| 801 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 802 | // Accumulate success of all tests. |
| 803 | int testsRun = 0; |
| 804 | int testsPassed = 0; |
| 805 | int testsFailed = 0; |
| 806 | int testsMissingReferenceImages = 0; |
| 807 | |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 808 | if (disableTextureCache) { |
| 809 | skiagm::GetGr()->setTextureCacheLimits(0, 0); |
| 810 | } |
| 811 | |
bsalomon@google.com | 3914958 | 2011-06-13 21:55:32 +0000 | [diff] [blame] | 812 | iter.reset(); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 813 | while ((gm = iter.next()) != NULL) { |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 814 | const char* shortName = gm->shortName(); |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 815 | if (skip_name(fMatches, shortName)) { |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 816 | SkDELETE(gm); |
| 817 | continue; |
| 818 | } |
| 819 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 820 | SkISize size = gm->getISize(); |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 821 | SkDebugf("drawing... %s [%d %d]\n", shortName, |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 822 | size.width(), size.height()); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 823 | SkBitmap forwardRenderedBitmap; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 824 | |
bsalomon@google.com | 29d3501 | 2011-11-30 16:57:21 +0000 | [diff] [blame] | 825 | // Above we created an fbo for the context at maxW x maxH size. |
| 826 | // Here we lie about the size of the rt. We claim it is the size |
| 827 | // desired by the test. The reason is that rasterization may change |
| 828 | // slightly when the viewport dimensions change. Previously, whenever |
| 829 | // a new test was checked in that bumped maxW or maxH several images |
| 830 | // would slightly change. |
| 831 | rtDesc.fWidth = size.width(); |
| 832 | rtDesc.fHeight = size.height(); |
| 833 | SkAutoTUnref<GrRenderTarget> rt; |
| 834 | if (gGrContext) { |
| 835 | rt.reset(gGrContext->createPlatformRenderTarget(rtDesc)); |
| 836 | } |
reed@google.com | fbc2117 | 2011-09-19 19:08:33 +0000 | [diff] [blame] | 837 | |
bsalomon@google.com | 29d3501 | 2011-11-30 16:57:21 +0000 | [diff] [blame] | 838 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 839 | // Skip any tests that we don't even need to try. |
bsalomon@google.com | 29d3501 | 2011-11-30 16:57:21 +0000 | [diff] [blame] | 840 | uint32_t gmFlags = gm->getFlags(); |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 841 | if ((kPDF_Backend == gRec[i].fBackend) && |
bungeman@google.com | 64e011a | 2011-09-19 19:31:04 +0000 | [diff] [blame] | 842 | (!doPDF || (gmFlags & GM::kSkipPDF_Flag))) |
| 843 | { |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 844 | continue; |
| 845 | } |
| 846 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 847 | // Now we know that we want to run this test and record its |
| 848 | // success or failure. |
| 849 | ErrorBitfield testErrors = ERROR_NONE; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 850 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 851 | if ((ERROR_NONE == testErrors) && |
| 852 | (kGPU_Backend == gRec[i].fBackend) && |
| 853 | (NULL == rt.get())) { |
| 854 | fprintf(stderr, "Could not create render target for gpu.\n"); |
| 855 | testErrors |= ERROR_NO_GPU_CONTEXT; |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 856 | } |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 857 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 858 | if (ERROR_NONE == testErrors) { |
| 859 | testErrors |= test_drawing(gm, gRec[i], |
| 860 | writePath, readPath, diffPath, |
| 861 | gGrContext, |
| 862 | rt.get(), &forwardRenderedBitmap); |
| 863 | } |
| 864 | |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 865 | if (doDeferred && !testErrors && |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 866 | (kGPU_Backend == gRec[i].fBackend || |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 867 | kRaster_Backend == gRec[i].fBackend)) { |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 868 | testErrors |= test_deferred_drawing(gm, gRec[i], |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 869 | forwardRenderedBitmap, |
| 870 | diffPath, gGrContext, rt.get()); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 871 | } |
| 872 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 873 | if ((ERROR_NONE == testErrors) && doReplay && |
| 874 | !(gmFlags & GM::kSkipPicture_Flag)) { |
| 875 | testErrors |= test_picture_playback(gm, gRec[i], |
| 876 | forwardRenderedBitmap, |
| 877 | readPath, diffPath); |
| 878 | } |
| 879 | |
| 880 | if ((ERROR_NONE == testErrors) && doSerialize) { |
| 881 | testErrors |= test_picture_serialization(gm, gRec[i], |
| 882 | forwardRenderedBitmap, |
| 883 | readPath, diffPath); |
| 884 | } |
| 885 | |
| 886 | // Update overall results. |
| 887 | // We only tabulate the particular error types that we currently |
| 888 | // care about (e.g., missing reference images). Later on, if we |
| 889 | // want to also tabulate pixel mismatches vs dimension mistmatches |
| 890 | // (or whatever else), we can do so. |
| 891 | testsRun++; |
| 892 | if (ERROR_NONE == testErrors) { |
| 893 | testsPassed++; |
| 894 | } else if (ERROR_READING_REFERENCE_IMAGE & testErrors) { |
| 895 | testsMissingReferenceImages++; |
| 896 | } else { |
| 897 | testsFailed++; |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 898 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 899 | } |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 900 | SkDELETE(gm); |
| 901 | } |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 902 | printf("Ran %d tests: %d passed, %d failed, %d missing reference images\n", |
| 903 | testsRun, testsPassed, testsFailed, testsMissingReferenceImages); |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame^] | 904 | |
| 905 | SkDELETE(skiagm::gGrContext); |
| 906 | skiagm::gGrContext = NULL; |
| 907 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 908 | return (0 == testsFailed) ? 0 : -1; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 909 | } |