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