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 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 8 | #include "gm.h" |
epoger@google.com | 7bc13a6 | 2012-02-14 14:53:59 +0000 | [diff] [blame] | 9 | #include "system_preferences.h" |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 10 | #include "GrContextFactory.h" |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 11 | #include "GrRenderTarget.h" |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 12 | #include "SkColorPriv.h" |
reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 13 | #include "SkData.h" |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 14 | #include "SkDeferredCanvas.h" |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 15 | #include "SkDevice.h" |
scroggo@google.com | 5af9b20 | 2012-06-04 17:17:36 +0000 | [diff] [blame] | 16 | #include "SkGPipe.h" |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 17 | #include "SkGpuCanvas.h" |
| 18 | #include "SkGpuDevice.h" |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 19 | #include "SkGraphics.h" |
| 20 | #include "SkImageDecoder.h" |
| 21 | #include "SkImageEncoder.h" |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 22 | #include "SkPicture.h" |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 23 | #include "SkRefCnt.h" |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 24 | #include "SkStream.h" |
| 25 | #include "SamplePipeControllers.h" |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 26 | |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 27 | static bool gForceBWtext; |
| 28 | |
reed@google.com | 8923c6c | 2011-11-08 14:59:38 +0000 | [diff] [blame] | 29 | extern bool gSkSuppressFontCachePurgeSpew; |
| 30 | |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 31 | #ifdef SK_SUPPORT_PDF |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 32 | #include "SkPDFDevice.h" |
| 33 | #include "SkPDFDocument.h" |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 34 | #endif |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 35 | |
epoger@google.com | e3cc2eb | 2012-01-18 20:11:13 +0000 | [diff] [blame] | 36 | // Until we resolve http://code.google.com/p/skia/issues/detail?id=455 , |
| 37 | // stop writing out XPS-format image baselines in gm. |
| 38 | #undef SK_SUPPORT_XPS |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 39 | #ifdef SK_SUPPORT_XPS |
| 40 | #include "SkXPSDevice.h" |
| 41 | #endif |
| 42 | |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 43 | #ifdef SK_BUILD_FOR_MAC |
| 44 | #include "SkCGUtils.h" |
bsalomon@google.com | 0a09eef | 2011-06-29 19:42:58 +0000 | [diff] [blame] | 45 | #define CAN_IMAGE_PDF 1 |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 46 | #else |
bsalomon@google.com | 0a09eef | 2011-06-29 19:42:58 +0000 | [diff] [blame] | 47 | #define CAN_IMAGE_PDF 0 |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 48 | #endif |
| 49 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 50 | typedef int ErrorBitfield; |
| 51 | const static ErrorBitfield ERROR_NONE = 0x00; |
| 52 | const static ErrorBitfield ERROR_NO_GPU_CONTEXT = 0x01; |
| 53 | const static ErrorBitfield ERROR_PIXEL_MISMATCH = 0x02; |
| 54 | const static ErrorBitfield ERROR_DIMENSION_MISMATCH = 0x04; |
| 55 | const static ErrorBitfield ERROR_READING_REFERENCE_IMAGE = 0x08; |
| 56 | const static ErrorBitfield ERROR_WRITING_REFERENCE_IMAGE = 0x10; |
| 57 | |
reed@google.com | e8fcb50 | 2012-05-17 15:28:20 +0000 | [diff] [blame] | 58 | // If true, emit a messange when we can't find a reference image to compare |
| 59 | static bool gNotifyMissingReadReference; |
| 60 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 61 | using namespace skiagm; |
| 62 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 63 | class Iter { |
| 64 | public: |
| 65 | Iter() { |
bsalomon@google.com | 3914958 | 2011-06-13 21:55:32 +0000 | [diff] [blame] | 66 | this->reset(); |
| 67 | } |
| 68 | |
| 69 | void reset() { |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 70 | fReg = GMRegistry::Head(); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 71 | } |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 72 | |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 73 | GM* next() { |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 74 | if (fReg) { |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 75 | GMRegistry::Factory fact = fReg->factory(); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 76 | fReg = fReg->next(); |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 77 | return fact(0); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 78 | } |
| 79 | return NULL; |
| 80 | } |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 81 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 82 | static int Count() { |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 83 | const GMRegistry* reg = GMRegistry::Head(); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 84 | int count = 0; |
| 85 | while (reg) { |
| 86 | count += 1; |
| 87 | reg = reg->next(); |
| 88 | } |
| 89 | return count; |
| 90 | } |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 91 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 92 | private: |
| 93 | const GMRegistry* fReg; |
| 94 | }; |
| 95 | |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 96 | static SkString make_name(const char shortName[], const char configName[]) { |
| 97 | SkString name(shortName); |
| 98 | name.appendf("_%s", configName); |
| 99 | return name; |
| 100 | } |
| 101 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 102 | static SkString make_filename(const char path[], |
| 103 | const char pathSuffix[], |
| 104 | const SkString& name, |
| 105 | const char suffix[]) { |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 106 | SkString filename(path); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 107 | if (filename.endsWith("/")) { |
| 108 | filename.remove(filename.size() - 1, 1); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 109 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 110 | filename.append(pathSuffix); |
| 111 | filename.append("/"); |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 112 | filename.appendf("%s.%s", name.c_str(), suffix); |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 113 | return filename; |
| 114 | } |
| 115 | |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 116 | /* since PNG insists on unpremultiplying our alpha, we take no precision chances |
| 117 | and force all pixels to be 100% opaque, otherwise on compare we may not get |
| 118 | a perfect match. |
| 119 | */ |
| 120 | static void force_all_opaque(const SkBitmap& bitmap) { |
| 121 | SkAutoLockPixels lock(bitmap); |
| 122 | for (int y = 0; y < bitmap.height(); y++) { |
| 123 | for (int x = 0; x < bitmap.width(); x++) { |
| 124 | *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT); |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | static bool write_bitmap(const SkString& path, const SkBitmap& bitmap) { |
| 130 | SkBitmap copy; |
| 131 | bitmap.copyTo(©, SkBitmap::kARGB_8888_Config); |
| 132 | force_all_opaque(copy); |
| 133 | return SkImageEncoder::EncodeFile(path.c_str(), copy, |
| 134 | SkImageEncoder::kPNG_Type, 100); |
| 135 | } |
| 136 | |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 137 | static inline SkPMColor compute_diff_pmcolor(SkPMColor c0, SkPMColor c1) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 138 | int dr = SkGetPackedR32(c0) - SkGetPackedR32(c1); |
| 139 | int dg = SkGetPackedG32(c0) - SkGetPackedG32(c1); |
| 140 | int db = SkGetPackedB32(c0) - SkGetPackedB32(c1); |
| 141 | return SkPackARGB32(0xFF, SkAbs32(dr), SkAbs32(dg), SkAbs32(db)); |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | static void compute_diff(const SkBitmap& target, const SkBitmap& base, |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 145 | SkBitmap* diff) { |
| 146 | SkAutoLockPixels alp(*diff); |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 147 | |
| 148 | const int w = target.width(); |
| 149 | const int h = target.height(); |
| 150 | for (int y = 0; y < h; y++) { |
| 151 | for (int x = 0; x < w; x++) { |
| 152 | SkPMColor c0 = *base.getAddr32(x, y); |
| 153 | SkPMColor c1 = *target.getAddr32(x, y); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 154 | SkPMColor d = 0; |
| 155 | if (c0 != c1) { |
| 156 | d = compute_diff_pmcolor(c0, c1); |
| 157 | } |
| 158 | *diff->getAddr32(x, y) = d; |
| 159 | } |
| 160 | } |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 161 | } |
| 162 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 163 | static ErrorBitfield compare(const SkBitmap& target, const SkBitmap& base, |
| 164 | const SkString& name, |
| 165 | const char* renderModeDescriptor, |
| 166 | SkBitmap* diff) { |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 167 | SkBitmap copy; |
| 168 | const SkBitmap* bm = ⌖ |
| 169 | if (target.config() != SkBitmap::kARGB_8888_Config) { |
| 170 | target.copyTo(©, SkBitmap::kARGB_8888_Config); |
| 171 | bm = © |
| 172 | } |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 173 | SkBitmap baseCopy; |
| 174 | const SkBitmap* bp = &base; |
| 175 | if (base.config() != SkBitmap::kARGB_8888_Config) { |
| 176 | base.copyTo(&baseCopy, SkBitmap::kARGB_8888_Config); |
| 177 | bp = &baseCopy; |
| 178 | } |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 179 | |
| 180 | force_all_opaque(*bm); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 181 | force_all_opaque(*bp); |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 182 | |
| 183 | const int w = bm->width(); |
| 184 | const int h = bm->height(); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 185 | if (w != bp->width() || h != bp->height()) { |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 186 | SkDebugf( |
| 187 | "---- %s dimensions mismatch for %s base [%d %d] current [%d %d]\n", |
| 188 | renderModeDescriptor, name.c_str(), |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 189 | bp->width(), bp->height(), w, h); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 190 | return ERROR_DIMENSION_MISMATCH; |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | SkAutoLockPixels bmLock(*bm); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 194 | SkAutoLockPixels baseLock(*bp); |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 195 | |
| 196 | for (int y = 0; y < h; y++) { |
| 197 | for (int x = 0; x < w; x++) { |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 198 | SkPMColor c0 = *bp->getAddr32(x, y); |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 199 | SkPMColor c1 = *bm->getAddr32(x, y); |
| 200 | if (c0 != c1) { |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 201 | SkDebugf( |
| 202 | "----- %s pixel mismatch for %s at [%d %d] base 0x%08X current 0x%08X\n", |
| 203 | renderModeDescriptor, name.c_str(), x, y, c0, c1); |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 204 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 205 | if (diff) { |
| 206 | diff->setConfig(SkBitmap::kARGB_8888_Config, w, h); |
| 207 | diff->allocPixels(); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 208 | compute_diff(*bm, *bp, diff); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 209 | } |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 210 | return ERROR_PIXEL_MISMATCH; |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 211 | } |
| 212 | } |
| 213 | } |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 214 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 215 | // they're equal |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 216 | return ERROR_NONE; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 217 | } |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 218 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 219 | static bool write_document(const SkString& path, |
| 220 | const SkDynamicMemoryWStream& document) { |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 221 | SkFILEWStream stream(path.c_str()); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 222 | SkAutoDataUnref data(document.copyToData()); |
reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 223 | return stream.writeData(data.get()); |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 224 | } |
| 225 | |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 226 | enum Backend { |
| 227 | kRaster_Backend, |
| 228 | kGPU_Backend, |
| 229 | kPDF_Backend, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 230 | kXPS_Backend, |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 231 | }; |
| 232 | |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 233 | enum ConfigFlags { |
| 234 | kNone_ConfigFlag = 0x0, |
| 235 | /* Write GM images if a write path is provided. */ |
| 236 | kWrite_ConfigFlag = 0x1, |
| 237 | /* Read comparison GM images if a read path is provided. */ |
| 238 | kRead_ConfigFlag = 0x2, |
| 239 | kRW_ConfigFlag = (kWrite_ConfigFlag | kRead_ConfigFlag), |
| 240 | }; |
| 241 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 242 | struct ConfigData { |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 243 | SkBitmap::Config fConfig; |
| 244 | Backend fBackend; |
| 245 | GrContextFactory::GLContextType fGLContextType; // GPU backend only |
| 246 | int fSampleCnt; // GPU backend only |
| 247 | ConfigFlags fFlags; |
| 248 | const char* fName; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 249 | }; |
| 250 | |
| 251 | /// Returns true if processing should continue, false to skip the |
| 252 | /// remainder of this config for this GM. |
| 253 | //@todo thudson 22 April 2011 - could refactor this to take in |
| 254 | // a factory to generate the context, always call readPixels() |
| 255 | // (logically a noop for rasters, if wasted time), and thus collapse the |
| 256 | // GPU special case and also let this be used for SkPicture testing. |
| 257 | static void setup_bitmap(const ConfigData& gRec, SkISize& size, |
| 258 | SkBitmap* bitmap) { |
| 259 | bitmap->setConfig(gRec.fConfig, size.width(), size.height()); |
| 260 | bitmap->allocPixels(); |
| 261 | bitmap->eraseColor(0); |
| 262 | } |
| 263 | |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 264 | #include "SkDrawFilter.h" |
| 265 | class BWTextDrawFilter : public SkDrawFilter { |
| 266 | public: |
| 267 | virtual void filter(SkPaint*, Type) SK_OVERRIDE; |
| 268 | }; |
| 269 | void BWTextDrawFilter::filter(SkPaint* p, Type t) { |
| 270 | if (kText_Type == t) { |
| 271 | p->setAntiAlias(false); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | static void installFilter(SkCanvas* canvas) { |
| 276 | if (gForceBWtext) { |
| 277 | canvas->setDrawFilter(new BWTextDrawFilter)->unref(); |
| 278 | } |
| 279 | } |
| 280 | |
vandebo@chromium.org | 79d3cb4 | 2012-03-21 17:34:30 +0000 | [diff] [blame] | 281 | static void invokeGM(GM* gm, SkCanvas* canvas, bool isPDF = false) { |
reed@google.com | 778e163 | 2012-06-04 20:00:01 +0000 | [diff] [blame] | 282 | SkAutoCanvasRestore acr(canvas, true); |
| 283 | |
vandebo@chromium.org | 79d3cb4 | 2012-03-21 17:34:30 +0000 | [diff] [blame] | 284 | if (!isPDF) { |
reed@google.com | 778e163 | 2012-06-04 20:00:01 +0000 | [diff] [blame] | 285 | canvas->concat(gm->getInitialTransform()); |
vandebo@chromium.org | 79d3cb4 | 2012-03-21 17:34:30 +0000 | [diff] [blame] | 286 | } |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 287 | installFilter(canvas); |
| 288 | gm->draw(canvas); |
| 289 | canvas->setDrawFilter(NULL); |
| 290 | } |
| 291 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 292 | static ErrorBitfield generate_image(GM* gm, const ConfigData& gRec, |
| 293 | GrContext* context, |
| 294 | GrRenderTarget* rt, |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 295 | SkBitmap* bitmap, |
| 296 | bool deferred) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 297 | SkISize size (gm->getISize()); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 298 | setup_bitmap(gRec, size, bitmap); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 299 | |
| 300 | if (gRec.fBackend == kRaster_Backend) { |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 301 | SkCanvas* canvas; |
| 302 | if (deferred) { |
| 303 | canvas = new SkDeferredCanvas; |
| 304 | canvas->setDevice(new SkDevice(*bitmap))->unref(); |
| 305 | } else { |
| 306 | canvas = new SkCanvas(*bitmap); |
| 307 | } |
| 308 | SkAutoUnref canvasUnref(canvas); |
| 309 | invokeGM(gm, canvas); |
junov@chromium.org | bf6c1e4 | 2012-01-30 14:53:22 +0000 | [diff] [blame] | 310 | canvas->flush(); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 311 | } else { // GPU |
| 312 | if (NULL == context) { |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 313 | return ERROR_NO_GPU_CONTEXT; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 314 | } |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 315 | SkCanvas* gc; |
| 316 | if (deferred) { |
| 317 | gc = new SkDeferredCanvas; |
| 318 | } else { |
| 319 | gc = new SkGpuCanvas(context, rt); |
| 320 | } |
| 321 | SkAutoUnref gcUnref(gc); |
| 322 | gc->setDevice(new SkGpuDevice(context, rt))->unref(); |
| 323 | invokeGM(gm, gc); |
reed@google.com | af951c9 | 2011-06-16 19:10:39 +0000 | [diff] [blame] | 324 | // the device is as large as the current rendertarget, so we explicitly |
| 325 | // only readback the amount we expect (in size) |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 326 | // overwrite our previous allocation |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 327 | bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth, |
| 328 | size.fHeight); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 329 | gc->readPixels(bitmap, 0, 0); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 330 | } |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 331 | return ERROR_NONE; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | static void generate_image_from_picture(GM* gm, const ConfigData& gRec, |
| 335 | SkPicture* pict, SkBitmap* bitmap) { |
| 336 | SkISize size = gm->getISize(); |
| 337 | setup_bitmap(gRec, size, bitmap); |
| 338 | SkCanvas canvas(*bitmap); |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 339 | installFilter(&canvas); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 340 | canvas.drawPicture(*pict); |
| 341 | } |
| 342 | |
| 343 | static void generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) { |
| 344 | #ifdef SK_SUPPORT_PDF |
vandebo@chromium.org | 79d3cb4 | 2012-03-21 17:34:30 +0000 | [diff] [blame] | 345 | SkMatrix initialTransform = gm->getInitialTransform(); |
| 346 | SkISize pageSize = gm->getISize(); |
| 347 | SkPDFDevice* dev = NULL; |
| 348 | if (initialTransform.isIdentity()) { |
| 349 | dev = new SkPDFDevice(pageSize, pageSize, initialTransform); |
| 350 | } else { |
| 351 | SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()), |
| 352 | SkIntToScalar(pageSize.height())); |
| 353 | initialTransform.mapRect(&content); |
| 354 | content.intersect(0, 0, SkIntToScalar(pageSize.width()), |
| 355 | SkIntToScalar(pageSize.height())); |
| 356 | SkISize contentSize = |
| 357 | SkISize::Make(SkScalarRoundToInt(content.width()), |
| 358 | SkScalarRoundToInt(content.height())); |
| 359 | dev = new SkPDFDevice(pageSize, contentSize, initialTransform); |
| 360 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 361 | SkAutoUnref aur(dev); |
| 362 | |
| 363 | SkCanvas c(dev); |
vandebo@chromium.org | 79d3cb4 | 2012-03-21 17:34:30 +0000 | [diff] [blame] | 364 | invokeGM(gm, &c, true); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 365 | |
| 366 | SkPDFDocument doc; |
| 367 | doc.appendPage(dev); |
| 368 | doc.emitPDF(&pdf); |
| 369 | #endif |
| 370 | } |
| 371 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 372 | static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) { |
| 373 | #ifdef SK_SUPPORT_XPS |
| 374 | SkISize size = gm->getISize(); |
| 375 | |
| 376 | SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()), |
| 377 | SkIntToScalar(size.height())); |
bungeman@google.com | dc9a695 | 2012-01-05 16:56:29 +0000 | [diff] [blame] | 378 | static const SkScalar inchesPerMeter = SkScalarDiv(10000, 254); |
| 379 | static const SkScalar upm = 72 * inchesPerMeter; |
| 380 | SkVector unitsPerMeter = SkPoint::Make(upm, upm); |
| 381 | static const SkScalar ppm = 200 * inchesPerMeter; |
| 382 | SkVector pixelsPerMeter = SkPoint::Make(ppm, ppm); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 383 | |
| 384 | SkXPSDevice* dev = new SkXPSDevice(); |
| 385 | SkAutoUnref aur(dev); |
| 386 | |
| 387 | SkCanvas c(dev); |
| 388 | dev->beginPortfolio(&xps); |
| 389 | dev->beginSheet(unitsPerMeter, pixelsPerMeter, trimSize); |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 390 | invokeGM(gm, &c); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 391 | dev->endSheet(); |
| 392 | dev->endPortfolio(); |
| 393 | |
| 394 | #endif |
| 395 | } |
| 396 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 397 | static ErrorBitfield write_reference_image(const ConfigData& gRec, |
| 398 | const char writePath [], |
| 399 | const char renderModeDescriptor [], |
| 400 | const SkString& name, |
| 401 | SkBitmap& bitmap, |
| 402 | SkDynamicMemoryWStream* document) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 403 | SkString path; |
| 404 | bool success = false; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 405 | if (gRec.fBackend == kRaster_Backend || |
| 406 | gRec.fBackend == kGPU_Backend || |
| 407 | (gRec.fBackend == kPDF_Backend && CAN_IMAGE_PDF)) { |
| 408 | |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 409 | path = make_filename(writePath, renderModeDescriptor, name, "png"); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 410 | success = write_bitmap(path, bitmap); |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 411 | } |
| 412 | if (kPDF_Backend == gRec.fBackend) { |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 413 | path = make_filename(writePath, renderModeDescriptor, name, "pdf"); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 414 | success = write_document(path, *document); |
| 415 | } |
| 416 | if (kXPS_Backend == gRec.fBackend) { |
| 417 | path = make_filename(writePath, renderModeDescriptor, name, "xps"); |
| 418 | success = write_document(path, *document); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 419 | } |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 420 | if (success) { |
| 421 | return ERROR_NONE; |
| 422 | } else { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 423 | fprintf(stderr, "FAILED to write %s\n", path.c_str()); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 424 | return ERROR_WRITING_REFERENCE_IMAGE; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 428 | static ErrorBitfield compare_to_reference_image(const SkString& name, |
| 429 | SkBitmap &bitmap, |
| 430 | const SkBitmap& comparisonBitmap, |
| 431 | const char diffPath [], |
| 432 | const char renderModeDescriptor []) { |
| 433 | ErrorBitfield errors; |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 434 | SkBitmap diffBitmap; |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 435 | errors = compare(bitmap, comparisonBitmap, name, renderModeDescriptor, |
| 436 | diffPath ? &diffBitmap : NULL); |
reed@google.com | 8e529b7 | 2012-04-09 20:20:10 +0000 | [diff] [blame] | 437 | if ((ERROR_NONE != errors) && diffPath) { |
| 438 | // write out the generated image |
| 439 | SkString genName = make_filename(diffPath, "", name, "png"); |
| 440 | if (!write_bitmap(genName, bitmap)) { |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 441 | errors |= ERROR_WRITING_REFERENCE_IMAGE; |
| 442 | } |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 443 | } |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 444 | return errors; |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 445 | } |
| 446 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 447 | static ErrorBitfield compare_to_reference_image(const char readPath [], |
| 448 | const SkString& name, |
| 449 | SkBitmap &bitmap, |
| 450 | const char diffPath [], |
| 451 | const char renderModeDescriptor []) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 452 | SkString path = make_filename(readPath, "", name, "png"); |
| 453 | SkBitmap orig; |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 454 | if (SkImageDecoder::DecodeFile(path.c_str(), &orig, |
| 455 | SkBitmap::kARGB_8888_Config, |
| 456 | SkImageDecoder::kDecodePixels_Mode, NULL)) { |
| 457 | return compare_to_reference_image(name, bitmap, |
| 458 | orig, diffPath, |
| 459 | renderModeDescriptor); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 460 | } else { |
reed@google.com | e8fcb50 | 2012-05-17 15:28:20 +0000 | [diff] [blame] | 461 | if (gNotifyMissingReadReference) { |
| 462 | fprintf(stderr, "FAILED to read %s\n", path.c_str()); |
| 463 | } |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 464 | return ERROR_READING_REFERENCE_IMAGE; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 465 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 466 | } |
| 467 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 468 | static ErrorBitfield handle_test_results(GM* gm, |
| 469 | const ConfigData& gRec, |
| 470 | const char writePath [], |
| 471 | const char readPath [], |
| 472 | const char diffPath [], |
| 473 | const char renderModeDescriptor [], |
| 474 | SkBitmap& bitmap, |
| 475 | SkDynamicMemoryWStream* pdf, |
| 476 | const SkBitmap* comparisonBitmap) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 477 | SkString name = make_name(gm->shortName(), gRec.fName); |
epoger@google.com | 9284ccd | 2012-04-18 13:36:54 +0000 | [diff] [blame] | 478 | ErrorBitfield retval = ERROR_NONE; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 479 | |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 480 | if (readPath && (gRec.fFlags & kRead_ConfigFlag)) { |
epoger@google.com | 9284ccd | 2012-04-18 13:36:54 +0000 | [diff] [blame] | 481 | retval |= compare_to_reference_image(readPath, name, bitmap, |
| 482 | diffPath, renderModeDescriptor); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 483 | } |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 484 | if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) { |
epoger@google.com | 9284ccd | 2012-04-18 13:36:54 +0000 | [diff] [blame] | 485 | retval |= write_reference_image(gRec, writePath, renderModeDescriptor, |
| 486 | name, bitmap, pdf); |
| 487 | } |
| 488 | if (comparisonBitmap) { |
| 489 | retval |= compare_to_reference_image(name, bitmap, |
| 490 | *comparisonBitmap, diffPath, |
| 491 | renderModeDescriptor); |
| 492 | } |
| 493 | return retval; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | static SkPicture* generate_new_picture(GM* gm) { |
| 497 | // Pictures are refcounted so must be on heap |
| 498 | SkPicture* pict = new SkPicture; |
| 499 | SkCanvas* cv = pict->beginRecording(1000, 1000); |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 500 | invokeGM(gm, cv); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 501 | pict->endRecording(); |
| 502 | |
| 503 | return pict; |
| 504 | } |
| 505 | |
| 506 | static SkPicture* stream_to_new_picture(const SkPicture& src) { |
| 507 | |
| 508 | // To do in-memory commiunications with a stream, we need to: |
| 509 | // * create a dynamic memory stream |
| 510 | // * copy it into a buffer |
| 511 | // * create a read stream from it |
| 512 | // ?!?! |
| 513 | |
| 514 | SkDynamicMemoryWStream storage; |
| 515 | src.serialize(&storage); |
| 516 | |
| 517 | int streamSize = storage.getOffset(); |
| 518 | SkAutoMalloc dstStorage(streamSize); |
| 519 | void* dst = dstStorage.get(); |
| 520 | //char* dst = new char [streamSize]; |
| 521 | //@todo thudson 22 April 2011 when can we safely delete [] dst? |
| 522 | storage.copyTo(dst); |
| 523 | SkMemoryStream pictReadback(dst, streamSize); |
| 524 | SkPicture* retval = new SkPicture (&pictReadback); |
| 525 | return retval; |
| 526 | } |
| 527 | |
| 528 | // Test: draw into a bitmap or pdf. |
| 529 | // Depending on flags, possibly compare to an expected image |
| 530 | // and possibly output a diff image if it fails to match. |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 531 | static ErrorBitfield test_drawing(GM* gm, |
| 532 | const ConfigData& gRec, |
| 533 | const char writePath [], |
| 534 | const char readPath [], |
| 535 | const char diffPath [], |
| 536 | GrContext* context, |
| 537 | GrRenderTarget* rt, |
| 538 | SkBitmap* bitmap) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 539 | SkDynamicMemoryWStream document; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 540 | |
| 541 | if (gRec.fBackend == kRaster_Backend || |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 542 | gRec.fBackend == kGPU_Backend) { |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 543 | // Early exit if we can't generate the image. |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 544 | ErrorBitfield errors = generate_image(gm, gRec, context, rt, bitmap, |
| 545 | false); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 546 | if (ERROR_NONE != errors) { |
| 547 | return errors; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 548 | } |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 549 | } else if (gRec.fBackend == kPDF_Backend) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 550 | generate_pdf(gm, document); |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 551 | #if CAN_IMAGE_PDF |
bungeman@google.com | 0f1541f | 2011-10-10 13:47:06 +0000 | [diff] [blame] | 552 | SkAutoDataUnref data(document.copyToData()); |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 553 | SkMemoryStream stream(data.data(), data.size()); |
| 554 | SkPDFDocumentToBitmap(&stream, bitmap); |
| 555 | #endif |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 556 | } else if (gRec.fBackend == kXPS_Backend) { |
| 557 | generate_xps(gm, document); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 558 | } |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 559 | return handle_test_results(gm, gRec, writePath, readPath, diffPath, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 560 | "", *bitmap, &document, NULL); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 561 | } |
| 562 | |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 563 | static ErrorBitfield test_deferred_drawing(GM* gm, |
| 564 | const ConfigData& gRec, |
| 565 | const SkBitmap& comparisonBitmap, |
| 566 | const char diffPath [], |
| 567 | GrContext* context, |
| 568 | GrRenderTarget* rt) { |
| 569 | SkDynamicMemoryWStream document; |
| 570 | |
| 571 | if (gRec.fBackend == kRaster_Backend || |
| 572 | gRec.fBackend == kGPU_Backend) { |
| 573 | SkBitmap bitmap; |
| 574 | // Early exit if we can't generate the image, but this is |
| 575 | // expected in some cases, so don't report a test failure. |
| 576 | if (!generate_image(gm, gRec, context, rt, &bitmap, true)) { |
| 577 | return ERROR_NONE; |
| 578 | } |
| 579 | return handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 580 | "-deferred", bitmap, NULL, &comparisonBitmap); |
| 581 | } |
| 582 | return ERROR_NONE; |
| 583 | } |
| 584 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 585 | static ErrorBitfield test_picture_playback(GM* gm, |
| 586 | const ConfigData& gRec, |
| 587 | const SkBitmap& comparisonBitmap, |
| 588 | const char readPath [], |
| 589 | const char diffPath []) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 590 | SkPicture* pict = generate_new_picture(gm); |
| 591 | SkAutoUnref aur(pict); |
| 592 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 593 | if (kRaster_Backend == gRec.fBackend) { |
| 594 | SkBitmap bitmap; |
| 595 | generate_image_from_picture(gm, gRec, pict, &bitmap); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 596 | return handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 597 | "-replay", bitmap, NULL, &comparisonBitmap); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 598 | } else { |
| 599 | return ERROR_NONE; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 600 | } |
| 601 | } |
| 602 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 603 | static ErrorBitfield test_picture_serialization(GM* gm, |
| 604 | const ConfigData& gRec, |
| 605 | const SkBitmap& comparisonBitmap, |
| 606 | const char readPath [], |
| 607 | const char diffPath []) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 608 | SkPicture* pict = generate_new_picture(gm); |
| 609 | SkAutoUnref aurp(pict); |
| 610 | SkPicture* repict = stream_to_new_picture(*pict); |
| 611 | SkAutoUnref aurr(repict); |
| 612 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 613 | if (kRaster_Backend == gRec.fBackend) { |
| 614 | SkBitmap bitmap; |
| 615 | generate_image_from_picture(gm, gRec, repict, &bitmap); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 616 | return handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 617 | "-serialize", bitmap, NULL, &comparisonBitmap); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 618 | } else { |
| 619 | return ERROR_NONE; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 620 | } |
| 621 | } |
| 622 | |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 623 | struct PipeFlagComboData { |
| 624 | const char* name; |
| 625 | uint32_t flags; |
| 626 | }; |
| 627 | |
| 628 | static PipeFlagComboData gPipeWritingFlagCombos[] = { |
| 629 | { "", 0 }, |
| 630 | { " cross-process", SkGPipeWriter::kCrossProcess_Flag }, |
scroggo | b3c0f48 | 2012-07-02 19:07:57 +0000 | [diff] [blame] | 631 | { " cross-process, shared address", SkGPipeWriter::kCrossProcess_Flag |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 632 | | SkGPipeWriter::kSharedAddressSpace_SkGPipeFlag } |
| 633 | }; |
| 634 | |
scroggo@google.com | 5af9b20 | 2012-06-04 17:17:36 +0000 | [diff] [blame] | 635 | static ErrorBitfield test_pipe_playback(GM* gm, |
| 636 | const ConfigData& gRec, |
| 637 | const SkBitmap& comparisonBitmap, |
| 638 | const char readPath [], |
| 639 | const char diffPath []) { |
| 640 | if (kRaster_Backend != gRec.fBackend) { |
| 641 | return ERROR_NONE; |
| 642 | } |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 643 | ErrorBitfield errors = ERROR_NONE; |
| 644 | for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) { |
| 645 | SkBitmap bitmap; |
| 646 | SkISize size = gm->getISize(); |
| 647 | setup_bitmap(gRec, size, &bitmap); |
| 648 | SkCanvas canvas(bitmap); |
| 649 | PipeController pipeController(&canvas); |
| 650 | SkGPipeWriter writer; |
| 651 | SkCanvas* pipeCanvas = writer.startRecording(&pipeController, |
| 652 | gPipeWritingFlagCombos[i].flags); |
| 653 | invokeGM(gm, pipeCanvas); |
| 654 | writer.endRecording(); |
| 655 | SkString string("-pipe"); |
| 656 | string.append(gPipeWritingFlagCombos[i].name); |
| 657 | errors |= handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 658 | string.c_str(), bitmap, NULL, &comparisonBitmap); |
| 659 | if (errors != ERROR_NONE) { |
| 660 | break; |
| 661 | } |
| 662 | } |
| 663 | return errors; |
scroggo@google.com | 5af9b20 | 2012-06-04 17:17:36 +0000 | [diff] [blame] | 664 | } |
| 665 | |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 666 | static ErrorBitfield test_tiled_pipe_playback(GM* gm, |
| 667 | const ConfigData& gRec, |
| 668 | const SkBitmap& comparisonBitmap, |
| 669 | const char readPath [], |
| 670 | const char diffPath []) { |
| 671 | if (kRaster_Backend != gRec.fBackend) { |
| 672 | return ERROR_NONE; |
| 673 | } |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 674 | ErrorBitfield errors = ERROR_NONE; |
| 675 | for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) { |
| 676 | SkBitmap bitmap; |
| 677 | SkISize size = gm->getISize(); |
| 678 | setup_bitmap(gRec, size, &bitmap); |
| 679 | SkCanvas canvas(bitmap); |
| 680 | TiledPipeController pipeController(bitmap); |
| 681 | SkGPipeWriter writer; |
| 682 | SkCanvas* pipeCanvas = writer.startRecording(&pipeController, |
| 683 | gPipeWritingFlagCombos[i].flags); |
| 684 | invokeGM(gm, pipeCanvas); |
| 685 | writer.endRecording(); |
| 686 | SkString string("-pipe"); |
| 687 | string.append(gPipeWritingFlagCombos[i].name); |
| 688 | errors |= handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 689 | string.c_str(), bitmap, NULL, &comparisonBitmap); |
| 690 | if (errors != ERROR_NONE) { |
| 691 | break; |
| 692 | } |
| 693 | } |
| 694 | return errors; |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 695 | } |
| 696 | |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 697 | static void write_picture_serialization(GM* gm, const ConfigData& rec, |
| 698 | const char writePicturePath[]) { |
| 699 | // only do this once, so we pick raster |
| 700 | if (kRaster_Backend == rec.fBackend && |
| 701 | SkBitmap::kARGB_8888_Config == rec.fConfig) { |
| 702 | |
| 703 | SkAutoTUnref<SkPicture> pict(generate_new_picture(gm)); |
| 704 | |
| 705 | const char* pictureSuffix = "skp"; |
| 706 | SkString path = make_filename(writePicturePath, "", |
| 707 | SkString(gm->shortName()), pictureSuffix); |
| 708 | |
| 709 | SkFILEWStream stream(path.c_str()); |
| 710 | pict->serialize(&stream); |
| 711 | } |
| 712 | } |
| 713 | |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 714 | static const GrContextFactory::GLContextType kDontCare_GLContextType = |
| 715 | GrContextFactory::kNative_GLContextType; |
| 716 | |
| 717 | // If the platform does not support writing PNGs of PDFs then there will be no |
| 718 | // comparison images to read. However, we can always write the .pdf files |
| 719 | static const ConfigFlags kPDFConfigFlags = CAN_IMAGE_PDF ? kRW_ConfigFlag : |
| 720 | kWrite_ConfigFlag; |
| 721 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 722 | static const ConfigData gRec[] = { |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 723 | { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "8888" }, |
| 724 | { SkBitmap::kARGB_4444_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "4444" }, |
| 725 | { SkBitmap::kRGB_565_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "565" }, |
reed@google.com | 1a7e946 | 2011-06-20 13:21:24 +0000 | [diff] [blame] | 726 | #ifdef SK_SCALAR_IS_FLOAT |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 727 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 0, kRW_ConfigFlag, "gpu" }, |
| 728 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 16, kRW_ConfigFlag, "msaa16" }, |
| 729 | /* The debug context does not generate images */ |
| 730 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kDebug_GLContextType, 0, kNone_ConfigFlag, "debug" }, |
| 731 | #ifdef SK_ANGLE |
| 732 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 0, kRW_ConfigFlag, "angle" }, |
| 733 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 16, kRW_ConfigFlag, "anglemsaa16" }, |
| 734 | #endif |
| 735 | #ifdef SK_MESA |
| 736 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kMESA_GLContextType, 0, kRW_ConfigFlag, "mesa" }, |
| 737 | #endif |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 738 | #endif |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 739 | #ifdef SK_SUPPORT_XPS |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 740 | /* At present we have no way of comparing XPS files (either natively or by converting to PNG). */ |
| 741 | { SkBitmap::kARGB_8888_Config, kXPS_Backend, kDontCare_GLContextType, 0, kWrite_ConfigFlag, "xps" }, |
| 742 | #endif |
| 743 | #ifdef SK_SUPPORT_PDF |
| 744 | { SkBitmap::kARGB_8888_Config, kPDF_Backend, kDontCare_GLContextType, 0, kPDFConfigFlags, "pdf" }, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 745 | #endif |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 746 | }; |
| 747 | |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 748 | static void usage(const char * argv0) { |
| 749 | SkDebugf("%s\n", argv0); |
| 750 | SkDebugf(" [-w writePath] [-r readPath] [-d diffPath] [-i resourcePath]\n"); |
reed@google.com | e5f48b9 | 2012-06-22 15:27:39 +0000 | [diff] [blame] | 751 | SkDebugf(" [--config "); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 752 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 753 | if (i > 0) { |
| 754 | SkDebugf("|"); |
| 755 | } |
| 756 | SkDebugf(gRec[i].fName); |
| 757 | } |
| 758 | SkDebugf(" ]\n"); |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 759 | SkDebugf(" [--noreplay] [--nopipe] [--serialize] [--forceBWtext] [--nopdf] \n" |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 760 | " [--tiledPipe] \n" |
| 761 | " [--nodeferred] [--match substring] [--notexturecache]\n" |
| 762 | " [-h|--help]\n" |
| 763 | ); |
| 764 | SkDebugf(" writePath: directory to write rendered images in.\n"); |
| 765 | SkDebugf( |
| 766 | " readPath: directory to read reference images from;\n" |
| 767 | " reports if any pixels mismatch between reference and new images\n"); |
| 768 | SkDebugf(" diffPath: directory to write difference images in.\n"); |
| 769 | SkDebugf(" resourcePath: directory that stores image resources.\n"); |
| 770 | SkDebugf(" --noreplay: do not exercise SkPicture replay.\n"); |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 771 | SkDebugf(" --nopipe: Skip SkGPipe replay.\n"); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 772 | SkDebugf(" --tiledPipe: Exercise tiled SkGPipe replay.\n"); |
| 773 | SkDebugf( |
borenet@google.com | 14ca1d3 | 2012-06-15 13:46:44 +0000 | [diff] [blame] | 774 | " --serialize: exercise SkPicture serialization & deserialization.\n"); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 775 | SkDebugf(" --forceBWtext: disable text anti-aliasing.\n"); |
| 776 | SkDebugf(" --nopdf: skip the pdf rendering test pass.\n"); |
| 777 | SkDebugf(" --nodeferred: skip the deferred rendering test pass.\n"); |
| 778 | SkDebugf(" --match foo: will only run tests that substring match foo.\n"); |
| 779 | SkDebugf(" --notexturecache: disable the gpu texture cache.\n"); |
| 780 | SkDebugf(" -h|--help : Show this help message. \n"); |
| 781 | } |
| 782 | |
| 783 | static int findConfig(const char config[]) { |
| 784 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { |
| 785 | if (!strcmp(config, gRec[i].fName)) { |
| 786 | return i; |
| 787 | } |
| 788 | } |
| 789 | return -1; |
| 790 | } |
| 791 | |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 792 | static bool skip_name(const SkTDArray<const char*> array, const char name[]) { |
| 793 | if (0 == array.count()) { |
| 794 | // no names, so don't skip anything |
| 795 | return false; |
| 796 | } |
| 797 | for (int i = 0; i < array.count(); ++i) { |
| 798 | if (strstr(name, array[i])) { |
| 799 | // found the name, so don't skip |
| 800 | return false; |
| 801 | } |
| 802 | } |
| 803 | return true; |
| 804 | } |
| 805 | |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 806 | namespace skiagm { |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 807 | SkAutoTUnref<GrContext> gGrContext; |
| 808 | /** |
| 809 | * Sets the global GrContext, accessible by indivual GMs |
| 810 | */ |
caryclark@google.com | 1313086 | 2012-06-06 12:10:45 +0000 | [diff] [blame] | 811 | static void SetGr(GrContext* grContext) { |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 812 | SkSafeRef(grContext); |
| 813 | gGrContext.reset(grContext); |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 814 | } |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 815 | |
| 816 | /** |
| 817 | * Gets the global GrContext, can be called by GM tests. |
| 818 | */ |
caryclark@google.com | 1313086 | 2012-06-06 12:10:45 +0000 | [diff] [blame] | 819 | GrContext* GetGr(); |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 820 | GrContext* GetGr() { |
| 821 | return gGrContext.get(); |
| 822 | } |
| 823 | |
| 824 | /** |
| 825 | * Sets the global GrContext and then resets it to its previous value at |
| 826 | * destruction. |
| 827 | */ |
| 828 | class AutoResetGr : SkNoncopyable { |
| 829 | public: |
| 830 | AutoResetGr() : fOld(NULL) {} |
| 831 | void set(GrContext* context) { |
| 832 | SkASSERT(NULL == fOld); |
| 833 | fOld = GetGr(); |
| 834 | SkSafeRef(fOld); |
| 835 | SetGr(context); |
| 836 | } |
| 837 | ~AutoResetGr() { SetGr(fOld); SkSafeUnref(fOld); } |
| 838 | private: |
| 839 | GrContext* fOld; |
| 840 | }; |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 841 | } |
| 842 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 843 | int main(int argc, char * const argv[]) { |
robertphillips@google.com | b74af87 | 2012-06-27 19:41:42 +0000 | [diff] [blame] | 844 | |
| 845 | #ifdef SK_ENABLE_INST_COUNT |
| 846 | gPrintInstCount = true; |
| 847 | #endif |
| 848 | |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 849 | SkGraphics::Init(); |
reed@google.com | 8923c6c | 2011-11-08 14:59:38 +0000 | [diff] [blame] | 850 | // we don't need to see this during a run |
| 851 | gSkSuppressFontCachePurgeSpew = true; |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 852 | |
epoger@google.com | 7bc13a6 | 2012-02-14 14:53:59 +0000 | [diff] [blame] | 853 | setSystemPreferences(); |
| 854 | |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 855 | const char* writePath = NULL; // if non-null, where we write the originals |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 856 | const char* writePicturePath = NULL; // if non-null, where we write serialized pictures |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 857 | const char* readPath = NULL; // if non-null, were we read from to compare |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 858 | const char* diffPath = NULL; // if non-null, where we write our diffs (from compare) |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 859 | const char* resourcePath = NULL;// if non-null, where we read from for image resources |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 860 | |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 861 | SkTDArray<const char*> fMatches; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 862 | |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 863 | bool doPDF = true; |
reed@google.com | b8b0983 | 2011-05-26 15:57:56 +0000 | [diff] [blame] | 864 | bool doReplay = true; |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 865 | bool doPipe = true; |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 866 | bool doTiledPipe = false; |
borenet@google.com | 14ca1d3 | 2012-06-15 13:46:44 +0000 | [diff] [blame] | 867 | bool doSerialize = false; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 868 | bool doDeferred = true; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 869 | bool disableTextureCache = false; |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 870 | SkTDArray<size_t> configs; |
| 871 | bool userConfig = false; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 872 | |
reed@google.com | e8fcb50 | 2012-05-17 15:28:20 +0000 | [diff] [blame] | 873 | gNotifyMissingReadReference = true; |
| 874 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 875 | const char* const commandName = argv[0]; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 876 | char* const* stop = argv + argc; |
| 877 | for (++argv; argv < stop; ++argv) { |
| 878 | if (strcmp(*argv, "-w") == 0) { |
| 879 | argv++; |
| 880 | if (argv < stop && **argv) { |
| 881 | writePath = *argv; |
| 882 | } |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 883 | } else if (strcmp(*argv, "-wp") == 0) { |
| 884 | argv++; |
| 885 | if (argv < stop && **argv) { |
| 886 | writePicturePath = *argv; |
| 887 | } |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 888 | } else if (strcmp(*argv, "-r") == 0) { |
| 889 | argv++; |
| 890 | if (argv < stop && **argv) { |
| 891 | readPath = *argv; |
| 892 | } |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 893 | } else if (strcmp(*argv, "-d") == 0) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 894 | argv++; |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 895 | if (argv < stop && **argv) { |
| 896 | diffPath = *argv; |
| 897 | } |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 898 | } else if (strcmp(*argv, "-i") == 0) { |
| 899 | argv++; |
| 900 | if (argv < stop && **argv) { |
| 901 | resourcePath = *argv; |
| 902 | } |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 903 | } else if (strcmp(*argv, "--forceBWtext") == 0) { |
| 904 | gForceBWtext = true; |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 905 | } else if (strcmp(*argv, "--nopipe") == 0) { |
| 906 | doPipe = false; |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 907 | } else if (strcmp(*argv, "--tiledPipe") == 0) { |
| 908 | doTiledPipe = true; |
reed@google.com | b8b0983 | 2011-05-26 15:57:56 +0000 | [diff] [blame] | 909 | } else if (strcmp(*argv, "--noreplay") == 0) { |
| 910 | doReplay = false; |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 911 | } else if (strcmp(*argv, "--nopdf") == 0) { |
| 912 | doPDF = false; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 913 | } else if (strcmp(*argv, "--nodeferred") == 0) { |
| 914 | doDeferred = false; |
reed@google.com | e8fcb50 | 2012-05-17 15:28:20 +0000 | [diff] [blame] | 915 | } else if (strcmp(*argv, "--disable-missing-warning") == 0) { |
| 916 | gNotifyMissingReadReference = false; |
| 917 | } else if (strcmp(*argv, "--enable-missing-warning") == 0) { |
| 918 | gNotifyMissingReadReference = true; |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 919 | } else if (strcmp(*argv, "--serialize") == 0) { |
borenet@google.com | 14ca1d3 | 2012-06-15 13:46:44 +0000 | [diff] [blame] | 920 | doSerialize = true; |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 921 | } else if (strcmp(*argv, "--match") == 0) { |
| 922 | ++argv; |
| 923 | if (argv < stop && **argv) { |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 924 | // just record the ptr, no need for a deep copy |
| 925 | *fMatches.append() = *argv; |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 926 | } |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 927 | } else if (strcmp(*argv, "--notexturecache") == 0) { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 928 | disableTextureCache = true; |
reed@google.com | e5f48b9 | 2012-06-22 15:27:39 +0000 | [diff] [blame] | 929 | } else if (strcmp(*argv, "--config") == 0) { |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 930 | argv++; |
| 931 | if (argv < stop) { |
| 932 | int index = findConfig(*argv); |
| 933 | if (index >= 0) { |
| 934 | *configs.append() = index; |
| 935 | userConfig = true; |
| 936 | } else { |
| 937 | SkString str; |
| 938 | str.printf("unrecognized config %s\n", *argv); |
| 939 | SkDebugf(str.c_str()); |
| 940 | usage(commandName); |
| 941 | return -1; |
| 942 | } |
| 943 | } else { |
reed@google.com | e5f48b9 | 2012-06-22 15:27:39 +0000 | [diff] [blame] | 944 | SkDebugf("missing arg for --config\n"); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 945 | usage(commandName); |
| 946 | return -1; |
| 947 | } |
| 948 | } else if (strcmp(*argv, "--help") == 0 || strcmp(*argv, "-h") == 0) { |
| 949 | usage(commandName); |
| 950 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 951 | } else { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 952 | usage(commandName); |
| 953 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 954 | } |
| 955 | } |
| 956 | if (argv != stop) { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 957 | usage(commandName); |
| 958 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 959 | } |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 960 | |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 961 | if (!userConfig) { |
| 962 | // if no config is specified by user, we add them all. |
| 963 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 964 | *configs.append() = i; |
| 965 | } |
| 966 | } |
| 967 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 968 | GM::SetResourcePath(resourcePath); |
| 969 | |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 970 | GrContextFactory* grFactory = new GrContextFactory; |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 971 | |
reed@android.com | 00f883e | 2010-12-14 17:46:14 +0000 | [diff] [blame] | 972 | if (readPath) { |
| 973 | fprintf(stderr, "reading from %s\n", readPath); |
epoger@google.com | 9284ccd | 2012-04-18 13:36:54 +0000 | [diff] [blame] | 974 | } |
| 975 | if (writePath) { |
reed@android.com | 00f883e | 2010-12-14 17:46:14 +0000 | [diff] [blame] | 976 | fprintf(stderr, "writing to %s\n", writePath); |
| 977 | } |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 978 | if (writePicturePath) { |
| 979 | fprintf(stderr, "writing pictures to %s\n", writePicturePath); |
| 980 | } |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 981 | if (resourcePath) { |
| 982 | fprintf(stderr, "reading resources from %s\n", resourcePath); |
| 983 | } |
| 984 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 985 | // Accumulate success of all tests. |
| 986 | int testsRun = 0; |
| 987 | int testsPassed = 0; |
| 988 | int testsFailed = 0; |
| 989 | int testsMissingReferenceImages = 0; |
| 990 | |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 991 | if (disableTextureCache) { |
| 992 | skiagm::GetGr()->setTextureCacheLimits(0, 0); |
| 993 | } |
| 994 | |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 995 | Iter iter; |
| 996 | GM* gm; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 997 | while ((gm = iter.next()) != NULL) { |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 998 | const char* shortName = gm->shortName(); |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 999 | if (skip_name(fMatches, shortName)) { |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 1000 | SkDELETE(gm); |
| 1001 | continue; |
| 1002 | } |
| 1003 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1004 | SkISize size = gm->getISize(); |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 1005 | SkDebugf("drawing... %s [%d %d]\n", shortName, |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 1006 | size.width(), size.height()); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 1007 | SkBitmap forwardRenderedBitmap; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 1008 | |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1009 | for (int i = 0; i < configs.count(); i++) { |
| 1010 | ConfigData config = gRec[configs[i]]; |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1011 | SkAutoTUnref<GrRenderTarget> rt; |
| 1012 | AutoResetGr autogr; |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1013 | if (kGPU_Backend == config.fBackend) { |
| 1014 | GrContext* gr = grFactory->get(config.fGLContextType); |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1015 | if (!gr) { |
| 1016 | continue; |
| 1017 | } |
| 1018 | |
| 1019 | // create a render target to back the device |
| 1020 | GrTextureDesc desc; |
| 1021 | desc.fConfig = kSkia8888_PM_GrPixelConfig; |
| 1022 | desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 1023 | desc.fWidth = gm->getISize().width(); |
| 1024 | desc.fHeight = gm->getISize().height(); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1025 | desc.fSampleCnt = config.fSampleCnt; |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1026 | GrTexture* tex = gr->createUncachedTexture(desc, NULL, 0); |
| 1027 | if (!tex) { |
bsalomon@google.com | daf12bb | 2012-04-20 19:08:44 +0000 | [diff] [blame] | 1028 | continue; |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1029 | } |
| 1030 | rt.reset(tex->asRenderTarget()); |
| 1031 | rt.get()->ref(); |
| 1032 | tex->unref(); |
| 1033 | |
| 1034 | autogr.set(gr); |
| 1035 | } |
| 1036 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1037 | // Skip any tests that we don't even need to try. |
bsalomon@google.com | 29d3501 | 2011-11-30 16:57:21 +0000 | [diff] [blame] | 1038 | uint32_t gmFlags = gm->getFlags(); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1039 | if ((kPDF_Backend == config.fBackend) && |
bungeman@google.com | 64e011a | 2011-09-19 19:31:04 +0000 | [diff] [blame] | 1040 | (!doPDF || (gmFlags & GM::kSkipPDF_Flag))) |
| 1041 | { |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 1042 | continue; |
| 1043 | } |
| 1044 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1045 | // Now we know that we want to run this test and record its |
| 1046 | // success or failure. |
| 1047 | ErrorBitfield testErrors = ERROR_NONE; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1048 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1049 | if ((ERROR_NONE == testErrors) && |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1050 | (kGPU_Backend == config.fBackend) && |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1051 | (NULL == rt.get())) { |
| 1052 | fprintf(stderr, "Could not create render target for gpu.\n"); |
| 1053 | testErrors |= ERROR_NO_GPU_CONTEXT; |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 1054 | } |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 1055 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1056 | if (ERROR_NONE == testErrors) { |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1057 | testErrors |= test_drawing(gm, config, |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1058 | writePath, readPath, diffPath, |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1059 | GetGr(), |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1060 | rt.get(), &forwardRenderedBitmap); |
| 1061 | } |
| 1062 | |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 1063 | if (doDeferred && !testErrors && |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1064 | (kGPU_Backend == config.fBackend || |
| 1065 | kRaster_Backend == config.fBackend)) { |
| 1066 | testErrors |= test_deferred_drawing(gm, config, |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 1067 | forwardRenderedBitmap, |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1068 | diffPath, GetGr(), rt.get()); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1071 | if ((ERROR_NONE == testErrors) && doReplay && |
| 1072 | !(gmFlags & GM::kSkipPicture_Flag)) { |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1073 | testErrors |= test_picture_playback(gm, config, |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1074 | forwardRenderedBitmap, |
| 1075 | readPath, diffPath); |
| 1076 | } |
| 1077 | |
scroggo@google.com | 5af9b20 | 2012-06-04 17:17:36 +0000 | [diff] [blame] | 1078 | if ((ERROR_NONE == testErrors) && doPipe && |
| 1079 | !(gmFlags & GM::kSkipPipe_Flag)) { |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1080 | testErrors |= test_pipe_playback(gm, config, |
scroggo@google.com | 5af9b20 | 2012-06-04 17:17:36 +0000 | [diff] [blame] | 1081 | forwardRenderedBitmap, |
| 1082 | readPath, diffPath); |
| 1083 | } |
| 1084 | |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 1085 | if ((ERROR_NONE == testErrors) && doTiledPipe && |
| 1086 | !(gmFlags & GM::kSkipPipe_Flag)) { |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1087 | testErrors |= test_tiled_pipe_playback(gm, config, |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 1088 | forwardRenderedBitmap, |
| 1089 | readPath, diffPath); |
| 1090 | } |
| 1091 | |
djsollen@google.com | a2ca41e | 2012-03-23 19:00:34 +0000 | [diff] [blame] | 1092 | if ((ERROR_NONE == testErrors) && doSerialize && |
| 1093 | !(gmFlags & GM::kSkipPicture_Flag)) { |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1094 | testErrors |= test_picture_serialization(gm, config, |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1095 | forwardRenderedBitmap, |
| 1096 | readPath, diffPath); |
| 1097 | } |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 1098 | |
| 1099 | if (!(gmFlags & GM::kSkipPicture_Flag) && writePicturePath) { |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1100 | write_picture_serialization(gm, config, writePicturePath); |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 1101 | } |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1102 | |
| 1103 | // Update overall results. |
| 1104 | // We only tabulate the particular error types that we currently |
| 1105 | // care about (e.g., missing reference images). Later on, if we |
| 1106 | // want to also tabulate pixel mismatches vs dimension mistmatches |
| 1107 | // (or whatever else), we can do so. |
| 1108 | testsRun++; |
| 1109 | if (ERROR_NONE == testErrors) { |
| 1110 | testsPassed++; |
| 1111 | } else if (ERROR_READING_REFERENCE_IMAGE & testErrors) { |
| 1112 | testsMissingReferenceImages++; |
| 1113 | } else { |
| 1114 | testsFailed++; |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 1115 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1116 | } |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1117 | SkDELETE(gm); |
| 1118 | } |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1119 | printf("Ran %d tests: %d passed, %d failed, %d missing reference images\n", |
| 1120 | testsRun, testsPassed, testsFailed, testsMissingReferenceImages); |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 1121 | |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 1122 | delete grFactory; |
| 1123 | SkGraphics::Term(); |
| 1124 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1125 | return (0 == testsFailed) ? 0 : -1; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1126 | } |