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