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) { |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame^] | 751 | // TODO: rearrange into alphabetical order |
| 752 | // TODO: add documentation for missing options |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 753 | SkDebugf("%s\n", argv0); |
| 754 | SkDebugf(" [-w writePath] [-r readPath] [-d diffPath] [-i resourcePath]\n"); |
chudy@google.com | f32f6e8 | 2012-07-12 15:42:37 +0000 | [diff] [blame] | 755 | SkDebugf(" [-wp writePicturePath]\n"); |
reed@google.com | e5f48b9 | 2012-06-22 15:27:39 +0000 | [diff] [blame] | 756 | SkDebugf(" [--config "); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 757 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 758 | if (i > 0) { |
| 759 | SkDebugf("|"); |
| 760 | } |
| 761 | SkDebugf(gRec[i].fName); |
| 762 | } |
| 763 | SkDebugf(" ]\n"); |
scroggo@google.com | 3936252 | 2012-09-14 17:37:46 +0000 | [diff] [blame] | 764 | SkDebugf(" [--noreplay] [--nopipe] [--noserialize] [--forceBWtext] [--nopdf] \n" |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame^] | 765 | " [--tiledPipe] [--hierarchy | --nohierarchy]\n" |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 766 | " [--nodeferred] [--match substring] [--notexturecache]\n" |
| 767 | " [-h|--help]\n" |
| 768 | ); |
| 769 | SkDebugf(" writePath: directory to write rendered images in.\n"); |
chudy@google.com | f32f6e8 | 2012-07-12 15:42:37 +0000 | [diff] [blame] | 770 | SkDebugf(" writePicturePath: directory to write images to in .skp format.\n"); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 771 | SkDebugf( |
| 772 | " readPath: directory to read reference images from;\n" |
| 773 | " reports if any pixels mismatch between reference and new images\n"); |
| 774 | SkDebugf(" diffPath: directory to write difference images in.\n"); |
| 775 | SkDebugf(" resourcePath: directory that stores image resources.\n"); |
| 776 | SkDebugf(" --noreplay: do not exercise SkPicture replay.\n"); |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 777 | SkDebugf(" --nopipe: Skip SkGPipe replay.\n"); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 778 | SkDebugf(" --tiledPipe: Exercise tiled SkGPipe replay.\n"); |
| 779 | SkDebugf( |
scroggo@google.com | 3936252 | 2012-09-14 17:37:46 +0000 | [diff] [blame] | 780 | " --noserialize: do not exercise SkPicture serialization & deserialization.\n"); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 781 | SkDebugf(" --forceBWtext: disable text anti-aliasing.\n"); |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame^] | 782 | SkDebugf(" --hierarchy: use multilevel directory structure when reading/writing files.\n"); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 783 | SkDebugf(" --nopdf: skip the pdf rendering test pass.\n"); |
| 784 | SkDebugf(" --nodeferred: skip the deferred rendering test pass.\n"); |
| 785 | SkDebugf(" --match foo: will only run tests that substring match foo.\n"); |
| 786 | SkDebugf(" --notexturecache: disable the gpu texture cache.\n"); |
| 787 | SkDebugf(" -h|--help : Show this help message. \n"); |
| 788 | } |
| 789 | |
| 790 | static int findConfig(const char config[]) { |
| 791 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { |
| 792 | if (!strcmp(config, gRec[i].fName)) { |
| 793 | return i; |
| 794 | } |
| 795 | } |
| 796 | return -1; |
| 797 | } |
| 798 | |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 799 | static bool skip_name(const SkTDArray<const char*> array, const char name[]) { |
| 800 | if (0 == array.count()) { |
| 801 | // no names, so don't skip anything |
| 802 | return false; |
| 803 | } |
| 804 | for (int i = 0; i < array.count(); ++i) { |
| 805 | if (strstr(name, array[i])) { |
| 806 | // found the name, so don't skip |
| 807 | return false; |
| 808 | } |
| 809 | } |
| 810 | return true; |
| 811 | } |
| 812 | |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 813 | namespace skiagm { |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 814 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 815 | SkAutoTUnref<GrContext> gGrContext; |
| 816 | /** |
| 817 | * Sets the global GrContext, accessible by indivual GMs |
| 818 | */ |
caryclark@google.com | 1313086 | 2012-06-06 12:10:45 +0000 | [diff] [blame] | 819 | static void SetGr(GrContext* grContext) { |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 820 | SkSafeRef(grContext); |
| 821 | gGrContext.reset(grContext); |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 822 | } |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 823 | |
| 824 | /** |
| 825 | * Gets the global GrContext, can be called by GM tests. |
| 826 | */ |
caryclark@google.com | 1313086 | 2012-06-06 12:10:45 +0000 | [diff] [blame] | 827 | GrContext* GetGr(); |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 828 | GrContext* GetGr() { |
| 829 | return gGrContext.get(); |
| 830 | } |
| 831 | |
| 832 | /** |
| 833 | * Sets the global GrContext and then resets it to its previous value at |
| 834 | * destruction. |
| 835 | */ |
| 836 | class AutoResetGr : SkNoncopyable { |
| 837 | public: |
| 838 | AutoResetGr() : fOld(NULL) {} |
| 839 | void set(GrContext* context) { |
| 840 | SkASSERT(NULL == fOld); |
| 841 | fOld = GetGr(); |
| 842 | SkSafeRef(fOld); |
| 843 | SetGr(context); |
| 844 | } |
| 845 | ~AutoResetGr() { SetGr(fOld); SkSafeUnref(fOld); } |
| 846 | private: |
| 847 | GrContext* fOld; |
| 848 | }; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 849 | #else |
| 850 | GrContext* GetGr() { return NULL; } |
| 851 | #endif |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 852 | } |
| 853 | |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 854 | static bool is_recordable_failure(ErrorBitfield errorCode) { |
| 855 | return ERROR_NONE != errorCode && !(ERROR_READING_REFERENCE_IMAGE & errorCode); |
| 856 | } |
| 857 | |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 858 | int tool_main(int argc, char** argv); |
| 859 | int tool_main(int argc, char** argv) { |
robertphillips@google.com | b74af87 | 2012-06-27 19:41:42 +0000 | [diff] [blame] | 860 | |
| 861 | #ifdef SK_ENABLE_INST_COUNT |
| 862 | gPrintInstCount = true; |
| 863 | #endif |
| 864 | |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 865 | SkGraphics::Init(); |
reed@google.com | 8923c6c | 2011-11-08 14:59:38 +0000 | [diff] [blame] | 866 | // we don't need to see this during a run |
| 867 | gSkSuppressFontCachePurgeSpew = true; |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 868 | |
epoger@google.com | 7bc13a6 | 2012-02-14 14:53:59 +0000 | [diff] [blame] | 869 | setSystemPreferences(); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 870 | GMMain gmmain; |
epoger@google.com | 7bc13a6 | 2012-02-14 14:53:59 +0000 | [diff] [blame] | 871 | |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 872 | 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] | 873 | 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] | 874 | 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] | 875 | 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] | 876 | 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] | 877 | |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 878 | SkTDArray<const char*> fMatches; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 879 | |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 880 | bool doPDF = true; |
reed@google.com | b8b0983 | 2011-05-26 15:57:56 +0000 | [diff] [blame] | 881 | bool doReplay = true; |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 882 | bool doPipe = true; |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 883 | bool doTiledPipe = false; |
scroggo@google.com | 3936252 | 2012-09-14 17:37:46 +0000 | [diff] [blame] | 884 | bool doSerialize = true; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 885 | bool doDeferred = true; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 886 | bool disableTextureCache = false; |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 887 | SkTDArray<size_t> configs; |
| 888 | bool userConfig = false; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 889 | |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 890 | int moduloIndex = -1; |
| 891 | int moduloCount = -1; |
| 892 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 893 | const char* const commandName = argv[0]; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 894 | char* const* stop = argv + argc; |
| 895 | for (++argv; argv < stop; ++argv) { |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame^] | 896 | // TODO: rearrange options into alphabetical order |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 897 | if (strcmp(*argv, "-w") == 0) { |
| 898 | argv++; |
| 899 | if (argv < stop && **argv) { |
| 900 | writePath = *argv; |
| 901 | } |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 902 | } else if (strcmp(*argv, "-wp") == 0) { |
| 903 | argv++; |
| 904 | if (argv < stop && **argv) { |
| 905 | writePicturePath = *argv; |
| 906 | } |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 907 | } else if (strcmp(*argv, "-r") == 0) { |
| 908 | argv++; |
| 909 | if (argv < stop && **argv) { |
| 910 | readPath = *argv; |
| 911 | } |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 912 | } else if (strcmp(*argv, "-d") == 0) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 913 | argv++; |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 914 | if (argv < stop && **argv) { |
| 915 | diffPath = *argv; |
| 916 | } |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 917 | } else if (strcmp(*argv, "-i") == 0) { |
| 918 | argv++; |
| 919 | if (argv < stop && **argv) { |
| 920 | resourcePath = *argv; |
| 921 | } |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 922 | } else if (strcmp(*argv, "--forceBWtext") == 0) { |
| 923 | gForceBWtext = true; |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 924 | } else if (strcmp(*argv, "--nopipe") == 0) { |
| 925 | doPipe = false; |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 926 | } else if (strcmp(*argv, "--tiledPipe") == 0) { |
| 927 | doTiledPipe = true; |
reed@google.com | b8b0983 | 2011-05-26 15:57:56 +0000 | [diff] [blame] | 928 | } else if (strcmp(*argv, "--noreplay") == 0) { |
| 929 | doReplay = false; |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 930 | } else if (strcmp(*argv, "--nopdf") == 0) { |
| 931 | doPDF = false; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 932 | } else if (strcmp(*argv, "--nodeferred") == 0) { |
| 933 | doDeferred = false; |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 934 | } else if (strcmp(*argv, "--modulo") == 0) { |
| 935 | ++argv; |
| 936 | if (argv >= stop) { |
| 937 | continue; |
| 938 | } |
| 939 | moduloIndex = atoi(*argv); |
skia.committer@gmail.com | 6a748ad | 2012-10-19 02:01:19 +0000 | [diff] [blame] | 940 | |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 941 | ++argv; |
| 942 | if (argv >= stop) { |
| 943 | continue; |
| 944 | } |
| 945 | moduloCount = atoi(*argv); |
reed@google.com | e8fcb50 | 2012-05-17 15:28:20 +0000 | [diff] [blame] | 946 | } else if (strcmp(*argv, "--disable-missing-warning") == 0) { |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame^] | 947 | gmmain.fNotifyMissingReadReference = false; |
reed@google.com | e8fcb50 | 2012-05-17 15:28:20 +0000 | [diff] [blame] | 948 | } else if (strcmp(*argv, "--enable-missing-warning") == 0) { |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame^] | 949 | gmmain.fNotifyMissingReadReference = true; |
| 950 | } else if (strcmp(*argv, "--hierarchy") == 0) { |
| 951 | gmmain.fUseFileHierarchy = true; |
| 952 | } else if (strcmp(*argv, "--nohierarchy") == 0) { |
| 953 | gmmain.fUseFileHierarchy = false; |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 954 | } else if (strcmp(*argv, "--serialize") == 0) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 955 | // Leaving in this option so that a user need not modify |
| 956 | // their command line arguments to still run. |
borenet@google.com | 14ca1d3 | 2012-06-15 13:46:44 +0000 | [diff] [blame] | 957 | doSerialize = true; |
scroggo@google.com | 3936252 | 2012-09-14 17:37:46 +0000 | [diff] [blame] | 958 | } else if (strcmp(*argv, "--noserialize") == 0) { |
| 959 | doSerialize = false; |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 960 | } else if (strcmp(*argv, "--match") == 0) { |
| 961 | ++argv; |
| 962 | if (argv < stop && **argv) { |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 963 | // just record the ptr, no need for a deep copy |
| 964 | *fMatches.append() = *argv; |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 965 | } |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 966 | } else if (strcmp(*argv, "--notexturecache") == 0) { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 967 | disableTextureCache = true; |
reed@google.com | e5f48b9 | 2012-06-22 15:27:39 +0000 | [diff] [blame] | 968 | } else if (strcmp(*argv, "--config") == 0) { |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 969 | argv++; |
| 970 | if (argv < stop) { |
| 971 | int index = findConfig(*argv); |
| 972 | if (index >= 0) { |
| 973 | *configs.append() = index; |
| 974 | userConfig = true; |
| 975 | } else { |
| 976 | SkString str; |
| 977 | str.printf("unrecognized config %s\n", *argv); |
| 978 | SkDebugf(str.c_str()); |
| 979 | usage(commandName); |
| 980 | return -1; |
| 981 | } |
| 982 | } else { |
reed@google.com | e5f48b9 | 2012-06-22 15:27:39 +0000 | [diff] [blame] | 983 | SkDebugf("missing arg for --config\n"); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 984 | usage(commandName); |
| 985 | return -1; |
| 986 | } |
| 987 | } else if (strcmp(*argv, "--help") == 0 || strcmp(*argv, "-h") == 0) { |
| 988 | usage(commandName); |
| 989 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 990 | } else { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 991 | usage(commandName); |
| 992 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 993 | } |
| 994 | } |
| 995 | if (argv != stop) { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 996 | usage(commandName); |
| 997 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 998 | } |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 999 | |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1000 | if (!userConfig) { |
| 1001 | // if no config is specified by user, we add them all. |
| 1002 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 1003 | *configs.append() = i; |
| 1004 | } |
| 1005 | } |
| 1006 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 1007 | GM::SetResourcePath(resourcePath); |
| 1008 | |
reed@android.com | 00f883e | 2010-12-14 17:46:14 +0000 | [diff] [blame] | 1009 | if (readPath) { |
| 1010 | fprintf(stderr, "reading from %s\n", readPath); |
chudy@google.com | f32f6e8 | 2012-07-12 15:42:37 +0000 | [diff] [blame] | 1011 | } |
epoger@google.com | 9284ccd | 2012-04-18 13:36:54 +0000 | [diff] [blame] | 1012 | if (writePath) { |
reed@android.com | 00f883e | 2010-12-14 17:46:14 +0000 | [diff] [blame] | 1013 | fprintf(stderr, "writing to %s\n", writePath); |
| 1014 | } |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 1015 | if (writePicturePath) { |
| 1016 | fprintf(stderr, "writing pictures to %s\n", writePicturePath); |
| 1017 | } |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 1018 | if (resourcePath) { |
| 1019 | fprintf(stderr, "reading resources from %s\n", resourcePath); |
| 1020 | } |
| 1021 | |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1022 | if (moduloCount <= 0) { |
| 1023 | moduloIndex = -1; |
| 1024 | } |
| 1025 | if (moduloIndex < 0 || moduloIndex >= moduloCount) { |
| 1026 | moduloIndex = -1; |
| 1027 | } |
| 1028 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1029 | // Accumulate success of all tests. |
| 1030 | int testsRun = 0; |
| 1031 | int testsPassed = 0; |
| 1032 | int testsFailed = 0; |
| 1033 | int testsMissingReferenceImages = 0; |
| 1034 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1035 | #if SK_SUPPORT_GPU |
| 1036 | GrContextFactory* grFactory = new GrContextFactory; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 1037 | if (disableTextureCache) { |
| 1038 | skiagm::GetGr()->setTextureCacheLimits(0, 0); |
| 1039 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1040 | #endif |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 1041 | |
robertphillips@google.com | a2f8008 | 2012-08-02 16:22:47 +0000 | [diff] [blame] | 1042 | SkTArray<SkString> failedTests; |
| 1043 | |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1044 | int gmIndex = -1; |
| 1045 | SkString moduloStr; |
| 1046 | |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame^] | 1047 | // If we will be writing out files, prepare subdirectories. |
| 1048 | if (writePath) { |
| 1049 | if (!sk_mkdir(writePath)) { |
| 1050 | return -1; |
| 1051 | } |
| 1052 | if (gmmain.fUseFileHierarchy) { |
| 1053 | for (int i = 0; i < configs.count(); i++) { |
| 1054 | ConfigData config = gRec[configs[i]]; |
| 1055 | SkString subdir; |
| 1056 | subdir.appendf("%s%c%s", writePath, SkPATH_SEPARATOR, |
| 1057 | config.fName); |
| 1058 | if (!sk_mkdir(subdir.c_str())) { |
| 1059 | return -1; |
| 1060 | } |
| 1061 | } |
| 1062 | } |
| 1063 | } |
| 1064 | |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1065 | Iter iter; |
| 1066 | GM* gm; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1067 | while ((gm = iter.next()) != NULL) { |
skia.committer@gmail.com | 6a748ad | 2012-10-19 02:01:19 +0000 | [diff] [blame] | 1068 | |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1069 | ++gmIndex; |
| 1070 | if (moduloIndex >= 0) { |
| 1071 | if ((gmIndex % moduloCount) != moduloIndex) { |
| 1072 | continue; |
| 1073 | } |
reed@google.com | b5a5a9d | 2012-10-25 17:58:23 +0000 | [diff] [blame] | 1074 | moduloStr.printf("[%d.%d] ", gmIndex, moduloCount); |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 1077 | const char* shortName = gm->shortName(); |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 1078 | if (skip_name(fMatches, shortName)) { |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 1079 | SkDELETE(gm); |
| 1080 | continue; |
| 1081 | } |
| 1082 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1083 | SkISize size = gm->getISize(); |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1084 | SkDebugf("%sdrawing... %s [%d %d]\n", moduloStr.c_str(), shortName, |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 1085 | size.width(), size.height()); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1086 | |
| 1087 | ErrorBitfield testErrors = ERROR_NONE; |
| 1088 | uint32_t gmFlags = gm->getFlags(); |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 1089 | |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1090 | for (int i = 0; i < configs.count(); i++) { |
| 1091 | ConfigData config = gRec[configs[i]]; |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame^] | 1092 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1093 | // Skip any tests that we don't even need to try. |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1094 | if ((kPDF_Backend == config.fBackend) && |
bungeman@google.com | 64e011a | 2011-09-19 19:31:04 +0000 | [diff] [blame] | 1095 | (!doPDF || (gmFlags & GM::kSkipPDF_Flag))) |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1096 | { |
| 1097 | continue; |
| 1098 | } |
reed@google.com | 1b6c73d | 2012-10-10 15:17:24 +0000 | [diff] [blame] | 1099 | if ((gmFlags & GM::kSkip565_Flag) && |
| 1100 | (kRaster_Backend == config.fBackend) && |
| 1101 | (SkBitmap::kRGB_565_Config == config.fConfig)) { |
| 1102 | continue; |
| 1103 | } |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 1104 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1105 | // Now we know that we want to run this test and record its |
| 1106 | // success or failure. |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1107 | ErrorBitfield renderErrors = ERROR_NONE; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1108 | GrRenderTarget* renderTarget = NULL; |
| 1109 | #if SK_SUPPORT_GPU |
| 1110 | SkAutoTUnref<GrRenderTarget> rt; |
| 1111 | AutoResetGr autogr; |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1112 | if ((ERROR_NONE == renderErrors) && |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1113 | kGPU_Backend == config.fBackend) { |
| 1114 | GrContext* gr = grFactory->get(config.fGLContextType); |
| 1115 | bool grSuccess = false; |
| 1116 | if (gr) { |
| 1117 | // create a render target to back the device |
| 1118 | GrTextureDesc desc; |
| 1119 | desc.fConfig = kSkia8888_PM_GrPixelConfig; |
| 1120 | desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 1121 | desc.fWidth = gm->getISize().width(); |
| 1122 | desc.fHeight = gm->getISize().height(); |
| 1123 | desc.fSampleCnt = config.fSampleCnt; |
| 1124 | GrTexture* tex = gr->createUncachedTexture(desc, NULL, 0); |
| 1125 | if (tex) { |
| 1126 | rt.reset(tex->asRenderTarget()); |
| 1127 | rt.get()->ref(); |
| 1128 | tex->unref(); |
| 1129 | autogr.set(gr); |
| 1130 | renderTarget = rt.get(); |
| 1131 | grSuccess = NULL != renderTarget; |
| 1132 | } |
| 1133 | } |
| 1134 | if (!grSuccess) { |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1135 | renderErrors |= ERROR_NO_GPU_CONTEXT; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1136 | } |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 1137 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1138 | #endif |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 1139 | |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1140 | SkBitmap comparisonBitmap; |
| 1141 | |
| 1142 | if (ERROR_NONE == renderErrors) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1143 | renderErrors |= gmmain.test_drawing(gm, config, writePath, |
| 1144 | readPath, diffPath, GetGr(), |
| 1145 | renderTarget, |
| 1146 | &comparisonBitmap); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1147 | } |
| 1148 | |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1149 | if (doDeferred && !renderErrors && |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1150 | (kGPU_Backend == config.fBackend || |
| 1151 | kRaster_Backend == config.fBackend)) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1152 | renderErrors |= gmmain.test_deferred_drawing(gm, config, |
| 1153 | comparisonBitmap, |
| 1154 | diffPath, GetGr(), |
| 1155 | renderTarget); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1158 | testErrors |= renderErrors; |
| 1159 | if (is_recordable_failure(renderErrors)) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1160 | failedTests.push_back(gmmain.make_name(shortName, |
| 1161 | config.fName)); |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 1162 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1163 | } |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1164 | |
| 1165 | SkBitmap comparisonBitmap; |
| 1166 | const ConfigData compareConfig = |
| 1167 | { 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] | 1168 | testErrors |= gmmain.generate_image(gm, compareConfig, NULL, NULL, &comparisonBitmap, false); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1169 | |
| 1170 | // run the picture centric GM steps |
| 1171 | if (!(gmFlags & GM::kSkipPicture_Flag)) { |
| 1172 | |
| 1173 | ErrorBitfield pictErrors = ERROR_NONE; |
| 1174 | |
| 1175 | //SkAutoTUnref<SkPicture> pict(generate_new_picture(gm)); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1176 | SkPicture* pict = gmmain.generate_new_picture(gm); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1177 | SkAutoUnref aur(pict); |
| 1178 | |
| 1179 | if ((ERROR_NONE == testErrors) && doReplay) { |
| 1180 | SkBitmap bitmap; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1181 | gmmain.generate_image_from_picture(gm, compareConfig, pict, |
| 1182 | &bitmap); |
| 1183 | pictErrors |= gmmain.handle_test_results(gm, compareConfig, |
| 1184 | NULL, NULL, diffPath, |
| 1185 | "-replay", bitmap, |
| 1186 | NULL, |
| 1187 | &comparisonBitmap); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1188 | if (is_recordable_failure(pictErrors)) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1189 | failedTests.push_back(gmmain.make_name(shortName, |
| 1190 | "pict-replay")); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1191 | } |
| 1192 | } |
| 1193 | |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1194 | if ((ERROR_NONE == testErrors) && |
| 1195 | (ERROR_NONE == pictErrors) && |
| 1196 | doSerialize) { |
| 1197 | SkPicture* repict = gmmain.stream_to_new_picture(*pict); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1198 | SkAutoUnref aurr(repict); |
| 1199 | |
| 1200 | SkBitmap bitmap; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1201 | gmmain.generate_image_from_picture(gm, compareConfig, repict, |
| 1202 | &bitmap); |
| 1203 | pictErrors |= gmmain.handle_test_results(gm, compareConfig, |
| 1204 | NULL, NULL, diffPath, |
| 1205 | "-serialize", bitmap, |
| 1206 | NULL, |
| 1207 | &comparisonBitmap); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1208 | if (is_recordable_failure(pictErrors)) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1209 | failedTests.push_back(gmmain.make_name(shortName, |
| 1210 | "pict-serialize")); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1211 | } |
| 1212 | } |
| 1213 | |
| 1214 | if (writePicturePath) { |
| 1215 | const char* pictureSuffix = "skp"; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1216 | SkString path = gmmain.make_filename(writePicturePath, "", |
| 1217 | SkString(gm->shortName()), |
| 1218 | pictureSuffix); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1219 | SkFILEWStream stream(path.c_str()); |
| 1220 | pict->serialize(&stream); |
| 1221 | } |
| 1222 | |
| 1223 | testErrors |= pictErrors; |
| 1224 | } |
| 1225 | |
| 1226 | // run the pipe centric GM steps |
| 1227 | if (!(gmFlags & GM::kSkipPipe_Flag)) { |
| 1228 | |
| 1229 | ErrorBitfield pipeErrors = ERROR_NONE; |
| 1230 | |
| 1231 | if ((ERROR_NONE == testErrors) && doPipe) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1232 | pipeErrors |= gmmain.test_pipe_playback(gm, compareConfig, |
| 1233 | comparisonBitmap, |
| 1234 | readPath, diffPath); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1235 | if (is_recordable_failure(pipeErrors)) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1236 | failedTests.push_back(gmmain.make_name(shortName, "pipe")); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1237 | } |
| 1238 | } |
| 1239 | |
| 1240 | if ((ERROR_NONE == testErrors) && |
| 1241 | (ERROR_NONE == pipeErrors) && |
| 1242 | doTiledPipe && !(gmFlags & GM::kSkipTiled_Flag)) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1243 | pipeErrors |= gmmain.test_tiled_pipe_playback(gm, compareConfig, |
| 1244 | comparisonBitmap, |
| 1245 | readPath, |
| 1246 | diffPath); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1247 | if (is_recordable_failure(pipeErrors)) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1248 | failedTests.push_back(gmmain.make_name(shortName, |
| 1249 | "pipe-tiled")); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | testErrors |= pipeErrors; |
| 1254 | } |
| 1255 | |
| 1256 | // Update overall results. |
| 1257 | // We only tabulate the particular error types that we currently |
| 1258 | // care about (e.g., missing reference images). Later on, if we |
| 1259 | // want to also tabulate pixel mismatches vs dimension mistmatches |
| 1260 | // (or whatever else), we can do so. |
| 1261 | testsRun++; |
| 1262 | if (ERROR_NONE == testErrors) { |
| 1263 | testsPassed++; |
| 1264 | } else if (ERROR_READING_REFERENCE_IMAGE & testErrors) { |
| 1265 | testsMissingReferenceImages++; |
| 1266 | } else { |
| 1267 | testsFailed++; |
| 1268 | } |
| 1269 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1270 | SkDELETE(gm); |
| 1271 | } |
robertphillips@google.com | a2f8008 | 2012-08-02 16:22:47 +0000 | [diff] [blame] | 1272 | SkDebugf("Ran %d tests: %d passed, %d failed, %d missing reference images\n", |
| 1273 | testsRun, testsPassed, testsFailed, testsMissingReferenceImages); |
| 1274 | for (int i = 0; i < failedTests.count(); ++i) { |
| 1275 | SkDebugf("\t\t%s\n", failedTests[i].c_str()); |
| 1276 | } |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 1277 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1278 | #if SK_SUPPORT_GPU |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 1279 | |
robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 1280 | #if GR_CACHE_STATS |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 1281 | for (int i = 0; i < configs.count(); i++) { |
| 1282 | ConfigData config = gRec[configs[i]]; |
| 1283 | |
| 1284 | if (kGPU_Backend == config.fBackend) { |
| 1285 | GrContext* gr = grFactory->get(config.fGLContextType); |
| 1286 | |
| 1287 | SkDebugf("config: %s %x\n", config.fName, gr); |
| 1288 | gr->printCacheStats(); |
| 1289 | } |
| 1290 | } |
| 1291 | #endif |
| 1292 | |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 1293 | delete grFactory; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1294 | #endif |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 1295 | SkGraphics::Term(); |
| 1296 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1297 | return (0 == testsFailed) ? 0 : -1; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1298 | } |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 1299 | |
| 1300 | #if !defined SK_BUILD_FOR_IOS |
| 1301 | int main(int argc, char * const argv[]) { |
| 1302 | return tool_main(argc, (char**) argv); |
| 1303 | } |
| 1304 | #endif |