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