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