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