| 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}, | 
| robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame^] | 1261 |     /* The gpunull context does the least amount of work possible and doesn't | 
 | 1262 |        generate meaninful images, so don't record them!. It can be run to | 
 | 1263 |        isolate the CPU-side processing expense from the GPU-side. | 
 | 1264 |       */ | 
 | 1265 |     { SkBitmap::kARGB_8888_Config, kGPU_Backend,    GrContextFactory::kNull_GLContextType,    0, kNone_ConfigFlag,  "gpunull",      GR_DEBUG}, | 
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1266 | #if SK_ANGLE | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1267 |     { SkBitmap::kARGB_8888_Config, kGPU_Backend,    GrContextFactory::kANGLE_GLContextType,   0, kRW_ConfigFlag,    "angle",        true }, | 
 | 1268 |     { 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] | 1269 | #endif // SK_ANGLE | 
 | 1270 | #ifdef SK_MESA | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1271 |     { 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] | 1272 | #endif // SK_MESA | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1273 | #endif // SK_SUPPORT_GPU | 
| bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1274 | #ifdef SK_SUPPORT_XPS | 
| bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1275 |     /* 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] | 1276 |     { 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] | 1277 | #endif // SK_SUPPORT_XPS | 
| bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1278 | #ifdef SK_SUPPORT_PDF | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1279 |     { 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] | 1280 | #endif // SK_SUPPORT_PDF | 
| reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1281 | }; | 
 | 1282 |  | 
| bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1283 | static const char kDefaultsConfigStr[] = "defaults"; | 
 | 1284 | static const char kExcludeConfigChar = '~'; | 
 | 1285 |  | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1286 | static SkString configUsage() { | 
| scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1287 |     SkString result; | 
 | 1288 |     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] | 1289 |     for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { | 
| bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1290 |         SkASSERT(gRec[i].fName != kDefaultsConfigStr); | 
| scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1291 |         if (i > 0) { | 
| scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1292 |             result.append("|"); | 
| scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1293 |         } | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1294 |         result.appendf("%s", gRec[i].fName); | 
| scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1295 |     } | 
| scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1296 |     result.append("]\n"); | 
 | 1297 |     result.appendf("The default value is: \""); | 
| bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1298 |     SkString firstDefault; | 
 | 1299 |     SkString allButFirstDefaults; | 
 | 1300 |     SkString nonDefault; | 
| scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1301 |     for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { | 
 | 1302 |         if (gRec[i].fRunByDefault) { | 
 | 1303 |             if (i > 0) { | 
 | 1304 |                 result.append(" "); | 
 | 1305 |             } | 
| bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1306 |             result.append(gRec[i].fName); | 
 | 1307 |             if (firstDefault.isEmpty()) { | 
 | 1308 |                 firstDefault = gRec[i].fName; | 
 | 1309 |             } else { | 
 | 1310 |                 if (!allButFirstDefaults.isEmpty()) { | 
 | 1311 |                     allButFirstDefaults.append(" "); | 
 | 1312 |                 } | 
 | 1313 |                 allButFirstDefaults.append(gRec[i].fName); | 
 | 1314 |             } | 
 | 1315 |         } else { | 
 | 1316 |             nonDefault = gRec[i].fName; | 
| scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1317 |         } | 
 | 1318 |     } | 
| bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1319 |     result.append("\"\n"); | 
 | 1320 |     result.appendf("\"%s\" evaluates to the default set of configs.\n", kDefaultsConfigStr); | 
 | 1321 |     result.appendf("Prepending \"%c\" on a config name excludes it from the set of configs to run.\n" | 
 | 1322 |                    "Exclusions always override inclusions regardless of order.\n", | 
 | 1323 |                    kExcludeConfigChar); | 
 | 1324 |     result.appendf("E.g. \"--config %s %c%s %s\" will run these configs:\n\t%s %s", | 
 | 1325 |                    kDefaultsConfigStr, | 
 | 1326 |                    kExcludeConfigChar, | 
 | 1327 |                    firstDefault.c_str(), | 
 | 1328 |                    nonDefault.c_str(), | 
 | 1329 |                    allButFirstDefaults.c_str(), | 
 | 1330 |                    nonDefault.c_str()); | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1331 |     return result; | 
| scroggo@google.com | 0b73563 | 2013-03-19 17:38:50 +0000 | [diff] [blame] | 1332 | } | 
| scroggo@google.com | 7d51930 | 2013-03-19 17:28:10 +0000 | [diff] [blame] | 1333 |  | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1334 | // Macro magic to convert a numeric preprocessor token into a string. | 
 | 1335 | // Adapted from http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string | 
 | 1336 | // This should probably be moved into one of our common headers... | 
 | 1337 | #define TOSTRING_INTERNAL(x) #x | 
 | 1338 | #define TOSTRING(x) TOSTRING_INTERNAL(x) | 
 | 1339 |  | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1340 | // Alphabetized ignoring "no" prefix ("readPath", "noreplay", "resourcePath"). | 
| scroggo@google.com | 0f567c6 | 2013-03-20 15:35:08 +0000 | [diff] [blame] | 1341 | DEFINE_string(config, "", configUsage().c_str()); | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1342 | DEFINE_bool(deferred, true, "Exercise the deferred rendering test pass."); | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1343 | DEFINE_string(excludeConfig, "", "Space delimited list of configs to skip."); | 
 | 1344 | DEFINE_bool(forceBWtext, false, "Disable text anti-aliasing."); | 
 | 1345 | #if SK_SUPPORT_GPU | 
 | 1346 | 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] | 1347 |               "object count. " TOSTRING(DEFAULT_CACHE_VALUE) " for either value means " | 
 | 1348 |               "use the default. 0 for either disables the cache."); | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1349 | #endif | 
 | 1350 | DEFINE_bool(hierarchy, false, "Whether to use multilevel directory structure " | 
 | 1351 |             "when reading/writing files."); | 
| epoger@google.com | 5079d2c | 2013-04-12 14:11:21 +0000 | [diff] [blame] | 1352 | DEFINE_string(ignoreErrorTypes, kDefaultIgnorableErrorTypes.asString(" ").c_str(), | 
 | 1353 |               "Space-separated list of ErrorTypes that should be ignored. If any *other* error " | 
 | 1354 |               "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] | 1355 | DEFINE_string(match, "", "[~][^]substring[$] [...] of test name to run.\n" | 
 | 1356 |               "Multiple matches may be separated by spaces.\n" | 
 | 1357 |               "~ causes a matching test to always be skipped\n" | 
 | 1358 |               "^ requires the start of the test to match\n" | 
 | 1359 |               "$ requires the end of the test to match\n" | 
 | 1360 |               "^ and $ requires an exact match\n" | 
 | 1361 |               "If a test does not match any list entry,\n" | 
 | 1362 |               "it is skipped unless some list entry starts with ~"); | 
| epoger@google.com | 5f99545 | 2013-06-21 18:16:47 +0000 | [diff] [blame] | 1363 | DEFINE_string(missingExpectationsPath, "", "Write images for tests without expectations " | 
 | 1364 |               "into this directory."); | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1365 | DEFINE_string(mismatchPath, "", "Write images for tests that failed due to " | 
 | 1366 |               "pixel mismatches into this directory."); | 
 | 1367 | DEFINE_string(modulo, "", "[--modulo <remainder> <divisor>]: only run tests for which " | 
 | 1368 |               "testIndex %% divisor == remainder."); | 
 | 1369 | DEFINE_bool(pdf, true, "Exercise the pdf rendering test pass."); | 
 | 1370 | DEFINE_bool(pipe, true, "Exercise the SkGPipe replay test pass."); | 
 | 1371 | DEFINE_string2(readPath, r, "", "Read reference images from this dir, and report " | 
 | 1372 |                "any differences between those and the newly generated ones."); | 
 | 1373 | DEFINE_bool(replay, true, "Exercise the SkPicture replay test pass."); | 
 | 1374 | DEFINE_string2(resourcePath, i, "", "Directory that stores image resources."); | 
 | 1375 | DEFINE_bool(rtree, true, "Exercise the R-Tree variant of SkPicture test pass."); | 
 | 1376 | DEFINE_bool(serialize, true, "Exercise the SkPicture serialization & deserialization test pass."); | 
| epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 1377 | 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] | 1378 | DEFINE_bool(tiledPipe, false, "Exercise tiled SkGPipe replay."); | 
 | 1379 | DEFINE_bool(tileGrid, true, "Exercise the tile grid variant of SkPicture."); | 
 | 1380 | DEFINE_string(tileGridReplayScales, "", "Space separated list of floating-point scale " | 
 | 1381 |               "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] | 1382 | DEFINE_bool2(verbose, v, false, "Give more detail (e.g. list all GMs run, more info about " | 
 | 1383 |              "each test)."); | 
| epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 1384 | DEFINE_bool(writeChecksumBasedFilenames, false, "When writing out actual images, use checksum-" | 
 | 1385 |             "based filenames, as rebaseline.py will use when downloading them from Google Storage"); | 
 | 1386 | 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] | 1387 | DEFINE_string2(writePath, w, "",  "Write rendered images into this directory."); | 
| scroggo@google.com | 604e0c2 | 2013-04-09 21:25:46 +0000 | [diff] [blame] | 1388 | DEFINE_string2(writePicturePath, p, "", "Write .skp files into this directory."); | 
| edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 1389 | DEFINE_int32(pdfJpegQuality, -1, "Encodes images in JPEG at quality level N, " | 
 | 1390 |              "which can be in range 0-100). N = -1 will disable JPEG compression. " | 
 | 1391 |              "Default is N = 100, maximum quality."); | 
 | 1392 |  | 
 | 1393 | static bool encode_to_dct_stream(SkWStream* stream, const SkBitmap& bitmap, const SkIRect& rect) { | 
 | 1394 |     // Filter output of warnings that JPEG is not available for the image. | 
 | 1395 |     if (bitmap.width() >= 65500 || bitmap.height() >= 65500) return false; | 
 | 1396 |     if (FLAGS_pdfJpegQuality == -1) return false; | 
 | 1397 |  | 
 | 1398 |     SkIRect bitmapBounds; | 
 | 1399 |     SkBitmap subset; | 
 | 1400 |     const SkBitmap* bitmapToUse = &bitmap; | 
 | 1401 |     bitmap.getBounds(&bitmapBounds); | 
 | 1402 |     if (rect != bitmapBounds) { | 
 | 1403 |         SkAssertResult(bitmap.extractSubset(&subset, rect)); | 
 | 1404 |         bitmapToUse = ⊂ | 
 | 1405 |     } | 
 | 1406 |  | 
 | 1407 | #if defined(SK_BUILD_FOR_MAC) | 
 | 1408 |     // Workaround bug #1043 where bitmaps with referenced pixels cause | 
 | 1409 |     // CGImageDestinationFinalize to crash | 
 | 1410 |     SkBitmap copy; | 
 | 1411 |     bitmapToUse->deepCopyTo(©, bitmapToUse->config()); | 
 | 1412 |     bitmapToUse = © | 
 | 1413 | #endif | 
 | 1414 |  | 
 | 1415 |     return SkImageEncoder::EncodeStream(stream, | 
 | 1416 |                                         *bitmapToUse, | 
 | 1417 |                                         SkImageEncoder::kJPEG_Type, | 
 | 1418 |                                         FLAGS_pdfJpegQuality); | 
 | 1419 | } | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1420 |  | 
| scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1421 | static int findConfig(const char config[]) { | 
 | 1422 |     for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { | 
 | 1423 |         if (!strcmp(config, gRec[i].fName)) { | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1424 |             return (int) i; | 
| scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1425 |         } | 
 | 1426 |     } | 
 | 1427 |     return -1; | 
 | 1428 | } | 
 | 1429 |  | 
| scroggo@google.com | b7dbf63 | 2013-04-23 15:38:09 +0000 | [diff] [blame] | 1430 | static bool skip_name(SkCommandLineFlags::StringArray array, const char name[]) { | 
| caryclark@google.com | 512c9b6 | 2013-05-10 15:16:13 +0000 | [diff] [blame] | 1431 |     // FIXME: this duplicates the logic in test/skia_test.cpp -- consolidate | 
 | 1432 |     int count = array.count(); | 
 | 1433 |     size_t testLen = strlen(name); | 
 | 1434 |     bool anyExclude = count == 0; | 
| reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 1435 |     for (int i = 0; i < array.count(); ++i) { | 
| caryclark@google.com | 512c9b6 | 2013-05-10 15:16:13 +0000 | [diff] [blame] | 1436 |         const char* matchName = array[i]; | 
 | 1437 |         size_t matchLen = strlen(matchName); | 
 | 1438 |         bool matchExclude, matchStart, matchEnd; | 
 | 1439 |         if ((matchExclude = matchName[0] == '~')) { | 
 | 1440 |             anyExclude = true; | 
 | 1441 |             matchName++; | 
 | 1442 |             matchLen--; | 
 | 1443 |         } | 
 | 1444 |         if ((matchStart = matchName[0] == '^')) { | 
 | 1445 |             matchName++; | 
 | 1446 |             matchLen--; | 
 | 1447 |         } | 
 | 1448 |         if ((matchEnd = matchName[matchLen - 1] == '$')) { | 
 | 1449 |             matchLen--; | 
 | 1450 |         } | 
 | 1451 |         if (matchStart ? (!matchEnd || matchLen == testLen) | 
 | 1452 |                 && strncmp(name, matchName, matchLen) == 0 | 
 | 1453 |                 : matchEnd ? matchLen <= testLen | 
 | 1454 |                 && strncmp(name + testLen - matchLen, matchName, matchLen) == 0 | 
 | 1455 |                 : strstr(name, matchName) != 0) { | 
 | 1456 |             return matchExclude; | 
| reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 1457 |         } | 
 | 1458 |     } | 
| caryclark@google.com | 512c9b6 | 2013-05-10 15:16:13 +0000 | [diff] [blame] | 1459 |     return !anyExclude; | 
| reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 1460 | } | 
 | 1461 |  | 
| bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 1462 | namespace skiagm { | 
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1463 | #if SK_SUPPORT_GPU | 
| bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1464 | SkAutoTUnref<GrContext> gGrContext; | 
 | 1465 | /** | 
| bsalomon@google.com | c7a24d2 | 2012-11-01 18:03:48 +0000 | [diff] [blame] | 1466 |  * Sets the global GrContext, accessible by individual GMs | 
| bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1467 |  */ | 
| caryclark@google.com | 1313086 | 2012-06-06 12:10:45 +0000 | [diff] [blame] | 1468 | static void SetGr(GrContext* grContext) { | 
| bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1469 |     SkSafeRef(grContext); | 
 | 1470 |     gGrContext.reset(grContext); | 
| bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 1471 | } | 
| bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1472 |  | 
 | 1473 | /** | 
 | 1474 |  * Gets the global GrContext, can be called by GM tests. | 
 | 1475 |  */ | 
| caryclark@google.com | 1313086 | 2012-06-06 12:10:45 +0000 | [diff] [blame] | 1476 | GrContext* GetGr(); | 
| bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1477 | GrContext* GetGr() { | 
 | 1478 |     return gGrContext.get(); | 
 | 1479 | } | 
 | 1480 |  | 
 | 1481 | /** | 
 | 1482 |  * Sets the global GrContext and then resets it to its previous value at | 
 | 1483 |  * destruction. | 
 | 1484 |  */ | 
 | 1485 | class AutoResetGr : SkNoncopyable { | 
 | 1486 | public: | 
 | 1487 |     AutoResetGr() : fOld(NULL) {} | 
 | 1488 |     void set(GrContext* context) { | 
 | 1489 |         SkASSERT(NULL == fOld); | 
 | 1490 |         fOld = GetGr(); | 
 | 1491 |         SkSafeRef(fOld); | 
 | 1492 |         SetGr(context); | 
 | 1493 |     } | 
 | 1494 |     ~AutoResetGr() { SetGr(fOld); SkSafeUnref(fOld); } | 
 | 1495 | private: | 
 | 1496 |     GrContext* fOld; | 
 | 1497 | }; | 
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1498 | #else | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1499 | GrContext* GetGr(); | 
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1500 | GrContext* GetGr() { return NULL; } | 
 | 1501 | #endif | 
| bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 1502 | } | 
 | 1503 |  | 
| reed@google.com | fb2cd42 | 2013-01-04 14:43:03 +0000 | [diff] [blame] | 1504 | template <typename T> void appendUnique(SkTDArray<T>* array, const T& value) { | 
 | 1505 |     int index = array->find(value); | 
 | 1506 |     if (index < 0) { | 
 | 1507 |         *array->append() = value; | 
 | 1508 |     } | 
 | 1509 | } | 
 | 1510 |  | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1511 | /** | 
 | 1512 |  * Run this test in a number of different configs (8888, 565, PDF, | 
 | 1513 |  * etc.), confirming that the resulting bitmaps match expectations | 
 | 1514 |  * (which may be different for each config). | 
 | 1515 |  * | 
 | 1516 |  * Returns all errors encountered while doing so. | 
 | 1517 |  */ | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1518 | ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm, const SkTDArray<size_t> &configs, | 
 | 1519 |                                       GrContextFactory *grFactory); | 
 | 1520 | ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm, const SkTDArray<size_t> &configs, | 
 | 1521 |                                       GrContextFactory *grFactory) { | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1522 |     const char renderModeDescriptor[] = ""; | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1523 |     ErrorCombination errorsForAllConfigs; | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1524 |     uint32_t gmFlags = gm->getFlags(); | 
 | 1525 |  | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1526 |     for (int i = 0; i < configs.count(); i++) { | 
 | 1527 |         ConfigData config = gRec[configs[i]]; | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1528 |         const SkString shortNamePlusConfig = gmmain.make_shortname_plus_config(gm->shortName(), | 
 | 1529 |                                                                                config.fName); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1530 |  | 
 | 1531 |         // Skip any tests that we don't even need to try. | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1532 |         // If any of these were skipped on a per-GM basis, record them as | 
 | 1533 |         // kIntentionallySkipped. | 
 | 1534 |         if (kPDF_Backend == config.fBackend) { | 
 | 1535 |             if (!FLAGS_pdf) { | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1536 |                 continue; | 
 | 1537 |             } | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1538 |             if (gmFlags & GM::kSkipPDF_Flag) { | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1539 |                 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1540 |                                          renderModeDescriptor); | 
 | 1541 |                 errorsForAllConfigs.add(kIntentionallySkipped_ErrorType); | 
 | 1542 |                 continue; | 
 | 1543 |             } | 
 | 1544 |         } | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1545 |         if ((gmFlags & GM::kSkip565_Flag) && | 
 | 1546 |             (kRaster_Backend == config.fBackend) && | 
 | 1547 |             (SkBitmap::kRGB_565_Config == config.fConfig)) { | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1548 |             gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1549 |                                      renderModeDescriptor); | 
 | 1550 |             errorsForAllConfigs.add(kIntentionallySkipped_ErrorType); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1551 |             continue; | 
 | 1552 |         } | 
 | 1553 |         if ((gmFlags & GM::kSkipGPU_Flag) && | 
 | 1554 |             kGPU_Backend == config.fBackend) { | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1555 |             gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1556 |                                      renderModeDescriptor); | 
 | 1557 |             errorsForAllConfigs.add(kIntentionallySkipped_ErrorType); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1558 |             continue; | 
 | 1559 |         } | 
 | 1560 |  | 
 | 1561 |         // Now we know that we want to run this test and record its | 
 | 1562 |         // success or failure. | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1563 |         ErrorCombination errorsForThisConfig; | 
| bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1564 |         GrSurface* gpuTarget = NULL; | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1565 | #if SK_SUPPORT_GPU | 
| bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1566 |         SkAutoTUnref<GrSurface> auGpuTarget; | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1567 |         AutoResetGr autogr; | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1568 |         if ((errorsForThisConfig.isEmpty()) && (kGPU_Backend == config.fBackend)) { | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1569 |             GrContext* gr = grFactory->get(config.fGLContextType); | 
 | 1570 |             bool grSuccess = false; | 
 | 1571 |             if (gr) { | 
 | 1572 |                 // create a render target to back the device | 
 | 1573 |                 GrTextureDesc desc; | 
 | 1574 |                 desc.fConfig = kSkia8888_GrPixelConfig; | 
 | 1575 |                 desc.fFlags = kRenderTarget_GrTextureFlagBit; | 
 | 1576 |                 desc.fWidth = gm->getISize().width(); | 
 | 1577 |                 desc.fHeight = gm->getISize().height(); | 
 | 1578 |                 desc.fSampleCnt = config.fSampleCnt; | 
| bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1579 |                 auGpuTarget.reset(gr->createUncachedTexture(desc, NULL, 0)); | 
 | 1580 |                 if (NULL != auGpuTarget) { | 
 | 1581 |                     gpuTarget = auGpuTarget; | 
 | 1582 |                     grSuccess = true; | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1583 |                     autogr.set(gr); | 
| bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1584 |                     // Set the user specified cache limits if non-default. | 
 | 1585 |                     size_t bytes; | 
 | 1586 |                     int count; | 
 | 1587 |                     gr->getTextureCacheLimits(&count, &bytes); | 
 | 1588 |                     if (DEFAULT_CACHE_VALUE != gGpuCacheSizeBytes) { | 
 | 1589 |                         bytes = static_cast<size_t>(gGpuCacheSizeBytes); | 
 | 1590 |                     } | 
 | 1591 |                     if (DEFAULT_CACHE_VALUE != gGpuCacheSizeCount) { | 
 | 1592 |                         count = gGpuCacheSizeCount; | 
 | 1593 |                     } | 
 | 1594 |                     gr->setTextureCacheLimits(count, bytes); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1595 |                 } | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1596 |             } | 
 | 1597 |             if (!grSuccess) { | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1598 |                 errorsForThisConfig.add(kNoGpuContext_ErrorType); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1599 |             } | 
 | 1600 |         } | 
 | 1601 | #endif | 
 | 1602 |  | 
 | 1603 |         SkBitmap comparisonBitmap; | 
 | 1604 |  | 
 | 1605 |         const char* writePath; | 
 | 1606 |         if (FLAGS_writePath.count() == 1) { | 
 | 1607 |             writePath = FLAGS_writePath[0]; | 
 | 1608 |         } else { | 
 | 1609 |             writePath = NULL; | 
 | 1610 |         } | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1611 |         if (errorsForThisConfig.isEmpty()) { | 
| bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1612 |             errorsForThisConfig.add(gmmain.test_drawing(gm,config, writePath, gpuTarget, | 
 | 1613 |                                                         &comparisonBitmap)); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1614 |         } | 
 | 1615 |  | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1616 |         if (FLAGS_deferred && errorsForThisConfig.isEmpty() && | 
 | 1617 |             (kGPU_Backend == config.fBackend || kRaster_Backend == config.fBackend)) { | 
 | 1618 |             errorsForThisConfig.add(gmmain.test_deferred_drawing(gm, config, comparisonBitmap, | 
| bsalomon@google.com | 123ac1d | 2013-03-28 19:18:12 +0000 | [diff] [blame] | 1619 |                                                                  gpuTarget)); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1620 |         } | 
 | 1621 |  | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1622 |         errorsForAllConfigs.add(errorsForThisConfig); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1623 |     } | 
 | 1624 |     return errorsForAllConfigs; | 
 | 1625 | } | 
 | 1626 |  | 
 | 1627 | /** | 
 | 1628 |  * Run this test in a number of different drawing modes (pipe, | 
 | 1629 |  * deferred, tiled, etc.), confirming that the resulting bitmaps all | 
 | 1630 |  * *exactly* match comparisonBitmap. | 
 | 1631 |  * | 
 | 1632 |  * Returns all errors encountered while doing so. | 
 | 1633 |  */ | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1634 | ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm, const ConfigData &compareConfig, | 
 | 1635 |                                     const SkBitmap &comparisonBitmap, | 
 | 1636 |                                     const SkTDArray<SkScalar> &tileGridReplayScales); | 
 | 1637 | ErrorCombination run_multiple_modes(GMMain &gmmain, GM *gm, const ConfigData &compareConfig, | 
 | 1638 |                                     const SkBitmap &comparisonBitmap, | 
 | 1639 |                                     const SkTDArray<SkScalar> &tileGridReplayScales) { | 
 | 1640 |     ErrorCombination errorsForAllModes; | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1641 |     uint32_t gmFlags = gm->getFlags(); | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1642 |     const SkString shortNamePlusConfig = gmmain.make_shortname_plus_config(gm->shortName(), | 
 | 1643 |                                                                            compareConfig.fName); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1644 |  | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1645 |     SkPicture* pict = gmmain.generate_new_picture(gm, kNone_BbhType, 0); | 
 | 1646 |     SkAutoUnref aur(pict); | 
 | 1647 |     if (FLAGS_replay) { | 
 | 1648 |         const char renderModeDescriptor[] = "-replay"; | 
 | 1649 |         if (gmFlags & GM::kSkipPicture_Flag) { | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1650 |             gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, | 
 | 1651 |                                      renderModeDescriptor); | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1652 |             errorsForAllModes.add(kIntentionallySkipped_ErrorType); | 
 | 1653 |         } else { | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1654 |             SkBitmap bitmap; | 
 | 1655 |             gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap); | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1656 |             errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap( | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1657 |                 gm->shortName(), compareConfig.fName, renderModeDescriptor, bitmap, | 
 | 1658 |                 &comparisonBitmap)); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1659 |         } | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1660 |     } | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1661 |  | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1662 |     if (FLAGS_serialize) { | 
 | 1663 |         const char renderModeDescriptor[] = "-serialize"; | 
 | 1664 |         if (gmFlags & GM::kSkipPicture_Flag) { | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1665 |             gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, | 
 | 1666 |                                      renderModeDescriptor); | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1667 |             errorsForAllModes.add(kIntentionallySkipped_ErrorType); | 
 | 1668 |         } else { | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1669 |             SkPicture* repict = gmmain.stream_to_new_picture(*pict); | 
 | 1670 |             SkAutoUnref aurr(repict); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1671 |             SkBitmap bitmap; | 
 | 1672 |             gmmain.generate_image_from_picture(gm, compareConfig, repict, &bitmap); | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1673 |             errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap( | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1674 |                 gm->shortName(), compareConfig.fName, renderModeDescriptor, bitmap, | 
 | 1675 |                 &comparisonBitmap)); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1676 |         } | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1677 |     } | 
 | 1678 |  | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1679 |     if ((1 == FLAGS_writePicturePath.count()) && | 
 | 1680 |         !(gmFlags & GM::kSkipPicture_Flag)) { | 
 | 1681 |         const char* pictureSuffix = "skp"; | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1682 |         // TODO(epoger): Make sure this still works even though the | 
 | 1683 |         // filename now contains the config name (it used to contain | 
 | 1684 |         // just the shortName).  I think this is actually an | 
 | 1685 |         // *improvement*, because now runs with different configs will | 
 | 1686 |         // write out their SkPictures to separate files rather than | 
 | 1687 |         // overwriting each other.  But we should make sure it doesn't | 
 | 1688 |         // break anybody. | 
 | 1689 |         SkString path = gmmain.make_filename(FLAGS_writePicturePath[0], gm->shortName(), | 
 | 1690 |                                              compareConfig.fName, "", pictureSuffix); | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1691 |         SkFILEWStream stream(path.c_str()); | 
 | 1692 |         pict->serialize(&stream); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1693 |     } | 
 | 1694 |  | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1695 |     if (FLAGS_rtree) { | 
 | 1696 |         const char renderModeDescriptor[] = "-rtree"; | 
 | 1697 |         if (gmFlags & GM::kSkipPicture_Flag) { | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1698 |             gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, | 
 | 1699 |                                      renderModeDescriptor); | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1700 |             errorsForAllModes.add(kIntentionallySkipped_ErrorType); | 
 | 1701 |         } else { | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1702 |             SkPicture* pict = gmmain.generate_new_picture( | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1703 |                 gm, kRTree_BbhType, SkPicture::kUsePathBoundsForClip_RecordingFlag); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1704 |             SkAutoUnref aur(pict); | 
 | 1705 |             SkBitmap bitmap; | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1706 |             gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap); | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1707 |             errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap( | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1708 |                 gm->shortName(), compareConfig.fName, renderModeDescriptor, bitmap, | 
 | 1709 |                 &comparisonBitmap)); | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1710 |         } | 
 | 1711 |     } | 
 | 1712 |  | 
 | 1713 |     if (FLAGS_tileGrid) { | 
 | 1714 |         for(int scaleIndex = 0; scaleIndex < tileGridReplayScales.count(); ++scaleIndex) { | 
 | 1715 |             SkScalar replayScale = tileGridReplayScales[scaleIndex]; | 
 | 1716 |             SkString renderModeDescriptor("-tilegrid"); | 
 | 1717 |             if (SK_Scalar1 != replayScale) { | 
 | 1718 |                 renderModeDescriptor += "-scale-"; | 
 | 1719 |                 renderModeDescriptor.appendScalar(replayScale); | 
 | 1720 |             } | 
 | 1721 |  | 
 | 1722 |             if ((gmFlags & GM::kSkipPicture_Flag) || | 
 | 1723 |                 ((gmFlags & GM::kSkipScaledReplay_Flag) && replayScale != 1)) { | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1724 |                 gmmain.RecordTestResults(kIntentionallySkipped_ErrorType, shortNamePlusConfig, | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1725 |                                          renderModeDescriptor.c_str()); | 
 | 1726 |                 errorsForAllModes.add(kIntentionallySkipped_ErrorType); | 
 | 1727 |             } else { | 
 | 1728 |                 // We record with the reciprocal scale to obtain a replay | 
 | 1729 |                 // result that can be validated against comparisonBitmap. | 
 | 1730 |                 SkScalar recordScale = SkScalarInvert(replayScale); | 
 | 1731 |                 SkPicture* pict = gmmain.generate_new_picture( | 
 | 1732 |                     gm, kTileGrid_BbhType, SkPicture::kUsePathBoundsForClip_RecordingFlag, | 
 | 1733 |                     recordScale); | 
 | 1734 |                 SkAutoUnref aur(pict); | 
 | 1735 |                 SkBitmap bitmap; | 
 | 1736 |                 // We cannot yet pass 'true' to generate_image_from_picture to | 
 | 1737 |                 // perform actual tiled rendering (see Issue 1198 - | 
 | 1738 |                 // https://code.google.com/p/skia/issues/detail?id=1198) | 
 | 1739 |                 gmmain.generate_image_from_picture(gm, compareConfig, pict, &bitmap, | 
 | 1740 |                                                    replayScale /*, true */); | 
 | 1741 |                 errorsForAllModes.add(gmmain.compare_test_results_to_reference_bitmap( | 
| epoger@google.com | 659c8c0 | 2013-05-21 15:45:45 +0000 | [diff] [blame] | 1742 |                     gm->shortName(), compareConfig.fName, renderModeDescriptor.c_str(), bitmap, | 
 | 1743 |                     &comparisonBitmap)); | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1744 |             } | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1745 |         } | 
 | 1746 |     } | 
 | 1747 |  | 
 | 1748 |     // run the pipe centric GM steps | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 1749 |     if (FLAGS_pipe) { | 
 | 1750 |         errorsForAllModes.add(gmmain.test_pipe_playback(gm, compareConfig, comparisonBitmap, | 
 | 1751 |                                                         FLAGS_simulatePipePlaybackFailure)); | 
 | 1752 |         if (FLAGS_tiledPipe) { | 
 | 1753 |             errorsForAllModes.add(gmmain.test_tiled_pipe_playback(gm, compareConfig, | 
 | 1754 |                                                                   comparisonBitmap)); | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1755 |         } | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1756 |     } | 
 | 1757 |     return errorsForAllModes; | 
 | 1758 | } | 
 | 1759 |  | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 1760 | /** | 
 | 1761 |  * Return a list of all entries in an array of strings as a single string | 
 | 1762 |  * of this form: | 
 | 1763 |  * "item1", "item2", "item3" | 
 | 1764 |  */ | 
 | 1765 | SkString list_all(const SkTArray<SkString> &stringArray); | 
 | 1766 | SkString list_all(const SkTArray<SkString> &stringArray) { | 
 | 1767 |     SkString total; | 
 | 1768 |     for (int i = 0; i < stringArray.count(); i++) { | 
 | 1769 |         if (i > 0) { | 
 | 1770 |             total.append(", "); | 
 | 1771 |         } | 
 | 1772 |         total.append("\""); | 
 | 1773 |         total.append(stringArray[i]); | 
 | 1774 |         total.append("\""); | 
 | 1775 |     } | 
 | 1776 |     return total; | 
 | 1777 | } | 
 | 1778 |  | 
 | 1779 | /** | 
 | 1780 |  * Return a list of configuration names, as a single string of this form: | 
 | 1781 |  * "item1", "item2", "item3" | 
 | 1782 |  * | 
 | 1783 |  * @param configs configurations, as a list of indices into gRec | 
 | 1784 |  */ | 
 | 1785 | SkString list_all_config_names(const SkTDArray<size_t> &configs); | 
 | 1786 | SkString list_all_config_names(const SkTDArray<size_t> &configs) { | 
 | 1787 |     SkString total; | 
 | 1788 |     for (int i = 0; i < configs.count(); i++) { | 
 | 1789 |         if (i > 0) { | 
 | 1790 |             total.append(", "); | 
 | 1791 |         } | 
 | 1792 |         total.append("\""); | 
 | 1793 |         total.append(gRec[configs[i]].fName); | 
 | 1794 |         total.append("\""); | 
 | 1795 |     } | 
 | 1796 |     return total; | 
 | 1797 | } | 
 | 1798 |  | 
| epoger@google.com | fdea325 | 2013-05-02 18:24:03 +0000 | [diff] [blame] | 1799 | bool prepare_subdirectories(const char *root, bool useFileHierarchy, | 
 | 1800 |                             const SkTDArray<size_t> &configs); | 
 | 1801 | bool prepare_subdirectories(const char *root, bool useFileHierarchy, | 
 | 1802 |                             const SkTDArray<size_t> &configs) { | 
 | 1803 |     if (!sk_mkdir(root)) { | 
 | 1804 |         return false; | 
 | 1805 |     } | 
 | 1806 |     if (useFileHierarchy) { | 
 | 1807 |         for (int i = 0; i < configs.count(); i++) { | 
 | 1808 |             ConfigData config = gRec[configs[i]]; | 
 | 1809 |             SkString subdir; | 
 | 1810 |             subdir.appendf("%s%c%s", root, SkPATH_SEPARATOR, config.fName); | 
 | 1811 |             if (!sk_mkdir(subdir.c_str())) { | 
 | 1812 |                 return false; | 
 | 1813 |             } | 
 | 1814 |         } | 
 | 1815 |     } | 
 | 1816 |     return true; | 
 | 1817 | } | 
 | 1818 |  | 
| epoger@google.com | 0b62b3d | 2013-03-20 17:59:28 +0000 | [diff] [blame] | 1819 | int tool_main(int argc, char** argv); | 
 | 1820 | int tool_main(int argc, char** argv) { | 
 | 1821 |  | 
 | 1822 | #if SK_ENABLE_INST_COUNT | 
 | 1823 |     gPrintInstCount = true; | 
 | 1824 | #endif | 
 | 1825 |  | 
 | 1826 |     SkGraphics::Init(); | 
 | 1827 |     // we don't need to see this during a run | 
 | 1828 |     gSkSuppressFontCachePurgeSpew = true; | 
 | 1829 |  | 
 | 1830 |     setSystemPreferences(); | 
 | 1831 |     GMMain gmmain; | 
 | 1832 |  | 
 | 1833 |     SkTDArray<size_t> configs; | 
 | 1834 |     SkTDArray<size_t> excludeConfigs; | 
 | 1835 |     bool userConfig = false; | 
 | 1836 |  | 
 | 1837 |     SkString usage; | 
 | 1838 |     usage.printf("Run the golden master tests.\n"); | 
| scroggo@google.com | d9ba9a0 | 2013-03-21 19:43:15 +0000 | [diff] [blame] | 1839 |     SkCommandLineFlags::SetUsage(usage.c_str()); | 
 | 1840 |     SkCommandLineFlags::Parse(argc, argv); | 
| epoger@google.com | 0b62b3d | 2013-03-20 17:59:28 +0000 | [diff] [blame] | 1841 |  | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1842 |     gmmain.fUseFileHierarchy = FLAGS_hierarchy; | 
| epoger@google.com | 6f7f14d | 2013-06-19 18:28:31 +0000 | [diff] [blame] | 1843 |     gmmain.fWriteChecksumBasedFilenames = FLAGS_writeChecksumBasedFilenames; | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1844 |     if (FLAGS_mismatchPath.count() == 1) { | 
 | 1845 |         gmmain.fMismatchPath = FLAGS_mismatchPath[0]; | 
 | 1846 |     } | 
| epoger@google.com | 5f99545 | 2013-06-21 18:16:47 +0000 | [diff] [blame] | 1847 |     if (FLAGS_missingExpectationsPath.count() == 1) { | 
 | 1848 |         gmmain.fMissingExpectationsPath = FLAGS_missingExpectationsPath[0]; | 
 | 1849 |     } | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1850 |  | 
 | 1851 |     for (int i = 0; i < FLAGS_config.count(); i++) { | 
| bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1852 |         const char* config = FLAGS_config[i]; | 
 | 1853 |         userConfig = true; | 
 | 1854 |         bool exclude = false; | 
 | 1855 |         if (*config == kExcludeConfigChar) { | 
 | 1856 |             exclude = true; | 
 | 1857 |             config += 1; | 
 | 1858 |         } | 
 | 1859 |         int index = findConfig(config); | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1860 |         if (index >= 0) { | 
| bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1861 |             if (exclude) { | 
 | 1862 |                 *excludeConfigs.append() = index; | 
 | 1863 |             } else { | 
 | 1864 |                 appendUnique<size_t>(&configs, index); | 
 | 1865 |             } | 
 | 1866 |         } else if (0 == strcmp(kDefaultsConfigStr, config)) { | 
 | 1867 |             for (size_t c = 0; c < SK_ARRAY_COUNT(gRec); ++c) { | 
 | 1868 |                 if (gRec[c].fRunByDefault) { | 
 | 1869 |                     if (exclude) { | 
 | 1870 |                         gm_fprintf(stderr, "%c%s is not allowed.\n", | 
 | 1871 |                                    kExcludeConfigChar, kDefaultsConfigStr); | 
 | 1872 |                         return -1; | 
 | 1873 |                     } else { | 
 | 1874 |                         appendUnique<size_t>(&configs, c); | 
 | 1875 |                     } | 
 | 1876 |                 } | 
 | 1877 |             } | 
| scroggo@google.com | 0b73563 | 2013-03-19 17:38:50 +0000 | [diff] [blame] | 1878 |         } else { | 
| bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1879 |             gm_fprintf(stderr, "unrecognized config %s\n", config); | 
| scroggo@google.com | 7d51930 | 2013-03-19 17:28:10 +0000 | [diff] [blame] | 1880 |             return -1; | 
 | 1881 |         } | 
 | 1882 |     } | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1883 |  | 
 | 1884 |     for (int i = 0; i < FLAGS_excludeConfig.count(); i++) { | 
 | 1885 |         int index = findConfig(FLAGS_excludeConfig[i]); | 
 | 1886 |         if (index >= 0) { | 
 | 1887 |             *excludeConfigs.append() = index; | 
 | 1888 |         } else { | 
 | 1889 |             gm_fprintf(stderr, "unrecognized excludeConfig %s\n", FLAGS_excludeConfig[i]); | 
 | 1890 |             return -1; | 
 | 1891 |         } | 
 | 1892 |     } | 
 | 1893 |  | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1894 |     int moduloRemainder = -1; | 
 | 1895 |     int moduloDivisor = -1; | 
 | 1896 |  | 
 | 1897 |     if (FLAGS_modulo.count() == 2) { | 
 | 1898 |         moduloRemainder = atoi(FLAGS_modulo[0]); | 
 | 1899 |         moduloDivisor = atoi(FLAGS_modulo[1]); | 
 | 1900 |         if (moduloRemainder < 0 || moduloDivisor <= 0 || moduloRemainder >= moduloDivisor) { | 
 | 1901 |             gm_fprintf(stderr, "invalid modulo values."); | 
 | 1902 |             return -1; | 
 | 1903 |         } | 
| tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1904 |     } | 
| reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 1905 |  | 
| epoger@google.com | 5079d2c | 2013-04-12 14:11:21 +0000 | [diff] [blame] | 1906 |     if (FLAGS_ignoreErrorTypes.count() > 0) { | 
 | 1907 |         gmmain.fIgnorableErrorTypes = ErrorCombination(); | 
 | 1908 |         for (int i = 0; i < FLAGS_ignoreErrorTypes.count(); i++) { | 
 | 1909 |             ErrorType type; | 
 | 1910 |             const char *name = FLAGS_ignoreErrorTypes[i]; | 
 | 1911 |             if (!getErrorTypeByName(name, &type)) { | 
 | 1912 |                 gm_fprintf(stderr, "cannot find ErrorType with name '%s'\n", name); | 
 | 1913 |                 return -1; | 
 | 1914 |             } else { | 
 | 1915 |                 gmmain.fIgnorableErrorTypes.add(type); | 
 | 1916 |             } | 
 | 1917 |         } | 
 | 1918 |     } | 
 | 1919 |  | 
| epoger@google.com | 6f6568b | 2013-03-22 17:29:46 +0000 | [diff] [blame] | 1920 | #if SK_SUPPORT_GPU | 
 | 1921 |     if (FLAGS_gpuCacheSize.count() > 0) { | 
 | 1922 |         if (FLAGS_gpuCacheSize.count() != 2) { | 
 | 1923 |             gm_fprintf(stderr, "--gpuCacheSize requires two arguments\n"); | 
 | 1924 |             return -1; | 
 | 1925 |         } | 
 | 1926 |         gGpuCacheSizeBytes = atoi(FLAGS_gpuCacheSize[0]); | 
 | 1927 |         gGpuCacheSizeCount = atoi(FLAGS_gpuCacheSize[1]); | 
 | 1928 |     } else { | 
 | 1929 |         gGpuCacheSizeBytes = DEFAULT_CACHE_VALUE; | 
 | 1930 |         gGpuCacheSizeCount = DEFAULT_CACHE_VALUE; | 
 | 1931 |     } | 
 | 1932 | #endif | 
 | 1933 |  | 
 | 1934 |     SkTDArray<SkScalar> tileGridReplayScales; | 
 | 1935 |     *tileGridReplayScales.append() = SK_Scalar1; // By default only test at scale 1.0 | 
 | 1936 |     if (FLAGS_tileGridReplayScales.count() > 0) { | 
 | 1937 |         tileGridReplayScales.reset(); | 
 | 1938 |         for (int i = 0; i < FLAGS_tileGridReplayScales.count(); i++) { | 
 | 1939 |             double val = atof(FLAGS_tileGridReplayScales[i]); | 
 | 1940 |             if (0 < val) { | 
 | 1941 |                 *tileGridReplayScales.append() = SkDoubleToScalar(val); | 
 | 1942 |             } | 
 | 1943 |         } | 
 | 1944 |         if (0 == tileGridReplayScales.count()) { | 
 | 1945 |             // Should have at least one scale | 
 | 1946 |             gm_fprintf(stderr, "--tileGridReplayScales requires at least one scale.\n"); | 
 | 1947 |             return -1; | 
 | 1948 |         } | 
 | 1949 |     } | 
 | 1950 |  | 
| scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1951 |     if (!userConfig) { | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1952 |         // if no config is specified by user, add the defaults | 
| scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1953 |         for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1954 |             if (gRec[i].fRunByDefault) { | 
 | 1955 |                 *configs.append() = i; | 
 | 1956 |             } | 
| scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1957 |         } | 
 | 1958 |     } | 
| reed@google.com | fb2cd42 | 2013-01-04 14:43:03 +0000 | [diff] [blame] | 1959 |     // now remove any explicitly excluded configs | 
 | 1960 |     for (int i = 0; i < excludeConfigs.count(); ++i) { | 
 | 1961 |         int index = configs.find(excludeConfigs[i]); | 
 | 1962 |         if (index >= 0) { | 
 | 1963 |             configs.remove(index); | 
 | 1964 |             // now assert that there was only one copy in configs[] | 
 | 1965 |             SkASSERT(configs.find(excludeConfigs[i]) < 0); | 
 | 1966 |         } | 
 | 1967 |     } | 
 | 1968 |  | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1969 | #if SK_SUPPORT_GPU | 
 | 1970 |     GrContextFactory* grFactory = new GrContextFactory; | 
 | 1971 |     for (int i = 0; i < configs.count(); ++i) { | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 1972 |         size_t index = configs[i]; | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1973 |         if (kGPU_Backend == gRec[index].fBackend) { | 
 | 1974 |             GrContext* ctx = grFactory->get(gRec[index].fGLContextType); | 
 | 1975 |             if (NULL == ctx) { | 
| epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 1976 |                 gm_fprintf(stderr, "GrContext could not be created for config %s." | 
 | 1977 |                            " Config will be skipped.\n", gRec[index].fName); | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1978 |                 configs.remove(i); | 
 | 1979 |                 --i; | 
| bsalomon@google.com | 42db2e4 | 2013-06-11 19:22:44 +0000 | [diff] [blame] | 1980 |                 continue; | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1981 |             } | 
 | 1982 |             if (gRec[index].fSampleCnt > ctx->getMaxSampleCount()) { | 
| epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 1983 |                 gm_fprintf(stderr, "Sample count (%d) of config %s is not supported." | 
 | 1984 |                            " Config will be skipped.\n", gRec[index].fSampleCnt, gRec[index].fName); | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1985 |                 configs.remove(i); | 
 | 1986 |                 --i; | 
 | 1987 |             } | 
 | 1988 |         } | 
 | 1989 |     } | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 1990 | #else | 
 | 1991 |     GrContextFactory* grFactory = NULL; | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 1992 | #endif | 
 | 1993 |  | 
| bsalomon@google.com | dd8e353 | 2013-04-24 18:07:11 +0000 | [diff] [blame] | 1994 |     if (configs.isEmpty()) { | 
 | 1995 |         gm_fprintf(stderr, "No configs to run."); | 
 | 1996 |         return -1; | 
 | 1997 |     } | 
 | 1998 |  | 
 | 1999 |     // now show the user the set of configs that will be run. | 
 | 2000 |     SkString configStr("These configs will be run: "); | 
 | 2001 |     // show the user the config that will run. | 
 | 2002 |     for (int i = 0; i < configs.count(); ++i) { | 
 | 2003 |         configStr.appendf("%s%s", gRec[configs[i]].fName, (i == configs.count() - 1) ? "\n" : " "); | 
 | 2004 |     } | 
 | 2005 |     gm_fprintf(stdout, "%s", configStr.c_str()); | 
 | 2006 |  | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 2007 |     if (FLAGS_resourcePath.count() == 1) { | 
 | 2008 |         GM::SetResourcePath(FLAGS_resourcePath[0]); | 
 | 2009 |     } | 
| robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 2010 |  | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 2011 |     if (FLAGS_readPath.count() == 1) { | 
 | 2012 |         const char* readPath = FLAGS_readPath[0]; | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 2013 |         if (!sk_exists(readPath)) { | 
| epoger@google.com | 5efdd0c | 2013-03-13 14:18:40 +0000 | [diff] [blame] | 2014 |             gm_fprintf(stderr, "readPath %s does not exist!\n", readPath); | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 2015 |             return -1; | 
 | 2016 |         } | 
 | 2017 |         if (sk_isdir(readPath)) { | 
| epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 2018 |             if (FLAGS_verbose) { | 
 | 2019 |                 gm_fprintf(stdout, "reading from %s\n", readPath); | 
 | 2020 |             } | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 2021 |             gmmain.fExpectationsSource.reset(SkNEW_ARGS( | 
| epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 2022 |                 IndividualImageExpectationsSource, (readPath))); | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 2023 |         } else { | 
| epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 2024 |             if (FLAGS_verbose) { | 
 | 2025 |                 gm_fprintf(stdout, "reading expectations from JSON summary file %s\n", readPath); | 
 | 2026 |             } | 
| epoger@google.com | d271d24 | 2013-02-13 18:14:48 +0000 | [diff] [blame] | 2027 |             gmmain.fExpectationsSource.reset(SkNEW_ARGS( | 
 | 2028 |                 JsonExpectationsSource, (readPath))); | 
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 2029 |         } | 
| chudy@google.com | f32f6e8 | 2012-07-12 15:42:37 +0000 | [diff] [blame] | 2030 |     } | 
| epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 2031 |     if (FLAGS_verbose) { | 
 | 2032 |         if (FLAGS_writePath.count() == 1) { | 
 | 2033 |             gm_fprintf(stdout, "writing to %s\n", FLAGS_writePath[0]); | 
 | 2034 |         } | 
| epoger@google.com | fdea325 | 2013-05-02 18:24:03 +0000 | [diff] [blame] | 2035 |         if (NULL != gmmain.fMismatchPath) { | 
 | 2036 |             gm_fprintf(stdout, "writing mismatches to %s\n", gmmain.fMismatchPath); | 
 | 2037 |         } | 
| epoger@google.com | 5f99545 | 2013-06-21 18:16:47 +0000 | [diff] [blame] | 2038 |         if (NULL != gmmain.fMissingExpectationsPath) { | 
 | 2039 |             gm_fprintf(stdout, "writing images without expectations to %s\n", | 
 | 2040 |                        gmmain.fMissingExpectationsPath); | 
 | 2041 |         } | 
| epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 2042 |         if (FLAGS_writePicturePath.count() == 1) { | 
 | 2043 |             gm_fprintf(stdout, "writing pictures to %s\n", FLAGS_writePicturePath[0]); | 
 | 2044 |         } | 
 | 2045 |         if (FLAGS_resourcePath.count() == 1) { | 
 | 2046 |             gm_fprintf(stdout, "reading resources from %s\n", FLAGS_resourcePath[0]); | 
 | 2047 |         } | 
| robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 2048 |     } | 
 | 2049 |  | 
| epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 2050 |     if (moduloDivisor <= 0) { | 
 | 2051 |         moduloRemainder = -1; | 
| reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 2052 |     } | 
| epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 2053 |     if (moduloRemainder < 0 || moduloRemainder >= moduloDivisor) { | 
 | 2054 |         moduloRemainder = -1; | 
| reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 2055 |     } | 
 | 2056 |  | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 2057 |     int gmsRun = 0; | 
| reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 2058 |     int gmIndex = -1; | 
 | 2059 |     SkString moduloStr; | 
 | 2060 |  | 
| epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 2061 |     // If we will be writing out files, prepare subdirectories. | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 2062 |     if (FLAGS_writePath.count() == 1) { | 
| epoger@google.com | fdea325 | 2013-05-02 18:24:03 +0000 | [diff] [blame] | 2063 |         if (!prepare_subdirectories(FLAGS_writePath[0], gmmain.fUseFileHierarchy, configs)) { | 
| epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 2064 |             return -1; | 
 | 2065 |         } | 
| epoger@google.com | fdea325 | 2013-05-02 18:24:03 +0000 | [diff] [blame] | 2066 |     } | 
 | 2067 |     if (NULL != gmmain.fMismatchPath) { | 
 | 2068 |         if (!prepare_subdirectories(gmmain.fMismatchPath, gmmain.fUseFileHierarchy, configs)) { | 
 | 2069 |             return -1; | 
| epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 2070 |         } | 
 | 2071 |     } | 
| epoger@google.com | 5f99545 | 2013-06-21 18:16:47 +0000 | [diff] [blame] | 2072 |     if (NULL != gmmain.fMissingExpectationsPath) { | 
 | 2073 |         if (!prepare_subdirectories(gmmain.fMissingExpectationsPath, gmmain.fUseFileHierarchy, | 
 | 2074 |                                     configs)) { | 
 | 2075 |             return -1; | 
 | 2076 |         } | 
 | 2077 |     } | 
| epoger@google.com | e8ebeb1 | 2012-10-29 16:42:11 +0000 | [diff] [blame] | 2078 |  | 
| edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 2079 |     if (FLAGS_pdfJpegQuality < -1 || FLAGS_pdfJpegQuality > 100) { | 
 | 2080 |         gm_fprintf(stderr, "%s\n", "pdfJpegQuality must be in [-1 .. 100] range."); | 
 | 2081 |     } | 
 | 2082 |  | 
| bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 2083 |     Iter iter; | 
 | 2084 |     GM* gm; | 
| reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 2085 |     while ((gm = iter.next()) != NULL) { | 
| scroggo@google.com | 7fd2d70 | 2013-04-16 19:11:14 +0000 | [diff] [blame] | 2086 |         SkAutoTDelete<GM> adgm(gm); | 
| reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 2087 |         ++gmIndex; | 
| epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 2088 |         if (moduloRemainder >= 0) { | 
 | 2089 |             if ((gmIndex % moduloDivisor) != moduloRemainder) { | 
| reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 2090 |                 continue; | 
 | 2091 |             } | 
| epoger@google.com | 82cb65b | 2012-10-29 18:59:17 +0000 | [diff] [blame] | 2092 |             moduloStr.printf("[%d.%d] ", gmIndex, moduloDivisor); | 
| reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 2093 |         } | 
 | 2094 |  | 
| reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 2095 |         const char* shortName = gm->shortName(); | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 2096 |         if (skip_name(FLAGS_match, shortName)) { | 
| reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 2097 |             continue; | 
 | 2098 |         } | 
 | 2099 |  | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 2100 |         gmsRun++; | 
| tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 2101 |         SkISize size = gm->getISize(); | 
| epoger@google.com | bcbf5aa | 2013-04-12 02:11:54 +0000 | [diff] [blame] | 2102 |         gm_fprintf(stdout, "%sdrawing... %s [%d %d]\n", moduloStr.c_str(), shortName, | 
 | 2103 |                    size.width(), size.height()); | 
| djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 2104 |  | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 2105 |         run_multiple_configs(gmmain, gm, configs, grFactory); | 
| djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 2106 |  | 
 | 2107 |         SkBitmap comparisonBitmap; | 
 | 2108 |         const ConfigData compareConfig = | 
| bsalomon@google.com | 4c75f24 | 2013-03-19 18:58:43 +0000 | [diff] [blame] | 2109 |             { 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] | 2110 |         gmmain.generate_image(gm, compareConfig, NULL, &comparisonBitmap, false); | 
| djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 2111 |  | 
| epoger@google.com | 80724df | 2013-03-21 13:49:54 +0000 | [diff] [blame] | 2112 |         // TODO(epoger): only run this if gmmain.generate_image() succeeded? | 
 | 2113 |         // Otherwise, what are we comparing against? | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 2114 |         run_multiple_modes(gmmain, gm, compareConfig, comparisonBitmap, tileGridReplayScales); | 
| reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 2115 |     } | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 2116 |  | 
 | 2117 |     SkTArray<SkString> modes; | 
 | 2118 |     gmmain.GetRenderModesEncountered(modes); | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 2119 |     bool reportError = false; | 
 | 2120 |     if (gmmain.NumSignificantErrors() > 0) { | 
 | 2121 |         reportError = true; | 
 | 2122 |     } | 
| epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame] | 2123 |     int expectedNumberOfTests = gmsRun * (configs.count() + modes.count()); | 
| epoger@google.com | 310478e | 2013-04-03 18:00:39 +0000 | [diff] [blame] | 2124 |  | 
 | 2125 |     // Output summary to stdout. | 
| epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame] | 2126 |     if (FLAGS_verbose) { | 
 | 2127 |         gm_fprintf(stdout, "Ran %d GMs\n", gmsRun); | 
 | 2128 |         gm_fprintf(stdout, "... over %2d configs [%s]\n", configs.count(), | 
 | 2129 |                    list_all_config_names(configs).c_str()); | 
 | 2130 |         gm_fprintf(stdout, "...  and %2d modes   [%s]\n", modes.count(), list_all(modes).c_str()); | 
 | 2131 |         gm_fprintf(stdout, "... so there should be a total of %d tests.\n", expectedNumberOfTests); | 
 | 2132 |     } | 
 | 2133 |     gmmain.ListErrors(FLAGS_verbose); | 
| robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 2134 |  | 
| epoger@google.com | 07947d9 | 2013-04-11 15:41:02 +0000 | [diff] [blame] | 2135 |     // TODO(epoger): Enable this check for Android, too, once we resolve | 
 | 2136 |     // https://code.google.com/p/skia/issues/detail?id=1222 | 
 | 2137 |     // ('GM is unexpectedly skipping tests on Android') | 
 | 2138 | #ifndef SK_BUILD_FOR_ANDROID | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 2139 |     if (expectedNumberOfTests != gmmain.fTestsRun) { | 
 | 2140 |         gm_fprintf(stderr, "expected %d tests, but ran or skipped %d tests\n", | 
 | 2141 |                    expectedNumberOfTests, gmmain.fTestsRun); | 
 | 2142 |         reportError = true; | 
 | 2143 |     } | 
 | 2144 | #endif | 
 | 2145 |  | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 2146 |     if (FLAGS_writeJsonSummaryPath.count() == 1) { | 
| epoger@google.com | 76c913d | 2013-04-26 15:06:44 +0000 | [diff] [blame] | 2147 |         Json::Value root = CreateJsonTree( | 
 | 2148 |             gmmain.fJsonExpectedResults, | 
 | 2149 |             gmmain.fJsonActualResults_Failed, gmmain.fJsonActualResults_FailureIgnored, | 
 | 2150 |             gmmain.fJsonActualResults_NoComparison, gmmain.fJsonActualResults_Succeeded); | 
| epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 2151 |         std::string jsonStdString = root.toStyledString(); | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 2152 |         SkFILEWStream stream(FLAGS_writeJsonSummaryPath[0]); | 
| epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 2153 |         stream.write(jsonStdString.c_str(), jsonStdString.length()); | 
 | 2154 |     } | 
 | 2155 |  | 
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 2156 | #if SK_SUPPORT_GPU | 
| robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 2157 |  | 
| robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 2158 | #if GR_CACHE_STATS | 
| robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 2159 |     for (int i = 0; i < configs.count(); i++) { | 
 | 2160 |         ConfigData config = gRec[configs[i]]; | 
 | 2161 |  | 
| epoger@google.com | b0f8b43 | 2013-04-10 18:46:25 +0000 | [diff] [blame] | 2162 |         if (FLAGS_verbose && (kGPU_Backend == config.fBackend)) { | 
| robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 2163 |             GrContext* gr = grFactory->get(config.fGLContextType); | 
 | 2164 |  | 
| epoger@google.com | 5efdd0c | 2013-03-13 14:18:40 +0000 | [diff] [blame] | 2165 |             gm_fprintf(stdout, "config: %s %x\n", config.fName, gr); | 
| robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 2166 |             gr->printCacheStats(); | 
 | 2167 |         } | 
 | 2168 |     } | 
 | 2169 | #endif | 
 | 2170 |  | 
| robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 2171 |     delete grFactory; | 
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 2172 | #endif | 
| robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 2173 |     SkGraphics::Term(); | 
 | 2174 |  | 
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 2175 |     return (reportError) ? -1 : 0; | 
| reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 2176 | } | 
| caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 2177 |  | 
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 2178 | void GMMain::installFilter(SkCanvas* canvas) { | 
 | 2179 |     if (FLAGS_forceBWtext) { | 
 | 2180 |         canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); | 
 | 2181 |     } | 
 | 2182 | } | 
 | 2183 |  | 
| borenet@google.com | 7158e6a | 2012-11-01 17:43:44 +0000 | [diff] [blame] | 2184 | #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 
| caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 2185 | int main(int argc, char * const argv[]) { | 
 | 2186 |     return tool_main(argc, (char**) argv); | 
 | 2187 | } | 
 | 2188 | #endif |