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