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