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