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