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