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" |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 21 | #include "SkColorPriv.h" |
scroggo@google.com | d9ba9a0 | 2013-03-21 19:43:15 +0000 | [diff] [blame] | 22 | #include "SkCommandLineFlags.h" |
reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 23 | #include "SkData.h" |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 24 | #include "SkDeferredCanvas.h" |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 25 | #include "SkDevice.h" |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 26 | #include "SkDocument.h" |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 27 | #include "SkDrawFilter.h" |
commit-bot@chromium.org | c41295d | 2013-06-18 20:06:36 +0000 | [diff] [blame] | 28 | #include "SkForceLinking.h" |
scroggo@google.com | 5af9b20 | 2012-06-04 17:17:36 +0000 | [diff] [blame] | 29 | #include "SkGPipe.h" |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 30 | #include "SkGraphics.h" |
| 31 | #include "SkImageDecoder.h" |
| 32 | #include "SkImageEncoder.h" |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 33 | #include "SkJSONCPP.h" |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 34 | #include "SkOSFile.h" |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 35 | #include "SkPDFRasterizer.h" |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 36 | #include "SkPicture.h" |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 37 | #include "SkRefCnt.h" |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 38 | #include "SkScalar.h" |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 39 | #include "SkStream.h" |
epoger@google.com | f711f32 | 2013-10-18 14:55:47 +0000 | [diff] [blame] | 40 | #include "SkString.h" |
bsalomon@google.com | 2a48c3a | 2012-08-03 14:54:45 +0000 | [diff] [blame] | 41 | #include "SkTArray.h" |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 42 | #include "SkTDict.h" |
junov@chromium.org | 3cb834b | 2012-12-13 16:39:53 +0000 | [diff] [blame] | 43 | #include "SkTileGridPicture.h" |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 44 | #include "SamplePipeControllers.h" |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 45 | |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 46 | #ifdef SK_DEBUG |
| 47 | static const bool kDebugOnly = true; |
| 48 | #else |
| 49 | static const bool kDebugOnly = false; |
| 50 | #endif |
| 51 | |
epoger@google.com | ed5eb4e | 2013-07-23 17:56:20 +0000 | [diff] [blame] | 52 | __SK_FORCE_IMAGE_DECODER_LINKING; |
| 53 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 54 | #if SK_SUPPORT_GPU |
| 55 | #include "GrContextFactory.h" |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 56 | #include "SkGpuDevice.h" |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 57 | typedef GrContextFactory::GLContextType GLContextType; |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 58 | #define DEFAULT_CACHE_VALUE -1 |
| 59 | static int gGpuCacheSizeBytes; |
| 60 | static int gGpuCacheSizeCount; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 61 | #else |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 62 | class GrContextFactory; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 63 | class GrContext; |
bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 64 | class GrSurface; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 65 | typedef int GLContextType; |
| 66 | #endif |
| 67 | |
epoger@google.com | 76c913d | 2013-04-26 15:06:44 +0000 | [diff] [blame] | 68 | #define DEBUGFAIL_SEE_STDERR SkDEBUGFAIL("see stderr for message") |
| 69 | |
reed@google.com | 8923c6c | 2011-11-08 14:59:38 +0000 | [diff] [blame] | 70 | extern bool gSkSuppressFontCachePurgeSpew; |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 71 | DECLARE_bool(useDocumentInsteadOfDevice); |
reed@google.com | 8923c6c | 2011-11-08 14:59:38 +0000 | [diff] [blame] | 72 | |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 73 | #ifdef SK_SUPPORT_PDF |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 74 | #include "SkPDFDevice.h" |
| 75 | #include "SkPDFDocument.h" |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 76 | #endif |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 77 | |
epoger@google.com | e3cc2eb | 2012-01-18 20:11:13 +0000 | [diff] [blame] | 78 | // Until we resolve http://code.google.com/p/skia/issues/detail?id=455 , |
| 79 | // stop writing out XPS-format image baselines in gm. |
| 80 | #undef SK_SUPPORT_XPS |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 81 | #ifdef SK_SUPPORT_XPS |
| 82 | #include "SkXPSDevice.h" |
| 83 | #endif |
| 84 | |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 85 | #ifdef SK_BUILD_FOR_MAC |
| 86 | #include "SkCGUtils.h" |
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 | |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 161 | struct PDFRasterizerData { |
| 162 | bool (*fRasterizerFunction)(SkStream*, SkBitmap*); |
| 163 | const char* fName; |
| 164 | bool fRunByDefault; |
| 165 | }; |
| 166 | |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 167 | class BWTextDrawFilter : public SkDrawFilter { |
| 168 | public: |
reed@google.com | 971aca7 | 2012-11-26 20:26:54 +0000 | [diff] [blame] | 169 | virtual bool filter(SkPaint*, Type) SK_OVERRIDE; |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 170 | }; |
reed@google.com | 971aca7 | 2012-11-26 20:26:54 +0000 | [diff] [blame] | 171 | bool BWTextDrawFilter::filter(SkPaint* p, Type t) { |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 172 | if (kText_Type == t) { |
| 173 | p->setAntiAlias(false); |
| 174 | } |
reed@google.com | 971aca7 | 2012-11-26 20:26:54 +0000 | [diff] [blame] | 175 | return true; |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 176 | } |
| 177 | |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 178 | struct PipeFlagComboData { |
| 179 | const char* name; |
| 180 | uint32_t flags; |
| 181 | }; |
| 182 | |
| 183 | static PipeFlagComboData gPipeWritingFlagCombos[] = { |
| 184 | { "", 0 }, |
| 185 | { " cross-process", SkGPipeWriter::kCrossProcess_Flag }, |
scroggo | b3c0f48 | 2012-07-02 19:07:57 +0000 | [diff] [blame] | 186 | { " cross-process, shared address", SkGPipeWriter::kCrossProcess_Flag |
scroggo@google.com | 15011ee | 2012-07-26 20:03:32 +0000 | [diff] [blame] | 187 | | SkGPipeWriter::kSharedAddressSpace_Flag } |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 188 | }; |
| 189 | |
commit-bot@chromium.org | 608ea65 | 2013-10-03 19:29:21 +0000 | [diff] [blame] | 190 | static SkData* encode_to_dct_data(size_t* pixelRefOffset, const SkBitmap& bitmap); |
edisonn@google.com | 73a7ea3 | 2013-11-11 20:55:15 +0000 | [diff] [blame] | 191 | DECLARE_int32(pdfRasterDpi); |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 192 | |
epoger@google.com | 5079d2c | 2013-04-12 14:11:21 +0000 | [diff] [blame] | 193 | const static ErrorCombination kDefaultIgnorableErrorTypes = ErrorCombination() |
| 194 | .plus(kMissingExpectations_ErrorType) |
| 195 | .plus(kIntentionallySkipped_ErrorType); |
| 196 | |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 197 | class GMMain { |
| 198 | public: |
epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 199 | GMMain() : fUseFileHierarchy(false), fWriteChecksumBasedFilenames(false), |
| 200 | fIgnorableErrorTypes(kDefaultIgnorableErrorTypes), |
epoger@google.com | 5f99545 | 2013-06-21 18:16:47 +0000 | [diff] [blame] | 201 | fMismatchPath(NULL), fMissingExpectationsPath(NULL), fTestsRun(0), |
| 202 | fRenderModesEncountered(1) {} |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 203 | |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 204 | /** |
| 205 | * Assemble shortNamePlusConfig from (surprise!) shortName and configName. |
| 206 | * |
| 207 | * The method for doing so depends on whether we are using hierarchical naming. |
| 208 | * For example, shortName "selftest1" and configName "8888" could be assembled into |
| 209 | * either "selftest1_8888" or "8888/selftest1". |
| 210 | */ |
| 211 | SkString make_shortname_plus_config(const char *shortName, const char *configName) { |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 212 | SkString name; |
epoger@google.com | 57f7abc | 2012-11-13 03:41:55 +0000 | [diff] [blame] | 213 | if (0 == strlen(configName)) { |
| 214 | name.append(shortName); |
| 215 | } else if (fUseFileHierarchy) { |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 216 | name.appendf("%s%c%s", configName, SkPATH_SEPARATOR, shortName); |
| 217 | } else { |
| 218 | name.appendf("%s_%s", shortName, configName); |
| 219 | } |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 220 | return name; |
| 221 | } |
| 222 | |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 223 | /** |
| 224 | * Assemble filename, suitable for writing out the results of a particular test. |
| 225 | */ |
| 226 | SkString make_filename(const char *path, |
| 227 | const char *shortName, |
| 228 | const char *configName, |
| 229 | const char *renderModeDescriptor, |
| 230 | const char *suffix) { |
| 231 | SkString filename = make_shortname_plus_config(shortName, configName); |
| 232 | filename.append(renderModeDescriptor); |
| 233 | filename.appendUnichar('.'); |
| 234 | filename.append(suffix); |
scroggo@google.com | ccd7afb | 2013-05-28 16:45:07 +0000 | [diff] [blame] | 235 | return SkOSPath::SkPathJoin(path, filename.c_str()); |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 236 | } |
| 237 | |
epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 238 | /** |
| 239 | * Assemble filename suitable for writing out an SkBitmap. |
| 240 | */ |
| 241 | SkString make_bitmap_filename(const char *path, |
| 242 | const char *shortName, |
| 243 | const char *configName, |
| 244 | const char *renderModeDescriptor, |
| 245 | const GmResultDigest &bitmapDigest) { |
| 246 | if (fWriteChecksumBasedFilenames) { |
| 247 | SkString filename; |
| 248 | filename.append(bitmapDigest.getHashType()); |
| 249 | filename.appendUnichar('_'); |
| 250 | filename.append(shortName); |
| 251 | filename.appendUnichar('_'); |
| 252 | filename.append(bitmapDigest.getDigestValue()); |
| 253 | filename.appendUnichar('.'); |
| 254 | filename.append(kPNG_FileExtension); |
| 255 | return SkOSPath::SkPathJoin(path, filename.c_str()); |
| 256 | } else { |
| 257 | return make_filename(path, shortName, configName, renderModeDescriptor, |
| 258 | kPNG_FileExtension); |
| 259 | } |
| 260 | } |
| 261 | |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 262 | /* since PNG insists on unpremultiplying our alpha, we take no |
| 263 | precision chances and force all pixels to be 100% opaque, |
| 264 | otherwise on compare we may not get a perfect match. |
| 265 | */ |
| 266 | static void force_all_opaque(const SkBitmap& bitmap) { |
| 267 | SkBitmap::Config config = bitmap.config(); |
| 268 | switch (config) { |
| 269 | case SkBitmap::kARGB_8888_Config: |
| 270 | force_all_opaque_8888(bitmap); |
| 271 | break; |
| 272 | case SkBitmap::kRGB_565_Config: |
| 273 | // nothing to do here; 565 bitmaps are inherently opaque |
| 274 | break; |
| 275 | default: |
epoger@google.com | 5efdd0c | 2013-03-13 14:18:40 +0000 | [diff] [blame] | 276 | gm_fprintf(stderr, "unsupported bitmap config %d\n", config); |
| 277 | DEBUGFAIL_SEE_STDERR; |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | |
| 281 | static void force_all_opaque_8888(const SkBitmap& bitmap) { |
| 282 | SkAutoLockPixels lock(bitmap); |
| 283 | for (int y = 0; y < bitmap.height(); y++) { |
| 284 | for (int x = 0; x < bitmap.width(); x++) { |
| 285 | *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT); |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 290 | static ErrorCombination write_bitmap(const SkString& path, const SkBitmap& bitmap) { |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 291 | // TODO(epoger): Now that we have removed force_all_opaque() |
| 292 | // from this method, we should be able to get rid of the |
| 293 | // transformation to 8888 format also. |
| 294 | SkBitmap copy; |
| 295 | bitmap.copyTo(©, SkBitmap::kARGB_8888_Config); |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 296 | if (!SkImageEncoder::EncodeFile(path.c_str(), copy, |
| 297 | SkImageEncoder::kPNG_Type, |
| 298 | 100)) { |
| 299 | gm_fprintf(stderr, "FAILED to write bitmap: %s\n", path.c_str()); |
| 300 | return ErrorCombination(kWritingReferenceImage_ErrorType); |
| 301 | } |
| 302 | return kEmpty_ErrorCombination; |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 303 | } |
| 304 | |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 305 | /** |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 306 | * Add all render modes encountered thus far to the "modes" array. |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 307 | */ |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 308 | void GetRenderModesEncountered(SkTArray<SkString> &modes) { |
| 309 | SkTDict<int>::Iter iter(this->fRenderModesEncountered); |
| 310 | const char* mode; |
| 311 | while ((mode = iter.next(NULL)) != NULL) { |
| 312 | SkString modeAsString = SkString(mode); |
| 313 | // TODO(epoger): It seems a bit silly that all of these modes were |
| 314 | // recorded with a leading "-" which we have to remove here |
| 315 | // (except for mode "", which means plain old original mode). |
| 316 | // But that's how renderModeDescriptor has been passed into |
| 317 | // compare_test_results_to_reference_bitmap() historically, |
| 318 | // and changing that now may affect other parts of our code. |
| 319 | if (modeAsString.startsWith("-")) { |
| 320 | modeAsString.remove(0, 1); |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 321 | } |
commit-bot@chromium.org | 8519548 | 2014-01-13 18:27:59 +0000 | [diff] [blame] | 322 | modes.push_back(modeAsString); |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | |
| 326 | /** |
epoger@google.com | 3a882dd | 2013-10-07 18:55:09 +0000 | [diff] [blame] | 327 | * Returns true if failures on this test should be ignored. |
| 328 | */ |
commit-bot@chromium.org | 3e62ebf | 2014-01-14 02:54:11 +0000 | [diff] [blame] | 329 | bool ShouldIgnoreTest(const char *name) const { |
| 330 | for (int i = 0; i < fIgnorableTestNames.count(); i++) { |
| 331 | if (fIgnorableTestNames[i].equals(name)) { |
epoger@google.com | 3a882dd | 2013-10-07 18:55:09 +0000 | [diff] [blame] | 332 | return true; |
| 333 | } |
| 334 | } |
| 335 | return false; |
| 336 | } |
| 337 | |
| 338 | /** |
commit-bot@chromium.org | 8519548 | 2014-01-13 18:27:59 +0000 | [diff] [blame] | 339 | * Calls RecordTestResults to record that we skipped a test. |
| 340 | * |
| 341 | * Depending on the backend, this may mean that we skipped a single rendermode, or all |
| 342 | * rendermodes; see http://skbug.com/1994 and https://codereview.chromium.org/129203002/ |
| 343 | */ |
| 344 | void RecordSkippedTest(const SkString& shortNamePlusConfig, |
| 345 | const char renderModeDescriptor [], Backend backend) { |
| 346 | if (kRaster_Backend == backend) { |
| 347 | // Skipping a test on kRaster_Backend means that we will skip ALL renderModes |
| 348 | // (as opposed to other backends, on which we only run the default renderMode). |
| 349 | // |
| 350 | // We cannot call RecordTestResults yet, because we won't know the full set of |
| 351 | // renderModes until we have run all tests. |
| 352 | fTestsSkippedOnAllRenderModes.push_back(shortNamePlusConfig); |
| 353 | } else { |
| 354 | this->RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, |
| 355 | renderModeDescriptor); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | /** |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 360 | * Records the results of this test in fTestsRun and fFailedTests. |
| 361 | * |
| 362 | * We even record successes, and errors that we regard as |
| 363 | * "ignorable"; we can filter them out later. |
| 364 | */ |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 365 | void RecordTestResults(const ErrorCombination& errorCombination, |
| 366 | const SkString& shortNamePlusConfig, |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 367 | const char renderModeDescriptor []) { |
| 368 | // Things to do regardless of errorCombination. |
| 369 | fTestsRun++; |
| 370 | int renderModeCount = 0; |
| 371 | this->fRenderModesEncountered.find(renderModeDescriptor, &renderModeCount); |
| 372 | renderModeCount++; |
| 373 | this->fRenderModesEncountered.set(renderModeDescriptor, renderModeCount); |
| 374 | |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 375 | if (errorCombination.isEmpty()) { |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 376 | return; |
epoger@google.com | eb06636 | 2013-03-08 09:39:36 +0000 | [diff] [blame] | 377 | } |
| 378 | |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 379 | // Things to do only if there is some error condition. |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 380 | SkString fullName = shortNamePlusConfig; |
epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 381 | fullName.append(renderModeDescriptor); |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 382 | for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) { |
| 383 | ErrorType type = static_cast<ErrorType>(typeInt); |
| 384 | if (errorCombination.includes(type)) { |
| 385 | fFailedTests[type].push_back(fullName); |
epoger@google.com | f60494b | 2013-04-03 17:02:53 +0000 | [diff] [blame] | 386 | } |
epoger@google.com | f60494b | 2013-04-03 17:02:53 +0000 | [diff] [blame] | 387 | } |
epoger@google.com | f60494b | 2013-04-03 17:02:53 +0000 | [diff] [blame] | 388 | } |
| 389 | |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 390 | /** |
| 391 | * Return the number of significant (non-ignorable) errors we have |
| 392 | * encountered so far. |
| 393 | */ |
| 394 | int NumSignificantErrors() { |
| 395 | int significantErrors = 0; |
| 396 | for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) { |
| 397 | ErrorType type = static_cast<ErrorType>(typeInt); |
epoger@google.com | 5079d2c | 2013-04-12 14:11:21 +0000 | [diff] [blame] | 398 | if (!fIgnorableErrorTypes.includes(type)) { |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 399 | significantErrors += fFailedTests[type].count(); |
| 400 | } |
| 401 | } |
| 402 | return significantErrors; |
| 403 | } |
| 404 | |
| 405 | /** |
epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame] | 406 | * Display the summary of results with this ErrorType. |
| 407 | * |
| 408 | * @param type which ErrorType |
| 409 | * @param verbose whether to be all verbose about it |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 410 | */ |
epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame] | 411 | void DisplayResultTypeSummary(ErrorType type, bool verbose) { |
epoger@google.com | 5079d2c | 2013-04-12 14:11:21 +0000 | [diff] [blame] | 412 | bool isIgnorableType = fIgnorableErrorTypes.includes(type); |
epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame] | 413 | |
| 414 | SkString line; |
| 415 | if (isIgnorableType) { |
| 416 | line.append("[ ] "); |
| 417 | } else { |
| 418 | line.append("[*] "); |
| 419 | } |
| 420 | |
| 421 | SkTArray<SkString> *failedTestsOfThisType = &fFailedTests[type]; |
| 422 | int count = failedTestsOfThisType->count(); |
| 423 | line.appendf("%d %s", count, getErrorTypeName(type)); |
| 424 | if (!isIgnorableType || verbose) { |
| 425 | line.append(":"); |
| 426 | for (int i = 0; i < count; ++i) { |
| 427 | line.append(" "); |
| 428 | line.append((*failedTestsOfThisType)[i]); |
| 429 | } |
| 430 | } |
| 431 | gm_fprintf(stdout, "%s\n", line.c_str()); |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * List contents of fFailedTests to stdout. |
| 436 | * |
| 437 | * @param verbose whether to be all verbose about it |
| 438 | */ |
| 439 | void ListErrors(bool verbose) { |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 440 | // First, print a single summary line. |
| 441 | SkString summary; |
| 442 | summary.appendf("Ran %d tests:", fTestsRun); |
| 443 | for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) { |
| 444 | ErrorType type = static_cast<ErrorType>(typeInt); |
| 445 | summary.appendf(" %s=%d", getErrorTypeName(type), fFailedTests[type].count()); |
| 446 | } |
| 447 | gm_fprintf(stdout, "%s\n", summary.c_str()); |
| 448 | |
| 449 | // Now, for each failure type, list the tests that failed that way. |
| 450 | for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) { |
epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame] | 451 | this->DisplayResultTypeSummary(static_cast<ErrorType>(typeInt), verbose); |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 452 | } |
| 453 | gm_fprintf(stdout, "(results marked with [*] will cause nonzero return value)\n"); |
| 454 | } |
| 455 | |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 456 | static ErrorCombination write_document(const SkString& path, SkStreamAsset* asset) { |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 457 | SkFILEWStream stream(path.c_str()); |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 458 | if (!stream.writeStream(asset, asset->getLength())) { |
| 459 | gm_fprintf(stderr, "FAILED to write document: %s\n", path.c_str()); |
| 460 | return ErrorCombination(kWritingReferenceImage_ErrorType); |
| 461 | } |
| 462 | return kEmpty_ErrorCombination; |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 463 | } |
| 464 | |
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 | * Prepare an SkBitmap to render a GM into. |
| 467 | * |
| 468 | * After you've rendered the GM into the SkBitmap, you must call |
| 469 | * complete_bitmap()! |
| 470 | * |
| 471 | * @todo thudson 22 April 2011 - could refactor this to take in |
| 472 | * a factory to generate the context, always call readPixels() |
| 473 | * (logically a noop for rasters, if wasted time), and thus collapse the |
| 474 | * GPU special case and also let this be used for SkPicture testing. |
| 475 | */ |
| 476 | static void setup_bitmap(const ConfigData& gRec, SkISize& size, |
| 477 | SkBitmap* bitmap) { |
reed@google.com | eb9a46c | 2014-01-25 16:46:20 +0000 | [diff] [blame] | 478 | bitmap->allocConfigPixels(gRec.fConfig, size.width(), size.height()); |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 479 | bitmap->eraseColor(SK_ColorTRANSPARENT); |
| 480 | } |
| 481 | |
| 482 | /** |
| 483 | * Any finalization steps we need to perform on the SkBitmap after |
| 484 | * we have rendered the GM into it. |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 485 | * |
| 486 | * It's too bad that we are throwing away alpha channel data |
| 487 | * we could otherwise be examining, but this had always been happening |
| 488 | * before... it was buried within the compare() method at |
| 489 | * https://code.google.com/p/skia/source/browse/trunk/gm/gmmain.cpp?r=7289#305 . |
| 490 | * |
| 491 | * Apparently we need this, at least for bitmaps that are either: |
| 492 | * (a) destined to be written out as PNG files, or |
| 493 | * (b) compared against bitmaps read in from PNG files |
| 494 | * for the reasons described just above the force_all_opaque() method. |
| 495 | * |
| 496 | * Neglecting to do this led to the difficult-to-diagnose |
| 497 | * http://code.google.com/p/skia/issues/detail?id=1079 ('gm generating |
| 498 | * spurious pixel_error messages as of r7258') |
| 499 | * |
| 500 | * TODO(epoger): Come up with a better solution that allows us to |
| 501 | * compare full pixel data, including alpha channel, while still being |
| 502 | * robust in the face of transformations to/from PNG files. |
| 503 | * Options include: |
| 504 | * |
| 505 | * 1. Continue to call force_all_opaque(), but ONLY for bitmaps that |
| 506 | * will be written to, or compared against, PNG files. |
| 507 | * PRO: Preserve/compare alpha channel info for the non-PNG cases |
| 508 | * (comparing different renderModes in-memory) |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 509 | * 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] | 510 | * different than those for the PNG-compared cases, and in the |
| 511 | * case of a failed renderMode comparison, how would we write the |
| 512 | * image to disk for examination? |
| 513 | * |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 514 | * 2. Always compute image hash digests from PNG format (either |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 515 | * directly from the the bytes of a PNG file, or capturing the |
| 516 | * bytes we would have written to disk if we were writing the |
| 517 | * bitmap out as a PNG). |
| 518 | * PRO: I think this would allow us to never force opaque, and to |
| 519 | * the extent that alpha channel data can be preserved in a PNG |
| 520 | * file, we could observe it. |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 521 | * 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] | 522 | * from the source PNG (we can't compute it from the bitmap we |
| 523 | * read out of the PNG, because we will have already premultiplied |
| 524 | * the alpha). |
| 525 | * 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] | 526 | * its hash digest. (Although we're wasting lots of effort already |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 527 | * calling force_all_opaque().) |
| 528 | * |
| 529 | * 3. Make the alpha premultiply/unpremultiply routines 100% consistent, |
| 530 | * so we can transform images back and forth without fear of off-by-one |
| 531 | * errors. |
| 532 | * CON: Math is hard. |
| 533 | * |
| 534 | * 4. Perform a "close enough" comparison of bitmaps (+/- 1 bit in each |
| 535 | * channel), rather than demanding absolute equality. |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 536 | * CON: Can't do this with hash digests. |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 537 | */ |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 538 | static void complete_bitmap(SkBitmap* bitmap) { |
| 539 | force_all_opaque(*bitmap); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 540 | } |
| 541 | |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 542 | static void installFilter(SkCanvas* canvas); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 543 | |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 544 | static void invokeGM(GM* gm, SkCanvas* canvas, bool isPDF, bool isDeferred) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 545 | SkAutoCanvasRestore acr(canvas, true); |
| 546 | |
| 547 | if (!isPDF) { |
| 548 | canvas->concat(gm->getInitialTransform()); |
| 549 | } |
| 550 | installFilter(canvas); |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 551 | gm->setCanvasIsDeferred(isDeferred); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 552 | gm->draw(canvas); |
| 553 | canvas->setDrawFilter(NULL); |
| 554 | } |
| 555 | |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 556 | static ErrorCombination generate_image(GM* gm, const ConfigData& gRec, |
bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 557 | GrSurface* gpuTarget, |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 558 | SkBitmap* bitmap, |
| 559 | bool deferred) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 560 | SkISize size (gm->getISize()); |
| 561 | setup_bitmap(gRec, size, bitmap); |
| 562 | |
| 563 | SkAutoTUnref<SkCanvas> canvas; |
| 564 | |
| 565 | if (gRec.fBackend == kRaster_Backend) { |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 566 | SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (*bitmap))); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 567 | if (deferred) { |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 568 | canvas.reset(SkDeferredCanvas::Create(device)); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 569 | } else { |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 570 | canvas.reset(SkNEW_ARGS(SkCanvas, (device))); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 571 | } |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 572 | invokeGM(gm, canvas, false, deferred); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 573 | canvas->flush(); |
| 574 | } |
| 575 | #if SK_SUPPORT_GPU |
| 576 | else { // GPU |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 577 | SkAutoTUnref<SkBaseDevice> device(SkGpuDevice::Create(gpuTarget)); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 578 | if (deferred) { |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 579 | canvas.reset(SkDeferredCanvas::Create(device)); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 580 | } else { |
junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 581 | canvas.reset(SkNEW_ARGS(SkCanvas, (device))); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 582 | } |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 583 | invokeGM(gm, canvas, false, deferred); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 584 | // the device is as large as the current rendertarget, so |
| 585 | // we explicitly only readback the amount we expect (in |
| 586 | // size) overwrite our previous allocation |
| 587 | bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth, |
| 588 | size.fHeight); |
| 589 | canvas->readPixels(bitmap, 0, 0); |
| 590 | } |
| 591 | #endif |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 592 | complete_bitmap(bitmap); |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 593 | return kEmpty_ErrorCombination; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | static void generate_image_from_picture(GM* gm, const ConfigData& gRec, |
junov@chromium.org | c938c48 | 2012-12-19 15:24:38 +0000 | [diff] [blame] | 597 | SkPicture* pict, SkBitmap* bitmap, |
robertphillips@google.com | 5a7d029 | 2013-04-02 15:18:41 +0000 | [diff] [blame] | 598 | SkScalar scale = SK_Scalar1, |
| 599 | bool tile = false) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 600 | SkISize size = gm->getISize(); |
| 601 | setup_bitmap(gRec, size, bitmap); |
robertphillips@google.com | 5a7d029 | 2013-04-02 15:18:41 +0000 | [diff] [blame] | 602 | |
| 603 | if (tile) { |
| 604 | // Generate the result image by rendering to tiles and accumulating |
| 605 | // the results in 'bitmap' |
| 606 | |
skia.committer@gmail.com | 041e2db | 2013-04-03 07:01:14 +0000 | [diff] [blame] | 607 | // This 16x16 tiling matches the settings applied to 'pict' in |
robertphillips@google.com | 5a7d029 | 2013-04-02 15:18:41 +0000 | [diff] [blame] | 608 | // 'generate_new_picture' |
| 609 | SkISize tileSize = SkISize::Make(16, 16); |
| 610 | |
| 611 | SkBitmap tileBM; |
| 612 | setup_bitmap(gRec, tileSize, &tileBM); |
| 613 | SkCanvas tileCanvas(tileBM); |
| 614 | installFilter(&tileCanvas); |
| 615 | |
| 616 | SkCanvas bmpCanvas(*bitmap); |
| 617 | SkPaint bmpPaint; |
| 618 | bmpPaint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 619 | |
| 620 | for (int yTile = 0; yTile < (size.height()+15)/16; ++yTile) { |
| 621 | for (int xTile = 0; xTile < (size.width()+15)/16; ++xTile) { |
| 622 | int saveCount = tileCanvas.save(); |
| 623 | SkMatrix mat(tileCanvas.getTotalMatrix()); |
skia.committer@gmail.com | 041e2db | 2013-04-03 07:01:14 +0000 | [diff] [blame] | 624 | mat.postTranslate(SkIntToScalar(-xTile*tileSize.width()), |
robertphillips@google.com | 5a7d029 | 2013-04-02 15:18:41 +0000 | [diff] [blame] | 625 | SkIntToScalar(-yTile*tileSize.height())); |
| 626 | tileCanvas.setMatrix(mat); |
| 627 | pict->draw(&tileCanvas); |
| 628 | tileCanvas.flush(); |
| 629 | tileCanvas.restoreToCount(saveCount); |
skia.committer@gmail.com | 041e2db | 2013-04-03 07:01:14 +0000 | [diff] [blame] | 630 | bmpCanvas.drawBitmap(tileBM, |
| 631 | SkIntToScalar(xTile * tileSize.width()), |
robertphillips@google.com | 5a7d029 | 2013-04-02 15:18:41 +0000 | [diff] [blame] | 632 | SkIntToScalar(yTile * tileSize.height()), |
| 633 | &bmpPaint); |
| 634 | } |
| 635 | } |
| 636 | } else { |
| 637 | SkCanvas canvas(*bitmap); |
| 638 | installFilter(&canvas); |
| 639 | canvas.scale(scale, scale); |
| 640 | canvas.drawPicture(*pict); |
| 641 | complete_bitmap(bitmap); |
| 642 | } |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 643 | } |
| 644 | |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 645 | static bool generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 646 | #ifdef SK_SUPPORT_PDF |
| 647 | SkMatrix initialTransform = gm->getInitialTransform(); |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 648 | if (FLAGS_useDocumentInsteadOfDevice) { |
| 649 | SkISize pageISize = gm->getISize(); |
edisonn@google.com | 73a7ea3 | 2013-11-11 20:55:15 +0000 | [diff] [blame] | 650 | SkAutoTUnref<SkDocument> pdfDoc( |
| 651 | SkDocument::CreatePDF(&pdf, NULL, |
| 652 | encode_to_dct_data, |
| 653 | SkIntToScalar(FLAGS_pdfRasterDpi))); |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 654 | |
| 655 | if (!pdfDoc.get()) { |
| 656 | return false; |
| 657 | } |
| 658 | |
| 659 | SkCanvas* canvas = NULL; |
| 660 | canvas = pdfDoc->beginPage(SkIntToScalar(pageISize.width()), |
| 661 | SkIntToScalar(pageISize.height())); |
| 662 | canvas->concat(initialTransform); |
| 663 | |
| 664 | invokeGM(gm, canvas, true, false); |
| 665 | |
| 666 | return pdfDoc->close(); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 667 | } else { |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 668 | SkISize pageSize = gm->getISize(); |
| 669 | SkPDFDevice* dev = NULL; |
| 670 | if (initialTransform.isIdentity()) { |
| 671 | dev = new SkPDFDevice(pageSize, pageSize, initialTransform); |
| 672 | } else { |
| 673 | SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()), |
| 674 | SkIntToScalar(pageSize.height())); |
| 675 | initialTransform.mapRect(&content); |
| 676 | content.intersect(0, 0, SkIntToScalar(pageSize.width()), |
| 677 | SkIntToScalar(pageSize.height())); |
| 678 | SkISize contentSize = |
| 679 | SkISize::Make(SkScalarRoundToInt(content.width()), |
| 680 | SkScalarRoundToInt(content.height())); |
| 681 | dev = new SkPDFDevice(pageSize, contentSize, initialTransform); |
| 682 | } |
| 683 | dev->setDCTEncoder(encode_to_dct_data); |
edisonn@google.com | 73a7ea3 | 2013-11-11 20:55:15 +0000 | [diff] [blame] | 684 | dev->setRasterDpi(SkIntToScalar(FLAGS_pdfRasterDpi)); |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 685 | SkAutoUnref aur(dev); |
| 686 | SkCanvas c(dev); |
| 687 | invokeGM(gm, &c, true, false); |
| 688 | SkPDFDocument doc; |
| 689 | doc.appendPage(dev); |
| 690 | doc.emitPDF(&pdf); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 691 | } |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 692 | #endif // SK_SUPPORT_PDF |
| 693 | return true; // Do not report failure if pdf is not supported. |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) { |
| 697 | #ifdef SK_SUPPORT_XPS |
| 698 | SkISize size = gm->getISize(); |
| 699 | |
| 700 | SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()), |
| 701 | SkIntToScalar(size.height())); |
| 702 | static const SkScalar inchesPerMeter = SkScalarDiv(10000, 254); |
| 703 | static const SkScalar upm = 72 * inchesPerMeter; |
| 704 | SkVector unitsPerMeter = SkPoint::Make(upm, upm); |
| 705 | static const SkScalar ppm = 200 * inchesPerMeter; |
| 706 | SkVector pixelsPerMeter = SkPoint::Make(ppm, ppm); |
| 707 | |
| 708 | SkXPSDevice* dev = new SkXPSDevice(); |
| 709 | SkAutoUnref aur(dev); |
| 710 | |
| 711 | SkCanvas c(dev); |
| 712 | dev->beginPortfolio(&xps); |
| 713 | dev->beginSheet(unitsPerMeter, pixelsPerMeter, trimSize); |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 714 | invokeGM(gm, &c, false, false); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 715 | dev->endSheet(); |
| 716 | dev->endPortfolio(); |
| 717 | |
| 718 | #endif |
| 719 | } |
| 720 | |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 721 | /** |
epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 722 | * Log more detail about the mistmatch between expectedBitmap and |
| 723 | * actualBitmap. |
| 724 | */ |
| 725 | void report_bitmap_diffs(const SkBitmap& expectedBitmap, const SkBitmap& actualBitmap, |
| 726 | const char *testName) { |
| 727 | const int expectedWidth = expectedBitmap.width(); |
| 728 | const int expectedHeight = expectedBitmap.height(); |
| 729 | const int width = actualBitmap.width(); |
| 730 | const int height = actualBitmap.height(); |
| 731 | if ((expectedWidth != width) || (expectedHeight != height)) { |
epoger@google.com | 5efdd0c | 2013-03-13 14:18:40 +0000 | [diff] [blame] | 732 | gm_fprintf(stderr, "---- %s: dimension mismatch --" |
| 733 | " expected [%d %d], actual [%d %d]\n", |
| 734 | testName, expectedWidth, expectedHeight, width, height); |
epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 735 | return; |
| 736 | } |
| 737 | |
| 738 | if ((SkBitmap::kARGB_8888_Config != expectedBitmap.config()) || |
| 739 | (SkBitmap::kARGB_8888_Config != actualBitmap.config())) { |
epoger@google.com | 5efdd0c | 2013-03-13 14:18:40 +0000 | [diff] [blame] | 740 | gm_fprintf(stderr, "---- %s: not computing max per-channel" |
| 741 | " pixel mismatch because non-8888\n", testName); |
epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 742 | return; |
| 743 | } |
| 744 | |
| 745 | SkAutoLockPixels alp0(expectedBitmap); |
| 746 | SkAutoLockPixels alp1(actualBitmap); |
| 747 | int errR = 0; |
| 748 | int errG = 0; |
| 749 | int errB = 0; |
| 750 | int errA = 0; |
| 751 | int differingPixels = 0; |
| 752 | |
| 753 | for (int y = 0; y < height; ++y) { |
| 754 | const SkPMColor* expectedPixelPtr = expectedBitmap.getAddr32(0, y); |
| 755 | const SkPMColor* actualPixelPtr = actualBitmap.getAddr32(0, y); |
| 756 | for (int x = 0; x < width; ++x) { |
| 757 | SkPMColor expectedPixel = *expectedPixelPtr++; |
| 758 | SkPMColor actualPixel = *actualPixelPtr++; |
| 759 | if (expectedPixel != actualPixel) { |
| 760 | differingPixels++; |
| 761 | errR = SkMax32(errR, SkAbs32((int)SkGetPackedR32(expectedPixel) - |
| 762 | (int)SkGetPackedR32(actualPixel))); |
| 763 | errG = SkMax32(errG, SkAbs32((int)SkGetPackedG32(expectedPixel) - |
| 764 | (int)SkGetPackedG32(actualPixel))); |
| 765 | errB = SkMax32(errB, SkAbs32((int)SkGetPackedB32(expectedPixel) - |
| 766 | (int)SkGetPackedB32(actualPixel))); |
| 767 | errA = SkMax32(errA, SkAbs32((int)SkGetPackedA32(expectedPixel) - |
| 768 | (int)SkGetPackedA32(actualPixel))); |
| 769 | } |
| 770 | } |
| 771 | } |
epoger@google.com | 5efdd0c | 2013-03-13 14:18:40 +0000 | [diff] [blame] | 772 | gm_fprintf(stderr, "---- %s: %d (of %d) differing pixels," |
| 773 | " max per-channel mismatch R=%d G=%d B=%d A=%d\n", |
| 774 | testName, differingPixels, width*height, errR, errG, errB, errA); |
epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | /** |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 778 | * Compares actual hash digest to expectations, returning the set of errors |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 779 | * (if any) that we saw along the way. |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 780 | * |
| 781 | * If fMismatchPath has been set, and there are pixel diffs, then the |
| 782 | * actual bitmap will be written out to a file within fMismatchPath. |
epoger@google.com | 5f99545 | 2013-06-21 18:16:47 +0000 | [diff] [blame] | 783 | * And similarly for fMissingExpectationsPath... |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 784 | * |
| 785 | * @param expectations what expectations to compare actualBitmap against |
epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 786 | * @param actualBitmapAndDigest the SkBitmap we actually generated, and its GmResultDigest |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 787 | * @param shortName name of test, e.g. "selftest1" |
| 788 | * @param configName name of config, e.g. "8888" |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 789 | * @param renderModeDescriptor e.g., "-rtree", "-deferred" |
| 790 | * @param addToJsonSummary whether to add these results (both actual and |
epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 791 | * expected) to the JSON summary. Regardless of this setting, if |
| 792 | * we find an image mismatch in this test, we will write these |
| 793 | * results to the JSON summary. (This is so that we will always |
| 794 | * report errors across rendering modes, such as pipe vs tiled. |
| 795 | * See https://codereview.chromium.org/13650002/ ) |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 796 | */ |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 797 | ErrorCombination compare_to_expectations(Expectations expectations, |
epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 798 | const BitmapAndDigest& actualBitmapAndDigest, |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 799 | const char *shortName, const char *configName, |
| 800 | const char *renderModeDescriptor, |
epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 801 | bool addToJsonSummary) { |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 802 | ErrorCombination errors; |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 803 | SkString shortNamePlusConfig = make_shortname_plus_config(shortName, configName); |
| 804 | SkString completeNameString(shortNamePlusConfig); |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 805 | completeNameString.append(renderModeDescriptor); |
epoger@google.com | ce057fe | 2013-05-14 15:17:46 +0000 | [diff] [blame] | 806 | completeNameString.append("."); |
| 807 | completeNameString.append(kPNG_FileExtension); |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 808 | const char* completeName = completeNameString.c_str(); |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 809 | |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 810 | if (expectations.empty()) { |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 811 | errors.add(kMissingExpectations_ErrorType); |
epoger@google.com | 5f99545 | 2013-06-21 18:16:47 +0000 | [diff] [blame] | 812 | |
| 813 | // Write out the "actuals" for any tests without expectations, if we have |
| 814 | // been directed to do so. |
| 815 | if (fMissingExpectationsPath) { |
| 816 | SkString path = make_bitmap_filename(fMissingExpectationsPath, shortName, |
| 817 | configName, renderModeDescriptor, |
| 818 | actualBitmapAndDigest.fDigest); |
| 819 | write_bitmap(path, actualBitmapAndDigest.fBitmap); |
| 820 | } |
| 821 | |
epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 822 | } else if (!expectations.match(actualBitmapAndDigest.fDigest)) { |
epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 823 | addToJsonSummary = true; |
| 824 | // The error mode we record depends on whether this was running |
| 825 | // in a non-standard renderMode. |
| 826 | if ('\0' == *renderModeDescriptor) { |
| 827 | errors.add(kExpectationsMismatch_ErrorType); |
| 828 | } else { |
| 829 | errors.add(kRenderModeMismatch_ErrorType); |
| 830 | } |
epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 831 | |
| 832 | // Write out the "actuals" for any mismatches, if we have |
| 833 | // been directed to do so. |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 834 | if (fMismatchPath) { |
epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 835 | SkString path = make_bitmap_filename(fMismatchPath, shortName, configName, |
| 836 | renderModeDescriptor, |
| 837 | actualBitmapAndDigest.fDigest); |
| 838 | write_bitmap(path, actualBitmapAndDigest.fBitmap); |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 839 | } |
epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 840 | |
| 841 | // If we have access to a single expected bitmap, log more |
| 842 | // detail about the mismatch. |
| 843 | const SkBitmap *expectedBitmapPtr = expectations.asBitmap(); |
| 844 | if (NULL != expectedBitmapPtr) { |
epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 845 | report_bitmap_diffs(*expectedBitmapPtr, actualBitmapAndDigest.fBitmap, |
| 846 | completeName); |
epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 847 | } |
epoger@google.com | a243b22 | 2013-01-17 17:54:28 +0000 | [diff] [blame] | 848 | } |
epoger@google.com | a243b22 | 2013-01-17 17:54:28 +0000 | [diff] [blame] | 849 | |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 850 | if (addToJsonSummary) { |
epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 851 | add_actual_results_to_json_summary(completeName, actualBitmapAndDigest.fDigest, errors, |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 852 | expectations.ignoreFailure()); |
| 853 | add_expected_results_to_json_summary(completeName, expectations); |
| 854 | } |
epoger@google.com | a243b22 | 2013-01-17 17:54:28 +0000 | [diff] [blame] | 855 | |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 856 | return errors; |
epoger@google.com | 06b8a19 | 2013-01-15 19:10:16 +0000 | [diff] [blame] | 857 | } |
| 858 | |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 859 | /** |
epoger@google.com | 1ddfbc2 | 2013-10-10 17:24:20 +0000 | [diff] [blame] | 860 | * Add this result to the appropriate JSON collection of actual results (but just ONE), |
epoger@google.com | 76c913d | 2013-04-26 15:06:44 +0000 | [diff] [blame] | 861 | * depending on errors encountered. |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 862 | */ |
| 863 | void add_actual_results_to_json_summary(const char testName[], |
epoger@google.com | d4993ff | 2013-05-24 14:33:28 +0000 | [diff] [blame] | 864 | const GmResultDigest &actualResultDigest, |
epoger@google.com | 76c913d | 2013-04-26 15:06:44 +0000 | [diff] [blame] | 865 | ErrorCombination errors, |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 866 | bool ignoreFailure) { |
epoger@google.com | d4993ff | 2013-05-24 14:33:28 +0000 | [diff] [blame] | 867 | Json::Value jsonActualResults = actualResultDigest.asJsonTypeValuePair(); |
epoger@google.com | 1ddfbc2 | 2013-10-10 17:24:20 +0000 | [diff] [blame] | 868 | Json::Value *resultCollection = NULL; |
| 869 | |
epoger@google.com | 76c913d | 2013-04-26 15:06:44 +0000 | [diff] [blame] | 870 | if (errors.isEmpty()) { |
epoger@google.com | 1ddfbc2 | 2013-10-10 17:24:20 +0000 | [diff] [blame] | 871 | resultCollection = &this->fJsonActualResults_Succeeded; |
| 872 | } else if (errors.includes(kRenderModeMismatch_ErrorType)) { |
| 873 | resultCollection = &this->fJsonActualResults_Failed; |
| 874 | } else if (errors.includes(kExpectationsMismatch_ErrorType)) { |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 875 | if (ignoreFailure) { |
epoger@google.com | 1ddfbc2 | 2013-10-10 17:24:20 +0000 | [diff] [blame] | 876 | resultCollection = &this->fJsonActualResults_FailureIgnored; |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 877 | } else { |
epoger@google.com | 1ddfbc2 | 2013-10-10 17:24:20 +0000 | [diff] [blame] | 878 | resultCollection = &this->fJsonActualResults_Failed; |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 879 | } |
epoger@google.com | 1ddfbc2 | 2013-10-10 17:24:20 +0000 | [diff] [blame] | 880 | } else if (errors.includes(kMissingExpectations_ErrorType)) { |
| 881 | // TODO: What about the case where there IS an expected |
| 882 | // image hash digest, but that gm test doesn't actually |
| 883 | // run? For now, those cases will always be ignored, |
| 884 | // because gm only looks at expectations that correspond |
| 885 | // to gm tests that were actually run. |
| 886 | // |
| 887 | // Once we have the ability to express expectations as a |
| 888 | // JSON file, we should fix this (and add a test case for |
| 889 | // which an expectation is given but the test is never |
| 890 | // run). |
| 891 | resultCollection = &this->fJsonActualResults_NoComparison; |
| 892 | } |
| 893 | |
| 894 | // If none of the above cases match, we don't add it to ANY tally of actual results. |
| 895 | if (resultCollection) { |
| 896 | (*resultCollection)[testName] = jsonActualResults; |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 897 | } |
| 898 | } |
| 899 | |
| 900 | /** |
| 901 | * Add this test to the JSON collection of expected results. |
| 902 | */ |
| 903 | void add_expected_results_to_json_summary(const char testName[], |
| 904 | Expectations expectations) { |
epoger@google.com | 76c913d | 2013-04-26 15:06:44 +0000 | [diff] [blame] | 905 | this->fJsonExpectedResults[testName] = expectations.asJsonValue(); |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | /** |
| 909 | * Compare actualBitmap to expectations stored in this->fExpectationsSource. |
| 910 | * |
| 911 | * @param gm which test generated the actualBitmap |
| 912 | * @param gRec |
vandebo@chromium.org | 8fc3766 | 2013-08-21 18:04:09 +0000 | [diff] [blame] | 913 | * @param configName The config name to look for in the expectation file. |
epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 914 | * @param actualBitmapAndDigest ptr to bitmap generated by this run, or NULL |
| 915 | * if we don't have a usable bitmap representation |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 916 | */ |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 917 | ErrorCombination compare_test_results_to_stored_expectations( |
vandebo@chromium.org | 8fc3766 | 2013-08-21 18:04:09 +0000 | [diff] [blame] | 918 | GM* gm, const ConfigData& gRec, const char* configName, |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 919 | const BitmapAndDigest* actualBitmapAndDigest) { |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 920 | ErrorCombination errors; |
epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 921 | |
| 922 | if (NULL == actualBitmapAndDigest) { |
| 923 | // Note that we intentionally skipped validating the results for |
| 924 | // this test, because we don't know how to generate an SkBitmap |
| 925 | // version of the output. |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 926 | errors.add(ErrorCombination(kIntentionallySkipped_ErrorType)); |
epoger@google.com | c824c83 | 2013-07-12 15:52:59 +0000 | [diff] [blame] | 927 | } else if (!(gRec.fFlags & kWrite_ConfigFlag)) { |
| 928 | // We don't record the results for this test or compare them |
| 929 | // against any expectations, because the output image isn't |
| 930 | // meaningful. |
| 931 | // See https://code.google.com/p/skia/issues/detail?id=1410 ('some |
| 932 | // GM result images not available for download from Google Storage') |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 933 | errors.add(ErrorCombination(kIntentionallySkipped_ErrorType)); |
epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 934 | } else { |
| 935 | ExpectationsSource *expectationsSource = this->fExpectationsSource.get(); |
commit-bot@chromium.org | 3e62ebf | 2014-01-14 02:54:11 +0000 | [diff] [blame] | 936 | SkString nameWithExtension = make_shortname_plus_config(gm->shortName(), configName); |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 937 | nameWithExtension.append("."); |
| 938 | nameWithExtension.append(kPNG_FileExtension); |
| 939 | |
epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 940 | if (expectationsSource && (gRec.fFlags & kRead_ConfigFlag)) { |
| 941 | /* |
| 942 | * Get the expected results for this test, as one or more allowed |
| 943 | * hash digests. The current implementation of expectationsSource |
| 944 | * get this by computing the hash digest of a single PNG file on disk. |
| 945 | * |
| 946 | * TODO(epoger): This relies on the fact that |
| 947 | * force_all_opaque() was called on the bitmap before it |
| 948 | * was written to disk as a PNG in the first place. If |
| 949 | * not, the hash digest returned here may not match the |
| 950 | * hash digest of actualBitmap, which *has* been run through |
| 951 | * force_all_opaque(). |
| 952 | * See comments above complete_bitmap() for more detail. |
| 953 | */ |
| 954 | Expectations expectations = expectationsSource->get(nameWithExtension.c_str()); |
commit-bot@chromium.org | 3e62ebf | 2014-01-14 02:54:11 +0000 | [diff] [blame] | 955 | if (this->ShouldIgnoreTest(gm->shortName())) { |
epoger@google.com | defc487 | 2013-09-19 06:18:27 +0000 | [diff] [blame] | 956 | expectations.setIgnoreFailure(true); |
| 957 | } |
epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 958 | errors.add(compare_to_expectations(expectations, *actualBitmapAndDigest, |
vandebo@chromium.org | 8fc3766 | 2013-08-21 18:04:09 +0000 | [diff] [blame] | 959 | gm->shortName(), configName, "", true)); |
epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 960 | } else { |
| 961 | // If we are running without expectations, we still want to |
| 962 | // record the actual results. |
| 963 | add_actual_results_to_json_summary(nameWithExtension.c_str(), |
| 964 | actualBitmapAndDigest->fDigest, |
| 965 | ErrorCombination(kMissingExpectations_ErrorType), |
| 966 | false); |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 967 | errors.add(ErrorCombination(kMissingExpectations_ErrorType)); |
epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 968 | } |
epoger@google.com | 9ef89ce | 2013-01-18 21:45:42 +0000 | [diff] [blame] | 969 | } |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 970 | return errors; |
epoger@google.com | a243b22 | 2013-01-17 17:54:28 +0000 | [diff] [blame] | 971 | } |
| 972 | |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 973 | /** |
| 974 | * Compare actualBitmap to referenceBitmap. |
| 975 | * |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 976 | * @param shortName test name, e.g. "selftest1" |
| 977 | * @param configName configuration name, e.g. "8888" |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 978 | * @param renderModeDescriptor |
| 979 | * @param actualBitmap actual bitmap generated by this run |
| 980 | * @param referenceBitmap bitmap we expected to be generated |
| 981 | */ |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 982 | ErrorCombination compare_test_results_to_reference_bitmap( |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 983 | const char *shortName, const char *configName, const char *renderModeDescriptor, |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 984 | SkBitmap& actualBitmap, const SkBitmap* referenceBitmap) { |
| 985 | |
| 986 | SkASSERT(referenceBitmap); |
epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 987 | Expectations expectations(*referenceBitmap); |
epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 988 | BitmapAndDigest actualBitmapAndDigest(actualBitmap); |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 989 | |
| 990 | // TODO: Eliminate RecordTestResults from here. |
| 991 | // Results recording code for the test_drawing path has been refactored so that |
| 992 | // RecordTestResults is only called once, at the topmost level. However, the |
| 993 | // other paths have not yet been refactored, and RecordTestResults has been added |
| 994 | // here to maintain proper behavior for calls not coming from the test_drawing path. |
| 995 | ErrorCombination errors; |
| 996 | errors.add(compare_to_expectations(expectations, actualBitmapAndDigest, shortName, |
| 997 | configName, renderModeDescriptor, false)); |
| 998 | SkString shortNamePlusConfig = make_shortname_plus_config(shortName, configName); |
| 999 | RecordTestResults(errors, shortNamePlusConfig, renderModeDescriptor); |
| 1000 | |
| 1001 | return errors; |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
junov@chromium.org | 20bd04e | 2013-01-16 18:43:36 +0000 | [diff] [blame] | 1004 | static SkPicture* generate_new_picture(GM* gm, BbhType bbhType, uint32_t recordFlags, |
| 1005 | SkScalar scale = SK_Scalar1) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1006 | // Pictures are refcounted so must be on heap |
junov@chromium.org | 3cb834b | 2012-12-13 16:39:53 +0000 | [diff] [blame] | 1007 | SkPicture* pict; |
junov@chromium.org | 706ff2f | 2012-12-19 15:55:40 +0000 | [diff] [blame] | 1008 | int width = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().width()), scale)); |
| 1009 | int height = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().height()), scale)); |
skia.committer@gmail.com | d8b2799 | 2012-12-20 02:01:41 +0000 | [diff] [blame] | 1010 | |
junov@chromium.org | 3cb834b | 2012-12-13 16:39:53 +0000 | [diff] [blame] | 1011 | if (kTileGrid_BbhType == bbhType) { |
junov@chromium.org | 29b19e5 | 2013-02-27 18:35:16 +0000 | [diff] [blame] | 1012 | SkTileGridPicture::TileGridInfo info; |
| 1013 | info.fMargin.setEmpty(); |
| 1014 | info.fOffset.setZero(); |
| 1015 | info.fTileInterval.set(16, 16); |
| 1016 | pict = new SkTileGridPicture(width, height, info); |
junov@chromium.org | 3cb834b | 2012-12-13 16:39:53 +0000 | [diff] [blame] | 1017 | } else { |
| 1018 | pict = new SkPicture; |
| 1019 | } |
junov@chromium.org | 20bd04e | 2013-01-16 18:43:36 +0000 | [diff] [blame] | 1020 | if (kNone_BbhType != bbhType) { |
| 1021 | recordFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; |
| 1022 | } |
junov@chromium.org | 706ff2f | 2012-12-19 15:55:40 +0000 | [diff] [blame] | 1023 | SkCanvas* cv = pict->beginRecording(width, height, recordFlags); |
junov@chromium.org | c938c48 | 2012-12-19 15:24:38 +0000 | [diff] [blame] | 1024 | cv->scale(scale, scale); |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 1025 | invokeGM(gm, cv, false, false); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1026 | pict->endRecording(); |
| 1027 | |
| 1028 | return pict; |
| 1029 | } |
| 1030 | |
| 1031 | static SkPicture* stream_to_new_picture(const SkPicture& src) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1032 | SkDynamicMemoryWStream storage; |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 1033 | src.serialize(&storage, NULL); |
bungeman@google.com | c29f3d8 | 2013-07-19 22:32:11 +0000 | [diff] [blame] | 1034 | SkAutoTUnref<SkStreamAsset> pictReadback(storage.detachAsStream()); |
commit-bot@chromium.org | 805df1a | 2013-08-16 19:18:12 +0000 | [diff] [blame] | 1035 | SkPicture* retval = SkPicture::CreateFromStream(pictReadback, |
| 1036 | &SkImageDecoder::DecodeMemory); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1037 | return retval; |
| 1038 | } |
| 1039 | |
| 1040 | // Test: draw into a bitmap or pdf. |
epoger@google.com | 15655b2 | 2013-01-08 18:47:31 +0000 | [diff] [blame] | 1041 | // Depending on flags, possibly compare to an expected image. |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1042 | // If writePath is not NULL, also write images (or documents) to the specified path. |
| 1043 | ErrorCombination test_drawing(GM* gm, const ConfigData& gRec, |
| 1044 | const SkTDArray<const PDFRasterizerData*> &pdfRasterizers, |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1045 | const char writePath [], |
bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1046 | GrSurface* gpuTarget, |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1047 | SkBitmap* bitmap) { |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1048 | ErrorCombination errors; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1049 | SkDynamicMemoryWStream document; |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1050 | SkString path; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1051 | |
| 1052 | if (gRec.fBackend == kRaster_Backend || |
| 1053 | gRec.fBackend == kGPU_Backend) { |
| 1054 | // Early exit if we can't generate the image. |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1055 | errors.add(generate_image(gm, gRec, gpuTarget, bitmap, false)); |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1056 | if (!errors.isEmpty()) { |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1057 | // TODO: Add a test to exercise what the stdout and |
| 1058 | // JSON look like if we get an "early error" while |
| 1059 | // trying to generate the image. |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1060 | return errors; |
| 1061 | } |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1062 | BitmapAndDigest bitmapAndDigest(*bitmap); |
| 1063 | errors.add(compare_test_results_to_stored_expectations( |
vandebo@chromium.org | 8fc3766 | 2013-08-21 18:04:09 +0000 | [diff] [blame] | 1064 | gm, gRec, gRec.fName, &bitmapAndDigest)); |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1065 | |
| 1066 | if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) { |
| 1067 | path = make_bitmap_filename(writePath, gm->shortName(), gRec.fName, |
| 1068 | "", bitmapAndDigest.fDigest); |
| 1069 | errors.add(write_bitmap(path, bitmapAndDigest.fBitmap)); |
| 1070 | } |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1071 | } else if (gRec.fBackend == kPDF_Backend) { |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 1072 | if (!generate_pdf(gm, document)) { |
| 1073 | errors.add(kGeneratePdfFailed_ErrorType); |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1074 | } else { |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 1075 | SkAutoTUnref<SkStreamAsset> documentStream(document.detachAsStream()); |
| 1076 | if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) { |
| 1077 | path = make_filename(writePath, gm->shortName(), gRec.fName, "", "pdf"); |
| 1078 | errors.add(write_document(path, documentStream)); |
| 1079 | } |
| 1080 | |
| 1081 | if (!(gm->getFlags() & GM::kSkipPDFRasterization_Flag)) { |
| 1082 | for (int i = 0; i < pdfRasterizers.count(); i++) { |
| 1083 | SkBitmap pdfBitmap; |
vandebo@chromium.org | 969967e | 2013-12-09 23:22:15 +0000 | [diff] [blame] | 1084 | documentStream->rewind(); |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 1085 | bool success = (*pdfRasterizers[i]->fRasterizerFunction)( |
| 1086 | documentStream.get(), &pdfBitmap); |
| 1087 | if (!success) { |
| 1088 | gm_fprintf(stderr, "FAILED to render PDF for %s using renderer %s\n", |
| 1089 | gm->shortName(), |
| 1090 | pdfRasterizers[i]->fName); |
| 1091 | continue; |
| 1092 | } |
| 1093 | |
| 1094 | SkString configName(gRec.fName); |
| 1095 | configName.append("-"); |
| 1096 | configName.append(pdfRasterizers[i]->fName); |
| 1097 | |
| 1098 | BitmapAndDigest bitmapAndDigest(pdfBitmap); |
| 1099 | errors.add(compare_test_results_to_stored_expectations( |
| 1100 | gm, gRec, configName.c_str(), &bitmapAndDigest)); |
| 1101 | |
| 1102 | if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) { |
| 1103 | path = make_bitmap_filename(writePath, gm->shortName(), |
| 1104 | configName.c_str(), |
| 1105 | "", bitmapAndDigest.fDigest); |
| 1106 | errors.add(write_bitmap(path, bitmapAndDigest.fBitmap)); |
| 1107 | } |
| 1108 | } |
| 1109 | } else { |
| 1110 | errors.add(kIntentionallySkipped_ErrorType); |
| 1111 | } |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1112 | } |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1113 | } else if (gRec.fBackend == kXPS_Backend) { |
| 1114 | generate_xps(gm, document); |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1115 | SkAutoTUnref<SkStreamAsset> documentStream(document.detachAsStream()); |
epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 1116 | |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1117 | errors.add(compare_test_results_to_stored_expectations( |
vandebo@chromium.org | 8fc3766 | 2013-08-21 18:04:09 +0000 | [diff] [blame] | 1118 | gm, gRec, gRec.fName, NULL)); |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1119 | |
| 1120 | if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) { |
| 1121 | path = make_filename(writePath, gm->shortName(), gRec.fName, "", "xps"); |
| 1122 | errors.add(write_document(path, documentStream)); |
| 1123 | } |
epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 1124 | } else { |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1125 | SkASSERT(false); |
epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 1126 | } |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1127 | return errors; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1130 | ErrorCombination test_deferred_drawing(GM* gm, |
| 1131 | const ConfigData& gRec, |
| 1132 | const SkBitmap& referenceBitmap, |
bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1133 | GrSurface* gpuTarget) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1134 | if (gRec.fBackend == kRaster_Backend || |
| 1135 | gRec.fBackend == kGPU_Backend) { |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1136 | const char renderModeDescriptor[] = "-deferred"; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1137 | SkBitmap bitmap; |
| 1138 | // Early exit if we can't generate the image, but this is |
| 1139 | // expected in some cases, so don't report a test failure. |
bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1140 | ErrorCombination errors = generate_image(gm, gRec, gpuTarget, &bitmap, true); |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1141 | // TODO(epoger): This logic is the opposite of what is |
| 1142 | // described above... if we succeeded in generating the |
| 1143 | // -deferred image, we exit early! We should fix this |
| 1144 | // ASAP, because it is hiding -deferred errors... but for |
| 1145 | // now, I'm leaving the logic as it is so that the |
| 1146 | // refactoring change |
| 1147 | // https://codereview.chromium.org/12992003/ is unblocked. |
| 1148 | // |
| 1149 | // Filed as https://code.google.com/p/skia/issues/detail?id=1180 |
| 1150 | // ('image-surface gm test is failing in "deferred" mode, |
| 1151 | // and gm is not reporting the failure') |
| 1152 | if (errors.isEmpty()) { |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 1153 | // TODO(epoger): Report this as a new ErrorType, |
| 1154 | // something like kImageGeneration_ErrorType? |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1155 | return kEmpty_ErrorCombination; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1156 | } |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1157 | return compare_test_results_to_reference_bitmap( |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1158 | gm->shortName(), gRec.fName, renderModeDescriptor, bitmap, &referenceBitmap); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1159 | } |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1160 | return kEmpty_ErrorCombination; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1161 | } |
| 1162 | |
epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 1163 | ErrorCombination test_pipe_playback(GM* gm, const ConfigData& gRec, |
| 1164 | const SkBitmap& referenceBitmap, bool simulateFailure) { |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1165 | const SkString shortNamePlusConfig = make_shortname_plus_config(gm->shortName(), |
| 1166 | gRec.fName); |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1167 | ErrorCombination errors; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1168 | for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) { |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1169 | SkString renderModeDescriptor("-pipe"); |
| 1170 | renderModeDescriptor.append(gPipeWritingFlagCombos[i].name); |
| 1171 | |
commit-bot@chromium.org | 805df1a | 2013-08-16 19:18:12 +0000 | [diff] [blame] | 1172 | if (gm->getFlags() & GM::kSkipPipe_Flag |
| 1173 | || (gPipeWritingFlagCombos[i].flags == SkGPipeWriter::kCrossProcess_Flag |
| 1174 | && gm->getFlags() & GM::kSkipPipeCrossProcess_Flag)) { |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1175 | RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1176 | renderModeDescriptor.c_str()); |
| 1177 | errors.add(kIntentionallySkipped_ErrorType); |
| 1178 | } else { |
| 1179 | SkBitmap bitmap; |
| 1180 | SkISize size = gm->getISize(); |
| 1181 | setup_bitmap(gRec, size, &bitmap); |
| 1182 | SkCanvas canvas(bitmap); |
| 1183 | installFilter(&canvas); |
scroggo@google.com | 74b7ffd | 2013-04-30 02:32:41 +0000 | [diff] [blame] | 1184 | // Pass a decoding function so the factory GM (which has an SkBitmap |
| 1185 | // with encoded data) will not fail playback. |
| 1186 | PipeController pipeController(&canvas, &SkImageDecoder::DecodeMemory); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1187 | SkGPipeWriter writer; |
| 1188 | SkCanvas* pipeCanvas = writer.startRecording(&pipeController, |
scroggo@google.com | aef2d3b | 2013-04-10 18:10:41 +0000 | [diff] [blame] | 1189 | gPipeWritingFlagCombos[i].flags, |
| 1190 | size.width(), size.height()); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1191 | if (!simulateFailure) { |
| 1192 | invokeGM(gm, pipeCanvas, false, false); |
| 1193 | } |
| 1194 | complete_bitmap(&bitmap); |
| 1195 | writer.endRecording(); |
| 1196 | errors.add(compare_test_results_to_reference_bitmap( |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1197 | gm->shortName(), gRec.fName, renderModeDescriptor.c_str(), bitmap, |
| 1198 | &referenceBitmap)); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1199 | if (!errors.isEmpty()) { |
| 1200 | break; |
| 1201 | } |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1202 | } |
| 1203 | } |
| 1204 | return errors; |
| 1205 | } |
| 1206 | |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1207 | ErrorCombination test_tiled_pipe_playback(GM* gm, const ConfigData& gRec, |
| 1208 | const SkBitmap& referenceBitmap) { |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1209 | const SkString shortNamePlusConfig = make_shortname_plus_config(gm->shortName(), |
| 1210 | gRec.fName); |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1211 | ErrorCombination errors; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1212 | for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) { |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1213 | SkString renderModeDescriptor("-tiled pipe"); |
| 1214 | renderModeDescriptor.append(gPipeWritingFlagCombos[i].name); |
| 1215 | |
| 1216 | if ((gm->getFlags() & GM::kSkipPipe_Flag) || |
| 1217 | (gm->getFlags() & GM::kSkipTiled_Flag)) { |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1218 | RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1219 | renderModeDescriptor.c_str()); |
| 1220 | errors.add(kIntentionallySkipped_ErrorType); |
| 1221 | } else { |
| 1222 | SkBitmap bitmap; |
| 1223 | SkISize size = gm->getISize(); |
| 1224 | setup_bitmap(gRec, size, &bitmap); |
| 1225 | SkCanvas canvas(bitmap); |
| 1226 | installFilter(&canvas); |
scroggo@google.com | 74b7ffd | 2013-04-30 02:32:41 +0000 | [diff] [blame] | 1227 | TiledPipeController pipeController(bitmap, &SkImageDecoder::DecodeMemory); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1228 | SkGPipeWriter writer; |
| 1229 | SkCanvas* pipeCanvas = writer.startRecording(&pipeController, |
scroggo@google.com | aef2d3b | 2013-04-10 18:10:41 +0000 | [diff] [blame] | 1230 | gPipeWritingFlagCombos[i].flags, |
| 1231 | size.width(), size.height()); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1232 | invokeGM(gm, pipeCanvas, false, false); |
| 1233 | complete_bitmap(&bitmap); |
| 1234 | writer.endRecording(); |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1235 | 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] | 1236 | renderModeDescriptor.c_str(), |
| 1237 | bitmap, &referenceBitmap)); |
| 1238 | if (!errors.isEmpty()) { |
| 1239 | break; |
| 1240 | } |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1241 | } |
| 1242 | } |
| 1243 | return errors; |
| 1244 | } |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 1245 | |
| 1246 | // |
| 1247 | // member variables. |
| 1248 | // They are public for now, to allow easier setting by tool_main(). |
| 1249 | // |
| 1250 | |
epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 1251 | bool fUseFileHierarchy, fWriteChecksumBasedFilenames; |
epoger@google.com | 5079d2c | 2013-04-12 14:11:21 +0000 | [diff] [blame] | 1252 | ErrorCombination fIgnorableErrorTypes; |
commit-bot@chromium.org | 3e62ebf | 2014-01-14 02:54:11 +0000 | [diff] [blame] | 1253 | SkTArray<SkString> fIgnorableTestNames; |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 1254 | |
junov@chromium.org | 95146eb | 2013-01-11 21:04:40 +0000 | [diff] [blame] | 1255 | const char* fMismatchPath; |
epoger@google.com | 5f99545 | 2013-06-21 18:16:47 +0000 | [diff] [blame] | 1256 | const char* fMissingExpectationsPath; |
junov@chromium.org | 95146eb | 2013-01-11 21:04:40 +0000 | [diff] [blame] | 1257 | |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 1258 | // collection of tests that have failed with each ErrorType |
| 1259 | SkTArray<SkString> fFailedTests[kLast_ErrorType+1]; |
commit-bot@chromium.org | 8519548 | 2014-01-13 18:27:59 +0000 | [diff] [blame] | 1260 | SkTArray<SkString> fTestsSkippedOnAllRenderModes; |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 1261 | int fTestsRun; |
| 1262 | SkTDict<int> fRenderModesEncountered; |
epoger@google.com | 57f7abc | 2012-11-13 03:41:55 +0000 | [diff] [blame] | 1263 | |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 1264 | // Where to read expectations (expected image hash digests, etc.) from. |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1265 | // If unset, we don't do comparisons. |
| 1266 | SkAutoTUnref<ExpectationsSource> fExpectationsSource; |
| 1267 | |
| 1268 | // JSON summaries that we generate as we go (just for output). |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 1269 | Json::Value fJsonExpectedResults; |
| 1270 | Json::Value fJsonActualResults_Failed; |
| 1271 | Json::Value fJsonActualResults_FailureIgnored; |
epoger@google.com | 9c56a8d | 2012-12-20 18:34:29 +0000 | [diff] [blame] | 1272 | Json::Value fJsonActualResults_NoComparison; |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 1273 | Json::Value fJsonActualResults_Succeeded; |
| 1274 | |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1275 | }; // end of GMMain class definition |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 1276 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1277 | #if SK_SUPPORT_GPU |
| 1278 | static const GLContextType kDontCare_GLContextType = GrContextFactory::kNative_GLContextType; |
| 1279 | #else |
| 1280 | static const GLContextType kDontCare_GLContextType = 0; |
| 1281 | #endif |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1282 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1283 | static const ConfigData gRec[] = { |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1284 | { 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] | 1285 | #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] | 1286 | { 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] | 1287 | #endif |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1288 | { SkBitmap::kRGB_565_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "565", true }, |
| 1289 | #if SK_SUPPORT_GPU |
| 1290 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 0, kRW_ConfigFlag, "gpu", true }, |
robertphillips@google.com | 7bb28a1 | 2013-06-06 21:29:39 +0000 | [diff] [blame] | 1291 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 16, kRW_ConfigFlag, "msaa16", false}, |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1292 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 4, kRW_ConfigFlag, "msaa4", false}, |
epoger@google.com | c824c83 | 2013-07-12 15:52:59 +0000 | [diff] [blame] | 1293 | /* The gpudebug context does not generate meaningful images, so don't record |
| 1294 | * the images it generates! We only run it to look for asserts. */ |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 1295 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kDebug_GLContextType, 0, kNone_ConfigFlag, "gpudebug", kDebugOnly}, |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 1296 | /* The gpunull context does the least amount of work possible and doesn't |
| 1297 | generate meaninful images, so don't record them!. It can be run to |
| 1298 | isolate the CPU-side processing expense from the GPU-side. |
| 1299 | */ |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 1300 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNull_GLContextType, 0, kNone_ConfigFlag, "gpunull", kDebugOnly}, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1301 | #if SK_ANGLE |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1302 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 0, kRW_ConfigFlag, "angle", true }, |
| 1303 | { 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] | 1304 | #endif // SK_ANGLE |
| 1305 | #ifdef SK_MESA |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1306 | { 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] | 1307 | #endif // SK_MESA |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1308 | #endif // SK_SUPPORT_GPU |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1309 | #ifdef SK_SUPPORT_XPS |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1310 | /* 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] | 1311 | { 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] | 1312 | #endif // SK_SUPPORT_XPS |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1313 | #ifdef SK_SUPPORT_PDF |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1314 | { SkBitmap::kARGB_8888_Config, kPDF_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "pdf", true }, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1315 | #endif // SK_SUPPORT_PDF |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1316 | }; |
| 1317 | |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1318 | static const PDFRasterizerData kPDFRasterizers[] = { |
| 1319 | #ifdef SK_BUILD_FOR_MAC |
| 1320 | { &SkPDFDocumentToBitmap, "mac", true }, |
| 1321 | #endif |
| 1322 | #ifdef SK_BUILD_POPPLER |
| 1323 | { &SkPopplerRasterizePDF, "poppler", true }, |
| 1324 | #endif |
commit-bot@chromium.org | ffd178c | 2013-11-11 15:10:47 +0000 | [diff] [blame] | 1325 | #ifdef SK_BUILD_NATIVE_PDF_RENDERER |
| 1326 | { &SkNativeRasterizePDF, "native", true }, |
| 1327 | #endif // SK_BUILD_NATIVE_PDF_RENDERER |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1328 | }; |
| 1329 | |
bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1330 | static const char kDefaultsConfigStr[] = "defaults"; |
| 1331 | static const char kExcludeConfigChar = '~'; |
| 1332 | |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1333 | static SkString configUsage() { |
scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1334 | SkString result; |
| 1335 | 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] | 1336 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1337 | SkASSERT(gRec[i].fName != kDefaultsConfigStr); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1338 | if (i > 0) { |
scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1339 | result.append("|"); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1340 | } |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1341 | result.appendf("%s", gRec[i].fName); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1342 | } |
scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1343 | result.append("]\n"); |
| 1344 | result.appendf("The default value is: \""); |
bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1345 | SkString firstDefault; |
| 1346 | SkString allButFirstDefaults; |
| 1347 | SkString nonDefault; |
scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1348 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 1349 | if (gRec[i].fRunByDefault) { |
| 1350 | if (i > 0) { |
| 1351 | result.append(" "); |
| 1352 | } |
bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1353 | result.append(gRec[i].fName); |
| 1354 | if (firstDefault.isEmpty()) { |
| 1355 | firstDefault = gRec[i].fName; |
| 1356 | } else { |
| 1357 | if (!allButFirstDefaults.isEmpty()) { |
| 1358 | allButFirstDefaults.append(" "); |
| 1359 | } |
| 1360 | allButFirstDefaults.append(gRec[i].fName); |
| 1361 | } |
| 1362 | } else { |
| 1363 | nonDefault = gRec[i].fName; |
scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1364 | } |
| 1365 | } |
bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1366 | result.append("\"\n"); |
| 1367 | result.appendf("\"%s\" evaluates to the default set of configs.\n", kDefaultsConfigStr); |
| 1368 | result.appendf("Prepending \"%c\" on a config name excludes it from the set of configs to run.\n" |
| 1369 | "Exclusions always override inclusions regardless of order.\n", |
| 1370 | kExcludeConfigChar); |
| 1371 | result.appendf("E.g. \"--config %s %c%s %s\" will run these configs:\n\t%s %s", |
| 1372 | kDefaultsConfigStr, |
| 1373 | kExcludeConfigChar, |
| 1374 | firstDefault.c_str(), |
| 1375 | nonDefault.c_str(), |
| 1376 | allButFirstDefaults.c_str(), |
| 1377 | nonDefault.c_str()); |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1378 | return result; |
scroggo@google.com | 0b73563 | 2013-03-19 17:38:50 +0000 | [diff] [blame] | 1379 | } |
scroggo@google.com | 7d51930 | 2013-03-19 17:28:10 +0000 | [diff] [blame] | 1380 | |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1381 | static SkString pdfRasterizerUsage() { |
| 1382 | SkString result; |
| 1383 | result.appendf("Space delimited list of which PDF rasterizers to run. Possible options: ["); |
| 1384 | // For this (and further) loops through kPDFRasterizers, there is a typecast to int to avoid |
| 1385 | // the compiler giving an "comparison of unsigned expression < 0 is always false" warning |
| 1386 | // and turning it into a build-breaking error. |
| 1387 | for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); ++i) { |
| 1388 | if (i > 0) { |
| 1389 | result.append(" "); |
| 1390 | } |
| 1391 | result.append(kPDFRasterizers[i].fName); |
| 1392 | } |
| 1393 | result.append("]\n"); |
| 1394 | result.append("The default value is: \""); |
| 1395 | for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); ++i) { |
| 1396 | if (kPDFRasterizers[i].fRunByDefault) { |
| 1397 | if (i > 0) { |
| 1398 | result.append(" "); |
| 1399 | } |
| 1400 | result.append(kPDFRasterizers[i].fName); |
| 1401 | } |
| 1402 | } |
| 1403 | result.append("\""); |
| 1404 | return result; |
| 1405 | } |
| 1406 | |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1407 | // Macro magic to convert a numeric preprocessor token into a string. |
| 1408 | // Adapted from http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string |
| 1409 | // This should probably be moved into one of our common headers... |
| 1410 | #define TOSTRING_INTERNAL(x) #x |
| 1411 | #define TOSTRING(x) TOSTRING_INTERNAL(x) |
| 1412 | |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1413 | // Alphabetized ignoring "no" prefix ("readPath", "noreplay", "resourcePath"). |
scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1414 | DEFINE_string(config, "", configUsage().c_str()); |
vandebo@chromium.org | f8afb2b | 2013-11-06 16:32:15 +0000 | [diff] [blame] | 1415 | DEFINE_string(pdfRasterizers, "default", pdfRasterizerUsage().c_str()); |
epoger@google.com | 5e49738 | 2013-09-30 07:01:55 +0000 | [diff] [blame] | 1416 | DEFINE_bool(deferred, false, "Exercise the deferred rendering test pass."); |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1417 | DEFINE_string(excludeConfig, "", "Space delimited list of configs to skip."); |
| 1418 | DEFINE_bool(forceBWtext, false, "Disable text anti-aliasing."); |
| 1419 | #if SK_SUPPORT_GPU |
| 1420 | 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] | 1421 | "object count. " TOSTRING(DEFAULT_CACHE_VALUE) " for either value means " |
| 1422 | "use the default. 0 for either disables the cache."); |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1423 | #endif |
| 1424 | DEFINE_bool(hierarchy, false, "Whether to use multilevel directory structure " |
| 1425 | "when reading/writing files."); |
epoger@google.com | 5079d2c | 2013-04-12 14:11:21 +0000 | [diff] [blame] | 1426 | DEFINE_string(ignoreErrorTypes, kDefaultIgnorableErrorTypes.asString(" ").c_str(), |
| 1427 | "Space-separated list of ErrorTypes that should be ignored. If any *other* error " |
| 1428 | "types are encountered, the tool will exit with a nonzero return value."); |
epoger@google.com | f711f32 | 2013-10-18 14:55:47 +0000 | [diff] [blame] | 1429 | DEFINE_string(ignoreFailuresFile, "", "Path to file containing a list of tests for which we " |
| 1430 | "should ignore failures.\n" |
| 1431 | "The file should list one test per line, except for comment lines starting with #"); |
commit-bot@chromium.org | 6dda827 | 2014-01-23 17:21:19 +0000 | [diff] [blame] | 1432 | DEFINE_bool2(leaks, l, false, "show leaked ref cnt'd objects."); |
caryclark@google.com | 512c9b6 | 2013-05-10 15:16:13 +0000 | [diff] [blame] | 1433 | DEFINE_string(match, "", "[~][^]substring[$] [...] of test name to run.\n" |
| 1434 | "Multiple matches may be separated by spaces.\n" |
| 1435 | "~ causes a matching test to always be skipped\n" |
| 1436 | "^ requires the start of the test to match\n" |
| 1437 | "$ requires the end of the test to match\n" |
| 1438 | "^ and $ requires an exact match\n" |
| 1439 | "If a test does not match any list entry,\n" |
| 1440 | "it is skipped unless some list entry starts with ~"); |
epoger@google.com | 5f99545 | 2013-06-21 18:16:47 +0000 | [diff] [blame] | 1441 | DEFINE_string(missingExpectationsPath, "", "Write images for tests without expectations " |
| 1442 | "into this directory."); |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1443 | DEFINE_string(mismatchPath, "", "Write images for tests that failed due to " |
| 1444 | "pixel mismatches into this directory."); |
| 1445 | DEFINE_string(modulo, "", "[--modulo <remainder> <divisor>]: only run tests for which " |
| 1446 | "testIndex %% divisor == remainder."); |
epoger@google.com | 5e49738 | 2013-09-30 07:01:55 +0000 | [diff] [blame] | 1447 | DEFINE_bool(pipe, false, "Exercise the SkGPipe replay test pass."); |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1448 | DEFINE_string2(readPath, r, "", "Read reference images from this dir, and report " |
| 1449 | "any differences between those and the newly generated ones."); |
epoger@google.com | 5e49738 | 2013-09-30 07:01:55 +0000 | [diff] [blame] | 1450 | DEFINE_bool(replay, false, "Exercise the SkPicture replay test pass."); |
djsollen@google.com | ac8f3a4 | 2013-10-04 14:57:00 +0000 | [diff] [blame] | 1451 | #if SK_SUPPORT_GPU |
| 1452 | DEFINE_bool(resetGpuContext, false, "Reset the GrContext prior to running each GM."); |
| 1453 | #endif |
tfarina@chromium.org | 725a64c | 2013-12-31 14:29:52 +0000 | [diff] [blame] | 1454 | DEFINE_string2(resourcePath, i, "resources", "Directory that stores image resources."); |
epoger@google.com | 5e49738 | 2013-09-30 07:01:55 +0000 | [diff] [blame] | 1455 | DEFINE_bool(rtree, false, "Exercise the R-Tree variant of SkPicture test pass."); |
| 1456 | DEFINE_bool(serialize, false, "Exercise the SkPicture serialization & deserialization test pass."); |
epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 1457 | 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] | 1458 | DEFINE_bool(tiledPipe, false, "Exercise tiled SkGPipe replay."); |
epoger@google.com | 5e49738 | 2013-09-30 07:01:55 +0000 | [diff] [blame] | 1459 | DEFINE_bool(tileGrid, false, "Exercise the tile grid variant of SkPicture."); |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1460 | DEFINE_string(tileGridReplayScales, "", "Space separated list of floating-point scale " |
| 1461 | "factors to be used for tileGrid playback testing. Default value: 1.0"); |
epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 1462 | DEFINE_bool2(verbose, v, false, "Give more detail (e.g. list all GMs run, more info about " |
| 1463 | "each test)."); |
epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 1464 | DEFINE_bool(writeChecksumBasedFilenames, false, "When writing out actual images, use checksum-" |
| 1465 | "based filenames, as rebaseline.py will use when downloading them from Google Storage"); |
| 1466 | DEFINE_string(writeJsonSummaryPath, "", "Write a JSON-formatted result summary to this file."); |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1467 | DEFINE_string2(writePath, w, "", "Write rendered images into this directory."); |
scroggo@google.com | 604e0c2 | 2013-04-09 21:25:46 +0000 | [diff] [blame] | 1468 | DEFINE_string2(writePicturePath, p, "", "Write .skp files into this directory."); |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 1469 | DEFINE_int32(pdfJpegQuality, -1, "Encodes images in JPEG at quality level N, " |
| 1470 | "which can be in range 0-100). N = -1 will disable JPEG compression. " |
| 1471 | "Default is N = 100, maximum quality."); |
commit-bot@chromium.org | f4f9df4 | 2013-09-26 20:44:24 +0000 | [diff] [blame] | 1472 | // TODO(edisonn): pass a matrix instead of forcePerspectiveMatrix |
| 1473 | // Either the 9 numbers defining the matrix |
| 1474 | // or probably more readable would be to replace it with a set of a few predicates |
| 1475 | // Like --prerotate 100 200 10 --posttranslate 10, 10 |
| 1476 | // Probably define spacial names like centerx, centery, top, bottom, left, right |
| 1477 | // then we can write something reabable like --rotate centerx centery 90 |
| 1478 | DEFINE_bool(forcePerspectiveMatrix, false, "Force a perspective matrix."); |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 1479 | DEFINE_bool(useDocumentInsteadOfDevice, false, "Use SkDocument::CreateFoo instead of SkFooDevice."); |
edisonn@google.com | 73a7ea3 | 2013-11-11 20:55:15 +0000 | [diff] [blame] | 1480 | DEFINE_int32(pdfRasterDpi, 72, "Scale at which at which the non suported " |
| 1481 | "features in PDF are rasterized. Must be be in range 0-10000. " |
| 1482 | "Default is 72. N = 0 will disable rasterizing features like " |
| 1483 | "text shadows or perspective bitmaps."); |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 1484 | static SkData* encode_to_dct_data(size_t*, const SkBitmap& bitmap) { |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 1485 | // Filter output of warnings that JPEG is not available for the image. |
commit-bot@chromium.org | 608ea65 | 2013-10-03 19:29:21 +0000 | [diff] [blame] | 1486 | if (bitmap.width() >= 65500 || bitmap.height() >= 65500) return NULL; |
| 1487 | if (FLAGS_pdfJpegQuality == -1) return NULL; |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 1488 | |
commit-bot@chromium.org | 608ea65 | 2013-10-03 19:29:21 +0000 | [diff] [blame] | 1489 | SkBitmap bm = bitmap; |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 1490 | #if defined(SK_BUILD_FOR_MAC) |
| 1491 | // Workaround bug #1043 where bitmaps with referenced pixels cause |
| 1492 | // CGImageDestinationFinalize to crash |
| 1493 | SkBitmap copy; |
commit-bot@chromium.org | 608ea65 | 2013-10-03 19:29:21 +0000 | [diff] [blame] | 1494 | bitmap.deepCopyTo(©, bitmap.config()); |
| 1495 | bm = copy; |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 1496 | #endif |
| 1497 | |
commit-bot@chromium.org | 608ea65 | 2013-10-03 19:29:21 +0000 | [diff] [blame] | 1498 | SkPixelRef* pr = bm.pixelRef(); |
| 1499 | if (pr != NULL) { |
| 1500 | SkData* data = pr->refEncodedData(); |
| 1501 | if (data != NULL) { |
commit-bot@chromium.org | 608ea65 | 2013-10-03 19:29:21 +0000 | [diff] [blame] | 1502 | return data; |
| 1503 | } |
| 1504 | } |
| 1505 | |
commit-bot@chromium.org | 608ea65 | 2013-10-03 19:29:21 +0000 | [diff] [blame] | 1506 | return SkImageEncoder::EncodeData(bm, |
| 1507 | SkImageEncoder::kJPEG_Type, |
| 1508 | FLAGS_pdfJpegQuality); |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 1509 | } |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1510 | |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1511 | static int findConfig(const char config[]) { |
| 1512 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { |
| 1513 | if (!strcmp(config, gRec[i].fName)) { |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1514 | return (int) i; |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1515 | } |
| 1516 | } |
| 1517 | return -1; |
| 1518 | } |
| 1519 | |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1520 | static const PDFRasterizerData* findPDFRasterizer(const char rasterizer[]) { |
| 1521 | for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); i++) { |
| 1522 | if (!strcmp(rasterizer, kPDFRasterizers[i].fName)) { |
| 1523 | return &kPDFRasterizers[i]; |
| 1524 | } |
| 1525 | } |
| 1526 | return NULL; |
| 1527 | } |
| 1528 | |
reed@google.com | fb2cd42 | 2013-01-04 14:43:03 +0000 | [diff] [blame] | 1529 | template <typename T> void appendUnique(SkTDArray<T>* array, const T& value) { |
| 1530 | int index = array->find(value); |
| 1531 | if (index < 0) { |
| 1532 | *array->append() = value; |
| 1533 | } |
| 1534 | } |
| 1535 | |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1536 | /** |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1537 | * Run this test in a number of different drawing modes (pipe, |
| 1538 | * deferred, tiled, etc.), confirming that the resulting bitmaps all |
| 1539 | * *exactly* match comparisonBitmap. |
| 1540 | * |
| 1541 | * Returns all errors encountered while doing so. |
| 1542 | */ |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1543 | ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm, const ConfigData &compareConfig, |
| 1544 | const SkBitmap &comparisonBitmap, |
| 1545 | const SkTDArray<SkScalar> &tileGridReplayScales); |
| 1546 | ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm, const ConfigData &compareConfig, |
| 1547 | const SkBitmap &comparisonBitmap, |
| 1548 | const SkTDArray<SkScalar> &tileGridReplayScales) { |
| 1549 | ErrorCombination errorsForAllModes; |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1550 | uint32_t gmFlags = gm->getFlags(); |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1551 | const SkString shortNamePlusConfig = gmmain.make_shortname_plus_config(gm->shortName(), |
| 1552 | compareConfig.fName); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1553 | |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1554 | SkPicture* pict = gmmain.generate_new_picture(gm, kNone_BbhType, 0); |
| 1555 | SkAutoUnref aur(pict); |
| 1556 | if (FLAGS_replay) { |
| 1557 | const char renderModeDescriptor[] = "-replay"; |
| 1558 | if (gmFlags & GM::kSkipPicture_Flag) { |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1559 | gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, |
| 1560 | renderModeDescriptor); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1561 | errorsForAllModes.add(kIntentionallySkipped_ErrorType); |
| 1562 | } else { |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1563 | SkBitmap bitmap; |
| 1564 | gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1565 | errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap( |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1566 | gm->shortName(), compareConfig.fName, renderModeDescriptor, bitmap, |
| 1567 | &comparisonBitmap)); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1568 | } |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1569 | } |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1570 | |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1571 | if (FLAGS_serialize) { |
| 1572 | const char renderModeDescriptor[] = "-serialize"; |
| 1573 | if (gmFlags & GM::kSkipPicture_Flag) { |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1574 | gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, |
| 1575 | renderModeDescriptor); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1576 | errorsForAllModes.add(kIntentionallySkipped_ErrorType); |
| 1577 | } else { |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1578 | SkPicture* repict = gmmain.stream_to_new_picture(*pict); |
| 1579 | SkAutoUnref aurr(repict); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1580 | SkBitmap bitmap; |
| 1581 | gmmain.generate_image_from_picture(gm, compareConfig, repict, &bitmap); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1582 | errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap( |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1583 | gm->shortName(), compareConfig.fName, renderModeDescriptor, bitmap, |
| 1584 | &comparisonBitmap)); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1585 | } |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1586 | } |
| 1587 | |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1588 | if ((1 == FLAGS_writePicturePath.count()) && |
| 1589 | !(gmFlags & GM::kSkipPicture_Flag)) { |
| 1590 | const char* pictureSuffix = "skp"; |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1591 | // TODO(epoger): Make sure this still works even though the |
| 1592 | // filename now contains the config name (it used to contain |
| 1593 | // just the shortName). I think this is actually an |
| 1594 | // *improvement*, because now runs with different configs will |
| 1595 | // write out their SkPictures to separate files rather than |
| 1596 | // overwriting each other. But we should make sure it doesn't |
| 1597 | // break anybody. |
| 1598 | SkString path = gmmain.make_filename(FLAGS_writePicturePath[0], gm->shortName(), |
| 1599 | compareConfig.fName, "", pictureSuffix); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1600 | SkFILEWStream stream(path.c_str()); |
| 1601 | pict->serialize(&stream); |
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 (FLAGS_rtree) { |
| 1605 | const char renderModeDescriptor[] = "-rtree"; |
| 1606 | if (gmFlags & GM::kSkipPicture_Flag) { |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1607 | gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, |
| 1608 | renderModeDescriptor); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1609 | errorsForAllModes.add(kIntentionallySkipped_ErrorType); |
| 1610 | } else { |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1611 | SkPicture* pict = gmmain.generate_new_picture( |
commit-bot@chromium.org | af94d9a | 2013-10-29 21:38:54 +0000 | [diff] [blame] | 1612 | gm, kRTree_BbhType, SkPicture::kOptimizeForClippedPlayback_RecordingFlag); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1613 | SkAutoUnref aur(pict); |
| 1614 | SkBitmap bitmap; |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1615 | gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap); |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1616 | errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap( |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1617 | gm->shortName(), compareConfig.fName, renderModeDescriptor, bitmap, |
| 1618 | &comparisonBitmap)); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1619 | } |
| 1620 | } |
| 1621 | |
| 1622 | if (FLAGS_tileGrid) { |
| 1623 | for(int scaleIndex = 0; scaleIndex < tileGridReplayScales.count(); ++scaleIndex) { |
| 1624 | SkScalar replayScale = tileGridReplayScales[scaleIndex]; |
| 1625 | SkString renderModeDescriptor("-tilegrid"); |
| 1626 | if (SK_Scalar1 != replayScale) { |
| 1627 | renderModeDescriptor += "-scale-"; |
| 1628 | renderModeDescriptor.appendScalar(replayScale); |
| 1629 | } |
| 1630 | |
| 1631 | if ((gmFlags & GM::kSkipPicture_Flag) || |
| 1632 | ((gmFlags & GM::kSkipScaledReplay_Flag) && replayScale != 1)) { |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1633 | gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1634 | renderModeDescriptor.c_str()); |
| 1635 | errorsForAllModes.add(kIntentionallySkipped_ErrorType); |
| 1636 | } else { |
| 1637 | // We record with the reciprocal scale to obtain a replay |
| 1638 | // result that can be validated against comparisonBitmap. |
| 1639 | SkScalar recordScale = SkScalarInvert(replayScale); |
| 1640 | SkPicture* pict = gmmain.generate_new_picture( |
| 1641 | gm, kTileGrid_BbhType, SkPicture::kUsePathBoundsForClip_RecordingFlag, |
| 1642 | recordScale); |
| 1643 | SkAutoUnref aur(pict); |
| 1644 | SkBitmap bitmap; |
| 1645 | // We cannot yet pass 'true' to generate_image_from_picture to |
| 1646 | // perform actual tiled rendering (see Issue 1198 - |
| 1647 | // https://code.google.com/p/skia/issues/detail?id=1198) |
| 1648 | gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap, |
| 1649 | replayScale /*, true */); |
| 1650 | errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap( |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1651 | gm->shortName(), compareConfig.fName, renderModeDescriptor.c_str(), bitmap, |
| 1652 | &comparisonBitmap)); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1653 | } |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1654 | } |
| 1655 | } |
| 1656 | |
| 1657 | // run the pipe centric GM steps |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1658 | if (FLAGS_pipe) { |
| 1659 | errorsForAllModes.add(gmmain.test_pipe_playback(gm, compareConfig, comparisonBitmap, |
| 1660 | FLAGS_simulatePipePlaybackFailure)); |
| 1661 | if (FLAGS_tiledPipe) { |
| 1662 | errorsForAllModes.add(gmmain.test_tiled_pipe_playback(gm, compareConfig, |
| 1663 | comparisonBitmap)); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1664 | } |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1665 | } |
| 1666 | return errorsForAllModes; |
| 1667 | } |
| 1668 | |
commit-bot@chromium.org | 8519548 | 2014-01-13 18:27:59 +0000 | [diff] [blame] | 1669 | |
| 1670 | /** |
| 1671 | * Run this test in a number of different configs (8888, 565, PDF, |
| 1672 | * etc.), confirming that the resulting bitmaps match expectations |
| 1673 | * (which may be different for each config). |
| 1674 | * |
| 1675 | * Returns all errors encountered while doing so. |
| 1676 | */ |
| 1677 | ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm, |
| 1678 | const SkTDArray<size_t> &configs, |
| 1679 | const SkTDArray<const PDFRasterizerData*> &pdfRasterizers, |
| 1680 | const SkTDArray<SkScalar> &tileGridReplayScales, |
| 1681 | GrContextFactory *grFactory); |
| 1682 | ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm, |
| 1683 | const SkTDArray<size_t> &configs, |
| 1684 | const SkTDArray<const PDFRasterizerData*> &pdfRasterizers, |
| 1685 | const SkTDArray<SkScalar> &tileGridReplayScales, |
| 1686 | GrContextFactory *grFactory) { |
| 1687 | const char renderModeDescriptor[] = ""; |
| 1688 | ErrorCombination errorsForAllConfigs; |
| 1689 | uint32_t gmFlags = gm->getFlags(); |
| 1690 | |
| 1691 | for (int i = 0; i < configs.count(); i++) { |
| 1692 | ConfigData config = gRec[configs[i]]; |
| 1693 | const SkString shortNamePlusConfig = gmmain.make_shortname_plus_config(gm->shortName(), |
| 1694 | config.fName); |
| 1695 | |
| 1696 | // Skip any tests that we don't even need to try. |
| 1697 | // If any of these were skipped on a per-GM basis, record them as |
| 1698 | // kIntentionallySkipped. |
| 1699 | if (kPDF_Backend == config.fBackend) { |
| 1700 | if (gmFlags & GM::kSkipPDF_Flag) { |
| 1701 | gmmain.RecordSkippedTest(shortNamePlusConfig, |
| 1702 | renderModeDescriptor, |
| 1703 | config.fBackend); |
| 1704 | errorsForAllConfigs.add(kIntentionallySkipped_ErrorType); |
| 1705 | continue; |
| 1706 | } |
| 1707 | } |
| 1708 | if ((gmFlags & GM::kSkip565_Flag) && |
| 1709 | (kRaster_Backend == config.fBackend) && |
| 1710 | (SkBitmap::kRGB_565_Config == config.fConfig)) { |
| 1711 | gmmain.RecordSkippedTest(shortNamePlusConfig, |
| 1712 | renderModeDescriptor, |
| 1713 | config.fBackend); |
| 1714 | errorsForAllConfigs.add(kIntentionallySkipped_ErrorType); |
| 1715 | continue; |
| 1716 | } |
| 1717 | if (((gmFlags & GM::kSkipGPU_Flag) && kGPU_Backend == config.fBackend) || |
| 1718 | ((gmFlags & GM::kGPUOnly_Flag) && kGPU_Backend != config.fBackend)) { |
| 1719 | gmmain.RecordSkippedTest(shortNamePlusConfig, |
| 1720 | renderModeDescriptor, |
| 1721 | config.fBackend); |
| 1722 | errorsForAllConfigs.add(kIntentionallySkipped_ErrorType); |
| 1723 | continue; |
| 1724 | } |
| 1725 | |
| 1726 | // Now we know that we want to run this test and record its |
| 1727 | // success or failure. |
| 1728 | ErrorCombination errorsForThisConfig; |
| 1729 | GrSurface* gpuTarget = NULL; |
| 1730 | #if SK_SUPPORT_GPU |
| 1731 | SkAutoTUnref<GrSurface> auGpuTarget; |
| 1732 | if ((errorsForThisConfig.isEmpty()) && (kGPU_Backend == config.fBackend)) { |
| 1733 | if (FLAGS_resetGpuContext) { |
| 1734 | grFactory->destroyContexts(); |
| 1735 | } |
| 1736 | GrContext* gr = grFactory->get(config.fGLContextType); |
| 1737 | bool grSuccess = false; |
| 1738 | if (gr) { |
| 1739 | // create a render target to back the device |
| 1740 | GrTextureDesc desc; |
| 1741 | desc.fConfig = kSkia8888_GrPixelConfig; |
| 1742 | desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 1743 | desc.fWidth = gm->getISize().width(); |
| 1744 | desc.fHeight = gm->getISize().height(); |
| 1745 | desc.fSampleCnt = config.fSampleCnt; |
| 1746 | auGpuTarget.reset(gr->createUncachedTexture(desc, NULL, 0)); |
| 1747 | if (NULL != auGpuTarget) { |
| 1748 | gpuTarget = auGpuTarget; |
| 1749 | grSuccess = true; |
| 1750 | // Set the user specified cache limits if non-default. |
| 1751 | size_t bytes; |
| 1752 | int count; |
| 1753 | gr->getTextureCacheLimits(&count, &bytes); |
| 1754 | if (DEFAULT_CACHE_VALUE != gGpuCacheSizeBytes) { |
| 1755 | bytes = static_cast<size_t>(gGpuCacheSizeBytes); |
| 1756 | } |
| 1757 | if (DEFAULT_CACHE_VALUE != gGpuCacheSizeCount) { |
| 1758 | count = gGpuCacheSizeCount; |
| 1759 | } |
| 1760 | gr->setTextureCacheLimits(count, bytes); |
| 1761 | } |
| 1762 | } |
| 1763 | if (!grSuccess) { |
| 1764 | errorsForThisConfig.add(kNoGpuContext_ErrorType); |
| 1765 | } |
| 1766 | } |
| 1767 | #endif |
| 1768 | |
| 1769 | SkBitmap comparisonBitmap; |
| 1770 | |
| 1771 | const char* writePath; |
| 1772 | if (FLAGS_writePath.count() == 1) { |
| 1773 | writePath = FLAGS_writePath[0]; |
| 1774 | } else { |
| 1775 | writePath = NULL; |
| 1776 | } |
| 1777 | |
| 1778 | if (errorsForThisConfig.isEmpty()) { |
| 1779 | errorsForThisConfig.add(gmmain.test_drawing(gm, config, pdfRasterizers, |
| 1780 | writePath, gpuTarget, |
| 1781 | &comparisonBitmap)); |
| 1782 | gmmain.RecordTestResults(errorsForThisConfig, shortNamePlusConfig, ""); |
| 1783 | } |
| 1784 | |
| 1785 | // TODO: run only if gmmain.test_drawing succeeded. |
| 1786 | if (kRaster_Backend == config.fBackend) { |
| 1787 | run_multiple_modes(gmmain, gm, config, comparisonBitmap, tileGridReplayScales); |
| 1788 | } |
| 1789 | |
| 1790 | if (FLAGS_deferred && errorsForThisConfig.isEmpty() && |
| 1791 | (kGPU_Backend == config.fBackend || kRaster_Backend == config.fBackend)) { |
| 1792 | errorsForThisConfig.add(gmmain.test_deferred_drawing(gm, config, comparisonBitmap, |
| 1793 | gpuTarget)); |
| 1794 | } |
| 1795 | |
| 1796 | errorsForAllConfigs.add(errorsForThisConfig); |
| 1797 | } |
| 1798 | return errorsForAllConfigs; |
| 1799 | } |
| 1800 | |
| 1801 | |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 1802 | /** |
epoger@google.com | f711f32 | 2013-10-18 14:55:47 +0000 | [diff] [blame] | 1803 | * Read individual lines from a file, pushing them into the given array. |
| 1804 | * |
| 1805 | * @param filename path to the file to read |
| 1806 | * @param lines array of strings to add the lines to |
| 1807 | * @returns true if able to read lines from the file |
| 1808 | */ |
| 1809 | static bool read_lines_from_file(const char* filename, SkTArray<SkString> &lines) { |
| 1810 | SkAutoTUnref<SkStream> streamWrapper(SkStream::NewFromFile(filename)); |
| 1811 | SkStream *stream = streamWrapper.get(); |
| 1812 | if (!stream) { |
| 1813 | gm_fprintf(stderr, "unable to read file '%s'\n", filename); |
| 1814 | return false; |
| 1815 | } |
| 1816 | |
| 1817 | char c; |
| 1818 | SkString line; |
| 1819 | while (1 == stream->read(&c, 1)) { |
| 1820 | // If we hit either CR or LF, we've completed a line. |
| 1821 | // |
| 1822 | // TODO: If the file uses both CR and LF, this will return an extra blank |
| 1823 | // line for each line of the file. Which is OK for current purposes... |
| 1824 | // |
| 1825 | // TODO: Does this properly handle unicode? It doesn't matter for |
| 1826 | // current purposes... |
| 1827 | if ((c == 0x0d) || (c == 0x0a)) { |
| 1828 | lines.push_back(line); |
| 1829 | line.reset(); |
| 1830 | } else { |
| 1831 | line.append(&c, 1); |
| 1832 | } |
| 1833 | } |
| 1834 | lines.push_back(line); |
| 1835 | return true; |
| 1836 | } |
| 1837 | |
| 1838 | /** |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 1839 | * Return a list of all entries in an array of strings as a single string |
| 1840 | * of this form: |
| 1841 | * "item1", "item2", "item3" |
| 1842 | */ |
| 1843 | SkString list_all(const SkTArray<SkString> &stringArray); |
| 1844 | SkString list_all(const SkTArray<SkString> &stringArray) { |
| 1845 | SkString total; |
| 1846 | for (int i = 0; i < stringArray.count(); i++) { |
| 1847 | if (i > 0) { |
| 1848 | total.append(", "); |
| 1849 | } |
| 1850 | total.append("\""); |
| 1851 | total.append(stringArray[i]); |
| 1852 | total.append("\""); |
| 1853 | } |
| 1854 | return total; |
| 1855 | } |
| 1856 | |
| 1857 | /** |
| 1858 | * Return a list of configuration names, as a single string of this form: |
| 1859 | * "item1", "item2", "item3" |
| 1860 | * |
| 1861 | * @param configs configurations, as a list of indices into gRec |
| 1862 | */ |
| 1863 | SkString list_all_config_names(const SkTDArray<size_t> &configs); |
| 1864 | SkString list_all_config_names(const SkTDArray<size_t> &configs) { |
| 1865 | SkString total; |
| 1866 | for (int i = 0; i < configs.count(); i++) { |
| 1867 | if (i > 0) { |
| 1868 | total.append(", "); |
| 1869 | } |
| 1870 | total.append("\""); |
| 1871 | total.append(gRec[configs[i]].fName); |
| 1872 | total.append("\""); |
| 1873 | } |
| 1874 | return total; |
| 1875 | } |
| 1876 | |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1877 | static bool prepare_subdirectories(const char *root, bool useFileHierarchy, |
| 1878 | const SkTDArray<size_t> &configs, |
| 1879 | const SkTDArray<const PDFRasterizerData*>& pdfRasterizers) { |
epoger@google.com | fdea325 | 2013-05-02 18:24:03 +0000 | [diff] [blame] | 1880 | if (!sk_mkdir(root)) { |
| 1881 | return false; |
| 1882 | } |
| 1883 | if (useFileHierarchy) { |
| 1884 | for (int i = 0; i < configs.count(); i++) { |
| 1885 | ConfigData config = gRec[configs[i]]; |
| 1886 | SkString subdir; |
| 1887 | subdir.appendf("%s%c%s", root, SkPATH_SEPARATOR, config.fName); |
| 1888 | if (!sk_mkdir(subdir.c_str())) { |
| 1889 | return false; |
| 1890 | } |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1891 | |
| 1892 | if (config.fBackend == kPDF_Backend) { |
| 1893 | for (int j = 0; j < pdfRasterizers.count(); j++) { |
| 1894 | SkString pdfSubdir = subdir; |
vandebo@chromium.org | 8fc3766 | 2013-08-21 18:04:09 +0000 | [diff] [blame] | 1895 | pdfSubdir.appendf("-%s", pdfRasterizers[j]->fName); |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1896 | if (!sk_mkdir(pdfSubdir.c_str())) { |
| 1897 | return false; |
| 1898 | } |
| 1899 | } |
| 1900 | } |
epoger@google.com | fdea325 | 2013-05-02 18:24:03 +0000 | [diff] [blame] | 1901 | } |
| 1902 | } |
| 1903 | return true; |
| 1904 | } |
| 1905 | |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 1906 | static bool parse_flags_configs(SkTDArray<size_t>* outConfigs, |
| 1907 | GrContextFactory* grFactory) { |
| 1908 | SkTDArray<size_t> excludeConfigs; |
| 1909 | |
| 1910 | for (int i = 0; i < FLAGS_config.count(); i++) { |
| 1911 | const char* config = FLAGS_config[i]; |
| 1912 | bool exclude = false; |
| 1913 | if (*config == kExcludeConfigChar) { |
| 1914 | exclude = true; |
| 1915 | config += 1; |
| 1916 | } |
| 1917 | int index = findConfig(config); |
| 1918 | if (index >= 0) { |
| 1919 | if (exclude) { |
| 1920 | *excludeConfigs.append() = index; |
| 1921 | } else { |
| 1922 | appendUnique<size_t>(outConfigs, index); |
| 1923 | } |
| 1924 | } else if (0 == strcmp(kDefaultsConfigStr, config)) { |
| 1925 | if (exclude) { |
| 1926 | gm_fprintf(stderr, "%c%s is not allowed.\n", |
| 1927 | kExcludeConfigChar, kDefaultsConfigStr); |
| 1928 | return false; |
| 1929 | } |
| 1930 | for (size_t c = 0; c < SK_ARRAY_COUNT(gRec); ++c) { |
| 1931 | if (gRec[c].fRunByDefault) { |
| 1932 | appendUnique<size_t>(outConfigs, c); |
| 1933 | } |
| 1934 | } |
| 1935 | } else { |
| 1936 | gm_fprintf(stderr, "unrecognized config %s\n", config); |
| 1937 | return false; |
| 1938 | } |
| 1939 | } |
| 1940 | |
| 1941 | for (int i = 0; i < FLAGS_excludeConfig.count(); i++) { |
| 1942 | int index = findConfig(FLAGS_excludeConfig[i]); |
| 1943 | if (index >= 0) { |
| 1944 | *excludeConfigs.append() = index; |
| 1945 | } else { |
| 1946 | gm_fprintf(stderr, "unrecognized excludeConfig %s\n", FLAGS_excludeConfig[i]); |
| 1947 | return false; |
| 1948 | } |
| 1949 | } |
| 1950 | |
| 1951 | if (outConfigs->count() == 0) { |
| 1952 | // if no config is specified by user, add the defaults |
| 1953 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 1954 | if (gRec[i].fRunByDefault) { |
| 1955 | *outConfigs->append() = i; |
| 1956 | } |
| 1957 | } |
| 1958 | } |
| 1959 | // now remove any explicitly excluded configs |
| 1960 | for (int i = 0; i < excludeConfigs.count(); ++i) { |
| 1961 | int index = outConfigs->find(excludeConfigs[i]); |
| 1962 | if (index >= 0) { |
| 1963 | outConfigs->remove(index); |
| 1964 | // now assert that there was only one copy in configs[] |
| 1965 | SkASSERT(outConfigs->find(excludeConfigs[i]) < 0); |
| 1966 | } |
| 1967 | } |
| 1968 | |
| 1969 | #if SK_SUPPORT_GPU |
| 1970 | SkASSERT(grFactory != NULL); |
| 1971 | for (int i = 0; i < outConfigs->count(); ++i) { |
| 1972 | size_t index = (*outConfigs)[i]; |
| 1973 | if (kGPU_Backend == gRec[index].fBackend) { |
| 1974 | GrContext* ctx = grFactory->get(gRec[index].fGLContextType); |
| 1975 | if (NULL == ctx) { |
| 1976 | gm_fprintf(stderr, "GrContext could not be created for config %s." |
| 1977 | " Config will be skipped.\n", gRec[index].fName); |
| 1978 | outConfigs->remove(i); |
| 1979 | --i; |
| 1980 | continue; |
| 1981 | } |
| 1982 | if (gRec[index].fSampleCnt > ctx->getMaxSampleCount()) { |
| 1983 | gm_fprintf(stderr, "Sample count (%d) of config %s is not supported." |
| 1984 | " Config will be skipped.\n", |
| 1985 | gRec[index].fSampleCnt, gRec[index].fName); |
| 1986 | outConfigs->remove(i); |
| 1987 | --i; |
| 1988 | } |
| 1989 | } |
| 1990 | } |
| 1991 | #endif |
| 1992 | |
| 1993 | if (outConfigs->isEmpty()) { |
| 1994 | gm_fprintf(stderr, "No configs to run."); |
| 1995 | return false; |
| 1996 | } |
| 1997 | |
| 1998 | // now show the user the set of configs that will be run. |
| 1999 | SkString configStr("These configs will be run:"); |
| 2000 | // show the user the config that will run. |
| 2001 | for (int i = 0; i < outConfigs->count(); ++i) { |
| 2002 | configStr.appendf(" %s", gRec[(*outConfigs)[i]].fName); |
| 2003 | } |
| 2004 | gm_fprintf(stdout, "%s\n", configStr.c_str()); |
| 2005 | |
| 2006 | return true; |
| 2007 | } |
| 2008 | |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 2009 | static bool parse_flags_pdf_rasterizers(const SkTDArray<size_t>& configs, |
| 2010 | SkTDArray<const PDFRasterizerData*>* outRasterizers) { |
| 2011 | // No need to run this check (and display the PDF rasterizers message) |
| 2012 | // if no PDF backends are in the configs. |
| 2013 | bool configHasPDF = false; |
| 2014 | for (int i = 0; i < configs.count(); i++) { |
| 2015 | if (gRec[configs[i]].fBackend == kPDF_Backend) { |
| 2016 | configHasPDF = true; |
| 2017 | break; |
| 2018 | } |
| 2019 | } |
| 2020 | if (!configHasPDF) { |
| 2021 | return true; |
| 2022 | } |
| 2023 | |
vandebo@chromium.org | f8afb2b | 2013-11-06 16:32:15 +0000 | [diff] [blame] | 2024 | if (FLAGS_pdfRasterizers.count() == 1 && |
| 2025 | !strcmp(FLAGS_pdfRasterizers[0], "default")) { |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 2026 | for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); ++i) { |
| 2027 | if (kPDFRasterizers[i].fRunByDefault) { |
| 2028 | *outRasterizers->append() = &kPDFRasterizers[i]; |
| 2029 | } |
| 2030 | } |
vandebo@chromium.org | f8afb2b | 2013-11-06 16:32:15 +0000 | [diff] [blame] | 2031 | } else { |
| 2032 | for (int i = 0; i < FLAGS_pdfRasterizers.count(); i++) { |
| 2033 | const char* rasterizer = FLAGS_pdfRasterizers[i]; |
| 2034 | const PDFRasterizerData* rasterizerPtr = |
| 2035 | findPDFRasterizer(rasterizer); |
| 2036 | if (rasterizerPtr == NULL) { |
| 2037 | gm_fprintf(stderr, "unrecognized rasterizer %s\n", rasterizer); |
| 2038 | return false; |
| 2039 | } |
| 2040 | appendUnique<const PDFRasterizerData*>(outRasterizers, |
| 2041 | rasterizerPtr); |
| 2042 | } |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 2043 | } |
| 2044 | |
| 2045 | // now show the user the set of configs that will be run. |
| 2046 | SkString configStr("These PDF rasterizers will be run:"); |
| 2047 | // show the user the config that will run. |
| 2048 | for (int i = 0; i < outRasterizers->count(); ++i) { |
| 2049 | configStr.appendf(" %s", (*outRasterizers)[i]->fName); |
| 2050 | } |
| 2051 | gm_fprintf(stdout, "%s\n", configStr.c_str()); |
| 2052 | |
| 2053 | return true; |
| 2054 | } |
| 2055 | |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2056 | static bool parse_flags_ignore_error_types(ErrorCombination* outErrorTypes) { |
| 2057 | if (FLAGS_ignoreErrorTypes.count() > 0) { |
| 2058 | *outErrorTypes = ErrorCombination(); |
| 2059 | for (int i = 0; i < FLAGS_ignoreErrorTypes.count(); i++) { |
| 2060 | ErrorType type; |
| 2061 | const char *name = FLAGS_ignoreErrorTypes[i]; |
| 2062 | if (!getErrorTypeByName(name, &type)) { |
| 2063 | gm_fprintf(stderr, "cannot find ErrorType with name '%s'\n", name); |
| 2064 | return false; |
| 2065 | } else { |
| 2066 | outErrorTypes->add(type); |
| 2067 | } |
| 2068 | } |
| 2069 | } |
| 2070 | return true; |
| 2071 | } |
| 2072 | |
epoger@google.com | 3a882dd | 2013-10-07 18:55:09 +0000 | [diff] [blame] | 2073 | /** |
commit-bot@chromium.org | 3e62ebf | 2014-01-14 02:54:11 +0000 | [diff] [blame] | 2074 | * Replace contents of ignoreTestNames with a list of test names, indicating |
epoger@google.com | 3a882dd | 2013-10-07 18:55:09 +0000 | [diff] [blame] | 2075 | * which tests' failures should be ignored. |
| 2076 | */ |
commit-bot@chromium.org | 3e62ebf | 2014-01-14 02:54:11 +0000 | [diff] [blame] | 2077 | static bool parse_flags_ignore_tests(SkTArray<SkString> &ignoreTestNames) { |
| 2078 | ignoreTestNames.reset(); |
epoger@google.com | f711f32 | 2013-10-18 14:55:47 +0000 | [diff] [blame] | 2079 | |
epoger@google.com | f711f32 | 2013-10-18 14:55:47 +0000 | [diff] [blame] | 2080 | // Parse --ignoreFailuresFile |
| 2081 | for (int i = 0; i < FLAGS_ignoreFailuresFile.count(); i++) { |
| 2082 | SkTArray<SkString> linesFromFile; |
| 2083 | if (!read_lines_from_file(FLAGS_ignoreFailuresFile[i], linesFromFile)) { |
| 2084 | return false; |
| 2085 | } else { |
| 2086 | for (int j = 0; j < linesFromFile.count(); j++) { |
| 2087 | SkString thisLine = linesFromFile[j]; |
| 2088 | if (thisLine.isEmpty() || thisLine.startsWith('#')) { |
| 2089 | // skip this line |
| 2090 | } else { |
commit-bot@chromium.org | 3e62ebf | 2014-01-14 02:54:11 +0000 | [diff] [blame] | 2091 | ignoreTestNames.push_back(thisLine); |
epoger@google.com | f711f32 | 2013-10-18 14:55:47 +0000 | [diff] [blame] | 2092 | } |
| 2093 | } |
| 2094 | } |
| 2095 | } |
| 2096 | |
epoger@google.com | 3a882dd | 2013-10-07 18:55:09 +0000 | [diff] [blame] | 2097 | return true; |
| 2098 | } |
| 2099 | |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2100 | static bool parse_flags_modulo(int* moduloRemainder, int* moduloDivisor) { |
| 2101 | if (FLAGS_modulo.count() == 2) { |
| 2102 | *moduloRemainder = atoi(FLAGS_modulo[0]); |
| 2103 | *moduloDivisor = atoi(FLAGS_modulo[1]); |
| 2104 | if (*moduloRemainder < 0 || *moduloDivisor <= 0 || |
| 2105 | *moduloRemainder >= *moduloDivisor) { |
| 2106 | gm_fprintf(stderr, "invalid modulo values."); |
| 2107 | return false; |
| 2108 | } |
| 2109 | } |
| 2110 | return true; |
| 2111 | } |
| 2112 | |
| 2113 | #if SK_SUPPORT_GPU |
| 2114 | static bool parse_flags_gpu_cache(int* sizeBytes, int* sizeCount) { |
| 2115 | if (FLAGS_gpuCacheSize.count() > 0) { |
| 2116 | if (FLAGS_gpuCacheSize.count() != 2) { |
| 2117 | gm_fprintf(stderr, "--gpuCacheSize requires two arguments\n"); |
| 2118 | return false; |
| 2119 | } |
| 2120 | *sizeBytes = atoi(FLAGS_gpuCacheSize[0]); |
| 2121 | *sizeCount = atoi(FLAGS_gpuCacheSize[1]); |
| 2122 | } else { |
| 2123 | *sizeBytes = DEFAULT_CACHE_VALUE; |
| 2124 | *sizeCount = DEFAULT_CACHE_VALUE; |
| 2125 | } |
| 2126 | return true; |
| 2127 | } |
| 2128 | #endif |
| 2129 | |
| 2130 | static bool parse_flags_tile_grid_replay_scales(SkTDArray<SkScalar>* outScales) { |
| 2131 | *outScales->append() = SK_Scalar1; // By default only test at scale 1.0 |
| 2132 | if (FLAGS_tileGridReplayScales.count() > 0) { |
| 2133 | outScales->reset(); |
| 2134 | for (int i = 0; i < FLAGS_tileGridReplayScales.count(); i++) { |
| 2135 | double val = atof(FLAGS_tileGridReplayScales[i]); |
| 2136 | if (0 < val) { |
| 2137 | *outScales->append() = SkDoubleToScalar(val); |
| 2138 | } |
| 2139 | } |
| 2140 | if (0 == outScales->count()) { |
| 2141 | // Should have at least one scale |
| 2142 | gm_fprintf(stderr, "--tileGridReplayScales requires at least one scale.\n"); |
| 2143 | return false; |
| 2144 | } |
| 2145 | } |
| 2146 | return true; |
| 2147 | } |
| 2148 | |
| 2149 | static bool parse_flags_gmmain_paths(GMMain* gmmain) { |
| 2150 | gmmain->fUseFileHierarchy = FLAGS_hierarchy; |
| 2151 | gmmain->fWriteChecksumBasedFilenames = FLAGS_writeChecksumBasedFilenames; |
| 2152 | |
| 2153 | if (FLAGS_mismatchPath.count() == 1) { |
| 2154 | gmmain->fMismatchPath = FLAGS_mismatchPath[0]; |
| 2155 | } |
| 2156 | |
| 2157 | if (FLAGS_missingExpectationsPath.count() == 1) { |
| 2158 | gmmain->fMissingExpectationsPath = FLAGS_missingExpectationsPath[0]; |
| 2159 | } |
| 2160 | |
| 2161 | if (FLAGS_readPath.count() == 1) { |
| 2162 | const char* readPath = FLAGS_readPath[0]; |
| 2163 | if (!sk_exists(readPath)) { |
| 2164 | gm_fprintf(stderr, "readPath %s does not exist!\n", readPath); |
| 2165 | return false; |
| 2166 | } |
| 2167 | if (sk_isdir(readPath)) { |
| 2168 | if (FLAGS_verbose) { |
| 2169 | gm_fprintf(stdout, "reading from %s\n", readPath); |
| 2170 | } |
| 2171 | gmmain->fExpectationsSource.reset(SkNEW_ARGS( |
| 2172 | IndividualImageExpectationsSource, (readPath))); |
| 2173 | } else { |
| 2174 | if (FLAGS_verbose) { |
| 2175 | gm_fprintf(stdout, "reading expectations from JSON summary file %s\n", readPath); |
| 2176 | } |
| 2177 | gmmain->fExpectationsSource.reset(SkNEW_ARGS(JsonExpectationsSource, (readPath))); |
| 2178 | } |
| 2179 | } |
| 2180 | return true; |
| 2181 | } |
| 2182 | |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2183 | static bool parse_flags_resource_path() { |
| 2184 | if (FLAGS_resourcePath.count() == 1) { |
| 2185 | GM::SetResourcePath(FLAGS_resourcePath[0]); |
| 2186 | } |
| 2187 | return true; |
| 2188 | } |
| 2189 | |
| 2190 | static bool parse_flags_jpeg_quality() { |
| 2191 | if (FLAGS_pdfJpegQuality < -1 || FLAGS_pdfJpegQuality > 100) { |
| 2192 | gm_fprintf(stderr, "%s\n", "pdfJpegQuality must be in [-1 .. 100] range."); |
| 2193 | return false; |
| 2194 | } |
| 2195 | return true; |
| 2196 | } |
| 2197 | |
epoger@google.com | 0b62b3d | 2013-03-20 17:59:28 +0000 | [diff] [blame] | 2198 | int tool_main(int argc, char** argv); |
| 2199 | int tool_main(int argc, char** argv) { |
| 2200 | |
commit-bot@chromium.org | 6dda827 | 2014-01-23 17:21:19 +0000 | [diff] [blame] | 2201 | SkString usage; |
| 2202 | usage.printf("Run the golden master tests.\n"); |
| 2203 | SkCommandLineFlags::SetUsage(usage.c_str()); |
| 2204 | SkCommandLineFlags::Parse(argc, argv); |
| 2205 | |
epoger@google.com | 0b62b3d | 2013-03-20 17:59:28 +0000 | [diff] [blame] | 2206 | #if SK_ENABLE_INST_COUNT |
commit-bot@chromium.org | 6dda827 | 2014-01-23 17:21:19 +0000 | [diff] [blame] | 2207 | if (FLAGS_leaks) { |
| 2208 | gPrintInstCount = true; |
| 2209 | } |
epoger@google.com | 0b62b3d | 2013-03-20 17:59:28 +0000 | [diff] [blame] | 2210 | #endif |
| 2211 | |
| 2212 | SkGraphics::Init(); |
| 2213 | // we don't need to see this during a run |
| 2214 | gSkSuppressFontCachePurgeSpew = true; |
| 2215 | |
| 2216 | setSystemPreferences(); |
| 2217 | GMMain gmmain; |
| 2218 | |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2219 | SkTDArray<size_t> configs; |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 2220 | |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 2221 | int moduloRemainder = -1; |
| 2222 | int moduloDivisor = -1; |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 2223 | SkTDArray<const PDFRasterizerData*> pdfRasterizers; |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 2224 | SkTDArray<SkScalar> tileGridReplayScales; |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 2225 | #if SK_SUPPORT_GPU |
| 2226 | GrContextFactory* grFactory = new GrContextFactory; |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 2227 | #else |
| 2228 | GrContextFactory* grFactory = NULL; |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 2229 | #endif |
| 2230 | |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2231 | if (!parse_flags_modulo(&moduloRemainder, &moduloDivisor) || |
| 2232 | !parse_flags_ignore_error_types(&gmmain.fIgnorableErrorTypes) || |
commit-bot@chromium.org | 3e62ebf | 2014-01-14 02:54:11 +0000 | [diff] [blame] | 2233 | !parse_flags_ignore_tests(gmmain.fIgnorableTestNames) || |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2234 | #if SK_SUPPORT_GPU |
| 2235 | !parse_flags_gpu_cache(&gGpuCacheSizeBytes, &gGpuCacheSizeCount) || |
| 2236 | #endif |
| 2237 | !parse_flags_tile_grid_replay_scales(&tileGridReplayScales) || |
| 2238 | !parse_flags_resource_path() || |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2239 | !parse_flags_jpeg_quality() || |
| 2240 | !parse_flags_configs(&configs, grFactory) || |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 2241 | !parse_flags_pdf_rasterizers(configs, &pdfRasterizers) || |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2242 | !parse_flags_gmmain_paths(&gmmain)) { |
bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 2243 | return -1; |
| 2244 | } |
| 2245 | |
epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 2246 | if (FLAGS_verbose) { |
| 2247 | if (FLAGS_writePath.count() == 1) { |
| 2248 | gm_fprintf(stdout, "writing to %s\n", FLAGS_writePath[0]); |
| 2249 | } |
epoger@google.com | fdea325 | 2013-05-02 18:24:03 +0000 | [diff] [blame] | 2250 | if (NULL != gmmain.fMismatchPath) { |
| 2251 | gm_fprintf(stdout, "writing mismatches to %s\n", gmmain.fMismatchPath); |
| 2252 | } |
epoger@google.com | 5f99545 | 2013-06-21 18:16:47 +0000 | [diff] [blame] | 2253 | if (NULL != gmmain.fMissingExpectationsPath) { |
| 2254 | gm_fprintf(stdout, "writing images without expectations to %s\n", |
| 2255 | gmmain.fMissingExpectationsPath); |
| 2256 | } |
epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 2257 | if (FLAGS_writePicturePath.count() == 1) { |
| 2258 | gm_fprintf(stdout, "writing pictures to %s\n", FLAGS_writePicturePath[0]); |
| 2259 | } |
| 2260 | if (FLAGS_resourcePath.count() == 1) { |
| 2261 | gm_fprintf(stdout, "reading resources from %s\n", FLAGS_resourcePath[0]); |
| 2262 | } |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 2263 | } |
| 2264 | |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 2265 | int gmsRun = 0; |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 2266 | int gmIndex = -1; |
| 2267 | SkString moduloStr; |
| 2268 | |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 2269 | // If we will be writing out files, prepare subdirectories. |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 2270 | if (FLAGS_writePath.count() == 1) { |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 2271 | if (!prepare_subdirectories(FLAGS_writePath[0], gmmain.fUseFileHierarchy, |
| 2272 | configs, pdfRasterizers)) { |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 2273 | return -1; |
| 2274 | } |
epoger@google.com | fdea325 | 2013-05-02 18:24:03 +0000 | [diff] [blame] | 2275 | } |
| 2276 | if (NULL != gmmain.fMismatchPath) { |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 2277 | if (!prepare_subdirectories(gmmain.fMismatchPath, gmmain.fUseFileHierarchy, |
| 2278 | configs, pdfRasterizers)) { |
epoger@google.com | fdea325 | 2013-05-02 18:24:03 +0000 | [diff] [blame] | 2279 | return -1; |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 2280 | } |
| 2281 | } |
epoger@google.com | 5f99545 | 2013-06-21 18:16:47 +0000 | [diff] [blame] | 2282 | if (NULL != gmmain.fMissingExpectationsPath) { |
| 2283 | if (!prepare_subdirectories(gmmain.fMissingExpectationsPath, gmmain.fUseFileHierarchy, |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 2284 | configs, pdfRasterizers)) { |
epoger@google.com | 5f99545 | 2013-06-21 18:16:47 +0000 | [diff] [blame] | 2285 | return -1; |
| 2286 | } |
| 2287 | } |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 2288 | |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 2289 | Iter iter; |
| 2290 | GM* gm; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 2291 | while ((gm = iter.next()) != NULL) { |
commit-bot@chromium.org | f4f9df4 | 2013-09-26 20:44:24 +0000 | [diff] [blame] | 2292 | if (FLAGS_forcePerspectiveMatrix) { |
| 2293 | SkMatrix perspective; |
| 2294 | perspective.setIdentity(); |
| 2295 | perspective.setPerspY(SkScalarDiv(SK_Scalar1, SkIntToScalar(1000))); |
| 2296 | perspective.setSkewX(SkScalarDiv(SkIntToScalar(8), |
| 2297 | SkIntToScalar(25))); |
| 2298 | |
| 2299 | gm->setStarterMatrix(perspective); |
skia.committer@gmail.com | 65caeaf | 2013-09-27 07:01:29 +0000 | [diff] [blame] | 2300 | } |
scroggo@google.com | 7fd2d70 | 2013-04-16 19:11:14 +0000 | [diff] [blame] | 2301 | SkAutoTDelete<GM> adgm(gm); |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 2302 | ++gmIndex; |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 2303 | if (moduloRemainder >= 0) { |
| 2304 | if ((gmIndex % moduloDivisor) != moduloRemainder) { |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 2305 | continue; |
| 2306 | } |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 2307 | moduloStr.printf("[%d.%d] ", gmIndex, moduloDivisor); |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 2308 | } |
| 2309 | |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 2310 | const char* shortName = gm->shortName(); |
sglez@google.com | 586db93 | 2013-07-24 17:24:23 +0000 | [diff] [blame] | 2311 | |
commit-bot@chromium.org | a6f37e7 | 2013-08-30 15:52:46 +0000 | [diff] [blame] | 2312 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, shortName)) { |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 2313 | continue; |
| 2314 | } |
| 2315 | |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 2316 | gmsRun++; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 2317 | SkISize size = gm->getISize(); |
epoger@google.com | bcbf5aa | 2013-04-12 02:11:54 +0000 | [diff] [blame] | 2318 | gm_fprintf(stdout, "%sdrawing... %s [%d %d]\n", moduloStr.c_str(), shortName, |
| 2319 | size.width(), size.height()); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 2320 | |
commit-bot@chromium.org | 8519548 | 2014-01-13 18:27:59 +0000 | [diff] [blame] | 2321 | run_multiple_configs(gmmain, gm, configs, pdfRasterizers, tileGridReplayScales, grFactory); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 2322 | } |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 2323 | |
| 2324 | SkTArray<SkString> modes; |
| 2325 | gmmain.GetRenderModesEncountered(modes); |
commit-bot@chromium.org | 8519548 | 2014-01-13 18:27:59 +0000 | [diff] [blame] | 2326 | int modeCount = modes.count(); |
| 2327 | |
| 2328 | // Now that we have run all the tests and thus know the full set of renderModes that we |
| 2329 | // tried to run, we can call RecordTestResults() to record the cases in which we skipped |
| 2330 | // ALL renderModes. |
| 2331 | // See http://skbug.com/1994 and https://codereview.chromium.org/129203002/ |
| 2332 | int testCount = gmmain.fTestsSkippedOnAllRenderModes.count(); |
| 2333 | for (int testNum = 0; testNum < testCount; ++testNum) { |
| 2334 | const SkString &shortNamePlusConfig = gmmain.fTestsSkippedOnAllRenderModes[testNum]; |
| 2335 | for (int modeNum = 0; modeNum < modeCount; ++modeNum) { |
| 2336 | gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, |
| 2337 | modes[modeNum].c_str()); |
| 2338 | } |
| 2339 | } |
| 2340 | |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 2341 | bool reportError = false; |
| 2342 | if (gmmain.NumSignificantErrors() > 0) { |
| 2343 | reportError = true; |
| 2344 | } |
commit-bot@chromium.org | 8519548 | 2014-01-13 18:27:59 +0000 | [diff] [blame] | 2345 | |
| 2346 | // We test every GM against every config, and for every raster config also test every mode. |
| 2347 | int rasterConfigs = 0; |
| 2348 | for (int i = 0; i < configs.count(); i++) { |
| 2349 | if (gRec[configs[i]].fBackend == kRaster_Backend) { |
| 2350 | rasterConfigs++; |
| 2351 | } |
| 2352 | } |
| 2353 | // For raster configs, we run all renderModes; for non-raster configs, just default renderMode |
| 2354 | const int expectedNumberOfTests = rasterConfigs * gmsRun * modeCount |
| 2355 | + (configs.count() - rasterConfigs) * gmsRun; |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 2356 | |
| 2357 | // Output summary to stdout. |
epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame] | 2358 | if (FLAGS_verbose) { |
| 2359 | gm_fprintf(stdout, "Ran %d GMs\n", gmsRun); |
| 2360 | gm_fprintf(stdout, "... over %2d configs [%s]\n", configs.count(), |
| 2361 | list_all_config_names(configs).c_str()); |
commit-bot@chromium.org | 8519548 | 2014-01-13 18:27:59 +0000 | [diff] [blame] | 2362 | gm_fprintf(stdout, "... and %2d modes [%s]\n", modeCount, list_all(modes).c_str()); |
epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame] | 2363 | gm_fprintf(stdout, "... so there should be a total of %d tests.\n", expectedNumberOfTests); |
| 2364 | } |
| 2365 | gmmain.ListErrors(FLAGS_verbose); |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 2366 | |
epoger@google.com | 07947d9 | 2013-04-11 15:41:02 +0000 | [diff] [blame] | 2367 | // TODO(epoger): Enable this check for Android, too, once we resolve |
| 2368 | // https://code.google.com/p/skia/issues/detail?id=1222 |
| 2369 | // ('GM is unexpectedly skipping tests on Android') |
| 2370 | #ifndef SK_BUILD_FOR_ANDROID |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 2371 | if (expectedNumberOfTests != gmmain.fTestsRun) { |
| 2372 | gm_fprintf(stderr, "expected %d tests, but ran or skipped %d tests\n", |
| 2373 | expectedNumberOfTests, gmmain.fTestsRun); |
| 2374 | reportError = true; |
| 2375 | } |
| 2376 | #endif |
| 2377 | |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 2378 | if (FLAGS_writeJsonSummaryPath.count() == 1) { |
epoger@google.com | 76c913d | 2013-04-26 15:06:44 +0000 | [diff] [blame] | 2379 | Json::Value root = CreateJsonTree( |
| 2380 | gmmain.fJsonExpectedResults, |
| 2381 | gmmain.fJsonActualResults_Failed, gmmain.fJsonActualResults_FailureIgnored, |
| 2382 | gmmain.fJsonActualResults_NoComparison, gmmain.fJsonActualResults_Succeeded); |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 2383 | std::string jsonStdString = root.toStyledString(); |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 2384 | SkFILEWStream stream(FLAGS_writeJsonSummaryPath[0]); |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 2385 | stream.write(jsonStdString.c_str(), jsonStdString.length()); |
| 2386 | } |
| 2387 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 2388 | #if SK_SUPPORT_GPU |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 2389 | |
robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 2390 | #if GR_CACHE_STATS |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 2391 | for (int i = 0; i < configs.count(); i++) { |
| 2392 | ConfigData config = gRec[configs[i]]; |
| 2393 | |
epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 2394 | if (FLAGS_verbose && (kGPU_Backend == config.fBackend)) { |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 2395 | GrContext* gr = grFactory->get(config.fGLContextType); |
| 2396 | |
epoger@google.com | 5efdd0c | 2013-03-13 14:18:40 +0000 | [diff] [blame] | 2397 | gm_fprintf(stdout, "config: %s %x\n", config.fName, gr); |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 2398 | gr->printCacheStats(); |
| 2399 | } |
| 2400 | } |
| 2401 | #endif |
| 2402 | |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 2403 | delete grFactory; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 2404 | #endif |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 2405 | SkGraphics::Term(); |
| 2406 | |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 2407 | return (reportError) ? -1 : 0; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 2408 | } |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 2409 | |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 2410 | void GMMain::installFilter(SkCanvas* canvas) { |
| 2411 | if (FLAGS_forceBWtext) { |
| 2412 | canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); |
| 2413 | } |
| 2414 | } |
| 2415 | |
borenet@google.com | 7158e6a | 2012-11-01 17:43:44 +0000 | [diff] [blame] | 2416 | #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 2417 | int main(int argc, char * const argv[]) { |
| 2418 | return tool_main(argc, (char**) argv); |
| 2419 | } |
| 2420 | #endif |