| 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 | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 17 | #include "gm_error.h" | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 18 | #include "gm_expectations.h" | 
| epoger@google.com | 7bc13a6 | 2012-02-14 14:53:59 +0000 | [diff] [blame] | 19 | #include "system_preferences.h" | 
| epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 20 | #include "SkBitmap.h" | 
| reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 21 | #include "SkColorPriv.h" | 
| scroggo@google.com | d9ba9a0 | 2013-03-21 19:43:15 +0000 | [diff] [blame] | 22 | #include "SkCommandLineFlags.h" | 
| reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 23 | #include "SkData.h" | 
| junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 24 | #include "SkDeferredCanvas.h" | 
| bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 25 | #include "SkDevice.h" | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 26 | #include "SkDrawFilter.h" | 
| commit-bot@chromium.org | c41295d | 2013-06-18 20:06:36 +0000 | [diff] [blame] | 27 | #include "SkForceLinking.h" | 
| scroggo@google.com | 5af9b20 | 2012-06-04 17:17:36 +0000 | [diff] [blame] | 28 | #include "SkGPipe.h" | 
| reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 29 | #include "SkGraphics.h" | 
|  | 30 | #include "SkImageDecoder.h" | 
|  | 31 | #include "SkImageEncoder.h" | 
| epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 32 | #include "SkOSFile.h" | 
| tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 33 | #include "SkPicture.h" | 
| robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 34 | #include "SkRefCnt.h" | 
| scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 35 | #include "SkStream.h" | 
| bsalomon@google.com | 2a48c3a | 2012-08-03 14:54:45 +0000 | [diff] [blame] | 36 | #include "SkTArray.h" | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 37 | #include "SkTDict.h" | 
| junov@chromium.org | 3cb834b | 2012-12-13 16:39:53 +0000 | [diff] [blame] | 38 | #include "SkTileGridPicture.h" | 
| scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 39 | #include "SamplePipeControllers.h" | 
| reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 40 |  | 
| commit-bot@chromium.org | c41295d | 2013-06-18 20:06:36 +0000 | [diff] [blame] | 41 | __SK_FORCE_IMAGE_DECODER_LINKING; | 
|  | 42 |  | 
| bsalomon@google.com | 50c79d8 | 2013-01-08 20:31:53 +0000 | [diff] [blame] | 43 | #ifdef SK_BUILD_FOR_WIN | 
|  | 44 | // 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] | 45 | // 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] | 46 | #pragma warning(push) | 
|  | 47 | #pragma warning(disable : 4530) | 
|  | 48 | #endif | 
| epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 49 | #include "json/value.h" | 
| bsalomon@google.com | 50c79d8 | 2013-01-08 20:31:53 +0000 | [diff] [blame] | 50 | #ifdef SK_BUILD_FOR_WIN | 
|  | 51 | #pragma warning(pop) | 
|  | 52 | #endif | 
| epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 53 |  | 
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 54 | #if SK_SUPPORT_GPU | 
|  | 55 | #include "GrContextFactory.h" | 
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 56 | #include "SkGpuDevice.h" | 
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 57 | typedef GrContextFactory::GLContextType GLContextType; | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 58 | #define DEFAULT_CACHE_VALUE -1 | 
|  | 59 | static int gGpuCacheSizeBytes; | 
|  | 60 | static int gGpuCacheSizeCount; | 
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 61 | #else | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 62 | class GrContextFactory; | 
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 63 | class GrContext; | 
| bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 64 | class GrSurface; | 
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 65 | typedef int GLContextType; | 
|  | 66 | #endif | 
|  | 67 |  | 
| epoger@google.com | 76c913d | 2013-04-26 15:06:44 +0000 | [diff] [blame] | 68 | #define DEBUGFAIL_SEE_STDERR SkDEBUGFAIL("see stderr for message") | 
|  | 69 |  | 
| reed@google.com | 8923c6c | 2011-11-08 14:59:38 +0000 | [diff] [blame] | 70 | extern bool gSkSuppressFontCachePurgeSpew; | 
|  | 71 |  | 
| reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 72 | #ifdef SK_SUPPORT_PDF | 
| tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 73 | #include "SkPDFDevice.h" | 
|  | 74 | #include "SkPDFDocument.h" | 
| reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 75 | #endif | 
| reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 76 |  | 
| epoger@google.com | e3cc2eb | 2012-01-18 20:11:13 +0000 | [diff] [blame] | 77 | // Until we resolve http://code.google.com/p/skia/issues/detail?id=455 , | 
|  | 78 | // stop writing out XPS-format image baselines in gm. | 
|  | 79 | #undef SK_SUPPORT_XPS | 
| bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 80 | #ifdef SK_SUPPORT_XPS | 
|  | 81 | #include "SkXPSDevice.h" | 
|  | 82 | #endif | 
|  | 83 |  | 
| reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 84 | #ifdef SK_BUILD_FOR_MAC | 
|  | 85 | #include "SkCGUtils.h" | 
| bsalomon@google.com | 0a09eef | 2011-06-29 19:42:58 +0000 | [diff] [blame] | 86 | #define CAN_IMAGE_PDF   1 | 
| reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 87 | #else | 
| bsalomon@google.com | 0a09eef | 2011-06-29 19:42:58 +0000 | [diff] [blame] | 88 | #define CAN_IMAGE_PDF   0 | 
| reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 89 | #endif | 
|  | 90 |  | 
| reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 91 | using namespace skiagm; | 
|  | 92 |  | 
| reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 93 | class Iter { | 
|  | 94 | public: | 
|  | 95 | Iter() { | 
| bsalomon@google.com | 3914958 | 2011-06-13 21:55:32 +0000 | [diff] [blame] | 96 | this->reset(); | 
|  | 97 | } | 
|  | 98 |  | 
|  | 99 | void reset() { | 
| reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 100 | fReg = GMRegistry::Head(); | 
| reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 101 | } | 
| reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 102 |  | 
| reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 103 | GM* next() { | 
| reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 104 | if (fReg) { | 
| reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 105 | GMRegistry::Factory fact = fReg->factory(); | 
| reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 106 | fReg = fReg->next(); | 
| reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 107 | return fact(0); | 
| reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 108 | } | 
|  | 109 | return NULL; | 
|  | 110 | } | 
| reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 111 |  | 
| reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 112 | static int Count() { | 
| reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 113 | const GMRegistry* reg = GMRegistry::Head(); | 
| reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 114 | int count = 0; | 
|  | 115 | while (reg) { | 
|  | 116 | count += 1; | 
|  | 117 | reg = reg->next(); | 
|  | 118 | } | 
|  | 119 | return count; | 
|  | 120 | } | 
| reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 121 |  | 
| reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 122 | private: | 
|  | 123 | const GMRegistry* fReg; | 
|  | 124 | }; | 
|  | 125 |  | 
| epoger@google.com | ce057fe | 2013-05-14 15:17:46 +0000 | [diff] [blame] | 126 | // TODO(epoger): Right now, various places in this code assume that all the | 
|  | 127 | // image files read/written by GM use this file extension. | 
|  | 128 | // Search for references to this constant to find these assumptions. | 
|  | 129 | const static char kPNG_FileExtension[] = "png"; | 
|  | 130 |  | 
| vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 131 | enum Backend { | 
| junov@chromium.org | 3cb834b | 2012-12-13 16:39:53 +0000 | [diff] [blame] | 132 | kRaster_Backend, | 
|  | 133 | kGPU_Backend, | 
|  | 134 | kPDF_Backend, | 
|  | 135 | kXPS_Backend, | 
|  | 136 | }; | 
|  | 137 |  | 
|  | 138 | enum BbhType { | 
|  | 139 | kNone_BbhType, | 
|  | 140 | kRTree_BbhType, | 
|  | 141 | kTileGrid_BbhType, | 
| vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 142 | }; | 
|  | 143 |  | 
| bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 144 | enum ConfigFlags { | 
|  | 145 | kNone_ConfigFlag  = 0x0, | 
|  | 146 | /* Write GM images if a write path is provided. */ | 
|  | 147 | kWrite_ConfigFlag = 0x1, | 
| epoger@google.com | f28dd8a | 2012-10-25 16:27:34 +0000 | [diff] [blame] | 148 | /* Read reference GM images if a read path is provided. */ | 
| bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 149 | kRead_ConfigFlag  = 0x2, | 
|  | 150 | kRW_ConfigFlag    = (kWrite_ConfigFlag | kRead_ConfigFlag), | 
|  | 151 | }; | 
|  | 152 |  | 
| tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 153 | struct ConfigData { | 
| bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 154 | SkBitmap::Config                fConfig; | 
|  | 155 | Backend                         fBackend; | 
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 156 | GLContextType                   fGLContextType; // GPU backend only | 
| bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 157 | int                             fSampleCnt;     // GPU backend only | 
|  | 158 | ConfigFlags                     fFlags; | 
|  | 159 | const char*                     fName; | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 160 | bool                            fRunByDefault; | 
| tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 161 | }; | 
|  | 162 |  | 
| mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 163 | class BWTextDrawFilter : public SkDrawFilter { | 
|  | 164 | public: | 
| reed@google.com | 971aca7 | 2012-11-26 20:26:54 +0000 | [diff] [blame] | 165 | virtual bool filter(SkPaint*, Type) SK_OVERRIDE; | 
| mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 166 | }; | 
| reed@google.com | 971aca7 | 2012-11-26 20:26:54 +0000 | [diff] [blame] | 167 | bool BWTextDrawFilter::filter(SkPaint* p, Type t) { | 
| mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 168 | if (kText_Type == t) { | 
|  | 169 | p->setAntiAlias(false); | 
|  | 170 | } | 
| reed@google.com | 971aca7 | 2012-11-26 20:26:54 +0000 | [diff] [blame] | 171 | return true; | 
| mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 172 | } | 
|  | 173 |  | 
| scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 174 | struct PipeFlagComboData { | 
|  | 175 | const char* name; | 
|  | 176 | uint32_t flags; | 
|  | 177 | }; | 
|  | 178 |  | 
|  | 179 | static PipeFlagComboData gPipeWritingFlagCombos[] = { | 
|  | 180 | { "", 0 }, | 
|  | 181 | { " cross-process", SkGPipeWriter::kCrossProcess_Flag }, | 
| scroggo | b3c0f48 | 2012-07-02 19:07:57 +0000 | [diff] [blame] | 182 | { " cross-process, shared address", SkGPipeWriter::kCrossProcess_Flag | 
| scroggo@google.com | 15011ee | 2012-07-26 20:03:32 +0000 | [diff] [blame] | 183 | | SkGPipeWriter::kSharedAddressSpace_Flag } | 
| scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 184 | }; | 
|  | 185 |  | 
| edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 186 | static bool encode_to_dct_stream(SkWStream* stream, const SkBitmap& bitmap, const SkIRect& rect); | 
|  | 187 |  | 
| epoger@google.com | 5079d2c | 2013-04-12 14:11:21 +0000 | [diff] [blame] | 188 | const static ErrorCombination kDefaultIgnorableErrorTypes = ErrorCombination() | 
|  | 189 | .plus(kMissingExpectations_ErrorType) | 
|  | 190 | .plus(kIntentionallySkipped_ErrorType); | 
|  | 191 |  | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 192 | class GMMain { | 
|  | 193 | public: | 
| epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 194 | GMMain() : fUseFileHierarchy(false), fWriteChecksumBasedFilenames(false), | 
|  | 195 | fIgnorableErrorTypes(kDefaultIgnorableErrorTypes), | 
| epoger@google.com | 5f99545 | 2013-06-21 18:16:47 +0000 | [diff] [blame] | 196 | fMismatchPath(NULL), fMissingExpectationsPath(NULL), fTestsRun(0), | 
|  | 197 | fRenderModesEncountered(1) {} | 
| epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 198 |  | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 199 | /** | 
|  | 200 | * Assemble shortNamePlusConfig from (surprise!) shortName and configName. | 
|  | 201 | * | 
|  | 202 | * The method for doing so depends on whether we are using hierarchical naming. | 
|  | 203 | * For example, shortName "selftest1" and configName "8888" could be assembled into | 
|  | 204 | * either "selftest1_8888" or "8888/selftest1". | 
|  | 205 | */ | 
|  | 206 | SkString make_shortname_plus_config(const char *shortName, const char *configName) { | 
| epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 207 | SkString name; | 
| epoger@google.com | 57f7abc | 2012-11-13 03:41:55 +0000 | [diff] [blame] | 208 | if (0 == strlen(configName)) { | 
|  | 209 | name.append(shortName); | 
|  | 210 | } else if (fUseFileHierarchy) { | 
| epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 211 | name.appendf("%s%c%s", configName, SkPATH_SEPARATOR, shortName); | 
|  | 212 | } else { | 
|  | 213 | name.appendf("%s_%s", shortName, configName); | 
|  | 214 | } | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 215 | return name; | 
|  | 216 | } | 
|  | 217 |  | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 218 | /** | 
|  | 219 | * Assemble filename, suitable for writing out the results of a particular test. | 
|  | 220 | */ | 
|  | 221 | SkString make_filename(const char *path, | 
|  | 222 | const char *shortName, | 
|  | 223 | const char *configName, | 
|  | 224 | const char *renderModeDescriptor, | 
|  | 225 | const char *suffix) { | 
|  | 226 | SkString filename = make_shortname_plus_config(shortName, configName); | 
|  | 227 | filename.append(renderModeDescriptor); | 
|  | 228 | filename.appendUnichar('.'); | 
|  | 229 | filename.append(suffix); | 
| scroggo@google.com | ccd7afb | 2013-05-28 16:45:07 +0000 | [diff] [blame] | 230 | return SkOSPath::SkPathJoin(path, filename.c_str()); | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 231 | } | 
|  | 232 |  | 
| epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 233 | /** | 
|  | 234 | * Assemble filename suitable for writing out an SkBitmap. | 
|  | 235 | */ | 
|  | 236 | SkString make_bitmap_filename(const char *path, | 
|  | 237 | const char *shortName, | 
|  | 238 | const char *configName, | 
|  | 239 | const char *renderModeDescriptor, | 
|  | 240 | const GmResultDigest &bitmapDigest) { | 
|  | 241 | if (fWriteChecksumBasedFilenames) { | 
|  | 242 | SkString filename; | 
|  | 243 | filename.append(bitmapDigest.getHashType()); | 
|  | 244 | filename.appendUnichar('_'); | 
|  | 245 | filename.append(shortName); | 
|  | 246 | filename.appendUnichar('_'); | 
|  | 247 | filename.append(bitmapDigest.getDigestValue()); | 
|  | 248 | filename.appendUnichar('.'); | 
|  | 249 | filename.append(kPNG_FileExtension); | 
|  | 250 | return SkOSPath::SkPathJoin(path, filename.c_str()); | 
|  | 251 | } else { | 
|  | 252 | return make_filename(path, shortName, configName, renderModeDescriptor, | 
|  | 253 | kPNG_FileExtension); | 
|  | 254 | } | 
|  | 255 | } | 
|  | 256 |  | 
| epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 257 | /* since PNG insists on unpremultiplying our alpha, we take no | 
|  | 258 | precision chances and force all pixels to be 100% opaque, | 
|  | 259 | otherwise on compare we may not get a perfect match. | 
|  | 260 | */ | 
|  | 261 | static void force_all_opaque(const SkBitmap& bitmap) { | 
|  | 262 | SkBitmap::Config config = bitmap.config(); | 
|  | 263 | switch (config) { | 
|  | 264 | case SkBitmap::kARGB_8888_Config: | 
|  | 265 | force_all_opaque_8888(bitmap); | 
|  | 266 | break; | 
|  | 267 | case SkBitmap::kRGB_565_Config: | 
|  | 268 | // nothing to do here; 565 bitmaps are inherently opaque | 
|  | 269 | break; | 
|  | 270 | default: | 
| epoger@google.com | 5efdd0c | 2013-03-13 14:18:40 +0000 | [diff] [blame] | 271 | gm_fprintf(stderr, "unsupported bitmap config %d\n", config); | 
|  | 272 | DEBUGFAIL_SEE_STDERR; | 
| epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 273 | } | 
|  | 274 | } | 
|  | 275 |  | 
|  | 276 | static void force_all_opaque_8888(const SkBitmap& bitmap) { | 
|  | 277 | SkAutoLockPixels lock(bitmap); | 
|  | 278 | for (int y = 0; y < bitmap.height(); y++) { | 
|  | 279 | for (int x = 0; x < bitmap.width(); x++) { | 
|  | 280 | *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT); | 
|  | 281 | } | 
|  | 282 | } | 
|  | 283 | } | 
|  | 284 |  | 
|  | 285 | static bool write_bitmap(const SkString& path, const SkBitmap& bitmap) { | 
|  | 286 | // TODO(epoger): Now that we have removed force_all_opaque() | 
|  | 287 | // from this method, we should be able to get rid of the | 
|  | 288 | // transformation to 8888 format also. | 
|  | 289 | SkBitmap copy; | 
|  | 290 | bitmap.copyTo(©, SkBitmap::kARGB_8888_Config); | 
|  | 291 | return SkImageEncoder::EncodeFile(path.c_str(), copy, | 
|  | 292 | SkImageEncoder::kPNG_Type, 100); | 
|  | 293 | } | 
|  | 294 |  | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 295 | /** | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 296 | * Add all render modes encountered thus far to the "modes" array. | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 297 | */ | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 298 | void GetRenderModesEncountered(SkTArray<SkString> &modes) { | 
|  | 299 | SkTDict<int>::Iter iter(this->fRenderModesEncountered); | 
|  | 300 | const char* mode; | 
|  | 301 | while ((mode = iter.next(NULL)) != NULL) { | 
|  | 302 | SkString modeAsString = SkString(mode); | 
|  | 303 | // TODO(epoger): It seems a bit silly that all of these modes were | 
|  | 304 | // recorded with a leading "-" which we have to remove here | 
|  | 305 | // (except for mode "", which means plain old original mode). | 
|  | 306 | // But that's how renderModeDescriptor has been passed into | 
|  | 307 | // compare_test_results_to_reference_bitmap() historically, | 
|  | 308 | // and changing that now may affect other parts of our code. | 
|  | 309 | if (modeAsString.startsWith("-")) { | 
|  | 310 | modeAsString.remove(0, 1); | 
|  | 311 | modes.push_back(modeAsString); | 
|  | 312 | } | 
|  | 313 | } | 
|  | 314 | } | 
|  | 315 |  | 
|  | 316 | /** | 
|  | 317 | * Records the results of this test in fTestsRun and fFailedTests. | 
|  | 318 | * | 
|  | 319 | * We even record successes, and errors that we regard as | 
|  | 320 | * "ignorable"; we can filter them out later. | 
|  | 321 | */ | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 322 | void RecordTestResults(const ErrorCombination& errorCombination, | 
|  | 323 | const SkString& shortNamePlusConfig, | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 324 | const char renderModeDescriptor []) { | 
|  | 325 | // Things to do regardless of errorCombination. | 
|  | 326 | fTestsRun++; | 
|  | 327 | int renderModeCount = 0; | 
|  | 328 | this->fRenderModesEncountered.find(renderModeDescriptor, &renderModeCount); | 
|  | 329 | renderModeCount++; | 
|  | 330 | this->fRenderModesEncountered.set(renderModeDescriptor, renderModeCount); | 
|  | 331 |  | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 332 | if (errorCombination.isEmpty()) { | 
| epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 333 | return; | 
| epoger@google.com | eb06636 | 2013-03-08 09:39:36 +0000 | [diff] [blame] | 334 | } | 
|  | 335 |  | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 336 | // Things to do only if there is some error condition. | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 337 | SkString fullName = shortNamePlusConfig; | 
| epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 338 | fullName.append(renderModeDescriptor); | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 339 | for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) { | 
|  | 340 | ErrorType type = static_cast<ErrorType>(typeInt); | 
|  | 341 | if (errorCombination.includes(type)) { | 
|  | 342 | fFailedTests[type].push_back(fullName); | 
| epoger@google.com | f60494b | 2013-04-03 17:02:53 +0000 | [diff] [blame] | 343 | } | 
| epoger@google.com | f60494b | 2013-04-03 17:02:53 +0000 | [diff] [blame] | 344 | } | 
| epoger@google.com | f60494b | 2013-04-03 17:02:53 +0000 | [diff] [blame] | 345 | } | 
|  | 346 |  | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 347 | /** | 
|  | 348 | * Return the number of significant (non-ignorable) errors we have | 
|  | 349 | * encountered so far. | 
|  | 350 | */ | 
|  | 351 | int NumSignificantErrors() { | 
|  | 352 | int significantErrors = 0; | 
|  | 353 | for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) { | 
|  | 354 | ErrorType type = static_cast<ErrorType>(typeInt); | 
| epoger@google.com | 5079d2c | 2013-04-12 14:11:21 +0000 | [diff] [blame] | 355 | if (!fIgnorableErrorTypes.includes(type)) { | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 356 | significantErrors += fFailedTests[type].count(); | 
|  | 357 | } | 
|  | 358 | } | 
|  | 359 | return significantErrors; | 
|  | 360 | } | 
|  | 361 |  | 
|  | 362 | /** | 
| epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame] | 363 | * Display the summary of results with this ErrorType. | 
|  | 364 | * | 
|  | 365 | * @param type which ErrorType | 
|  | 366 | * @param verbose whether to be all verbose about it | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 367 | */ | 
| epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame] | 368 | void DisplayResultTypeSummary(ErrorType type, bool verbose) { | 
| epoger@google.com | 5079d2c | 2013-04-12 14:11:21 +0000 | [diff] [blame] | 369 | bool isIgnorableType = fIgnorableErrorTypes.includes(type); | 
| epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame] | 370 |  | 
|  | 371 | SkString line; | 
|  | 372 | if (isIgnorableType) { | 
|  | 373 | line.append("[ ] "); | 
|  | 374 | } else { | 
|  | 375 | line.append("[*] "); | 
|  | 376 | } | 
|  | 377 |  | 
|  | 378 | SkTArray<SkString> *failedTestsOfThisType = &fFailedTests[type]; | 
|  | 379 | int count = failedTestsOfThisType->count(); | 
|  | 380 | line.appendf("%d %s", count, getErrorTypeName(type)); | 
|  | 381 | if (!isIgnorableType || verbose) { | 
|  | 382 | line.append(":"); | 
|  | 383 | for (int i = 0; i < count; ++i) { | 
|  | 384 | line.append(" "); | 
|  | 385 | line.append((*failedTestsOfThisType)[i]); | 
|  | 386 | } | 
|  | 387 | } | 
|  | 388 | gm_fprintf(stdout, "%s\n", line.c_str()); | 
|  | 389 | } | 
|  | 390 |  | 
|  | 391 | /** | 
|  | 392 | * List contents of fFailedTests to stdout. | 
|  | 393 | * | 
|  | 394 | * @param verbose whether to be all verbose about it | 
|  | 395 | */ | 
|  | 396 | void ListErrors(bool verbose) { | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 397 | // First, print a single summary line. | 
|  | 398 | SkString summary; | 
|  | 399 | summary.appendf("Ran %d tests:", fTestsRun); | 
|  | 400 | for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) { | 
|  | 401 | ErrorType type = static_cast<ErrorType>(typeInt); | 
|  | 402 | summary.appendf(" %s=%d", getErrorTypeName(type), fFailedTests[type].count()); | 
|  | 403 | } | 
|  | 404 | gm_fprintf(stdout, "%s\n", summary.c_str()); | 
|  | 405 |  | 
|  | 406 | // Now, for each failure type, list the tests that failed that way. | 
|  | 407 | for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) { | 
| epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame] | 408 | this->DisplayResultTypeSummary(static_cast<ErrorType>(typeInt), verbose); | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 409 | } | 
|  | 410 | gm_fprintf(stdout, "(results marked with [*] will cause nonzero return value)\n"); | 
|  | 411 | } | 
|  | 412 |  | 
| epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 413 | static bool write_document(const SkString& path, | 
|  | 414 | const SkDynamicMemoryWStream& document) { | 
|  | 415 | SkFILEWStream stream(path.c_str()); | 
|  | 416 | SkAutoDataUnref data(document.copyToData()); | 
| bungeman@google.com | 1ca36ec | 2013-05-06 14:28:43 +0000 | [diff] [blame] | 417 | return stream.write(data->data(), data->size()); | 
| epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 418 | } | 
|  | 419 |  | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 420 | /** | 
| epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 421 | * Prepare an SkBitmap to render a GM into. | 
|  | 422 | * | 
|  | 423 | * After you've rendered the GM into the SkBitmap, you must call | 
|  | 424 | * complete_bitmap()! | 
|  | 425 | * | 
|  | 426 | * @todo thudson 22 April 2011 - could refactor this to take in | 
|  | 427 | * a factory to generate the context, always call readPixels() | 
|  | 428 | * (logically a noop for rasters, if wasted time), and thus collapse the | 
|  | 429 | * GPU special case and also let this be used for SkPicture testing. | 
|  | 430 | */ | 
|  | 431 | static void setup_bitmap(const ConfigData& gRec, SkISize& size, | 
|  | 432 | SkBitmap* bitmap) { | 
|  | 433 | bitmap->setConfig(gRec.fConfig, size.width(), size.height()); | 
|  | 434 | bitmap->allocPixels(); | 
|  | 435 | bitmap->eraseColor(SK_ColorTRANSPARENT); | 
|  | 436 | } | 
|  | 437 |  | 
|  | 438 | /** | 
|  | 439 | * Any finalization steps we need to perform on the SkBitmap after | 
|  | 440 | * we have rendered the GM into it. | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 441 | * | 
|  | 442 | * It's too bad that we are throwing away alpha channel data | 
|  | 443 | * we could otherwise be examining, but this had always been happening | 
|  | 444 | * before... it was buried within the compare() method at | 
|  | 445 | * https://code.google.com/p/skia/source/browse/trunk/gm/gmmain.cpp?r=7289#305 . | 
|  | 446 | * | 
|  | 447 | * Apparently we need this, at least for bitmaps that are either: | 
|  | 448 | * (a) destined to be written out as PNG files, or | 
|  | 449 | * (b) compared against bitmaps read in from PNG files | 
|  | 450 | * for the reasons described just above the force_all_opaque() method. | 
|  | 451 | * | 
|  | 452 | * Neglecting to do this led to the difficult-to-diagnose | 
|  | 453 | * http://code.google.com/p/skia/issues/detail?id=1079 ('gm generating | 
|  | 454 | * spurious pixel_error messages as of r7258') | 
|  | 455 | * | 
|  | 456 | * TODO(epoger): Come up with a better solution that allows us to | 
|  | 457 | * compare full pixel data, including alpha channel, while still being | 
|  | 458 | * robust in the face of transformations to/from PNG files. | 
|  | 459 | * Options include: | 
|  | 460 | * | 
|  | 461 | * 1. Continue to call force_all_opaque(), but ONLY for bitmaps that | 
|  | 462 | *    will be written to, or compared against, PNG files. | 
|  | 463 | *    PRO: Preserve/compare alpha channel info for the non-PNG cases | 
|  | 464 | *         (comparing different renderModes in-memory) | 
| epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 465 | *    CON: The bitmaps (and hash digests) for these non-PNG cases would be | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 466 | *         different than those for the PNG-compared cases, and in the | 
|  | 467 | *         case of a failed renderMode comparison, how would we write the | 
|  | 468 | *         image to disk for examination? | 
|  | 469 | * | 
| epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 470 | * 2. Always compute image hash digests from PNG format (either | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 471 | *    directly from the the bytes of a PNG file, or capturing the | 
|  | 472 | *    bytes we would have written to disk if we were writing the | 
|  | 473 | *    bitmap out as a PNG). | 
|  | 474 | *    PRO: I think this would allow us to never force opaque, and to | 
|  | 475 | *         the extent that alpha channel data can be preserved in a PNG | 
|  | 476 | *         file, we could observe it. | 
| epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 477 | *    CON: If we read a bitmap from disk, we need to take its hash digest | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 478 | *         from the source PNG (we can't compute it from the bitmap we | 
|  | 479 | *         read out of the PNG, because we will have already premultiplied | 
|  | 480 | *         the alpha). | 
|  | 481 | *    CON: Seems wasteful to convert a bitmap to PNG format just to take | 
| epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 482 | *         its hash digest. (Although we're wasting lots of effort already | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 483 | *         calling force_all_opaque().) | 
|  | 484 | * | 
|  | 485 | * 3. Make the alpha premultiply/unpremultiply routines 100% consistent, | 
|  | 486 | *    so we can transform images back and forth without fear of off-by-one | 
|  | 487 | *    errors. | 
|  | 488 | *    CON: Math is hard. | 
|  | 489 | * | 
|  | 490 | * 4. Perform a "close enough" comparison of bitmaps (+/- 1 bit in each | 
|  | 491 | *    channel), rather than demanding absolute equality. | 
| epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 492 | *    CON: Can't do this with hash digests. | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 493 | */ | 
| epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 494 | static void complete_bitmap(SkBitmap* bitmap) { | 
|  | 495 | force_all_opaque(*bitmap); | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 496 | } | 
|  | 497 |  | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 498 | static void installFilter(SkCanvas* canvas); | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 499 |  | 
| reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 500 | static void invokeGM(GM* gm, SkCanvas* canvas, bool isPDF, bool isDeferred) { | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 501 | SkAutoCanvasRestore acr(canvas, true); | 
|  | 502 |  | 
|  | 503 | if (!isPDF) { | 
|  | 504 | canvas->concat(gm->getInitialTransform()); | 
|  | 505 | } | 
|  | 506 | installFilter(canvas); | 
| reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 507 | gm->setCanvasIsDeferred(isDeferred); | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 508 | gm->draw(canvas); | 
|  | 509 | canvas->setDrawFilter(NULL); | 
|  | 510 | } | 
|  | 511 |  | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 512 | static ErrorCombination generate_image(GM* gm, const ConfigData& gRec, | 
| bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 513 | GrSurface* gpuTarget, | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 514 | SkBitmap* bitmap, | 
|  | 515 | bool deferred) { | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 516 | SkISize size (gm->getISize()); | 
|  | 517 | setup_bitmap(gRec, size, bitmap); | 
|  | 518 |  | 
|  | 519 | SkAutoTUnref<SkCanvas> canvas; | 
|  | 520 |  | 
|  | 521 | if (gRec.fBackend == kRaster_Backend) { | 
| junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 522 | SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*bitmap))); | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 523 | if (deferred) { | 
| junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 524 | #if SK_DEFERRED_CANVAS_USES_FACTORIES | 
|  | 525 | canvas.reset(SkDeferredCanvas::Create(device)); | 
|  | 526 | #else | 
|  | 527 | canvas.reset(SkNEW_ARGS(SkDeferredCanvas, (device))); | 
|  | 528 | #endif | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 529 | } else { | 
| junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 530 | canvas.reset(SkNEW_ARGS(SkCanvas, (device))); | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 531 | } | 
| reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 532 | invokeGM(gm, canvas, false, deferred); | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 533 | canvas->flush(); | 
|  | 534 | } | 
|  | 535 | #if SK_SUPPORT_GPU | 
|  | 536 | else {  // GPU | 
| bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 537 | SkAutoTUnref<SkDevice> device(SkGpuDevice::Create(gpuTarget)); | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 538 | if (deferred) { | 
| junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 539 | #if SK_DEFERRED_CANVAS_USES_FACTORIES | 
|  | 540 | canvas.reset(SkDeferredCanvas::Create(device)); | 
|  | 541 | #else | 
|  | 542 | canvas.reset(SkNEW_ARGS(SkDeferredCanvas, (device))); | 
|  | 543 | #endif | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 544 | } else { | 
| junov@chromium.org | 66070a5 | 2013-05-28 17:39:08 +0000 | [diff] [blame] | 545 | canvas.reset(SkNEW_ARGS(SkCanvas, (device))); | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 546 | } | 
| reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 547 | invokeGM(gm, canvas, false, deferred); | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 548 | // the device is as large as the current rendertarget, so | 
|  | 549 | // we explicitly only readback the amount we expect (in | 
|  | 550 | // size) overwrite our previous allocation | 
|  | 551 | bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth, | 
|  | 552 | size.fHeight); | 
|  | 553 | canvas->readPixels(bitmap, 0, 0); | 
|  | 554 | } | 
|  | 555 | #endif | 
| epoger@google.com | 5f6a007 | 2013-01-31 16:30:55 +0000 | [diff] [blame] | 556 | complete_bitmap(bitmap); | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 557 | return kEmpty_ErrorCombination; | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 558 | } | 
|  | 559 |  | 
|  | 560 | static void generate_image_from_picture(GM* gm, const ConfigData& gRec, | 
| junov@chromium.org | c938c48 | 2012-12-19 15:24:38 +0000 | [diff] [blame] | 561 | SkPicture* pict, SkBitmap* bitmap, | 
| robertphillips@google.com | 5a7d029 | 2013-04-02 15:18:41 +0000 | [diff] [blame] | 562 | SkScalar scale = SK_Scalar1, | 
|  | 563 | bool tile = false) { | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 564 | SkISize size = gm->getISize(); | 
|  | 565 | setup_bitmap(gRec, size, bitmap); | 
| robertphillips@google.com | 5a7d029 | 2013-04-02 15:18:41 +0000 | [diff] [blame] | 566 |  | 
|  | 567 | if (tile) { | 
|  | 568 | // Generate the result image by rendering to tiles and accumulating | 
|  | 569 | // the results in 'bitmap' | 
|  | 570 |  | 
| skia.committer@gmail.com | 041e2db | 2013-04-03 07:01:14 +0000 | [diff] [blame] | 571 | // This 16x16 tiling matches the settings applied to 'pict' in | 
| robertphillips@google.com | 5a7d029 | 2013-04-02 15:18:41 +0000 | [diff] [blame] | 572 | // 'generate_new_picture' | 
|  | 573 | SkISize tileSize = SkISize::Make(16, 16); | 
|  | 574 |  | 
|  | 575 | SkBitmap tileBM; | 
|  | 576 | setup_bitmap(gRec, tileSize, &tileBM); | 
|  | 577 | SkCanvas tileCanvas(tileBM); | 
|  | 578 | installFilter(&tileCanvas); | 
|  | 579 |  | 
|  | 580 | SkCanvas bmpCanvas(*bitmap); | 
|  | 581 | SkPaint bmpPaint; | 
|  | 582 | bmpPaint.setXfermodeMode(SkXfermode::kSrc_Mode); | 
|  | 583 |  | 
|  | 584 | for (int yTile = 0; yTile < (size.height()+15)/16; ++yTile) { | 
|  | 585 | for (int xTile = 0; xTile < (size.width()+15)/16; ++xTile) { | 
|  | 586 | int saveCount = tileCanvas.save(); | 
|  | 587 | SkMatrix mat(tileCanvas.getTotalMatrix()); | 
| skia.committer@gmail.com | 041e2db | 2013-04-03 07:01:14 +0000 | [diff] [blame] | 588 | mat.postTranslate(SkIntToScalar(-xTile*tileSize.width()), | 
| robertphillips@google.com | 5a7d029 | 2013-04-02 15:18:41 +0000 | [diff] [blame] | 589 | SkIntToScalar(-yTile*tileSize.height())); | 
|  | 590 | tileCanvas.setMatrix(mat); | 
|  | 591 | pict->draw(&tileCanvas); | 
|  | 592 | tileCanvas.flush(); | 
|  | 593 | tileCanvas.restoreToCount(saveCount); | 
| skia.committer@gmail.com | 041e2db | 2013-04-03 07:01:14 +0000 | [diff] [blame] | 594 | bmpCanvas.drawBitmap(tileBM, | 
|  | 595 | SkIntToScalar(xTile * tileSize.width()), | 
| robertphillips@google.com | 5a7d029 | 2013-04-02 15:18:41 +0000 | [diff] [blame] | 596 | SkIntToScalar(yTile * tileSize.height()), | 
|  | 597 | &bmpPaint); | 
|  | 598 | } | 
|  | 599 | } | 
|  | 600 | } else { | 
|  | 601 | SkCanvas canvas(*bitmap); | 
|  | 602 | installFilter(&canvas); | 
|  | 603 | canvas.scale(scale, scale); | 
|  | 604 | canvas.drawPicture(*pict); | 
|  | 605 | complete_bitmap(bitmap); | 
|  | 606 | } | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 607 | } | 
|  | 608 |  | 
|  | 609 | static void generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) { | 
|  | 610 | #ifdef SK_SUPPORT_PDF | 
|  | 611 | SkMatrix initialTransform = gm->getInitialTransform(); | 
|  | 612 | SkISize pageSize = gm->getISize(); | 
|  | 613 | SkPDFDevice* dev = NULL; | 
|  | 614 | if (initialTransform.isIdentity()) { | 
|  | 615 | dev = new SkPDFDevice(pageSize, pageSize, initialTransform); | 
|  | 616 | } else { | 
|  | 617 | SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()), | 
|  | 618 | SkIntToScalar(pageSize.height())); | 
|  | 619 | initialTransform.mapRect(&content); | 
|  | 620 | content.intersect(0, 0, SkIntToScalar(pageSize.width()), | 
|  | 621 | SkIntToScalar(pageSize.height())); | 
|  | 622 | SkISize contentSize = | 
|  | 623 | SkISize::Make(SkScalarRoundToInt(content.width()), | 
|  | 624 | SkScalarRoundToInt(content.height())); | 
|  | 625 | dev = new SkPDFDevice(pageSize, contentSize, initialTransform); | 
|  | 626 | } | 
| edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 627 | dev->setDCTEncoder(encode_to_dct_stream); | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 628 | SkAutoUnref aur(dev); | 
|  | 629 |  | 
|  | 630 | SkCanvas c(dev); | 
| reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 631 | invokeGM(gm, &c, true, false); | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 632 |  | 
|  | 633 | SkPDFDocument doc; | 
|  | 634 | doc.appendPage(dev); | 
|  | 635 | doc.emitPDF(&pdf); | 
|  | 636 | #endif | 
|  | 637 | } | 
|  | 638 |  | 
|  | 639 | static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) { | 
|  | 640 | #ifdef SK_SUPPORT_XPS | 
|  | 641 | SkISize size = gm->getISize(); | 
|  | 642 |  | 
|  | 643 | SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()), | 
|  | 644 | SkIntToScalar(size.height())); | 
|  | 645 | static const SkScalar inchesPerMeter = SkScalarDiv(10000, 254); | 
|  | 646 | static const SkScalar upm = 72 * inchesPerMeter; | 
|  | 647 | SkVector unitsPerMeter = SkPoint::Make(upm, upm); | 
|  | 648 | static const SkScalar ppm = 200 * inchesPerMeter; | 
|  | 649 | SkVector pixelsPerMeter = SkPoint::Make(ppm, ppm); | 
|  | 650 |  | 
|  | 651 | SkXPSDevice* dev = new SkXPSDevice(); | 
|  | 652 | SkAutoUnref aur(dev); | 
|  | 653 |  | 
|  | 654 | SkCanvas c(dev); | 
|  | 655 | dev->beginPortfolio(&xps); | 
|  | 656 | dev->beginSheet(unitsPerMeter, pixelsPerMeter, trimSize); | 
| reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 657 | invokeGM(gm, &c, false, false); | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 658 | dev->endSheet(); | 
|  | 659 | dev->endPortfolio(); | 
|  | 660 |  | 
|  | 661 | #endif | 
|  | 662 | } | 
|  | 663 |  | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 664 | ErrorCombination write_reference_image(const ConfigData& gRec, const char writePath [], | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 665 | const char renderModeDescriptor [], | 
| epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 666 | const char *shortName, | 
| epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 667 | const BitmapAndDigest* bitmapAndDigest, | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 668 | SkDynamicMemoryWStream* document) { | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 669 | SkString path; | 
|  | 670 | bool success = false; | 
|  | 671 | if (gRec.fBackend == kRaster_Backend || | 
|  | 672 | gRec.fBackend == kGPU_Backend || | 
|  | 673 | (gRec.fBackend == kPDF_Backend && CAN_IMAGE_PDF)) { | 
|  | 674 |  | 
| epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 675 | path = make_bitmap_filename(writePath, shortName, gRec.fName, renderModeDescriptor, | 
| epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 676 | bitmapAndDigest->fDigest); | 
|  | 677 | success = write_bitmap(path, bitmapAndDigest->fBitmap); | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 678 | } | 
|  | 679 | if (kPDF_Backend == gRec.fBackend) { | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 680 | path = make_filename(writePath, shortName, gRec.fName, renderModeDescriptor, | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 681 | "pdf"); | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 682 | success = write_document(path, *document); | 
|  | 683 | } | 
|  | 684 | if (kXPS_Backend == gRec.fBackend) { | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 685 | path = make_filename(writePath, shortName, gRec.fName, renderModeDescriptor, | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 686 | "xps"); | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 687 | success = write_document(path, *document); | 
|  | 688 | } | 
|  | 689 | if (success) { | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 690 | return kEmpty_ErrorCombination; | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 691 | } else { | 
| epoger@google.com | 5efdd0c | 2013-03-13 14:18:40 +0000 | [diff] [blame] | 692 | gm_fprintf(stderr, "FAILED to write %s\n", path.c_str()); | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 693 | ErrorCombination errors(kWritingReferenceImage_ErrorType); | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 694 | // TODO(epoger): Don't call RecordTestResults() here... | 
|  | 695 | // Instead, we should make sure to call RecordTestResults | 
|  | 696 | // exactly ONCE per test.  (Otherwise, gmmain.fTestsRun | 
|  | 697 | // will be incremented twice for this test: once in | 
|  | 698 | // compare_test_results_to_stored_expectations() before | 
|  | 699 | // that method calls this one, and again here.) | 
|  | 700 | // | 
|  | 701 | // When we make that change, we should probably add a | 
|  | 702 | // WritingReferenceImage test to the gm self-tests.) | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 703 | RecordTestResults(errors, make_shortname_plus_config(shortName, gRec.fName), | 
|  | 704 | renderModeDescriptor); | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 705 | return errors; | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 706 | } | 
|  | 707 | } | 
|  | 708 |  | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 709 | /** | 
| epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 710 | * Log more detail about the mistmatch between expectedBitmap and | 
|  | 711 | * actualBitmap. | 
|  | 712 | */ | 
|  | 713 | void report_bitmap_diffs(const SkBitmap& expectedBitmap, const SkBitmap& actualBitmap, | 
|  | 714 | const char *testName) { | 
|  | 715 | const int expectedWidth = expectedBitmap.width(); | 
|  | 716 | const int expectedHeight = expectedBitmap.height(); | 
|  | 717 | const int width = actualBitmap.width(); | 
|  | 718 | const int height = actualBitmap.height(); | 
|  | 719 | if ((expectedWidth != width) || (expectedHeight != height)) { | 
| epoger@google.com | 5efdd0c | 2013-03-13 14:18:40 +0000 | [diff] [blame] | 720 | gm_fprintf(stderr, "---- %s: dimension mismatch --" | 
|  | 721 | " expected [%d %d], actual [%d %d]\n", | 
|  | 722 | testName, expectedWidth, expectedHeight, width, height); | 
| epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 723 | return; | 
|  | 724 | } | 
|  | 725 |  | 
|  | 726 | if ((SkBitmap::kARGB_8888_Config != expectedBitmap.config()) || | 
|  | 727 | (SkBitmap::kARGB_8888_Config != actualBitmap.config())) { | 
| epoger@google.com | 5efdd0c | 2013-03-13 14:18:40 +0000 | [diff] [blame] | 728 | gm_fprintf(stderr, "---- %s: not computing max per-channel" | 
|  | 729 | " pixel mismatch because non-8888\n", testName); | 
| epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 730 | return; | 
|  | 731 | } | 
|  | 732 |  | 
|  | 733 | SkAutoLockPixels alp0(expectedBitmap); | 
|  | 734 | SkAutoLockPixels alp1(actualBitmap); | 
|  | 735 | int errR = 0; | 
|  | 736 | int errG = 0; | 
|  | 737 | int errB = 0; | 
|  | 738 | int errA = 0; | 
|  | 739 | int differingPixels = 0; | 
|  | 740 |  | 
|  | 741 | for (int y = 0; y < height; ++y) { | 
|  | 742 | const SkPMColor* expectedPixelPtr = expectedBitmap.getAddr32(0, y); | 
|  | 743 | const SkPMColor* actualPixelPtr = actualBitmap.getAddr32(0, y); | 
|  | 744 | for (int x = 0; x < width; ++x) { | 
|  | 745 | SkPMColor expectedPixel = *expectedPixelPtr++; | 
|  | 746 | SkPMColor actualPixel = *actualPixelPtr++; | 
|  | 747 | if (expectedPixel != actualPixel) { | 
|  | 748 | differingPixels++; | 
|  | 749 | errR = SkMax32(errR, SkAbs32((int)SkGetPackedR32(expectedPixel) - | 
|  | 750 | (int)SkGetPackedR32(actualPixel))); | 
|  | 751 | errG = SkMax32(errG, SkAbs32((int)SkGetPackedG32(expectedPixel) - | 
|  | 752 | (int)SkGetPackedG32(actualPixel))); | 
|  | 753 | errB = SkMax32(errB, SkAbs32((int)SkGetPackedB32(expectedPixel) - | 
|  | 754 | (int)SkGetPackedB32(actualPixel))); | 
|  | 755 | errA = SkMax32(errA, SkAbs32((int)SkGetPackedA32(expectedPixel) - | 
|  | 756 | (int)SkGetPackedA32(actualPixel))); | 
|  | 757 | } | 
|  | 758 | } | 
|  | 759 | } | 
| epoger@google.com | 5efdd0c | 2013-03-13 14:18:40 +0000 | [diff] [blame] | 760 | gm_fprintf(stderr, "---- %s: %d (of %d) differing pixels," | 
|  | 761 | " max per-channel mismatch R=%d G=%d B=%d A=%d\n", | 
|  | 762 | testName, differingPixels, width*height, errR, errG, errB, errA); | 
| epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 763 | } | 
|  | 764 |  | 
|  | 765 | /** | 
| epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 766 | * Compares actual hash digest to expectations, returning the set of errors | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 767 | * (if any) that we saw along the way. | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 768 | * | 
|  | 769 | * If fMismatchPath has been set, and there are pixel diffs, then the | 
|  | 770 | * actual bitmap will be written out to a file within fMismatchPath. | 
| epoger@google.com | 5f99545 | 2013-06-21 18:16:47 +0000 | [diff] [blame] | 771 | * And similarly for fMissingExpectationsPath... | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 772 | * | 
|  | 773 | * @param expectations what expectations to compare actualBitmap against | 
| epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 774 | * @param actualBitmapAndDigest the SkBitmap we actually generated, and its GmResultDigest | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 775 | * @param shortName name of test, e.g. "selftest1" | 
|  | 776 | * @param configName name of config, e.g. "8888" | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 777 | * @param renderModeDescriptor e.g., "-rtree", "-deferred" | 
|  | 778 | * @param addToJsonSummary whether to add these results (both actual and | 
| epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 779 | *        expected) to the JSON summary. Regardless of this setting, if | 
|  | 780 | *        we find an image mismatch in this test, we will write these | 
|  | 781 | *        results to the JSON summary.  (This is so that we will always | 
|  | 782 | *        report errors across rendering modes, such as pipe vs tiled. | 
|  | 783 | *        See https://codereview.chromium.org/13650002/ ) | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 784 | */ | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 785 | ErrorCombination compare_to_expectations(Expectations expectations, | 
| epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 786 | const BitmapAndDigest& actualBitmapAndDigest, | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 787 | const char *shortName, const char *configName, | 
|  | 788 | const char *renderModeDescriptor, | 
| epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 789 | bool addToJsonSummary) { | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 790 | ErrorCombination errors; | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 791 | SkString shortNamePlusConfig = make_shortname_plus_config(shortName, configName); | 
|  | 792 | SkString completeNameString(shortNamePlusConfig); | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 793 | completeNameString.append(renderModeDescriptor); | 
| epoger@google.com | ce057fe | 2013-05-14 15:17:46 +0000 | [diff] [blame] | 794 | completeNameString.append("."); | 
|  | 795 | completeNameString.append(kPNG_FileExtension); | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 796 | const char* completeName = completeNameString.c_str(); | 
| epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 797 |  | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 798 | if (expectations.empty()) { | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 799 | errors.add(kMissingExpectations_ErrorType); | 
| epoger@google.com | 5f99545 | 2013-06-21 18:16:47 +0000 | [diff] [blame] | 800 |  | 
|  | 801 | // Write out the "actuals" for any tests without expectations, if we have | 
|  | 802 | // been directed to do so. | 
|  | 803 | if (fMissingExpectationsPath) { | 
|  | 804 | SkString path = make_bitmap_filename(fMissingExpectationsPath, shortName, | 
|  | 805 | configName, renderModeDescriptor, | 
|  | 806 | actualBitmapAndDigest.fDigest); | 
|  | 807 | write_bitmap(path, actualBitmapAndDigest.fBitmap); | 
|  | 808 | } | 
|  | 809 |  | 
| epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 810 | } else if (!expectations.match(actualBitmapAndDigest.fDigest)) { | 
| epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 811 | addToJsonSummary = true; | 
|  | 812 | // The error mode we record depends on whether this was running | 
|  | 813 | // in a non-standard renderMode. | 
|  | 814 | if ('\0' == *renderModeDescriptor) { | 
|  | 815 | errors.add(kExpectationsMismatch_ErrorType); | 
|  | 816 | } else { | 
|  | 817 | errors.add(kRenderModeMismatch_ErrorType); | 
|  | 818 | } | 
| epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 819 |  | 
|  | 820 | // Write out the "actuals" for any mismatches, if we have | 
|  | 821 | // been directed to do so. | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 822 | if (fMismatchPath) { | 
| epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 823 | SkString path = make_bitmap_filename(fMismatchPath, shortName, configName, | 
|  | 824 | renderModeDescriptor, | 
|  | 825 | actualBitmapAndDigest.fDigest); | 
|  | 826 | write_bitmap(path, actualBitmapAndDigest.fBitmap); | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 827 | } | 
| epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 828 |  | 
|  | 829 | // If we have access to a single expected bitmap, log more | 
|  | 830 | // detail about the mismatch. | 
|  | 831 | const SkBitmap *expectedBitmapPtr = expectations.asBitmap(); | 
|  | 832 | if (NULL != expectedBitmapPtr) { | 
| epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 833 | report_bitmap_diffs(*expectedBitmapPtr, actualBitmapAndDigest.fBitmap, | 
|  | 834 | completeName); | 
| epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 835 | } | 
| epoger@google.com | a243b22 | 2013-01-17 17:54:28 +0000 | [diff] [blame] | 836 | } | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 837 | RecordTestResults(errors, shortNamePlusConfig, renderModeDescriptor); | 
| epoger@google.com | a243b22 | 2013-01-17 17:54:28 +0000 | [diff] [blame] | 838 |  | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 839 | if (addToJsonSummary) { | 
| epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 840 | add_actual_results_to_json_summary(completeName, actualBitmapAndDigest.fDigest, errors, | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 841 | expectations.ignoreFailure()); | 
|  | 842 | add_expected_results_to_json_summary(completeName, expectations); | 
|  | 843 | } | 
| epoger@google.com | a243b22 | 2013-01-17 17:54:28 +0000 | [diff] [blame] | 844 |  | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 845 | return errors; | 
| epoger@google.com | 06b8a19 | 2013-01-15 19:10:16 +0000 | [diff] [blame] | 846 | } | 
|  | 847 |  | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 848 | /** | 
|  | 849 | * Add this result to the appropriate JSON collection of actual results, | 
| epoger@google.com | 76c913d | 2013-04-26 15:06:44 +0000 | [diff] [blame] | 850 | * depending on errors encountered. | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 851 | */ | 
|  | 852 | void add_actual_results_to_json_summary(const char testName[], | 
| epoger@google.com | d4993ff | 2013-05-24 14:33:28 +0000 | [diff] [blame] | 853 | const GmResultDigest &actualResultDigest, | 
| epoger@google.com | 76c913d | 2013-04-26 15:06:44 +0000 | [diff] [blame] | 854 | ErrorCombination errors, | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 855 | bool ignoreFailure) { | 
| epoger@google.com | d4993ff | 2013-05-24 14:33:28 +0000 | [diff] [blame] | 856 | Json::Value jsonActualResults = actualResultDigest.asJsonTypeValuePair(); | 
| epoger@google.com | 76c913d | 2013-04-26 15:06:44 +0000 | [diff] [blame] | 857 | if (errors.isEmpty()) { | 
|  | 858 | this->fJsonActualResults_Succeeded[testName] = jsonActualResults; | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 859 | } else { | 
|  | 860 | if (ignoreFailure) { | 
|  | 861 | // TODO: Once we have added the ability to compare | 
|  | 862 | // actual results against expectations in a JSON file | 
|  | 863 | // (where we can set ignore-failure to either true or | 
| epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 864 | // false), add test cases that exercise ignored | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 865 | // failures (both for kMissingExpectations_ErrorType | 
| epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 866 | // and kExpectationsMismatch_ErrorType). | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 867 | this->fJsonActualResults_FailureIgnored[testName] = | 
| epoger@google.com | 76c913d | 2013-04-26 15:06:44 +0000 | [diff] [blame] | 868 | jsonActualResults; | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 869 | } else { | 
| epoger@google.com | 76c913d | 2013-04-26 15:06:44 +0000 | [diff] [blame] | 870 | if (errors.includes(kMissingExpectations_ErrorType)) { | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 871 | // TODO: What about the case where there IS an | 
| epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 872 | // expected image hash digest, but that gm test | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 873 | // doesn't actually run?  For now, those cases | 
|  | 874 | // will always be ignored, because gm only looks | 
|  | 875 | // at expectations that correspond to gm tests | 
|  | 876 | // that were actually run. | 
|  | 877 | // | 
|  | 878 | // Once we have the ability to express | 
|  | 879 | // expectations as a JSON file, we should fix this | 
|  | 880 | // (and add a test case for which an expectation | 
|  | 881 | // is given but the test is never run). | 
|  | 882 | this->fJsonActualResults_NoComparison[testName] = | 
| epoger@google.com | 76c913d | 2013-04-26 15:06:44 +0000 | [diff] [blame] | 883 | jsonActualResults; | 
| epoger@google.com | eb06636 | 2013-03-08 09:39:36 +0000 | [diff] [blame] | 884 | } | 
| epoger@google.com | 76c913d | 2013-04-26 15:06:44 +0000 | [diff] [blame] | 885 | if (errors.includes(kExpectationsMismatch_ErrorType) || | 
|  | 886 | errors.includes(kRenderModeMismatch_ErrorType)) { | 
|  | 887 | this->fJsonActualResults_Failed[testName] = jsonActualResults; | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 888 | } | 
|  | 889 | } | 
|  | 890 | } | 
|  | 891 | } | 
|  | 892 |  | 
|  | 893 | /** | 
|  | 894 | * Add this test to the JSON collection of expected results. | 
|  | 895 | */ | 
|  | 896 | void add_expected_results_to_json_summary(const char testName[], | 
|  | 897 | Expectations expectations) { | 
| epoger@google.com | 76c913d | 2013-04-26 15:06:44 +0000 | [diff] [blame] | 898 | this->fJsonExpectedResults[testName] = expectations.asJsonValue(); | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 899 | } | 
|  | 900 |  | 
|  | 901 | /** | 
|  | 902 | * Compare actualBitmap to expectations stored in this->fExpectationsSource. | 
|  | 903 | * | 
|  | 904 | * @param gm which test generated the actualBitmap | 
|  | 905 | * @param gRec | 
|  | 906 | * @param writePath unless this is NULL, write out actual images into this | 
|  | 907 | *        directory | 
| epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 908 | * @param actualBitmapAndDigest ptr to bitmap generated by this run, or NULL | 
|  | 909 | *        if we don't have a usable bitmap representation | 
|  | 910 | * @param document pdf or xps representation, if appropriate | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 911 | */ | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 912 | ErrorCombination compare_test_results_to_stored_expectations( | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 913 | GM* gm, const ConfigData& gRec, const char writePath[], | 
| epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 914 | const BitmapAndDigest* actualBitmapAndDigest, SkDynamicMemoryWStream* document) { | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 915 |  | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 916 | SkString shortNamePlusConfig = make_shortname_plus_config(gm->shortName(), gRec.fName); | 
|  | 917 | SkString nameWithExtension(shortNamePlusConfig); | 
|  | 918 | nameWithExtension.append("."); | 
|  | 919 | nameWithExtension.append(kPNG_FileExtension); | 
| epoger@google.com | 9ef89ce | 2013-01-18 21:45:42 +0000 | [diff] [blame] | 920 |  | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 921 | ErrorCombination errors; | 
| epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 922 |  | 
|  | 923 | if (NULL == actualBitmapAndDigest) { | 
|  | 924 | // Note that we intentionally skipped validating the results for | 
|  | 925 | // this test, because we don't know how to generate an SkBitmap | 
|  | 926 | // version of the output. | 
|  | 927 | RecordTestResults(ErrorCombination(kIntentionallySkipped_ErrorType), | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 928 | shortNamePlusConfig, ""); | 
| epoger@google.com | c824c83 | 2013-07-12 15:52:59 +0000 | [diff] [blame^] | 929 | } else if (!(gRec.fFlags & kWrite_ConfigFlag)) { | 
|  | 930 | // We don't record the results for this test or compare them | 
|  | 931 | // against any expectations, because the output image isn't | 
|  | 932 | // meaningful. | 
|  | 933 | // See https://code.google.com/p/skia/issues/detail?id=1410 ('some | 
|  | 934 | // GM result images not available for download from Google Storage') | 
|  | 935 | RecordTestResults(ErrorCombination(kIntentionallySkipped_ErrorType), | 
|  | 936 | shortNamePlusConfig, ""); | 
| epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 937 | } else { | 
|  | 938 | ExpectationsSource *expectationsSource = this->fExpectationsSource.get(); | 
|  | 939 | if (expectationsSource && (gRec.fFlags & kRead_ConfigFlag)) { | 
|  | 940 | /* | 
|  | 941 | * Get the expected results for this test, as one or more allowed | 
|  | 942 | * hash digests. The current implementation of expectationsSource | 
|  | 943 | * get this by computing the hash digest of a single PNG file on disk. | 
|  | 944 | * | 
|  | 945 | * TODO(epoger): This relies on the fact that | 
|  | 946 | * force_all_opaque() was called on the bitmap before it | 
|  | 947 | * was written to disk as a PNG in the first place. If | 
|  | 948 | * not, the hash digest returned here may not match the | 
|  | 949 | * hash digest of actualBitmap, which *has* been run through | 
|  | 950 | * force_all_opaque(). | 
|  | 951 | * See comments above complete_bitmap() for more detail. | 
|  | 952 | */ | 
|  | 953 | Expectations expectations = expectationsSource->get(nameWithExtension.c_str()); | 
|  | 954 | errors.add(compare_to_expectations(expectations, *actualBitmapAndDigest, | 
|  | 955 | gm->shortName(), gRec.fName, "", true)); | 
|  | 956 | } else { | 
|  | 957 | // If we are running without expectations, we still want to | 
|  | 958 | // record the actual results. | 
|  | 959 | add_actual_results_to_json_summary(nameWithExtension.c_str(), | 
|  | 960 | actualBitmapAndDigest->fDigest, | 
|  | 961 | ErrorCombination(kMissingExpectations_ErrorType), | 
|  | 962 | false); | 
|  | 963 | RecordTestResults(ErrorCombination(kMissingExpectations_ErrorType), | 
|  | 964 | shortNamePlusConfig, ""); | 
|  | 965 | } | 
| epoger@google.com | 9ef89ce | 2013-01-18 21:45:42 +0000 | [diff] [blame] | 966 | } | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 967 |  | 
|  | 968 | // TODO: Consider moving this into compare_to_expectations(), | 
|  | 969 | // similar to fMismatchPath... for now, we don't do that, because | 
|  | 970 | // we don't want to write out the actual bitmaps for all | 
|  | 971 | // renderModes of all tests!  That would be a lot of files. | 
| epoger@google.com | 9ef89ce | 2013-01-18 21:45:42 +0000 | [diff] [blame] | 972 | if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) { | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 973 | errors.add(write_reference_image(gRec, writePath, "", gm->shortName(), | 
| epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 974 | actualBitmapAndDigest, document)); | 
| epoger@google.com | 9ef89ce | 2013-01-18 21:45:42 +0000 | [diff] [blame] | 975 | } | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 976 |  | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 977 | return errors; | 
| epoger@google.com | a243b22 | 2013-01-17 17:54:28 +0000 | [diff] [blame] | 978 | } | 
|  | 979 |  | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 980 | /** | 
|  | 981 | * Compare actualBitmap to referenceBitmap. | 
|  | 982 | * | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 983 | * @param shortName test name, e.g. "selftest1" | 
|  | 984 | * @param configName configuration name, e.g. "8888" | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 985 | * @param renderModeDescriptor | 
|  | 986 | * @param actualBitmap actual bitmap generated by this run | 
|  | 987 | * @param referenceBitmap bitmap we expected to be generated | 
|  | 988 | */ | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 989 | ErrorCombination compare_test_results_to_reference_bitmap( | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 990 | const char *shortName, const char *configName, const char *renderModeDescriptor, | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 991 | SkBitmap& actualBitmap, const SkBitmap* referenceBitmap) { | 
|  | 992 |  | 
|  | 993 | SkASSERT(referenceBitmap); | 
| epoger@google.com | 84a1802 | 2013-02-01 20:39:15 +0000 | [diff] [blame] | 994 | Expectations expectations(*referenceBitmap); | 
| epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 995 | BitmapAndDigest actualBitmapAndDigest(actualBitmap); | 
|  | 996 | return compare_to_expectations(expectations, actualBitmapAndDigest, shortName, | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 997 | configName, renderModeDescriptor, false); | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 998 | } | 
|  | 999 |  | 
| junov@chromium.org | 20bd04e | 2013-01-16 18:43:36 +0000 | [diff] [blame] | 1000 | static SkPicture* generate_new_picture(GM* gm, BbhType bbhType, uint32_t recordFlags, | 
|  | 1001 | SkScalar scale = SK_Scalar1) { | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1002 | // Pictures are refcounted so must be on heap | 
| junov@chromium.org | 3cb834b | 2012-12-13 16:39:53 +0000 | [diff] [blame] | 1003 | SkPicture* pict; | 
| junov@chromium.org | 706ff2f | 2012-12-19 15:55:40 +0000 | [diff] [blame] | 1004 | int width = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().width()), scale)); | 
|  | 1005 | int height = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().height()), scale)); | 
| skia.committer@gmail.com | d8b2799 | 2012-12-20 02:01:41 +0000 | [diff] [blame] | 1006 |  | 
| junov@chromium.org | 3cb834b | 2012-12-13 16:39:53 +0000 | [diff] [blame] | 1007 | if (kTileGrid_BbhType == bbhType) { | 
| junov@chromium.org | 29b19e5 | 2013-02-27 18:35:16 +0000 | [diff] [blame] | 1008 | SkTileGridPicture::TileGridInfo info; | 
|  | 1009 | info.fMargin.setEmpty(); | 
|  | 1010 | info.fOffset.setZero(); | 
|  | 1011 | info.fTileInterval.set(16, 16); | 
|  | 1012 | pict = new SkTileGridPicture(width, height, info); | 
| junov@chromium.org | 3cb834b | 2012-12-13 16:39:53 +0000 | [diff] [blame] | 1013 | } else { | 
|  | 1014 | pict = new SkPicture; | 
|  | 1015 | } | 
| junov@chromium.org | 20bd04e | 2013-01-16 18:43:36 +0000 | [diff] [blame] | 1016 | if (kNone_BbhType != bbhType) { | 
|  | 1017 | recordFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; | 
|  | 1018 | } | 
| junov@chromium.org | 706ff2f | 2012-12-19 15:55:40 +0000 | [diff] [blame] | 1019 | SkCanvas* cv = pict->beginRecording(width, height, recordFlags); | 
| junov@chromium.org | c938c48 | 2012-12-19 15:24:38 +0000 | [diff] [blame] | 1020 | cv->scale(scale, scale); | 
| reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 1021 | invokeGM(gm, cv, false, false); | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1022 | pict->endRecording(); | 
|  | 1023 |  | 
|  | 1024 | return pict; | 
|  | 1025 | } | 
|  | 1026 |  | 
|  | 1027 | static SkPicture* stream_to_new_picture(const SkPicture& src) { | 
|  | 1028 |  | 
|  | 1029 | // To do in-memory commiunications with a stream, we need to: | 
|  | 1030 | // * create a dynamic memory stream | 
|  | 1031 | // * copy it into a buffer | 
|  | 1032 | // * create a read stream from it | 
|  | 1033 | // ?!?! | 
|  | 1034 |  | 
|  | 1035 | SkDynamicMemoryWStream storage; | 
|  | 1036 | src.serialize(&storage); | 
|  | 1037 |  | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1038 | size_t streamSize = storage.getOffset(); | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1039 | SkAutoMalloc dstStorage(streamSize); | 
|  | 1040 | void* dst = dstStorage.get(); | 
|  | 1041 | //char* dst = new char [streamSize]; | 
|  | 1042 | //@todo thudson 22 April 2011 when can we safely delete [] dst? | 
|  | 1043 | storage.copyTo(dst); | 
|  | 1044 | SkMemoryStream pictReadback(dst, streamSize); | 
| scroggo@google.com | f1754ec | 2013-06-28 21:32:00 +0000 | [diff] [blame] | 1045 | SkPicture* retval = SkPicture::CreateFromStream(&pictReadback); | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1046 | return retval; | 
|  | 1047 | } | 
|  | 1048 |  | 
|  | 1049 | // Test: draw into a bitmap or pdf. | 
| epoger@google.com | 15655b2 | 2013-01-08 18:47:31 +0000 | [diff] [blame] | 1050 | // Depending on flags, possibly compare to an expected image. | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1051 | ErrorCombination test_drawing(GM* gm, | 
|  | 1052 | const ConfigData& gRec, | 
|  | 1053 | const char writePath [], | 
| bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1054 | GrSurface* gpuTarget, | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1055 | SkBitmap* bitmap) { | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1056 | SkDynamicMemoryWStream document; | 
|  | 1057 |  | 
|  | 1058 | if (gRec.fBackend == kRaster_Backend || | 
|  | 1059 | gRec.fBackend == kGPU_Backend) { | 
|  | 1060 | // Early exit if we can't generate the image. | 
| bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1061 | ErrorCombination errors = generate_image(gm, gRec, gpuTarget, bitmap, false); | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1062 | if (!errors.isEmpty()) { | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1063 | // TODO: Add a test to exercise what the stdout and | 
|  | 1064 | // JSON look like if we get an "early error" while | 
|  | 1065 | // trying to generate the image. | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1066 | return errors; | 
|  | 1067 | } | 
|  | 1068 | } else if (gRec.fBackend == kPDF_Backend) { | 
|  | 1069 | generate_pdf(gm, document); | 
|  | 1070 | #if CAN_IMAGE_PDF | 
|  | 1071 | SkAutoDataUnref data(document.copyToData()); | 
|  | 1072 | SkMemoryStream stream(data->data(), data->size()); | 
|  | 1073 | SkPDFDocumentToBitmap(&stream, bitmap); | 
| epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 1074 | #else | 
|  | 1075 | bitmap = NULL;  // we don't generate a bitmap rendering of the PDF file | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1076 | #endif | 
|  | 1077 | } else if (gRec.fBackend == kXPS_Backend) { | 
|  | 1078 | generate_xps(gm, document); | 
| epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 1079 | bitmap = NULL;  // we don't generate a bitmap rendering of the XPS file | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1080 | } | 
| epoger@google.com | e33e137 | 2013-07-08 19:13:33 +0000 | [diff] [blame] | 1081 |  | 
|  | 1082 | if (NULL == bitmap) { | 
|  | 1083 | return compare_test_results_to_stored_expectations( | 
|  | 1084 | gm, gRec, writePath, NULL, &document); | 
|  | 1085 | } else { | 
|  | 1086 | BitmapAndDigest bitmapAndDigest(*bitmap); | 
|  | 1087 | return compare_test_results_to_stored_expectations( | 
|  | 1088 | gm, gRec, writePath, &bitmapAndDigest, &document); | 
|  | 1089 | } | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1090 | } | 
|  | 1091 |  | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1092 | ErrorCombination test_deferred_drawing(GM* gm, | 
|  | 1093 | const ConfigData& gRec, | 
|  | 1094 | const SkBitmap& referenceBitmap, | 
| bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1095 | GrSurface* gpuTarget) { | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1096 | SkDynamicMemoryWStream document; | 
|  | 1097 |  | 
|  | 1098 | if (gRec.fBackend == kRaster_Backend || | 
|  | 1099 | gRec.fBackend == kGPU_Backend) { | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1100 | const char renderModeDescriptor[] = "-deferred"; | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1101 | SkBitmap bitmap; | 
|  | 1102 | // Early exit if we can't generate the image, but this is | 
|  | 1103 | // expected in some cases, so don't report a test failure. | 
| bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1104 | ErrorCombination errors = generate_image(gm, gRec, gpuTarget, &bitmap, true); | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1105 | // TODO(epoger): This logic is the opposite of what is | 
|  | 1106 | // described above... if we succeeded in generating the | 
|  | 1107 | // -deferred image, we exit early!  We should fix this | 
|  | 1108 | // ASAP, because it is hiding -deferred errors... but for | 
|  | 1109 | // now, I'm leaving the logic as it is so that the | 
|  | 1110 | // refactoring change | 
|  | 1111 | // https://codereview.chromium.org/12992003/ is unblocked. | 
|  | 1112 | // | 
|  | 1113 | // Filed as https://code.google.com/p/skia/issues/detail?id=1180 | 
|  | 1114 | // ('image-surface gm test is failing in "deferred" mode, | 
|  | 1115 | // and gm is not reporting the failure') | 
|  | 1116 | if (errors.isEmpty()) { | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 1117 | // TODO(epoger): Report this as a new ErrorType, | 
|  | 1118 | // something like kImageGeneration_ErrorType? | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1119 | return kEmpty_ErrorCombination; | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1120 | } | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1121 | return compare_test_results_to_reference_bitmap( | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1122 | gm->shortName(), gRec.fName, renderModeDescriptor, bitmap, &referenceBitmap); | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1123 | } | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1124 | return kEmpty_ErrorCombination; | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1125 | } | 
|  | 1126 |  | 
| epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 1127 | ErrorCombination test_pipe_playback(GM* gm, const ConfigData& gRec, | 
|  | 1128 | const SkBitmap& referenceBitmap, bool simulateFailure) { | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1129 | const SkString shortNamePlusConfig = make_shortname_plus_config(gm->shortName(), | 
|  | 1130 | gRec.fName); | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1131 | ErrorCombination errors; | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1132 | for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) { | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1133 | SkString renderModeDescriptor("-pipe"); | 
|  | 1134 | renderModeDescriptor.append(gPipeWritingFlagCombos[i].name); | 
|  | 1135 |  | 
|  | 1136 | if (gm->getFlags() & GM::kSkipPipe_Flag) { | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1137 | RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1138 | renderModeDescriptor.c_str()); | 
|  | 1139 | errors.add(kIntentionallySkipped_ErrorType); | 
|  | 1140 | } else { | 
|  | 1141 | SkBitmap bitmap; | 
|  | 1142 | SkISize size = gm->getISize(); | 
|  | 1143 | setup_bitmap(gRec, size, &bitmap); | 
|  | 1144 | SkCanvas canvas(bitmap); | 
|  | 1145 | installFilter(&canvas); | 
| scroggo@google.com | 74b7ffd | 2013-04-30 02:32:41 +0000 | [diff] [blame] | 1146 | // Pass a decoding function so the factory GM (which has an SkBitmap | 
|  | 1147 | // with encoded data) will not fail playback. | 
|  | 1148 | PipeController pipeController(&canvas, &SkImageDecoder::DecodeMemory); | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1149 | SkGPipeWriter writer; | 
|  | 1150 | SkCanvas* pipeCanvas = writer.startRecording(&pipeController, | 
| scroggo@google.com | aef2d3b | 2013-04-10 18:10:41 +0000 | [diff] [blame] | 1151 | gPipeWritingFlagCombos[i].flags, | 
|  | 1152 | size.width(), size.height()); | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1153 | if (!simulateFailure) { | 
|  | 1154 | invokeGM(gm, pipeCanvas, false, false); | 
|  | 1155 | } | 
|  | 1156 | complete_bitmap(&bitmap); | 
|  | 1157 | writer.endRecording(); | 
|  | 1158 | errors.add(compare_test_results_to_reference_bitmap( | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1159 | gm->shortName(), gRec.fName, renderModeDescriptor.c_str(), bitmap, | 
|  | 1160 | &referenceBitmap)); | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1161 | if (!errors.isEmpty()) { | 
|  | 1162 | break; | 
|  | 1163 | } | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1164 | } | 
|  | 1165 | } | 
|  | 1166 | return errors; | 
|  | 1167 | } | 
|  | 1168 |  | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1169 | ErrorCombination test_tiled_pipe_playback(GM* gm, const ConfigData& gRec, | 
|  | 1170 | const SkBitmap& referenceBitmap) { | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1171 | const SkString shortNamePlusConfig = make_shortname_plus_config(gm->shortName(), | 
|  | 1172 | gRec.fName); | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1173 | ErrorCombination errors; | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1174 | for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) { | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1175 | SkString renderModeDescriptor("-tiled pipe"); | 
|  | 1176 | renderModeDescriptor.append(gPipeWritingFlagCombos[i].name); | 
|  | 1177 |  | 
|  | 1178 | if ((gm->getFlags() & GM::kSkipPipe_Flag) || | 
|  | 1179 | (gm->getFlags() & GM::kSkipTiled_Flag)) { | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1180 | RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1181 | renderModeDescriptor.c_str()); | 
|  | 1182 | errors.add(kIntentionallySkipped_ErrorType); | 
|  | 1183 | } else { | 
|  | 1184 | SkBitmap bitmap; | 
|  | 1185 | SkISize size = gm->getISize(); | 
|  | 1186 | setup_bitmap(gRec, size, &bitmap); | 
|  | 1187 | SkCanvas canvas(bitmap); | 
|  | 1188 | installFilter(&canvas); | 
| scroggo@google.com | 74b7ffd | 2013-04-30 02:32:41 +0000 | [diff] [blame] | 1189 | TiledPipeController pipeController(bitmap, &SkImageDecoder::DecodeMemory); | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1190 | SkGPipeWriter writer; | 
|  | 1191 | SkCanvas* pipeCanvas = writer.startRecording(&pipeController, | 
| scroggo@google.com | aef2d3b | 2013-04-10 18:10:41 +0000 | [diff] [blame] | 1192 | gPipeWritingFlagCombos[i].flags, | 
|  | 1193 | size.width(), size.height()); | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1194 | invokeGM(gm, pipeCanvas, false, false); | 
|  | 1195 | complete_bitmap(&bitmap); | 
|  | 1196 | writer.endRecording(); | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1197 | errors.add(compare_test_results_to_reference_bitmap(gm->shortName(), gRec.fName, | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1198 | renderModeDescriptor.c_str(), | 
|  | 1199 | bitmap, &referenceBitmap)); | 
|  | 1200 | if (!errors.isEmpty()) { | 
|  | 1201 | break; | 
|  | 1202 | } | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1203 | } | 
|  | 1204 | } | 
|  | 1205 | return errors; | 
|  | 1206 | } | 
| epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 1207 |  | 
|  | 1208 | // | 
|  | 1209 | // member variables. | 
|  | 1210 | // They are public for now, to allow easier setting by tool_main(). | 
|  | 1211 | // | 
|  | 1212 |  | 
| epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 1213 | bool fUseFileHierarchy, fWriteChecksumBasedFilenames; | 
| epoger@google.com | 5079d2c | 2013-04-12 14:11:21 +0000 | [diff] [blame] | 1214 | ErrorCombination fIgnorableErrorTypes; | 
| epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 1215 |  | 
| junov@chromium.org | 95146eb | 2013-01-11 21:04:40 +0000 | [diff] [blame] | 1216 | const char* fMismatchPath; | 
| epoger@google.com | 5f99545 | 2013-06-21 18:16:47 +0000 | [diff] [blame] | 1217 | const char* fMissingExpectationsPath; | 
| junov@chromium.org | 95146eb | 2013-01-11 21:04:40 +0000 | [diff] [blame] | 1218 |  | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 1219 | // collection of tests that have failed with each ErrorType | 
|  | 1220 | SkTArray<SkString> fFailedTests[kLast_ErrorType+1]; | 
|  | 1221 | int fTestsRun; | 
|  | 1222 | SkTDict<int> fRenderModesEncountered; | 
| epoger@google.com | 57f7abc | 2012-11-13 03:41:55 +0000 | [diff] [blame] | 1223 |  | 
| epoger@google.com | 908f583 | 2013-04-12 02:23:55 +0000 | [diff] [blame] | 1224 | // Where to read expectations (expected image hash digests, etc.) from. | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 1225 | // If unset, we don't do comparisons. | 
|  | 1226 | SkAutoTUnref<ExpectationsSource> fExpectationsSource; | 
|  | 1227 |  | 
|  | 1228 | // JSON summaries that we generate as we go (just for output). | 
| epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 1229 | Json::Value fJsonExpectedResults; | 
|  | 1230 | Json::Value fJsonActualResults_Failed; | 
|  | 1231 | Json::Value fJsonActualResults_FailureIgnored; | 
| epoger@google.com | 9c56a8d | 2012-12-20 18:34:29 +0000 | [diff] [blame] | 1232 | Json::Value fJsonActualResults_NoComparison; | 
| epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 1233 | Json::Value fJsonActualResults_Succeeded; | 
|  | 1234 |  | 
| epoger@google.com | de96163 | 2012-10-26 18:56:36 +0000 | [diff] [blame] | 1235 | }; // end of GMMain class definition | 
| scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 1236 |  | 
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1237 | #if SK_SUPPORT_GPU | 
|  | 1238 | static const GLContextType kDontCare_GLContextType = GrContextFactory::kNative_GLContextType; | 
|  | 1239 | #else | 
|  | 1240 | static const GLContextType kDontCare_GLContextType = 0; | 
|  | 1241 | #endif | 
| bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1242 |  | 
|  | 1243 | // 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] | 1244 | // 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] | 1245 | static const ConfigFlags kPDFConfigFlags = CAN_IMAGE_PDF ? kRW_ConfigFlag : | 
|  | 1246 | kWrite_ConfigFlag; | 
|  | 1247 |  | 
| tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1248 | static const ConfigData gRec[] = { | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1249 | { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType,                  0, kRW_ConfigFlag,    "8888",         true }, | 
| reed@google.com | 69dc4ff | 2012-11-29 21:21:54 +0000 | [diff] [blame] | 1250 | #if 0   // stop testing this (for now at least) since we want to remove support for it (soon please!!!) | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1251 | { SkBitmap::kARGB_4444_Config, kRaster_Backend, kDontCare_GLContextType,                  0, kRW_ConfigFlag,    "4444",         true }, | 
| reed@google.com | 69dc4ff | 2012-11-29 21:21:54 +0000 | [diff] [blame] | 1252 | #endif | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1253 | { SkBitmap::kRGB_565_Config,   kRaster_Backend, kDontCare_GLContextType,                  0, kRW_ConfigFlag,    "565",          true }, | 
|  | 1254 | #if SK_SUPPORT_GPU | 
|  | 1255 | { SkBitmap::kARGB_8888_Config, kGPU_Backend,    GrContextFactory::kNative_GLContextType,  0, kRW_ConfigFlag,    "gpu",          true }, | 
| robertphillips@google.com | 7bb28a1 | 2013-06-06 21:29:39 +0000 | [diff] [blame] | 1256 | { SkBitmap::kARGB_8888_Config, kGPU_Backend,    GrContextFactory::kNative_GLContextType, 16, kRW_ConfigFlag,    "msaa16",       false}, | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1257 | { SkBitmap::kARGB_8888_Config, kGPU_Backend,    GrContextFactory::kNative_GLContextType,  4, kRW_ConfigFlag,    "msaa4",        false}, | 
| epoger@google.com | c824c83 | 2013-07-12 15:52:59 +0000 | [diff] [blame^] | 1258 | /* The gpudebug context does not generate meaningful images, so don't record | 
|  | 1259 | * the images it generates!  We only run it to look for asserts. */ | 
| scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1260 | { SkBitmap::kARGB_8888_Config, kGPU_Backend,    GrContextFactory::kDebug_GLContextType,   0, kNone_ConfigFlag,  "gpudebug",     GR_DEBUG}, | 
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1261 | #if SK_ANGLE | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1262 | { SkBitmap::kARGB_8888_Config, kGPU_Backend,    GrContextFactory::kANGLE_GLContextType,   0, kRW_ConfigFlag,    "angle",        true }, | 
|  | 1263 | { SkBitmap::kARGB_8888_Config, kGPU_Backend,    GrContextFactory::kANGLE_GLContextType,  16, kRW_ConfigFlag,    "anglemsaa16",  true }, | 
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1264 | #endif // SK_ANGLE | 
|  | 1265 | #ifdef SK_MESA | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1266 | { SkBitmap::kARGB_8888_Config, kGPU_Backend,    GrContextFactory::kMESA_GLContextType,    0, kRW_ConfigFlag,    "mesa",         true }, | 
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1267 | #endif // SK_MESA | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1268 | #endif // SK_SUPPORT_GPU | 
| bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1269 | #ifdef SK_SUPPORT_XPS | 
| bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1270 | /* At present we have no way of comparing XPS files (either natively or by converting to PNG). */ | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1271 | { SkBitmap::kARGB_8888_Config, kXPS_Backend,    kDontCare_GLContextType,                  0, kWrite_ConfigFlag, "xps",          true }, | 
| robertphillips@google.com | a73e860 | 2012-08-02 17:56:02 +0000 | [diff] [blame] | 1272 | #endif // SK_SUPPORT_XPS | 
| bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1273 | #ifdef SK_SUPPORT_PDF | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1274 | { SkBitmap::kARGB_8888_Config, kPDF_Backend,    kDontCare_GLContextType,                  0, kPDFConfigFlags,   "pdf",          true }, | 
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1275 | #endif // SK_SUPPORT_PDF | 
| reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1276 | }; | 
|  | 1277 |  | 
| bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1278 | static const char kDefaultsConfigStr[] = "defaults"; | 
|  | 1279 | static const char kExcludeConfigChar = '~'; | 
|  | 1280 |  | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1281 | static SkString configUsage() { | 
| scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1282 | SkString result; | 
|  | 1283 | result.appendf("Space delimited list of which configs to run. Possible options: ["); | 
| scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1284 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { | 
| bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1285 | SkASSERT(gRec[i].fName != kDefaultsConfigStr); | 
| scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1286 | if (i > 0) { | 
| scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1287 | result.append("|"); | 
| scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1288 | } | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1289 | result.appendf("%s", gRec[i].fName); | 
| scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1290 | } | 
| scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1291 | result.append("]\n"); | 
|  | 1292 | result.appendf("The default value is: \""); | 
| bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1293 | SkString firstDefault; | 
|  | 1294 | SkString allButFirstDefaults; | 
|  | 1295 | SkString nonDefault; | 
| scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1296 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { | 
|  | 1297 | if (gRec[i].fRunByDefault) { | 
|  | 1298 | if (i > 0) { | 
|  | 1299 | result.append(" "); | 
|  | 1300 | } | 
| bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1301 | result.append(gRec[i].fName); | 
|  | 1302 | if (firstDefault.isEmpty()) { | 
|  | 1303 | firstDefault = gRec[i].fName; | 
|  | 1304 | } else { | 
|  | 1305 | if (!allButFirstDefaults.isEmpty()) { | 
|  | 1306 | allButFirstDefaults.append(" "); | 
|  | 1307 | } | 
|  | 1308 | allButFirstDefaults.append(gRec[i].fName); | 
|  | 1309 | } | 
|  | 1310 | } else { | 
|  | 1311 | nonDefault = gRec[i].fName; | 
| scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1312 | } | 
|  | 1313 | } | 
| bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1314 | result.append("\"\n"); | 
|  | 1315 | result.appendf("\"%s\" evaluates to the default set of configs.\n", kDefaultsConfigStr); | 
|  | 1316 | result.appendf("Prepending \"%c\" on a config name excludes it from the set of configs to run.\n" | 
|  | 1317 | "Exclusions always override inclusions regardless of order.\n", | 
|  | 1318 | kExcludeConfigChar); | 
|  | 1319 | result.appendf("E.g. \"--config %s %c%s %s\" will run these configs:\n\t%s %s", | 
|  | 1320 | kDefaultsConfigStr, | 
|  | 1321 | kExcludeConfigChar, | 
|  | 1322 | firstDefault.c_str(), | 
|  | 1323 | nonDefault.c_str(), | 
|  | 1324 | allButFirstDefaults.c_str(), | 
|  | 1325 | nonDefault.c_str()); | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1326 | return result; | 
| scroggo@google.com | 0b73563 | 2013-03-19 17:38:50 +0000 | [diff] [blame] | 1327 | } | 
| scroggo@google.com | 7d51930 | 2013-03-19 17:28:10 +0000 | [diff] [blame] | 1328 |  | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1329 | // Macro magic to convert a numeric preprocessor token into a string. | 
|  | 1330 | // Adapted from http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string | 
|  | 1331 | // This should probably be moved into one of our common headers... | 
|  | 1332 | #define TOSTRING_INTERNAL(x) #x | 
|  | 1333 | #define TOSTRING(x) TOSTRING_INTERNAL(x) | 
|  | 1334 |  | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1335 | // Alphabetized ignoring "no" prefix ("readPath", "noreplay", "resourcePath"). | 
| scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1336 | DEFINE_string(config, "", configUsage().c_str()); | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1337 | DEFINE_bool(deferred, true, "Exercise the deferred rendering test pass."); | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1338 | DEFINE_string(excludeConfig, "", "Space delimited list of configs to skip."); | 
|  | 1339 | DEFINE_bool(forceBWtext, false, "Disable text anti-aliasing."); | 
|  | 1340 | #if SK_SUPPORT_GPU | 
|  | 1341 | DEFINE_string(gpuCacheSize, "", "<bytes> <count>: Limit the gpu cache to byte size or " | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1342 | "object count. " TOSTRING(DEFAULT_CACHE_VALUE) " for either value means " | 
|  | 1343 | "use the default. 0 for either disables the cache."); | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1344 | #endif | 
|  | 1345 | DEFINE_bool(hierarchy, false, "Whether to use multilevel directory structure " | 
|  | 1346 | "when reading/writing files."); | 
| epoger@google.com | 5079d2c | 2013-04-12 14:11:21 +0000 | [diff] [blame] | 1347 | DEFINE_string(ignoreErrorTypes, kDefaultIgnorableErrorTypes.asString(" ").c_str(), | 
|  | 1348 | "Space-separated list of ErrorTypes that should be ignored. If any *other* error " | 
|  | 1349 | "types are encountered, the tool will exit with a nonzero return value."); | 
| caryclark@google.com | 512c9b6 | 2013-05-10 15:16:13 +0000 | [diff] [blame] | 1350 | DEFINE_string(match, "", "[~][^]substring[$] [...] of test name to run.\n" | 
|  | 1351 | "Multiple matches may be separated by spaces.\n" | 
|  | 1352 | "~ causes a matching test to always be skipped\n" | 
|  | 1353 | "^ requires the start of the test to match\n" | 
|  | 1354 | "$ requires the end of the test to match\n" | 
|  | 1355 | "^ and $ requires an exact match\n" | 
|  | 1356 | "If a test does not match any list entry,\n" | 
|  | 1357 | "it is skipped unless some list entry starts with ~"); | 
| epoger@google.com | 5f99545 | 2013-06-21 18:16:47 +0000 | [diff] [blame] | 1358 | DEFINE_string(missingExpectationsPath, "", "Write images for tests without expectations " | 
|  | 1359 | "into this directory."); | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1360 | DEFINE_string(mismatchPath, "", "Write images for tests that failed due to " | 
|  | 1361 | "pixel mismatches into this directory."); | 
|  | 1362 | DEFINE_string(modulo, "", "[--modulo <remainder> <divisor>]: only run tests for which " | 
|  | 1363 | "testIndex %% divisor == remainder."); | 
|  | 1364 | DEFINE_bool(pdf, true, "Exercise the pdf rendering test pass."); | 
|  | 1365 | DEFINE_bool(pipe, true, "Exercise the SkGPipe replay test pass."); | 
|  | 1366 | DEFINE_string2(readPath, r, "", "Read reference images from this dir, and report " | 
|  | 1367 | "any differences between those and the newly generated ones."); | 
|  | 1368 | DEFINE_bool(replay, true, "Exercise the SkPicture replay test pass."); | 
|  | 1369 | DEFINE_string2(resourcePath, i, "", "Directory that stores image resources."); | 
|  | 1370 | DEFINE_bool(rtree, true, "Exercise the R-Tree variant of SkPicture test pass."); | 
|  | 1371 | DEFINE_bool(serialize, true, "Exercise the SkPicture serialization & deserialization test pass."); | 
| epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 1372 | DEFINE_bool(simulatePipePlaybackFailure, false, "Simulate a rendering failure in pipe mode only."); | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1373 | DEFINE_bool(tiledPipe, false, "Exercise tiled SkGPipe replay."); | 
|  | 1374 | DEFINE_bool(tileGrid, true, "Exercise the tile grid variant of SkPicture."); | 
|  | 1375 | DEFINE_string(tileGridReplayScales, "", "Space separated list of floating-point scale " | 
|  | 1376 | "factors to be used for tileGrid playback testing. Default value: 1.0"); | 
| epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 1377 | DEFINE_bool2(verbose, v, false, "Give more detail (e.g. list all GMs run, more info about " | 
|  | 1378 | "each test)."); | 
| epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 1379 | DEFINE_bool(writeChecksumBasedFilenames, false, "When writing out actual images, use checksum-" | 
|  | 1380 | "based filenames, as rebaseline.py will use when downloading them from Google Storage"); | 
|  | 1381 | DEFINE_string(writeJsonSummaryPath, "", "Write a JSON-formatted result summary to this file."); | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1382 | DEFINE_string2(writePath, w, "",  "Write rendered images into this directory."); | 
| scroggo@google.com | 604e0c2 | 2013-04-09 21:25:46 +0000 | [diff] [blame] | 1383 | DEFINE_string2(writePicturePath, p, "", "Write .skp files into this directory."); | 
| edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 1384 | DEFINE_int32(pdfJpegQuality, -1, "Encodes images in JPEG at quality level N, " | 
|  | 1385 | "which can be in range 0-100). N = -1 will disable JPEG compression. " | 
|  | 1386 | "Default is N = 100, maximum quality."); | 
|  | 1387 |  | 
|  | 1388 | static bool encode_to_dct_stream(SkWStream* stream, const SkBitmap& bitmap, const SkIRect& rect) { | 
|  | 1389 | // Filter output of warnings that JPEG is not available for the image. | 
|  | 1390 | if (bitmap.width() >= 65500 || bitmap.height() >= 65500) return false; | 
|  | 1391 | if (FLAGS_pdfJpegQuality == -1) return false; | 
|  | 1392 |  | 
|  | 1393 | SkIRect bitmapBounds; | 
|  | 1394 | SkBitmap subset; | 
|  | 1395 | const SkBitmap* bitmapToUse = &bitmap; | 
|  | 1396 | bitmap.getBounds(&bitmapBounds); | 
|  | 1397 | if (rect != bitmapBounds) { | 
|  | 1398 | SkAssertResult(bitmap.extractSubset(&subset, rect)); | 
|  | 1399 | bitmapToUse = ⊂ | 
|  | 1400 | } | 
|  | 1401 |  | 
|  | 1402 | #if defined(SK_BUILD_FOR_MAC) | 
|  | 1403 | // Workaround bug #1043 where bitmaps with referenced pixels cause | 
|  | 1404 | // CGImageDestinationFinalize to crash | 
|  | 1405 | SkBitmap copy; | 
|  | 1406 | bitmapToUse->deepCopyTo(©, bitmapToUse->config()); | 
|  | 1407 | bitmapToUse = © | 
|  | 1408 | #endif | 
|  | 1409 |  | 
|  | 1410 | return SkImageEncoder::EncodeStream(stream, | 
|  | 1411 | *bitmapToUse, | 
|  | 1412 | SkImageEncoder::kJPEG_Type, | 
|  | 1413 | FLAGS_pdfJpegQuality); | 
|  | 1414 | } | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1415 |  | 
| scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1416 | static int findConfig(const char config[]) { | 
|  | 1417 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { | 
|  | 1418 | if (!strcmp(config, gRec[i].fName)) { | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1419 | return (int) i; | 
| scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1420 | } | 
|  | 1421 | } | 
|  | 1422 | return -1; | 
|  | 1423 | } | 
|  | 1424 |  | 
| scroggo@google.com | b7dbf63 | 2013-04-23 15:38:09 +0000 | [diff] [blame] | 1425 | static bool skip_name(SkCommandLineFlags::StringArray array, const char name[]) { | 
| caryclark@google.com | 512c9b6 | 2013-05-10 15:16:13 +0000 | [diff] [blame] | 1426 | // FIXME: this duplicates the logic in test/skia_test.cpp -- consolidate | 
|  | 1427 | int count = array.count(); | 
|  | 1428 | size_t testLen = strlen(name); | 
|  | 1429 | bool anyExclude = count == 0; | 
| reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 1430 | for (int i = 0; i < array.count(); ++i) { | 
| caryclark@google.com | 512c9b6 | 2013-05-10 15:16:13 +0000 | [diff] [blame] | 1431 | const char* matchName = array[i]; | 
|  | 1432 | size_t matchLen = strlen(matchName); | 
|  | 1433 | bool matchExclude, matchStart, matchEnd; | 
|  | 1434 | if ((matchExclude = matchName[0] == '~')) { | 
|  | 1435 | anyExclude = true; | 
|  | 1436 | matchName++; | 
|  | 1437 | matchLen--; | 
|  | 1438 | } | 
|  | 1439 | if ((matchStart = matchName[0] == '^')) { | 
|  | 1440 | matchName++; | 
|  | 1441 | matchLen--; | 
|  | 1442 | } | 
|  | 1443 | if ((matchEnd = matchName[matchLen - 1] == '$')) { | 
|  | 1444 | matchLen--; | 
|  | 1445 | } | 
|  | 1446 | if (matchStart ? (!matchEnd || matchLen == testLen) | 
|  | 1447 | && strncmp(name, matchName, matchLen) == 0 | 
|  | 1448 | : matchEnd ? matchLen <= testLen | 
|  | 1449 | && strncmp(name + testLen - matchLen, matchName, matchLen) == 0 | 
|  | 1450 | : strstr(name, matchName) != 0) { | 
|  | 1451 | return matchExclude; | 
| reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 1452 | } | 
|  | 1453 | } | 
| caryclark@google.com | 512c9b6 | 2013-05-10 15:16:13 +0000 | [diff] [blame] | 1454 | return !anyExclude; | 
| reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 1455 | } | 
|  | 1456 |  | 
| bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 1457 | namespace skiagm { | 
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1458 | #if SK_SUPPORT_GPU | 
| bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1459 | SkAutoTUnref<GrContext> gGrContext; | 
|  | 1460 | /** | 
| bsalomon@google.com | c7a24d2 | 2012-11-01 18:03:48 +0000 | [diff] [blame] | 1461 | * Sets the global GrContext, accessible by individual GMs | 
| bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1462 | */ | 
| caryclark@google.com | 1313086 | 2012-06-06 12:10:45 +0000 | [diff] [blame] | 1463 | static void SetGr(GrContext* grContext) { | 
| bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1464 | SkSafeRef(grContext); | 
|  | 1465 | gGrContext.reset(grContext); | 
| bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 1466 | } | 
| bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1467 |  | 
|  | 1468 | /** | 
|  | 1469 | * Gets the global GrContext, can be called by GM tests. | 
|  | 1470 | */ | 
| caryclark@google.com | 1313086 | 2012-06-06 12:10:45 +0000 | [diff] [blame] | 1471 | GrContext* GetGr(); | 
| bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1472 | GrContext* GetGr() { | 
|  | 1473 | return gGrContext.get(); | 
|  | 1474 | } | 
|  | 1475 |  | 
|  | 1476 | /** | 
|  | 1477 | * Sets the global GrContext and then resets it to its previous value at | 
|  | 1478 | * destruction. | 
|  | 1479 | */ | 
|  | 1480 | class AutoResetGr : SkNoncopyable { | 
|  | 1481 | public: | 
|  | 1482 | AutoResetGr() : fOld(NULL) {} | 
|  | 1483 | void set(GrContext* context) { | 
|  | 1484 | SkASSERT(NULL == fOld); | 
|  | 1485 | fOld = GetGr(); | 
|  | 1486 | SkSafeRef(fOld); | 
|  | 1487 | SetGr(context); | 
|  | 1488 | } | 
|  | 1489 | ~AutoResetGr() { SetGr(fOld); SkSafeUnref(fOld); } | 
|  | 1490 | private: | 
|  | 1491 | GrContext* fOld; | 
|  | 1492 | }; | 
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1493 | #else | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1494 | GrContext* GetGr(); | 
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1495 | GrContext* GetGr() { return NULL; } | 
|  | 1496 | #endif | 
| bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 1497 | } | 
|  | 1498 |  | 
| reed@google.com | fb2cd42 | 2013-01-04 14:43:03 +0000 | [diff] [blame] | 1499 | template <typename T> void appendUnique(SkTDArray<T>* array, const T& value) { | 
|  | 1500 | int index = array->find(value); | 
|  | 1501 | if (index < 0) { | 
|  | 1502 | *array->append() = value; | 
|  | 1503 | } | 
|  | 1504 | } | 
|  | 1505 |  | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1506 | /** | 
|  | 1507 | * Run this test in a number of different configs (8888, 565, PDF, | 
|  | 1508 | * etc.), confirming that the resulting bitmaps match expectations | 
|  | 1509 | * (which may be different for each config). | 
|  | 1510 | * | 
|  | 1511 | * Returns all errors encountered while doing so. | 
|  | 1512 | */ | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1513 | ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm, const SkTDArray<size_t> &configs, | 
|  | 1514 | GrContextFactory *grFactory); | 
|  | 1515 | ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm, const SkTDArray<size_t> &configs, | 
|  | 1516 | GrContextFactory *grFactory) { | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1517 | const char renderModeDescriptor[] = ""; | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1518 | ErrorCombination errorsForAllConfigs; | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1519 | uint32_t gmFlags = gm->getFlags(); | 
|  | 1520 |  | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1521 | for (int i = 0; i < configs.count(); i++) { | 
|  | 1522 | ConfigData config = gRec[configs[i]]; | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1523 | const SkString shortNamePlusConfig = gmmain.make_shortname_plus_config(gm->shortName(), | 
|  | 1524 | config.fName); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1525 |  | 
|  | 1526 | // Skip any tests that we don't even need to try. | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1527 | // If any of these were skipped on a per-GM basis, record them as | 
|  | 1528 | // kIntentionallySkipped. | 
|  | 1529 | if (kPDF_Backend == config.fBackend) { | 
|  | 1530 | if (!FLAGS_pdf) { | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1531 | continue; | 
|  | 1532 | } | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1533 | if (gmFlags & GM::kSkipPDF_Flag) { | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1534 | gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1535 | renderModeDescriptor); | 
|  | 1536 | errorsForAllConfigs.add(kIntentionallySkipped_ErrorType); | 
|  | 1537 | continue; | 
|  | 1538 | } | 
|  | 1539 | } | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1540 | if ((gmFlags & GM::kSkip565_Flag) && | 
|  | 1541 | (kRaster_Backend == config.fBackend) && | 
|  | 1542 | (SkBitmap::kRGB_565_Config == config.fConfig)) { | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1543 | gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1544 | renderModeDescriptor); | 
|  | 1545 | errorsForAllConfigs.add(kIntentionallySkipped_ErrorType); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1546 | continue; | 
|  | 1547 | } | 
|  | 1548 | if ((gmFlags & GM::kSkipGPU_Flag) && | 
|  | 1549 | kGPU_Backend == config.fBackend) { | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1550 | gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1551 | renderModeDescriptor); | 
|  | 1552 | errorsForAllConfigs.add(kIntentionallySkipped_ErrorType); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1553 | continue; | 
|  | 1554 | } | 
|  | 1555 |  | 
|  | 1556 | // Now we know that we want to run this test and record its | 
|  | 1557 | // success or failure. | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1558 | ErrorCombination errorsForThisConfig; | 
| bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1559 | GrSurface* gpuTarget = NULL; | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1560 | #if SK_SUPPORT_GPU | 
| bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1561 | SkAutoTUnref<GrSurface> auGpuTarget; | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1562 | AutoResetGr autogr; | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1563 | if ((errorsForThisConfig.isEmpty()) && (kGPU_Backend == config.fBackend)) { | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1564 | GrContext* gr = grFactory->get(config.fGLContextType); | 
|  | 1565 | bool grSuccess = false; | 
|  | 1566 | if (gr) { | 
|  | 1567 | // create a render target to back the device | 
|  | 1568 | GrTextureDesc desc; | 
|  | 1569 | desc.fConfig = kSkia8888_GrPixelConfig; | 
|  | 1570 | desc.fFlags = kRenderTarget_GrTextureFlagBit; | 
|  | 1571 | desc.fWidth = gm->getISize().width(); | 
|  | 1572 | desc.fHeight = gm->getISize().height(); | 
|  | 1573 | desc.fSampleCnt = config.fSampleCnt; | 
| bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1574 | auGpuTarget.reset(gr->createUncachedTexture(desc, NULL, 0)); | 
|  | 1575 | if (NULL != auGpuTarget) { | 
|  | 1576 | gpuTarget = auGpuTarget; | 
|  | 1577 | grSuccess = true; | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1578 | autogr.set(gr); | 
| bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1579 | // Set the user specified cache limits if non-default. | 
|  | 1580 | size_t bytes; | 
|  | 1581 | int count; | 
|  | 1582 | gr->getTextureCacheLimits(&count, &bytes); | 
|  | 1583 | if (DEFAULT_CACHE_VALUE != gGpuCacheSizeBytes) { | 
|  | 1584 | bytes = static_cast<size_t>(gGpuCacheSizeBytes); | 
|  | 1585 | } | 
|  | 1586 | if (DEFAULT_CACHE_VALUE != gGpuCacheSizeCount) { | 
|  | 1587 | count = gGpuCacheSizeCount; | 
|  | 1588 | } | 
|  | 1589 | gr->setTextureCacheLimits(count, bytes); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1590 | } | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1591 | } | 
|  | 1592 | if (!grSuccess) { | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1593 | errorsForThisConfig.add(kNoGpuContext_ErrorType); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1594 | } | 
|  | 1595 | } | 
|  | 1596 | #endif | 
|  | 1597 |  | 
|  | 1598 | SkBitmap comparisonBitmap; | 
|  | 1599 |  | 
|  | 1600 | const char* writePath; | 
|  | 1601 | if (FLAGS_writePath.count() == 1) { | 
|  | 1602 | writePath = FLAGS_writePath[0]; | 
|  | 1603 | } else { | 
|  | 1604 | writePath = NULL; | 
|  | 1605 | } | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1606 | if (errorsForThisConfig.isEmpty()) { | 
| bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1607 | errorsForThisConfig.add(gmmain.test_drawing(gm,config, writePath, gpuTarget, | 
|  | 1608 | &comparisonBitmap)); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1609 | } | 
|  | 1610 |  | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1611 | if (FLAGS_deferred && errorsForThisConfig.isEmpty() && | 
|  | 1612 | (kGPU_Backend == config.fBackend || kRaster_Backend == config.fBackend)) { | 
|  | 1613 | errorsForThisConfig.add(gmmain.test_deferred_drawing(gm, config, comparisonBitmap, | 
| bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1614 | gpuTarget)); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1615 | } | 
|  | 1616 |  | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1617 | errorsForAllConfigs.add(errorsForThisConfig); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1618 | } | 
|  | 1619 | return errorsForAllConfigs; | 
|  | 1620 | } | 
|  | 1621 |  | 
|  | 1622 | /** | 
|  | 1623 | * Run this test in a number of different drawing modes (pipe, | 
|  | 1624 | * deferred, tiled, etc.), confirming that the resulting bitmaps all | 
|  | 1625 | * *exactly* match comparisonBitmap. | 
|  | 1626 | * | 
|  | 1627 | * Returns all errors encountered while doing so. | 
|  | 1628 | */ | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1629 | ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm, const ConfigData &compareConfig, | 
|  | 1630 | const SkBitmap &comparisonBitmap, | 
|  | 1631 | const SkTDArray<SkScalar> &tileGridReplayScales); | 
|  | 1632 | ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm, const ConfigData &compareConfig, | 
|  | 1633 | const SkBitmap &comparisonBitmap, | 
|  | 1634 | const SkTDArray<SkScalar> &tileGridReplayScales) { | 
|  | 1635 | ErrorCombination errorsForAllModes; | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1636 | uint32_t gmFlags = gm->getFlags(); | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1637 | const SkString shortNamePlusConfig = gmmain.make_shortname_plus_config(gm->shortName(), | 
|  | 1638 | compareConfig.fName); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1639 |  | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1640 | SkPicture* pict = gmmain.generate_new_picture(gm, kNone_BbhType, 0); | 
|  | 1641 | SkAutoUnref aur(pict); | 
|  | 1642 | if (FLAGS_replay) { | 
|  | 1643 | const char renderModeDescriptor[] = "-replay"; | 
|  | 1644 | if (gmFlags & GM::kSkipPicture_Flag) { | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1645 | gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, | 
|  | 1646 | renderModeDescriptor); | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1647 | errorsForAllModes.add(kIntentionallySkipped_ErrorType); | 
|  | 1648 | } else { | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1649 | SkBitmap bitmap; | 
|  | 1650 | gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap); | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1651 | errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap( | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1652 | gm->shortName(), compareConfig.fName, renderModeDescriptor, bitmap, | 
|  | 1653 | &comparisonBitmap)); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1654 | } | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1655 | } | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1656 |  | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1657 | if (FLAGS_serialize) { | 
|  | 1658 | const char renderModeDescriptor[] = "-serialize"; | 
|  | 1659 | if (gmFlags & GM::kSkipPicture_Flag) { | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1660 | gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, | 
|  | 1661 | renderModeDescriptor); | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1662 | errorsForAllModes.add(kIntentionallySkipped_ErrorType); | 
|  | 1663 | } else { | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1664 | SkPicture* repict = gmmain.stream_to_new_picture(*pict); | 
|  | 1665 | SkAutoUnref aurr(repict); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1666 | SkBitmap bitmap; | 
|  | 1667 | gmmain.generate_image_from_picture(gm, compareConfig, repict, &bitmap); | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1668 | errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap( | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1669 | gm->shortName(), compareConfig.fName, renderModeDescriptor, bitmap, | 
|  | 1670 | &comparisonBitmap)); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1671 | } | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1672 | } | 
|  | 1673 |  | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1674 | if ((1 == FLAGS_writePicturePath.count()) && | 
|  | 1675 | !(gmFlags & GM::kSkipPicture_Flag)) { | 
|  | 1676 | const char* pictureSuffix = "skp"; | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1677 | // TODO(epoger): Make sure this still works even though the | 
|  | 1678 | // filename now contains the config name (it used to contain | 
|  | 1679 | // just the shortName).  I think this is actually an | 
|  | 1680 | // *improvement*, because now runs with different configs will | 
|  | 1681 | // write out their SkPictures to separate files rather than | 
|  | 1682 | // overwriting each other.  But we should make sure it doesn't | 
|  | 1683 | // break anybody. | 
|  | 1684 | SkString path = gmmain.make_filename(FLAGS_writePicturePath[0], gm->shortName(), | 
|  | 1685 | compareConfig.fName, "", pictureSuffix); | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1686 | SkFILEWStream stream(path.c_str()); | 
|  | 1687 | pict->serialize(&stream); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1688 | } | 
|  | 1689 |  | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1690 | if (FLAGS_rtree) { | 
|  | 1691 | const char renderModeDescriptor[] = "-rtree"; | 
|  | 1692 | if (gmFlags & GM::kSkipPicture_Flag) { | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1693 | gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, | 
|  | 1694 | renderModeDescriptor); | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1695 | errorsForAllModes.add(kIntentionallySkipped_ErrorType); | 
|  | 1696 | } else { | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1697 | SkPicture* pict = gmmain.generate_new_picture( | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1698 | gm, kRTree_BbhType, SkPicture::kUsePathBoundsForClip_RecordingFlag); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1699 | SkAutoUnref aur(pict); | 
|  | 1700 | SkBitmap bitmap; | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1701 | gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap); | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1702 | errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap( | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1703 | gm->shortName(), compareConfig.fName, renderModeDescriptor, bitmap, | 
|  | 1704 | &comparisonBitmap)); | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1705 | } | 
|  | 1706 | } | 
|  | 1707 |  | 
|  | 1708 | if (FLAGS_tileGrid) { | 
|  | 1709 | for(int scaleIndex = 0; scaleIndex < tileGridReplayScales.count(); ++scaleIndex) { | 
|  | 1710 | SkScalar replayScale = tileGridReplayScales[scaleIndex]; | 
|  | 1711 | SkString renderModeDescriptor("-tilegrid"); | 
|  | 1712 | if (SK_Scalar1 != replayScale) { | 
|  | 1713 | renderModeDescriptor += "-scale-"; | 
|  | 1714 | renderModeDescriptor.appendScalar(replayScale); | 
|  | 1715 | } | 
|  | 1716 |  | 
|  | 1717 | if ((gmFlags & GM::kSkipPicture_Flag) || | 
|  | 1718 | ((gmFlags & GM::kSkipScaledReplay_Flag) && replayScale != 1)) { | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1719 | gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1720 | renderModeDescriptor.c_str()); | 
|  | 1721 | errorsForAllModes.add(kIntentionallySkipped_ErrorType); | 
|  | 1722 | } else { | 
|  | 1723 | // We record with the reciprocal scale to obtain a replay | 
|  | 1724 | // result that can be validated against comparisonBitmap. | 
|  | 1725 | SkScalar recordScale = SkScalarInvert(replayScale); | 
|  | 1726 | SkPicture* pict = gmmain.generate_new_picture( | 
|  | 1727 | gm, kTileGrid_BbhType, SkPicture::kUsePathBoundsForClip_RecordingFlag, | 
|  | 1728 | recordScale); | 
|  | 1729 | SkAutoUnref aur(pict); | 
|  | 1730 | SkBitmap bitmap; | 
|  | 1731 | // We cannot yet pass 'true' to generate_image_from_picture to | 
|  | 1732 | // perform actual tiled rendering (see Issue 1198 - | 
|  | 1733 | // https://code.google.com/p/skia/issues/detail?id=1198) | 
|  | 1734 | gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap, | 
|  | 1735 | replayScale /*, true */); | 
|  | 1736 | errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap( | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1737 | gm->shortName(), compareConfig.fName, renderModeDescriptor.c_str(), bitmap, | 
|  | 1738 | &comparisonBitmap)); | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1739 | } | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1740 | } | 
|  | 1741 | } | 
|  | 1742 |  | 
|  | 1743 | // run the pipe centric GM steps | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1744 | if (FLAGS_pipe) { | 
|  | 1745 | errorsForAllModes.add(gmmain.test_pipe_playback(gm, compareConfig, comparisonBitmap, | 
|  | 1746 | FLAGS_simulatePipePlaybackFailure)); | 
|  | 1747 | if (FLAGS_tiledPipe) { | 
|  | 1748 | errorsForAllModes.add(gmmain.test_tiled_pipe_playback(gm, compareConfig, | 
|  | 1749 | comparisonBitmap)); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1750 | } | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1751 | } | 
|  | 1752 | return errorsForAllModes; | 
|  | 1753 | } | 
|  | 1754 |  | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 1755 | /** | 
|  | 1756 | * Return a list of all entries in an array of strings as a single string | 
|  | 1757 | * of this form: | 
|  | 1758 | * "item1", "item2", "item3" | 
|  | 1759 | */ | 
|  | 1760 | SkString list_all(const SkTArray<SkString> &stringArray); | 
|  | 1761 | SkString list_all(const SkTArray<SkString> &stringArray) { | 
|  | 1762 | SkString total; | 
|  | 1763 | for (int i = 0; i < stringArray.count(); i++) { | 
|  | 1764 | if (i > 0) { | 
|  | 1765 | total.append(", "); | 
|  | 1766 | } | 
|  | 1767 | total.append("\""); | 
|  | 1768 | total.append(stringArray[i]); | 
|  | 1769 | total.append("\""); | 
|  | 1770 | } | 
|  | 1771 | return total; | 
|  | 1772 | } | 
|  | 1773 |  | 
|  | 1774 | /** | 
|  | 1775 | * Return a list of configuration names, as a single string of this form: | 
|  | 1776 | * "item1", "item2", "item3" | 
|  | 1777 | * | 
|  | 1778 | * @param configs configurations, as a list of indices into gRec | 
|  | 1779 | */ | 
|  | 1780 | SkString list_all_config_names(const SkTDArray<size_t> &configs); | 
|  | 1781 | SkString list_all_config_names(const SkTDArray<size_t> &configs) { | 
|  | 1782 | SkString total; | 
|  | 1783 | for (int i = 0; i < configs.count(); i++) { | 
|  | 1784 | if (i > 0) { | 
|  | 1785 | total.append(", "); | 
|  | 1786 | } | 
|  | 1787 | total.append("\""); | 
|  | 1788 | total.append(gRec[configs[i]].fName); | 
|  | 1789 | total.append("\""); | 
|  | 1790 | } | 
|  | 1791 | return total; | 
|  | 1792 | } | 
|  | 1793 |  | 
| epoger@google.com | fdea325 | 2013-05-02 18:24:03 +0000 | [diff] [blame] | 1794 | bool prepare_subdirectories(const char *root, bool useFileHierarchy, | 
|  | 1795 | const SkTDArray<size_t> &configs); | 
|  | 1796 | bool prepare_subdirectories(const char *root, bool useFileHierarchy, | 
|  | 1797 | const SkTDArray<size_t> &configs) { | 
|  | 1798 | if (!sk_mkdir(root)) { | 
|  | 1799 | return false; | 
|  | 1800 | } | 
|  | 1801 | if (useFileHierarchy) { | 
|  | 1802 | for (int i = 0; i < configs.count(); i++) { | 
|  | 1803 | ConfigData config = gRec[configs[i]]; | 
|  | 1804 | SkString subdir; | 
|  | 1805 | subdir.appendf("%s%c%s", root, SkPATH_SEPARATOR, config.fName); | 
|  | 1806 | if (!sk_mkdir(subdir.c_str())) { | 
|  | 1807 | return false; | 
|  | 1808 | } | 
|  | 1809 | } | 
|  | 1810 | } | 
|  | 1811 | return true; | 
|  | 1812 | } | 
|  | 1813 |  | 
| epoger@google.com | 0b62b3d | 2013-03-20 17:59:28 +0000 | [diff] [blame] | 1814 | int tool_main(int argc, char** argv); | 
|  | 1815 | int tool_main(int argc, char** argv) { | 
|  | 1816 |  | 
|  | 1817 | #if SK_ENABLE_INST_COUNT | 
|  | 1818 | gPrintInstCount = true; | 
|  | 1819 | #endif | 
|  | 1820 |  | 
|  | 1821 | SkGraphics::Init(); | 
|  | 1822 | // we don't need to see this during a run | 
|  | 1823 | gSkSuppressFontCachePurgeSpew = true; | 
|  | 1824 |  | 
|  | 1825 | setSystemPreferences(); | 
|  | 1826 | GMMain gmmain; | 
|  | 1827 |  | 
|  | 1828 | SkTDArray<size_t> configs; | 
|  | 1829 | SkTDArray<size_t> excludeConfigs; | 
|  | 1830 | bool userConfig = false; | 
|  | 1831 |  | 
|  | 1832 | SkString usage; | 
|  | 1833 | usage.printf("Run the golden master tests.\n"); | 
| scroggo@google.com | d9ba9a0 | 2013-03-21 19:43:15 +0000 | [diff] [blame] | 1834 | SkCommandLineFlags::SetUsage(usage.c_str()); | 
|  | 1835 | SkCommandLineFlags::Parse(argc, argv); | 
| epoger@google.com | 0b62b3d | 2013-03-20 17:59:28 +0000 | [diff] [blame] | 1836 |  | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1837 | gmmain.fUseFileHierarchy = FLAGS_hierarchy; | 
| epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 1838 | gmmain.fWriteChecksumBasedFilenames = FLAGS_writeChecksumBasedFilenames; | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1839 | if (FLAGS_mismatchPath.count() == 1) { | 
|  | 1840 | gmmain.fMismatchPath = FLAGS_mismatchPath[0]; | 
|  | 1841 | } | 
| epoger@google.com | 5f99545 | 2013-06-21 18:16:47 +0000 | [diff] [blame] | 1842 | if (FLAGS_missingExpectationsPath.count() == 1) { | 
|  | 1843 | gmmain.fMissingExpectationsPath = FLAGS_missingExpectationsPath[0]; | 
|  | 1844 | } | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1845 |  | 
|  | 1846 | for (int i = 0; i < FLAGS_config.count(); i++) { | 
| bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1847 | const char* config = FLAGS_config[i]; | 
|  | 1848 | userConfig = true; | 
|  | 1849 | bool exclude = false; | 
|  | 1850 | if (*config == kExcludeConfigChar) { | 
|  | 1851 | exclude = true; | 
|  | 1852 | config += 1; | 
|  | 1853 | } | 
|  | 1854 | int index = findConfig(config); | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1855 | if (index >= 0) { | 
| bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1856 | if (exclude) { | 
|  | 1857 | *excludeConfigs.append() = index; | 
|  | 1858 | } else { | 
|  | 1859 | appendUnique<size_t>(&configs, index); | 
|  | 1860 | } | 
|  | 1861 | } else if (0 == strcmp(kDefaultsConfigStr, config)) { | 
|  | 1862 | for (size_t c = 0; c < SK_ARRAY_COUNT(gRec); ++c) { | 
|  | 1863 | if (gRec[c].fRunByDefault) { | 
|  | 1864 | if (exclude) { | 
|  | 1865 | gm_fprintf(stderr, "%c%s is not allowed.\n", | 
|  | 1866 | kExcludeConfigChar, kDefaultsConfigStr); | 
|  | 1867 | return -1; | 
|  | 1868 | } else { | 
|  | 1869 | appendUnique<size_t>(&configs, c); | 
|  | 1870 | } | 
|  | 1871 | } | 
|  | 1872 | } | 
| scroggo@google.com | 0b73563 | 2013-03-19 17:38:50 +0000 | [diff] [blame] | 1873 | } else { | 
| bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1874 | gm_fprintf(stderr, "unrecognized config %s\n", config); | 
| scroggo@google.com | 7d51930 | 2013-03-19 17:28:10 +0000 | [diff] [blame] | 1875 | return -1; | 
|  | 1876 | } | 
|  | 1877 | } | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1878 |  | 
|  | 1879 | for (int i = 0; i < FLAGS_excludeConfig.count(); i++) { | 
|  | 1880 | int index = findConfig(FLAGS_excludeConfig[i]); | 
|  | 1881 | if (index >= 0) { | 
|  | 1882 | *excludeConfigs.append() = index; | 
|  | 1883 | } else { | 
|  | 1884 | gm_fprintf(stderr, "unrecognized excludeConfig %s\n", FLAGS_excludeConfig[i]); | 
|  | 1885 | return -1; | 
|  | 1886 | } | 
|  | 1887 | } | 
|  | 1888 |  | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1889 | int moduloRemainder = -1; | 
|  | 1890 | int moduloDivisor = -1; | 
|  | 1891 |  | 
|  | 1892 | if (FLAGS_modulo.count() == 2) { | 
|  | 1893 | moduloRemainder = atoi(FLAGS_modulo[0]); | 
|  | 1894 | moduloDivisor = atoi(FLAGS_modulo[1]); | 
|  | 1895 | if (moduloRemainder < 0 || moduloDivisor <= 0 || moduloRemainder >= moduloDivisor) { | 
|  | 1896 | gm_fprintf(stderr, "invalid modulo values."); | 
|  | 1897 | return -1; | 
|  | 1898 | } | 
| tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1899 | } | 
| reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 1900 |  | 
| epoger@google.com | 5079d2c | 2013-04-12 14:11:21 +0000 | [diff] [blame] | 1901 | if (FLAGS_ignoreErrorTypes.count() > 0) { | 
|  | 1902 | gmmain.fIgnorableErrorTypes = ErrorCombination(); | 
|  | 1903 | for (int i = 0; i < FLAGS_ignoreErrorTypes.count(); i++) { | 
|  | 1904 | ErrorType type; | 
|  | 1905 | const char *name = FLAGS_ignoreErrorTypes[i]; | 
|  | 1906 | if (!getErrorTypeByName(name, &type)) { | 
|  | 1907 | gm_fprintf(stderr, "cannot find ErrorType with name '%s'\n", name); | 
|  | 1908 | return -1; | 
|  | 1909 | } else { | 
|  | 1910 | gmmain.fIgnorableErrorTypes.add(type); | 
|  | 1911 | } | 
|  | 1912 | } | 
|  | 1913 | } | 
|  | 1914 |  | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1915 | #if SK_SUPPORT_GPU | 
|  | 1916 | if (FLAGS_gpuCacheSize.count() > 0) { | 
|  | 1917 | if (FLAGS_gpuCacheSize.count() != 2) { | 
|  | 1918 | gm_fprintf(stderr, "--gpuCacheSize requires two arguments\n"); | 
|  | 1919 | return -1; | 
|  | 1920 | } | 
|  | 1921 | gGpuCacheSizeBytes = atoi(FLAGS_gpuCacheSize[0]); | 
|  | 1922 | gGpuCacheSizeCount = atoi(FLAGS_gpuCacheSize[1]); | 
|  | 1923 | } else { | 
|  | 1924 | gGpuCacheSizeBytes = DEFAULT_CACHE_VALUE; | 
|  | 1925 | gGpuCacheSizeCount = DEFAULT_CACHE_VALUE; | 
|  | 1926 | } | 
|  | 1927 | #endif | 
|  | 1928 |  | 
|  | 1929 | SkTDArray<SkScalar> tileGridReplayScales; | 
|  | 1930 | *tileGridReplayScales.append() = SK_Scalar1; // By default only test at scale 1.0 | 
|  | 1931 | if (FLAGS_tileGridReplayScales.count() > 0) { | 
|  | 1932 | tileGridReplayScales.reset(); | 
|  | 1933 | for (int i = 0; i < FLAGS_tileGridReplayScales.count(); i++) { | 
|  | 1934 | double val = atof(FLAGS_tileGridReplayScales[i]); | 
|  | 1935 | if (0 < val) { | 
|  | 1936 | *tileGridReplayScales.append() = SkDoubleToScalar(val); | 
|  | 1937 | } | 
|  | 1938 | } | 
|  | 1939 | if (0 == tileGridReplayScales.count()) { | 
|  | 1940 | // Should have at least one scale | 
|  | 1941 | gm_fprintf(stderr, "--tileGridReplayScales requires at least one scale.\n"); | 
|  | 1942 | return -1; | 
|  | 1943 | } | 
|  | 1944 | } | 
|  | 1945 |  | 
| scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1946 | if (!userConfig) { | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1947 | // if no config is specified by user, add the defaults | 
| scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1948 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1949 | if (gRec[i].fRunByDefault) { | 
|  | 1950 | *configs.append() = i; | 
|  | 1951 | } | 
| scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1952 | } | 
|  | 1953 | } | 
| reed@google.com | fb2cd42 | 2013-01-04 14:43:03 +0000 | [diff] [blame] | 1954 | // now remove any explicitly excluded configs | 
|  | 1955 | for (int i = 0; i < excludeConfigs.count(); ++i) { | 
|  | 1956 | int index = configs.find(excludeConfigs[i]); | 
|  | 1957 | if (index >= 0) { | 
|  | 1958 | configs.remove(index); | 
|  | 1959 | // now assert that there was only one copy in configs[] | 
|  | 1960 | SkASSERT(configs.find(excludeConfigs[i]) < 0); | 
|  | 1961 | } | 
|  | 1962 | } | 
|  | 1963 |  | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1964 | #if SK_SUPPORT_GPU | 
|  | 1965 | GrContextFactory* grFactory = new GrContextFactory; | 
|  | 1966 | for (int i = 0; i < configs.count(); ++i) { | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1967 | size_t index = configs[i]; | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1968 | if (kGPU_Backend == gRec[index].fBackend) { | 
|  | 1969 | GrContext* ctx = grFactory->get(gRec[index].fGLContextType); | 
|  | 1970 | if (NULL == ctx) { | 
| epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 1971 | gm_fprintf(stderr, "GrContext could not be created for config %s." | 
|  | 1972 | " Config will be skipped.\n", gRec[index].fName); | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1973 | configs.remove(i); | 
|  | 1974 | --i; | 
| bsalomon@google.com | 42db2e4 | 2013-06-11 19:22:44 +0000 | [diff] [blame] | 1975 | continue; | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1976 | } | 
|  | 1977 | if (gRec[index].fSampleCnt > ctx->getMaxSampleCount()) { | 
| epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 1978 | gm_fprintf(stderr, "Sample count (%d) of config %s is not supported." | 
|  | 1979 | " Config will be skipped.\n", gRec[index].fSampleCnt, gRec[index].fName); | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1980 | configs.remove(i); | 
|  | 1981 | --i; | 
|  | 1982 | } | 
|  | 1983 | } | 
|  | 1984 | } | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1985 | #else | 
|  | 1986 | GrContextFactory* grFactory = NULL; | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1987 | #endif | 
|  | 1988 |  | 
| bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1989 | if (configs.isEmpty()) { | 
|  | 1990 | gm_fprintf(stderr, "No configs to run."); | 
|  | 1991 | return -1; | 
|  | 1992 | } | 
|  | 1993 |  | 
|  | 1994 | // now show the user the set of configs that will be run. | 
|  | 1995 | SkString configStr("These configs will be run: "); | 
|  | 1996 | // show the user the config that will run. | 
|  | 1997 | for (int i = 0; i < configs.count(); ++i) { | 
|  | 1998 | configStr.appendf("%s%s", gRec[configs[i]].fName, (i == configs.count() - 1) ? "\n" : " "); | 
|  | 1999 | } | 
|  | 2000 | gm_fprintf(stdout, "%s", configStr.c_str()); | 
|  | 2001 |  | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 2002 | if (FLAGS_resourcePath.count() == 1) { | 
|  | 2003 | GM::SetResourcePath(FLAGS_resourcePath[0]); | 
|  | 2004 | } | 
| robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 2005 |  | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 2006 | if (FLAGS_readPath.count() == 1) { | 
|  | 2007 | const char* readPath = FLAGS_readPath[0]; | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 2008 | if (!sk_exists(readPath)) { | 
| epoger@google.com | 5efdd0c | 2013-03-13 14:18:40 +0000 | [diff] [blame] | 2009 | gm_fprintf(stderr, "readPath %s does not exist!\n", readPath); | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 2010 | return -1; | 
|  | 2011 | } | 
|  | 2012 | if (sk_isdir(readPath)) { | 
| epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 2013 | if (FLAGS_verbose) { | 
|  | 2014 | gm_fprintf(stdout, "reading from %s\n", readPath); | 
|  | 2015 | } | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 2016 | gmmain.fExpectationsSource.reset(SkNEW_ARGS( | 
| epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 2017 | IndividualImageExpectationsSource, (readPath))); | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 2018 | } else { | 
| epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 2019 | if (FLAGS_verbose) { | 
|  | 2020 | gm_fprintf(stdout, "reading expectations from JSON summary file %s\n", readPath); | 
|  | 2021 | } | 
| epoger@google.com | d271d24 | 2013-02-13 18:14:48 +0000 | [diff] [blame] | 2022 | gmmain.fExpectationsSource.reset(SkNEW_ARGS( | 
|  | 2023 | JsonExpectationsSource, (readPath))); | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 2024 | } | 
| chudy@google.com | f32f6e8 | 2012-07-12 15:42:37 +0000 | [diff] [blame] | 2025 | } | 
| epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 2026 | if (FLAGS_verbose) { | 
|  | 2027 | if (FLAGS_writePath.count() == 1) { | 
|  | 2028 | gm_fprintf(stdout, "writing to %s\n", FLAGS_writePath[0]); | 
|  | 2029 | } | 
| epoger@google.com | fdea325 | 2013-05-02 18:24:03 +0000 | [diff] [blame] | 2030 | if (NULL != gmmain.fMismatchPath) { | 
|  | 2031 | gm_fprintf(stdout, "writing mismatches to %s\n", gmmain.fMismatchPath); | 
|  | 2032 | } | 
| epoger@google.com | 5f99545 | 2013-06-21 18:16:47 +0000 | [diff] [blame] | 2033 | if (NULL != gmmain.fMissingExpectationsPath) { | 
|  | 2034 | gm_fprintf(stdout, "writing images without expectations to %s\n", | 
|  | 2035 | gmmain.fMissingExpectationsPath); | 
|  | 2036 | } | 
| epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 2037 | if (FLAGS_writePicturePath.count() == 1) { | 
|  | 2038 | gm_fprintf(stdout, "writing pictures to %s\n", FLAGS_writePicturePath[0]); | 
|  | 2039 | } | 
|  | 2040 | if (FLAGS_resourcePath.count() == 1) { | 
|  | 2041 | gm_fprintf(stdout, "reading resources from %s\n", FLAGS_resourcePath[0]); | 
|  | 2042 | } | 
| robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 2043 | } | 
|  | 2044 |  | 
| epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 2045 | if (moduloDivisor <= 0) { | 
|  | 2046 | moduloRemainder = -1; | 
| reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 2047 | } | 
| epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 2048 | if (moduloRemainder < 0 || moduloRemainder >= moduloDivisor) { | 
|  | 2049 | moduloRemainder = -1; | 
| reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 2050 | } | 
|  | 2051 |  | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 2052 | int gmsRun = 0; | 
| reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 2053 | int gmIndex = -1; | 
|  | 2054 | SkString moduloStr; | 
|  | 2055 |  | 
| epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 2056 | // If we will be writing out files, prepare subdirectories. | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 2057 | if (FLAGS_writePath.count() == 1) { | 
| epoger@google.com | fdea325 | 2013-05-02 18:24:03 +0000 | [diff] [blame] | 2058 | if (!prepare_subdirectories(FLAGS_writePath[0], gmmain.fUseFileHierarchy, configs)) { | 
| epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 2059 | return -1; | 
|  | 2060 | } | 
| epoger@google.com | fdea325 | 2013-05-02 18:24:03 +0000 | [diff] [blame] | 2061 | } | 
|  | 2062 | if (NULL != gmmain.fMismatchPath) { | 
|  | 2063 | if (!prepare_subdirectories(gmmain.fMismatchPath, gmmain.fUseFileHierarchy, configs)) { | 
|  | 2064 | return -1; | 
| epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 2065 | } | 
|  | 2066 | } | 
| epoger@google.com | 5f99545 | 2013-06-21 18:16:47 +0000 | [diff] [blame] | 2067 | if (NULL != gmmain.fMissingExpectationsPath) { | 
|  | 2068 | if (!prepare_subdirectories(gmmain.fMissingExpectationsPath, gmmain.fUseFileHierarchy, | 
|  | 2069 | configs)) { | 
|  | 2070 | return -1; | 
|  | 2071 | } | 
|  | 2072 | } | 
| epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 2073 |  | 
| edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 2074 | if (FLAGS_pdfJpegQuality < -1 || FLAGS_pdfJpegQuality > 100) { | 
|  | 2075 | gm_fprintf(stderr, "%s\n", "pdfJpegQuality must be in [-1 .. 100] range."); | 
|  | 2076 | } | 
|  | 2077 |  | 
| bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 2078 | Iter iter; | 
|  | 2079 | GM* gm; | 
| reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 2080 | while ((gm = iter.next()) != NULL) { | 
| scroggo@google.com | 7fd2d70 | 2013-04-16 19:11:14 +0000 | [diff] [blame] | 2081 | SkAutoTDelete<GM> adgm(gm); | 
| reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 2082 | ++gmIndex; | 
| epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 2083 | if (moduloRemainder >= 0) { | 
|  | 2084 | if ((gmIndex % moduloDivisor) != moduloRemainder) { | 
| reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 2085 | continue; | 
|  | 2086 | } | 
| epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 2087 | moduloStr.printf("[%d.%d] ", gmIndex, moduloDivisor); | 
| reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 2088 | } | 
|  | 2089 |  | 
| reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 2090 | const char* shortName = gm->shortName(); | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 2091 | if (skip_name(FLAGS_match, shortName)) { | 
| reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 2092 | continue; | 
|  | 2093 | } | 
|  | 2094 |  | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 2095 | gmsRun++; | 
| tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 2096 | SkISize size = gm->getISize(); | 
| epoger@google.com | bcbf5aa | 2013-04-12 02:11:54 +0000 | [diff] [blame] | 2097 | gm_fprintf(stdout, "%sdrawing... %s [%d %d]\n", moduloStr.c_str(), shortName, | 
|  | 2098 | size.width(), size.height()); | 
| djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 2099 |  | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 2100 | run_multiple_configs(gmmain, gm, configs, grFactory); | 
| djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 2101 |  | 
|  | 2102 | SkBitmap comparisonBitmap; | 
|  | 2103 | const ConfigData compareConfig = | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 2104 | { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "comparison", false }; | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 2105 | gmmain.generate_image(gm, compareConfig, NULL, &comparisonBitmap, false); | 
| djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 2106 |  | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 2107 | // TODO(epoger): only run this if gmmain.generate_image() succeeded? | 
|  | 2108 | // Otherwise, what are we comparing against? | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 2109 | run_multiple_modes(gmmain, gm, compareConfig, comparisonBitmap, tileGridReplayScales); | 
| reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 2110 | } | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 2111 |  | 
|  | 2112 | SkTArray<SkString> modes; | 
|  | 2113 | gmmain.GetRenderModesEncountered(modes); | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 2114 | bool reportError = false; | 
|  | 2115 | if (gmmain.NumSignificantErrors() > 0) { | 
|  | 2116 | reportError = true; | 
|  | 2117 | } | 
| epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame] | 2118 | int expectedNumberOfTests = gmsRun * (configs.count() + modes.count()); | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 2119 |  | 
|  | 2120 | // Output summary to stdout. | 
| epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame] | 2121 | if (FLAGS_verbose) { | 
|  | 2122 | gm_fprintf(stdout, "Ran %d GMs\n", gmsRun); | 
|  | 2123 | gm_fprintf(stdout, "... over %2d configs [%s]\n", configs.count(), | 
|  | 2124 | list_all_config_names(configs).c_str()); | 
|  | 2125 | gm_fprintf(stdout, "...  and %2d modes   [%s]\n", modes.count(), list_all(modes).c_str()); | 
|  | 2126 | gm_fprintf(stdout, "... so there should be a total of %d tests.\n", expectedNumberOfTests); | 
|  | 2127 | } | 
|  | 2128 | gmmain.ListErrors(FLAGS_verbose); | 
| robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 2129 |  | 
| epoger@google.com | 07947d9 | 2013-04-11 15:41:02 +0000 | [diff] [blame] | 2130 | // TODO(epoger): Enable this check for Android, too, once we resolve | 
|  | 2131 | // https://code.google.com/p/skia/issues/detail?id=1222 | 
|  | 2132 | // ('GM is unexpectedly skipping tests on Android') | 
|  | 2133 | #ifndef SK_BUILD_FOR_ANDROID | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 2134 | if (expectedNumberOfTests != gmmain.fTestsRun) { | 
|  | 2135 | gm_fprintf(stderr, "expected %d tests, but ran or skipped %d tests\n", | 
|  | 2136 | expectedNumberOfTests, gmmain.fTestsRun); | 
|  | 2137 | reportError = true; | 
|  | 2138 | } | 
|  | 2139 | #endif | 
|  | 2140 |  | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 2141 | if (FLAGS_writeJsonSummaryPath.count() == 1) { | 
| epoger@google.com | 76c913d | 2013-04-26 15:06:44 +0000 | [diff] [blame] | 2142 | Json::Value root = CreateJsonTree( | 
|  | 2143 | gmmain.fJsonExpectedResults, | 
|  | 2144 | gmmain.fJsonActualResults_Failed, gmmain.fJsonActualResults_FailureIgnored, | 
|  | 2145 | gmmain.fJsonActualResults_NoComparison, gmmain.fJsonActualResults_Succeeded); | 
| epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 2146 | std::string jsonStdString = root.toStyledString(); | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 2147 | SkFILEWStream stream(FLAGS_writeJsonSummaryPath[0]); | 
| epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 2148 | stream.write(jsonStdString.c_str(), jsonStdString.length()); | 
|  | 2149 | } | 
|  | 2150 |  | 
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 2151 | #if SK_SUPPORT_GPU | 
| robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 2152 |  | 
| robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 2153 | #if GR_CACHE_STATS | 
| robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 2154 | for (int i = 0; i < configs.count(); i++) { | 
|  | 2155 | ConfigData config = gRec[configs[i]]; | 
|  | 2156 |  | 
| epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 2157 | if (FLAGS_verbose && (kGPU_Backend == config.fBackend)) { | 
| robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 2158 | GrContext* gr = grFactory->get(config.fGLContextType); | 
|  | 2159 |  | 
| epoger@google.com | 5efdd0c | 2013-03-13 14:18:40 +0000 | [diff] [blame] | 2160 | gm_fprintf(stdout, "config: %s %x\n", config.fName, gr); | 
| robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 2161 | gr->printCacheStats(); | 
|  | 2162 | } | 
|  | 2163 | } | 
|  | 2164 | #endif | 
|  | 2165 |  | 
| robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 2166 | delete grFactory; | 
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 2167 | #endif | 
| robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 2168 | SkGraphics::Term(); | 
|  | 2169 |  | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 2170 | return (reportError) ? -1 : 0; | 
| reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 2171 | } | 
| caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 2172 |  | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 2173 | void GMMain::installFilter(SkCanvas* canvas) { | 
|  | 2174 | if (FLAGS_forceBWtext) { | 
|  | 2175 | canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); | 
|  | 2176 | } | 
|  | 2177 | } | 
|  | 2178 |  | 
| borenet@google.com | 7158e6a | 2012-11-01 17:43:44 +0000 | [diff] [blame] | 2179 | #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 
| caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 2180 | int main(int argc, char * const argv[]) { | 
|  | 2181 | return tool_main(argc, (char**) argv); | 
|  | 2182 | } | 
|  | 2183 | #endif |