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