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