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