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