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