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