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 | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 37 | #include "SkPictureRecorder.h" |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 38 | #include "SkRefCnt.h" |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 39 | #include "SkScalar.h" |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 40 | #include "SkStream.h" |
epoger@google.com | f711f32 | 2013-10-18 14:55:47 +0000 | [diff] [blame] | 41 | #include "SkString.h" |
reed@google.com | 11db6fa | 2014-02-04 15:30:57 +0000 | [diff] [blame] | 42 | #include "SkSurface.h" |
bsalomon@google.com | 2a48c3a | 2012-08-03 14:54:45 +0000 | [diff] [blame] | 43 | #include "SkTArray.h" |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 44 | #include "SkTDict.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 | |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 72 | DECLARE_bool(useDocumentInsteadOfDevice); |
reed@google.com | 8923c6c | 2011-11-08 14:59:38 +0000 | [diff] [blame] | 73 | |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 74 | #ifdef SK_SUPPORT_PDF |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 75 | #include "SkPDFDevice.h" |
| 76 | #include "SkPDFDocument.h" |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 77 | #endif |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 78 | |
epoger@google.com | e3cc2eb | 2012-01-18 20:11:13 +0000 | [diff] [blame] | 79 | // Until we resolve http://code.google.com/p/skia/issues/detail?id=455 , |
| 80 | // stop writing out XPS-format image baselines in gm. |
| 81 | #undef SK_SUPPORT_XPS |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 82 | #ifdef SK_SUPPORT_XPS |
| 83 | #include "SkXPSDevice.h" |
| 84 | #endif |
| 85 | |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 86 | #ifdef SK_BUILD_FOR_MAC |
| 87 | #include "SkCGUtils.h" |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 88 | #endif |
| 89 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 90 | using namespace skiagm; |
| 91 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 92 | class Iter { |
| 93 | public: |
| 94 | Iter() { |
bsalomon@google.com | 3914958 | 2011-06-13 21:55:32 +0000 | [diff] [blame] | 95 | this->reset(); |
| 96 | } |
| 97 | |
| 98 | void reset() { |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 99 | fReg = GMRegistry::Head(); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 100 | } |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 101 | |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 102 | GM* next() { |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 103 | if (fReg) { |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 104 | GMRegistry::Factory fact = fReg->factory(); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 105 | fReg = fReg->next(); |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 106 | return fact(0); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 107 | } |
| 108 | return NULL; |
| 109 | } |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 110 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 111 | static int Count() { |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 112 | const GMRegistry* reg = GMRegistry::Head(); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 113 | int count = 0; |
| 114 | while (reg) { |
| 115 | count += 1; |
| 116 | reg = reg->next(); |
| 117 | } |
| 118 | return count; |
| 119 | } |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 120 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 121 | private: |
| 122 | const GMRegistry* fReg; |
| 123 | }; |
| 124 | |
epoger@google.com | ce057fe | 2013-05-14 15:17:46 +0000 | [diff] [blame] | 125 | // TODO(epoger): Right now, various places in this code assume that all the |
| 126 | // image files read/written by GM use this file extension. |
| 127 | // Search for references to this constant to find these assumptions. |
| 128 | const static char kPNG_FileExtension[] = "png"; |
| 129 | |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 130 | enum Backend { |
junov@chromium.org | 3cb834b | 2012-12-13 16:39:53 +0000 | [diff] [blame] | 131 | kRaster_Backend, |
| 132 | kGPU_Backend, |
| 133 | kPDF_Backend, |
| 134 | kXPS_Backend, |
| 135 | }; |
| 136 | |
| 137 | enum BbhType { |
| 138 | kNone_BbhType, |
| 139 | kRTree_BbhType, |
| 140 | kTileGrid_BbhType, |
commit-bot@chromium.org | d393b17 | 2014-04-16 16:02:10 +0000 | [diff] [blame] | 141 | kQuadTree_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 | 28fcae2 | 2014-04-11 17:15:40 +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 | 28fcae2 | 2014-04-11 17:15:40 +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); |
commit-bot@chromium.org | 466f5f3 | 2014-05-27 21:30:37 +0000 | [diff] [blame] | 564 | const SkImageInfo info = bitmap->info(); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 565 | |
reed@google.com | 11db6fa | 2014-02-04 15:30:57 +0000 | [diff] [blame] | 566 | SkAutoTUnref<SkSurface> surface; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 567 | SkAutoTUnref<SkCanvas> canvas; |
| 568 | |
| 569 | if (gRec.fBackend == kRaster_Backend) { |
reed@google.com | 11db6fa | 2014-02-04 15:30:57 +0000 | [diff] [blame] | 570 | surface.reset(SkSurface::NewRasterDirect(info, |
| 571 | bitmap->getPixels(), |
| 572 | bitmap->rowBytes())); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 573 | if (deferred) { |
reed@google.com | 11db6fa | 2014-02-04 15:30:57 +0000 | [diff] [blame] | 574 | canvas.reset(SkDeferredCanvas::Create(surface)); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 575 | } else { |
reed@google.com | 11db6fa | 2014-02-04 15:30:57 +0000 | [diff] [blame] | 576 | canvas.reset(SkRef(surface->getCanvas())); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 577 | } |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 578 | invokeGM(gm, canvas, false, deferred); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 579 | canvas->flush(); |
| 580 | } |
| 581 | #if SK_SUPPORT_GPU |
| 582 | else { // GPU |
reed@google.com | 11db6fa | 2014-02-04 15:30:57 +0000 | [diff] [blame] | 583 | surface.reset(SkSurface::NewRenderTargetDirect(gpuTarget->asRenderTarget())); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 584 | if (deferred) { |
reed@google.com | 11db6fa | 2014-02-04 15:30:57 +0000 | [diff] [blame] | 585 | canvas.reset(SkDeferredCanvas::Create(surface)); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 586 | } else { |
reed@google.com | 11db6fa | 2014-02-04 15:30:57 +0000 | [diff] [blame] | 587 | canvas.reset(SkRef(surface->getCanvas())); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 588 | } |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 589 | invokeGM(gm, canvas, false, deferred); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 590 | // the device is as large as the current rendertarget, so |
| 591 | // we explicitly only readback the amount we expect (in |
| 592 | // size) overwrite our previous allocation |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 593 | bitmap->setInfo(SkImageInfo::MakeN32Premul(size.fWidth, size.fHeight)); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 594 | canvas->readPixels(bitmap, 0, 0); |
| 595 | } |
| 596 | #endif |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 597 | complete_bitmap(bitmap); |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 598 | return kEmpty_ErrorCombination; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | static void generate_image_from_picture(GM* gm, const ConfigData& gRec, |
junov@chromium.org | c938c48 | 2012-12-19 15:24:38 +0000 | [diff] [blame] | 602 | SkPicture* pict, SkBitmap* bitmap, |
robertphillips@google.com | 5a7d029 | 2013-04-02 15:18:41 +0000 | [diff] [blame] | 603 | SkScalar scale = SK_Scalar1, |
| 604 | bool tile = false) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 605 | SkISize size = gm->getISize(); |
| 606 | setup_bitmap(gRec, size, bitmap); |
robertphillips@google.com | 5a7d029 | 2013-04-02 15:18:41 +0000 | [diff] [blame] | 607 | |
| 608 | if (tile) { |
| 609 | // Generate the result image by rendering to tiles and accumulating |
| 610 | // the results in 'bitmap' |
| 611 | |
skia.committer@gmail.com | 041e2db | 2013-04-03 07:01:14 +0000 | [diff] [blame] | 612 | // This 16x16 tiling matches the settings applied to 'pict' in |
robertphillips@google.com | 5a7d029 | 2013-04-02 15:18:41 +0000 | [diff] [blame] | 613 | // 'generate_new_picture' |
| 614 | SkISize tileSize = SkISize::Make(16, 16); |
| 615 | |
| 616 | SkBitmap tileBM; |
| 617 | setup_bitmap(gRec, tileSize, &tileBM); |
| 618 | SkCanvas tileCanvas(tileBM); |
| 619 | installFilter(&tileCanvas); |
| 620 | |
| 621 | SkCanvas bmpCanvas(*bitmap); |
| 622 | SkPaint bmpPaint; |
| 623 | bmpPaint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 624 | |
| 625 | for (int yTile = 0; yTile < (size.height()+15)/16; ++yTile) { |
| 626 | for (int xTile = 0; xTile < (size.width()+15)/16; ++xTile) { |
| 627 | int saveCount = tileCanvas.save(); |
| 628 | SkMatrix mat(tileCanvas.getTotalMatrix()); |
skia.committer@gmail.com | 041e2db | 2013-04-03 07:01:14 +0000 | [diff] [blame] | 629 | mat.postTranslate(SkIntToScalar(-xTile*tileSize.width()), |
robertphillips@google.com | 5a7d029 | 2013-04-02 15:18:41 +0000 | [diff] [blame] | 630 | SkIntToScalar(-yTile*tileSize.height())); |
| 631 | tileCanvas.setMatrix(mat); |
| 632 | pict->draw(&tileCanvas); |
| 633 | tileCanvas.flush(); |
| 634 | tileCanvas.restoreToCount(saveCount); |
skia.committer@gmail.com | 041e2db | 2013-04-03 07:01:14 +0000 | [diff] [blame] | 635 | bmpCanvas.drawBitmap(tileBM, |
| 636 | SkIntToScalar(xTile * tileSize.width()), |
robertphillips@google.com | 5a7d029 | 2013-04-02 15:18:41 +0000 | [diff] [blame] | 637 | SkIntToScalar(yTile * tileSize.height()), |
| 638 | &bmpPaint); |
| 639 | } |
| 640 | } |
| 641 | } else { |
| 642 | SkCanvas canvas(*bitmap); |
| 643 | installFilter(&canvas); |
| 644 | canvas.scale(scale, scale); |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 645 | canvas.drawPicture(pict); |
robertphillips@google.com | 5a7d029 | 2013-04-02 15:18:41 +0000 | [diff] [blame] | 646 | complete_bitmap(bitmap); |
| 647 | } |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 648 | } |
| 649 | |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 650 | static bool generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 651 | #ifdef SK_SUPPORT_PDF |
| 652 | SkMatrix initialTransform = gm->getInitialTransform(); |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 653 | if (FLAGS_useDocumentInsteadOfDevice) { |
| 654 | SkISize pageISize = gm->getISize(); |
edisonn@google.com | 73a7ea3 | 2013-11-11 20:55:15 +0000 | [diff] [blame] | 655 | SkAutoTUnref<SkDocument> pdfDoc( |
| 656 | SkDocument::CreatePDF(&pdf, NULL, |
| 657 | encode_to_dct_data, |
| 658 | SkIntToScalar(FLAGS_pdfRasterDpi))); |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 659 | |
| 660 | if (!pdfDoc.get()) { |
| 661 | return false; |
| 662 | } |
| 663 | |
| 664 | SkCanvas* canvas = NULL; |
| 665 | canvas = pdfDoc->beginPage(SkIntToScalar(pageISize.width()), |
| 666 | SkIntToScalar(pageISize.height())); |
| 667 | canvas->concat(initialTransform); |
| 668 | |
| 669 | invokeGM(gm, canvas, true, false); |
| 670 | |
| 671 | return pdfDoc->close(); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 672 | } else { |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 673 | SkISize pageSize = gm->getISize(); |
| 674 | SkPDFDevice* dev = NULL; |
| 675 | if (initialTransform.isIdentity()) { |
| 676 | dev = new SkPDFDevice(pageSize, pageSize, initialTransform); |
| 677 | } else { |
| 678 | SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()), |
| 679 | SkIntToScalar(pageSize.height())); |
| 680 | initialTransform.mapRect(&content); |
| 681 | content.intersect(0, 0, SkIntToScalar(pageSize.width()), |
| 682 | SkIntToScalar(pageSize.height())); |
| 683 | SkISize contentSize = |
| 684 | SkISize::Make(SkScalarRoundToInt(content.width()), |
| 685 | SkScalarRoundToInt(content.height())); |
| 686 | dev = new SkPDFDevice(pageSize, contentSize, initialTransform); |
| 687 | } |
| 688 | dev->setDCTEncoder(encode_to_dct_data); |
edisonn@google.com | 73a7ea3 | 2013-11-11 20:55:15 +0000 | [diff] [blame] | 689 | dev->setRasterDpi(SkIntToScalar(FLAGS_pdfRasterDpi)); |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 690 | SkAutoUnref aur(dev); |
| 691 | SkCanvas c(dev); |
| 692 | invokeGM(gm, &c, true, false); |
| 693 | SkPDFDocument doc; |
| 694 | doc.appendPage(dev); |
| 695 | doc.emitPDF(&pdf); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 696 | } |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 697 | #endif // SK_SUPPORT_PDF |
| 698 | return true; // Do not report failure if pdf is not supported. |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) { |
| 702 | #ifdef SK_SUPPORT_XPS |
| 703 | SkISize size = gm->getISize(); |
| 704 | |
| 705 | SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()), |
| 706 | SkIntToScalar(size.height())); |
| 707 | static const SkScalar inchesPerMeter = SkScalarDiv(10000, 254); |
| 708 | static const SkScalar upm = 72 * inchesPerMeter; |
| 709 | SkVector unitsPerMeter = SkPoint::Make(upm, upm); |
| 710 | static const SkScalar ppm = 200 * inchesPerMeter; |
| 711 | SkVector pixelsPerMeter = SkPoint::Make(ppm, ppm); |
| 712 | |
| 713 | SkXPSDevice* dev = new SkXPSDevice(); |
| 714 | SkAutoUnref aur(dev); |
| 715 | |
| 716 | SkCanvas c(dev); |
| 717 | dev->beginPortfolio(&xps); |
| 718 | dev->beginSheet(unitsPerMeter, pixelsPerMeter, trimSize); |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 719 | invokeGM(gm, &c, false, false); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 720 | dev->endSheet(); |
| 721 | dev->endPortfolio(); |
| 722 | |
| 723 | #endif |
| 724 | } |
| 725 | |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 726 | /** |
epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 727 | * Log more detail about the mistmatch between expectedBitmap and |
| 728 | * actualBitmap. |
| 729 | */ |
| 730 | void report_bitmap_diffs(const SkBitmap& expectedBitmap, const SkBitmap& actualBitmap, |
| 731 | const char *testName) { |
| 732 | const int expectedWidth = expectedBitmap.width(); |
| 733 | const int expectedHeight = expectedBitmap.height(); |
| 734 | const int width = actualBitmap.width(); |
| 735 | const int height = actualBitmap.height(); |
| 736 | if ((expectedWidth != width) || (expectedHeight != height)) { |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 737 | SkDebugf("---- %s: dimension mismatch -- expected [%d %d], actual [%d %d]\n", |
| 738 | testName, expectedWidth, expectedHeight, width, height); |
epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 739 | return; |
| 740 | } |
| 741 | |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 742 | if ((kN32_SkColorType != expectedBitmap.colorType()) || |
| 743 | (kN32_SkColorType != actualBitmap.colorType())) { |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 744 | SkDebugf("---- %s: not computing max per-channel pixel mismatch because non-8888\n", |
| 745 | testName); |
epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 746 | return; |
| 747 | } |
| 748 | |
| 749 | SkAutoLockPixels alp0(expectedBitmap); |
| 750 | SkAutoLockPixels alp1(actualBitmap); |
| 751 | int errR = 0; |
| 752 | int errG = 0; |
| 753 | int errB = 0; |
| 754 | int errA = 0; |
| 755 | int differingPixels = 0; |
| 756 | |
| 757 | for (int y = 0; y < height; ++y) { |
| 758 | const SkPMColor* expectedPixelPtr = expectedBitmap.getAddr32(0, y); |
| 759 | const SkPMColor* actualPixelPtr = actualBitmap.getAddr32(0, y); |
| 760 | for (int x = 0; x < width; ++x) { |
| 761 | SkPMColor expectedPixel = *expectedPixelPtr++; |
| 762 | SkPMColor actualPixel = *actualPixelPtr++; |
| 763 | if (expectedPixel != actualPixel) { |
| 764 | differingPixels++; |
| 765 | errR = SkMax32(errR, SkAbs32((int)SkGetPackedR32(expectedPixel) - |
| 766 | (int)SkGetPackedR32(actualPixel))); |
| 767 | errG = SkMax32(errG, SkAbs32((int)SkGetPackedG32(expectedPixel) - |
| 768 | (int)SkGetPackedG32(actualPixel))); |
| 769 | errB = SkMax32(errB, SkAbs32((int)SkGetPackedB32(expectedPixel) - |
| 770 | (int)SkGetPackedB32(actualPixel))); |
| 771 | errA = SkMax32(errA, SkAbs32((int)SkGetPackedA32(expectedPixel) - |
| 772 | (int)SkGetPackedA32(actualPixel))); |
| 773 | } |
| 774 | } |
| 775 | } |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 776 | SkDebugf("---- %s: %d (of %d) differing pixels, " |
| 777 | "max per-channel mismatch R=%d G=%d B=%d A=%d\n", |
| 778 | testName, differingPixels, width*height, errR, errG, errB, errA); |
epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | /** |
epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 782 | * Compares actual hash digest to expectations, returning the set of errors |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 783 | * (if any) that we saw along the way. |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 784 | * |
| 785 | * If fMismatchPath has been set, and there are pixel diffs, then the |
| 786 | * actual bitmap will be written out to a file within fMismatchPath. |
epoger@google.com | 5f99545 | 2013-06-21 18:16:47 +0000 | [diff] [blame] | 787 | * And similarly for fMissingExpectationsPath... |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 788 | * |
| 789 | * @param expectations what expectations to compare actualBitmap against |
epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 790 | * @param actualBitmapAndDigest the SkBitmap we actually generated, and its GmResultDigest |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 791 | * @param shortName name of test, e.g. "selftest1" |
| 792 | * @param configName name of config, e.g. "8888" |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 793 | * @param renderModeDescriptor e.g., "-rtree", "-deferred" |
| 794 | * @param addToJsonSummary whether to add these results (both actual and |
epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 795 | * expected) to the JSON summary. Regardless of this setting, if |
| 796 | * we find an image mismatch in this test, we will write these |
| 797 | * results to the JSON summary. (This is so that we will always |
| 798 | * report errors across rendering modes, such as pipe vs tiled. |
| 799 | * See https://codereview.chromium.org/13650002/ ) |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 800 | */ |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 801 | ErrorCombination compare_to_expectations(Expectations expectations, |
epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 802 | const BitmapAndDigest& actualBitmapAndDigest, |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 803 | const char *shortName, const char *configName, |
| 804 | const char *renderModeDescriptor, |
epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 805 | bool addToJsonSummary) { |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 806 | ErrorCombination errors; |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 807 | SkString shortNamePlusConfig = make_shortname_plus_config(shortName, configName); |
| 808 | SkString completeNameString(shortNamePlusConfig); |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 809 | completeNameString.append(renderModeDescriptor); |
epoger@google.com | ce057fe | 2013-05-14 15:17:46 +0000 | [diff] [blame] | 810 | completeNameString.append("."); |
| 811 | completeNameString.append(kPNG_FileExtension); |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 812 | const char* completeName = completeNameString.c_str(); |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 813 | |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 814 | if (expectations.empty()) { |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 815 | errors.add(kMissingExpectations_ErrorType); |
epoger@google.com | 5f99545 | 2013-06-21 18:16:47 +0000 | [diff] [blame] | 816 | |
| 817 | // Write out the "actuals" for any tests without expectations, if we have |
| 818 | // been directed to do so. |
| 819 | if (fMissingExpectationsPath) { |
| 820 | SkString path = make_bitmap_filename(fMissingExpectationsPath, shortName, |
| 821 | configName, renderModeDescriptor, |
| 822 | actualBitmapAndDigest.fDigest); |
| 823 | write_bitmap(path, actualBitmapAndDigest.fBitmap); |
| 824 | } |
| 825 | |
epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 826 | } else if (!expectations.match(actualBitmapAndDigest.fDigest)) { |
epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 827 | addToJsonSummary = true; |
| 828 | // The error mode we record depends on whether this was running |
| 829 | // in a non-standard renderMode. |
| 830 | if ('\0' == *renderModeDescriptor) { |
| 831 | errors.add(kExpectationsMismatch_ErrorType); |
| 832 | } else { |
| 833 | errors.add(kRenderModeMismatch_ErrorType); |
| 834 | } |
epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 835 | |
| 836 | // Write out the "actuals" for any mismatches, if we have |
| 837 | // been directed to do so. |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 838 | if (fMismatchPath) { |
epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 839 | SkString path = make_bitmap_filename(fMismatchPath, shortName, configName, |
| 840 | renderModeDescriptor, |
| 841 | actualBitmapAndDigest.fDigest); |
| 842 | write_bitmap(path, actualBitmapAndDigest.fBitmap); |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 843 | } |
epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 844 | |
| 845 | // If we have access to a single expected bitmap, log more |
| 846 | // detail about the mismatch. |
| 847 | const SkBitmap *expectedBitmapPtr = expectations.asBitmap(); |
| 848 | if (NULL != expectedBitmapPtr) { |
epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 849 | report_bitmap_diffs(*expectedBitmapPtr, actualBitmapAndDigest.fBitmap, |
| 850 | completeName); |
epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 851 | } |
epoger@google.com | a243b22 | 2013-01-17 17:54:28 +0000 | [diff] [blame] | 852 | } |
epoger@google.com | a243b22 | 2013-01-17 17:54:28 +0000 | [diff] [blame] | 853 | |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 854 | if (addToJsonSummary) { |
epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 855 | add_actual_results_to_json_summary(completeName, actualBitmapAndDigest.fDigest, errors, |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 856 | expectations.ignoreFailure()); |
| 857 | add_expected_results_to_json_summary(completeName, expectations); |
| 858 | } |
epoger@google.com | a243b22 | 2013-01-17 17:54:28 +0000 | [diff] [blame] | 859 | |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 860 | return errors; |
epoger@google.com | 06b8a19 | 2013-01-15 19:10:16 +0000 | [diff] [blame] | 861 | } |
| 862 | |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 863 | /** |
epoger@google.com | 1ddfbc2 | 2013-10-10 17:24:20 +0000 | [diff] [blame] | 864 | * 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] | 865 | * depending on errors encountered. |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 866 | */ |
| 867 | void add_actual_results_to_json_summary(const char testName[], |
epoger@google.com | d4993ff | 2013-05-24 14:33:28 +0000 | [diff] [blame] | 868 | const GmResultDigest &actualResultDigest, |
epoger@google.com | 76c913d | 2013-04-26 15:06:44 +0000 | [diff] [blame] | 869 | ErrorCombination errors, |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 870 | bool ignoreFailure) { |
commit-bot@chromium.org | 25c1066 | 2014-05-16 17:56:43 +0000 | [diff] [blame] | 871 | #ifdef SK_BUILD_JSON_WRITER |
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 | } |
commit-bot@chromium.org | 25c1066 | 2014-05-16 17:56:43 +0000 | [diff] [blame] | 903 | #endif |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | /** |
| 907 | * Add this test to the JSON collection of expected results. |
| 908 | */ |
| 909 | void add_expected_results_to_json_summary(const char testName[], |
| 910 | Expectations expectations) { |
commit-bot@chromium.org | 25c1066 | 2014-05-16 17:56:43 +0000 | [diff] [blame] | 911 | #ifdef SK_BUILD_JSON_WRITER |
epoger@google.com | 76c913d | 2013-04-26 15:06:44 +0000 | [diff] [blame] | 912 | this->fJsonExpectedResults[testName] = expectations.asJsonValue(); |
commit-bot@chromium.org | 25c1066 | 2014-05-16 17:56:43 +0000 | [diff] [blame] | 913 | #endif |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | /** |
| 917 | * Compare actualBitmap to expectations stored in this->fExpectationsSource. |
| 918 | * |
| 919 | * @param gm which test generated the actualBitmap |
| 920 | * @param gRec |
vandebo@chromium.org | 8fc3766 | 2013-08-21 18:04:09 +0000 | [diff] [blame] | 921 | * @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] | 922 | * @param actualBitmapAndDigest ptr to bitmap generated by this run, or NULL |
| 923 | * if we don't have a usable bitmap representation |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 924 | */ |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 925 | ErrorCombination compare_test_results_to_stored_expectations( |
vandebo@chromium.org | 8fc3766 | 2013-08-21 18:04:09 +0000 | [diff] [blame] | 926 | GM* gm, const ConfigData& gRec, const char* configName, |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 927 | const BitmapAndDigest* actualBitmapAndDigest) { |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 928 | ErrorCombination errors; |
epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 929 | |
| 930 | if (NULL == actualBitmapAndDigest) { |
| 931 | // Note that we intentionally skipped validating the results for |
| 932 | // this test, because we don't know how to generate an SkBitmap |
| 933 | // version of the output. |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 934 | errors.add(ErrorCombination(kIntentionallySkipped_ErrorType)); |
epoger@google.com | c824c83 | 2013-07-12 15:52:59 +0000 | [diff] [blame] | 935 | } else if (!(gRec.fFlags & kWrite_ConfigFlag)) { |
| 936 | // We don't record the results for this test or compare them |
| 937 | // against any expectations, because the output image isn't |
| 938 | // meaningful. |
| 939 | // See https://code.google.com/p/skia/issues/detail?id=1410 ('some |
| 940 | // GM result images not available for download from Google Storage') |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 941 | errors.add(ErrorCombination(kIntentionallySkipped_ErrorType)); |
epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 942 | } else { |
| 943 | ExpectationsSource *expectationsSource = this->fExpectationsSource.get(); |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 944 | SkString nameWithExtension = make_shortname_plus_config(gm->getName(), configName); |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 945 | nameWithExtension.append("."); |
| 946 | nameWithExtension.append(kPNG_FileExtension); |
| 947 | |
epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 948 | if (expectationsSource && (gRec.fFlags & kRead_ConfigFlag)) { |
| 949 | /* |
| 950 | * Get the expected results for this test, as one or more allowed |
| 951 | * hash digests. The current implementation of expectationsSource |
| 952 | * get this by computing the hash digest of a single PNG file on disk. |
| 953 | * |
| 954 | * TODO(epoger): This relies on the fact that |
| 955 | * force_all_opaque() was called on the bitmap before it |
| 956 | * was written to disk as a PNG in the first place. If |
| 957 | * not, the hash digest returned here may not match the |
| 958 | * hash digest of actualBitmap, which *has* been run through |
| 959 | * force_all_opaque(). |
| 960 | * See comments above complete_bitmap() for more detail. |
| 961 | */ |
| 962 | Expectations expectations = expectationsSource->get(nameWithExtension.c_str()); |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 963 | if (this->ShouldIgnoreTest(gm->getName())) { |
epoger@google.com | defc487 | 2013-09-19 06:18:27 +0000 | [diff] [blame] | 964 | expectations.setIgnoreFailure(true); |
| 965 | } |
epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 966 | errors.add(compare_to_expectations(expectations, *actualBitmapAndDigest, |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 967 | gm->getName(), configName, "", true)); |
epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 968 | } else { |
| 969 | // If we are running without expectations, we still want to |
| 970 | // record the actual results. |
| 971 | add_actual_results_to_json_summary(nameWithExtension.c_str(), |
| 972 | actualBitmapAndDigest->fDigest, |
| 973 | ErrorCombination(kMissingExpectations_ErrorType), |
| 974 | false); |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 975 | errors.add(ErrorCombination(kMissingExpectations_ErrorType)); |
epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 976 | } |
epoger@google.com | 9ef89ce | 2013-01-18 21:45:42 +0000 | [diff] [blame] | 977 | } |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 978 | return errors; |
epoger@google.com | a243b22 | 2013-01-17 17:54:28 +0000 | [diff] [blame] | 979 | } |
| 980 | |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 981 | /** |
| 982 | * Compare actualBitmap to referenceBitmap. |
| 983 | * |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 984 | * @param shortName test name, e.g. "selftest1" |
| 985 | * @param configName configuration name, e.g. "8888" |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 986 | * @param renderModeDescriptor |
| 987 | * @param actualBitmap actual bitmap generated by this run |
| 988 | * @param referenceBitmap bitmap we expected to be generated |
| 989 | */ |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 990 | ErrorCombination compare_test_results_to_reference_bitmap( |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 991 | const char *shortName, const char *configName, const char *renderModeDescriptor, |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 992 | SkBitmap& actualBitmap, const SkBitmap* referenceBitmap) { |
| 993 | |
| 994 | SkASSERT(referenceBitmap); |
epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 995 | Expectations expectations(*referenceBitmap); |
epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 996 | BitmapAndDigest actualBitmapAndDigest(actualBitmap); |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 997 | |
| 998 | // TODO: Eliminate RecordTestResults from here. |
| 999 | // Results recording code for the test_drawing path has been refactored so that |
| 1000 | // RecordTestResults is only called once, at the topmost level. However, the |
| 1001 | // other paths have not yet been refactored, and RecordTestResults has been added |
| 1002 | // here to maintain proper behavior for calls not coming from the test_drawing path. |
| 1003 | ErrorCombination errors; |
| 1004 | errors.add(compare_to_expectations(expectations, actualBitmapAndDigest, shortName, |
| 1005 | configName, renderModeDescriptor, false)); |
| 1006 | SkString shortNamePlusConfig = make_shortname_plus_config(shortName, configName); |
| 1007 | RecordTestResults(errors, shortNamePlusConfig, renderModeDescriptor); |
| 1008 | |
| 1009 | return errors; |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
junov@chromium.org | 20bd04e | 2013-01-16 18:43:36 +0000 | [diff] [blame] | 1012 | static SkPicture* generate_new_picture(GM* gm, BbhType bbhType, uint32_t recordFlags, |
| 1013 | SkScalar scale = SK_Scalar1) { |
junov@chromium.org | 706ff2f | 2012-12-19 15:55:40 +0000 | [diff] [blame] | 1014 | int width = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().width()), scale)); |
| 1015 | int height = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().height()), scale)); |
skia.committer@gmail.com | d8b2799 | 2012-12-20 02:01:41 +0000 | [diff] [blame] | 1016 | |
commit-bot@chromium.org | 5fb2ce3 | 2014-04-17 23:35:06 +0000 | [diff] [blame] | 1017 | SkAutoTDelete<SkBBHFactory> factory; |
junov@chromium.org | 3cb834b | 2012-12-13 16:39:53 +0000 | [diff] [blame] | 1018 | if (kTileGrid_BbhType == bbhType) { |
commit-bot@chromium.org | 5fb2ce3 | 2014-04-17 23:35:06 +0000 | [diff] [blame] | 1019 | SkTileGridFactory::TileGridInfo info; |
junov@chromium.org | 29b19e5 | 2013-02-27 18:35:16 +0000 | [diff] [blame] | 1020 | info.fMargin.setEmpty(); |
| 1021 | info.fOffset.setZero(); |
| 1022 | info.fTileInterval.set(16, 16); |
commit-bot@chromium.org | 5fb2ce3 | 2014-04-17 23:35:06 +0000 | [diff] [blame] | 1023 | factory.reset(SkNEW_ARGS(SkTileGridFactory, (info))); |
commit-bot@chromium.org | d393b17 | 2014-04-16 16:02:10 +0000 | [diff] [blame] | 1024 | } else if (kQuadTree_BbhType == bbhType) { |
commit-bot@chromium.org | 5fb2ce3 | 2014-04-17 23:35:06 +0000 | [diff] [blame] | 1025 | factory.reset(SkNEW(SkQuadTreeFactory)); |
commit-bot@chromium.org | d393b17 | 2014-04-16 16:02:10 +0000 | [diff] [blame] | 1026 | } else if (kRTree_BbhType == bbhType) { |
commit-bot@chromium.org | 5fb2ce3 | 2014-04-17 23:35:06 +0000 | [diff] [blame] | 1027 | factory.reset(SkNEW(SkRTreeFactory)); |
junov@chromium.org | 20bd04e | 2013-01-16 18:43:36 +0000 | [diff] [blame] | 1028 | } |
commit-bot@chromium.org | 5fb2ce3 | 2014-04-17 23:35:06 +0000 | [diff] [blame] | 1029 | SkPictureRecorder recorder; |
| 1030 | SkCanvas* cv = recorder.beginRecording(width, height, factory.get(), recordFlags); |
junov@chromium.org | c938c48 | 2012-12-19 15:24:38 +0000 | [diff] [blame] | 1031 | cv->scale(scale, scale); |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 1032 | invokeGM(gm, cv, false, false); |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 1033 | return recorder.endRecording(); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 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 | |
commit-bot@chromium.org | 25c1066 | 2014-05-16 17:56:43 +0000 | [diff] [blame] | 1273 | #ifdef SK_BUILD_JSON_WRITER |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1274 | // JSON summaries that we generate as we go (just for output). |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 1275 | Json::Value fJsonExpectedResults; |
| 1276 | Json::Value fJsonActualResults_Failed; |
| 1277 | Json::Value fJsonActualResults_FailureIgnored; |
epoger@google.com | 9c56a8d | 2012-12-20 18:34:29 +0000 | [diff] [blame] | 1278 | Json::Value fJsonActualResults_NoComparison; |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 1279 | Json::Value fJsonActualResults_Succeeded; |
commit-bot@chromium.org | 25c1066 | 2014-05-16 17:56:43 +0000 | [diff] [blame] | 1280 | #endif |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1281 | }; // end of GMMain class definition |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 1282 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1283 | #if SK_SUPPORT_GPU |
| 1284 | static const GLContextType kDontCare_GLContextType = GrContextFactory::kNative_GLContextType; |
| 1285 | #else |
| 1286 | static const GLContextType kDontCare_GLContextType = 0; |
| 1287 | #endif |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1288 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1289 | static const ConfigData gRec[] = { |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1290 | { 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] | 1291 | #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] | 1292 | { 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] | 1293 | #endif |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1294 | { SkBitmap::kRGB_565_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "565", true }, |
| 1295 | #if SK_SUPPORT_GPU |
| 1296 | { 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] | 1297 | { 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] | 1298 | { 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] | 1299 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNVPR_GLContextType, 4, kRW_ConfigFlag, "nvprmsaa4", true }, |
| 1300 | { 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] | 1301 | /* The gpudebug context does not generate meaningful images, so don't record |
| 1302 | * 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] | 1303 | { 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] | 1304 | /* The gpunull context does the least amount of work possible and doesn't |
| 1305 | generate meaninful images, so don't record them!. It can be run to |
| 1306 | isolate the CPU-side processing expense from the GPU-side. |
| 1307 | */ |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 1308 | { 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] | 1309 | #if SK_ANGLE |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1310 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 0, kRW_ConfigFlag, "angle", true }, |
| 1311 | { 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] | 1312 | #endif // SK_ANGLE |
| 1313 | #ifdef SK_MESA |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1314 | { 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] | 1315 | #endif // SK_MESA |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1316 | #endif // SK_SUPPORT_GPU |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1317 | #ifdef SK_SUPPORT_XPS |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1318 | /* 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] | 1319 | { 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] | 1320 | #endif // SK_SUPPORT_XPS |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1321 | #ifdef SK_SUPPORT_PDF |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1322 | { 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] | 1323 | #endif // SK_SUPPORT_PDF |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1324 | }; |
| 1325 | |
bungeman@google.com | 5d20cae | 2014-05-09 15:22:41 +0000 | [diff] [blame] | 1326 | static bool SkNoRasterizePDF(SkStream*, SkBitmap*) { return false; } |
| 1327 | |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1328 | static const PDFRasterizerData kPDFRasterizers[] = { |
| 1329 | #ifdef SK_BUILD_FOR_MAC |
| 1330 | { &SkPDFDocumentToBitmap, "mac", true }, |
| 1331 | #endif |
| 1332 | #ifdef SK_BUILD_POPPLER |
| 1333 | { &SkPopplerRasterizePDF, "poppler", true }, |
| 1334 | #endif |
commit-bot@chromium.org | ffd178c | 2013-11-11 15:10:47 +0000 | [diff] [blame] | 1335 | #ifdef SK_BUILD_NATIVE_PDF_RENDERER |
| 1336 | { &SkNativeRasterizePDF, "native", true }, |
| 1337 | #endif // SK_BUILD_NATIVE_PDF_RENDERER |
bungeman@google.com | 5d20cae | 2014-05-09 15:22:41 +0000 | [diff] [blame] | 1338 | // The following exists so that this array is never zero length. |
| 1339 | { &SkNoRasterizePDF, "none", false}, |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1340 | }; |
| 1341 | |
bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1342 | static const char kDefaultsConfigStr[] = "defaults"; |
| 1343 | static const char kExcludeConfigChar = '~'; |
| 1344 | |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1345 | static SkString configUsage() { |
scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1346 | SkString result; |
| 1347 | 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] | 1348 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1349 | SkASSERT(gRec[i].fName != kDefaultsConfigStr); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1350 | if (i > 0) { |
scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1351 | result.append("|"); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1352 | } |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1353 | result.appendf("%s", gRec[i].fName); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1354 | } |
scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1355 | result.append("]\n"); |
| 1356 | result.appendf("The default value is: \""); |
bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1357 | SkString firstDefault; |
| 1358 | SkString allButFirstDefaults; |
| 1359 | SkString nonDefault; |
scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1360 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 1361 | if (gRec[i].fRunByDefault) { |
| 1362 | if (i > 0) { |
| 1363 | result.append(" "); |
| 1364 | } |
bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1365 | result.append(gRec[i].fName); |
| 1366 | if (firstDefault.isEmpty()) { |
| 1367 | firstDefault = gRec[i].fName; |
| 1368 | } else { |
| 1369 | if (!allButFirstDefaults.isEmpty()) { |
| 1370 | allButFirstDefaults.append(" "); |
| 1371 | } |
| 1372 | allButFirstDefaults.append(gRec[i].fName); |
| 1373 | } |
| 1374 | } else { |
| 1375 | nonDefault = gRec[i].fName; |
scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1376 | } |
| 1377 | } |
bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1378 | result.append("\"\n"); |
| 1379 | result.appendf("\"%s\" evaluates to the default set of configs.\n", kDefaultsConfigStr); |
| 1380 | result.appendf("Prepending \"%c\" on a config name excludes it from the set of configs to run.\n" |
| 1381 | "Exclusions always override inclusions regardless of order.\n", |
| 1382 | kExcludeConfigChar); |
| 1383 | result.appendf("E.g. \"--config %s %c%s %s\" will run these configs:\n\t%s %s", |
| 1384 | kDefaultsConfigStr, |
| 1385 | kExcludeConfigChar, |
| 1386 | firstDefault.c_str(), |
| 1387 | nonDefault.c_str(), |
| 1388 | allButFirstDefaults.c_str(), |
| 1389 | nonDefault.c_str()); |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1390 | return result; |
scroggo@google.com | 0b73563 | 2013-03-19 17:38:50 +0000 | [diff] [blame] | 1391 | } |
scroggo@google.com | 7d51930 | 2013-03-19 17:28:10 +0000 | [diff] [blame] | 1392 | |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1393 | static SkString pdfRasterizerUsage() { |
| 1394 | SkString result; |
| 1395 | result.appendf("Space delimited list of which PDF rasterizers to run. Possible options: ["); |
| 1396 | // For this (and further) loops through kPDFRasterizers, there is a typecast to int to avoid |
| 1397 | // the compiler giving an "comparison of unsigned expression < 0 is always false" warning |
| 1398 | // and turning it into a build-breaking error. |
| 1399 | for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); ++i) { |
| 1400 | if (i > 0) { |
| 1401 | result.append(" "); |
| 1402 | } |
| 1403 | result.append(kPDFRasterizers[i].fName); |
| 1404 | } |
| 1405 | result.append("]\n"); |
| 1406 | result.append("The default value is: \""); |
| 1407 | for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); ++i) { |
| 1408 | if (kPDFRasterizers[i].fRunByDefault) { |
| 1409 | if (i > 0) { |
| 1410 | result.append(" "); |
| 1411 | } |
| 1412 | result.append(kPDFRasterizers[i].fName); |
| 1413 | } |
| 1414 | } |
| 1415 | result.append("\""); |
| 1416 | return result; |
| 1417 | } |
| 1418 | |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1419 | // Macro magic to convert a numeric preprocessor token into a string. |
| 1420 | // Adapted from http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string |
| 1421 | // This should probably be moved into one of our common headers... |
| 1422 | #define TOSTRING_INTERNAL(x) #x |
| 1423 | #define TOSTRING(x) TOSTRING_INTERNAL(x) |
| 1424 | |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1425 | // Alphabetized ignoring "no" prefix ("readPath", "noreplay", "resourcePath"). |
scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1426 | DEFINE_string(config, "", configUsage().c_str()); |
vandebo@chromium.org | f8afb2b | 2013-11-06 16:32:15 +0000 | [diff] [blame] | 1427 | DEFINE_string(pdfRasterizers, "default", pdfRasterizerUsage().c_str()); |
epoger@google.com | 5e49738 | 2013-09-30 07:01:55 +0000 | [diff] [blame] | 1428 | DEFINE_bool(deferred, false, "Exercise the deferred rendering test pass."); |
commit-bot@chromium.org | b17ccc9 | 2014-03-13 16:16:36 +0000 | [diff] [blame] | 1429 | 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] | 1430 | DEFINE_string(excludeConfig, "", "Space delimited list of configs to skip."); |
| 1431 | DEFINE_bool(forceBWtext, false, "Disable text anti-aliasing."); |
| 1432 | #if SK_SUPPORT_GPU |
| 1433 | 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] | 1434 | "object count. " TOSTRING(DEFAULT_CACHE_VALUE) " for either value means " |
| 1435 | "use the default. 0 for either disables the cache."); |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1436 | #endif |
| 1437 | DEFINE_bool(hierarchy, false, "Whether to use multilevel directory structure " |
| 1438 | "when reading/writing files."); |
epoger@google.com | 5079d2c | 2013-04-12 14:11:21 +0000 | [diff] [blame] | 1439 | DEFINE_string(ignoreErrorTypes, kDefaultIgnorableErrorTypes.asString(" ").c_str(), |
| 1440 | "Space-separated list of ErrorTypes that should be ignored. If any *other* error " |
| 1441 | "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] | 1442 | DEFINE_string(ignoreFailuresFile, "", "Path to file containing a list of tests for which we " |
| 1443 | "should ignore failures.\n" |
| 1444 | "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] | 1445 | DEFINE_bool2(leaks, l, false, "show leaked ref cnt'd objects."); |
caryclark@google.com | 512c9b6 | 2013-05-10 15:16:13 +0000 | [diff] [blame] | 1446 | DEFINE_string(match, "", "[~][^]substring[$] [...] of test name to run.\n" |
| 1447 | "Multiple matches may be separated by spaces.\n" |
| 1448 | "~ causes a matching test to always be skipped\n" |
| 1449 | "^ requires the start of the test to match\n" |
| 1450 | "$ requires the end of the test to match\n" |
| 1451 | "^ and $ requires an exact match\n" |
| 1452 | "If a test does not match any list entry,\n" |
| 1453 | "it is skipped unless some list entry starts with ~"); |
epoger@google.com | 5f99545 | 2013-06-21 18:16:47 +0000 | [diff] [blame] | 1454 | DEFINE_string(missingExpectationsPath, "", "Write images for tests without expectations " |
| 1455 | "into this directory."); |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1456 | DEFINE_string(mismatchPath, "", "Write images for tests that failed due to " |
| 1457 | "pixel mismatches into this directory."); |
| 1458 | DEFINE_string(modulo, "", "[--modulo <remainder> <divisor>]: only run tests for which " |
| 1459 | "testIndex %% divisor == remainder."); |
epoger@google.com | 5e49738 | 2013-09-30 07:01:55 +0000 | [diff] [blame] | 1460 | DEFINE_bool(pipe, false, "Exercise the SkGPipe replay test pass."); |
commit-bot@chromium.org | d393b17 | 2014-04-16 16:02:10 +0000 | [diff] [blame] | 1461 | DEFINE_bool(quadtree, false, "Exercise the QuadTree variant of SkPicture test pass."); |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1462 | DEFINE_string2(readPath, r, "", "Read reference images from this dir, and report " |
| 1463 | "any differences between those and the newly generated ones."); |
epoger@google.com | 5e49738 | 2013-09-30 07:01:55 +0000 | [diff] [blame] | 1464 | DEFINE_bool(replay, false, "Exercise the SkPicture replay test pass."); |
djsollen@google.com | ac8f3a4 | 2013-10-04 14:57:00 +0000 | [diff] [blame] | 1465 | #if SK_SUPPORT_GPU |
| 1466 | DEFINE_bool(resetGpuContext, false, "Reset the GrContext prior to running each GM."); |
| 1467 | #endif |
tfarina@chromium.org | 725a64c | 2013-12-31 14:29:52 +0000 | [diff] [blame] | 1468 | DEFINE_string2(resourcePath, i, "resources", "Directory that stores image resources."); |
epoger@google.com | 5e49738 | 2013-09-30 07:01:55 +0000 | [diff] [blame] | 1469 | DEFINE_bool(rtree, false, "Exercise the R-Tree variant of SkPicture test pass."); |
| 1470 | DEFINE_bool(serialize, false, "Exercise the SkPicture serialization & deserialization test pass."); |
epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 1471 | 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] | 1472 | DEFINE_bool(tiledPipe, false, "Exercise tiled SkGPipe replay."); |
epoger@google.com | 5e49738 | 2013-09-30 07:01:55 +0000 | [diff] [blame] | 1473 | DEFINE_bool(tileGrid, false, "Exercise the tile grid variant of SkPicture."); |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1474 | DEFINE_string(tileGridReplayScales, "", "Space separated list of floating-point scale " |
| 1475 | "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] | 1476 | DEFINE_bool2(verbose, v, false, "Give more detail (e.g. list all GMs run, more info about " |
| 1477 | "each test)."); |
epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 1478 | DEFINE_bool(writeChecksumBasedFilenames, false, "When writing out actual images, use checksum-" |
| 1479 | "based filenames, as rebaseline.py will use when downloading them from Google Storage"); |
commit-bot@chromium.org | 25c1066 | 2014-05-16 17:56:43 +0000 | [diff] [blame] | 1480 | #ifdef SK_BUILD_JSON_WRITER |
epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 1481 | DEFINE_string(writeJsonSummaryPath, "", "Write a JSON-formatted result summary to this file."); |
commit-bot@chromium.org | 25c1066 | 2014-05-16 17:56:43 +0000 | [diff] [blame] | 1482 | #endif |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1483 | DEFINE_string2(writePath, w, "", "Write rendered images into this directory."); |
scroggo@google.com | 604e0c2 | 2013-04-09 21:25:46 +0000 | [diff] [blame] | 1484 | DEFINE_string2(writePicturePath, p, "", "Write .skp files into this directory."); |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 1485 | DEFINE_int32(pdfJpegQuality, -1, "Encodes images in JPEG at quality level N, " |
| 1486 | "which can be in range 0-100). N = -1 will disable JPEG compression. " |
| 1487 | "Default is N = 100, maximum quality."); |
commit-bot@chromium.org | f4f9df4 | 2013-09-26 20:44:24 +0000 | [diff] [blame] | 1488 | // TODO(edisonn): pass a matrix instead of forcePerspectiveMatrix |
| 1489 | // Either the 9 numbers defining the matrix |
| 1490 | // or probably more readable would be to replace it with a set of a few predicates |
| 1491 | // Like --prerotate 100 200 10 --posttranslate 10, 10 |
| 1492 | // Probably define spacial names like centerx, centery, top, bottom, left, right |
| 1493 | // then we can write something reabable like --rotate centerx centery 90 |
| 1494 | DEFINE_bool(forcePerspectiveMatrix, false, "Force a perspective matrix."); |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 1495 | DEFINE_bool(useDocumentInsteadOfDevice, false, "Use SkDocument::CreateFoo instead of SkFooDevice."); |
edisonn@google.com | 73a7ea3 | 2013-11-11 20:55:15 +0000 | [diff] [blame] | 1496 | DEFINE_int32(pdfRasterDpi, 72, "Scale at which at which the non suported " |
| 1497 | "features in PDF are rasterized. Must be be in range 0-10000. " |
| 1498 | "Default is 72. N = 0 will disable rasterizing features like " |
| 1499 | "text shadows or perspective bitmaps."); |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 1500 | static SkData* encode_to_dct_data(size_t*, const SkBitmap& bitmap) { |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 1501 | // 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] | 1502 | if (bitmap.width() >= 65500 || bitmap.height() >= 65500) return NULL; |
| 1503 | if (FLAGS_pdfJpegQuality == -1) return NULL; |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 1504 | |
commit-bot@chromium.org | 608ea65 | 2013-10-03 19:29:21 +0000 | [diff] [blame] | 1505 | SkBitmap bm = bitmap; |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 1506 | #if defined(SK_BUILD_FOR_MAC) |
| 1507 | // Workaround bug #1043 where bitmaps with referenced pixels cause |
| 1508 | // CGImageDestinationFinalize to crash |
| 1509 | SkBitmap copy; |
commit-bot@chromium.org | d5f032d | 2014-02-24 18:51:43 +0000 | [diff] [blame] | 1510 | bitmap.deepCopyTo(©); |
commit-bot@chromium.org | 608ea65 | 2013-10-03 19:29:21 +0000 | [diff] [blame] | 1511 | bm = copy; |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 1512 | #endif |
| 1513 | |
commit-bot@chromium.org | 608ea65 | 2013-10-03 19:29:21 +0000 | [diff] [blame] | 1514 | SkPixelRef* pr = bm.pixelRef(); |
| 1515 | if (pr != NULL) { |
| 1516 | SkData* data = pr->refEncodedData(); |
| 1517 | if (data != NULL) { |
commit-bot@chromium.org | 608ea65 | 2013-10-03 19:29:21 +0000 | [diff] [blame] | 1518 | return data; |
| 1519 | } |
| 1520 | } |
| 1521 | |
commit-bot@chromium.org | 608ea65 | 2013-10-03 19:29:21 +0000 | [diff] [blame] | 1522 | return SkImageEncoder::EncodeData(bm, |
| 1523 | SkImageEncoder::kJPEG_Type, |
| 1524 | FLAGS_pdfJpegQuality); |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 1525 | } |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1526 | |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1527 | static int findConfig(const char config[]) { |
| 1528 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { |
| 1529 | if (!strcmp(config, gRec[i].fName)) { |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1530 | return (int) i; |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1531 | } |
| 1532 | } |
| 1533 | return -1; |
| 1534 | } |
| 1535 | |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1536 | static const PDFRasterizerData* findPDFRasterizer(const char rasterizer[]) { |
| 1537 | for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); i++) { |
| 1538 | if (!strcmp(rasterizer, kPDFRasterizers[i].fName)) { |
| 1539 | return &kPDFRasterizers[i]; |
| 1540 | } |
| 1541 | } |
| 1542 | return NULL; |
| 1543 | } |
| 1544 | |
reed@google.com | fb2cd42 | 2013-01-04 14:43:03 +0000 | [diff] [blame] | 1545 | template <typename T> void appendUnique(SkTDArray<T>* array, const T& value) { |
| 1546 | int index = array->find(value); |
| 1547 | if (index < 0) { |
| 1548 | *array->append() = value; |
| 1549 | } |
| 1550 | } |
| 1551 | |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1552 | /** |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1553 | * Run this test in a number of different drawing modes (pipe, |
| 1554 | * deferred, tiled, etc.), confirming that the resulting bitmaps all |
| 1555 | * *exactly* match comparisonBitmap. |
| 1556 | * |
| 1557 | * Returns all errors encountered while doing so. |
| 1558 | */ |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1559 | ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm, const ConfigData &compareConfig, |
| 1560 | const SkBitmap &comparisonBitmap, |
| 1561 | const SkTDArray<SkScalar> &tileGridReplayScales); |
| 1562 | ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm, const ConfigData &compareConfig, |
| 1563 | const SkBitmap &comparisonBitmap, |
| 1564 | const SkTDArray<SkScalar> &tileGridReplayScales) { |
| 1565 | ErrorCombination errorsForAllModes; |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1566 | uint32_t gmFlags = gm->getFlags(); |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 1567 | const SkString shortNamePlusConfig = gmmain.make_shortname_plus_config(gm->getName(), |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1568 | compareConfig.fName); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1569 | |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1570 | SkPicture* pict = gmmain.generate_new_picture(gm, kNone_BbhType, 0); |
| 1571 | SkAutoUnref aur(pict); |
| 1572 | if (FLAGS_replay) { |
| 1573 | const char renderModeDescriptor[] = "-replay"; |
| 1574 | if (gmFlags & GM::kSkipPicture_Flag) { |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1575 | gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, |
| 1576 | renderModeDescriptor); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1577 | errorsForAllModes.add(kIntentionallySkipped_ErrorType); |
| 1578 | } else { |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1579 | SkBitmap bitmap; |
| 1580 | gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1581 | errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap( |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 1582 | gm->getName(), compareConfig.fName, renderModeDescriptor, bitmap, |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1583 | &comparisonBitmap)); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1584 | } |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1585 | } |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1586 | |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1587 | if (FLAGS_serialize) { |
| 1588 | const char renderModeDescriptor[] = "-serialize"; |
| 1589 | if (gmFlags & GM::kSkipPicture_Flag) { |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1590 | gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, |
| 1591 | renderModeDescriptor); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1592 | errorsForAllModes.add(kIntentionallySkipped_ErrorType); |
| 1593 | } else { |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1594 | SkPicture* repict = gmmain.stream_to_new_picture(*pict); |
| 1595 | SkAutoUnref aurr(repict); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1596 | SkBitmap bitmap; |
| 1597 | gmmain.generate_image_from_picture(gm, compareConfig, repict, &bitmap); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1598 | errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap( |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 1599 | gm->getName(), compareConfig.fName, renderModeDescriptor, bitmap, |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1600 | &comparisonBitmap)); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1601 | } |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1602 | } |
| 1603 | |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1604 | if ((1 == FLAGS_writePicturePath.count()) && |
| 1605 | !(gmFlags & GM::kSkipPicture_Flag)) { |
| 1606 | const char* pictureSuffix = "skp"; |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1607 | // TODO(epoger): Make sure this still works even though the |
| 1608 | // filename now contains the config name (it used to contain |
| 1609 | // just the shortName). I think this is actually an |
| 1610 | // *improvement*, because now runs with different configs will |
| 1611 | // write out their SkPictures to separate files rather than |
| 1612 | // overwriting each other. But we should make sure it doesn't |
| 1613 | // break anybody. |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 1614 | SkString path = gmmain.make_filename(FLAGS_writePicturePath[0], gm->getName(), |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1615 | compareConfig.fName, "", pictureSuffix); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1616 | SkFILEWStream stream(path.c_str()); |
| 1617 | pict->serialize(&stream); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1618 | } |
| 1619 | |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1620 | if (FLAGS_rtree) { |
| 1621 | const char renderModeDescriptor[] = "-rtree"; |
commit-bot@chromium.org | d393b17 | 2014-04-16 16:02:10 +0000 | [diff] [blame] | 1622 | if ((gmFlags & GM::kSkipPicture_Flag) || (gmFlags & GM::kSkipTiled_Flag)) { |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1623 | gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, |
| 1624 | renderModeDescriptor); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1625 | errorsForAllModes.add(kIntentionallySkipped_ErrorType); |
| 1626 | } else { |
commit-bot@chromium.org | d393b17 | 2014-04-16 16:02:10 +0000 | [diff] [blame] | 1627 | SkPicture* pict = gmmain.generate_new_picture(gm, kRTree_BbhType, 0); |
| 1628 | SkAutoUnref aur(pict); |
| 1629 | SkBitmap bitmap; |
| 1630 | gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap); |
| 1631 | errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap( |
| 1632 | gm->getName(), compareConfig.fName, renderModeDescriptor, bitmap, |
| 1633 | &comparisonBitmap)); |
| 1634 | } |
| 1635 | } |
| 1636 | |
| 1637 | if (FLAGS_quadtree) { |
| 1638 | const char renderModeDescriptor[] = "-quadtree"; |
| 1639 | if ((gmFlags & GM::kSkipPicture_Flag) || (gmFlags & GM::kSkipTiled_Flag)) { |
| 1640 | gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, |
| 1641 | renderModeDescriptor); |
| 1642 | errorsForAllModes.add(kIntentionallySkipped_ErrorType); |
| 1643 | } else { |
| 1644 | SkPicture* pict = gmmain.generate_new_picture(gm, kQuadTree_BbhType, 0); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1645 | SkAutoUnref aur(pict); |
| 1646 | SkBitmap bitmap; |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1647 | gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap); |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1648 | errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap( |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 1649 | gm->getName(), compareConfig.fName, renderModeDescriptor, bitmap, |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1650 | &comparisonBitmap)); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1651 | } |
| 1652 | } |
| 1653 | |
| 1654 | if (FLAGS_tileGrid) { |
| 1655 | for(int scaleIndex = 0; scaleIndex < tileGridReplayScales.count(); ++scaleIndex) { |
| 1656 | SkScalar replayScale = tileGridReplayScales[scaleIndex]; |
| 1657 | SkString renderModeDescriptor("-tilegrid"); |
| 1658 | if (SK_Scalar1 != replayScale) { |
| 1659 | renderModeDescriptor += "-scale-"; |
| 1660 | renderModeDescriptor.appendScalar(replayScale); |
| 1661 | } |
| 1662 | |
| 1663 | if ((gmFlags & GM::kSkipPicture_Flag) || |
senorblanco@chromium.org | d4d44f0 | 2014-02-20 17:17:57 +0000 | [diff] [blame] | 1664 | (gmFlags & GM::kSkipTiled_Flag) || |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1665 | ((gmFlags & GM::kSkipScaledReplay_Flag) && replayScale != 1)) { |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1666 | gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1667 | renderModeDescriptor.c_str()); |
| 1668 | errorsForAllModes.add(kIntentionallySkipped_ErrorType); |
| 1669 | } else { |
| 1670 | // We record with the reciprocal scale to obtain a replay |
| 1671 | // result that can be validated against comparisonBitmap. |
| 1672 | SkScalar recordScale = SkScalarInvert(replayScale); |
| 1673 | SkPicture* pict = gmmain.generate_new_picture( |
| 1674 | gm, kTileGrid_BbhType, SkPicture::kUsePathBoundsForClip_RecordingFlag, |
| 1675 | recordScale); |
| 1676 | SkAutoUnref aur(pict); |
| 1677 | SkBitmap bitmap; |
| 1678 | // We cannot yet pass 'true' to generate_image_from_picture to |
| 1679 | // perform actual tiled rendering (see Issue 1198 - |
| 1680 | // https://code.google.com/p/skia/issues/detail?id=1198) |
| 1681 | gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap, |
| 1682 | replayScale /*, true */); |
| 1683 | errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap( |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 1684 | gm->getName(), compareConfig.fName, renderModeDescriptor.c_str(), bitmap, |
epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1685 | &comparisonBitmap)); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1686 | } |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | // run the pipe centric GM steps |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1691 | if (FLAGS_pipe) { |
| 1692 | errorsForAllModes.add(gmmain.test_pipe_playback(gm, compareConfig, comparisonBitmap, |
| 1693 | FLAGS_simulatePipePlaybackFailure)); |
| 1694 | if (FLAGS_tiledPipe) { |
| 1695 | errorsForAllModes.add(gmmain.test_tiled_pipe_playback(gm, compareConfig, |
| 1696 | comparisonBitmap)); |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1697 | } |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1698 | } |
| 1699 | return errorsForAllModes; |
| 1700 | } |
| 1701 | |
commit-bot@chromium.org | 8519548 | 2014-01-13 18:27:59 +0000 | [diff] [blame] | 1702 | |
| 1703 | /** |
| 1704 | * Run this test in a number of different configs (8888, 565, PDF, |
| 1705 | * etc.), confirming that the resulting bitmaps match expectations |
| 1706 | * (which may be different for each config). |
| 1707 | * |
| 1708 | * Returns all errors encountered while doing so. |
| 1709 | */ |
| 1710 | ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm, |
| 1711 | const SkTDArray<size_t> &configs, |
| 1712 | const SkTDArray<const PDFRasterizerData*> &pdfRasterizers, |
| 1713 | const SkTDArray<SkScalar> &tileGridReplayScales, |
| 1714 | GrContextFactory *grFactory); |
| 1715 | ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm, |
| 1716 | const SkTDArray<size_t> &configs, |
| 1717 | const SkTDArray<const PDFRasterizerData*> &pdfRasterizers, |
| 1718 | const SkTDArray<SkScalar> &tileGridReplayScales, |
| 1719 | GrContextFactory *grFactory) { |
| 1720 | const char renderModeDescriptor[] = ""; |
| 1721 | ErrorCombination errorsForAllConfigs; |
| 1722 | uint32_t gmFlags = gm->getFlags(); |
| 1723 | |
| 1724 | for (int i = 0; i < configs.count(); i++) { |
| 1725 | ConfigData config = gRec[configs[i]]; |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 1726 | const SkString shortNamePlusConfig = gmmain.make_shortname_plus_config(gm->getName(), |
commit-bot@chromium.org | 8519548 | 2014-01-13 18:27:59 +0000 | [diff] [blame] | 1727 | config.fName); |
| 1728 | |
| 1729 | // Skip any tests that we don't even need to try. |
| 1730 | // If any of these were skipped on a per-GM basis, record them as |
| 1731 | // kIntentionallySkipped. |
| 1732 | if (kPDF_Backend == config.fBackend) { |
| 1733 | if (gmFlags & GM::kSkipPDF_Flag) { |
| 1734 | gmmain.RecordSkippedTest(shortNamePlusConfig, |
| 1735 | renderModeDescriptor, |
| 1736 | config.fBackend); |
| 1737 | errorsForAllConfigs.add(kIntentionallySkipped_ErrorType); |
| 1738 | continue; |
| 1739 | } |
| 1740 | } |
| 1741 | if ((gmFlags & GM::kSkip565_Flag) && |
| 1742 | (kRaster_Backend == config.fBackend) && |
| 1743 | (SkBitmap::kRGB_565_Config == config.fConfig)) { |
| 1744 | gmmain.RecordSkippedTest(shortNamePlusConfig, |
| 1745 | renderModeDescriptor, |
| 1746 | config.fBackend); |
| 1747 | errorsForAllConfigs.add(kIntentionallySkipped_ErrorType); |
| 1748 | continue; |
| 1749 | } |
| 1750 | if (((gmFlags & GM::kSkipGPU_Flag) && kGPU_Backend == config.fBackend) || |
| 1751 | ((gmFlags & GM::kGPUOnly_Flag) && kGPU_Backend != config.fBackend)) { |
| 1752 | gmmain.RecordSkippedTest(shortNamePlusConfig, |
| 1753 | renderModeDescriptor, |
| 1754 | config.fBackend); |
| 1755 | errorsForAllConfigs.add(kIntentionallySkipped_ErrorType); |
| 1756 | continue; |
| 1757 | } |
| 1758 | |
| 1759 | // Now we know that we want to run this test and record its |
| 1760 | // success or failure. |
| 1761 | ErrorCombination errorsForThisConfig; |
| 1762 | GrSurface* gpuTarget = NULL; |
| 1763 | #if SK_SUPPORT_GPU |
| 1764 | SkAutoTUnref<GrSurface> auGpuTarget; |
| 1765 | if ((errorsForThisConfig.isEmpty()) && (kGPU_Backend == config.fBackend)) { |
| 1766 | if (FLAGS_resetGpuContext) { |
| 1767 | grFactory->destroyContexts(); |
| 1768 | } |
| 1769 | GrContext* gr = grFactory->get(config.fGLContextType); |
| 1770 | bool grSuccess = false; |
| 1771 | if (gr) { |
| 1772 | // create a render target to back the device |
| 1773 | GrTextureDesc desc; |
| 1774 | desc.fConfig = kSkia8888_GrPixelConfig; |
| 1775 | desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 1776 | desc.fWidth = gm->getISize().width(); |
| 1777 | desc.fHeight = gm->getISize().height(); |
| 1778 | desc.fSampleCnt = config.fSampleCnt; |
| 1779 | auGpuTarget.reset(gr->createUncachedTexture(desc, NULL, 0)); |
| 1780 | if (NULL != auGpuTarget) { |
| 1781 | gpuTarget = auGpuTarget; |
| 1782 | grSuccess = true; |
| 1783 | // Set the user specified cache limits if non-default. |
| 1784 | size_t bytes; |
| 1785 | int count; |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 1786 | gr->getResourceCacheLimits(&count, &bytes); |
commit-bot@chromium.org | 8519548 | 2014-01-13 18:27:59 +0000 | [diff] [blame] | 1787 | if (DEFAULT_CACHE_VALUE != gGpuCacheSizeBytes) { |
| 1788 | bytes = static_cast<size_t>(gGpuCacheSizeBytes); |
| 1789 | } |
| 1790 | if (DEFAULT_CACHE_VALUE != gGpuCacheSizeCount) { |
| 1791 | count = gGpuCacheSizeCount; |
| 1792 | } |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 1793 | gr->setResourceCacheLimits(count, bytes); |
commit-bot@chromium.org | 8519548 | 2014-01-13 18:27:59 +0000 | [diff] [blame] | 1794 | } |
| 1795 | } |
| 1796 | if (!grSuccess) { |
| 1797 | errorsForThisConfig.add(kNoGpuContext_ErrorType); |
| 1798 | } |
| 1799 | } |
| 1800 | #endif |
| 1801 | |
| 1802 | SkBitmap comparisonBitmap; |
| 1803 | |
| 1804 | const char* writePath; |
| 1805 | if (FLAGS_writePath.count() == 1) { |
| 1806 | writePath = FLAGS_writePath[0]; |
| 1807 | } else { |
| 1808 | writePath = NULL; |
| 1809 | } |
| 1810 | |
| 1811 | if (errorsForThisConfig.isEmpty()) { |
| 1812 | errorsForThisConfig.add(gmmain.test_drawing(gm, config, pdfRasterizers, |
| 1813 | writePath, gpuTarget, |
| 1814 | &comparisonBitmap)); |
| 1815 | gmmain.RecordTestResults(errorsForThisConfig, shortNamePlusConfig, ""); |
| 1816 | } |
| 1817 | |
| 1818 | // TODO: run only if gmmain.test_drawing succeeded. |
| 1819 | if (kRaster_Backend == config.fBackend) { |
| 1820 | run_multiple_modes(gmmain, gm, config, comparisonBitmap, tileGridReplayScales); |
| 1821 | } |
| 1822 | |
| 1823 | if (FLAGS_deferred && errorsForThisConfig.isEmpty() && |
| 1824 | (kGPU_Backend == config.fBackend || kRaster_Backend == config.fBackend)) { |
| 1825 | errorsForThisConfig.add(gmmain.test_deferred_drawing(gm, config, comparisonBitmap, |
| 1826 | gpuTarget)); |
| 1827 | } |
| 1828 | |
| 1829 | errorsForAllConfigs.add(errorsForThisConfig); |
| 1830 | } |
| 1831 | return errorsForAllConfigs; |
| 1832 | } |
| 1833 | |
| 1834 | |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 1835 | /** |
epoger@google.com | f711f32 | 2013-10-18 14:55:47 +0000 | [diff] [blame] | 1836 | * Read individual lines from a file, pushing them into the given array. |
| 1837 | * |
| 1838 | * @param filename path to the file to read |
| 1839 | * @param lines array of strings to add the lines to |
| 1840 | * @returns true if able to read lines from the file |
| 1841 | */ |
| 1842 | static bool read_lines_from_file(const char* filename, SkTArray<SkString> &lines) { |
| 1843 | SkAutoTUnref<SkStream> streamWrapper(SkStream::NewFromFile(filename)); |
| 1844 | SkStream *stream = streamWrapper.get(); |
| 1845 | if (!stream) { |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 1846 | SkDebugf("unable to read file '%s'\n", filename); |
epoger@google.com | f711f32 | 2013-10-18 14:55:47 +0000 | [diff] [blame] | 1847 | return false; |
| 1848 | } |
| 1849 | |
| 1850 | char c; |
| 1851 | SkString line; |
| 1852 | while (1 == stream->read(&c, 1)) { |
| 1853 | // If we hit either CR or LF, we've completed a line. |
| 1854 | // |
| 1855 | // TODO: If the file uses both CR and LF, this will return an extra blank |
| 1856 | // line for each line of the file. Which is OK for current purposes... |
| 1857 | // |
| 1858 | // TODO: Does this properly handle unicode? It doesn't matter for |
| 1859 | // current purposes... |
| 1860 | if ((c == 0x0d) || (c == 0x0a)) { |
| 1861 | lines.push_back(line); |
| 1862 | line.reset(); |
| 1863 | } else { |
| 1864 | line.append(&c, 1); |
| 1865 | } |
| 1866 | } |
| 1867 | lines.push_back(line); |
| 1868 | return true; |
| 1869 | } |
| 1870 | |
| 1871 | /** |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 1872 | * Return a list of all entries in an array of strings as a single string |
| 1873 | * of this form: |
| 1874 | * "item1", "item2", "item3" |
| 1875 | */ |
| 1876 | SkString list_all(const SkTArray<SkString> &stringArray); |
| 1877 | SkString list_all(const SkTArray<SkString> &stringArray) { |
| 1878 | SkString total; |
| 1879 | for (int i = 0; i < stringArray.count(); i++) { |
| 1880 | if (i > 0) { |
| 1881 | total.append(", "); |
| 1882 | } |
| 1883 | total.append("\""); |
| 1884 | total.append(stringArray[i]); |
| 1885 | total.append("\""); |
| 1886 | } |
| 1887 | return total; |
| 1888 | } |
| 1889 | |
| 1890 | /** |
| 1891 | * Return a list of configuration names, as a single string of this form: |
| 1892 | * "item1", "item2", "item3" |
| 1893 | * |
| 1894 | * @param configs configurations, as a list of indices into gRec |
| 1895 | */ |
| 1896 | SkString list_all_config_names(const SkTDArray<size_t> &configs); |
| 1897 | SkString list_all_config_names(const SkTDArray<size_t> &configs) { |
| 1898 | SkString total; |
| 1899 | for (int i = 0; i < configs.count(); i++) { |
| 1900 | if (i > 0) { |
| 1901 | total.append(", "); |
| 1902 | } |
| 1903 | total.append("\""); |
| 1904 | total.append(gRec[configs[i]].fName); |
| 1905 | total.append("\""); |
| 1906 | } |
| 1907 | return total; |
| 1908 | } |
| 1909 | |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1910 | static bool prepare_subdirectories(const char *root, bool useFileHierarchy, |
| 1911 | const SkTDArray<size_t> &configs, |
| 1912 | const SkTDArray<const PDFRasterizerData*>& pdfRasterizers) { |
epoger@google.com | fdea325 | 2013-05-02 18:24:03 +0000 | [diff] [blame] | 1913 | if (!sk_mkdir(root)) { |
| 1914 | return false; |
| 1915 | } |
| 1916 | if (useFileHierarchy) { |
| 1917 | for (int i = 0; i < configs.count(); i++) { |
| 1918 | ConfigData config = gRec[configs[i]]; |
| 1919 | SkString subdir; |
| 1920 | subdir.appendf("%s%c%s", root, SkPATH_SEPARATOR, config.fName); |
| 1921 | if (!sk_mkdir(subdir.c_str())) { |
| 1922 | return false; |
| 1923 | } |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1924 | |
| 1925 | if (config.fBackend == kPDF_Backend) { |
| 1926 | for (int j = 0; j < pdfRasterizers.count(); j++) { |
| 1927 | SkString pdfSubdir = subdir; |
vandebo@chromium.org | 8fc3766 | 2013-08-21 18:04:09 +0000 | [diff] [blame] | 1928 | pdfSubdir.appendf("-%s", pdfRasterizers[j]->fName); |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 1929 | if (!sk_mkdir(pdfSubdir.c_str())) { |
| 1930 | return false; |
| 1931 | } |
| 1932 | } |
| 1933 | } |
epoger@google.com | fdea325 | 2013-05-02 18:24:03 +0000 | [diff] [blame] | 1934 | } |
| 1935 | } |
| 1936 | return true; |
| 1937 | } |
| 1938 | |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 1939 | static bool parse_flags_configs(SkTDArray<size_t>* outConfigs, |
| 1940 | GrContextFactory* grFactory) { |
| 1941 | SkTDArray<size_t> excludeConfigs; |
| 1942 | |
| 1943 | for (int i = 0; i < FLAGS_config.count(); i++) { |
| 1944 | const char* config = FLAGS_config[i]; |
| 1945 | bool exclude = false; |
| 1946 | if (*config == kExcludeConfigChar) { |
| 1947 | exclude = true; |
| 1948 | config += 1; |
| 1949 | } |
| 1950 | int index = findConfig(config); |
| 1951 | if (index >= 0) { |
| 1952 | if (exclude) { |
| 1953 | *excludeConfigs.append() = index; |
| 1954 | } else { |
| 1955 | appendUnique<size_t>(outConfigs, index); |
| 1956 | } |
| 1957 | } else if (0 == strcmp(kDefaultsConfigStr, config)) { |
| 1958 | if (exclude) { |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 1959 | SkDebugf("%c%s is not allowed.\n", |
| 1960 | kExcludeConfigChar, kDefaultsConfigStr); |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 1961 | return false; |
| 1962 | } |
| 1963 | for (size_t c = 0; c < SK_ARRAY_COUNT(gRec); ++c) { |
| 1964 | if (gRec[c].fRunByDefault) { |
| 1965 | appendUnique<size_t>(outConfigs, c); |
| 1966 | } |
| 1967 | } |
| 1968 | } else { |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 1969 | SkDebugf("unrecognized config %s\n", config); |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 1970 | return false; |
| 1971 | } |
| 1972 | } |
| 1973 | |
| 1974 | for (int i = 0; i < FLAGS_excludeConfig.count(); i++) { |
| 1975 | int index = findConfig(FLAGS_excludeConfig[i]); |
| 1976 | if (index >= 0) { |
| 1977 | *excludeConfigs.append() = index; |
| 1978 | } else { |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 1979 | SkDebugf("unrecognized excludeConfig %s\n", FLAGS_excludeConfig[i]); |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 1980 | return false; |
| 1981 | } |
| 1982 | } |
| 1983 | |
| 1984 | if (outConfigs->count() == 0) { |
| 1985 | // if no config is specified by user, add the defaults |
| 1986 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 1987 | if (gRec[i].fRunByDefault) { |
| 1988 | *outConfigs->append() = i; |
| 1989 | } |
| 1990 | } |
| 1991 | } |
| 1992 | // now remove any explicitly excluded configs |
| 1993 | for (int i = 0; i < excludeConfigs.count(); ++i) { |
| 1994 | int index = outConfigs->find(excludeConfigs[i]); |
| 1995 | if (index >= 0) { |
| 1996 | outConfigs->remove(index); |
| 1997 | // now assert that there was only one copy in configs[] |
| 1998 | SkASSERT(outConfigs->find(excludeConfigs[i]) < 0); |
| 1999 | } |
| 2000 | } |
| 2001 | |
| 2002 | #if SK_SUPPORT_GPU |
| 2003 | SkASSERT(grFactory != NULL); |
| 2004 | for (int i = 0; i < outConfigs->count(); ++i) { |
| 2005 | size_t index = (*outConfigs)[i]; |
| 2006 | if (kGPU_Backend == gRec[index].fBackend) { |
| 2007 | GrContext* ctx = grFactory->get(gRec[index].fGLContextType); |
| 2008 | if (NULL == ctx) { |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 2009 | SkDebugf("GrContext could not be created for config %s. Config will be skipped.\n", |
| 2010 | gRec[index].fName); |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2011 | outConfigs->remove(i); |
| 2012 | --i; |
| 2013 | continue; |
| 2014 | } |
| 2015 | if (gRec[index].fSampleCnt > ctx->getMaxSampleCount()) { |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 2016 | SkDebugf("Sample count (%d) of config %s is not supported." |
| 2017 | " Config will be skipped.\n", |
| 2018 | gRec[index].fSampleCnt, gRec[index].fName); |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2019 | outConfigs->remove(i); |
| 2020 | --i; |
| 2021 | } |
| 2022 | } |
| 2023 | } |
| 2024 | #endif |
| 2025 | |
| 2026 | if (outConfigs->isEmpty()) { |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 2027 | SkDebugf("No configs to run."); |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2028 | return false; |
| 2029 | } |
| 2030 | |
| 2031 | // now show the user the set of configs that will be run. |
| 2032 | SkString configStr("These configs will be run:"); |
| 2033 | // show the user the config that will run. |
| 2034 | for (int i = 0; i < outConfigs->count(); ++i) { |
| 2035 | configStr.appendf(" %s", gRec[(*outConfigs)[i]].fName); |
| 2036 | } |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 2037 | SkDebugf("%s\n", configStr.c_str()); |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2038 | |
| 2039 | return true; |
| 2040 | } |
| 2041 | |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 2042 | static bool parse_flags_pdf_rasterizers(const SkTDArray<size_t>& configs, |
| 2043 | SkTDArray<const PDFRasterizerData*>* outRasterizers) { |
| 2044 | // No need to run this check (and display the PDF rasterizers message) |
| 2045 | // if no PDF backends are in the configs. |
| 2046 | bool configHasPDF = false; |
| 2047 | for (int i = 0; i < configs.count(); i++) { |
| 2048 | if (gRec[configs[i]].fBackend == kPDF_Backend) { |
| 2049 | configHasPDF = true; |
| 2050 | break; |
| 2051 | } |
| 2052 | } |
| 2053 | if (!configHasPDF) { |
| 2054 | return true; |
| 2055 | } |
| 2056 | |
vandebo@chromium.org | f8afb2b | 2013-11-06 16:32:15 +0000 | [diff] [blame] | 2057 | if (FLAGS_pdfRasterizers.count() == 1 && |
| 2058 | !strcmp(FLAGS_pdfRasterizers[0], "default")) { |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 2059 | for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); ++i) { |
| 2060 | if (kPDFRasterizers[i].fRunByDefault) { |
| 2061 | *outRasterizers->append() = &kPDFRasterizers[i]; |
| 2062 | } |
| 2063 | } |
vandebo@chromium.org | f8afb2b | 2013-11-06 16:32:15 +0000 | [diff] [blame] | 2064 | } else { |
| 2065 | for (int i = 0; i < FLAGS_pdfRasterizers.count(); i++) { |
| 2066 | const char* rasterizer = FLAGS_pdfRasterizers[i]; |
| 2067 | const PDFRasterizerData* rasterizerPtr = |
| 2068 | findPDFRasterizer(rasterizer); |
| 2069 | if (rasterizerPtr == NULL) { |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 2070 | SkDebugf("unrecognized rasterizer %s\n", rasterizer); |
vandebo@chromium.org | f8afb2b | 2013-11-06 16:32:15 +0000 | [diff] [blame] | 2071 | return false; |
| 2072 | } |
| 2073 | appendUnique<const PDFRasterizerData*>(outRasterizers, |
| 2074 | rasterizerPtr); |
| 2075 | } |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 2076 | } |
| 2077 | |
| 2078 | // now show the user the set of configs that will be run. |
| 2079 | SkString configStr("These PDF rasterizers will be run:"); |
| 2080 | // show the user the config that will run. |
| 2081 | for (int i = 0; i < outRasterizers->count(); ++i) { |
| 2082 | configStr.appendf(" %s", (*outRasterizers)[i]->fName); |
| 2083 | } |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 2084 | SkDebugf("%s\n", configStr.c_str()); |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 2085 | |
| 2086 | return true; |
| 2087 | } |
| 2088 | |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2089 | static bool parse_flags_ignore_error_types(ErrorCombination* outErrorTypes) { |
| 2090 | if (FLAGS_ignoreErrorTypes.count() > 0) { |
| 2091 | *outErrorTypes = ErrorCombination(); |
| 2092 | for (int i = 0; i < FLAGS_ignoreErrorTypes.count(); i++) { |
| 2093 | ErrorType type; |
| 2094 | const char *name = FLAGS_ignoreErrorTypes[i]; |
| 2095 | if (!getErrorTypeByName(name, &type)) { |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 2096 | SkDebugf("cannot find ErrorType with name '%s'\n", name); |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2097 | return false; |
| 2098 | } else { |
| 2099 | outErrorTypes->add(type); |
| 2100 | } |
| 2101 | } |
| 2102 | } |
| 2103 | return true; |
| 2104 | } |
| 2105 | |
epoger@google.com | 3a882dd | 2013-10-07 18:55:09 +0000 | [diff] [blame] | 2106 | /** |
commit-bot@chromium.org | 3e62ebf | 2014-01-14 02:54:11 +0000 | [diff] [blame] | 2107 | * Replace contents of ignoreTestNames with a list of test names, indicating |
epoger@google.com | 3a882dd | 2013-10-07 18:55:09 +0000 | [diff] [blame] | 2108 | * which tests' failures should be ignored. |
| 2109 | */ |
commit-bot@chromium.org | 3e62ebf | 2014-01-14 02:54:11 +0000 | [diff] [blame] | 2110 | static bool parse_flags_ignore_tests(SkTArray<SkString> &ignoreTestNames) { |
| 2111 | ignoreTestNames.reset(); |
epoger@google.com | f711f32 | 2013-10-18 14:55:47 +0000 | [diff] [blame] | 2112 | |
epoger@google.com | f711f32 | 2013-10-18 14:55:47 +0000 | [diff] [blame] | 2113 | // Parse --ignoreFailuresFile |
| 2114 | for (int i = 0; i < FLAGS_ignoreFailuresFile.count(); i++) { |
| 2115 | SkTArray<SkString> linesFromFile; |
| 2116 | if (!read_lines_from_file(FLAGS_ignoreFailuresFile[i], linesFromFile)) { |
| 2117 | return false; |
| 2118 | } else { |
| 2119 | for (int j = 0; j < linesFromFile.count(); j++) { |
| 2120 | SkString thisLine = linesFromFile[j]; |
| 2121 | if (thisLine.isEmpty() || thisLine.startsWith('#')) { |
| 2122 | // skip this line |
| 2123 | } else { |
commit-bot@chromium.org | 3e62ebf | 2014-01-14 02:54:11 +0000 | [diff] [blame] | 2124 | ignoreTestNames.push_back(thisLine); |
epoger@google.com | f711f32 | 2013-10-18 14:55:47 +0000 | [diff] [blame] | 2125 | } |
| 2126 | } |
| 2127 | } |
| 2128 | } |
| 2129 | |
epoger@google.com | 3a882dd | 2013-10-07 18:55:09 +0000 | [diff] [blame] | 2130 | return true; |
| 2131 | } |
| 2132 | |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2133 | static bool parse_flags_modulo(int* moduloRemainder, int* moduloDivisor) { |
| 2134 | if (FLAGS_modulo.count() == 2) { |
| 2135 | *moduloRemainder = atoi(FLAGS_modulo[0]); |
| 2136 | *moduloDivisor = atoi(FLAGS_modulo[1]); |
| 2137 | if (*moduloRemainder < 0 || *moduloDivisor <= 0 || |
| 2138 | *moduloRemainder >= *moduloDivisor) { |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 2139 | SkDebugf("invalid modulo values."); |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2140 | return false; |
| 2141 | } |
| 2142 | } |
| 2143 | return true; |
| 2144 | } |
| 2145 | |
| 2146 | #if SK_SUPPORT_GPU |
| 2147 | static bool parse_flags_gpu_cache(int* sizeBytes, int* sizeCount) { |
| 2148 | if (FLAGS_gpuCacheSize.count() > 0) { |
| 2149 | if (FLAGS_gpuCacheSize.count() != 2) { |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 2150 | SkDebugf("--gpuCacheSize requires two arguments\n"); |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2151 | return false; |
| 2152 | } |
| 2153 | *sizeBytes = atoi(FLAGS_gpuCacheSize[0]); |
| 2154 | *sizeCount = atoi(FLAGS_gpuCacheSize[1]); |
| 2155 | } else { |
| 2156 | *sizeBytes = DEFAULT_CACHE_VALUE; |
| 2157 | *sizeCount = DEFAULT_CACHE_VALUE; |
| 2158 | } |
| 2159 | return true; |
| 2160 | } |
| 2161 | #endif |
| 2162 | |
| 2163 | static bool parse_flags_tile_grid_replay_scales(SkTDArray<SkScalar>* outScales) { |
| 2164 | *outScales->append() = SK_Scalar1; // By default only test at scale 1.0 |
| 2165 | if (FLAGS_tileGridReplayScales.count() > 0) { |
| 2166 | outScales->reset(); |
| 2167 | for (int i = 0; i < FLAGS_tileGridReplayScales.count(); i++) { |
| 2168 | double val = atof(FLAGS_tileGridReplayScales[i]); |
| 2169 | if (0 < val) { |
| 2170 | *outScales->append() = SkDoubleToScalar(val); |
| 2171 | } |
| 2172 | } |
| 2173 | if (0 == outScales->count()) { |
| 2174 | // Should have at least one scale |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 2175 | SkDebugf("--tileGridReplayScales requires at least one scale.\n"); |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2176 | return false; |
| 2177 | } |
| 2178 | } |
| 2179 | return true; |
| 2180 | } |
| 2181 | |
| 2182 | static bool parse_flags_gmmain_paths(GMMain* gmmain) { |
| 2183 | gmmain->fUseFileHierarchy = FLAGS_hierarchy; |
| 2184 | gmmain->fWriteChecksumBasedFilenames = FLAGS_writeChecksumBasedFilenames; |
| 2185 | |
| 2186 | if (FLAGS_mismatchPath.count() == 1) { |
| 2187 | gmmain->fMismatchPath = FLAGS_mismatchPath[0]; |
| 2188 | } |
| 2189 | |
| 2190 | if (FLAGS_missingExpectationsPath.count() == 1) { |
| 2191 | gmmain->fMissingExpectationsPath = FLAGS_missingExpectationsPath[0]; |
| 2192 | } |
| 2193 | |
| 2194 | if (FLAGS_readPath.count() == 1) { |
| 2195 | const char* readPath = FLAGS_readPath[0]; |
| 2196 | if (!sk_exists(readPath)) { |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 2197 | SkDebugf("readPath %s does not exist!\n", readPath); |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2198 | return false; |
| 2199 | } |
| 2200 | if (sk_isdir(readPath)) { |
| 2201 | if (FLAGS_verbose) { |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 2202 | SkDebugf("reading from %s\n", readPath); |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2203 | } |
| 2204 | gmmain->fExpectationsSource.reset(SkNEW_ARGS( |
| 2205 | IndividualImageExpectationsSource, (readPath))); |
| 2206 | } else { |
commit-bot@chromium.org | 25c1066 | 2014-05-16 17:56:43 +0000 | [diff] [blame] | 2207 | #ifdef SK_BUILD_JSON_WRITER |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2208 | if (FLAGS_verbose) { |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 2209 | SkDebugf("reading expectations from JSON summary file %s\n", readPath); |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2210 | } |
| 2211 | gmmain->fExpectationsSource.reset(SkNEW_ARGS(JsonExpectationsSource, (readPath))); |
commit-bot@chromium.org | 25c1066 | 2014-05-16 17:56:43 +0000 | [diff] [blame] | 2212 | #endif |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2213 | } |
| 2214 | } |
| 2215 | return true; |
| 2216 | } |
| 2217 | |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2218 | static bool parse_flags_resource_path() { |
| 2219 | if (FLAGS_resourcePath.count() == 1) { |
| 2220 | GM::SetResourcePath(FLAGS_resourcePath[0]); |
| 2221 | } |
| 2222 | return true; |
| 2223 | } |
| 2224 | |
| 2225 | static bool parse_flags_jpeg_quality() { |
| 2226 | if (FLAGS_pdfJpegQuality < -1 || FLAGS_pdfJpegQuality > 100) { |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 2227 | SkDebugf("%s\n", "pdfJpegQuality must be in [-1 .. 100] range."); |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2228 | return false; |
| 2229 | } |
| 2230 | return true; |
| 2231 | } |
| 2232 | |
epoger@google.com | 0b62b3d | 2013-03-20 17:59:28 +0000 | [diff] [blame] | 2233 | int tool_main(int argc, char** argv); |
| 2234 | int tool_main(int argc, char** argv) { |
| 2235 | |
commit-bot@chromium.org | 6dda827 | 2014-01-23 17:21:19 +0000 | [diff] [blame] | 2236 | SkString usage; |
| 2237 | usage.printf("Run the golden master tests.\n"); |
| 2238 | SkCommandLineFlags::SetUsage(usage.c_str()); |
| 2239 | SkCommandLineFlags::Parse(argc, argv); |
| 2240 | |
epoger@google.com | 0b62b3d | 2013-03-20 17:59:28 +0000 | [diff] [blame] | 2241 | #if SK_ENABLE_INST_COUNT |
commit-bot@chromium.org | 6dda827 | 2014-01-23 17:21:19 +0000 | [diff] [blame] | 2242 | if (FLAGS_leaks) { |
| 2243 | gPrintInstCount = true; |
| 2244 | } |
epoger@google.com | 0b62b3d | 2013-03-20 17:59:28 +0000 | [diff] [blame] | 2245 | #endif |
| 2246 | |
| 2247 | SkGraphics::Init(); |
epoger@google.com | 0b62b3d | 2013-03-20 17:59:28 +0000 | [diff] [blame] | 2248 | |
| 2249 | setSystemPreferences(); |
| 2250 | GMMain gmmain; |
| 2251 | |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2252 | SkTDArray<size_t> configs; |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 2253 | |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 2254 | int moduloRemainder = -1; |
| 2255 | int moduloDivisor = -1; |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 2256 | SkTDArray<const PDFRasterizerData*> pdfRasterizers; |
epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 2257 | SkTDArray<SkScalar> tileGridReplayScales; |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 2258 | #if SK_SUPPORT_GPU |
| 2259 | GrContextFactory* grFactory = new GrContextFactory; |
epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 2260 | #else |
| 2261 | GrContextFactory* grFactory = NULL; |
bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 2262 | #endif |
| 2263 | |
commit-bot@chromium.org | b17ccc9 | 2014-03-13 16:16:36 +0000 | [diff] [blame] | 2264 | if (FLAGS_dryRun) { |
| 2265 | SkDebugf( "Doing a dry run; no tests will actually be executed.\n"); |
| 2266 | } |
| 2267 | |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2268 | if (!parse_flags_modulo(&moduloRemainder, &moduloDivisor) || |
| 2269 | !parse_flags_ignore_error_types(&gmmain.fIgnorableErrorTypes) || |
commit-bot@chromium.org | 3e62ebf | 2014-01-14 02:54:11 +0000 | [diff] [blame] | 2270 | !parse_flags_ignore_tests(gmmain.fIgnorableTestNames) || |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2271 | #if SK_SUPPORT_GPU |
| 2272 | !parse_flags_gpu_cache(&gGpuCacheSizeBytes, &gGpuCacheSizeCount) || |
| 2273 | #endif |
| 2274 | !parse_flags_tile_grid_replay_scales(&tileGridReplayScales) || |
| 2275 | !parse_flags_resource_path() || |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2276 | !parse_flags_jpeg_quality() || |
| 2277 | !parse_flags_configs(&configs, grFactory) || |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 2278 | !parse_flags_pdf_rasterizers(configs, &pdfRasterizers) || |
commit-bot@chromium.org | ab882bf | 2013-08-14 21:56:47 +0000 | [diff] [blame] | 2279 | !parse_flags_gmmain_paths(&gmmain)) { |
bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 2280 | return -1; |
| 2281 | } |
| 2282 | |
epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 2283 | if (FLAGS_verbose) { |
| 2284 | if (FLAGS_writePath.count() == 1) { |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 2285 | SkDebugf("writing to %s\n", FLAGS_writePath[0]); |
epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 2286 | } |
epoger@google.com | fdea325 | 2013-05-02 18:24:03 +0000 | [diff] [blame] | 2287 | if (NULL != gmmain.fMismatchPath) { |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 2288 | SkDebugf("writing mismatches to %s\n", gmmain.fMismatchPath); |
epoger@google.com | fdea325 | 2013-05-02 18:24:03 +0000 | [diff] [blame] | 2289 | } |
epoger@google.com | 5f99545 | 2013-06-21 18:16:47 +0000 | [diff] [blame] | 2290 | if (NULL != gmmain.fMissingExpectationsPath) { |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 2291 | SkDebugf("writing images without expectations to %s\n", |
| 2292 | gmmain.fMissingExpectationsPath); |
epoger@google.com | 5f99545 | 2013-06-21 18:16:47 +0000 | [diff] [blame] | 2293 | } |
epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 2294 | if (FLAGS_writePicturePath.count() == 1) { |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 2295 | SkDebugf("writing pictures to %s\n", FLAGS_writePicturePath[0]); |
epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 2296 | } |
| 2297 | if (FLAGS_resourcePath.count() == 1) { |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 2298 | SkDebugf("reading resources from %s\n", FLAGS_resourcePath[0]); |
epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 2299 | } |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 2300 | } |
| 2301 | |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 2302 | int gmsRun = 0; |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 2303 | int gmIndex = -1; |
| 2304 | SkString moduloStr; |
| 2305 | |
commit-bot@chromium.org | b17ccc9 | 2014-03-13 16:16:36 +0000 | [diff] [blame] | 2306 | if (!FLAGS_dryRun) { |
| 2307 | // If we will be writing out files, prepare subdirectories. |
| 2308 | if (FLAGS_writePath.count() == 1) { |
| 2309 | if (!prepare_subdirectories(FLAGS_writePath[0], gmmain.fUseFileHierarchy, |
| 2310 | configs, pdfRasterizers)) { |
| 2311 | return -1; |
| 2312 | } |
| 2313 | } |
| 2314 | if (NULL != gmmain.fMismatchPath) { |
| 2315 | if (!prepare_subdirectories(gmmain.fMismatchPath, gmmain.fUseFileHierarchy, |
| 2316 | configs, pdfRasterizers)) { |
| 2317 | return -1; |
| 2318 | } |
| 2319 | } |
| 2320 | if (NULL != gmmain.fMissingExpectationsPath) { |
| 2321 | if (!prepare_subdirectories(gmmain.fMissingExpectationsPath, gmmain.fUseFileHierarchy, |
| 2322 | configs, pdfRasterizers)) { |
| 2323 | return -1; |
| 2324 | } |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 2325 | } |
epoger@google.com | fdea325 | 2013-05-02 18:24:03 +0000 | [diff] [blame] | 2326 | } |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 2327 | Iter iter; |
| 2328 | GM* gm; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 2329 | while ((gm = iter.next()) != NULL) { |
commit-bot@chromium.org | f4f9df4 | 2013-09-26 20:44:24 +0000 | [diff] [blame] | 2330 | if (FLAGS_forcePerspectiveMatrix) { |
| 2331 | SkMatrix perspective; |
| 2332 | perspective.setIdentity(); |
| 2333 | perspective.setPerspY(SkScalarDiv(SK_Scalar1, SkIntToScalar(1000))); |
| 2334 | perspective.setSkewX(SkScalarDiv(SkIntToScalar(8), |
| 2335 | SkIntToScalar(25))); |
| 2336 | |
| 2337 | gm->setStarterMatrix(perspective); |
skia.committer@gmail.com | 65caeaf | 2013-09-27 07:01:29 +0000 | [diff] [blame] | 2338 | } |
scroggo@google.com | 7fd2d70 | 2013-04-16 19:11:14 +0000 | [diff] [blame] | 2339 | SkAutoTDelete<GM> adgm(gm); |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 2340 | ++gmIndex; |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 2341 | if (moduloRemainder >= 0) { |
| 2342 | if ((gmIndex % moduloDivisor) != moduloRemainder) { |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 2343 | continue; |
| 2344 | } |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 2345 | moduloStr.printf("[%d.%d] ", gmIndex, moduloDivisor); |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 2346 | } |
| 2347 | |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 2348 | const char* shortName = gm->getName(); |
sglez@google.com | 586db93 | 2013-07-24 17:24:23 +0000 | [diff] [blame] | 2349 | |
commit-bot@chromium.org | a6f37e7 | 2013-08-30 15:52:46 +0000 | [diff] [blame] | 2350 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, shortName)) { |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 2351 | continue; |
| 2352 | } |
| 2353 | |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 2354 | gmsRun++; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 2355 | SkISize size = gm->getISize(); |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 2356 | SkDebugf("%sdrawing... %s [%d %d]\n", moduloStr.c_str(), shortName, |
| 2357 | size.width(), size.height()); |
commit-bot@chromium.org | b17ccc9 | 2014-03-13 16:16:36 +0000 | [diff] [blame] | 2358 | if (!FLAGS_dryRun) |
| 2359 | run_multiple_configs(gmmain, gm, configs, pdfRasterizers, tileGridReplayScales, grFactory); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 2360 | } |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 2361 | |
commit-bot@chromium.org | b17ccc9 | 2014-03-13 16:16:36 +0000 | [diff] [blame] | 2362 | if (FLAGS_dryRun) |
| 2363 | return 0; |
| 2364 | |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 2365 | SkTArray<SkString> modes; |
| 2366 | gmmain.GetRenderModesEncountered(modes); |
commit-bot@chromium.org | 8519548 | 2014-01-13 18:27:59 +0000 | [diff] [blame] | 2367 | int modeCount = modes.count(); |
| 2368 | |
| 2369 | // Now that we have run all the tests and thus know the full set of renderModes that we |
| 2370 | // tried to run, we can call RecordTestResults() to record the cases in which we skipped |
| 2371 | // ALL renderModes. |
| 2372 | // See http://skbug.com/1994 and https://codereview.chromium.org/129203002/ |
| 2373 | int testCount = gmmain.fTestsSkippedOnAllRenderModes.count(); |
| 2374 | for (int testNum = 0; testNum < testCount; ++testNum) { |
| 2375 | const SkString &shortNamePlusConfig = gmmain.fTestsSkippedOnAllRenderModes[testNum]; |
| 2376 | for (int modeNum = 0; modeNum < modeCount; ++modeNum) { |
| 2377 | gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, |
| 2378 | modes[modeNum].c_str()); |
| 2379 | } |
| 2380 | } |
| 2381 | |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 2382 | bool reportError = false; |
| 2383 | if (gmmain.NumSignificantErrors() > 0) { |
| 2384 | reportError = true; |
| 2385 | } |
commit-bot@chromium.org | 8519548 | 2014-01-13 18:27:59 +0000 | [diff] [blame] | 2386 | |
| 2387 | // We test every GM against every config, and for every raster config also test every mode. |
| 2388 | int rasterConfigs = 0; |
| 2389 | for (int i = 0; i < configs.count(); i++) { |
| 2390 | if (gRec[configs[i]].fBackend == kRaster_Backend) { |
| 2391 | rasterConfigs++; |
| 2392 | } |
| 2393 | } |
| 2394 | // For raster configs, we run all renderModes; for non-raster configs, just default renderMode |
| 2395 | const int expectedNumberOfTests = rasterConfigs * gmsRun * modeCount |
| 2396 | + (configs.count() - rasterConfigs) * gmsRun; |
epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 2397 | |
| 2398 | // Output summary to stdout. |
epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame] | 2399 | if (FLAGS_verbose) { |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 2400 | SkDebugf("Ran %d GMs\n", gmsRun); |
| 2401 | SkDebugf("... over %2d configs [%s]\n", configs.count(), |
| 2402 | list_all_config_names(configs).c_str()); |
| 2403 | SkDebugf("... and %2d modes [%s]\n", modeCount, list_all(modes).c_str()); |
| 2404 | 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] | 2405 | } |
| 2406 | gmmain.ListErrors(FLAGS_verbose); |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 2407 | |
epoger@google.com | 07947d9 | 2013-04-11 15:41:02 +0000 | [diff] [blame] | 2408 | // TODO(epoger): Enable this check for Android, too, once we resolve |
| 2409 | // https://code.google.com/p/skia/issues/detail?id=1222 |
| 2410 | // ('GM is unexpectedly skipping tests on Android') |
| 2411 | #ifndef SK_BUILD_FOR_ANDROID |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 2412 | if (expectedNumberOfTests != gmmain.fTestsRun) { |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 2413 | SkDebugf("expected %d tests, but ran or skipped %d tests\n", |
| 2414 | expectedNumberOfTests, gmmain.fTestsRun); |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 2415 | reportError = true; |
| 2416 | } |
| 2417 | #endif |
| 2418 | |
commit-bot@chromium.org | 25c1066 | 2014-05-16 17:56:43 +0000 | [diff] [blame] | 2419 | #ifdef SK_BUILD_JSON_WRITER |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 2420 | if (FLAGS_writeJsonSummaryPath.count() == 1) { |
epoger@google.com | 76c913d | 2013-04-26 15:06:44 +0000 | [diff] [blame] | 2421 | Json::Value root = CreateJsonTree( |
| 2422 | gmmain.fJsonExpectedResults, |
| 2423 | gmmain.fJsonActualResults_Failed, gmmain.fJsonActualResults_FailureIgnored, |
| 2424 | gmmain.fJsonActualResults_NoComparison, gmmain.fJsonActualResults_Succeeded); |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 2425 | std::string jsonStdString = root.toStyledString(); |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 2426 | SkFILEWStream stream(FLAGS_writeJsonSummaryPath[0]); |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 2427 | stream.write(jsonStdString.c_str(), jsonStdString.length()); |
| 2428 | } |
commit-bot@chromium.org | 25c1066 | 2014-05-16 17:56:43 +0000 | [diff] [blame] | 2429 | #endif |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 2430 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 2431 | #if SK_SUPPORT_GPU |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 2432 | |
robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 2433 | #if GR_CACHE_STATS |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 2434 | for (int i = 0; i < configs.count(); i++) { |
| 2435 | ConfigData config = gRec[configs[i]]; |
| 2436 | |
epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 2437 | if (FLAGS_verbose && (kGPU_Backend == config.fBackend)) { |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 2438 | GrContext* gr = grFactory->get(config.fGLContextType); |
| 2439 | |
commit-bot@chromium.org | 2b3a204 | 2014-02-27 18:45:26 +0000 | [diff] [blame] | 2440 | SkDebugf("config: %s %x\n", config.fName, gr); |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 2441 | gr->printCacheStats(); |
| 2442 | } |
| 2443 | } |
| 2444 | #endif |
| 2445 | |
commit-bot@chromium.org | 8065ec5 | 2014-03-11 15:57:40 +0000 | [diff] [blame] | 2446 | #if GR_DUMP_FONT_CACHE |
| 2447 | for (int i = 0; i < configs.count(); i++) { |
| 2448 | ConfigData config = gRec[configs[i]]; |
| 2449 | |
| 2450 | if (kGPU_Backend == config.fBackend) { |
| 2451 | GrContext* gr = grFactory->get(config.fGLContextType); |
| 2452 | |
| 2453 | gr->dumpFontCache(); |
| 2454 | } |
| 2455 | } |
| 2456 | #endif |
| 2457 | |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 2458 | delete grFactory; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 2459 | #endif |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 2460 | SkGraphics::Term(); |
| 2461 | |
epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 2462 | return (reportError) ? -1 : 0; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 2463 | } |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 2464 | |
scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 2465 | void GMMain::installFilter(SkCanvas* canvas) { |
| 2466 | if (FLAGS_forceBWtext) { |
| 2467 | canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); |
| 2468 | } |
| 2469 | } |
| 2470 | |
borenet@google.com | 7158e6a | 2012-11-01 17:43:44 +0000 | [diff] [blame] | 2471 | #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 2472 | int main(int argc, char * const argv[]) { |
| 2473 | return tool_main(argc, (char**) argv); |
| 2474 | } |
| 2475 | #endif |