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