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 | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 17 | #include "gm_error.h" |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 18 | #include "gm_expectations.h" |
epoger@google.com | 7bc13a6 | 2012-02-14 14:53:59 +0000 | [diff] [blame] | 19 | #include "system_preferences.h" |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 20 | #include "SkBitmap.h" |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 21 | #include "SkBitmapHasher.h" |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 22 | #include "SkColorPriv.h" |
scroggo@google.com | d9ba9a0 | 2013-03-21 19:43:15 +0000 | [diff] [blame] | 23 | #include "SkCommandLineFlags.h" |
reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 24 | #include "SkData.h" |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 25 | #include "SkDeferredCanvas.h" |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 26 | #include "SkDevice.h" |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 27 | #include "SkDrawFilter.h" |
scroggo@google.com | 5af9b20 | 2012-06-04 17:17:36 +0000 | [diff] [blame] | 28 | #include "SkGPipe.h" |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 29 | #include "SkGraphics.h" |
| 30 | #include "SkImageDecoder.h" |
| 31 | #include "SkImageEncoder.h" |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 32 | #include "SkOSFile.h" |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 33 | #include "SkPicture.h" |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 34 | #include "SkRefCnt.h" |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 35 | #include "SkStream.h" |
bsalomon@google.com | 2a48c3a | 2012-08-03 14:54:45 +0000 | [diff] [blame] | 36 | #include "SkTArray.h" |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 37 | #include "SkTDict.h" |
junov@chromium.org | 3cb834b | 2012-12-13 16:39:53 +0000 | [diff] [blame] | 38 | #include "SkTileGridPicture.h" |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 39 | #include "SamplePipeControllers.h" |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 40 | |
bsalomon@google.com | 50c79d8 | 2013-01-08 20:31:53 +0000 | [diff] [blame] | 41 | #ifdef SK_BUILD_FOR_WIN |
| 42 | // json includes xlocale which generates warning 4530 because we're compiling without |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 43 | // exceptions; see https://code.google.com/p/skia/issues/detail?id=1067 |
bsalomon@google.com | 50c79d8 | 2013-01-08 20:31:53 +0000 | [diff] [blame] | 44 | #pragma warning(push) |
| 45 | #pragma warning(disable : 4530) |
| 46 | #endif |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 47 | #include "json/value.h" |
bsalomon@google.com | 50c79d8 | 2013-01-08 20:31:53 +0000 | [diff] [blame] | 48 | #ifdef SK_BUILD_FOR_WIN |
| 49 | #pragma warning(pop) |
| 50 | #endif |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 51 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 52 | #if SK_SUPPORT_GPU |
| 53 | #include "GrContextFactory.h" |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 54 | #include "SkGpuDevice.h" |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 55 | typedef GrContextFactory::GLContextType GLContextType; |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 56 | #define DEFAULT_CACHE_VALUE -1 |
| 57 | static int gGpuCacheSizeBytes; |
| 58 | static int gGpuCacheSizeCount; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 59 | #else |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 60 | class GrContextFactory; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 61 | class GrContext; |
bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 62 | class GrSurface; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 63 | typedef int GLContextType; |
| 64 | #endif |
| 65 | |
reed@google.com | 8923c6c | 2011-11-08 14:59:38 +0000 | [diff] [blame] | 66 | extern bool gSkSuppressFontCachePurgeSpew; |
| 67 | |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 68 | #ifdef SK_SUPPORT_PDF |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 69 | #include "SkPDFDevice.h" |
| 70 | #include "SkPDFDocument.h" |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 71 | #endif |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 72 | |
epoger@google.com | e3cc2eb | 2012-01-18 20:11:13 +0000 | [diff] [blame] | 73 | // Until we resolve http://code.google.com/p/skia/issues/detail?id=455 , |
| 74 | // stop writing out XPS-format image baselines in gm. |
| 75 | #undef SK_SUPPORT_XPS |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 76 | #ifdef SK_SUPPORT_XPS |
| 77 | #include "SkXPSDevice.h" |
| 78 | #endif |
| 79 | |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 80 | #ifdef SK_BUILD_FOR_MAC |
| 81 | #include "SkCGUtils.h" |
bsalomon@google.com | 0a09eef | 2011-06-29 19:42:58 +0000 | [diff] [blame] | 82 | #define CAN_IMAGE_PDF 1 |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 83 | #else |
bsalomon@google.com | 0a09eef | 2011-06-29 19:42:58 +0000 | [diff] [blame] | 84 | #define CAN_IMAGE_PDF 0 |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 85 | #endif |
| 86 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 87 | using namespace skiagm; |
| 88 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 89 | class Iter { |
| 90 | public: |
| 91 | Iter() { |
bsalomon@google.com | 3914958 | 2011-06-13 21:55:32 +0000 | [diff] [blame] | 92 | this->reset(); |
| 93 | } |
| 94 | |
| 95 | void reset() { |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 96 | fReg = GMRegistry::Head(); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 97 | } |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 98 | |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 99 | GM* next() { |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 100 | if (fReg) { |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 101 | GMRegistry::Factory fact = fReg->factory(); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 102 | fReg = fReg->next(); |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 103 | return fact(0); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 104 | } |
| 105 | return NULL; |
| 106 | } |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 107 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 108 | static int Count() { |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 109 | const GMRegistry* reg = GMRegistry::Head(); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 110 | int count = 0; |
| 111 | while (reg) { |
| 112 | count += 1; |
| 113 | reg = reg->next(); |
| 114 | } |
| 115 | return count; |
| 116 | } |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 117 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 118 | private: |
| 119 | const GMRegistry* fReg; |
| 120 | }; |
| 121 | |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 122 | enum Backend { |
junov@chromium.org | 3cb834b | 2012-12-13 16:39:53 +0000 | [diff] [blame] | 123 | kRaster_Backend, |
| 124 | kGPU_Backend, |
| 125 | kPDF_Backend, |
| 126 | kXPS_Backend, |
| 127 | }; |
| 128 | |
| 129 | enum BbhType { |
| 130 | kNone_BbhType, |
| 131 | kRTree_BbhType, |
| 132 | kTileGrid_BbhType, |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 133 | }; |
| 134 | |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 135 | enum ConfigFlags { |
| 136 | kNone_ConfigFlag = 0x0, |
| 137 | /* Write GM images if a write path is provided. */ |
| 138 | kWrite_ConfigFlag = 0x1, |
epoger@google.com | f28dd8a | 2012-10-25 16:27:34 +0000 | [diff] [blame] | 139 | /* Read reference GM images if a read path is provided. */ |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 140 | kRead_ConfigFlag = 0x2, |
| 141 | kRW_ConfigFlag = (kWrite_ConfigFlag | kRead_ConfigFlag), |
| 142 | }; |
| 143 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 144 | struct ConfigData { |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 145 | SkBitmap::Config fConfig; |
| 146 | Backend fBackend; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 147 | GLContextType fGLContextType; // GPU backend only |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 148 | int fSampleCnt; // GPU backend only |
| 149 | ConfigFlags fFlags; |
| 150 | const char* fName; |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 151 | bool fRunByDefault; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 152 | }; |
| 153 | |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 154 | class BWTextDrawFilter : public SkDrawFilter { |
| 155 | public: |
reed@google.com | 971aca7 | 2012-11-26 20:26:54 +0000 | [diff] [blame] | 156 | virtual bool filter(SkPaint*, Type) SK_OVERRIDE; |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 157 | }; |
reed@google.com | 971aca7 | 2012-11-26 20:26:54 +0000 | [diff] [blame] | 158 | bool BWTextDrawFilter::filter(SkPaint* p, Type t) { |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 159 | if (kText_Type == t) { |
| 160 | p->setAntiAlias(false); |
| 161 | } |
reed@google.com | 971aca7 | 2012-11-26 20:26:54 +0000 | [diff] [blame] | 162 | return true; |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 163 | } |
| 164 | |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 165 | struct PipeFlagComboData { |
| 166 | const char* name; |
| 167 | uint32_t flags; |
| 168 | }; |
| 169 | |
| 170 | static PipeFlagComboData gPipeWritingFlagCombos[] = { |
| 171 | { "", 0 }, |
| 172 | { " cross-process", SkGPipeWriter::kCrossProcess_Flag }, |
scroggo | b3c0f48 | 2012-07-02 19:07:57 +0000 | [diff] [blame] | 173 | { " cross-process, shared address", SkGPipeWriter::kCrossProcess_Flag |
scroggo@google.com | 15011ee | 2012-07-26 20:03:32 +0000 | [diff] [blame] | 174 | | SkGPipeWriter::kSharedAddressSpace_Flag } |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 175 | }; |
| 176 | |
epoger@google.com | 5079d2c | 2013-04-12 14:11:21 +0000 | [diff] [blame] | 177 | const static ErrorCombination kDefaultIgnorableErrorTypes = ErrorCombination() |
| 178 | .plus(kMissingExpectations_ErrorType) |
| 179 | .plus(kIntentionallySkipped_ErrorType); |
| 180 | |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 181 | class GMMain { |
| 182 | public: |
epoger@google.com | 5079d2c | 2013-04-12 14:11:21 +0000 | [diff] [blame] | 183 | GMMain() : fUseFileHierarchy(false), fIgnorableErrorTypes(kDefaultIgnorableErrorTypes), |
| 184 | fMismatchPath(NULL), fTestsRun(0), fRenderModesEncountered(1) {} |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 185 | |
| 186 | SkString make_name(const char shortName[], const char configName[]) { |
| 187 | SkString name; |
epoger@google.com | 57f7abc | 2012-11-13 03:41:55 +0000 | [diff] [blame] | 188 | if (0 == strlen(configName)) { |
| 189 | name.append(shortName); |
| 190 | } else if (fUseFileHierarchy) { |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 191 | name.appendf("%s%c%s", configName, SkPATH_SEPARATOR, shortName); |
| 192 | } else { |
| 193 | name.appendf("%s_%s", shortName, configName); |
| 194 | } |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 195 | return name; |
| 196 | } |
| 197 | |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 198 | /* since PNG insists on unpremultiplying our alpha, we take no |
| 199 | precision chances and force all pixels to be 100% opaque, |
| 200 | otherwise on compare we may not get a perfect match. |
| 201 | */ |
| 202 | static void force_all_opaque(const SkBitmap& bitmap) { |
| 203 | SkBitmap::Config config = bitmap.config(); |
| 204 | switch (config) { |
| 205 | case SkBitmap::kARGB_8888_Config: |
| 206 | force_all_opaque_8888(bitmap); |
| 207 | break; |
| 208 | case SkBitmap::kRGB_565_Config: |
| 209 | // nothing to do here; 565 bitmaps are inherently opaque |
| 210 | break; |
| 211 | default: |
epoger@google.com | 5efdd0c | 2013-03-13 14:18:40 +0000 | [diff] [blame] | 212 | gm_fprintf(stderr, "unsupported bitmap config %d\n", config); |
| 213 | DEBUGFAIL_SEE_STDERR; |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | |
| 217 | static void force_all_opaque_8888(const SkBitmap& bitmap) { |
| 218 | SkAutoLockPixels lock(bitmap); |
| 219 | for (int y = 0; y < bitmap.height(); y++) { |
| 220 | for (int x = 0; x < bitmap.width(); x++) { |
| 221 | *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT); |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | static bool write_bitmap(const SkString& path, const SkBitmap& bitmap) { |
| 227 | // TODO(epoger): Now that we have removed force_all_opaque() |
| 228 | // from this method, we should be able to get rid of the |
| 229 | // transformation to 8888 format also. |
| 230 | SkBitmap copy; |
| 231 | bitmap.copyTo(©, SkBitmap::kARGB_8888_Config); |
| 232 | return SkImageEncoder::EncodeFile(path.c_str(), copy, |
| 233 | SkImageEncoder::kPNG_Type, 100); |
| 234 | } |
| 235 | |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 236 | /** |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 237 | * Add all render modes encountered thus far to the "modes" array. |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 238 | */ |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 239 | void GetRenderModesEncountered(SkTArray<SkString> &modes) { |
| 240 | SkTDict<int>::Iter iter(this->fRenderModesEncountered); |
| 241 | const char* mode; |
| 242 | while ((mode = iter.next(NULL)) != NULL) { |
| 243 | SkString modeAsString = SkString(mode); |
| 244 | // TODO(epoger): It seems a bit silly that all of these modes were |
| 245 | // recorded with a leading "-" which we have to remove here |
| 246 | // (except for mode "", which means plain old original mode). |
| 247 | // But that's how renderModeDescriptor has been passed into |
| 248 | // compare_test_results_to_reference_bitmap() historically, |
| 249 | // and changing that now may affect other parts of our code. |
| 250 | if (modeAsString.startsWith("-")) { |
| 251 | modeAsString.remove(0, 1); |
| 252 | modes.push_back(modeAsString); |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * Records the results of this test in fTestsRun and fFailedTests. |
| 259 | * |
| 260 | * We even record successes, and errors that we regard as |
| 261 | * "ignorable"; we can filter them out later. |
| 262 | */ |
| 263 | void RecordTestResults(const ErrorCombination& errorCombination, const SkString& name, |
| 264 | const char renderModeDescriptor []) { |
| 265 | // Things to do regardless of errorCombination. |
| 266 | fTestsRun++; |
| 267 | int renderModeCount = 0; |
| 268 | this->fRenderModesEncountered.find(renderModeDescriptor, &renderModeCount); |
| 269 | renderModeCount++; |
| 270 | this->fRenderModesEncountered.set(renderModeDescriptor, renderModeCount); |
| 271 | |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 272 | if (errorCombination.isEmpty()) { |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 273 | return; |
epoger@google.com | eb06636 | 2013-03-08 09:39:36 +0000 | [diff] [blame] | 274 | } |
| 275 | |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 276 | // Things to do only if there is some error condition. |
epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 277 | SkString fullName = name; |
| 278 | fullName.append(renderModeDescriptor); |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 279 | for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) { |
| 280 | ErrorType type = static_cast<ErrorType>(typeInt); |
| 281 | if (errorCombination.includes(type)) { |
| 282 | fFailedTests[type].push_back(fullName); |
epoger@google.com | f60494b | 2013-04-03 17:02:53 +0000 | [diff] [blame] | 283 | } |
epoger@google.com | f60494b | 2013-04-03 17:02:53 +0000 | [diff] [blame] | 284 | } |
epoger@google.com | f60494b | 2013-04-03 17:02:53 +0000 | [diff] [blame] | 285 | } |
| 286 | |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 287 | /** |
| 288 | * Return the number of significant (non-ignorable) errors we have |
| 289 | * encountered so far. |
| 290 | */ |
| 291 | int NumSignificantErrors() { |
| 292 | int significantErrors = 0; |
| 293 | for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) { |
| 294 | ErrorType type = static_cast<ErrorType>(typeInt); |
epoger@google.com | 5079d2c | 2013-04-12 14:11:21 +0000 | [diff] [blame] | 295 | if (!fIgnorableErrorTypes.includes(type)) { |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 296 | significantErrors += fFailedTests[type].count(); |
| 297 | } |
| 298 | } |
| 299 | return significantErrors; |
| 300 | } |
| 301 | |
| 302 | /** |
epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame] | 303 | * Display the summary of results with this ErrorType. |
| 304 | * |
| 305 | * @param type which ErrorType |
| 306 | * @param verbose whether to be all verbose about it |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 307 | */ |
epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame] | 308 | void DisplayResultTypeSummary(ErrorType type, bool verbose) { |
epoger@google.com | 5079d2c | 2013-04-12 14:11:21 +0000 | [diff] [blame] | 309 | bool isIgnorableType = fIgnorableErrorTypes.includes(type); |
epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame] | 310 | |
| 311 | SkString line; |
| 312 | if (isIgnorableType) { |
| 313 | line.append("[ ] "); |
| 314 | } else { |
| 315 | line.append("[*] "); |
| 316 | } |
| 317 | |
| 318 | SkTArray<SkString> *failedTestsOfThisType = &fFailedTests[type]; |
| 319 | int count = failedTestsOfThisType->count(); |
| 320 | line.appendf("%d %s", count, getErrorTypeName(type)); |
| 321 | if (!isIgnorableType || verbose) { |
| 322 | line.append(":"); |
| 323 | for (int i = 0; i < count; ++i) { |
| 324 | line.append(" "); |
| 325 | line.append((*failedTestsOfThisType)[i]); |
| 326 | } |
| 327 | } |
| 328 | gm_fprintf(stdout, "%s\n", line.c_str()); |
| 329 | } |
| 330 | |
| 331 | /** |
| 332 | * List contents of fFailedTests to stdout. |
| 333 | * |
| 334 | * @param verbose whether to be all verbose about it |
| 335 | */ |
| 336 | void ListErrors(bool verbose) { |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 337 | // First, print a single summary line. |
| 338 | SkString summary; |
| 339 | summary.appendf("Ran %d tests:", fTestsRun); |
| 340 | for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) { |
| 341 | ErrorType type = static_cast<ErrorType>(typeInt); |
| 342 | summary.appendf(" %s=%d", getErrorTypeName(type), fFailedTests[type].count()); |
| 343 | } |
| 344 | gm_fprintf(stdout, "%s\n", summary.c_str()); |
| 345 | |
| 346 | // Now, for each failure type, list the tests that failed that way. |
| 347 | for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) { |
epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame] | 348 | this->DisplayResultTypeSummary(static_cast<ErrorType>(typeInt), verbose); |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 349 | } |
| 350 | gm_fprintf(stdout, "(results marked with [*] will cause nonzero return value)\n"); |
| 351 | } |
| 352 | |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 353 | static bool write_document(const SkString& path, |
| 354 | const SkDynamicMemoryWStream& document) { |
| 355 | SkFILEWStream stream(path.c_str()); |
| 356 | SkAutoDataUnref data(document.copyToData()); |
| 357 | return stream.writeData(data.get()); |
| 358 | } |
| 359 | |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 360 | /** |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 361 | * Prepare an SkBitmap to render a GM into. |
| 362 | * |
| 363 | * After you've rendered the GM into the SkBitmap, you must call |
| 364 | * complete_bitmap()! |
| 365 | * |
| 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 | */ |
| 371 | static void setup_bitmap(const ConfigData& gRec, SkISize& size, |
| 372 | SkBitmap* bitmap) { |
| 373 | bitmap->setConfig(gRec.fConfig, size.width(), size.height()); |
| 374 | bitmap->allocPixels(); |
| 375 | bitmap->eraseColor(SK_ColorTRANSPARENT); |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * Any finalization steps we need to perform on the SkBitmap after |
| 380 | * we have rendered the GM into it. |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 381 | * |
| 382 | * It's too bad that we are throwing away alpha channel data |
| 383 | * we could otherwise be examining, but this had always been happening |
| 384 | * before... it was buried within the compare() method at |
| 385 | * https://code.google.com/p/skia/source/browse/trunk/gm/gmmain.cpp?r=7289#305 . |
| 386 | * |
| 387 | * Apparently we need this, at least for bitmaps that are either: |
| 388 | * (a) destined to be written out as PNG files, or |
| 389 | * (b) compared against bitmaps read in from PNG files |
| 390 | * for the reasons described just above the force_all_opaque() method. |
| 391 | * |
| 392 | * Neglecting to do this led to the difficult-to-diagnose |
| 393 | * http://code.google.com/p/skia/issues/detail?id=1079 ('gm generating |
| 394 | * spurious pixel_error messages as of r7258') |
| 395 | * |
| 396 | * TODO(epoger): Come up with a better solution that allows us to |
| 397 | * compare full pixel data, including alpha channel, while still being |
| 398 | * robust in the face of transformations to/from PNG files. |
| 399 | * Options include: |
| 400 | * |
| 401 | * 1. Continue to call force_all_opaque(), but ONLY for bitmaps that |
| 402 | * will be written to, or compared against, PNG files. |
| 403 | * PRO: Preserve/compare alpha channel info for the non-PNG cases |
| 404 | * (comparing different renderModes in-memory) |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 405 | * CON: The bitmaps (and hash digests) for these non-PNG cases would be |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 406 | * different than those for the PNG-compared cases, and in the |
| 407 | * case of a failed renderMode comparison, how would we write the |
| 408 | * image to disk for examination? |
| 409 | * |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 410 | * 2. Always compute image hash digests from PNG format (either |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 411 | * directly from the the bytes of a PNG file, or capturing the |
| 412 | * bytes we would have written to disk if we were writing the |
| 413 | * bitmap out as a PNG). |
| 414 | * PRO: I think this would allow us to never force opaque, and to |
| 415 | * the extent that alpha channel data can be preserved in a PNG |
| 416 | * file, we could observe it. |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 417 | * CON: If we read a bitmap from disk, we need to take its hash digest |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 418 | * from the source PNG (we can't compute it from the bitmap we |
| 419 | * read out of the PNG, because we will have already premultiplied |
| 420 | * the alpha). |
| 421 | * CON: Seems wasteful to convert a bitmap to PNG format just to take |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 422 | * its hash digest. (Although we're wasting lots of effort already |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 423 | * calling force_all_opaque().) |
| 424 | * |
| 425 | * 3. Make the alpha premultiply/unpremultiply routines 100% consistent, |
| 426 | * so we can transform images back and forth without fear of off-by-one |
| 427 | * errors. |
| 428 | * CON: Math is hard. |
| 429 | * |
| 430 | * 4. Perform a "close enough" comparison of bitmaps (+/- 1 bit in each |
| 431 | * channel), rather than demanding absolute equality. |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 432 | * CON: Can't do this with hash digests. |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 433 | */ |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 434 | static void complete_bitmap(SkBitmap* bitmap) { |
| 435 | force_all_opaque(*bitmap); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 436 | } |
| 437 | |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 438 | static void installFilter(SkCanvas* canvas); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 439 | |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 440 | static void invokeGM(GM* gm, SkCanvas* canvas, bool isPDF, bool isDeferred) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 441 | SkAutoCanvasRestore acr(canvas, true); |
| 442 | |
| 443 | if (!isPDF) { |
| 444 | canvas->concat(gm->getInitialTransform()); |
| 445 | } |
| 446 | installFilter(canvas); |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 447 | gm->setCanvasIsDeferred(isDeferred); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 448 | gm->draw(canvas); |
| 449 | canvas->setDrawFilter(NULL); |
| 450 | } |
| 451 | |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 452 | static ErrorCombination generate_image(GM* gm, const ConfigData& gRec, |
bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 453 | GrSurface* gpuTarget, |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 454 | SkBitmap* bitmap, |
| 455 | bool deferred) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 456 | SkISize size (gm->getISize()); |
| 457 | setup_bitmap(gRec, size, bitmap); |
| 458 | |
| 459 | SkAutoTUnref<SkCanvas> canvas; |
| 460 | |
| 461 | if (gRec.fBackend == kRaster_Backend) { |
| 462 | SkAutoTUnref<SkDevice> device(new SkDevice(*bitmap)); |
| 463 | if (deferred) { |
| 464 | canvas.reset(new SkDeferredCanvas(device)); |
| 465 | } else { |
| 466 | canvas.reset(new SkCanvas(device)); |
| 467 | } |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 468 | invokeGM(gm, canvas, false, deferred); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 469 | canvas->flush(); |
| 470 | } |
| 471 | #if SK_SUPPORT_GPU |
| 472 | else { // GPU |
bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 473 | SkAutoTUnref<SkDevice> device(SkGpuDevice::Create(gpuTarget)); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 474 | if (deferred) { |
| 475 | canvas.reset(new SkDeferredCanvas(device)); |
| 476 | } else { |
| 477 | canvas.reset(new SkCanvas(device)); |
| 478 | } |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 479 | invokeGM(gm, canvas, false, deferred); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 480 | // the device is as large as the current rendertarget, so |
| 481 | // we explicitly only readback the amount we expect (in |
| 482 | // size) overwrite our previous allocation |
| 483 | bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth, |
| 484 | size.fHeight); |
| 485 | canvas->readPixels(bitmap, 0, 0); |
| 486 | } |
| 487 | #endif |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 488 | complete_bitmap(bitmap); |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 489 | return kEmpty_ErrorCombination; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | static void generate_image_from_picture(GM* gm, const ConfigData& gRec, |
junov@chromium.org | c938c48 | 2012-12-19 15:24:38 +0000 | [diff] [blame] | 493 | SkPicture* pict, SkBitmap* bitmap, |
robertphillips@google.com | 5a7d029 | 2013-04-02 15:18:41 +0000 | [diff] [blame] | 494 | SkScalar scale = SK_Scalar1, |
| 495 | bool tile = false) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 496 | SkISize size = gm->getISize(); |
| 497 | setup_bitmap(gRec, size, bitmap); |
robertphillips@google.com | 5a7d029 | 2013-04-02 15:18:41 +0000 | [diff] [blame] | 498 | |
| 499 | if (tile) { |
| 500 | // Generate the result image by rendering to tiles and accumulating |
| 501 | // the results in 'bitmap' |
| 502 | |
skia.committer@gmail.com | 041e2db | 2013-04-03 07:01:14 +0000 | [diff] [blame] | 503 | // This 16x16 tiling matches the settings applied to 'pict' in |
robertphillips@google.com | 5a7d029 | 2013-04-02 15:18:41 +0000 | [diff] [blame] | 504 | // 'generate_new_picture' |
| 505 | SkISize tileSize = SkISize::Make(16, 16); |
| 506 | |
| 507 | SkBitmap tileBM; |
| 508 | setup_bitmap(gRec, tileSize, &tileBM); |
| 509 | SkCanvas tileCanvas(tileBM); |
| 510 | installFilter(&tileCanvas); |
| 511 | |
| 512 | SkCanvas bmpCanvas(*bitmap); |
| 513 | SkPaint bmpPaint; |
| 514 | bmpPaint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 515 | |
| 516 | for (int yTile = 0; yTile < (size.height()+15)/16; ++yTile) { |
| 517 | for (int xTile = 0; xTile < (size.width()+15)/16; ++xTile) { |
| 518 | int saveCount = tileCanvas.save(); |
| 519 | SkMatrix mat(tileCanvas.getTotalMatrix()); |
skia.committer@gmail.com | 041e2db | 2013-04-03 07:01:14 +0000 | [diff] [blame] | 520 | mat.postTranslate(SkIntToScalar(-xTile*tileSize.width()), |
robertphillips@google.com | 5a7d029 | 2013-04-02 15:18:41 +0000 | [diff] [blame] | 521 | SkIntToScalar(-yTile*tileSize.height())); |
| 522 | tileCanvas.setMatrix(mat); |
| 523 | pict->draw(&tileCanvas); |
| 524 | tileCanvas.flush(); |
| 525 | tileCanvas.restoreToCount(saveCount); |
skia.committer@gmail.com | 041e2db | 2013-04-03 07:01:14 +0000 | [diff] [blame] | 526 | bmpCanvas.drawBitmap(tileBM, |
| 527 | SkIntToScalar(xTile * tileSize.width()), |
robertphillips@google.com | 5a7d029 | 2013-04-02 15:18:41 +0000 | [diff] [blame] | 528 | SkIntToScalar(yTile * tileSize.height()), |
| 529 | &bmpPaint); |
| 530 | } |
| 531 | } |
| 532 | } else { |
| 533 | SkCanvas canvas(*bitmap); |
| 534 | installFilter(&canvas); |
| 535 | canvas.scale(scale, scale); |
| 536 | canvas.drawPicture(*pict); |
| 537 | complete_bitmap(bitmap); |
| 538 | } |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | static void generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) { |
| 542 | #ifdef SK_SUPPORT_PDF |
| 543 | SkMatrix initialTransform = gm->getInitialTransform(); |
| 544 | SkISize pageSize = gm->getISize(); |
| 545 | SkPDFDevice* dev = NULL; |
| 546 | if (initialTransform.isIdentity()) { |
| 547 | dev = new SkPDFDevice(pageSize, pageSize, initialTransform); |
| 548 | } else { |
| 549 | SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()), |
| 550 | SkIntToScalar(pageSize.height())); |
| 551 | initialTransform.mapRect(&content); |
| 552 | content.intersect(0, 0, SkIntToScalar(pageSize.width()), |
| 553 | SkIntToScalar(pageSize.height())); |
| 554 | SkISize contentSize = |
| 555 | SkISize::Make(SkScalarRoundToInt(content.width()), |
| 556 | SkScalarRoundToInt(content.height())); |
| 557 | dev = new SkPDFDevice(pageSize, contentSize, initialTransform); |
| 558 | } |
| 559 | SkAutoUnref aur(dev); |
| 560 | |
| 561 | SkCanvas c(dev); |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 562 | invokeGM(gm, &c, true, false); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 563 | |
| 564 | SkPDFDocument doc; |
| 565 | doc.appendPage(dev); |
| 566 | doc.emitPDF(&pdf); |
| 567 | #endif |
| 568 | } |
| 569 | |
| 570 | static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) { |
| 571 | #ifdef SK_SUPPORT_XPS |
| 572 | SkISize size = gm->getISize(); |
| 573 | |
| 574 | SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()), |
| 575 | SkIntToScalar(size.height())); |
| 576 | static const SkScalar inchesPerMeter = SkScalarDiv(10000, 254); |
| 577 | static const SkScalar upm = 72 * inchesPerMeter; |
| 578 | SkVector unitsPerMeter = SkPoint::Make(upm, upm); |
| 579 | static const SkScalar ppm = 200 * inchesPerMeter; |
| 580 | SkVector pixelsPerMeter = SkPoint::Make(ppm, ppm); |
| 581 | |
| 582 | SkXPSDevice* dev = new SkXPSDevice(); |
| 583 | SkAutoUnref aur(dev); |
| 584 | |
| 585 | SkCanvas c(dev); |
| 586 | dev->beginPortfolio(&xps); |
| 587 | dev->beginSheet(unitsPerMeter, pixelsPerMeter, trimSize); |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 588 | invokeGM(gm, &c, false, false); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 589 | dev->endSheet(); |
| 590 | dev->endPortfolio(); |
| 591 | |
| 592 | #endif |
| 593 | } |
| 594 | |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 595 | ErrorCombination write_reference_image(const ConfigData& gRec, const char writePath [], |
| 596 | const char renderModeDescriptor [], const SkString& name, |
| 597 | SkBitmap& bitmap, SkDynamicMemoryWStream* document) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 598 | SkString path; |
| 599 | bool success = false; |
| 600 | if (gRec.fBackend == kRaster_Backend || |
| 601 | gRec.fBackend == kGPU_Backend || |
| 602 | (gRec.fBackend == kPDF_Backend && CAN_IMAGE_PDF)) { |
| 603 | |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 604 | path = make_filename(writePath, renderModeDescriptor, name.c_str(), |
| 605 | "png"); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 606 | success = write_bitmap(path, bitmap); |
| 607 | } |
| 608 | if (kPDF_Backend == gRec.fBackend) { |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 609 | path = make_filename(writePath, renderModeDescriptor, name.c_str(), |
| 610 | "pdf"); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 611 | success = write_document(path, *document); |
| 612 | } |
| 613 | if (kXPS_Backend == gRec.fBackend) { |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 614 | path = make_filename(writePath, renderModeDescriptor, name.c_str(), |
| 615 | "xps"); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 616 | success = write_document(path, *document); |
| 617 | } |
| 618 | if (success) { |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 619 | return kEmpty_ErrorCombination; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 620 | } else { |
epoger@google.com | 5efdd0c | 2013-03-13 14:18:40 +0000 | [diff] [blame] | 621 | gm_fprintf(stderr, "FAILED to write %s\n", path.c_str()); |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 622 | ErrorCombination errors(kWritingReferenceImage_ErrorType); |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 623 | // TODO(epoger): Don't call RecordTestResults() here... |
| 624 | // Instead, we should make sure to call RecordTestResults |
| 625 | // exactly ONCE per test. (Otherwise, gmmain.fTestsRun |
| 626 | // will be incremented twice for this test: once in |
| 627 | // compare_test_results_to_stored_expectations() before |
| 628 | // that method calls this one, and again here.) |
| 629 | // |
| 630 | // When we make that change, we should probably add a |
| 631 | // WritingReferenceImage test to the gm self-tests.) |
| 632 | RecordTestResults(errors, name, renderModeDescriptor); |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 633 | return errors; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 634 | } |
| 635 | } |
| 636 | |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 637 | /** |
epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 638 | * Log more detail about the mistmatch between expectedBitmap and |
| 639 | * actualBitmap. |
| 640 | */ |
| 641 | void report_bitmap_diffs(const SkBitmap& expectedBitmap, const SkBitmap& actualBitmap, |
| 642 | const char *testName) { |
| 643 | const int expectedWidth = expectedBitmap.width(); |
| 644 | const int expectedHeight = expectedBitmap.height(); |
| 645 | const int width = actualBitmap.width(); |
| 646 | const int height = actualBitmap.height(); |
| 647 | if ((expectedWidth != width) || (expectedHeight != height)) { |
epoger@google.com | 5efdd0c | 2013-03-13 14:18:40 +0000 | [diff] [blame] | 648 | gm_fprintf(stderr, "---- %s: dimension mismatch --" |
| 649 | " expected [%d %d], actual [%d %d]\n", |
| 650 | testName, expectedWidth, expectedHeight, width, height); |
epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 651 | return; |
| 652 | } |
| 653 | |
| 654 | if ((SkBitmap::kARGB_8888_Config != expectedBitmap.config()) || |
| 655 | (SkBitmap::kARGB_8888_Config != actualBitmap.config())) { |
epoger@google.com | 5efdd0c | 2013-03-13 14:18:40 +0000 | [diff] [blame] | 656 | gm_fprintf(stderr, "---- %s: not computing max per-channel" |
| 657 | " pixel mismatch because non-8888\n", testName); |
epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 658 | return; |
| 659 | } |
| 660 | |
| 661 | SkAutoLockPixels alp0(expectedBitmap); |
| 662 | SkAutoLockPixels alp1(actualBitmap); |
| 663 | int errR = 0; |
| 664 | int errG = 0; |
| 665 | int errB = 0; |
| 666 | int errA = 0; |
| 667 | int differingPixels = 0; |
| 668 | |
| 669 | for (int y = 0; y < height; ++y) { |
| 670 | const SkPMColor* expectedPixelPtr = expectedBitmap.getAddr32(0, y); |
| 671 | const SkPMColor* actualPixelPtr = actualBitmap.getAddr32(0, y); |
| 672 | for (int x = 0; x < width; ++x) { |
| 673 | SkPMColor expectedPixel = *expectedPixelPtr++; |
| 674 | SkPMColor actualPixel = *actualPixelPtr++; |
| 675 | if (expectedPixel != actualPixel) { |
| 676 | differingPixels++; |
| 677 | errR = SkMax32(errR, SkAbs32((int)SkGetPackedR32(expectedPixel) - |
| 678 | (int)SkGetPackedR32(actualPixel))); |
| 679 | errG = SkMax32(errG, SkAbs32((int)SkGetPackedG32(expectedPixel) - |
| 680 | (int)SkGetPackedG32(actualPixel))); |
| 681 | errB = SkMax32(errB, SkAbs32((int)SkGetPackedB32(expectedPixel) - |
| 682 | (int)SkGetPackedB32(actualPixel))); |
| 683 | errA = SkMax32(errA, SkAbs32((int)SkGetPackedA32(expectedPixel) - |
| 684 | (int)SkGetPackedA32(actualPixel))); |
| 685 | } |
| 686 | } |
| 687 | } |
epoger@google.com | 5efdd0c | 2013-03-13 14:18:40 +0000 | [diff] [blame] | 688 | gm_fprintf(stderr, "---- %s: %d (of %d) differing pixels," |
| 689 | " max per-channel mismatch R=%d G=%d B=%d A=%d\n", |
| 690 | testName, differingPixels, width*height, errR, errG, errB, errA); |
epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | /** |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 694 | * Compares actual hash digest to expectations, returning the set of errors |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 695 | * (if any) that we saw along the way. |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 696 | * |
| 697 | * If fMismatchPath has been set, and there are pixel diffs, then the |
| 698 | * actual bitmap will be written out to a file within fMismatchPath. |
| 699 | * |
| 700 | * @param expectations what expectations to compare actualBitmap against |
| 701 | * @param actualBitmap the image we actually generated |
| 702 | * @param baseNameString name of test without renderModeDescriptor added |
| 703 | * @param renderModeDescriptor e.g., "-rtree", "-deferred" |
| 704 | * @param addToJsonSummary whether to add these results (both actual and |
epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 705 | * expected) to the JSON summary. Regardless of this setting, if |
| 706 | * we find an image mismatch in this test, we will write these |
| 707 | * results to the JSON summary. (This is so that we will always |
| 708 | * report errors across rendering modes, such as pipe vs tiled. |
| 709 | * See https://codereview.chromium.org/13650002/ ) |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 710 | */ |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 711 | ErrorCombination compare_to_expectations(Expectations expectations, |
| 712 | const SkBitmap& actualBitmap, |
| 713 | const SkString& baseNameString, |
| 714 | const char renderModeDescriptor[], |
epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 715 | bool addToJsonSummary) { |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 716 | ErrorCombination errors; |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 717 | SkHashDigest actualBitmapHash; |
| 718 | // TODO(epoger): Better handling for error returned by ComputeDigest()? |
| 719 | // For now, we just report a digest of 0 in error cases, like before. |
| 720 | if (!SkBitmapHasher::ComputeDigest(actualBitmap, &actualBitmapHash)) { |
| 721 | actualBitmapHash = 0; |
| 722 | } |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 723 | SkString completeNameString = baseNameString; |
| 724 | completeNameString.append(renderModeDescriptor); |
| 725 | const char* completeName = completeNameString.c_str(); |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 726 | |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 727 | if (expectations.empty()) { |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 728 | errors.add(kMissingExpectations_ErrorType); |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 729 | } else if (!expectations.match(actualBitmapHash)) { |
epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 730 | addToJsonSummary = true; |
| 731 | // The error mode we record depends on whether this was running |
| 732 | // in a non-standard renderMode. |
| 733 | if ('\0' == *renderModeDescriptor) { |
| 734 | errors.add(kExpectationsMismatch_ErrorType); |
| 735 | } else { |
| 736 | errors.add(kRenderModeMismatch_ErrorType); |
| 737 | } |
epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 738 | |
| 739 | // Write out the "actuals" for any mismatches, if we have |
| 740 | // been directed to do so. |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 741 | if (fMismatchPath) { |
| 742 | SkString path = |
| 743 | make_filename(fMismatchPath, renderModeDescriptor, |
| 744 | baseNameString.c_str(), "png"); |
| 745 | write_bitmap(path, actualBitmap); |
| 746 | } |
epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 747 | |
| 748 | // If we have access to a single expected bitmap, log more |
| 749 | // detail about the mismatch. |
| 750 | const SkBitmap *expectedBitmapPtr = expectations.asBitmap(); |
| 751 | if (NULL != expectedBitmapPtr) { |
| 752 | report_bitmap_diffs(*expectedBitmapPtr, actualBitmap, completeName); |
| 753 | } |
epoger@google.com | a243b22 | 2013-01-17 17:54:28 +0000 | [diff] [blame] | 754 | } |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 755 | RecordTestResults(errors, baseNameString, renderModeDescriptor); |
epoger@google.com | a243b22 | 2013-01-17 17:54:28 +0000 | [diff] [blame] | 756 | |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 757 | if (addToJsonSummary) { |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 758 | add_actual_results_to_json_summary(completeName, actualBitmapHash, errors, |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 759 | expectations.ignoreFailure()); |
| 760 | add_expected_results_to_json_summary(completeName, expectations); |
| 761 | } |
epoger@google.com | a243b22 | 2013-01-17 17:54:28 +0000 | [diff] [blame] | 762 | |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 763 | return errors; |
epoger@google.com | 06b8a19 | 2013-01-15 19:10:16 +0000 | [diff] [blame] | 764 | } |
| 765 | |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 766 | /** |
| 767 | * Add this result to the appropriate JSON collection of actual results, |
| 768 | * depending on status. |
| 769 | */ |
| 770 | void add_actual_results_to_json_summary(const char testName[], |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 771 | const SkHashDigest& actualBitmapHash, |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 772 | ErrorCombination result, |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 773 | bool ignoreFailure) { |
| 774 | Json::Value actualResults; |
| 775 | actualResults[kJsonKey_ActualResults_AnyStatus_Checksum] = |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 776 | asJsonValue(actualBitmapHash); |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 777 | if (result.isEmpty()) { |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 778 | this->fJsonActualResults_Succeeded[testName] = actualResults; |
| 779 | } else { |
| 780 | if (ignoreFailure) { |
| 781 | // TODO: Once we have added the ability to compare |
| 782 | // actual results against expectations in a JSON file |
| 783 | // (where we can set ignore-failure to either true or |
epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 784 | // false), add test cases that exercise ignored |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 785 | // failures (both for kMissingExpectations_ErrorType |
epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 786 | // and kExpectationsMismatch_ErrorType). |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 787 | this->fJsonActualResults_FailureIgnored[testName] = |
| 788 | actualResults; |
| 789 | } else { |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 790 | if (result.includes(kMissingExpectations_ErrorType)) { |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 791 | // TODO: What about the case where there IS an |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 792 | // expected image hash digest, but that gm test |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 793 | // doesn't actually run? For now, those cases |
| 794 | // will always be ignored, because gm only looks |
| 795 | // at expectations that correspond to gm tests |
| 796 | // that were actually run. |
| 797 | // |
| 798 | // Once we have the ability to express |
| 799 | // expectations as a JSON file, we should fix this |
| 800 | // (and add a test case for which an expectation |
| 801 | // is given but the test is never run). |
| 802 | this->fJsonActualResults_NoComparison[testName] = |
| 803 | actualResults; |
epoger@google.com | eb06636 | 2013-03-08 09:39:36 +0000 | [diff] [blame] | 804 | } |
epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 805 | if (result.includes(kExpectationsMismatch_ErrorType) || |
| 806 | result.includes(kRenderModeMismatch_ErrorType)) { |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 807 | this->fJsonActualResults_Failed[testName] = actualResults; |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 808 | } |
| 809 | } |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | /** |
| 814 | * Add this test to the JSON collection of expected results. |
| 815 | */ |
| 816 | void add_expected_results_to_json_summary(const char testName[], |
| 817 | Expectations expectations) { |
| 818 | // For now, we assume that this collection starts out empty and we |
| 819 | // just fill it in as we go; once gm accepts a JSON file as input, |
| 820 | // we'll have to change that. |
| 821 | Json::Value expectedResults; |
| 822 | expectedResults[kJsonKey_ExpectedResults_Checksums] = |
| 823 | expectations.allowedChecksumsAsJson(); |
| 824 | expectedResults[kJsonKey_ExpectedResults_IgnoreFailure] = |
| 825 | expectations.ignoreFailure(); |
| 826 | this->fJsonExpectedResults[testName] = expectedResults; |
| 827 | } |
| 828 | |
| 829 | /** |
| 830 | * Compare actualBitmap to expectations stored in this->fExpectationsSource. |
| 831 | * |
| 832 | * @param gm which test generated the actualBitmap |
| 833 | * @param gRec |
| 834 | * @param writePath unless this is NULL, write out actual images into this |
| 835 | * directory |
| 836 | * @param actualBitmap bitmap generated by this run |
| 837 | * @param pdf |
| 838 | */ |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 839 | ErrorCombination compare_test_results_to_stored_expectations( |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 840 | GM* gm, const ConfigData& gRec, const char writePath[], |
| 841 | SkBitmap& actualBitmap, SkDynamicMemoryWStream* pdf) { |
| 842 | |
epoger@google.com | a243b22 | 2013-01-17 17:54:28 +0000 | [diff] [blame] | 843 | SkString name = make_name(gm->shortName(), gRec.fName); |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 844 | ErrorCombination errors; |
epoger@google.com | 9ef89ce | 2013-01-18 21:45:42 +0000 | [diff] [blame] | 845 | |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 846 | ExpectationsSource *expectationsSource = this->fExpectationsSource.get(); |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 847 | if (expectationsSource && (gRec.fFlags & kRead_ConfigFlag)) { |
| 848 | /* |
| 849 | * Get the expected results for this test, as one or more allowed |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 850 | * hash digests. The current implementation of expectationsSource |
| 851 | * get this by computing the hash digest of a single PNG file on disk. |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 852 | * |
| 853 | * TODO(epoger): This relies on the fact that |
| 854 | * force_all_opaque() was called on the bitmap before it |
| 855 | * was written to disk as a PNG in the first place. If |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 856 | * not, the hash digest returned here may not match the |
| 857 | * hash digest of actualBitmap, which *has* been run through |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 858 | * force_all_opaque(). |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 859 | * See comments above complete_bitmap() for more detail. |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 860 | */ |
| 861 | Expectations expectations = expectationsSource->get(name.c_str()); |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 862 | errors.add(compare_to_expectations(expectations, actualBitmap, |
| 863 | name, "", true)); |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 864 | } else { |
| 865 | // If we are running without expectations, we still want to |
epoger@google.com | 9ef89ce | 2013-01-18 21:45:42 +0000 | [diff] [blame] | 866 | // record the actual results. |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 867 | SkHashDigest actualBitmapHash; |
| 868 | // TODO(epoger): Better handling for error returned by ComputeDigest()? |
| 869 | // For now, we just report a digest of 0 in error cases, like before. |
| 870 | if (!SkBitmapHasher::ComputeDigest(actualBitmap, &actualBitmapHash)) { |
| 871 | actualBitmapHash = 0; |
| 872 | } |
| 873 | add_actual_results_to_json_summary(name.c_str(), actualBitmapHash, |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 874 | ErrorCombination(kMissingExpectations_ErrorType), |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 875 | false); |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 876 | RecordTestResults(ErrorCombination(kMissingExpectations_ErrorType), name, ""); |
epoger@google.com | 9ef89ce | 2013-01-18 21:45:42 +0000 | [diff] [blame] | 877 | } |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 878 | |
| 879 | // TODO: Consider moving this into compare_to_expectations(), |
| 880 | // similar to fMismatchPath... for now, we don't do that, because |
| 881 | // we don't want to write out the actual bitmaps for all |
| 882 | // renderModes of all tests! That would be a lot of files. |
epoger@google.com | 9ef89ce | 2013-01-18 21:45:42 +0000 | [diff] [blame] | 883 | if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) { |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 884 | errors.add(write_reference_image(gRec, writePath, "", |
| 885 | name, actualBitmap, pdf)); |
epoger@google.com | 9ef89ce | 2013-01-18 21:45:42 +0000 | [diff] [blame] | 886 | } |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 887 | |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 888 | return errors; |
epoger@google.com | a243b22 | 2013-01-17 17:54:28 +0000 | [diff] [blame] | 889 | } |
| 890 | |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 891 | /** |
| 892 | * Compare actualBitmap to referenceBitmap. |
| 893 | * |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 894 | * @param baseNameString name of test without renderModeDescriptor added |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 895 | * @param renderModeDescriptor |
| 896 | * @param actualBitmap actual bitmap generated by this run |
| 897 | * @param referenceBitmap bitmap we expected to be generated |
| 898 | */ |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 899 | ErrorCombination compare_test_results_to_reference_bitmap( |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 900 | const SkString& baseNameString, const char renderModeDescriptor[], |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 901 | SkBitmap& actualBitmap, const SkBitmap* referenceBitmap) { |
| 902 | |
| 903 | SkASSERT(referenceBitmap); |
epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 904 | Expectations expectations(*referenceBitmap); |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 905 | return compare_to_expectations(expectations, actualBitmap, |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 906 | baseNameString, renderModeDescriptor, false); |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 907 | } |
| 908 | |
junov@chromium.org | 20bd04e | 2013-01-16 18:43:36 +0000 | [diff] [blame] | 909 | static SkPicture* generate_new_picture(GM* gm, BbhType bbhType, uint32_t recordFlags, |
| 910 | SkScalar scale = SK_Scalar1) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 911 | // Pictures are refcounted so must be on heap |
junov@chromium.org | 3cb834b | 2012-12-13 16:39:53 +0000 | [diff] [blame] | 912 | SkPicture* pict; |
junov@chromium.org | 706ff2f | 2012-12-19 15:55:40 +0000 | [diff] [blame] | 913 | int width = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().width()), scale)); |
| 914 | int height = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().height()), scale)); |
skia.committer@gmail.com | d8b2799 | 2012-12-20 02:01:41 +0000 | [diff] [blame] | 915 | |
junov@chromium.org | 3cb834b | 2012-12-13 16:39:53 +0000 | [diff] [blame] | 916 | if (kTileGrid_BbhType == bbhType) { |
junov@chromium.org | 29b19e5 | 2013-02-27 18:35:16 +0000 | [diff] [blame] | 917 | SkTileGridPicture::TileGridInfo info; |
| 918 | info.fMargin.setEmpty(); |
| 919 | info.fOffset.setZero(); |
| 920 | info.fTileInterval.set(16, 16); |
| 921 | pict = new SkTileGridPicture(width, height, info); |
junov@chromium.org | 3cb834b | 2012-12-13 16:39:53 +0000 | [diff] [blame] | 922 | } else { |
| 923 | pict = new SkPicture; |
| 924 | } |
junov@chromium.org | 20bd04e | 2013-01-16 18:43:36 +0000 | [diff] [blame] | 925 | if (kNone_BbhType != bbhType) { |
| 926 | recordFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; |
| 927 | } |
junov@chromium.org | 706ff2f | 2012-12-19 15:55:40 +0000 | [diff] [blame] | 928 | SkCanvas* cv = pict->beginRecording(width, height, recordFlags); |
junov@chromium.org | c938c48 | 2012-12-19 15:24:38 +0000 | [diff] [blame] | 929 | cv->scale(scale, scale); |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 930 | invokeGM(gm, cv, false, false); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 931 | pict->endRecording(); |
| 932 | |
| 933 | return pict; |
| 934 | } |
| 935 | |
| 936 | static SkPicture* stream_to_new_picture(const SkPicture& src) { |
| 937 | |
| 938 | // To do in-memory commiunications with a stream, we need to: |
| 939 | // * create a dynamic memory stream |
| 940 | // * copy it into a buffer |
| 941 | // * create a read stream from it |
| 942 | // ?!?! |
| 943 | |
| 944 | SkDynamicMemoryWStream storage; |
| 945 | src.serialize(&storage); |
| 946 | |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 947 | size_t streamSize = storage.getOffset(); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 948 | SkAutoMalloc dstStorage(streamSize); |
| 949 | void* dst = dstStorage.get(); |
| 950 | //char* dst = new char [streamSize]; |
| 951 | //@todo thudson 22 April 2011 when can we safely delete [] dst? |
| 952 | storage.copyTo(dst); |
| 953 | SkMemoryStream pictReadback(dst, streamSize); |
| 954 | SkPicture* retval = new SkPicture (&pictReadback); |
| 955 | return retval; |
| 956 | } |
| 957 | |
| 958 | // Test: draw into a bitmap or pdf. |
epoger@google.com | 15655b2 | 2013-01-08 18:47:31 +0000 | [diff] [blame] | 959 | // Depending on flags, possibly compare to an expected image. |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 960 | ErrorCombination test_drawing(GM* gm, |
| 961 | const ConfigData& gRec, |
| 962 | const char writePath [], |
bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 963 | GrSurface* gpuTarget, |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 964 | SkBitmap* bitmap) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 965 | SkDynamicMemoryWStream document; |
| 966 | |
| 967 | if (gRec.fBackend == kRaster_Backend || |
| 968 | gRec.fBackend == kGPU_Backend) { |
| 969 | // Early exit if we can't generate the image. |
bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 970 | ErrorCombination errors = generate_image(gm, gRec, gpuTarget, bitmap, false); |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 971 | if (!errors.isEmpty()) { |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 972 | // TODO: Add a test to exercise what the stdout and |
| 973 | // JSON look like if we get an "early error" while |
| 974 | // trying to generate the image. |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 975 | return errors; |
| 976 | } |
| 977 | } else if (gRec.fBackend == kPDF_Backend) { |
| 978 | generate_pdf(gm, document); |
| 979 | #if CAN_IMAGE_PDF |
| 980 | SkAutoDataUnref data(document.copyToData()); |
| 981 | SkMemoryStream stream(data->data(), data->size()); |
| 982 | SkPDFDocumentToBitmap(&stream, bitmap); |
| 983 | #endif |
| 984 | } else if (gRec.fBackend == kXPS_Backend) { |
| 985 | generate_xps(gm, document); |
| 986 | } |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 987 | return compare_test_results_to_stored_expectations( |
| 988 | gm, gRec, writePath, *bitmap, &document); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 989 | } |
| 990 | |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 991 | ErrorCombination test_deferred_drawing(GM* gm, |
| 992 | const ConfigData& gRec, |
| 993 | const SkBitmap& referenceBitmap, |
bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 994 | GrSurface* gpuTarget) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 995 | SkDynamicMemoryWStream document; |
| 996 | |
| 997 | if (gRec.fBackend == kRaster_Backend || |
| 998 | gRec.fBackend == kGPU_Backend) { |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 999 | const char renderModeDescriptor[] = "-deferred"; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1000 | SkBitmap bitmap; |
| 1001 | // Early exit if we can't generate the image, but this is |
| 1002 | // expected in some cases, so don't report a test failure. |
bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1003 | ErrorCombination errors = generate_image(gm, gRec, gpuTarget, &bitmap, true); |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1004 | // TODO(epoger): This logic is the opposite of what is |
| 1005 | // described above... if we succeeded in generating the |
| 1006 | // -deferred image, we exit early! We should fix this |
| 1007 | // ASAP, because it is hiding -deferred errors... but for |
| 1008 | // now, I'm leaving the logic as it is so that the |
| 1009 | // refactoring change |
| 1010 | // https://codereview.chromium.org/12992003/ is unblocked. |
| 1011 | // |
| 1012 | // Filed as https://code.google.com/p/skia/issues/detail?id=1180 |
| 1013 | // ('image-surface gm test is failing in "deferred" mode, |
| 1014 | // and gm is not reporting the failure') |
| 1015 | if (errors.isEmpty()) { |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 1016 | // TODO(epoger): Report this as a new ErrorType, |
| 1017 | // something like kImageGeneration_ErrorType? |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1018 | return kEmpty_ErrorCombination; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1019 | } |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1020 | const SkString name = make_name(gm->shortName(), gRec.fName); |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1021 | return compare_test_results_to_reference_bitmap( |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1022 | name, renderModeDescriptor, bitmap, &referenceBitmap); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1023 | } |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1024 | return kEmpty_ErrorCombination; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 1027 | ErrorCombination test_pipe_playback(GM* gm, const ConfigData& gRec, |
| 1028 | const SkBitmap& referenceBitmap, bool simulateFailure) { |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1029 | const SkString name = make_name(gm->shortName(), gRec.fName); |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1030 | ErrorCombination errors; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1031 | for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) { |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1032 | SkString renderModeDescriptor("-pipe"); |
| 1033 | renderModeDescriptor.append(gPipeWritingFlagCombos[i].name); |
| 1034 | |
| 1035 | if (gm->getFlags() & GM::kSkipPipe_Flag) { |
| 1036 | RecordTestResults(kIntentionallySkipped_ErrorType, name, |
| 1037 | renderModeDescriptor.c_str()); |
| 1038 | errors.add(kIntentionallySkipped_ErrorType); |
| 1039 | } else { |
| 1040 | SkBitmap bitmap; |
| 1041 | SkISize size = gm->getISize(); |
| 1042 | setup_bitmap(gRec, size, &bitmap); |
| 1043 | SkCanvas canvas(bitmap); |
| 1044 | installFilter(&canvas); |
| 1045 | PipeController pipeController(&canvas); |
| 1046 | SkGPipeWriter writer; |
| 1047 | SkCanvas* pipeCanvas = writer.startRecording(&pipeController, |
scroggo@google.com | aef2d3b | 2013-04-10 18:10:41 +0000 | [diff] [blame] | 1048 | gPipeWritingFlagCombos[i].flags, |
| 1049 | size.width(), size.height()); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1050 | if (!simulateFailure) { |
| 1051 | invokeGM(gm, pipeCanvas, false, false); |
| 1052 | } |
| 1053 | complete_bitmap(&bitmap); |
| 1054 | writer.endRecording(); |
| 1055 | errors.add(compare_test_results_to_reference_bitmap( |
| 1056 | name, renderModeDescriptor.c_str(), bitmap, &referenceBitmap)); |
| 1057 | if (!errors.isEmpty()) { |
| 1058 | break; |
| 1059 | } |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1060 | } |
| 1061 | } |
| 1062 | return errors; |
| 1063 | } |
| 1064 | |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1065 | ErrorCombination test_tiled_pipe_playback(GM* gm, const ConfigData& gRec, |
| 1066 | const SkBitmap& referenceBitmap) { |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1067 | const SkString name = make_name(gm->shortName(), gRec.fName); |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1068 | ErrorCombination errors; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1069 | for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) { |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1070 | SkString renderModeDescriptor("-tiled pipe"); |
| 1071 | renderModeDescriptor.append(gPipeWritingFlagCombos[i].name); |
| 1072 | |
| 1073 | if ((gm->getFlags() & GM::kSkipPipe_Flag) || |
| 1074 | (gm->getFlags() & GM::kSkipTiled_Flag)) { |
| 1075 | RecordTestResults(kIntentionallySkipped_ErrorType, name, |
| 1076 | renderModeDescriptor.c_str()); |
| 1077 | errors.add(kIntentionallySkipped_ErrorType); |
| 1078 | } else { |
| 1079 | SkBitmap bitmap; |
| 1080 | SkISize size = gm->getISize(); |
| 1081 | setup_bitmap(gRec, size, &bitmap); |
| 1082 | SkCanvas canvas(bitmap); |
| 1083 | installFilter(&canvas); |
| 1084 | TiledPipeController pipeController(bitmap); |
| 1085 | SkGPipeWriter writer; |
| 1086 | SkCanvas* pipeCanvas = writer.startRecording(&pipeController, |
scroggo@google.com | aef2d3b | 2013-04-10 18:10:41 +0000 | [diff] [blame] | 1087 | gPipeWritingFlagCombos[i].flags, |
| 1088 | size.width(), size.height()); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1089 | invokeGM(gm, pipeCanvas, false, false); |
| 1090 | complete_bitmap(&bitmap); |
| 1091 | writer.endRecording(); |
| 1092 | errors.add(compare_test_results_to_reference_bitmap(name, |
| 1093 | renderModeDescriptor.c_str(), |
| 1094 | bitmap, &referenceBitmap)); |
| 1095 | if (!errors.isEmpty()) { |
| 1096 | break; |
| 1097 | } |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1098 | } |
| 1099 | } |
| 1100 | return errors; |
| 1101 | } |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 1102 | |
| 1103 | // |
| 1104 | // member variables. |
| 1105 | // They are public for now, to allow easier setting by tool_main(). |
| 1106 | // |
| 1107 | |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 1108 | bool fUseFileHierarchy; |
epoger@google.com | 5079d2c | 2013-04-12 14:11:21 +0000 | [diff] [blame] | 1109 | ErrorCombination fIgnorableErrorTypes; |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 1110 | |
junov@chromium.org | 95146eb | 2013-01-11 21:04:40 +0000 | [diff] [blame] | 1111 | const char* fMismatchPath; |
| 1112 | |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 1113 | // collection of tests that have failed with each ErrorType |
| 1114 | SkTArray<SkString> fFailedTests[kLast_ErrorType+1]; |
| 1115 | int fTestsRun; |
| 1116 | SkTDict<int> fRenderModesEncountered; |
epoger@google.com | 57f7abc | 2012-11-13 03:41:55 +0000 | [diff] [blame] | 1117 | |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 1118 | // Where to read expectations (expected image hash digests, etc.) from. |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1119 | // If unset, we don't do comparisons. |
| 1120 | SkAutoTUnref<ExpectationsSource> fExpectationsSource; |
| 1121 | |
| 1122 | // JSON summaries that we generate as we go (just for output). |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 1123 | Json::Value fJsonExpectedResults; |
| 1124 | Json::Value fJsonActualResults_Failed; |
| 1125 | Json::Value fJsonActualResults_FailureIgnored; |
epoger@google.com | 9c56a8d | 2012-12-20 18:34:29 +0000 | [diff] [blame] | 1126 | Json::Value fJsonActualResults_NoComparison; |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 1127 | Json::Value fJsonActualResults_Succeeded; |
| 1128 | |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1129 | }; // end of GMMain class definition |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 1130 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1131 | #if SK_SUPPORT_GPU |
| 1132 | static const GLContextType kDontCare_GLContextType = GrContextFactory::kNative_GLContextType; |
| 1133 | #else |
| 1134 | static const GLContextType kDontCare_GLContextType = 0; |
| 1135 | #endif |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1136 | |
| 1137 | // 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] | 1138 | // 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] | 1139 | static const ConfigFlags kPDFConfigFlags = CAN_IMAGE_PDF ? kRW_ConfigFlag : |
| 1140 | kWrite_ConfigFlag; |
| 1141 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1142 | static const ConfigData gRec[] = { |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1143 | { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "8888", true }, |
reed@google.com | 69dc4ff | 2012-11-29 21:21:54 +0000 | [diff] [blame] | 1144 | #if 0 // stop testing this (for now at least) since we want to remove support for it (soon please!!!) |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1145 | { SkBitmap::kARGB_4444_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "4444", true }, |
reed@google.com | 69dc4ff | 2012-11-29 21:21:54 +0000 | [diff] [blame] | 1146 | #endif |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1147 | { SkBitmap::kRGB_565_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "565", true }, |
| 1148 | #if SK_SUPPORT_GPU |
| 1149 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 0, kRW_ConfigFlag, "gpu", true }, |
| 1150 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 16, kRW_ConfigFlag, "msaa16", true }, |
| 1151 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 4, kRW_ConfigFlag, "msaa4", false}, |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1152 | /* The debug context does not generate images */ |
scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1153 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kDebug_GLContextType, 0, kNone_ConfigFlag, "gpudebug", GR_DEBUG}, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1154 | #if SK_ANGLE |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1155 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 0, kRW_ConfigFlag, "angle", true }, |
| 1156 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 16, kRW_ConfigFlag, "anglemsaa16", true }, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1157 | #endif // SK_ANGLE |
| 1158 | #ifdef SK_MESA |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1159 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kMESA_GLContextType, 0, kRW_ConfigFlag, "mesa", true }, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1160 | #endif // SK_MESA |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1161 | #endif // SK_SUPPORT_GPU |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1162 | #ifdef SK_SUPPORT_XPS |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1163 | /* At present we have no way of comparing XPS files (either natively or by converting to PNG). */ |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1164 | { SkBitmap::kARGB_8888_Config, kXPS_Backend, kDontCare_GLContextType, 0, kWrite_ConfigFlag, "xps", true }, |
robertphillips@google.com | a73e860 | 2012-08-02 17:56:02 +0000 | [diff] [blame] | 1165 | #endif // SK_SUPPORT_XPS |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1166 | #ifdef SK_SUPPORT_PDF |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1167 | { SkBitmap::kARGB_8888_Config, kPDF_Backend, kDontCare_GLContextType, 0, kPDFConfigFlags, "pdf", true }, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1168 | #endif // SK_SUPPORT_PDF |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1169 | }; |
| 1170 | |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1171 | static SkString configUsage() { |
scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1172 | SkString result; |
| 1173 | result.appendf("Space delimited list of which configs to run. Possible options: ["); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1174 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 1175 | if (i > 0) { |
scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1176 | result.append("|"); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1177 | } |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1178 | result.appendf("%s", gRec[i].fName); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1179 | } |
scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1180 | result.append("]\n"); |
| 1181 | result.appendf("The default value is: \""); |
| 1182 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 1183 | if (gRec[i].fRunByDefault) { |
| 1184 | if (i > 0) { |
| 1185 | result.append(" "); |
| 1186 | } |
| 1187 | result.appendf("%s", gRec[i].fName); |
| 1188 | } |
| 1189 | } |
| 1190 | result.appendf("\""); |
| 1191 | |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1192 | return result; |
scroggo@google.com | 0b73563 | 2013-03-19 17:38:50 +0000 | [diff] [blame] | 1193 | } |
scroggo@google.com | 7d51930 | 2013-03-19 17:28:10 +0000 | [diff] [blame] | 1194 | |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1195 | // Macro magic to convert a numeric preprocessor token into a string. |
| 1196 | // Adapted from http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string |
| 1197 | // This should probably be moved into one of our common headers... |
| 1198 | #define TOSTRING_INTERNAL(x) #x |
| 1199 | #define TOSTRING(x) TOSTRING_INTERNAL(x) |
| 1200 | |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1201 | // Alphabetized ignoring "no" prefix ("readPath", "noreplay", "resourcePath"). |
scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1202 | DEFINE_string(config, "", configUsage().c_str()); |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1203 | DEFINE_bool(deferred, true, "Exercise the deferred rendering test pass."); |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1204 | DEFINE_string(excludeConfig, "", "Space delimited list of configs to skip."); |
| 1205 | DEFINE_bool(forceBWtext, false, "Disable text anti-aliasing."); |
| 1206 | #if SK_SUPPORT_GPU |
| 1207 | DEFINE_string(gpuCacheSize, "", "<bytes> <count>: Limit the gpu cache to byte size or " |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1208 | "object count. " TOSTRING(DEFAULT_CACHE_VALUE) " for either value means " |
| 1209 | "use the default. 0 for either disables the cache."); |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1210 | #endif |
| 1211 | DEFINE_bool(hierarchy, false, "Whether to use multilevel directory structure " |
| 1212 | "when reading/writing files."); |
epoger@google.com | 5079d2c | 2013-04-12 14:11:21 +0000 | [diff] [blame] | 1213 | // TODO(epoger): Maybe should make SkCommandLineFlags handle default string |
| 1214 | // values differently, so that the first definition of ignoreErrorTypes worked? |
| 1215 | #if 0 |
| 1216 | DEFINE_string(ignoreErrorTypes, kDefaultIgnorableErrorTypes.asString(" ").c_str(), |
| 1217 | "Space-separated list of ErrorTypes that should be ignored. If any *other* error " |
| 1218 | "types are encountered, the tool will exit with a nonzero return value."); |
| 1219 | #else |
| 1220 | DEFINE_string(ignoreErrorTypes, "", SkString(SkString( |
| 1221 | "Space-separated list of ErrorTypes that should be ignored. If any *other* error " |
| 1222 | "types are encountered, the tool will exit with a nonzero return value. " |
| 1223 | "Defaults to: ") += kDefaultIgnorableErrorTypes.asString(" ")).c_str()); |
| 1224 | #endif |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1225 | DEFINE_string(match, "", "Only run tests whose name includes this substring/these substrings " |
| 1226 | "(more than one can be supplied, separated by spaces)."); |
| 1227 | DEFINE_string(mismatchPath, "", "Write images for tests that failed due to " |
| 1228 | "pixel mismatches into this directory."); |
| 1229 | DEFINE_string(modulo, "", "[--modulo <remainder> <divisor>]: only run tests for which " |
| 1230 | "testIndex %% divisor == remainder."); |
| 1231 | DEFINE_bool(pdf, true, "Exercise the pdf rendering test pass."); |
| 1232 | DEFINE_bool(pipe, true, "Exercise the SkGPipe replay test pass."); |
| 1233 | DEFINE_string2(readPath, r, "", "Read reference images from this dir, and report " |
| 1234 | "any differences between those and the newly generated ones."); |
| 1235 | DEFINE_bool(replay, true, "Exercise the SkPicture replay test pass."); |
| 1236 | DEFINE_string2(resourcePath, i, "", "Directory that stores image resources."); |
| 1237 | DEFINE_bool(rtree, true, "Exercise the R-Tree variant of SkPicture test pass."); |
| 1238 | DEFINE_bool(serialize, true, "Exercise the SkPicture serialization & deserialization test pass."); |
epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 1239 | DEFINE_bool(simulatePipePlaybackFailure, false, "Simulate a rendering failure in pipe mode only."); |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1240 | DEFINE_bool(tiledPipe, false, "Exercise tiled SkGPipe replay."); |
| 1241 | DEFINE_bool(tileGrid, true, "Exercise the tile grid variant of SkPicture."); |
| 1242 | DEFINE_string(tileGridReplayScales, "", "Space separated list of floating-point scale " |
| 1243 | "factors to be used for tileGrid playback testing. Default value: 1.0"); |
| 1244 | DEFINE_string(writeJsonSummaryPath, "", "Write a JSON-formatted result summary to this file."); |
epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 1245 | DEFINE_bool2(verbose, v, false, "Give more detail (e.g. list all GMs run, more info about " |
| 1246 | "each test)."); |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1247 | DEFINE_string2(writePath, w, "", "Write rendered images into this directory."); |
scroggo@google.com | 604e0c2 | 2013-04-09 21:25:46 +0000 | [diff] [blame] | 1248 | DEFINE_string2(writePicturePath, p, "", "Write .skp files into this directory."); |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1249 | |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1250 | static int findConfig(const char config[]) { |
| 1251 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { |
| 1252 | if (!strcmp(config, gRec[i].fName)) { |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1253 | return (int) i; |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1254 | } |
| 1255 | } |
| 1256 | return -1; |
| 1257 | } |
| 1258 | |
scroggo@google.com | b7dbf63 | 2013-04-23 15:38:09 +0000 | [diff] [blame^] | 1259 | static bool skip_name(SkCommandLineFlags::StringArray array, const char name[]) { |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 1260 | if (0 == array.count()) { |
| 1261 | // no names, so don't skip anything |
| 1262 | return false; |
| 1263 | } |
| 1264 | for (int i = 0; i < array.count(); ++i) { |
| 1265 | if (strstr(name, array[i])) { |
| 1266 | // found the name, so don't skip |
| 1267 | return false; |
| 1268 | } |
| 1269 | } |
| 1270 | return true; |
| 1271 | } |
| 1272 | |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 1273 | namespace skiagm { |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1274 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1275 | SkAutoTUnref<GrContext> gGrContext; |
| 1276 | /** |
bsalomon@google.com | c7a24d2 | 2012-11-01 18:03:48 +0000 | [diff] [blame] | 1277 | * Sets the global GrContext, accessible by individual GMs |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1278 | */ |
caryclark@google.com | 1313086 | 2012-06-06 12:10:45 +0000 | [diff] [blame] | 1279 | static void SetGr(GrContext* grContext) { |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1280 | SkSafeRef(grContext); |
| 1281 | gGrContext.reset(grContext); |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 1282 | } |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1283 | |
| 1284 | /** |
| 1285 | * Gets the global GrContext, can be called by GM tests. |
| 1286 | */ |
caryclark@google.com | 1313086 | 2012-06-06 12:10:45 +0000 | [diff] [blame] | 1287 | GrContext* GetGr(); |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1288 | GrContext* GetGr() { |
| 1289 | return gGrContext.get(); |
| 1290 | } |
| 1291 | |
| 1292 | /** |
| 1293 | * Sets the global GrContext and then resets it to its previous value at |
| 1294 | * destruction. |
| 1295 | */ |
| 1296 | class AutoResetGr : SkNoncopyable { |
| 1297 | public: |
| 1298 | AutoResetGr() : fOld(NULL) {} |
| 1299 | void set(GrContext* context) { |
| 1300 | SkASSERT(NULL == fOld); |
| 1301 | fOld = GetGr(); |
| 1302 | SkSafeRef(fOld); |
| 1303 | SetGr(context); |
| 1304 | } |
| 1305 | ~AutoResetGr() { SetGr(fOld); SkSafeUnref(fOld); } |
| 1306 | private: |
| 1307 | GrContext* fOld; |
| 1308 | }; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1309 | #else |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1310 | GrContext* GetGr(); |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1311 | GrContext* GetGr() { return NULL; } |
| 1312 | #endif |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 1313 | } |
| 1314 | |
reed@google.com | fb2cd42 | 2013-01-04 14:43:03 +0000 | [diff] [blame] | 1315 | template <typename T> void appendUnique(SkTDArray<T>* array, const T& value) { |
| 1316 | int index = array->find(value); |
| 1317 | if (index < 0) { |
| 1318 | *array->append() = value; |
| 1319 | } |
| 1320 | } |
| 1321 | |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1322 | /** |
| 1323 | * Run this test in a number of different configs (8888, 565, PDF, |
| 1324 | * etc.), confirming that the resulting bitmaps match expectations |
| 1325 | * (which may be different for each config). |
| 1326 | * |
| 1327 | * Returns all errors encountered while doing so. |
| 1328 | */ |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1329 | ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm, const SkTDArray<size_t> &configs, |
| 1330 | GrContextFactory *grFactory); |
| 1331 | ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm, const SkTDArray<size_t> &configs, |
| 1332 | GrContextFactory *grFactory) { |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1333 | const char renderModeDescriptor[] = ""; |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1334 | ErrorCombination errorsForAllConfigs; |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1335 | uint32_t gmFlags = gm->getFlags(); |
| 1336 | |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1337 | for (int i = 0; i < configs.count(); i++) { |
| 1338 | ConfigData config = gRec[configs[i]]; |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1339 | const SkString name = gmmain.make_name(gm->shortName(), config.fName); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1340 | |
| 1341 | // Skip any tests that we don't even need to try. |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1342 | // If any of these were skipped on a per-GM basis, record them as |
| 1343 | // kIntentionallySkipped. |
| 1344 | if (kPDF_Backend == config.fBackend) { |
| 1345 | if (!FLAGS_pdf) { |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1346 | continue; |
| 1347 | } |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1348 | if (gmFlags & GM::kSkipPDF_Flag) { |
| 1349 | gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, name, |
| 1350 | renderModeDescriptor); |
| 1351 | errorsForAllConfigs.add(kIntentionallySkipped_ErrorType); |
| 1352 | continue; |
| 1353 | } |
| 1354 | } |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1355 | if ((gmFlags & GM::kSkip565_Flag) && |
| 1356 | (kRaster_Backend == config.fBackend) && |
| 1357 | (SkBitmap::kRGB_565_Config == config.fConfig)) { |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1358 | gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, name, |
| 1359 | renderModeDescriptor); |
| 1360 | errorsForAllConfigs.add(kIntentionallySkipped_ErrorType); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1361 | continue; |
| 1362 | } |
| 1363 | if ((gmFlags & GM::kSkipGPU_Flag) && |
| 1364 | kGPU_Backend == config.fBackend) { |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1365 | gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, name, |
| 1366 | renderModeDescriptor); |
| 1367 | errorsForAllConfigs.add(kIntentionallySkipped_ErrorType); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1368 | continue; |
| 1369 | } |
| 1370 | |
| 1371 | // Now we know that we want to run this test and record its |
| 1372 | // success or failure. |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1373 | ErrorCombination errorsForThisConfig; |
bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1374 | GrSurface* gpuTarget = NULL; |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1375 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1376 | SkAutoTUnref<GrSurface> auGpuTarget; |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1377 | AutoResetGr autogr; |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1378 | if ((errorsForThisConfig.isEmpty()) && (kGPU_Backend == config.fBackend)) { |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1379 | GrContext* gr = grFactory->get(config.fGLContextType); |
| 1380 | bool grSuccess = false; |
| 1381 | if (gr) { |
| 1382 | // create a render target to back the device |
| 1383 | GrTextureDesc desc; |
| 1384 | desc.fConfig = kSkia8888_GrPixelConfig; |
| 1385 | desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 1386 | desc.fWidth = gm->getISize().width(); |
| 1387 | desc.fHeight = gm->getISize().height(); |
| 1388 | desc.fSampleCnt = config.fSampleCnt; |
bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1389 | auGpuTarget.reset(gr->createUncachedTexture(desc, NULL, 0)); |
| 1390 | if (NULL != auGpuTarget) { |
| 1391 | gpuTarget = auGpuTarget; |
| 1392 | grSuccess = true; |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1393 | autogr.set(gr); |
bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1394 | // Set the user specified cache limits if non-default. |
| 1395 | size_t bytes; |
| 1396 | int count; |
| 1397 | gr->getTextureCacheLimits(&count, &bytes); |
| 1398 | if (DEFAULT_CACHE_VALUE != gGpuCacheSizeBytes) { |
| 1399 | bytes = static_cast<size_t>(gGpuCacheSizeBytes); |
| 1400 | } |
| 1401 | if (DEFAULT_CACHE_VALUE != gGpuCacheSizeCount) { |
| 1402 | count = gGpuCacheSizeCount; |
| 1403 | } |
| 1404 | gr->setTextureCacheLimits(count, bytes); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1405 | } |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1406 | } |
| 1407 | if (!grSuccess) { |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1408 | errorsForThisConfig.add(kNoGpuContext_ErrorType); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1409 | } |
| 1410 | } |
| 1411 | #endif |
| 1412 | |
| 1413 | SkBitmap comparisonBitmap; |
| 1414 | |
| 1415 | const char* writePath; |
| 1416 | if (FLAGS_writePath.count() == 1) { |
| 1417 | writePath = FLAGS_writePath[0]; |
| 1418 | } else { |
| 1419 | writePath = NULL; |
| 1420 | } |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1421 | if (errorsForThisConfig.isEmpty()) { |
bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1422 | errorsForThisConfig.add(gmmain.test_drawing(gm,config, writePath, gpuTarget, |
| 1423 | &comparisonBitmap)); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1424 | } |
| 1425 | |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1426 | if (FLAGS_deferred && errorsForThisConfig.isEmpty() && |
| 1427 | (kGPU_Backend == config.fBackend || kRaster_Backend == config.fBackend)) { |
| 1428 | errorsForThisConfig.add(gmmain.test_deferred_drawing(gm, config, comparisonBitmap, |
bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1429 | gpuTarget)); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1430 | } |
| 1431 | |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1432 | errorsForAllConfigs.add(errorsForThisConfig); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1433 | } |
| 1434 | return errorsForAllConfigs; |
| 1435 | } |
| 1436 | |
| 1437 | /** |
| 1438 | * Run this test in a number of different drawing modes (pipe, |
| 1439 | * deferred, tiled, etc.), confirming that the resulting bitmaps all |
| 1440 | * *exactly* match comparisonBitmap. |
| 1441 | * |
| 1442 | * Returns all errors encountered while doing so. |
| 1443 | */ |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1444 | ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm, const ConfigData &compareConfig, |
| 1445 | const SkBitmap &comparisonBitmap, |
| 1446 | const SkTDArray<SkScalar> &tileGridReplayScales); |
| 1447 | ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm, const ConfigData &compareConfig, |
| 1448 | const SkBitmap &comparisonBitmap, |
| 1449 | const SkTDArray<SkScalar> &tileGridReplayScales) { |
| 1450 | ErrorCombination errorsForAllModes; |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1451 | uint32_t gmFlags = gm->getFlags(); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1452 | const SkString name = gmmain.make_name(gm->shortName(), compareConfig.fName); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1453 | |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1454 | SkPicture* pict = gmmain.generate_new_picture(gm, kNone_BbhType, 0); |
| 1455 | SkAutoUnref aur(pict); |
| 1456 | if (FLAGS_replay) { |
| 1457 | const char renderModeDescriptor[] = "-replay"; |
| 1458 | if (gmFlags & GM::kSkipPicture_Flag) { |
| 1459 | gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, name, renderModeDescriptor); |
| 1460 | errorsForAllModes.add(kIntentionallySkipped_ErrorType); |
| 1461 | } else { |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1462 | SkBitmap bitmap; |
| 1463 | gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1464 | errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap( |
| 1465 | name, renderModeDescriptor, bitmap, &comparisonBitmap)); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1466 | } |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1467 | } |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1468 | |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1469 | if (FLAGS_serialize) { |
| 1470 | const char renderModeDescriptor[] = "-serialize"; |
| 1471 | if (gmFlags & GM::kSkipPicture_Flag) { |
| 1472 | gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, name, renderModeDescriptor); |
| 1473 | errorsForAllModes.add(kIntentionallySkipped_ErrorType); |
| 1474 | } else { |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1475 | SkPicture* repict = gmmain.stream_to_new_picture(*pict); |
| 1476 | SkAutoUnref aurr(repict); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1477 | SkBitmap bitmap; |
| 1478 | gmmain.generate_image_from_picture(gm, compareConfig, repict, &bitmap); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1479 | errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap( |
| 1480 | name, renderModeDescriptor, bitmap, &comparisonBitmap)); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1481 | } |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1482 | } |
| 1483 | |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1484 | if ((1 == FLAGS_writePicturePath.count()) && |
| 1485 | !(gmFlags & GM::kSkipPicture_Flag)) { |
| 1486 | const char* pictureSuffix = "skp"; |
| 1487 | SkString path = make_filename(FLAGS_writePicturePath[0], "", |
| 1488 | gm->shortName(), pictureSuffix); |
| 1489 | SkFILEWStream stream(path.c_str()); |
| 1490 | pict->serialize(&stream); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1491 | } |
| 1492 | |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1493 | if (FLAGS_rtree) { |
| 1494 | const char renderModeDescriptor[] = "-rtree"; |
| 1495 | if (gmFlags & GM::kSkipPicture_Flag) { |
| 1496 | gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, name, renderModeDescriptor); |
| 1497 | errorsForAllModes.add(kIntentionallySkipped_ErrorType); |
| 1498 | } else { |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1499 | SkPicture* pict = gmmain.generate_new_picture( |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1500 | gm, kRTree_BbhType, SkPicture::kUsePathBoundsForClip_RecordingFlag); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1501 | SkAutoUnref aur(pict); |
| 1502 | SkBitmap bitmap; |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1503 | gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap); |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1504 | errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap( |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1505 | name, renderModeDescriptor, bitmap, &comparisonBitmap)); |
| 1506 | } |
| 1507 | } |
| 1508 | |
| 1509 | if (FLAGS_tileGrid) { |
| 1510 | for(int scaleIndex = 0; scaleIndex < tileGridReplayScales.count(); ++scaleIndex) { |
| 1511 | SkScalar replayScale = tileGridReplayScales[scaleIndex]; |
| 1512 | SkString renderModeDescriptor("-tilegrid"); |
| 1513 | if (SK_Scalar1 != replayScale) { |
| 1514 | renderModeDescriptor += "-scale-"; |
| 1515 | renderModeDescriptor.appendScalar(replayScale); |
| 1516 | } |
| 1517 | |
| 1518 | if ((gmFlags & GM::kSkipPicture_Flag) || |
| 1519 | ((gmFlags & GM::kSkipScaledReplay_Flag) && replayScale != 1)) { |
| 1520 | gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, name, |
| 1521 | renderModeDescriptor.c_str()); |
| 1522 | errorsForAllModes.add(kIntentionallySkipped_ErrorType); |
| 1523 | } else { |
| 1524 | // We record with the reciprocal scale to obtain a replay |
| 1525 | // result that can be validated against comparisonBitmap. |
| 1526 | SkScalar recordScale = SkScalarInvert(replayScale); |
| 1527 | SkPicture* pict = gmmain.generate_new_picture( |
| 1528 | gm, kTileGrid_BbhType, SkPicture::kUsePathBoundsForClip_RecordingFlag, |
| 1529 | recordScale); |
| 1530 | SkAutoUnref aur(pict); |
| 1531 | SkBitmap bitmap; |
| 1532 | // We cannot yet pass 'true' to generate_image_from_picture to |
| 1533 | // perform actual tiled rendering (see Issue 1198 - |
| 1534 | // https://code.google.com/p/skia/issues/detail?id=1198) |
| 1535 | gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap, |
| 1536 | replayScale /*, true */); |
| 1537 | errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap( |
| 1538 | name, renderModeDescriptor.c_str(), bitmap, &comparisonBitmap)); |
| 1539 | } |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1540 | } |
| 1541 | } |
| 1542 | |
| 1543 | // run the pipe centric GM steps |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1544 | if (FLAGS_pipe) { |
| 1545 | errorsForAllModes.add(gmmain.test_pipe_playback(gm, compareConfig, comparisonBitmap, |
| 1546 | FLAGS_simulatePipePlaybackFailure)); |
| 1547 | if (FLAGS_tiledPipe) { |
| 1548 | errorsForAllModes.add(gmmain.test_tiled_pipe_playback(gm, compareConfig, |
| 1549 | comparisonBitmap)); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1550 | } |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1551 | } |
| 1552 | return errorsForAllModes; |
| 1553 | } |
| 1554 | |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 1555 | /** |
| 1556 | * Return a list of all entries in an array of strings as a single string |
| 1557 | * of this form: |
| 1558 | * "item1", "item2", "item3" |
| 1559 | */ |
| 1560 | SkString list_all(const SkTArray<SkString> &stringArray); |
| 1561 | SkString list_all(const SkTArray<SkString> &stringArray) { |
| 1562 | SkString total; |
| 1563 | for (int i = 0; i < stringArray.count(); i++) { |
| 1564 | if (i > 0) { |
| 1565 | total.append(", "); |
| 1566 | } |
| 1567 | total.append("\""); |
| 1568 | total.append(stringArray[i]); |
| 1569 | total.append("\""); |
| 1570 | } |
| 1571 | return total; |
| 1572 | } |
| 1573 | |
| 1574 | /** |
| 1575 | * Return a list of configuration names, as a single string of this form: |
| 1576 | * "item1", "item2", "item3" |
| 1577 | * |
| 1578 | * @param configs configurations, as a list of indices into gRec |
| 1579 | */ |
| 1580 | SkString list_all_config_names(const SkTDArray<size_t> &configs); |
| 1581 | SkString list_all_config_names(const SkTDArray<size_t> &configs) { |
| 1582 | SkString total; |
| 1583 | for (int i = 0; i < configs.count(); i++) { |
| 1584 | if (i > 0) { |
| 1585 | total.append(", "); |
| 1586 | } |
| 1587 | total.append("\""); |
| 1588 | total.append(gRec[configs[i]].fName); |
| 1589 | total.append("\""); |
| 1590 | } |
| 1591 | return total; |
| 1592 | } |
| 1593 | |
epoger@google.com | 0b62b3d | 2013-03-20 17:59:28 +0000 | [diff] [blame] | 1594 | int tool_main(int argc, char** argv); |
| 1595 | int tool_main(int argc, char** argv) { |
| 1596 | |
| 1597 | #if SK_ENABLE_INST_COUNT |
| 1598 | gPrintInstCount = true; |
| 1599 | #endif |
| 1600 | |
| 1601 | SkGraphics::Init(); |
| 1602 | // we don't need to see this during a run |
| 1603 | gSkSuppressFontCachePurgeSpew = true; |
| 1604 | |
| 1605 | setSystemPreferences(); |
| 1606 | GMMain gmmain; |
| 1607 | |
| 1608 | SkTDArray<size_t> configs; |
| 1609 | SkTDArray<size_t> excludeConfigs; |
| 1610 | bool userConfig = false; |
| 1611 | |
| 1612 | SkString usage; |
| 1613 | usage.printf("Run the golden master tests.\n"); |
scroggo@google.com | d9ba9a0 | 2013-03-21 19:43:15 +0000 | [diff] [blame] | 1614 | SkCommandLineFlags::SetUsage(usage.c_str()); |
| 1615 | SkCommandLineFlags::Parse(argc, argv); |
epoger@google.com | 0b62b3d | 2013-03-20 17:59:28 +0000 | [diff] [blame] | 1616 | |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1617 | gmmain.fUseFileHierarchy = FLAGS_hierarchy; |
| 1618 | if (FLAGS_mismatchPath.count() == 1) { |
| 1619 | gmmain.fMismatchPath = FLAGS_mismatchPath[0]; |
| 1620 | } |
| 1621 | |
| 1622 | for (int i = 0; i < FLAGS_config.count(); i++) { |
| 1623 | int index = findConfig(FLAGS_config[i]); |
| 1624 | if (index >= 0) { |
| 1625 | appendUnique<size_t>(&configs, index); |
| 1626 | userConfig = true; |
scroggo@google.com | 0b73563 | 2013-03-19 17:38:50 +0000 | [diff] [blame] | 1627 | } else { |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1628 | gm_fprintf(stderr, "unrecognized config %s\n", FLAGS_config[i]); |
scroggo@google.com | 7d51930 | 2013-03-19 17:28:10 +0000 | [diff] [blame] | 1629 | return -1; |
| 1630 | } |
| 1631 | } |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1632 | |
| 1633 | for (int i = 0; i < FLAGS_excludeConfig.count(); i++) { |
| 1634 | int index = findConfig(FLAGS_excludeConfig[i]); |
| 1635 | if (index >= 0) { |
| 1636 | *excludeConfigs.append() = index; |
| 1637 | } else { |
| 1638 | gm_fprintf(stderr, "unrecognized excludeConfig %s\n", FLAGS_excludeConfig[i]); |
| 1639 | return -1; |
| 1640 | } |
| 1641 | } |
| 1642 | |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1643 | int moduloRemainder = -1; |
| 1644 | int moduloDivisor = -1; |
| 1645 | |
| 1646 | if (FLAGS_modulo.count() == 2) { |
| 1647 | moduloRemainder = atoi(FLAGS_modulo[0]); |
| 1648 | moduloDivisor = atoi(FLAGS_modulo[1]); |
| 1649 | if (moduloRemainder < 0 || moduloDivisor <= 0 || moduloRemainder >= moduloDivisor) { |
| 1650 | gm_fprintf(stderr, "invalid modulo values."); |
| 1651 | return -1; |
| 1652 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1653 | } |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 1654 | |
epoger@google.com | 5079d2c | 2013-04-12 14:11:21 +0000 | [diff] [blame] | 1655 | if (FLAGS_ignoreErrorTypes.count() > 0) { |
| 1656 | gmmain.fIgnorableErrorTypes = ErrorCombination(); |
| 1657 | for (int i = 0; i < FLAGS_ignoreErrorTypes.count(); i++) { |
| 1658 | ErrorType type; |
| 1659 | const char *name = FLAGS_ignoreErrorTypes[i]; |
| 1660 | if (!getErrorTypeByName(name, &type)) { |
| 1661 | gm_fprintf(stderr, "cannot find ErrorType with name '%s'\n", name); |
| 1662 | return -1; |
| 1663 | } else { |
| 1664 | gmmain.fIgnorableErrorTypes.add(type); |
| 1665 | } |
| 1666 | } |
| 1667 | } |
| 1668 | |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1669 | #if SK_SUPPORT_GPU |
| 1670 | if (FLAGS_gpuCacheSize.count() > 0) { |
| 1671 | if (FLAGS_gpuCacheSize.count() != 2) { |
| 1672 | gm_fprintf(stderr, "--gpuCacheSize requires two arguments\n"); |
| 1673 | return -1; |
| 1674 | } |
| 1675 | gGpuCacheSizeBytes = atoi(FLAGS_gpuCacheSize[0]); |
| 1676 | gGpuCacheSizeCount = atoi(FLAGS_gpuCacheSize[1]); |
| 1677 | } else { |
| 1678 | gGpuCacheSizeBytes = DEFAULT_CACHE_VALUE; |
| 1679 | gGpuCacheSizeCount = DEFAULT_CACHE_VALUE; |
| 1680 | } |
| 1681 | #endif |
| 1682 | |
| 1683 | SkTDArray<SkScalar> tileGridReplayScales; |
| 1684 | *tileGridReplayScales.append() = SK_Scalar1; // By default only test at scale 1.0 |
| 1685 | if (FLAGS_tileGridReplayScales.count() > 0) { |
| 1686 | tileGridReplayScales.reset(); |
| 1687 | for (int i = 0; i < FLAGS_tileGridReplayScales.count(); i++) { |
| 1688 | double val = atof(FLAGS_tileGridReplayScales[i]); |
| 1689 | if (0 < val) { |
| 1690 | *tileGridReplayScales.append() = SkDoubleToScalar(val); |
| 1691 | } |
| 1692 | } |
| 1693 | if (0 == tileGridReplayScales.count()) { |
| 1694 | // Should have at least one scale |
| 1695 | gm_fprintf(stderr, "--tileGridReplayScales requires at least one scale.\n"); |
| 1696 | return -1; |
| 1697 | } |
| 1698 | } |
| 1699 | |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1700 | if (!userConfig) { |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1701 | // if no config is specified by user, add the defaults |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1702 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1703 | if (gRec[i].fRunByDefault) { |
| 1704 | *configs.append() = i; |
| 1705 | } |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1706 | } |
| 1707 | } |
reed@google.com | fb2cd42 | 2013-01-04 14:43:03 +0000 | [diff] [blame] | 1708 | // now remove any explicitly excluded configs |
| 1709 | for (int i = 0; i < excludeConfigs.count(); ++i) { |
| 1710 | int index = configs.find(excludeConfigs[i]); |
| 1711 | if (index >= 0) { |
| 1712 | configs.remove(index); |
| 1713 | // now assert that there was only one copy in configs[] |
| 1714 | SkASSERT(configs.find(excludeConfigs[i]) < 0); |
| 1715 | } |
| 1716 | } |
| 1717 | |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1718 | #if SK_SUPPORT_GPU |
| 1719 | GrContextFactory* grFactory = new GrContextFactory; |
| 1720 | for (int i = 0; i < configs.count(); ++i) { |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1721 | size_t index = configs[i]; |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1722 | if (kGPU_Backend == gRec[index].fBackend) { |
| 1723 | GrContext* ctx = grFactory->get(gRec[index].fGLContextType); |
| 1724 | if (NULL == ctx) { |
epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 1725 | gm_fprintf(stderr, "GrContext could not be created for config %s." |
| 1726 | " Config will be skipped.\n", gRec[index].fName); |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1727 | configs.remove(i); |
| 1728 | --i; |
| 1729 | } |
| 1730 | if (gRec[index].fSampleCnt > ctx->getMaxSampleCount()) { |
epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 1731 | gm_fprintf(stderr, "Sample count (%d) of config %s is not supported." |
| 1732 | " Config will be skipped.\n", gRec[index].fSampleCnt, gRec[index].fName); |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1733 | configs.remove(i); |
| 1734 | --i; |
| 1735 | } |
| 1736 | } |
| 1737 | } |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1738 | #else |
| 1739 | GrContextFactory* grFactory = NULL; |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1740 | #endif |
| 1741 | |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1742 | if (FLAGS_resourcePath.count() == 1) { |
| 1743 | GM::SetResourcePath(FLAGS_resourcePath[0]); |
| 1744 | } |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 1745 | |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1746 | if (FLAGS_readPath.count() == 1) { |
| 1747 | const char* readPath = FLAGS_readPath[0]; |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1748 | if (!sk_exists(readPath)) { |
epoger@google.com | 5efdd0c | 2013-03-13 14:18:40 +0000 | [diff] [blame] | 1749 | gm_fprintf(stderr, "readPath %s does not exist!\n", readPath); |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1750 | return -1; |
| 1751 | } |
| 1752 | if (sk_isdir(readPath)) { |
epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 1753 | if (FLAGS_verbose) { |
| 1754 | gm_fprintf(stdout, "reading from %s\n", readPath); |
| 1755 | } |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1756 | gmmain.fExpectationsSource.reset(SkNEW_ARGS( |
epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 1757 | IndividualImageExpectationsSource, (readPath))); |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1758 | } else { |
epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 1759 | if (FLAGS_verbose) { |
| 1760 | gm_fprintf(stdout, "reading expectations from JSON summary file %s\n", readPath); |
| 1761 | } |
epoger@google.com | d271d24 | 2013-02-13 18:14:48 +0000 | [diff] [blame] | 1762 | gmmain.fExpectationsSource.reset(SkNEW_ARGS( |
| 1763 | JsonExpectationsSource, (readPath))); |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1764 | } |
chudy@google.com | f32f6e8 | 2012-07-12 15:42:37 +0000 | [diff] [blame] | 1765 | } |
epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 1766 | if (FLAGS_verbose) { |
| 1767 | if (FLAGS_writePath.count() == 1) { |
| 1768 | gm_fprintf(stdout, "writing to %s\n", FLAGS_writePath[0]); |
| 1769 | } |
| 1770 | if (FLAGS_writePicturePath.count() == 1) { |
| 1771 | gm_fprintf(stdout, "writing pictures to %s\n", FLAGS_writePicturePath[0]); |
| 1772 | } |
| 1773 | if (FLAGS_resourcePath.count() == 1) { |
| 1774 | gm_fprintf(stdout, "reading resources from %s\n", FLAGS_resourcePath[0]); |
| 1775 | } |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 1776 | } |
| 1777 | |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1778 | if (moduloDivisor <= 0) { |
| 1779 | moduloRemainder = -1; |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1780 | } |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1781 | if (moduloRemainder < 0 || moduloRemainder >= moduloDivisor) { |
| 1782 | moduloRemainder = -1; |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1783 | } |
| 1784 | |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 1785 | int gmsRun = 0; |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1786 | int gmIndex = -1; |
| 1787 | SkString moduloStr; |
| 1788 | |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 1789 | // If we will be writing out files, prepare subdirectories. |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1790 | if (FLAGS_writePath.count() == 1) { |
| 1791 | if (!sk_mkdir(FLAGS_writePath[0])) { |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 1792 | return -1; |
| 1793 | } |
| 1794 | if (gmmain.fUseFileHierarchy) { |
| 1795 | for (int i = 0; i < configs.count(); i++) { |
| 1796 | ConfigData config = gRec[configs[i]]; |
| 1797 | SkString subdir; |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1798 | subdir.appendf("%s%c%s", FLAGS_writePath[0], SkPATH_SEPARATOR, |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 1799 | config.fName); |
| 1800 | if (!sk_mkdir(subdir.c_str())) { |
| 1801 | return -1; |
| 1802 | } |
| 1803 | } |
| 1804 | } |
| 1805 | } |
| 1806 | |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1807 | Iter iter; |
| 1808 | GM* gm; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1809 | while ((gm = iter.next()) != NULL) { |
scroggo@google.com | 7fd2d70 | 2013-04-16 19:11:14 +0000 | [diff] [blame] | 1810 | SkAutoTDelete<GM> adgm(gm); |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1811 | ++gmIndex; |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1812 | if (moduloRemainder >= 0) { |
| 1813 | if ((gmIndex % moduloDivisor) != moduloRemainder) { |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1814 | continue; |
| 1815 | } |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1816 | moduloStr.printf("[%d.%d] ", gmIndex, moduloDivisor); |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1817 | } |
| 1818 | |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 1819 | const char* shortName = gm->shortName(); |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1820 | if (skip_name(FLAGS_match, shortName)) { |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 1821 | continue; |
| 1822 | } |
| 1823 | |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 1824 | gmsRun++; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1825 | SkISize size = gm->getISize(); |
epoger@google.com | bcbf5aa | 2013-04-12 02:11:54 +0000 | [diff] [blame] | 1826 | gm_fprintf(stdout, "%sdrawing... %s [%d %d]\n", moduloStr.c_str(), shortName, |
| 1827 | size.width(), size.height()); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1828 | |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 1829 | run_multiple_configs(gmmain, gm, configs, grFactory); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1830 | |
| 1831 | SkBitmap comparisonBitmap; |
| 1832 | const ConfigData compareConfig = |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1833 | { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "comparison", false }; |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 1834 | gmmain.generate_image(gm, compareConfig, NULL, &comparisonBitmap, false); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1835 | |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1836 | // TODO(epoger): only run this if gmmain.generate_image() succeeded? |
| 1837 | // Otherwise, what are we comparing against? |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 1838 | run_multiple_modes(gmmain, gm, compareConfig, comparisonBitmap, tileGridReplayScales); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1839 | } |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 1840 | |
| 1841 | SkTArray<SkString> modes; |
| 1842 | gmmain.GetRenderModesEncountered(modes); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1843 | bool reportError = false; |
| 1844 | if (gmmain.NumSignificantErrors() > 0) { |
| 1845 | reportError = true; |
| 1846 | } |
epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame] | 1847 | int expectedNumberOfTests = gmsRun * (configs.count() + modes.count()); |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 1848 | |
| 1849 | // Output summary to stdout. |
epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame] | 1850 | if (FLAGS_verbose) { |
| 1851 | gm_fprintf(stdout, "Ran %d GMs\n", gmsRun); |
| 1852 | gm_fprintf(stdout, "... over %2d configs [%s]\n", configs.count(), |
| 1853 | list_all_config_names(configs).c_str()); |
| 1854 | gm_fprintf(stdout, "... and %2d modes [%s]\n", modes.count(), list_all(modes).c_str()); |
| 1855 | gm_fprintf(stdout, "... so there should be a total of %d tests.\n", expectedNumberOfTests); |
| 1856 | } |
| 1857 | gmmain.ListErrors(FLAGS_verbose); |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 1858 | |
epoger@google.com | 07947d9 | 2013-04-11 15:41:02 +0000 | [diff] [blame] | 1859 | // TODO(epoger): Enable this check for Android, too, once we resolve |
| 1860 | // https://code.google.com/p/skia/issues/detail?id=1222 |
| 1861 | // ('GM is unexpectedly skipping tests on Android') |
| 1862 | #ifndef SK_BUILD_FOR_ANDROID |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1863 | if (expectedNumberOfTests != gmmain.fTestsRun) { |
| 1864 | gm_fprintf(stderr, "expected %d tests, but ran or skipped %d tests\n", |
| 1865 | expectedNumberOfTests, gmmain.fTestsRun); |
| 1866 | reportError = true; |
| 1867 | } |
| 1868 | #endif |
| 1869 | |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1870 | if (FLAGS_writeJsonSummaryPath.count() == 1) { |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 1871 | Json::Value actualResults; |
| 1872 | actualResults[kJsonKey_ActualResults_Failed] = |
| 1873 | gmmain.fJsonActualResults_Failed; |
| 1874 | actualResults[kJsonKey_ActualResults_FailureIgnored] = |
| 1875 | gmmain.fJsonActualResults_FailureIgnored; |
epoger@google.com | 9c56a8d | 2012-12-20 18:34:29 +0000 | [diff] [blame] | 1876 | actualResults[kJsonKey_ActualResults_NoComparison] = |
| 1877 | gmmain.fJsonActualResults_NoComparison; |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 1878 | actualResults[kJsonKey_ActualResults_Succeeded] = |
| 1879 | gmmain.fJsonActualResults_Succeeded; |
| 1880 | Json::Value root; |
| 1881 | root[kJsonKey_ActualResults] = actualResults; |
| 1882 | root[kJsonKey_ExpectedResults] = gmmain.fJsonExpectedResults; |
| 1883 | std::string jsonStdString = root.toStyledString(); |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1884 | SkFILEWStream stream(FLAGS_writeJsonSummaryPath[0]); |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 1885 | stream.write(jsonStdString.c_str(), jsonStdString.length()); |
| 1886 | } |
| 1887 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1888 | #if SK_SUPPORT_GPU |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 1889 | |
robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 1890 | #if GR_CACHE_STATS |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 1891 | for (int i = 0; i < configs.count(); i++) { |
| 1892 | ConfigData config = gRec[configs[i]]; |
| 1893 | |
epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 1894 | if (FLAGS_verbose && (kGPU_Backend == config.fBackend)) { |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 1895 | GrContext* gr = grFactory->get(config.fGLContextType); |
| 1896 | |
epoger@google.com | 5efdd0c | 2013-03-13 14:18:40 +0000 | [diff] [blame] | 1897 | gm_fprintf(stdout, "config: %s %x\n", config.fName, gr); |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 1898 | gr->printCacheStats(); |
| 1899 | } |
| 1900 | } |
| 1901 | #endif |
| 1902 | |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 1903 | delete grFactory; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1904 | #endif |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 1905 | SkGraphics::Term(); |
| 1906 | |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1907 | return (reportError) ? -1 : 0; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1908 | } |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 1909 | |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1910 | void GMMain::installFilter(SkCanvas* canvas) { |
| 1911 | if (FLAGS_forceBWtext) { |
| 1912 | canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); |
| 1913 | } |
| 1914 | } |
| 1915 | |
borenet@google.com | 7158e6a | 2012-11-01 17:43:44 +0000 | [diff] [blame] | 1916 | #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 1917 | int main(int argc, char * const argv[]) { |
| 1918 | return tool_main(argc, (char**) argv); |
| 1919 | } |
| 1920 | #endif |