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