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