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