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