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 | 526db49 | 2013-03-07 21:02:50 +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; |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 90 | const static ErrorBitfield ERROR_NONE = 0x00; |
| 91 | const static ErrorBitfield ERROR_NO_GPU_CONTEXT = 0x01; |
| 92 | const static ErrorBitfield ERROR_IMAGE_MISMATCH = 0x02; |
| 93 | // const static ErrorBitfield ERROR_DIMENSION_MISMATCH = 0x04; DEPRECATED in https://codereview.appspot.com/7064047 |
| 94 | const static ErrorBitfield ERROR_READING_REFERENCE_IMAGE = 0x08; |
| 95 | const static ErrorBitfield ERROR_WRITING_REFERENCE_IMAGE = 0x10; |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 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 | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 257 | bool isPixelError; |
| 258 | switch (errorType) { |
| 259 | case ERROR_NONE: |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 260 | return; |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 261 | case ERROR_READING_REFERENCE_IMAGE: |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 262 | return; |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 263 | case ERROR_IMAGE_MISMATCH: |
| 264 | isPixelError = true; |
| 265 | break; |
| 266 | default: |
| 267 | isPixelError = false; |
| 268 | break; |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | FailRec& rec = fFailedTests.push_back(make_name( |
| 272 | name.c_str(), renderModeDescriptor)); |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 273 | rec.fIsPixelError = isPixelError; |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 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) { |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 413 | return ERROR_NO_GPU_CONTEXT; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 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 | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 431 | return ERROR_NONE; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 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) { |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 525 | return ERROR_NONE; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 526 | } else { |
| 527 | fprintf(stderr, "FAILED to write %s\n", path.c_str()); |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 528 | RecordError(ERROR_WRITING_REFERENCE_IMAGE, name, |
epoger@google.com | 57f7abc | 2012-11-13 03:41:55 +0000 | [diff] [blame] | 529 | renderModeDescriptor); |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 530 | return ERROR_WRITING_REFERENCE_IMAGE; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 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 | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 590 | * Compares actual checksum to expectations. |
| 591 | * Returns ERROR_NONE if they match, or some particular error code otherwise |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 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 | 526db49 | 2013-03-07 21:02:50 +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)) { |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 622 | retval = ERROR_NONE; |
epoger@google.com | 9ef89ce | 2013-01-18 21:45:42 +0000 | [diff] [blame] | 623 | } else { |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +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); |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 665 | if (ERROR_NONE == result) { |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 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 | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 673 | // failures (both for ERROR_READING_REFERENCE_IMAGE |
| 674 | // and ERROR_IMAGE_MISMATCH). |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 675 | this->fJsonActualResults_FailureIgnored[testName] = |
| 676 | actualResults; |
| 677 | } else { |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 678 | switch(result) { |
| 679 | case ERROR_READING_REFERENCE_IMAGE: |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 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; |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 693 | break; |
| 694 | case ERROR_IMAGE_MISMATCH: |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 695 | this->fJsonActualResults_Failed[testName] = actualResults; |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 696 | break; |
| 697 | default: |
| 698 | fprintf(stderr, "encountered unexpected result %d\n", |
| 699 | result); |
| 700 | SkDEBUGFAIL("encountered unexpected result"); |
| 701 | break; |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 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 | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 738 | ErrorBitfield retval = ERROR_NONE; |
epoger@google.com | 9ef89ce | 2013-01-18 21:45:42 +0000 | [diff] [blame] | 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, |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 765 | ERROR_READING_REFERENCE_IMAGE, |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 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 | 29b19e5 | 2013-02-27 18:35:16 +0000 | [diff] [blame] | 809 | SkTileGridPicture::TileGridInfo info; |
| 810 | info.fMargin.setEmpty(); |
| 811 | info.fOffset.setZero(); |
| 812 | info.fTileInterval.set(16, 16); |
| 813 | pict = new SkTileGridPicture(width, height, info); |
junov@chromium.org | 3cb834b | 2012-12-13 16:39:53 +0000 | [diff] [blame] | 814 | } else { |
| 815 | pict = new SkPicture; |
| 816 | } |
junov@chromium.org | 20bd04e | 2013-01-16 18:43:36 +0000 | [diff] [blame] | 817 | if (kNone_BbhType != bbhType) { |
| 818 | recordFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; |
| 819 | } |
junov@chromium.org | 706ff2f | 2012-12-19 15:55:40 +0000 | [diff] [blame] | 820 | SkCanvas* cv = pict->beginRecording(width, height, recordFlags); |
junov@chromium.org | c938c48 | 2012-12-19 15:24:38 +0000 | [diff] [blame] | 821 | cv->scale(scale, scale); |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 822 | invokeGM(gm, cv, false, false); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 823 | pict->endRecording(); |
| 824 | |
| 825 | return pict; |
| 826 | } |
| 827 | |
| 828 | static SkPicture* stream_to_new_picture(const SkPicture& src) { |
| 829 | |
| 830 | // To do in-memory commiunications with a stream, we need to: |
| 831 | // * create a dynamic memory stream |
| 832 | // * copy it into a buffer |
| 833 | // * create a read stream from it |
| 834 | // ?!?! |
| 835 | |
| 836 | SkDynamicMemoryWStream storage; |
| 837 | src.serialize(&storage); |
| 838 | |
| 839 | int streamSize = storage.getOffset(); |
| 840 | SkAutoMalloc dstStorage(streamSize); |
| 841 | void* dst = dstStorage.get(); |
| 842 | //char* dst = new char [streamSize]; |
| 843 | //@todo thudson 22 April 2011 when can we safely delete [] dst? |
| 844 | storage.copyTo(dst); |
| 845 | SkMemoryStream pictReadback(dst, streamSize); |
| 846 | SkPicture* retval = new SkPicture (&pictReadback); |
| 847 | return retval; |
| 848 | } |
| 849 | |
| 850 | // Test: draw into a bitmap or pdf. |
epoger@google.com | 15655b2 | 2013-01-08 18:47:31 +0000 | [diff] [blame] | 851 | // Depending on flags, possibly compare to an expected image. |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 852 | ErrorBitfield test_drawing(GM* gm, |
| 853 | const ConfigData& gRec, |
| 854 | const char writePath [], |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 855 | GrContext* context, |
| 856 | GrRenderTarget* rt, |
epoger@google.com | 57f7abc | 2012-11-13 03:41:55 +0000 | [diff] [blame] | 857 | SkBitmap* bitmap) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 858 | SkDynamicMemoryWStream document; |
| 859 | |
| 860 | if (gRec.fBackend == kRaster_Backend || |
| 861 | gRec.fBackend == kGPU_Backend) { |
| 862 | // Early exit if we can't generate the image. |
| 863 | ErrorBitfield errors = generate_image(gm, gRec, context, rt, bitmap, |
| 864 | false); |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 865 | if (ERROR_NONE != errors) { |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 866 | // TODO: Add a test to exercise what the stdout and |
| 867 | // JSON look like if we get an "early error" while |
| 868 | // trying to generate the image. |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 869 | return errors; |
| 870 | } |
| 871 | } else if (gRec.fBackend == kPDF_Backend) { |
| 872 | generate_pdf(gm, document); |
| 873 | #if CAN_IMAGE_PDF |
| 874 | SkAutoDataUnref data(document.copyToData()); |
| 875 | SkMemoryStream stream(data->data(), data->size()); |
| 876 | SkPDFDocumentToBitmap(&stream, bitmap); |
| 877 | #endif |
| 878 | } else if (gRec.fBackend == kXPS_Backend) { |
| 879 | generate_xps(gm, document); |
| 880 | } |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 881 | return compare_test_results_to_stored_expectations( |
| 882 | gm, gRec, writePath, *bitmap, &document); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 883 | } |
| 884 | |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 885 | ErrorBitfield test_deferred_drawing(GM* gm, |
| 886 | const ConfigData& gRec, |
| 887 | const SkBitmap& referenceBitmap, |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 888 | GrContext* context, |
| 889 | GrRenderTarget* rt) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 890 | SkDynamicMemoryWStream document; |
| 891 | |
| 892 | if (gRec.fBackend == kRaster_Backend || |
| 893 | gRec.fBackend == kGPU_Backend) { |
| 894 | SkBitmap bitmap; |
| 895 | // Early exit if we can't generate the image, but this is |
| 896 | // expected in some cases, so don't report a test failure. |
| 897 | if (!generate_image(gm, gRec, context, rt, &bitmap, true)) { |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 898 | return ERROR_NONE; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 899 | } |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 900 | return compare_test_results_to_reference_bitmap( |
| 901 | gm, gRec, "-deferred", bitmap, &referenceBitmap); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 902 | } |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 903 | return ERROR_NONE; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 904 | } |
| 905 | |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 906 | ErrorBitfield test_pipe_playback(GM* gm, |
| 907 | const ConfigData& gRec, |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 908 | const SkBitmap& referenceBitmap) { |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 909 | ErrorBitfield errors = ERROR_NONE; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 910 | for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) { |
| 911 | SkBitmap bitmap; |
| 912 | SkISize size = gm->getISize(); |
| 913 | setup_bitmap(gRec, size, &bitmap); |
| 914 | SkCanvas canvas(bitmap); |
| 915 | PipeController pipeController(&canvas); |
| 916 | SkGPipeWriter writer; |
| 917 | SkCanvas* pipeCanvas = writer.startRecording( |
| 918 | &pipeController, gPipeWritingFlagCombos[i].flags); |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 919 | invokeGM(gm, pipeCanvas, false, false); |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 920 | complete_bitmap(&bitmap); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 921 | writer.endRecording(); |
| 922 | SkString string("-pipe"); |
| 923 | string.append(gPipeWritingFlagCombos[i].name); |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 924 | errors |= compare_test_results_to_reference_bitmap( |
| 925 | gm, gRec, string.c_str(), bitmap, &referenceBitmap); |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 926 | if (errors != ERROR_NONE) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 927 | break; |
| 928 | } |
| 929 | } |
| 930 | return errors; |
| 931 | } |
| 932 | |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 933 | ErrorBitfield test_tiled_pipe_playback( |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 934 | GM* gm, const ConfigData& gRec, const SkBitmap& referenceBitmap) { |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 935 | ErrorBitfield errors = ERROR_NONE; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 936 | for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) { |
| 937 | SkBitmap bitmap; |
| 938 | SkISize size = gm->getISize(); |
| 939 | setup_bitmap(gRec, size, &bitmap); |
| 940 | SkCanvas canvas(bitmap); |
| 941 | TiledPipeController pipeController(bitmap); |
| 942 | SkGPipeWriter writer; |
| 943 | SkCanvas* pipeCanvas = writer.startRecording( |
| 944 | &pipeController, gPipeWritingFlagCombos[i].flags); |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 945 | invokeGM(gm, pipeCanvas, false, false); |
epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 946 | complete_bitmap(&bitmap); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 947 | writer.endRecording(); |
| 948 | SkString string("-tiled pipe"); |
| 949 | string.append(gPipeWritingFlagCombos[i].name); |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 950 | errors |= compare_test_results_to_reference_bitmap( |
| 951 | gm, gRec, string.c_str(), bitmap, &referenceBitmap); |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 952 | if (errors != ERROR_NONE) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 953 | break; |
| 954 | } |
| 955 | } |
| 956 | return errors; |
| 957 | } |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 958 | |
| 959 | // |
| 960 | // member variables. |
| 961 | // They are public for now, to allow easier setting by tool_main(). |
| 962 | // |
| 963 | |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 964 | bool fUseFileHierarchy; |
| 965 | |
junov@chromium.org | 95146eb | 2013-01-11 21:04:40 +0000 | [diff] [blame] | 966 | const char* fMismatchPath; |
| 967 | |
epoger@google.com | 57f7abc | 2012-11-13 03:41:55 +0000 | [diff] [blame] | 968 | // information about all failed tests we have encountered so far |
| 969 | SkTArray<FailRec> fFailedTests; |
| 970 | |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 971 | // Where to read expectations (expected image checksums, etc.) from. |
| 972 | // If unset, we don't do comparisons. |
| 973 | SkAutoTUnref<ExpectationsSource> fExpectationsSource; |
| 974 | |
| 975 | // JSON summaries that we generate as we go (just for output). |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 976 | Json::Value fJsonExpectedResults; |
| 977 | Json::Value fJsonActualResults_Failed; |
| 978 | Json::Value fJsonActualResults_FailureIgnored; |
epoger@google.com | 9c56a8d | 2012-12-20 18:34:29 +0000 | [diff] [blame] | 979 | Json::Value fJsonActualResults_NoComparison; |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 980 | Json::Value fJsonActualResults_Succeeded; |
| 981 | |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 982 | }; // end of GMMain class definition |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 983 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 984 | #if SK_SUPPORT_GPU |
| 985 | static const GLContextType kDontCare_GLContextType = GrContextFactory::kNative_GLContextType; |
| 986 | #else |
| 987 | static const GLContextType kDontCare_GLContextType = 0; |
| 988 | #endif |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 989 | |
| 990 | // 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] | 991 | // 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] | 992 | static const ConfigFlags kPDFConfigFlags = CAN_IMAGE_PDF ? kRW_ConfigFlag : |
| 993 | kWrite_ConfigFlag; |
| 994 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 995 | static const ConfigData gRec[] = { |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 996 | { 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] | 997 | #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] | 998 | { 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] | 999 | #endif |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1000 | { 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] | 1001 | #if defined(SK_SCALAR_IS_FLOAT) && SK_SUPPORT_GPU |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1002 | { 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] | 1003 | #ifndef SK_BUILD_FOR_ANDROID |
| 1004 | // currently we don't want to run MSAA tests on Android |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1005 | { 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] | 1006 | #endif |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1007 | /* The debug context does not generate images */ |
| 1008 | { 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] | 1009 | #if SK_ANGLE |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1010 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 0, kRW_ConfigFlag, "angle" }, |
| 1011 | { 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] | 1012 | #endif // SK_ANGLE |
| 1013 | #ifdef SK_MESA |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1014 | { 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] | 1015 | #endif // SK_MESA |
robertphillips@google.com | a73e860 | 2012-08-02 17:56:02 +0000 | [diff] [blame] | 1016 | #endif // defined(SK_SCALAR_IS_FLOAT) && SK_SUPPORT_GPU |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1017 | #ifdef SK_SUPPORT_XPS |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1018 | /* At present we have no way of comparing XPS files (either natively or by converting to PNG). */ |
| 1019 | { 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] | 1020 | #endif // SK_SUPPORT_XPS |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1021 | #ifdef SK_SUPPORT_PDF |
| 1022 | { SkBitmap::kARGB_8888_Config, kPDF_Backend, kDontCare_GLContextType, 0, kPDFConfigFlags, "pdf" }, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1023 | #endif // SK_SUPPORT_PDF |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1024 | }; |
| 1025 | |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1026 | static void usage(const char * argv0) { |
| 1027 | SkDebugf("%s\n", argv0); |
reed@google.com | e5f48b9 | 2012-06-22 15:27:39 +0000 | [diff] [blame] | 1028 | SkDebugf(" [--config "); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1029 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 1030 | if (i > 0) { |
| 1031 | SkDebugf("|"); |
| 1032 | } |
| 1033 | SkDebugf(gRec[i].fName); |
| 1034 | } |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1035 | SkDebugf("]:\n run these configurations\n"); |
| 1036 | SkDebugf( |
| 1037 | // Alphabetized ignoring "no" prefix ("readPath", "noreplay", "resourcePath"). |
| 1038 | // It would probably be better if we allowed both yes-and-no settings for each |
| 1039 | // one, e.g.: |
| 1040 | // [--replay|--noreplay]: whether to exercise SkPicture replay; default is yes |
| 1041 | " [--nodeferred]: skip the deferred rendering test pass\n" |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1042 | " [--disable-missing-warning]: don't print a message to stderr if\n" |
| 1043 | " unable to read a reference image for any tests (NOT default behavior)\n" |
| 1044 | " [--enable-missing-warning]: print message to stderr (but don't fail) if\n" |
| 1045 | " 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] | 1046 | " [--exclude-config]: disable this config (may be used multiple times)\n" |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1047 | " [--forceBWtext]: disable text anti-aliasing\n" |
| 1048 | " [--help|-h]: show this help message\n" |
| 1049 | " [--hierarchy|--nohierarchy]: whether to use multilevel directory structure\n" |
| 1050 | " when reading/writing files; default is no\n" |
| 1051 | " [--match <substring>]: only run tests whose name includes this substring\n" |
junov@chromium.org | 95146eb | 2013-01-11 21:04:40 +0000 | [diff] [blame] | 1052 | " [--mismatchPath <path>]: write images for tests that failed due to\n" |
| 1053 | " pixel mismatched into this directory" |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1054 | " [--modulo <remainder> <divisor>]: only run tests for which \n" |
| 1055 | " testIndex %% divisor == remainder\n" |
| 1056 | " [--nopdf]: skip the pdf rendering test pass\n" |
| 1057 | " [--nopipe]: Skip SkGPipe replay\n" |
| 1058 | " [--readPath|-r <path>]: read reference images from this dir, and report\n" |
| 1059 | " any differences between those and the newly generated ones\n" |
| 1060 | " [--noreplay]: do not exercise SkPicture replay\n" |
| 1061 | " [--resourcePath|-i <path>]: directory that stores image resources\n" |
junov@chromium.org | 58be101 | 2012-12-18 21:09:45 +0000 | [diff] [blame] | 1062 | " [--nortree]: Do not exercise the R-Tree variant of SkPicture\n" |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1063 | " [--noserialize]: do not exercise SkPicture serialization & deserialization\n" |
| 1064 | " [--notexturecache]: disable the gpu texture cache\n" |
| 1065 | " [--tiledPipe]: Exercise tiled SkGPipe replay\n" |
junov@chromium.org | 58be101 | 2012-12-18 21:09:45 +0000 | [diff] [blame] | 1066 | " [--notileGrid]: Do not exercise the tile grid variant of SkPicture\n" |
junov@chromium.org | c938c48 | 2012-12-19 15:24:38 +0000 | [diff] [blame] | 1067 | " [--tileGridReplayScales <scales>]: Comma separated list of floating-point scale\n" |
| 1068 | " 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] | 1069 | " [--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] | 1070 | " [--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] | 1071 | " [--writePath|-w <path>]: write rendered images into this directory\n" |
| 1072 | " [--writePicturePath|-wp <path>]: write .skp files into this directory\n" |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1073 | ); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | static int findConfig(const char config[]) { |
| 1077 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { |
| 1078 | if (!strcmp(config, gRec[i].fName)) { |
| 1079 | return i; |
| 1080 | } |
| 1081 | } |
| 1082 | return -1; |
| 1083 | } |
| 1084 | |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 1085 | static bool skip_name(const SkTDArray<const char*> array, const char name[]) { |
| 1086 | if (0 == array.count()) { |
| 1087 | // no names, so don't skip anything |
| 1088 | return false; |
| 1089 | } |
| 1090 | for (int i = 0; i < array.count(); ++i) { |
| 1091 | if (strstr(name, array[i])) { |
| 1092 | // found the name, so don't skip |
| 1093 | return false; |
| 1094 | } |
| 1095 | } |
| 1096 | return true; |
| 1097 | } |
| 1098 | |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 1099 | namespace skiagm { |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1100 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1101 | SkAutoTUnref<GrContext> gGrContext; |
| 1102 | /** |
bsalomon@google.com | c7a24d2 | 2012-11-01 18:03:48 +0000 | [diff] [blame] | 1103 | * Sets the global GrContext, accessible by individual GMs |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1104 | */ |
caryclark@google.com | 1313086 | 2012-06-06 12:10:45 +0000 | [diff] [blame] | 1105 | static void SetGr(GrContext* grContext) { |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1106 | SkSafeRef(grContext); |
| 1107 | gGrContext.reset(grContext); |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 1108 | } |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1109 | |
| 1110 | /** |
| 1111 | * Gets the global GrContext, can be called by GM tests. |
| 1112 | */ |
caryclark@google.com | 1313086 | 2012-06-06 12:10:45 +0000 | [diff] [blame] | 1113 | GrContext* GetGr(); |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1114 | GrContext* GetGr() { |
| 1115 | return gGrContext.get(); |
| 1116 | } |
| 1117 | |
| 1118 | /** |
| 1119 | * Sets the global GrContext and then resets it to its previous value at |
| 1120 | * destruction. |
| 1121 | */ |
| 1122 | class AutoResetGr : SkNoncopyable { |
| 1123 | public: |
| 1124 | AutoResetGr() : fOld(NULL) {} |
| 1125 | void set(GrContext* context) { |
| 1126 | SkASSERT(NULL == fOld); |
| 1127 | fOld = GetGr(); |
| 1128 | SkSafeRef(fOld); |
| 1129 | SetGr(context); |
| 1130 | } |
| 1131 | ~AutoResetGr() { SetGr(fOld); SkSafeUnref(fOld); } |
| 1132 | private: |
| 1133 | GrContext* fOld; |
| 1134 | }; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1135 | #else |
| 1136 | GrContext* GetGr() { return NULL; } |
| 1137 | #endif |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 1138 | } |
| 1139 | |
reed@google.com | fb2cd42 | 2013-01-04 14:43:03 +0000 | [diff] [blame] | 1140 | template <typename T> void appendUnique(SkTDArray<T>* array, const T& value) { |
| 1141 | int index = array->find(value); |
| 1142 | if (index < 0) { |
| 1143 | *array->append() = value; |
| 1144 | } |
| 1145 | } |
| 1146 | |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 1147 | int tool_main(int argc, char** argv); |
| 1148 | int tool_main(int argc, char** argv) { |
robertphillips@google.com | b74af87 | 2012-06-27 19:41:42 +0000 | [diff] [blame] | 1149 | |
bsalomon@google.com | 4e23068 | 2013-01-15 20:37:04 +0000 | [diff] [blame] | 1150 | #if SK_ENABLE_INST_COUNT |
robertphillips@google.com | b74af87 | 2012-06-27 19:41:42 +0000 | [diff] [blame] | 1151 | gPrintInstCount = true; |
| 1152 | #endif |
| 1153 | |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 1154 | SkGraphics::Init(); |
reed@google.com | 8923c6c | 2011-11-08 14:59:38 +0000 | [diff] [blame] | 1155 | // we don't need to see this during a run |
| 1156 | gSkSuppressFontCachePurgeSpew = true; |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 1157 | |
epoger@google.com | 7bc13a6 | 2012-02-14 14:53:59 +0000 | [diff] [blame] | 1158 | setSystemPreferences(); |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1159 | GMMain gmmain; |
epoger@google.com | 7bc13a6 | 2012-02-14 14:53:59 +0000 | [diff] [blame] | 1160 | |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 1161 | 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] | 1162 | 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] | 1163 | 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] | 1164 | 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] | 1165 | 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] | 1166 | |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1167 | // if true, emit a message when we can't find a reference image to compare |
| 1168 | bool notifyMissingReadReference = true; |
| 1169 | |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 1170 | SkTDArray<const char*> fMatches; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 1171 | |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 1172 | bool doPDF = true; |
reed@google.com | b8b0983 | 2011-05-26 15:57:56 +0000 | [diff] [blame] | 1173 | bool doReplay = true; |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 1174 | bool doPipe = true; |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 1175 | bool doTiledPipe = false; |
scroggo@google.com | 3936252 | 2012-09-14 17:37:46 +0000 | [diff] [blame] | 1176 | bool doSerialize = true; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 1177 | bool doDeferred = true; |
junov@chromium.org | 58be101 | 2012-12-18 21:09:45 +0000 | [diff] [blame] | 1178 | bool doRTree = true; |
| 1179 | bool doTileGrid = true; |
reed@google.com | fb2cd42 | 2013-01-04 14:43:03 +0000 | [diff] [blame] | 1180 | bool doVerbose = false; |
sugoi@google.com | 9c55f80 | 2013-03-07 20:52:59 +0000 | [diff] [blame] | 1181 | #if SK_SUPPORT_GPU |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 1182 | bool disableTextureCache = false; |
sugoi@google.com | 9c55f80 | 2013-03-07 20:52:59 +0000 | [diff] [blame] | 1183 | #endif |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1184 | SkTDArray<size_t> configs; |
reed@google.com | fb2cd42 | 2013-01-04 14:43:03 +0000 | [diff] [blame] | 1185 | SkTDArray<size_t> excludeConfigs; |
junov@chromium.org | c938c48 | 2012-12-19 15:24:38 +0000 | [diff] [blame] | 1186 | SkTDArray<SkScalar> tileGridReplayScales; |
| 1187 | *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] | 1188 | bool userConfig = false; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 1189 | |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1190 | int moduloRemainder = -1; |
| 1191 | int moduloDivisor = -1; |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1192 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1193 | const char* const commandName = argv[0]; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 1194 | char* const* stop = argv + argc; |
| 1195 | for (++argv; argv < stop; ++argv) { |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1196 | if (strcmp(*argv, "--config") == 0) { |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1197 | argv++; |
| 1198 | if (argv < stop) { |
| 1199 | int index = findConfig(*argv); |
| 1200 | if (index >= 0) { |
reed@google.com | fb2cd42 | 2013-01-04 14:43:03 +0000 | [diff] [blame] | 1201 | appendUnique<size_t>(&configs, index); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1202 | userConfig = true; |
| 1203 | } else { |
| 1204 | SkString str; |
| 1205 | str.printf("unrecognized config %s\n", *argv); |
| 1206 | SkDebugf(str.c_str()); |
| 1207 | usage(commandName); |
| 1208 | return -1; |
| 1209 | } |
| 1210 | } else { |
reed@google.com | e5f48b9 | 2012-06-22 15:27:39 +0000 | [diff] [blame] | 1211 | SkDebugf("missing arg for --config\n"); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1212 | usage(commandName); |
| 1213 | return -1; |
| 1214 | } |
reed@google.com | fb2cd42 | 2013-01-04 14:43:03 +0000 | [diff] [blame] | 1215 | } else if (strcmp(*argv, "--exclude-config") == 0) { |
| 1216 | argv++; |
| 1217 | if (argv < stop) { |
| 1218 | int index = findConfig(*argv); |
| 1219 | if (index >= 0) { |
| 1220 | *excludeConfigs.append() = index; |
| 1221 | } else { |
| 1222 | SkString str; |
| 1223 | str.printf("unrecognized exclude-config %s\n", *argv); |
| 1224 | SkDebugf(str.c_str()); |
| 1225 | usage(commandName); |
| 1226 | return -1; |
| 1227 | } |
| 1228 | } else { |
| 1229 | SkDebugf("missing arg for --exclude-config\n"); |
| 1230 | usage(commandName); |
| 1231 | return -1; |
| 1232 | } |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1233 | } else if (strcmp(*argv, "--nodeferred") == 0) { |
| 1234 | doDeferred = false; |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1235 | } else if (strcmp(*argv, "--disable-missing-warning") == 0) { |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1236 | notifyMissingReadReference = false; |
junov@chromium.org | 95146eb | 2013-01-11 21:04:40 +0000 | [diff] [blame] | 1237 | } else if (strcmp(*argv, "--mismatchPath") == 0) { |
| 1238 | argv++; |
| 1239 | if (argv < stop && **argv) { |
| 1240 | gmmain.fMismatchPath = *argv; |
| 1241 | } |
junov@chromium.org | 58be101 | 2012-12-18 21:09:45 +0000 | [diff] [blame] | 1242 | } else if (strcmp(*argv, "--nortree") == 0) { |
| 1243 | doRTree = false; |
| 1244 | } else if (strcmp(*argv, "--notileGrid") == 0) { |
| 1245 | doTileGrid = false; |
junov@chromium.org | c938c48 | 2012-12-19 15:24:38 +0000 | [diff] [blame] | 1246 | } else if (strcmp(*argv, "--tileGridReplayScales") == 0) { |
| 1247 | tileGridReplayScales.reset(); |
| 1248 | ++argv; |
| 1249 | if (argv < stop) { |
| 1250 | char* token = strtok(*argv, ","); |
| 1251 | while (NULL != token) { |
| 1252 | double val = atof(token); |
| 1253 | if (0 < val) { |
| 1254 | *tileGridReplayScales.append() = SkDoubleToScalar(val); |
| 1255 | } |
| 1256 | token = strtok(NULL, ","); |
| 1257 | } |
| 1258 | } |
| 1259 | if (0 == tileGridReplayScales.count()) { |
| 1260 | // Should have at least one scale |
| 1261 | usage(commandName); |
| 1262 | return -1; |
| 1263 | } |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1264 | } else if (strcmp(*argv, "--enable-missing-warning") == 0) { |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1265 | notifyMissingReadReference = true; |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1266 | } else if (strcmp(*argv, "--forceBWtext") == 0) { |
| 1267 | gForceBWtext = true; |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1268 | } else if (strcmp(*argv, "--help") == 0 || strcmp(*argv, "-h") == 0) { |
| 1269 | usage(commandName); |
| 1270 | return -1; |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1271 | } else if (strcmp(*argv, "--hierarchy") == 0) { |
| 1272 | gmmain.fUseFileHierarchy = true; |
| 1273 | } else if (strcmp(*argv, "--nohierarchy") == 0) { |
| 1274 | gmmain.fUseFileHierarchy = false; |
| 1275 | } else if (strcmp(*argv, "--match") == 0) { |
| 1276 | ++argv; |
| 1277 | if (argv < stop && **argv) { |
| 1278 | // just record the ptr, no need for a deep copy |
| 1279 | *fMatches.append() = *argv; |
| 1280 | } |
| 1281 | } else if (strcmp(*argv, "--modulo") == 0) { |
| 1282 | ++argv; |
| 1283 | if (argv >= stop) { |
| 1284 | continue; |
| 1285 | } |
| 1286 | moduloRemainder = atoi(*argv); |
| 1287 | |
| 1288 | ++argv; |
| 1289 | if (argv >= stop) { |
| 1290 | continue; |
| 1291 | } |
| 1292 | moduloDivisor = atoi(*argv); |
bsalomon@google.com | c7a24d2 | 2012-11-01 18:03:48 +0000 | [diff] [blame] | 1293 | if (moduloRemainder < 0 || moduloDivisor <= 0 || moduloRemainder >= moduloDivisor) { |
| 1294 | SkDebugf("invalid modulo values."); |
| 1295 | return -1; |
| 1296 | } |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1297 | } else if (strcmp(*argv, "--nopdf") == 0) { |
| 1298 | doPDF = false; |
| 1299 | } else if (strcmp(*argv, "--nopipe") == 0) { |
| 1300 | doPipe = false; |
| 1301 | } else if ((0 == strcmp(*argv, "--readPath")) || |
| 1302 | (0 == strcmp(*argv, "-r"))) { |
| 1303 | argv++; |
| 1304 | if (argv < stop && **argv) { |
| 1305 | readPath = *argv; |
| 1306 | } |
| 1307 | } else if (strcmp(*argv, "--noreplay") == 0) { |
| 1308 | doReplay = false; |
| 1309 | } else if ((0 == strcmp(*argv, "--resourcePath")) || |
| 1310 | (0 == strcmp(*argv, "-i"))) { |
| 1311 | argv++; |
| 1312 | if (argv < stop && **argv) { |
| 1313 | resourcePath = *argv; |
| 1314 | } |
| 1315 | } else if (strcmp(*argv, "--serialize") == 0) { |
| 1316 | doSerialize = true; |
| 1317 | } else if (strcmp(*argv, "--noserialize") == 0) { |
| 1318 | doSerialize = false; |
| 1319 | } else if (strcmp(*argv, "--notexturecache") == 0) { |
sugoi@google.com | 9c55f80 | 2013-03-07 20:52:59 +0000 | [diff] [blame] | 1320 | #if SK_SUPPORT_GPU |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1321 | disableTextureCache = true; |
sugoi@google.com | 9c55f80 | 2013-03-07 20:52:59 +0000 | [diff] [blame] | 1322 | #endif |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1323 | } else if (strcmp(*argv, "--tiledPipe") == 0) { |
| 1324 | doTiledPipe = true; |
reed@google.com | fb2cd42 | 2013-01-04 14:43:03 +0000 | [diff] [blame] | 1325 | } else if (!strcmp(*argv, "--verbose") || !strcmp(*argv, "-v")) { |
| 1326 | doVerbose = true; |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1327 | } else if ((0 == strcmp(*argv, "--writePath")) || |
| 1328 | (0 == strcmp(*argv, "-w"))) { |
| 1329 | argv++; |
| 1330 | if (argv < stop && **argv) { |
| 1331 | writePath = *argv; |
| 1332 | } |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 1333 | } else if (0 == strcmp(*argv, "--writeJsonSummary")) { |
| 1334 | argv++; |
| 1335 | if (argv < stop && **argv) { |
| 1336 | writeJsonSummaryPath = *argv; |
| 1337 | } |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1338 | } else if ((0 == strcmp(*argv, "--writePicturePath")) || |
| 1339 | (0 == strcmp(*argv, "-wp"))) { |
| 1340 | argv++; |
| 1341 | if (argv < stop && **argv) { |
| 1342 | writePicturePath = *argv; |
| 1343 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1344 | } else { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 1345 | usage(commandName); |
| 1346 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1347 | } |
| 1348 | } |
| 1349 | if (argv != stop) { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 1350 | usage(commandName); |
| 1351 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1352 | } |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 1353 | |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1354 | if (!userConfig) { |
| 1355 | // if no config is specified by user, we add them all. |
| 1356 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 1357 | *configs.append() = i; |
| 1358 | } |
| 1359 | } |
reed@google.com | fb2cd42 | 2013-01-04 14:43:03 +0000 | [diff] [blame] | 1360 | // now remove any explicitly excluded configs |
| 1361 | for (int i = 0; i < excludeConfigs.count(); ++i) { |
| 1362 | int index = configs.find(excludeConfigs[i]); |
| 1363 | if (index >= 0) { |
| 1364 | configs.remove(index); |
| 1365 | // now assert that there was only one copy in configs[] |
| 1366 | SkASSERT(configs.find(excludeConfigs[i]) < 0); |
| 1367 | } |
| 1368 | } |
| 1369 | |
| 1370 | if (doVerbose) { |
| 1371 | SkString str; |
| 1372 | str.printf("gm: %d configs:", configs.count()); |
| 1373 | for (int i = 0; i < configs.count(); ++i) { |
| 1374 | str.appendf(" %s", gRec[configs[i]].fName); |
| 1375 | } |
| 1376 | SkDebugf("%s\n", str.c_str()); |
| 1377 | } |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1378 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 1379 | GM::SetResourcePath(resourcePath); |
| 1380 | |
reed@android.com | 00f883e | 2010-12-14 17:46:14 +0000 | [diff] [blame] | 1381 | if (readPath) { |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1382 | if (!sk_exists(readPath)) { |
| 1383 | fprintf(stderr, "readPath %s does not exist!\n", readPath); |
| 1384 | return -1; |
| 1385 | } |
| 1386 | if (sk_isdir(readPath)) { |
| 1387 | fprintf(stderr, "reading from %s\n", readPath); |
| 1388 | gmmain.fExpectationsSource.reset(SkNEW_ARGS( |
| 1389 | IndividualImageExpectationsSource, |
| 1390 | (readPath, notifyMissingReadReference))); |
| 1391 | } else { |
epoger@google.com | d271d24 | 2013-02-13 18:14:48 +0000 | [diff] [blame] | 1392 | fprintf(stderr, "reading expectations from JSON summary file %s\n", |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1393 | readPath); |
epoger@google.com | d271d24 | 2013-02-13 18:14:48 +0000 | [diff] [blame] | 1394 | gmmain.fExpectationsSource.reset(SkNEW_ARGS( |
| 1395 | JsonExpectationsSource, (readPath))); |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1396 | } |
chudy@google.com | f32f6e8 | 2012-07-12 15:42:37 +0000 | [diff] [blame] | 1397 | } |
epoger@google.com | 9284ccd | 2012-04-18 13:36:54 +0000 | [diff] [blame] | 1398 | if (writePath) { |
reed@android.com | 00f883e | 2010-12-14 17:46:14 +0000 | [diff] [blame] | 1399 | fprintf(stderr, "writing to %s\n", writePath); |
| 1400 | } |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 1401 | if (writePicturePath) { |
| 1402 | fprintf(stderr, "writing pictures to %s\n", writePicturePath); |
| 1403 | } |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 1404 | if (resourcePath) { |
| 1405 | fprintf(stderr, "reading resources from %s\n", resourcePath); |
| 1406 | } |
| 1407 | |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1408 | if (moduloDivisor <= 0) { |
| 1409 | moduloRemainder = -1; |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1410 | } |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1411 | if (moduloRemainder < 0 || moduloRemainder >= moduloDivisor) { |
| 1412 | moduloRemainder = -1; |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1413 | } |
| 1414 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1415 | // Accumulate success of all tests. |
| 1416 | int testsRun = 0; |
| 1417 | int testsPassed = 0; |
| 1418 | int testsFailed = 0; |
| 1419 | int testsMissingReferenceImages = 0; |
| 1420 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1421 | #if SK_SUPPORT_GPU |
| 1422 | GrContextFactory* grFactory = new GrContextFactory; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 1423 | if (disableTextureCache) { |
| 1424 | skiagm::GetGr()->setTextureCacheLimits(0, 0); |
| 1425 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1426 | #endif |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 1427 | |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1428 | int gmIndex = -1; |
| 1429 | SkString moduloStr; |
| 1430 | |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 1431 | // If we will be writing out files, prepare subdirectories. |
| 1432 | if (writePath) { |
| 1433 | if (!sk_mkdir(writePath)) { |
| 1434 | return -1; |
| 1435 | } |
| 1436 | if (gmmain.fUseFileHierarchy) { |
| 1437 | for (int i = 0; i < configs.count(); i++) { |
| 1438 | ConfigData config = gRec[configs[i]]; |
| 1439 | SkString subdir; |
| 1440 | subdir.appendf("%s%c%s", writePath, SkPATH_SEPARATOR, |
| 1441 | config.fName); |
| 1442 | if (!sk_mkdir(subdir.c_str())) { |
| 1443 | return -1; |
| 1444 | } |
| 1445 | } |
| 1446 | } |
| 1447 | } |
| 1448 | |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1449 | Iter iter; |
| 1450 | GM* gm; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1451 | while ((gm = iter.next()) != NULL) { |
skia.committer@gmail.com | 6a748ad | 2012-10-19 02:01:19 +0000 | [diff] [blame] | 1452 | |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1453 | ++gmIndex; |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1454 | if (moduloRemainder >= 0) { |
| 1455 | if ((gmIndex % moduloDivisor) != moduloRemainder) { |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1456 | continue; |
| 1457 | } |
epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 1458 | moduloStr.printf("[%d.%d] ", gmIndex, moduloDivisor); |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1459 | } |
| 1460 | |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 1461 | const char* shortName = gm->shortName(); |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 1462 | if (skip_name(fMatches, shortName)) { |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 1463 | SkDELETE(gm); |
| 1464 | continue; |
| 1465 | } |
| 1466 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1467 | SkISize size = gm->getISize(); |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1468 | SkDebugf("%sdrawing... %s [%d %d]\n", moduloStr.c_str(), shortName, |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 1469 | size.width(), size.height()); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1470 | |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 1471 | ErrorBitfield testErrors = ERROR_NONE; |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1472 | uint32_t gmFlags = gm->getFlags(); |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 1473 | |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1474 | for (int i = 0; i < configs.count(); i++) { |
| 1475 | ConfigData config = gRec[configs[i]]; |
epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 1476 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1477 | // Skip any tests that we don't even need to try. |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1478 | if ((kPDF_Backend == config.fBackend) && |
bungeman@google.com | 64e011a | 2011-09-19 19:31:04 +0000 | [diff] [blame] | 1479 | (!doPDF || (gmFlags & GM::kSkipPDF_Flag))) |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1480 | { |
| 1481 | continue; |
| 1482 | } |
reed@google.com | 1b6c73d | 2012-10-10 15:17:24 +0000 | [diff] [blame] | 1483 | if ((gmFlags & GM::kSkip565_Flag) && |
| 1484 | (kRaster_Backend == config.fBackend) && |
| 1485 | (SkBitmap::kRGB_565_Config == config.fConfig)) { |
| 1486 | continue; |
| 1487 | } |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 1488 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1489 | // Now we know that we want to run this test and record its |
| 1490 | // success or failure. |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 1491 | ErrorBitfield renderErrors = ERROR_NONE; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1492 | GrRenderTarget* renderTarget = NULL; |
| 1493 | #if SK_SUPPORT_GPU |
| 1494 | SkAutoTUnref<GrRenderTarget> rt; |
| 1495 | AutoResetGr autogr; |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 1496 | if ((ERROR_NONE == renderErrors) && |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1497 | kGPU_Backend == config.fBackend) { |
| 1498 | GrContext* gr = grFactory->get(config.fGLContextType); |
| 1499 | bool grSuccess = false; |
| 1500 | if (gr) { |
| 1501 | // create a render target to back the device |
| 1502 | GrTextureDesc desc; |
bsalomon@google.com | fec0bc3 | 2013-02-07 14:43:04 +0000 | [diff] [blame] | 1503 | desc.fConfig = kSkia8888_GrPixelConfig; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1504 | desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 1505 | desc.fWidth = gm->getISize().width(); |
| 1506 | desc.fHeight = gm->getISize().height(); |
| 1507 | desc.fSampleCnt = config.fSampleCnt; |
| 1508 | GrTexture* tex = gr->createUncachedTexture(desc, NULL, 0); |
| 1509 | if (tex) { |
| 1510 | rt.reset(tex->asRenderTarget()); |
| 1511 | rt.get()->ref(); |
| 1512 | tex->unref(); |
| 1513 | autogr.set(gr); |
| 1514 | renderTarget = rt.get(); |
| 1515 | grSuccess = NULL != renderTarget; |
| 1516 | } |
| 1517 | } |
| 1518 | if (!grSuccess) { |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 1519 | renderErrors |= ERROR_NO_GPU_CONTEXT; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1520 | } |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 1521 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1522 | #endif |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 1523 | |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1524 | SkBitmap comparisonBitmap; |
| 1525 | |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 1526 | if (ERROR_NONE == renderErrors) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1527 | renderErrors |= gmmain.test_drawing(gm, config, writePath, |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1528 | GetGr(), |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1529 | renderTarget, |
epoger@google.com | 57f7abc | 2012-11-13 03:41:55 +0000 | [diff] [blame] | 1530 | &comparisonBitmap); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1531 | } |
| 1532 | |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1533 | if (doDeferred && !renderErrors && |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1534 | (kGPU_Backend == config.fBackend || |
| 1535 | kRaster_Backend == config.fBackend)) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1536 | renderErrors |= gmmain.test_deferred_drawing(gm, config, |
| 1537 | comparisonBitmap, |
epoger@google.com | 15655b2 | 2013-01-08 18:47:31 +0000 | [diff] [blame] | 1538 | GetGr(), |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1539 | renderTarget); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 1540 | } |
| 1541 | |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1542 | testErrors |= renderErrors; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1543 | } |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1544 | |
| 1545 | SkBitmap comparisonBitmap; |
| 1546 | const ConfigData compareConfig = |
| 1547 | { 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] | 1548 | testErrors |= gmmain.generate_image(gm, compareConfig, NULL, NULL, &comparisonBitmap, false); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1549 | |
| 1550 | // run the picture centric GM steps |
| 1551 | if (!(gmFlags & GM::kSkipPicture_Flag)) { |
| 1552 | |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 1553 | ErrorBitfield pictErrors = ERROR_NONE; |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1554 | |
| 1555 | //SkAutoTUnref<SkPicture> pict(generate_new_picture(gm)); |
junov@chromium.org | 20bd04e | 2013-01-16 18:43:36 +0000 | [diff] [blame] | 1556 | SkPicture* pict = gmmain.generate_new_picture(gm, kNone_BbhType, 0); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1557 | SkAutoUnref aur(pict); |
| 1558 | |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 1559 | if ((ERROR_NONE == testErrors) && doReplay) { |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1560 | SkBitmap bitmap; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1561 | gmmain.generate_image_from_picture(gm, compareConfig, pict, |
| 1562 | &bitmap); |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1563 | pictErrors |= gmmain.compare_test_results_to_reference_bitmap( |
| 1564 | gm, compareConfig, "-replay", bitmap, &comparisonBitmap); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1565 | } |
| 1566 | |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 1567 | if ((ERROR_NONE == testErrors) && |
| 1568 | (ERROR_NONE == pictErrors) && |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1569 | doSerialize) { |
| 1570 | SkPicture* repict = gmmain.stream_to_new_picture(*pict); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1571 | SkAutoUnref aurr(repict); |
| 1572 | |
| 1573 | SkBitmap bitmap; |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1574 | gmmain.generate_image_from_picture(gm, compareConfig, repict, |
| 1575 | &bitmap); |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1576 | pictErrors |= gmmain.compare_test_results_to_reference_bitmap( |
| 1577 | gm, compareConfig, "-serialize", bitmap, &comparisonBitmap); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1578 | } |
| 1579 | |
| 1580 | if (writePicturePath) { |
| 1581 | const char* pictureSuffix = "skp"; |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1582 | SkString path = make_filename(writePicturePath, "", |
| 1583 | gm->shortName(), |
| 1584 | pictureSuffix); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1585 | SkFILEWStream stream(path.c_str()); |
| 1586 | pict->serialize(&stream); |
| 1587 | } |
| 1588 | |
| 1589 | testErrors |= pictErrors; |
| 1590 | } |
| 1591 | |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1592 | // TODO: add a test in which the RTree rendering results in a |
| 1593 | // different bitmap than the standard rendering. It should |
| 1594 | // show up as failed in the JSON summary, and should be listed |
| 1595 | // in the stdout also. |
junov@chromium.org | 58be101 | 2012-12-18 21:09:45 +0000 | [diff] [blame] | 1596 | if (!(gmFlags & GM::kSkipPicture_Flag) && doRTree) { |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1597 | SkPicture* pict = gmmain.generate_new_picture( |
| 1598 | gm, kRTree_BbhType, SkPicture::kUsePathBoundsForClip_RecordingFlag); |
junov@chromium.org | 58be101 | 2012-12-18 21:09:45 +0000 | [diff] [blame] | 1599 | SkAutoUnref aur(pict); |
| 1600 | SkBitmap bitmap; |
| 1601 | gmmain.generate_image_from_picture(gm, compareConfig, pict, |
| 1602 | &bitmap); |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1603 | testErrors |= gmmain.compare_test_results_to_reference_bitmap( |
| 1604 | gm, compareConfig, "-rtree", bitmap, &comparisonBitmap); |
junov@chromium.org | 58be101 | 2012-12-18 21:09:45 +0000 | [diff] [blame] | 1605 | } |
| 1606 | |
| 1607 | if (!(gmFlags & GM::kSkipPicture_Flag) && doTileGrid) { |
junov@chromium.org | c938c48 | 2012-12-19 15:24:38 +0000 | [diff] [blame] | 1608 | for(int scaleIndex = 0; scaleIndex < tileGridReplayScales.count(); ++scaleIndex) { |
| 1609 | SkScalar replayScale = tileGridReplayScales[scaleIndex]; |
junov@chromium.org | ff06af2 | 2013-01-14 16:27:50 +0000 | [diff] [blame] | 1610 | if ((gmFlags & GM::kSkipScaledReplay_Flag) && replayScale != 1) |
| 1611 | continue; |
junov@chromium.org | c938c48 | 2012-12-19 15:24:38 +0000 | [diff] [blame] | 1612 | // We record with the reciprocal scale to obtain a replay |
| 1613 | // result that can be validated against comparisonBitmap. |
| 1614 | SkScalar recordScale = SkScalarInvert(replayScale); |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1615 | SkPicture* pict = gmmain.generate_new_picture( |
| 1616 | gm, kTileGrid_BbhType, SkPicture::kUsePathBoundsForClip_RecordingFlag, |
| 1617 | recordScale); |
junov@chromium.org | c938c48 | 2012-12-19 15:24:38 +0000 | [diff] [blame] | 1618 | SkAutoUnref aur(pict); |
| 1619 | SkBitmap bitmap; |
| 1620 | gmmain.generate_image_from_picture(gm, compareConfig, pict, |
| 1621 | &bitmap, replayScale); |
| 1622 | SkString suffix("-tilegrid"); |
| 1623 | if (SK_Scalar1 != replayScale) { |
| 1624 | suffix += "-scale-"; |
| 1625 | suffix.appendScalar(replayScale); |
| 1626 | } |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1627 | testErrors |= gmmain.compare_test_results_to_reference_bitmap( |
| 1628 | gm, compareConfig, suffix.c_str(), bitmap, |
| 1629 | &comparisonBitmap); |
junov@chromium.org | c938c48 | 2012-12-19 15:24:38 +0000 | [diff] [blame] | 1630 | } |
junov@chromium.org | 58be101 | 2012-12-18 21:09:45 +0000 | [diff] [blame] | 1631 | } |
| 1632 | |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1633 | // run the pipe centric GM steps |
| 1634 | if (!(gmFlags & GM::kSkipPipe_Flag)) { |
| 1635 | |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 1636 | ErrorBitfield pipeErrors = ERROR_NONE; |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1637 | |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 1638 | if ((ERROR_NONE == testErrors) && doPipe) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1639 | pipeErrors |= gmmain.test_pipe_playback(gm, compareConfig, |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1640 | comparisonBitmap); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1641 | } |
| 1642 | |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 1643 | if ((ERROR_NONE == testErrors) && |
| 1644 | (ERROR_NONE == pipeErrors) && |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1645 | doTiledPipe && !(gmFlags & GM::kSkipTiled_Flag)) { |
epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1646 | pipeErrors |= gmmain.test_tiled_pipe_playback(gm, compareConfig, |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1647 | comparisonBitmap); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1648 | } |
| 1649 | |
| 1650 | testErrors |= pipeErrors; |
| 1651 | } |
| 1652 | |
| 1653 | // Update overall results. |
| 1654 | // We only tabulate the particular error types that we currently |
| 1655 | // care about (e.g., missing reference images). Later on, if we |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1656 | // want to also tabulate other error types, we can do so. |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1657 | testsRun++; |
epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1658 | if (!gmmain.fExpectationsSource.get() || |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 1659 | (ERROR_READING_REFERENCE_IMAGE & testErrors)) { |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1660 | testsMissingReferenceImages++; |
borenet@google.com | a904ea1 | 2013-02-21 18:34:14 +0000 | [diff] [blame] | 1661 | } |
epoger@google.com | 526db49 | 2013-03-07 21:02:50 +0000 | [diff] [blame] | 1662 | if (ERROR_NONE == testErrors || ERROR_READING_REFERENCE_IMAGE == testErrors) { |
epoger@google.com | 3499f3c | 2013-01-10 17:11:27 +0000 | [diff] [blame] | 1663 | testsPassed++; |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1664 | } else { |
| 1665 | testsFailed++; |
| 1666 | } |
| 1667 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1668 | SkDELETE(gm); |
| 1669 | } |
robertphillips@google.com | a2f8008 | 2012-08-02 16:22:47 +0000 | [diff] [blame] | 1670 | SkDebugf("Ran %d tests: %d passed, %d failed, %d missing reference images\n", |
| 1671 | testsRun, testsPassed, testsFailed, testsMissingReferenceImages); |
epoger@google.com | 57f7abc | 2012-11-13 03:41:55 +0000 | [diff] [blame] | 1672 | gmmain.ListErrors(); |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 1673 | |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 1674 | if (NULL != writeJsonSummaryPath) { |
| 1675 | Json::Value actualResults; |
| 1676 | actualResults[kJsonKey_ActualResults_Failed] = |
| 1677 | gmmain.fJsonActualResults_Failed; |
| 1678 | actualResults[kJsonKey_ActualResults_FailureIgnored] = |
| 1679 | gmmain.fJsonActualResults_FailureIgnored; |
epoger@google.com | 9c56a8d | 2012-12-20 18:34:29 +0000 | [diff] [blame] | 1680 | actualResults[kJsonKey_ActualResults_NoComparison] = |
| 1681 | gmmain.fJsonActualResults_NoComparison; |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 1682 | actualResults[kJsonKey_ActualResults_Succeeded] = |
| 1683 | gmmain.fJsonActualResults_Succeeded; |
| 1684 | Json::Value root; |
| 1685 | root[kJsonKey_ActualResults] = actualResults; |
| 1686 | root[kJsonKey_ExpectedResults] = gmmain.fJsonExpectedResults; |
| 1687 | std::string jsonStdString = root.toStyledString(); |
| 1688 | SkFILEWStream stream(writeJsonSummaryPath); |
| 1689 | stream.write(jsonStdString.c_str(), jsonStdString.length()); |
| 1690 | } |
| 1691 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1692 | #if SK_SUPPORT_GPU |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 1693 | |
robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 1694 | #if GR_CACHE_STATS |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 1695 | for (int i = 0; i < configs.count(); i++) { |
| 1696 | ConfigData config = gRec[configs[i]]; |
| 1697 | |
| 1698 | if (kGPU_Backend == config.fBackend) { |
| 1699 | GrContext* gr = grFactory->get(config.fGLContextType); |
| 1700 | |
| 1701 | SkDebugf("config: %s %x\n", config.fName, gr); |
| 1702 | gr->printCacheStats(); |
| 1703 | } |
| 1704 | } |
| 1705 | #endif |
| 1706 | |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 1707 | delete grFactory; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1708 | #endif |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 1709 | SkGraphics::Term(); |
| 1710 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1711 | return (0 == testsFailed) ? 0 : -1; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1712 | } |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 1713 | |
borenet@google.com | 7158e6a | 2012-11-01 17:43:44 +0000 | [diff] [blame] | 1714 | #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 1715 | int main(int argc, char * const argv[]) { |
| 1716 | return tool_main(argc, (char**) argv); |
| 1717 | } |
| 1718 | #endif |