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