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