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