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