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