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); |
| 426 | if ((ERROR_NONE == errors) && diffPath) { |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 427 | SkString diffName = make_filename(diffPath, "", name, ".diff.png"); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 428 | if (!write_bitmap(diffName, diffBitmap)) { |
| 429 | errors |= ERROR_WRITING_REFERENCE_IMAGE; |
| 430 | } |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 431 | } |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 432 | return errors; |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 433 | } |
| 434 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 435 | static ErrorBitfield compare_to_reference_image(const char readPath [], |
| 436 | const SkString& name, |
| 437 | SkBitmap &bitmap, |
| 438 | const char diffPath [], |
| 439 | const char renderModeDescriptor []) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 440 | SkString path = make_filename(readPath, "", name, "png"); |
| 441 | SkBitmap orig; |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 442 | if (SkImageDecoder::DecodeFile(path.c_str(), &orig, |
| 443 | SkBitmap::kARGB_8888_Config, |
| 444 | SkImageDecoder::kDecodePixels_Mode, NULL)) { |
| 445 | return compare_to_reference_image(name, bitmap, |
| 446 | orig, diffPath, |
| 447 | renderModeDescriptor); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 448 | } else { |
| 449 | fprintf(stderr, "FAILED to read %s\n", path.c_str()); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 450 | return ERROR_READING_REFERENCE_IMAGE; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 451 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 452 | } |
| 453 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 454 | static ErrorBitfield handle_test_results(GM* gm, |
| 455 | const ConfigData& gRec, |
| 456 | const char writePath [], |
| 457 | const char readPath [], |
| 458 | const char diffPath [], |
| 459 | const char renderModeDescriptor [], |
| 460 | SkBitmap& bitmap, |
| 461 | SkDynamicMemoryWStream* pdf, |
| 462 | const SkBitmap* comparisonBitmap) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 463 | SkString name = make_name(gm->shortName(), gRec.fName); |
| 464 | |
| 465 | if (writePath) { |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 466 | return write_reference_image(gRec, writePath, renderModeDescriptor, |
| 467 | name, bitmap, pdf); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 468 | } else if (readPath && ( |
| 469 | gRec.fBackend == kRaster_Backend || |
| 470 | gRec.fBackend == kGPU_Backend || |
| 471 | (gRec.fBackend == kPDF_Backend && CAN_IMAGE_PDF))) { |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 472 | return compare_to_reference_image(readPath, name, bitmap, |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 473 | diffPath, renderModeDescriptor); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 474 | } else if (comparisonBitmap) { |
| 475 | return compare_to_reference_image(name, bitmap, |
| 476 | *comparisonBitmap, diffPath, |
| 477 | renderModeDescriptor); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 478 | } else { |
| 479 | return ERROR_NONE; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 480 | } |
| 481 | } |
| 482 | |
| 483 | static SkPicture* generate_new_picture(GM* gm) { |
| 484 | // Pictures are refcounted so must be on heap |
| 485 | SkPicture* pict = new SkPicture; |
| 486 | SkCanvas* cv = pict->beginRecording(1000, 1000); |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 487 | invokeGM(gm, cv); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 488 | pict->endRecording(); |
| 489 | |
| 490 | return pict; |
| 491 | } |
| 492 | |
| 493 | static SkPicture* stream_to_new_picture(const SkPicture& src) { |
| 494 | |
| 495 | // To do in-memory commiunications with a stream, we need to: |
| 496 | // * create a dynamic memory stream |
| 497 | // * copy it into a buffer |
| 498 | // * create a read stream from it |
| 499 | // ?!?! |
| 500 | |
| 501 | SkDynamicMemoryWStream storage; |
| 502 | src.serialize(&storage); |
| 503 | |
| 504 | int streamSize = storage.getOffset(); |
| 505 | SkAutoMalloc dstStorage(streamSize); |
| 506 | void* dst = dstStorage.get(); |
| 507 | //char* dst = new char [streamSize]; |
| 508 | //@todo thudson 22 April 2011 when can we safely delete [] dst? |
| 509 | storage.copyTo(dst); |
| 510 | SkMemoryStream pictReadback(dst, streamSize); |
| 511 | SkPicture* retval = new SkPicture (&pictReadback); |
| 512 | return retval; |
| 513 | } |
| 514 | |
| 515 | // Test: draw into a bitmap or pdf. |
| 516 | // Depending on flags, possibly compare to an expected image |
| 517 | // and possibly output a diff image if it fails to match. |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 518 | static ErrorBitfield test_drawing(GM* gm, |
| 519 | const ConfigData& gRec, |
| 520 | const char writePath [], |
| 521 | const char readPath [], |
| 522 | const char diffPath [], |
| 523 | GrContext* context, |
| 524 | GrRenderTarget* rt, |
| 525 | SkBitmap* bitmap) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 526 | SkDynamicMemoryWStream document; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 527 | |
| 528 | if (gRec.fBackend == kRaster_Backend || |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 529 | gRec.fBackend == kGPU_Backend) { |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 530 | // Early exit if we can't generate the image. |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 531 | ErrorBitfield errors = generate_image(gm, gRec, context, rt, bitmap, |
| 532 | false); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 533 | if (ERROR_NONE != errors) { |
| 534 | return errors; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 535 | } |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 536 | } else if (gRec.fBackend == kPDF_Backend) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 537 | generate_pdf(gm, document); |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 538 | #if CAN_IMAGE_PDF |
bungeman@google.com | 0f1541f | 2011-10-10 13:47:06 +0000 | [diff] [blame] | 539 | SkAutoDataUnref data(document.copyToData()); |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 540 | SkMemoryStream stream(data.data(), data.size()); |
| 541 | SkPDFDocumentToBitmap(&stream, bitmap); |
| 542 | #endif |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 543 | } else if (gRec.fBackend == kXPS_Backend) { |
| 544 | generate_xps(gm, document); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 545 | } |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 546 | return handle_test_results(gm, gRec, writePath, readPath, diffPath, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 547 | "", *bitmap, &document, NULL); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 548 | } |
| 549 | |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 550 | static ErrorBitfield test_deferred_drawing(GM* gm, |
| 551 | const ConfigData& gRec, |
| 552 | const SkBitmap& comparisonBitmap, |
| 553 | const char diffPath [], |
| 554 | GrContext* context, |
| 555 | GrRenderTarget* rt) { |
| 556 | SkDynamicMemoryWStream document; |
| 557 | |
| 558 | if (gRec.fBackend == kRaster_Backend || |
| 559 | gRec.fBackend == kGPU_Backend) { |
| 560 | SkBitmap bitmap; |
| 561 | // Early exit if we can't generate the image, but this is |
| 562 | // expected in some cases, so don't report a test failure. |
| 563 | if (!generate_image(gm, gRec, context, rt, &bitmap, true)) { |
| 564 | return ERROR_NONE; |
| 565 | } |
| 566 | return handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 567 | "-deferred", bitmap, NULL, &comparisonBitmap); |
| 568 | } |
| 569 | return ERROR_NONE; |
| 570 | } |
| 571 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 572 | static ErrorBitfield test_picture_playback(GM* gm, |
| 573 | const ConfigData& gRec, |
| 574 | const SkBitmap& comparisonBitmap, |
| 575 | const char readPath [], |
| 576 | const char diffPath []) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 577 | SkPicture* pict = generate_new_picture(gm); |
| 578 | SkAutoUnref aur(pict); |
| 579 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 580 | if (kRaster_Backend == gRec.fBackend) { |
| 581 | SkBitmap bitmap; |
| 582 | generate_image_from_picture(gm, gRec, pict, &bitmap); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 583 | return handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 584 | "-replay", bitmap, NULL, &comparisonBitmap); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 585 | } else { |
| 586 | return ERROR_NONE; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 587 | } |
| 588 | } |
| 589 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 590 | static ErrorBitfield test_picture_serialization(GM* gm, |
| 591 | const ConfigData& gRec, |
| 592 | const SkBitmap& comparisonBitmap, |
| 593 | const char readPath [], |
| 594 | const char diffPath []) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 595 | SkPicture* pict = generate_new_picture(gm); |
| 596 | SkAutoUnref aurp(pict); |
| 597 | SkPicture* repict = stream_to_new_picture(*pict); |
| 598 | SkAutoUnref aurr(repict); |
| 599 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 600 | if (kRaster_Backend == gRec.fBackend) { |
| 601 | SkBitmap bitmap; |
| 602 | generate_image_from_picture(gm, gRec, repict, &bitmap); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 603 | return handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 604 | "-serialize", bitmap, NULL, &comparisonBitmap); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 605 | } else { |
| 606 | return ERROR_NONE; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 607 | } |
| 608 | } |
| 609 | |
| 610 | static void usage(const char * argv0) { |
junov@google.com | 77e498e | 2012-01-18 18:56:34 +0000 | [diff] [blame] | 611 | SkDebugf( |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 612 | "%s [-w writePath] [-r readPath] [-d diffPath] [-i resourcePath]\n" |
| 613 | " [--noreplay] [--serialize] [--forceBWtext] [--nopdf] \n" |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 614 | " [--nodeferred] [--match substring] [--notexturecache]\n" |
| 615 | " " |
junov@google.com | 77e498e | 2012-01-18 18:56:34 +0000 | [diff] [blame] | 616 | #if SK_MESA |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 617 | "[--mesagl]" |
junov@google.com | 77e498e | 2012-01-18 18:56:34 +0000 | [diff] [blame] | 618 | #endif |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 619 | #if SK_ANGLE |
| 620 | " [--angle]" |
| 621 | #endif |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 622 | " [--debuggl]\n\n", argv0); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 623 | SkDebugf(" writePath: directory to write rendered images in.\n"); |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 624 | SkDebugf( |
| 625 | " readPath: directory to read reference images from;\n" |
| 626 | " reports if any pixels mismatch between reference and new images\n"); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 627 | SkDebugf(" diffPath: directory to write difference images in.\n"); |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 628 | SkDebugf(" resourcePath: directory that stores image resources.\n"); |
junov@google.com | 77e498e | 2012-01-18 18:56:34 +0000 | [diff] [blame] | 629 | SkDebugf(" --noreplay: do not exercise SkPicture replay.\n"); |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 630 | SkDebugf( |
| 631 | " --serialize: exercise SkPicture serialization & deserialization.\n"); |
junov@google.com | 77e498e | 2012-01-18 18:56:34 +0000 | [diff] [blame] | 632 | SkDebugf(" --forceBWtext: disable text anti-aliasing.\n"); |
| 633 | SkDebugf(" --nopdf: skip the pdf rendering test pass.\n"); |
| 634 | SkDebugf(" --nodeferred: skip the deferred rendering test pass.\n"); |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 635 | 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] | 636 | #if SK_MESA |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 637 | SkDebugf(" --mesagl: will run using the osmesa sw gl rasterizer.\n"); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 638 | #endif |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 639 | #if SK_ANGLE |
| 640 | SkDebugf(" --angle: use ANGLE backend on Windows.\n"); |
| 641 | #endif |
| 642 | SkDebugf(" --debuggl: will run using the debugging gl utility.\n"); |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 643 | SkDebugf(" --notexturecache: disable the gpu texture cache.\n"); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | static const ConfigData gRec[] = { |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 647 | { SkBitmap::kARGB_8888_Config, kRaster_Backend, "8888" }, |
| 648 | { SkBitmap::kARGB_4444_Config, kRaster_Backend, "4444" }, |
| 649 | { SkBitmap::kRGB_565_Config, kRaster_Backend, "565" }, |
reed@google.com | 1a7e946 | 2011-06-20 13:21:24 +0000 | [diff] [blame] | 650 | #ifdef SK_SCALAR_IS_FLOAT |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 651 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, "gpu" }, |
reed@google.com | 1a7e946 | 2011-06-20 13:21:24 +0000 | [diff] [blame] | 652 | #endif |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 653 | #ifdef SK_SUPPORT_PDF |
| 654 | { SkBitmap::kARGB_8888_Config, kPDF_Backend, "pdf" }, |
| 655 | #endif |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 656 | #ifdef SK_SUPPORT_XPS |
| 657 | { SkBitmap::kARGB_8888_Config, kXPS_Backend, "xps" }, |
| 658 | #endif |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 659 | }; |
| 660 | |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 661 | static bool skip_name(const SkTDArray<const char*> array, const char name[]) { |
| 662 | if (0 == array.count()) { |
| 663 | // no names, so don't skip anything |
| 664 | return false; |
| 665 | } |
| 666 | for (int i = 0; i < array.count(); ++i) { |
| 667 | if (strstr(name, array[i])) { |
| 668 | // found the name, so don't skip |
| 669 | return false; |
| 670 | } |
| 671 | } |
| 672 | return true; |
| 673 | } |
| 674 | |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 675 | namespace skiagm { |
| 676 | static GrContext* gGrContext; |
| 677 | GrContext* GetGr() { |
| 678 | return gGrContext; |
| 679 | } |
| 680 | } |
| 681 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 682 | int main(int argc, char * const argv[]) { |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 683 | SkAutoGraphics ag; |
reed@google.com | 8923c6c | 2011-11-08 14:59:38 +0000 | [diff] [blame] | 684 | // we don't need to see this during a run |
| 685 | gSkSuppressFontCachePurgeSpew = true; |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 686 | |
epoger@google.com | 7bc13a6 | 2012-02-14 14:53:59 +0000 | [diff] [blame] | 687 | setSystemPreferences(); |
| 688 | |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 689 | const char* writePath = NULL; // if non-null, where we write the originals |
| 690 | 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] | 691 | 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] | 692 | 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] | 693 | |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 694 | SkTDArray<const char*> fMatches; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 695 | |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 696 | bool doPDF = true; |
reed@google.com | b8b0983 | 2011-05-26 15:57:56 +0000 | [diff] [blame] | 697 | bool doReplay = true; |
tomhudson@google.com | 6abfa49 | 2011-04-26 14:59:32 +0000 | [diff] [blame] | 698 | bool doSerialize = false; |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 699 | #if SK_MESA |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 700 | bool useMesa = false; |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 701 | #endif |
| 702 | #if SK_ANGLE |
| 703 | bool useAngle = false; |
| 704 | #endif |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 705 | bool useDebugGL = false; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 706 | bool doDeferred = true; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 707 | bool disableTextureCache = false; |
| 708 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 709 | const char* const commandName = argv[0]; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 710 | char* const* stop = argv + argc; |
| 711 | for (++argv; argv < stop; ++argv) { |
| 712 | if (strcmp(*argv, "-w") == 0) { |
| 713 | argv++; |
| 714 | if (argv < stop && **argv) { |
| 715 | writePath = *argv; |
| 716 | } |
| 717 | } else if (strcmp(*argv, "-r") == 0) { |
| 718 | argv++; |
| 719 | if (argv < stop && **argv) { |
| 720 | readPath = *argv; |
| 721 | } |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 722 | } else if (strcmp(*argv, "-d") == 0) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 723 | argv++; |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 724 | if (argv < stop && **argv) { |
| 725 | diffPath = *argv; |
| 726 | } |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 727 | } else if (strcmp(*argv, "-i") == 0) { |
| 728 | argv++; |
| 729 | if (argv < stop && **argv) { |
| 730 | resourcePath = *argv; |
| 731 | } |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 732 | } else if (strcmp(*argv, "--forceBWtext") == 0) { |
| 733 | gForceBWtext = true; |
reed@google.com | b8b0983 | 2011-05-26 15:57:56 +0000 | [diff] [blame] | 734 | } else if (strcmp(*argv, "--noreplay") == 0) { |
| 735 | doReplay = false; |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 736 | } else if (strcmp(*argv, "--nopdf") == 0) { |
| 737 | doPDF = false; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 738 | } else if (strcmp(*argv, "--nodeferred") == 0) { |
| 739 | doDeferred = false; |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 740 | } else if (strcmp(*argv, "--serialize") == 0) { |
| 741 | doSerialize = true; |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 742 | } else if (strcmp(*argv, "--match") == 0) { |
| 743 | ++argv; |
| 744 | if (argv < stop && **argv) { |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 745 | // just record the ptr, no need for a deep copy |
| 746 | *fMatches.append() = *argv; |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 747 | } |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 748 | #if SK_MESA |
| 749 | } else if (strcmp(*argv, "--mesagl") == 0) { |
| 750 | useMesa = true; |
| 751 | #endif |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 752 | #if SK_ANGLE |
| 753 | } else if (strcmp(*argv, "--angle") == 0) { |
| 754 | useAngle = true; |
| 755 | #endif |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 756 | } else if (strcmp(*argv, "--debuggl") == 0) { |
| 757 | useDebugGL = true; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 758 | } else if (strcmp(*argv, "--notexturecache") == 0) { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 759 | disableTextureCache = true; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 760 | } else { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 761 | usage(commandName); |
| 762 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 763 | } |
| 764 | } |
| 765 | if (argv != stop) { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 766 | usage(commandName); |
| 767 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 768 | } |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 769 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 770 | GM::SetResourcePath(resourcePath); |
| 771 | |
bsalomon@google.com | 3914958 | 2011-06-13 21:55:32 +0000 | [diff] [blame] | 772 | int maxW = -1; |
| 773 | int maxH = -1; |
| 774 | Iter iter; |
| 775 | GM* gm; |
| 776 | while ((gm = iter.next()) != NULL) { |
| 777 | SkISize size = gm->getISize(); |
| 778 | maxW = SkMax32(size.width(), maxW); |
| 779 | maxH = SkMax32(size.height(), maxH); |
tomhudson@google.com | 7816a4e | 2012-03-15 13:39:51 +0000 | [diff] [blame] | 780 | // This fixes a memory leak, but we are churning gms; we could |
| 781 | // instead cache them if we have constructors with side-effects. |
| 782 | SkDELETE(gm); |
bsalomon@google.com | 3914958 | 2011-06-13 21:55:32 +0000 | [diff] [blame] | 783 | } |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 784 | // setup a GL context for drawing offscreen |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 785 | SkAutoTUnref<SkGLContext> glContext; |
| 786 | #if SK_MESA |
| 787 | if (useMesa) { |
| 788 | glContext.reset(new SkMesaGLContext()); |
| 789 | } else |
| 790 | #endif |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 791 | #if SK_ANGLE |
| 792 | if (useAngle) { |
| 793 | glContext.reset(new SkANGLEGLContext()); |
| 794 | } else |
| 795 | #endif |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 796 | if (useDebugGL) { |
| 797 | glContext.reset(new SkDebugGLContext()); |
| 798 | } else { |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 799 | glContext.reset(new SkNativeGLContext()); |
| 800 | } |
| 801 | |
bsalomon@google.com | 29d3501 | 2011-11-30 16:57:21 +0000 | [diff] [blame] | 802 | GrPlatformRenderTargetDesc rtDesc; |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 803 | if (glContext.get()->init(maxW, maxH)) { |
| 804 | GrPlatform3DContext ctx = |
| 805 | reinterpret_cast<GrPlatform3DContext>(glContext.get()->gl()); |
| 806 | gGrContext = GrContext::Create(kOpenGL_Shaders_GrEngine, ctx); |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 807 | if (NULL != gGrContext) { |
bsalomon@google.com | 29d3501 | 2011-11-30 16:57:21 +0000 | [diff] [blame] | 808 | rtDesc.fConfig = kSkia8888_PM_GrPixelConfig; |
| 809 | rtDesc.fStencilBits = 8; |
| 810 | rtDesc.fRenderTargetHandle = glContext.get()->getFBOID(); |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 811 | } |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 812 | } else { |
| 813 | fprintf(stderr, "could not create GL context.\n"); |
reed@google.com | 37df17d | 2010-12-23 20:20:51 +0000 | [diff] [blame] | 814 | } |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 815 | |
reed@android.com | 00f883e | 2010-12-14 17:46:14 +0000 | [diff] [blame] | 816 | if (readPath) { |
| 817 | fprintf(stderr, "reading from %s\n", readPath); |
| 818 | } else if (writePath) { |
| 819 | fprintf(stderr, "writing to %s\n", writePath); |
| 820 | } |
| 821 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 822 | if (resourcePath) { |
| 823 | fprintf(stderr, "reading resources from %s\n", resourcePath); |
| 824 | } |
| 825 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 826 | // Accumulate success of all tests. |
| 827 | int testsRun = 0; |
| 828 | int testsPassed = 0; |
| 829 | int testsFailed = 0; |
| 830 | int testsMissingReferenceImages = 0; |
| 831 | |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 832 | if (disableTextureCache) { |
| 833 | skiagm::GetGr()->setTextureCacheLimits(0, 0); |
| 834 | } |
| 835 | |
bsalomon@google.com | 3914958 | 2011-06-13 21:55:32 +0000 | [diff] [blame] | 836 | iter.reset(); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 837 | while ((gm = iter.next()) != NULL) { |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 838 | const char* shortName = gm->shortName(); |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 839 | if (skip_name(fMatches, shortName)) { |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 840 | SkDELETE(gm); |
| 841 | continue; |
| 842 | } |
| 843 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 844 | SkISize size = gm->getISize(); |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 845 | SkDebugf("drawing... %s [%d %d]\n", shortName, |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 846 | size.width(), size.height()); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 847 | SkBitmap forwardRenderedBitmap; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 848 | |
bsalomon@google.com | 29d3501 | 2011-11-30 16:57:21 +0000 | [diff] [blame] | 849 | // Above we created an fbo for the context at maxW x maxH size. |
| 850 | // Here we lie about the size of the rt. We claim it is the size |
| 851 | // desired by the test. The reason is that rasterization may change |
| 852 | // slightly when the viewport dimensions change. Previously, whenever |
| 853 | // a new test was checked in that bumped maxW or maxH several images |
| 854 | // would slightly change. |
| 855 | rtDesc.fWidth = size.width(); |
| 856 | rtDesc.fHeight = size.height(); |
| 857 | SkAutoTUnref<GrRenderTarget> rt; |
| 858 | if (gGrContext) { |
| 859 | rt.reset(gGrContext->createPlatformRenderTarget(rtDesc)); |
| 860 | } |
reed@google.com | fbc2117 | 2011-09-19 19:08:33 +0000 | [diff] [blame] | 861 | |
bsalomon@google.com | 29d3501 | 2011-11-30 16:57:21 +0000 | [diff] [blame] | 862 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 863 | // Skip any tests that we don't even need to try. |
bsalomon@google.com | 29d3501 | 2011-11-30 16:57:21 +0000 | [diff] [blame] | 864 | uint32_t gmFlags = gm->getFlags(); |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 865 | if ((kPDF_Backend == gRec[i].fBackend) && |
bungeman@google.com | 64e011a | 2011-09-19 19:31:04 +0000 | [diff] [blame] | 866 | (!doPDF || (gmFlags & GM::kSkipPDF_Flag))) |
| 867 | { |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 868 | continue; |
| 869 | } |
| 870 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 871 | // Now we know that we want to run this test and record its |
| 872 | // success or failure. |
| 873 | ErrorBitfield testErrors = ERROR_NONE; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 874 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 875 | if ((ERROR_NONE == testErrors) && |
| 876 | (kGPU_Backend == gRec[i].fBackend) && |
| 877 | (NULL == rt.get())) { |
| 878 | fprintf(stderr, "Could not create render target for gpu.\n"); |
| 879 | testErrors |= ERROR_NO_GPU_CONTEXT; |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 880 | } |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 881 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 882 | if (ERROR_NONE == testErrors) { |
| 883 | testErrors |= test_drawing(gm, gRec[i], |
| 884 | writePath, readPath, diffPath, |
| 885 | gGrContext, |
| 886 | rt.get(), &forwardRenderedBitmap); |
| 887 | } |
| 888 | |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 889 | if (doDeferred && !testErrors && |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 890 | (kGPU_Backend == gRec[i].fBackend || |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 891 | kRaster_Backend == gRec[i].fBackend)) { |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 892 | testErrors |= test_deferred_drawing(gm, gRec[i], |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 893 | forwardRenderedBitmap, |
| 894 | diffPath, gGrContext, rt.get()); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 895 | } |
| 896 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 897 | if ((ERROR_NONE == testErrors) && doReplay && |
| 898 | !(gmFlags & GM::kSkipPicture_Flag)) { |
| 899 | testErrors |= test_picture_playback(gm, gRec[i], |
| 900 | forwardRenderedBitmap, |
| 901 | readPath, diffPath); |
| 902 | } |
| 903 | |
djsollen@google.com | a2ca41e | 2012-03-23 19:00:34 +0000 | [diff] [blame] | 904 | if ((ERROR_NONE == testErrors) && doSerialize && |
| 905 | !(gmFlags & GM::kSkipPicture_Flag)) { |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 906 | testErrors |= test_picture_serialization(gm, gRec[i], |
| 907 | forwardRenderedBitmap, |
| 908 | readPath, diffPath); |
| 909 | } |
| 910 | |
| 911 | // Update overall results. |
| 912 | // We only tabulate the particular error types that we currently |
| 913 | // care about (e.g., missing reference images). Later on, if we |
| 914 | // want to also tabulate pixel mismatches vs dimension mistmatches |
| 915 | // (or whatever else), we can do so. |
| 916 | testsRun++; |
| 917 | if (ERROR_NONE == testErrors) { |
| 918 | testsPassed++; |
| 919 | } else if (ERROR_READING_REFERENCE_IMAGE & testErrors) { |
| 920 | testsMissingReferenceImages++; |
| 921 | } else { |
| 922 | testsFailed++; |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 923 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 924 | } |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 925 | SkDELETE(gm); |
| 926 | } |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 927 | printf("Ran %d tests: %d passed, %d failed, %d missing reference images\n", |
| 928 | testsRun, testsPassed, testsFailed, testsMissingReferenceImages); |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 929 | |
| 930 | SkDELETE(skiagm::gGrContext); |
| 931 | skiagm::gGrContext = NULL; |
| 932 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 933 | return (0 == testsFailed) ? 0 : -1; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 934 | } |