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