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