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