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