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