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