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