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