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" |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 10 | #include "SkColorPriv.h" |
reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 11 | #include "SkData.h" |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 12 | #include "SkDeferredCanvas.h" |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 13 | #include "SkDevice.h" |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 14 | #include "SkDrawFilter.h" |
scroggo@google.com | 5af9b20 | 2012-06-04 17:17:36 +0000 | [diff] [blame] | 15 | #include "SkGPipe.h" |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 16 | #include "SkGraphics.h" |
| 17 | #include "SkImageDecoder.h" |
| 18 | #include "SkImageEncoder.h" |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 19 | #include "SkOSFile.h" |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 20 | #include "SkPicture.h" |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 21 | #include "SkRefCnt.h" |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 22 | #include "SkStream.h" |
bsalomon@google.com | 2a48c3a | 2012-08-03 14:54:45 +0000 | [diff] [blame] | 23 | #include "SkTArray.h" |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 24 | #include "SamplePipeControllers.h" |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 25 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 26 | #if SK_SUPPORT_GPU |
| 27 | #include "GrContextFactory.h" |
| 28 | #include "GrRenderTarget.h" |
| 29 | #include "SkGpuDevice.h" |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 30 | typedef GrContextFactory::GLContextType GLContextType; |
| 31 | #else |
| 32 | class GrContext; |
| 33 | class GrRenderTarget; |
| 34 | typedef int GLContextType; |
| 35 | #endif |
| 36 | |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 37 | static bool gForceBWtext; |
| 38 | |
reed@google.com | 8923c6c | 2011-11-08 14:59:38 +0000 | [diff] [blame] | 39 | extern bool gSkSuppressFontCachePurgeSpew; |
| 40 | |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 41 | #ifdef SK_SUPPORT_PDF |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 42 | #include "SkPDFDevice.h" |
| 43 | #include "SkPDFDocument.h" |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 44 | #endif |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 45 | |
epoger@google.com | e3cc2eb | 2012-01-18 20:11:13 +0000 | [diff] [blame] | 46 | // Until we resolve http://code.google.com/p/skia/issues/detail?id=455 , |
| 47 | // stop writing out XPS-format image baselines in gm. |
| 48 | #undef SK_SUPPORT_XPS |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 49 | #ifdef SK_SUPPORT_XPS |
| 50 | #include "SkXPSDevice.h" |
| 51 | #endif |
| 52 | |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 53 | #ifdef SK_BUILD_FOR_MAC |
| 54 | #include "SkCGUtils.h" |
bsalomon@google.com | 0a09eef | 2011-06-29 19:42:58 +0000 | [diff] [blame] | 55 | #define CAN_IMAGE_PDF 1 |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 56 | #else |
bsalomon@google.com | 0a09eef | 2011-06-29 19:42:58 +0000 | [diff] [blame] | 57 | #define CAN_IMAGE_PDF 0 |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 58 | #endif |
| 59 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 60 | typedef int ErrorBitfield; |
| 61 | const static ErrorBitfield ERROR_NONE = 0x00; |
| 62 | const static ErrorBitfield ERROR_NO_GPU_CONTEXT = 0x01; |
| 63 | const static ErrorBitfield ERROR_PIXEL_MISMATCH = 0x02; |
| 64 | const static ErrorBitfield ERROR_DIMENSION_MISMATCH = 0x04; |
| 65 | const static ErrorBitfield ERROR_READING_REFERENCE_IMAGE = 0x08; |
| 66 | const static ErrorBitfield ERROR_WRITING_REFERENCE_IMAGE = 0x10; |
| 67 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 68 | using namespace skiagm; |
| 69 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 70 | class Iter { |
| 71 | public: |
| 72 | Iter() { |
bsalomon@google.com | 3914958 | 2011-06-13 21:55:32 +0000 | [diff] [blame] | 73 | this->reset(); |
| 74 | } |
| 75 | |
| 76 | void reset() { |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 77 | fReg = GMRegistry::Head(); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 78 | } |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 79 | |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 80 | GM* next() { |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 81 | if (fReg) { |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 82 | GMRegistry::Factory fact = fReg->factory(); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 83 | fReg = fReg->next(); |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 84 | return fact(0); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 85 | } |
| 86 | return NULL; |
| 87 | } |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 88 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 89 | static int Count() { |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 90 | const GMRegistry* reg = GMRegistry::Head(); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 91 | int count = 0; |
| 92 | while (reg) { |
| 93 | count += 1; |
| 94 | reg = reg->next(); |
| 95 | } |
| 96 | return count; |
| 97 | } |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 98 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 99 | private: |
| 100 | const GMRegistry* fReg; |
| 101 | }; |
| 102 | |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 103 | enum Backend { |
| 104 | kRaster_Backend, |
| 105 | kGPU_Backend, |
| 106 | kPDF_Backend, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 107 | kXPS_Backend, |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 108 | }; |
| 109 | |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 110 | enum ConfigFlags { |
| 111 | kNone_ConfigFlag = 0x0, |
| 112 | /* Write GM images if a write path is provided. */ |
| 113 | kWrite_ConfigFlag = 0x1, |
epoger@google.com | f28dd8a | 2012-10-25 16:27:34 +0000 | [diff] [blame] | 114 | /* Read reference GM images if a read path is provided. */ |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 115 | kRead_ConfigFlag = 0x2, |
| 116 | kRW_ConfigFlag = (kWrite_ConfigFlag | kRead_ConfigFlag), |
| 117 | }; |
| 118 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 119 | struct ConfigData { |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 120 | SkBitmap::Config fConfig; |
| 121 | Backend fBackend; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 122 | GLContextType fGLContextType; // GPU backend only |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 123 | int fSampleCnt; // GPU backend only |
| 124 | ConfigFlags fFlags; |
| 125 | const char* fName; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 126 | }; |
| 127 | |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 128 | class BWTextDrawFilter : public SkDrawFilter { |
| 129 | public: |
| 130 | virtual void filter(SkPaint*, Type) SK_OVERRIDE; |
| 131 | }; |
| 132 | void BWTextDrawFilter::filter(SkPaint* p, Type t) { |
| 133 | if (kText_Type == t) { |
| 134 | p->setAntiAlias(false); |
| 135 | } |
| 136 | } |
| 137 | |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 138 | struct PipeFlagComboData { |
| 139 | const char* name; |
| 140 | uint32_t flags; |
| 141 | }; |
| 142 | |
| 143 | static PipeFlagComboData gPipeWritingFlagCombos[] = { |
| 144 | { "", 0 }, |
| 145 | { " cross-process", SkGPipeWriter::kCrossProcess_Flag }, |
scroggo | b3c0f48 | 2012-07-02 19:07:57 +0000 | [diff] [blame] | 146 | { " cross-process, shared address", SkGPipeWriter::kCrossProcess_Flag |
scroggo@google.com | 15011ee | 2012-07-26 20:03:32 +0000 | [diff] [blame] | 147 | | SkGPipeWriter::kSharedAddressSpace_Flag } |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 148 | }; |
| 149 | |
scroggo@google.com | 5af9b20 | 2012-06-04 17:17:36 +0000 | [diff] [blame] | 150 | |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 151 | class GMMain { |
| 152 | public: |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 153 | GMMain() { |
| 154 | // Set default values of member variables, which tool_main() |
| 155 | // may override. |
| 156 | fNotifyMissingReadReference = true; |
| 157 | fUseFileHierarchy = false; |
| 158 | } |
| 159 | |
| 160 | SkString make_name(const char shortName[], const char configName[]) { |
| 161 | SkString name; |
| 162 | if (fUseFileHierarchy) { |
| 163 | name.appendf("%s%c%s", configName, SkPATH_SEPARATOR, shortName); |
| 164 | } else { |
| 165 | name.appendf("%s_%s", shortName, configName); |
| 166 | } |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 167 | return name; |
| 168 | } |
| 169 | |
| 170 | static SkString make_filename(const char path[], |
| 171 | const char pathSuffix[], |
| 172 | const SkString& name, |
| 173 | const char suffix[]) { |
| 174 | SkString filename(path); |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 175 | if (filename.endsWith(SkPATH_SEPARATOR)) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 176 | filename.remove(filename.size() - 1, 1); |
| 177 | } |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 178 | filename.appendf("%s%c%s.%s", pathSuffix, SkPATH_SEPARATOR, |
| 179 | name.c_str(), suffix); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 180 | return filename; |
| 181 | } |
| 182 | |
| 183 | /* since PNG insists on unpremultiplying our alpha, we take no |
| 184 | precision chances and force all pixels to be 100% opaque, |
| 185 | otherwise on compare we may not get a perfect match. |
| 186 | */ |
| 187 | static void force_all_opaque(const SkBitmap& bitmap) { |
| 188 | SkAutoLockPixels lock(bitmap); |
| 189 | for (int y = 0; y < bitmap.height(); y++) { |
| 190 | for (int x = 0; x < bitmap.width(); x++) { |
| 191 | *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT); |
| 192 | } |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 193 | } |
| 194 | } |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 195 | |
| 196 | static bool write_bitmap(const SkString& path, const SkBitmap& bitmap) { |
| 197 | SkBitmap copy; |
| 198 | bitmap.copyTo(©, SkBitmap::kARGB_8888_Config); |
| 199 | force_all_opaque(copy); |
| 200 | return SkImageEncoder::EncodeFile(path.c_str(), copy, |
| 201 | SkImageEncoder::kPNG_Type, 100); |
| 202 | } |
| 203 | |
| 204 | static inline SkPMColor compute_diff_pmcolor(SkPMColor c0, SkPMColor c1) { |
| 205 | int dr = SkGetPackedR32(c0) - SkGetPackedR32(c1); |
| 206 | int dg = SkGetPackedG32(c0) - SkGetPackedG32(c1); |
| 207 | int db = SkGetPackedB32(c0) - SkGetPackedB32(c1); |
| 208 | return SkPackARGB32(0xFF, SkAbs32(dr), SkAbs32(dg), SkAbs32(db)); |
| 209 | } |
| 210 | |
| 211 | static void compute_diff(const SkBitmap& target, const SkBitmap& base, |
| 212 | SkBitmap* diff) { |
| 213 | SkAutoLockPixels alp(*diff); |
| 214 | |
| 215 | const int w = target.width(); |
| 216 | const int h = target.height(); |
| 217 | for (int y = 0; y < h; y++) { |
| 218 | for (int x = 0; x < w; x++) { |
| 219 | SkPMColor c0 = *base.getAddr32(x, y); |
| 220 | SkPMColor c1 = *target.getAddr32(x, y); |
| 221 | SkPMColor d = 0; |
| 222 | if (c0 != c1) { |
| 223 | d = compute_diff_pmcolor(c0, c1); |
| 224 | } |
| 225 | *diff->getAddr32(x, y) = d; |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | // Compares "target" and "base" bitmaps, returning the result |
| 231 | // (ERROR_NONE if the two bitmaps are identical). |
| 232 | // |
| 233 | // If a "diff" bitmap is passed in, pixel diffs (if any) will be written |
| 234 | // into it. |
| 235 | // |
| 236 | // The "name" and "renderModeDescriptor" arguments are only used |
| 237 | // in the debug output. |
| 238 | static ErrorBitfield compare(const SkBitmap& target, const SkBitmap& base, |
| 239 | const SkString& name, |
| 240 | const char* renderModeDescriptor, |
| 241 | SkBitmap* diff) { |
| 242 | SkBitmap copy; |
| 243 | const SkBitmap* bm = ⌖ |
| 244 | if (target.config() != SkBitmap::kARGB_8888_Config) { |
| 245 | target.copyTo(©, SkBitmap::kARGB_8888_Config); |
| 246 | bm = © |
| 247 | } |
| 248 | SkBitmap baseCopy; |
| 249 | const SkBitmap* bp = &base; |
| 250 | if (base.config() != SkBitmap::kARGB_8888_Config) { |
| 251 | base.copyTo(&baseCopy, SkBitmap::kARGB_8888_Config); |
| 252 | bp = &baseCopy; |
| 253 | } |
| 254 | |
| 255 | force_all_opaque(*bm); |
| 256 | force_all_opaque(*bp); |
| 257 | |
| 258 | const int w = bm->width(); |
| 259 | const int h = bm->height(); |
| 260 | if (w != bp->width() || h != bp->height()) { |
| 261 | SkDebugf( |
| 262 | "---- %s dimensions mismatch for %s base [%d %d] current [%d %d]\n", |
| 263 | renderModeDescriptor, name.c_str(), |
| 264 | bp->width(), bp->height(), w, h); |
| 265 | return ERROR_DIMENSION_MISMATCH; |
| 266 | } |
| 267 | |
| 268 | SkAutoLockPixels bmLock(*bm); |
| 269 | SkAutoLockPixels baseLock(*bp); |
| 270 | |
| 271 | for (int y = 0; y < h; y++) { |
| 272 | for (int x = 0; x < w; x++) { |
| 273 | SkPMColor c0 = *bp->getAddr32(x, y); |
| 274 | SkPMColor c1 = *bm->getAddr32(x, y); |
| 275 | if (c0 != c1) { |
| 276 | SkDebugf( |
| 277 | "----- %s pixel mismatch for %s at [%d %d] base 0x%08X current 0x%08X\n", |
| 278 | renderModeDescriptor, name.c_str(), x, y, c0, c1); |
| 279 | |
| 280 | if (diff) { |
| 281 | diff->setConfig(SkBitmap::kARGB_8888_Config, w, h); |
| 282 | diff->allocPixels(); |
| 283 | compute_diff(*bm, *bp, diff); |
| 284 | } |
| 285 | return ERROR_PIXEL_MISMATCH; |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | // they're equal |
| 291 | return ERROR_NONE; |
| 292 | } |
| 293 | |
| 294 | static bool write_document(const SkString& path, |
| 295 | const SkDynamicMemoryWStream& document) { |
| 296 | SkFILEWStream stream(path.c_str()); |
| 297 | SkAutoDataUnref data(document.copyToData()); |
| 298 | return stream.writeData(data.get()); |
| 299 | } |
| 300 | |
| 301 | /// Returns true if processing should continue, false to skip the |
| 302 | /// remainder of this config for this GM. |
| 303 | //@todo thudson 22 April 2011 - could refactor this to take in |
| 304 | // a factory to generate the context, always call readPixels() |
| 305 | // (logically a noop for rasters, if wasted time), and thus collapse the |
| 306 | // GPU special case and also let this be used for SkPicture testing. |
| 307 | static void setup_bitmap(const ConfigData& gRec, SkISize& size, |
| 308 | SkBitmap* bitmap) { |
| 309 | bitmap->setConfig(gRec.fConfig, size.width(), size.height()); |
| 310 | bitmap->allocPixels(); |
| 311 | bitmap->eraseColor(0); |
| 312 | } |
| 313 | |
| 314 | static void installFilter(SkCanvas* canvas) { |
| 315 | if (gForceBWtext) { |
| 316 | canvas->setDrawFilter(new BWTextDrawFilter)->unref(); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | static void invokeGM(GM* gm, SkCanvas* canvas, bool isPDF = false) { |
| 321 | SkAutoCanvasRestore acr(canvas, true); |
| 322 | |
| 323 | if (!isPDF) { |
| 324 | canvas->concat(gm->getInitialTransform()); |
| 325 | } |
| 326 | installFilter(canvas); |
| 327 | gm->draw(canvas); |
| 328 | canvas->setDrawFilter(NULL); |
| 329 | } |
| 330 | |
| 331 | static ErrorBitfield generate_image(GM* gm, const ConfigData& gRec, |
| 332 | GrContext* context, |
| 333 | GrRenderTarget* rt, |
| 334 | SkBitmap* bitmap, |
| 335 | bool deferred) { |
| 336 | SkISize size (gm->getISize()); |
| 337 | setup_bitmap(gRec, size, bitmap); |
| 338 | |
| 339 | SkAutoTUnref<SkCanvas> canvas; |
| 340 | |
| 341 | if (gRec.fBackend == kRaster_Backend) { |
| 342 | SkAutoTUnref<SkDevice> device(new SkDevice(*bitmap)); |
| 343 | if (deferred) { |
| 344 | canvas.reset(new SkDeferredCanvas(device)); |
| 345 | } else { |
| 346 | canvas.reset(new SkCanvas(device)); |
| 347 | } |
| 348 | invokeGM(gm, canvas); |
| 349 | canvas->flush(); |
| 350 | } |
| 351 | #if SK_SUPPORT_GPU |
| 352 | else { // GPU |
| 353 | if (NULL == context) { |
| 354 | return ERROR_NO_GPU_CONTEXT; |
| 355 | } |
| 356 | SkAutoTUnref<SkDevice> device(new SkGpuDevice(context, rt)); |
| 357 | if (deferred) { |
| 358 | canvas.reset(new SkDeferredCanvas(device)); |
| 359 | } else { |
| 360 | canvas.reset(new SkCanvas(device)); |
| 361 | } |
| 362 | invokeGM(gm, canvas); |
| 363 | // the device is as large as the current rendertarget, so |
| 364 | // we explicitly only readback the amount we expect (in |
| 365 | // size) overwrite our previous allocation |
| 366 | bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth, |
| 367 | size.fHeight); |
| 368 | canvas->readPixels(bitmap, 0, 0); |
| 369 | } |
| 370 | #endif |
| 371 | return ERROR_NONE; |
| 372 | } |
| 373 | |
| 374 | static void generate_image_from_picture(GM* gm, const ConfigData& gRec, |
| 375 | SkPicture* pict, SkBitmap* bitmap) { |
| 376 | SkISize size = gm->getISize(); |
| 377 | setup_bitmap(gRec, size, bitmap); |
| 378 | SkCanvas canvas(*bitmap); |
| 379 | installFilter(&canvas); |
| 380 | canvas.drawPicture(*pict); |
| 381 | } |
| 382 | |
| 383 | static void generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) { |
| 384 | #ifdef SK_SUPPORT_PDF |
| 385 | SkMatrix initialTransform = gm->getInitialTransform(); |
| 386 | SkISize pageSize = gm->getISize(); |
| 387 | SkPDFDevice* dev = NULL; |
| 388 | if (initialTransform.isIdentity()) { |
| 389 | dev = new SkPDFDevice(pageSize, pageSize, initialTransform); |
| 390 | } else { |
| 391 | SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()), |
| 392 | SkIntToScalar(pageSize.height())); |
| 393 | initialTransform.mapRect(&content); |
| 394 | content.intersect(0, 0, SkIntToScalar(pageSize.width()), |
| 395 | SkIntToScalar(pageSize.height())); |
| 396 | SkISize contentSize = |
| 397 | SkISize::Make(SkScalarRoundToInt(content.width()), |
| 398 | SkScalarRoundToInt(content.height())); |
| 399 | dev = new SkPDFDevice(pageSize, contentSize, initialTransform); |
| 400 | } |
| 401 | SkAutoUnref aur(dev); |
| 402 | |
| 403 | SkCanvas c(dev); |
| 404 | invokeGM(gm, &c, true); |
| 405 | |
| 406 | SkPDFDocument doc; |
| 407 | doc.appendPage(dev); |
| 408 | doc.emitPDF(&pdf); |
| 409 | #endif |
| 410 | } |
| 411 | |
| 412 | static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) { |
| 413 | #ifdef SK_SUPPORT_XPS |
| 414 | SkISize size = gm->getISize(); |
| 415 | |
| 416 | SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()), |
| 417 | SkIntToScalar(size.height())); |
| 418 | static const SkScalar inchesPerMeter = SkScalarDiv(10000, 254); |
| 419 | static const SkScalar upm = 72 * inchesPerMeter; |
| 420 | SkVector unitsPerMeter = SkPoint::Make(upm, upm); |
| 421 | static const SkScalar ppm = 200 * inchesPerMeter; |
| 422 | SkVector pixelsPerMeter = SkPoint::Make(ppm, ppm); |
| 423 | |
| 424 | SkXPSDevice* dev = new SkXPSDevice(); |
| 425 | SkAutoUnref aur(dev); |
| 426 | |
| 427 | SkCanvas c(dev); |
| 428 | dev->beginPortfolio(&xps); |
| 429 | dev->beginSheet(unitsPerMeter, pixelsPerMeter, trimSize); |
| 430 | invokeGM(gm, &c); |
| 431 | dev->endSheet(); |
| 432 | dev->endPortfolio(); |
| 433 | |
| 434 | #endif |
| 435 | } |
| 436 | |
| 437 | static ErrorBitfield write_reference_image( |
| 438 | const ConfigData& gRec, const char writePath [], |
| 439 | const char renderModeDescriptor [], const SkString& name, |
| 440 | SkBitmap& bitmap, SkDynamicMemoryWStream* document) { |
| 441 | SkString path; |
| 442 | bool success = false; |
| 443 | if (gRec.fBackend == kRaster_Backend || |
| 444 | gRec.fBackend == kGPU_Backend || |
| 445 | (gRec.fBackend == kPDF_Backend && CAN_IMAGE_PDF)) { |
| 446 | |
| 447 | path = make_filename(writePath, renderModeDescriptor, name, "png"); |
| 448 | success = write_bitmap(path, bitmap); |
| 449 | } |
| 450 | if (kPDF_Backend == gRec.fBackend) { |
| 451 | path = make_filename(writePath, renderModeDescriptor, name, "pdf"); |
| 452 | success = write_document(path, *document); |
| 453 | } |
| 454 | if (kXPS_Backend == gRec.fBackend) { |
| 455 | path = make_filename(writePath, renderModeDescriptor, name, "xps"); |
| 456 | success = write_document(path, *document); |
| 457 | } |
| 458 | if (success) { |
| 459 | return ERROR_NONE; |
| 460 | } else { |
| 461 | fprintf(stderr, "FAILED to write %s\n", path.c_str()); |
| 462 | return ERROR_WRITING_REFERENCE_IMAGE; |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | // Compares bitmap "bitmap" to "referenceBitmap"; if they are |
| 467 | // different, writes out "bitmap" (in PNG format) within the |
| 468 | // diffPath subdir. |
| 469 | // |
| 470 | // Returns the ErrorBitfield from compare(), describing any differences |
| 471 | // between "bitmap" and "referenceBitmap" (or ERROR_NONE if there are none). |
| 472 | static ErrorBitfield compare_to_reference_image_in_memory( |
| 473 | const SkString& name, SkBitmap &bitmap, const SkBitmap& referenceBitmap, |
| 474 | const char diffPath [], const char renderModeDescriptor []) { |
| 475 | ErrorBitfield errors; |
| 476 | SkBitmap diffBitmap; |
| 477 | errors = compare(bitmap, referenceBitmap, name, renderModeDescriptor, |
| 478 | diffPath ? &diffBitmap : NULL); |
| 479 | if ((ERROR_NONE != errors) && diffPath) { |
| 480 | // write out the generated image |
| 481 | SkString genName = make_filename(diffPath, "", name, "png"); |
| 482 | if (!write_bitmap(genName, bitmap)) { |
| 483 | errors |= ERROR_WRITING_REFERENCE_IMAGE; |
| 484 | } |
| 485 | } |
| 486 | return errors; |
| 487 | } |
| 488 | |
| 489 | // Compares bitmap "bitmap" to a reference bitmap read from disk; |
| 490 | // if they are different, writes out "bitmap" (in PNG format) |
| 491 | // within the diffPath subdir. |
| 492 | // |
| 493 | // Returns a description of the difference between "bitmap" and |
| 494 | // the reference bitmap, or ERROR_READING_REFERENCE_IMAGE if |
| 495 | // unable to read the reference bitmap from disk. |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 496 | ErrorBitfield compare_to_reference_image_on_disk( |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 497 | const char readPath [], const SkString& name, SkBitmap &bitmap, |
| 498 | const char diffPath [], const char renderModeDescriptor []) { |
| 499 | SkString path = make_filename(readPath, "", name, "png"); |
| 500 | SkBitmap referenceBitmap; |
| 501 | if (SkImageDecoder::DecodeFile(path.c_str(), &referenceBitmap, |
| 502 | SkBitmap::kARGB_8888_Config, |
| 503 | SkImageDecoder::kDecodePixels_Mode, |
| 504 | NULL)) { |
| 505 | return compare_to_reference_image_in_memory(name, bitmap, |
| 506 | referenceBitmap, |
| 507 | diffPath, |
| 508 | renderModeDescriptor); |
| 509 | } else { |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 510 | if (fNotifyMissingReadReference) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 511 | fprintf(stderr, "FAILED to read %s\n", path.c_str()); |
| 512 | } |
| 513 | return ERROR_READING_REFERENCE_IMAGE; |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | // NOTE: As far as I can tell, this function is NEVER called with a |
| 518 | // non-blank renderModeDescriptor, EXCEPT when readPath and writePath are |
| 519 | // both NULL (and thus no images are read from or written to disk). |
| 520 | // So I don't trust that the renderModeDescriptor is being used for |
| 521 | // anything other than debug output these days. |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 522 | ErrorBitfield handle_test_results(GM* gm, |
| 523 | const ConfigData& gRec, |
| 524 | const char writePath [], |
| 525 | const char readPath [], |
| 526 | const char diffPath [], |
| 527 | const char renderModeDescriptor [], |
| 528 | SkBitmap& bitmap, |
| 529 | SkDynamicMemoryWStream* pdf, |
| 530 | const SkBitmap* referenceBitmap) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 531 | SkString name = make_name(gm->shortName(), gRec.fName); |
| 532 | ErrorBitfield retval = ERROR_NONE; |
| 533 | |
| 534 | if (readPath && (gRec.fFlags & kRead_ConfigFlag)) { |
| 535 | retval |= compare_to_reference_image_on_disk(readPath, name, bitmap, |
| 536 | diffPath, |
| 537 | renderModeDescriptor); |
| 538 | } |
| 539 | if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) { |
| 540 | retval |= write_reference_image(gRec, writePath, |
| 541 | renderModeDescriptor, |
| 542 | name, bitmap, pdf); |
| 543 | } |
| 544 | if (referenceBitmap) { |
| 545 | retval |= compare_to_reference_image_in_memory( |
| 546 | name, bitmap, *referenceBitmap, diffPath, renderModeDescriptor); |
| 547 | } |
| 548 | return retval; |
| 549 | } |
| 550 | |
| 551 | static SkPicture* generate_new_picture(GM* gm) { |
| 552 | // Pictures are refcounted so must be on heap |
| 553 | SkPicture* pict = new SkPicture; |
| 554 | SkISize size = gm->getISize(); |
| 555 | SkCanvas* cv = pict->beginRecording(size.width(), size.height()); |
| 556 | invokeGM(gm, cv); |
| 557 | pict->endRecording(); |
| 558 | |
| 559 | return pict; |
| 560 | } |
| 561 | |
| 562 | static SkPicture* stream_to_new_picture(const SkPicture& src) { |
| 563 | |
| 564 | // To do in-memory commiunications with a stream, we need to: |
| 565 | // * create a dynamic memory stream |
| 566 | // * copy it into a buffer |
| 567 | // * create a read stream from it |
| 568 | // ?!?! |
| 569 | |
| 570 | SkDynamicMemoryWStream storage; |
| 571 | src.serialize(&storage); |
| 572 | |
| 573 | int streamSize = storage.getOffset(); |
| 574 | SkAutoMalloc dstStorage(streamSize); |
| 575 | void* dst = dstStorage.get(); |
| 576 | //char* dst = new char [streamSize]; |
| 577 | //@todo thudson 22 April 2011 when can we safely delete [] dst? |
| 578 | storage.copyTo(dst); |
| 579 | SkMemoryStream pictReadback(dst, streamSize); |
| 580 | SkPicture* retval = new SkPicture (&pictReadback); |
| 581 | return retval; |
| 582 | } |
| 583 | |
| 584 | // Test: draw into a bitmap or pdf. |
| 585 | // Depending on flags, possibly compare to an expected image |
| 586 | // and possibly output a diff image if it fails to match. |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 587 | ErrorBitfield test_drawing(GM* gm, |
| 588 | const ConfigData& gRec, |
| 589 | const char writePath [], |
| 590 | const char readPath [], |
| 591 | const char diffPath [], |
| 592 | GrContext* context, |
| 593 | GrRenderTarget* rt, |
| 594 | SkBitmap* bitmap) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 595 | SkDynamicMemoryWStream document; |
| 596 | |
| 597 | if (gRec.fBackend == kRaster_Backend || |
| 598 | gRec.fBackend == kGPU_Backend) { |
| 599 | // Early exit if we can't generate the image. |
| 600 | ErrorBitfield errors = generate_image(gm, gRec, context, rt, bitmap, |
| 601 | false); |
| 602 | if (ERROR_NONE != errors) { |
| 603 | return errors; |
| 604 | } |
| 605 | } else if (gRec.fBackend == kPDF_Backend) { |
| 606 | generate_pdf(gm, document); |
| 607 | #if CAN_IMAGE_PDF |
| 608 | SkAutoDataUnref data(document.copyToData()); |
| 609 | SkMemoryStream stream(data->data(), data->size()); |
| 610 | SkPDFDocumentToBitmap(&stream, bitmap); |
| 611 | #endif |
| 612 | } else if (gRec.fBackend == kXPS_Backend) { |
| 613 | generate_xps(gm, document); |
| 614 | } |
| 615 | return handle_test_results(gm, gRec, writePath, readPath, diffPath, |
| 616 | "", *bitmap, &document, NULL); |
| 617 | } |
| 618 | |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 619 | ErrorBitfield test_deferred_drawing(GM* gm, |
| 620 | const ConfigData& gRec, |
| 621 | const SkBitmap& referenceBitmap, |
| 622 | const char diffPath [], |
| 623 | GrContext* context, |
| 624 | GrRenderTarget* rt) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 625 | SkDynamicMemoryWStream document; |
| 626 | |
| 627 | if (gRec.fBackend == kRaster_Backend || |
| 628 | gRec.fBackend == kGPU_Backend) { |
| 629 | SkBitmap bitmap; |
| 630 | // Early exit if we can't generate the image, but this is |
| 631 | // expected in some cases, so don't report a test failure. |
| 632 | if (!generate_image(gm, gRec, context, rt, &bitmap, true)) { |
| 633 | return ERROR_NONE; |
| 634 | } |
| 635 | return handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 636 | "-deferred", bitmap, NULL, |
| 637 | &referenceBitmap); |
| 638 | } |
| 639 | return ERROR_NONE; |
| 640 | } |
| 641 | |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 642 | ErrorBitfield test_pipe_playback(GM* gm, |
| 643 | const ConfigData& gRec, |
| 644 | const SkBitmap& referenceBitmap, |
| 645 | const char readPath [], |
| 646 | const char diffPath []) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 647 | ErrorBitfield errors = ERROR_NONE; |
| 648 | for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) { |
| 649 | SkBitmap bitmap; |
| 650 | SkISize size = gm->getISize(); |
| 651 | setup_bitmap(gRec, size, &bitmap); |
| 652 | SkCanvas canvas(bitmap); |
| 653 | PipeController pipeController(&canvas); |
| 654 | SkGPipeWriter writer; |
| 655 | SkCanvas* pipeCanvas = writer.startRecording( |
| 656 | &pipeController, gPipeWritingFlagCombos[i].flags); |
| 657 | invokeGM(gm, pipeCanvas); |
| 658 | writer.endRecording(); |
| 659 | SkString string("-pipe"); |
| 660 | string.append(gPipeWritingFlagCombos[i].name); |
| 661 | errors |= handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 662 | string.c_str(), bitmap, NULL, |
| 663 | &referenceBitmap); |
| 664 | if (errors != ERROR_NONE) { |
| 665 | break; |
| 666 | } |
| 667 | } |
| 668 | return errors; |
| 669 | } |
| 670 | |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 671 | ErrorBitfield test_tiled_pipe_playback( |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 672 | GM* gm, const ConfigData& gRec, const SkBitmap& referenceBitmap, |
| 673 | const char readPath [], const char diffPath []) { |
| 674 | ErrorBitfield errors = ERROR_NONE; |
| 675 | for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) { |
| 676 | SkBitmap bitmap; |
| 677 | SkISize size = gm->getISize(); |
| 678 | setup_bitmap(gRec, size, &bitmap); |
| 679 | SkCanvas canvas(bitmap); |
| 680 | TiledPipeController pipeController(bitmap); |
| 681 | SkGPipeWriter writer; |
| 682 | SkCanvas* pipeCanvas = writer.startRecording( |
| 683 | &pipeController, gPipeWritingFlagCombos[i].flags); |
| 684 | invokeGM(gm, pipeCanvas); |
| 685 | writer.endRecording(); |
| 686 | SkString string("-tiled pipe"); |
| 687 | string.append(gPipeWritingFlagCombos[i].name); |
| 688 | errors |= handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 689 | string.c_str(), bitmap, NULL, |
| 690 | &referenceBitmap); |
| 691 | if (errors != ERROR_NONE) { |
| 692 | break; |
| 693 | } |
| 694 | } |
| 695 | return errors; |
| 696 | } |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 697 | |
| 698 | // |
| 699 | // member variables. |
| 700 | // They are public for now, to allow easier setting by tool_main(). |
| 701 | // |
| 702 | |
| 703 | // if true, emit a message when we can't find a reference image to compare |
| 704 | bool fNotifyMissingReadReference; |
| 705 | |
| 706 | bool fUseFileHierarchy; |
| 707 | |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 708 | }; // end of GMMain class definition |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 709 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 710 | #if SK_SUPPORT_GPU |
| 711 | static const GLContextType kDontCare_GLContextType = GrContextFactory::kNative_GLContextType; |
| 712 | #else |
| 713 | static const GLContextType kDontCare_GLContextType = 0; |
| 714 | #endif |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 715 | |
| 716 | // If the platform does not support writing PNGs of PDFs then there will be no |
epoger@google.com | f28dd8a | 2012-10-25 16:27:34 +0000 | [diff] [blame] | 717 | // reference images to read. However, we can always write the .pdf files |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 718 | static const ConfigFlags kPDFConfigFlags = CAN_IMAGE_PDF ? kRW_ConfigFlag : |
| 719 | kWrite_ConfigFlag; |
| 720 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 721 | static const ConfigData gRec[] = { |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 722 | { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "8888" }, |
| 723 | { SkBitmap::kARGB_4444_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "4444" }, |
| 724 | { SkBitmap::kRGB_565_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "565" }, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 725 | #if defined(SK_SCALAR_IS_FLOAT) && SK_SUPPORT_GPU |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 726 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 0, kRW_ConfigFlag, "gpu" }, |
robertphillips@google.com | a73e860 | 2012-08-02 17:56:02 +0000 | [diff] [blame] | 727 | #ifndef SK_BUILD_FOR_ANDROID |
| 728 | // currently we don't want to run MSAA tests on Android |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 729 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 16, kRW_ConfigFlag, "msaa16" }, |
robertphillips@google.com | a73e860 | 2012-08-02 17:56:02 +0000 | [diff] [blame] | 730 | #endif |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 731 | /* The debug context does not generate images */ |
| 732 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kDebug_GLContextType, 0, kNone_ConfigFlag, "debug" }, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 733 | #if SK_ANGLE |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 734 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 0, kRW_ConfigFlag, "angle" }, |
| 735 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 16, kRW_ConfigFlag, "anglemsaa16" }, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 736 | #endif // SK_ANGLE |
| 737 | #ifdef SK_MESA |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 738 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kMESA_GLContextType, 0, kRW_ConfigFlag, "mesa" }, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 739 | #endif // SK_MESA |
robertphillips@google.com | a73e860 | 2012-08-02 17:56:02 +0000 | [diff] [blame] | 740 | #endif // defined(SK_SCALAR_IS_FLOAT) && SK_SUPPORT_GPU |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 741 | #ifdef SK_SUPPORT_XPS |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 742 | /* At present we have no way of comparing XPS files (either natively or by converting to PNG). */ |
| 743 | { SkBitmap::kARGB_8888_Config, kXPS_Backend, kDontCare_GLContextType, 0, kWrite_ConfigFlag, "xps" }, |
robertphillips@google.com | a73e860 | 2012-08-02 17:56:02 +0000 | [diff] [blame] | 744 | #endif // SK_SUPPORT_XPS |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 745 | #ifdef SK_SUPPORT_PDF |
| 746 | { SkBitmap::kARGB_8888_Config, kPDF_Backend, kDontCare_GLContextType, 0, kPDFConfigFlags, "pdf" }, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 747 | #endif // SK_SUPPORT_PDF |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 748 | }; |
| 749 | |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 750 | static void usage(const char * argv0) { |
| 751 | SkDebugf("%s\n", argv0); |
reed@google.com | e5f48b9 | 2012-06-22 15:27:39 +0000 | [diff] [blame] | 752 | SkDebugf(" [--config "); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 753 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 754 | if (i > 0) { |
| 755 | SkDebugf("|"); |
| 756 | } |
| 757 | SkDebugf(gRec[i].fName); |
| 758 | } |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 759 | SkDebugf("]:\n run these configurations\n"); |
| 760 | SkDebugf( |
| 761 | // Alphabetized ignoring "no" prefix ("readPath", "noreplay", "resourcePath"). |
| 762 | // It would probably be better if we allowed both yes-and-no settings for each |
| 763 | // one, e.g.: |
| 764 | // [--replay|--noreplay]: whether to exercise SkPicture replay; default is yes |
| 765 | " [--nodeferred]: skip the deferred rendering test pass\n" |
| 766 | " [--diffPath|-d <path>]: write difference images into this directory\n" |
| 767 | " [--disable-missing-warning]: don't print a message to stderr if\n" |
| 768 | " unable to read a reference image for any tests (NOT default behavior)\n" |
| 769 | " [--enable-missing-warning]: print message to stderr (but don't fail) if\n" |
| 770 | " unable to read a reference image for any tests (default behavior)\n" |
| 771 | " [--forceBWtext]: disable text anti-aliasing\n" |
| 772 | " [--help|-h]: show this help message\n" |
| 773 | " [--hierarchy|--nohierarchy]: whether to use multilevel directory structure\n" |
| 774 | " when reading/writing files; default is no\n" |
| 775 | " [--match <substring>]: only run tests whose name includes this substring\n" |
| 776 | " [--modulo <remainder> <divisor>]: only run tests for which \n" |
| 777 | " testIndex %% divisor == remainder\n" |
| 778 | " [--nopdf]: skip the pdf rendering test pass\n" |
| 779 | " [--nopipe]: Skip SkGPipe replay\n" |
| 780 | " [--readPath|-r <path>]: read reference images from this dir, and report\n" |
| 781 | " any differences between those and the newly generated ones\n" |
| 782 | " [--noreplay]: do not exercise SkPicture replay\n" |
| 783 | " [--resourcePath|-i <path>]: directory that stores image resources\n" |
| 784 | " [--noserialize]: do not exercise SkPicture serialization & deserialization\n" |
| 785 | " [--notexturecache]: disable the gpu texture cache\n" |
| 786 | " [--tiledPipe]: Exercise tiled SkGPipe replay\n" |
| 787 | " [--writePath|-w <path>]: write rendered images into this directory\n" |
| 788 | " [--writePicturePath|-wp <path>]: write .skp files into this directory\n" |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 789 | ); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | static int findConfig(const char config[]) { |
| 793 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { |
| 794 | if (!strcmp(config, gRec[i].fName)) { |
| 795 | return i; |
| 796 | } |
| 797 | } |
| 798 | return -1; |
| 799 | } |
| 800 | |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 801 | static bool skip_name(const SkTDArray<const char*> array, const char name[]) { |
| 802 | if (0 == array.count()) { |
| 803 | // no names, so don't skip anything |
| 804 | return false; |
| 805 | } |
| 806 | for (int i = 0; i < array.count(); ++i) { |
| 807 | if (strstr(name, array[i])) { |
| 808 | // found the name, so don't skip |
| 809 | return false; |
| 810 | } |
| 811 | } |
| 812 | return true; |
| 813 | } |
| 814 | |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 815 | namespace skiagm { |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 816 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 817 | SkAutoTUnref<GrContext> gGrContext; |
| 818 | /** |
| 819 | * Sets the global GrContext, accessible by indivual GMs |
| 820 | */ |
caryclark@google.com | 1313086 | 2012-06-06 12:10:45 +0000 | [diff] [blame] | 821 | static void SetGr(GrContext* grContext) { |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 822 | SkSafeRef(grContext); |
| 823 | gGrContext.reset(grContext); |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 824 | } |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 825 | |
| 826 | /** |
| 827 | * Gets the global GrContext, can be called by GM tests. |
| 828 | */ |
caryclark@google.com | 1313086 | 2012-06-06 12:10:45 +0000 | [diff] [blame] | 829 | GrContext* GetGr(); |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 830 | GrContext* GetGr() { |
| 831 | return gGrContext.get(); |
| 832 | } |
| 833 | |
| 834 | /** |
| 835 | * Sets the global GrContext and then resets it to its previous value at |
| 836 | * destruction. |
| 837 | */ |
| 838 | class AutoResetGr : SkNoncopyable { |
| 839 | public: |
| 840 | AutoResetGr() : fOld(NULL) {} |
| 841 | void set(GrContext* context) { |
| 842 | SkASSERT(NULL == fOld); |
| 843 | fOld = GetGr(); |
| 844 | SkSafeRef(fOld); |
| 845 | SetGr(context); |
| 846 | } |
| 847 | ~AutoResetGr() { SetGr(fOld); SkSafeUnref(fOld); } |
| 848 | private: |
| 849 | GrContext* fOld; |
| 850 | }; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 851 | #else |
| 852 | GrContext* GetGr() { return NULL; } |
| 853 | #endif |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 854 | } |
| 855 | |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 856 | static bool is_recordable_failure(ErrorBitfield errorCode) { |
| 857 | return ERROR_NONE != errorCode && !(ERROR_READING_REFERENCE_IMAGE & errorCode); |
| 858 | } |
| 859 | |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 860 | int tool_main(int argc, char** argv); |
| 861 | int tool_main(int argc, char** argv) { |
robertphillips@google.com | b74af87 | 2012-06-27 19:41:42 +0000 | [diff] [blame] | 862 | |
| 863 | #ifdef SK_ENABLE_INST_COUNT |
| 864 | gPrintInstCount = true; |
| 865 | #endif |
| 866 | |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 867 | SkGraphics::Init(); |
reed@google.com | 8923c6c | 2011-11-08 14:59:38 +0000 | [diff] [blame] | 868 | // we don't need to see this during a run |
| 869 | gSkSuppressFontCachePurgeSpew = true; |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 870 | |
epoger@google.com | 7bc13a6 | 2012-02-14 14:53:59 +0000 | [diff] [blame] | 871 | setSystemPreferences(); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 872 | GMMain gmmain; |
epoger@google.com | 7bc13a6 | 2012-02-14 14:53:59 +0000 | [diff] [blame] | 873 | |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 874 | const char* writePath = NULL; // if non-null, where we write the originals |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 875 | const char* writePicturePath = NULL; // if non-null, where we write serialized pictures |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 876 | 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] | 877 | 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] | 878 | 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] | 879 | |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 880 | SkTDArray<const char*> fMatches; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 881 | |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 882 | bool doPDF = true; |
reed@google.com | b8b0983 | 2011-05-26 15:57:56 +0000 | [diff] [blame] | 883 | bool doReplay = true; |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 884 | bool doPipe = true; |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 885 | bool doTiledPipe = false; |
scroggo@google.com | 3936252 | 2012-09-14 17:37:46 +0000 | [diff] [blame] | 886 | bool doSerialize = true; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 887 | bool doDeferred = true; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 888 | bool disableTextureCache = false; |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 889 | SkTDArray<size_t> configs; |
| 890 | bool userConfig = false; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 891 | |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 892 | int moduloRemainder = -1; |
| 893 | int moduloDivisor = -1; |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 894 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 895 | const char* const commandName = argv[0]; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 896 | char* const* stop = argv + argc; |
| 897 | for (++argv; argv < stop; ++argv) { |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 898 | if (strcmp(*argv, "--config") == 0) { |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 899 | argv++; |
| 900 | if (argv < stop) { |
| 901 | int index = findConfig(*argv); |
| 902 | if (index >= 0) { |
| 903 | *configs.append() = index; |
| 904 | userConfig = true; |
| 905 | } else { |
| 906 | SkString str; |
| 907 | str.printf("unrecognized config %s\n", *argv); |
| 908 | SkDebugf(str.c_str()); |
| 909 | usage(commandName); |
| 910 | return -1; |
| 911 | } |
| 912 | } else { |
reed@google.com | e5f48b9 | 2012-06-22 15:27:39 +0000 | [diff] [blame] | 913 | SkDebugf("missing arg for --config\n"); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 914 | usage(commandName); |
| 915 | return -1; |
| 916 | } |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 917 | } else if (strcmp(*argv, "--nodeferred") == 0) { |
| 918 | doDeferred = false; |
| 919 | } else if ((0 == strcmp(*argv, "--diffPath")) || |
| 920 | (0 == strcmp(*argv, "-d"))) { |
| 921 | argv++; |
| 922 | if (argv < stop && **argv) { |
| 923 | diffPath = *argv; |
| 924 | } |
| 925 | } else if (strcmp(*argv, "--disable-missing-warning") == 0) { |
| 926 | gmmain.fNotifyMissingReadReference = false; |
| 927 | } else if (strcmp(*argv, "--enable-missing-warning") == 0) { |
| 928 | gmmain.fNotifyMissingReadReference = true; |
| 929 | } else if (strcmp(*argv, "--forceBWtext") == 0) { |
| 930 | gForceBWtext = true; |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 931 | } else if (strcmp(*argv, "--help") == 0 || strcmp(*argv, "-h") == 0) { |
| 932 | usage(commandName); |
| 933 | return -1; |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 934 | } else if (strcmp(*argv, "--hierarchy") == 0) { |
| 935 | gmmain.fUseFileHierarchy = true; |
| 936 | } else if (strcmp(*argv, "--nohierarchy") == 0) { |
| 937 | gmmain.fUseFileHierarchy = false; |
| 938 | } else if (strcmp(*argv, "--match") == 0) { |
| 939 | ++argv; |
| 940 | if (argv < stop && **argv) { |
| 941 | // just record the ptr, no need for a deep copy |
| 942 | *fMatches.append() = *argv; |
| 943 | } |
| 944 | } else if (strcmp(*argv, "--modulo") == 0) { |
| 945 | ++argv; |
| 946 | if (argv >= stop) { |
| 947 | continue; |
| 948 | } |
| 949 | moduloRemainder = atoi(*argv); |
| 950 | |
| 951 | ++argv; |
| 952 | if (argv >= stop) { |
| 953 | continue; |
| 954 | } |
| 955 | moduloDivisor = atoi(*argv); |
| 956 | } else if (strcmp(*argv, "--nopdf") == 0) { |
| 957 | doPDF = false; |
| 958 | } else if (strcmp(*argv, "--nopipe") == 0) { |
| 959 | doPipe = false; |
| 960 | } else if ((0 == strcmp(*argv, "--readPath")) || |
| 961 | (0 == strcmp(*argv, "-r"))) { |
| 962 | argv++; |
| 963 | if (argv < stop && **argv) { |
| 964 | readPath = *argv; |
| 965 | } |
| 966 | } else if (strcmp(*argv, "--noreplay") == 0) { |
| 967 | doReplay = false; |
| 968 | } else if ((0 == strcmp(*argv, "--resourcePath")) || |
| 969 | (0 == strcmp(*argv, "-i"))) { |
| 970 | argv++; |
| 971 | if (argv < stop && **argv) { |
| 972 | resourcePath = *argv; |
| 973 | } |
| 974 | } else if (strcmp(*argv, "--serialize") == 0) { |
| 975 | doSerialize = true; |
| 976 | } else if (strcmp(*argv, "--noserialize") == 0) { |
| 977 | doSerialize = false; |
| 978 | } else if (strcmp(*argv, "--notexturecache") == 0) { |
| 979 | disableTextureCache = true; |
| 980 | } else if (strcmp(*argv, "--tiledPipe") == 0) { |
| 981 | doTiledPipe = true; |
| 982 | } else if ((0 == strcmp(*argv, "--writePath")) || |
| 983 | (0 == strcmp(*argv, "-w"))) { |
| 984 | argv++; |
| 985 | if (argv < stop && **argv) { |
| 986 | writePath = *argv; |
| 987 | } |
| 988 | } else if ((0 == strcmp(*argv, "--writePicturePath")) || |
| 989 | (0 == strcmp(*argv, "-wp"))) { |
| 990 | argv++; |
| 991 | if (argv < stop && **argv) { |
| 992 | writePicturePath = *argv; |
| 993 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 994 | } else { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 995 | usage(commandName); |
| 996 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 997 | } |
| 998 | } |
| 999 | if (argv != stop) { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 1000 | usage(commandName); |
| 1001 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1002 | } |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 1003 | |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1004 | if (!userConfig) { |
| 1005 | // if no config is specified by user, we add them all. |
| 1006 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 1007 | *configs.append() = i; |
| 1008 | } |
| 1009 | } |
| 1010 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 1011 | GM::SetResourcePath(resourcePath); |
| 1012 | |
reed@android.com | 00f883e | 2010-12-14 17:46:14 +0000 | [diff] [blame] | 1013 | if (readPath) { |
| 1014 | fprintf(stderr, "reading from %s\n", readPath); |
chudy@google.com | f32f6e8 | 2012-07-12 15:42:37 +0000 | [diff] [blame] | 1015 | } |
epoger@google.com | 9284ccd | 2012-04-18 13:36:54 +0000 | [diff] [blame] | 1016 | if (writePath) { |
reed@android.com | 00f883e | 2010-12-14 17:46:14 +0000 | [diff] [blame] | 1017 | fprintf(stderr, "writing to %s\n", writePath); |
| 1018 | } |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 1019 | if (writePicturePath) { |
| 1020 | fprintf(stderr, "writing pictures to %s\n", writePicturePath); |
| 1021 | } |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 1022 | if (resourcePath) { |
| 1023 | fprintf(stderr, "reading resources from %s\n", resourcePath); |
| 1024 | } |
| 1025 | |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1026 | if (moduloDivisor <= 0) { |
| 1027 | moduloRemainder = -1; |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1028 | } |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1029 | if (moduloRemainder < 0 || moduloRemainder >= moduloDivisor) { |
| 1030 | moduloRemainder = -1; |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1033 | // Accumulate success of all tests. |
| 1034 | int testsRun = 0; |
| 1035 | int testsPassed = 0; |
| 1036 | int testsFailed = 0; |
| 1037 | int testsMissingReferenceImages = 0; |
| 1038 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1039 | #if SK_SUPPORT_GPU |
| 1040 | GrContextFactory* grFactory = new GrContextFactory; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 1041 | if (disableTextureCache) { |
| 1042 | skiagm::GetGr()->setTextureCacheLimits(0, 0); |
| 1043 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1044 | #endif |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 1045 | |
robertphillips@google.com | a2f8008 | 2012-08-02 16:22:47 +0000 | [diff] [blame] | 1046 | SkTArray<SkString> failedTests; |
| 1047 | |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1048 | int gmIndex = -1; |
| 1049 | SkString moduloStr; |
| 1050 | |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 1051 | // If we will be writing out files, prepare subdirectories. |
| 1052 | if (writePath) { |
| 1053 | if (!sk_mkdir(writePath)) { |
| 1054 | return -1; |
| 1055 | } |
| 1056 | if (gmmain.fUseFileHierarchy) { |
| 1057 | for (int i = 0; i < configs.count(); i++) { |
| 1058 | ConfigData config = gRec[configs[i]]; |
| 1059 | SkString subdir; |
| 1060 | subdir.appendf("%s%c%s", writePath, SkPATH_SEPARATOR, |
| 1061 | config.fName); |
| 1062 | if (!sk_mkdir(subdir.c_str())) { |
| 1063 | return -1; |
| 1064 | } |
| 1065 | } |
| 1066 | } |
| 1067 | } |
| 1068 | |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1069 | Iter iter; |
| 1070 | GM* gm; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1071 | while ((gm = iter.next()) != NULL) { |
skia.committer@gmail.com | 6a748ad | 2012-10-19 02:01:19 +0000 | [diff] [blame] | 1072 | |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1073 | ++gmIndex; |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1074 | if (moduloRemainder >= 0) { |
| 1075 | if ((gmIndex % moduloDivisor) != moduloRemainder) { |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1076 | continue; |
| 1077 | } |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1078 | moduloStr.printf("[%d.%d] ", gmIndex, moduloDivisor); |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1079 | } |
| 1080 | |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 1081 | const char* shortName = gm->shortName(); |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 1082 | if (skip_name(fMatches, shortName)) { |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 1083 | SkDELETE(gm); |
| 1084 | continue; |
| 1085 | } |
| 1086 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1087 | SkISize size = gm->getISize(); |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1088 | SkDebugf("%sdrawing... %s [%d %d]\n", moduloStr.c_str(), shortName, |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 1089 | size.width(), size.height()); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1090 | |
| 1091 | ErrorBitfield testErrors = ERROR_NONE; |
| 1092 | uint32_t gmFlags = gm->getFlags(); |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 1093 | |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1094 | for (int i = 0; i < configs.count(); i++) { |
| 1095 | ConfigData config = gRec[configs[i]]; |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 1096 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1097 | // Skip any tests that we don't even need to try. |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1098 | if ((kPDF_Backend == config.fBackend) && |
bungeman@google.com | 64e011a | 2011-09-19 19:31:04 +0000 | [diff] [blame] | 1099 | (!doPDF || (gmFlags & GM::kSkipPDF_Flag))) |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1100 | { |
| 1101 | continue; |
| 1102 | } |
reed@google.com | 1b6c73d | 2012-10-10 15:17:24 +0000 | [diff] [blame] | 1103 | if ((gmFlags & GM::kSkip565_Flag) && |
| 1104 | (kRaster_Backend == config.fBackend) && |
| 1105 | (SkBitmap::kRGB_565_Config == config.fConfig)) { |
| 1106 | continue; |
| 1107 | } |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 1108 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1109 | // Now we know that we want to run this test and record its |
| 1110 | // success or failure. |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1111 | ErrorBitfield renderErrors = ERROR_NONE; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1112 | GrRenderTarget* renderTarget = NULL; |
| 1113 | #if SK_SUPPORT_GPU |
| 1114 | SkAutoTUnref<GrRenderTarget> rt; |
| 1115 | AutoResetGr autogr; |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1116 | if ((ERROR_NONE == renderErrors) && |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1117 | kGPU_Backend == config.fBackend) { |
| 1118 | GrContext* gr = grFactory->get(config.fGLContextType); |
| 1119 | bool grSuccess = false; |
| 1120 | if (gr) { |
| 1121 | // create a render target to back the device |
| 1122 | GrTextureDesc desc; |
| 1123 | desc.fConfig = kSkia8888_PM_GrPixelConfig; |
| 1124 | desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 1125 | desc.fWidth = gm->getISize().width(); |
| 1126 | desc.fHeight = gm->getISize().height(); |
| 1127 | desc.fSampleCnt = config.fSampleCnt; |
| 1128 | GrTexture* tex = gr->createUncachedTexture(desc, NULL, 0); |
| 1129 | if (tex) { |
| 1130 | rt.reset(tex->asRenderTarget()); |
| 1131 | rt.get()->ref(); |
| 1132 | tex->unref(); |
| 1133 | autogr.set(gr); |
| 1134 | renderTarget = rt.get(); |
| 1135 | grSuccess = NULL != renderTarget; |
| 1136 | } |
| 1137 | } |
| 1138 | if (!grSuccess) { |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1139 | renderErrors |= ERROR_NO_GPU_CONTEXT; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1140 | } |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 1141 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1142 | #endif |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 1143 | |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1144 | SkBitmap comparisonBitmap; |
| 1145 | |
| 1146 | if (ERROR_NONE == renderErrors) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1147 | renderErrors |= gmmain.test_drawing(gm, config, writePath, |
| 1148 | readPath, diffPath, GetGr(), |
| 1149 | renderTarget, |
| 1150 | &comparisonBitmap); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1151 | } |
| 1152 | |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1153 | if (doDeferred && !renderErrors && |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1154 | (kGPU_Backend == config.fBackend || |
| 1155 | kRaster_Backend == config.fBackend)) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1156 | renderErrors |= gmmain.test_deferred_drawing(gm, config, |
| 1157 | comparisonBitmap, |
| 1158 | diffPath, GetGr(), |
| 1159 | renderTarget); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 1160 | } |
| 1161 | |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1162 | testErrors |= renderErrors; |
| 1163 | if (is_recordable_failure(renderErrors)) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1164 | failedTests.push_back(gmmain.make_name(shortName, |
| 1165 | config.fName)); |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 1166 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1167 | } |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1168 | |
| 1169 | SkBitmap comparisonBitmap; |
| 1170 | const ConfigData compareConfig = |
| 1171 | { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "comparison" }; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1172 | testErrors |= gmmain.generate_image(gm, compareConfig, NULL, NULL, &comparisonBitmap, false); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1173 | |
| 1174 | // run the picture centric GM steps |
| 1175 | if (!(gmFlags & GM::kSkipPicture_Flag)) { |
| 1176 | |
| 1177 | ErrorBitfield pictErrors = ERROR_NONE; |
| 1178 | |
| 1179 | //SkAutoTUnref<SkPicture> pict(generate_new_picture(gm)); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1180 | SkPicture* pict = gmmain.generate_new_picture(gm); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1181 | SkAutoUnref aur(pict); |
| 1182 | |
| 1183 | if ((ERROR_NONE == testErrors) && doReplay) { |
| 1184 | SkBitmap bitmap; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1185 | gmmain.generate_image_from_picture(gm, compareConfig, pict, |
| 1186 | &bitmap); |
| 1187 | pictErrors |= gmmain.handle_test_results(gm, compareConfig, |
| 1188 | NULL, NULL, diffPath, |
| 1189 | "-replay", bitmap, |
| 1190 | NULL, |
| 1191 | &comparisonBitmap); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1192 | if (is_recordable_failure(pictErrors)) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1193 | failedTests.push_back(gmmain.make_name(shortName, |
| 1194 | "pict-replay")); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1195 | } |
| 1196 | } |
| 1197 | |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1198 | if ((ERROR_NONE == testErrors) && |
| 1199 | (ERROR_NONE == pictErrors) && |
| 1200 | doSerialize) { |
| 1201 | SkPicture* repict = gmmain.stream_to_new_picture(*pict); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1202 | SkAutoUnref aurr(repict); |
| 1203 | |
| 1204 | SkBitmap bitmap; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1205 | gmmain.generate_image_from_picture(gm, compareConfig, repict, |
| 1206 | &bitmap); |
| 1207 | pictErrors |= gmmain.handle_test_results(gm, compareConfig, |
| 1208 | NULL, NULL, diffPath, |
| 1209 | "-serialize", bitmap, |
| 1210 | NULL, |
| 1211 | &comparisonBitmap); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1212 | if (is_recordable_failure(pictErrors)) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1213 | failedTests.push_back(gmmain.make_name(shortName, |
| 1214 | "pict-serialize")); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1215 | } |
| 1216 | } |
| 1217 | |
| 1218 | if (writePicturePath) { |
| 1219 | const char* pictureSuffix = "skp"; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1220 | SkString path = gmmain.make_filename(writePicturePath, "", |
| 1221 | SkString(gm->shortName()), |
| 1222 | pictureSuffix); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1223 | SkFILEWStream stream(path.c_str()); |
| 1224 | pict->serialize(&stream); |
| 1225 | } |
| 1226 | |
| 1227 | testErrors |= pictErrors; |
| 1228 | } |
| 1229 | |
| 1230 | // run the pipe centric GM steps |
| 1231 | if (!(gmFlags & GM::kSkipPipe_Flag)) { |
| 1232 | |
| 1233 | ErrorBitfield pipeErrors = ERROR_NONE; |
| 1234 | |
| 1235 | if ((ERROR_NONE == testErrors) && doPipe) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1236 | pipeErrors |= gmmain.test_pipe_playback(gm, compareConfig, |
| 1237 | comparisonBitmap, |
| 1238 | readPath, diffPath); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1239 | if (is_recordable_failure(pipeErrors)) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1240 | failedTests.push_back(gmmain.make_name(shortName, "pipe")); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | if ((ERROR_NONE == testErrors) && |
| 1245 | (ERROR_NONE == pipeErrors) && |
| 1246 | doTiledPipe && !(gmFlags & GM::kSkipTiled_Flag)) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1247 | pipeErrors |= gmmain.test_tiled_pipe_playback(gm, compareConfig, |
| 1248 | comparisonBitmap, |
| 1249 | readPath, |
| 1250 | diffPath); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1251 | if (is_recordable_failure(pipeErrors)) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1252 | failedTests.push_back(gmmain.make_name(shortName, |
| 1253 | "pipe-tiled")); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1254 | } |
| 1255 | } |
| 1256 | |
| 1257 | testErrors |= pipeErrors; |
| 1258 | } |
| 1259 | |
| 1260 | // Update overall results. |
| 1261 | // We only tabulate the particular error types that we currently |
| 1262 | // care about (e.g., missing reference images). Later on, if we |
| 1263 | // want to also tabulate pixel mismatches vs dimension mistmatches |
| 1264 | // (or whatever else), we can do so. |
| 1265 | testsRun++; |
| 1266 | if (ERROR_NONE == testErrors) { |
| 1267 | testsPassed++; |
| 1268 | } else if (ERROR_READING_REFERENCE_IMAGE & testErrors) { |
| 1269 | testsMissingReferenceImages++; |
| 1270 | } else { |
| 1271 | testsFailed++; |
| 1272 | } |
| 1273 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1274 | SkDELETE(gm); |
| 1275 | } |
robertphillips@google.com | a2f8008 | 2012-08-02 16:22:47 +0000 | [diff] [blame] | 1276 | SkDebugf("Ran %d tests: %d passed, %d failed, %d missing reference images\n", |
| 1277 | testsRun, testsPassed, testsFailed, testsMissingReferenceImages); |
| 1278 | for (int i = 0; i < failedTests.count(); ++i) { |
| 1279 | SkDebugf("\t\t%s\n", failedTests[i].c_str()); |
| 1280 | } |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 1281 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1282 | #if SK_SUPPORT_GPU |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 1283 | |
robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 1284 | #if GR_CACHE_STATS |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 1285 | for (int i = 0; i < configs.count(); i++) { |
| 1286 | ConfigData config = gRec[configs[i]]; |
| 1287 | |
| 1288 | if (kGPU_Backend == config.fBackend) { |
| 1289 | GrContext* gr = grFactory->get(config.fGLContextType); |
| 1290 | |
| 1291 | SkDebugf("config: %s %x\n", config.fName, gr); |
| 1292 | gr->printCacheStats(); |
| 1293 | } |
| 1294 | } |
| 1295 | #endif |
| 1296 | |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 1297 | delete grFactory; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1298 | #endif |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 1299 | SkGraphics::Term(); |
| 1300 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1301 | return (0 == testsFailed) ? 0 : -1; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1302 | } |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 1303 | |
borenet@google.com | 7158e6a | 2012-11-01 17:43:44 +0000 | [diff] [blame] | 1304 | #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 1305 | int main(int argc, char * const argv[]) { |
| 1306 | return tool_main(argc, (char**) argv); |
| 1307 | } |
| 1308 | #endif |