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