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