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 | 5af9b20 | 2012-06-04 17:17:36 +0000 | [diff] [blame] | 623 | static ErrorBitfield test_pipe_playback(GM* gm, |
| 624 | const ConfigData& gRec, |
| 625 | const SkBitmap& comparisonBitmap, |
| 626 | const char readPath [], |
| 627 | const char diffPath []) { |
| 628 | if (kRaster_Backend != gRec.fBackend) { |
| 629 | return ERROR_NONE; |
| 630 | } |
| 631 | SkBitmap bitmap; |
| 632 | SkISize size = gm->getISize(); |
| 633 | setup_bitmap(gRec, size, &bitmap); |
| 634 | SkCanvas canvas(bitmap); |
| 635 | PipeController pipeController(&canvas); |
| 636 | SkGPipeWriter writer; |
| 637 | SkCanvas* pipeCanvas = writer.startRecording(&pipeController, |
| 638 | SkGPipeWriter::kCrossProcess_Flag); |
| 639 | invokeGM(gm, pipeCanvas); |
| 640 | writer.endRecording(); |
| 641 | return handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 642 | "-pipe", bitmap, NULL, &comparisonBitmap); |
| 643 | } |
| 644 | |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 645 | static ErrorBitfield test_tiled_pipe_playback(GM* gm, |
| 646 | const ConfigData& gRec, |
| 647 | const SkBitmap& comparisonBitmap, |
| 648 | const char readPath [], |
| 649 | const char diffPath []) { |
| 650 | if (kRaster_Backend != gRec.fBackend) { |
| 651 | return ERROR_NONE; |
| 652 | } |
| 653 | SkBitmap bitmap; |
| 654 | SkISize size = gm->getISize(); |
| 655 | setup_bitmap(gRec, size, &bitmap); |
| 656 | TiledPipeController pipeController(bitmap); |
| 657 | SkGPipeWriter writer; |
| 658 | SkCanvas* pipeCanvas = writer.startRecording(&pipeController, |
| 659 | SkGPipeWriter::kCrossProcess_Flag); |
| 660 | invokeGM(gm, pipeCanvas); |
| 661 | writer.endRecording(); |
| 662 | return handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 663 | "-tiled pipe", bitmap, NULL, &comparisonBitmap); |
| 664 | } |
| 665 | |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 666 | static void write_picture_serialization(GM* gm, const ConfigData& rec, |
| 667 | const char writePicturePath[]) { |
| 668 | // only do this once, so we pick raster |
| 669 | if (kRaster_Backend == rec.fBackend && |
| 670 | SkBitmap::kARGB_8888_Config == rec.fConfig) { |
| 671 | |
| 672 | SkAutoTUnref<SkPicture> pict(generate_new_picture(gm)); |
| 673 | |
| 674 | const char* pictureSuffix = "skp"; |
| 675 | SkString path = make_filename(writePicturePath, "", |
| 676 | SkString(gm->shortName()), pictureSuffix); |
| 677 | |
| 678 | SkFILEWStream stream(path.c_str()); |
| 679 | pict->serialize(&stream); |
| 680 | } |
| 681 | } |
| 682 | |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 683 | static const GrContextFactory::GLContextType kDontCare_GLContextType = |
| 684 | GrContextFactory::kNative_GLContextType; |
| 685 | |
| 686 | // If the platform does not support writing PNGs of PDFs then there will be no |
| 687 | // comparison images to read. However, we can always write the .pdf files |
| 688 | static const ConfigFlags kPDFConfigFlags = CAN_IMAGE_PDF ? kRW_ConfigFlag : |
| 689 | kWrite_ConfigFlag; |
| 690 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 691 | static const ConfigData gRec[] = { |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 692 | { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "8888" }, |
| 693 | { SkBitmap::kARGB_4444_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "4444" }, |
| 694 | { 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] | 695 | #ifdef SK_SCALAR_IS_FLOAT |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 696 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 0, kRW_ConfigFlag, "gpu" }, |
| 697 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 16, kRW_ConfigFlag, "msaa16" }, |
| 698 | /* The debug context does not generate images */ |
| 699 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kDebug_GLContextType, 0, kNone_ConfigFlag, "debug" }, |
| 700 | #ifdef SK_ANGLE |
| 701 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 0, kRW_ConfigFlag, "angle" }, |
| 702 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 16, kRW_ConfigFlag, "anglemsaa16" }, |
| 703 | #endif |
| 704 | #ifdef SK_MESA |
| 705 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kMESA_GLContextType, 0, kRW_ConfigFlag, "mesa" }, |
| 706 | #endif |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 707 | #endif |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 708 | #ifdef SK_SUPPORT_XPS |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 709 | /* At present we have no way of comparing XPS files (either natively or by converting to PNG). */ |
| 710 | { SkBitmap::kARGB_8888_Config, kXPS_Backend, kDontCare_GLContextType, 0, kWrite_ConfigFlag, "xps" }, |
| 711 | #endif |
| 712 | #ifdef SK_SUPPORT_PDF |
| 713 | { SkBitmap::kARGB_8888_Config, kPDF_Backend, kDontCare_GLContextType, 0, kPDFConfigFlags, "pdf" }, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 714 | #endif |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 715 | }; |
| 716 | |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 717 | static void usage(const char * argv0) { |
| 718 | SkDebugf("%s\n", argv0); |
| 719 | SkDebugf(" [-w writePath] [-r readPath] [-d diffPath] [-i resourcePath]\n"); |
reed@google.com | e5f48b9 | 2012-06-22 15:27:39 +0000 | [diff] [blame] | 720 | SkDebugf(" [--config "); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 721 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 722 | if (i > 0) { |
| 723 | SkDebugf("|"); |
| 724 | } |
| 725 | SkDebugf(gRec[i].fName); |
| 726 | } |
| 727 | SkDebugf(" ]\n"); |
borenet@google.com | 14ca1d3 | 2012-06-15 13:46:44 +0000 | [diff] [blame] | 728 | SkDebugf(" [--noreplay] [--pipe] [--serialize] [--forceBWtext] [--nopdf] \n" |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 729 | " [--tiledPipe] \n" |
| 730 | " [--nodeferred] [--match substring] [--notexturecache]\n" |
| 731 | " [-h|--help]\n" |
| 732 | ); |
| 733 | SkDebugf(" writePath: directory to write rendered images in.\n"); |
| 734 | SkDebugf( |
| 735 | " readPath: directory to read reference images from;\n" |
| 736 | " reports if any pixels mismatch between reference and new images\n"); |
| 737 | SkDebugf(" diffPath: directory to write difference images in.\n"); |
| 738 | SkDebugf(" resourcePath: directory that stores image resources.\n"); |
| 739 | SkDebugf(" --noreplay: do not exercise SkPicture replay.\n"); |
| 740 | SkDebugf(" --pipe: Exercise SkGPipe replay.\n"); |
| 741 | SkDebugf(" --tiledPipe: Exercise tiled SkGPipe replay.\n"); |
| 742 | SkDebugf( |
borenet@google.com | 14ca1d3 | 2012-06-15 13:46:44 +0000 | [diff] [blame] | 743 | " --serialize: exercise SkPicture serialization & deserialization.\n"); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 744 | SkDebugf(" --forceBWtext: disable text anti-aliasing.\n"); |
| 745 | SkDebugf(" --nopdf: skip the pdf rendering test pass.\n"); |
| 746 | SkDebugf(" --nodeferred: skip the deferred rendering test pass.\n"); |
| 747 | SkDebugf(" --match foo: will only run tests that substring match foo.\n"); |
| 748 | SkDebugf(" --notexturecache: disable the gpu texture cache.\n"); |
| 749 | SkDebugf(" -h|--help : Show this help message. \n"); |
| 750 | } |
| 751 | |
| 752 | static int findConfig(const char config[]) { |
| 753 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { |
| 754 | if (!strcmp(config, gRec[i].fName)) { |
| 755 | return i; |
| 756 | } |
| 757 | } |
| 758 | return -1; |
| 759 | } |
| 760 | |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 761 | static bool skip_name(const SkTDArray<const char*> array, const char name[]) { |
| 762 | if (0 == array.count()) { |
| 763 | // no names, so don't skip anything |
| 764 | return false; |
| 765 | } |
| 766 | for (int i = 0; i < array.count(); ++i) { |
| 767 | if (strstr(name, array[i])) { |
| 768 | // found the name, so don't skip |
| 769 | return false; |
| 770 | } |
| 771 | } |
| 772 | return true; |
| 773 | } |
| 774 | |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 775 | namespace skiagm { |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 776 | SkAutoTUnref<GrContext> gGrContext; |
| 777 | /** |
| 778 | * Sets the global GrContext, accessible by indivual GMs |
| 779 | */ |
caryclark@google.com | 1313086 | 2012-06-06 12:10:45 +0000 | [diff] [blame] | 780 | static void SetGr(GrContext* grContext) { |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 781 | SkSafeRef(grContext); |
| 782 | gGrContext.reset(grContext); |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 783 | } |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 784 | |
| 785 | /** |
| 786 | * Gets the global GrContext, can be called by GM tests. |
| 787 | */ |
caryclark@google.com | 1313086 | 2012-06-06 12:10:45 +0000 | [diff] [blame] | 788 | GrContext* GetGr(); |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 789 | GrContext* GetGr() { |
| 790 | return gGrContext.get(); |
| 791 | } |
| 792 | |
| 793 | /** |
| 794 | * Sets the global GrContext and then resets it to its previous value at |
| 795 | * destruction. |
| 796 | */ |
| 797 | class AutoResetGr : SkNoncopyable { |
| 798 | public: |
| 799 | AutoResetGr() : fOld(NULL) {} |
| 800 | void set(GrContext* context) { |
| 801 | SkASSERT(NULL == fOld); |
| 802 | fOld = GetGr(); |
| 803 | SkSafeRef(fOld); |
| 804 | SetGr(context); |
| 805 | } |
| 806 | ~AutoResetGr() { SetGr(fOld); SkSafeUnref(fOld); } |
| 807 | private: |
| 808 | GrContext* fOld; |
| 809 | }; |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 810 | } |
| 811 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 812 | int main(int argc, char * const argv[]) { |
robertphillips@google.com | b74af87 | 2012-06-27 19:41:42 +0000 | [diff] [blame] | 813 | |
| 814 | #ifdef SK_ENABLE_INST_COUNT |
| 815 | gPrintInstCount = true; |
| 816 | #endif |
| 817 | |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 818 | SkGraphics::Init(); |
reed@google.com | 8923c6c | 2011-11-08 14:59:38 +0000 | [diff] [blame] | 819 | // we don't need to see this during a run |
| 820 | gSkSuppressFontCachePurgeSpew = true; |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 821 | |
epoger@google.com | 7bc13a6 | 2012-02-14 14:53:59 +0000 | [diff] [blame] | 822 | setSystemPreferences(); |
| 823 | |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 824 | 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] | 825 | 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] | 826 | 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] | 827 | 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] | 828 | 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] | 829 | |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 830 | SkTDArray<const char*> fMatches; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 831 | |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 832 | bool doPDF = true; |
reed@google.com | b8b0983 | 2011-05-26 15:57:56 +0000 | [diff] [blame] | 833 | bool doReplay = true; |
scroggo@google.com | d13bdfb | 2012-06-04 17:45:54 +0000 | [diff] [blame] | 834 | bool doPipe = false; |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 835 | bool doTiledPipe = false; |
borenet@google.com | 14ca1d3 | 2012-06-15 13:46:44 +0000 | [diff] [blame] | 836 | bool doSerialize = false; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 837 | bool doDeferred = true; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 838 | bool disableTextureCache = false; |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 839 | SkTDArray<size_t> configs; |
| 840 | bool userConfig = false; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 841 | |
reed@google.com | e8fcb50 | 2012-05-17 15:28:20 +0000 | [diff] [blame] | 842 | gNotifyMissingReadReference = true; |
| 843 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 844 | const char* const commandName = argv[0]; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 845 | char* const* stop = argv + argc; |
| 846 | for (++argv; argv < stop; ++argv) { |
| 847 | if (strcmp(*argv, "-w") == 0) { |
| 848 | argv++; |
| 849 | if (argv < stop && **argv) { |
| 850 | writePath = *argv; |
| 851 | } |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 852 | } else if (strcmp(*argv, "-wp") == 0) { |
| 853 | argv++; |
| 854 | if (argv < stop && **argv) { |
| 855 | writePicturePath = *argv; |
| 856 | } |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 857 | } else if (strcmp(*argv, "-r") == 0) { |
| 858 | argv++; |
| 859 | if (argv < stop && **argv) { |
| 860 | readPath = *argv; |
| 861 | } |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 862 | } else if (strcmp(*argv, "-d") == 0) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 863 | argv++; |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 864 | if (argv < stop && **argv) { |
| 865 | diffPath = *argv; |
| 866 | } |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 867 | } else if (strcmp(*argv, "-i") == 0) { |
| 868 | argv++; |
| 869 | if (argv < stop && **argv) { |
| 870 | resourcePath = *argv; |
| 871 | } |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 872 | } else if (strcmp(*argv, "--forceBWtext") == 0) { |
| 873 | gForceBWtext = true; |
scroggo@google.com | d13bdfb | 2012-06-04 17:45:54 +0000 | [diff] [blame] | 874 | } else if (strcmp(*argv, "--pipe") == 0) { |
| 875 | doPipe = true; |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 876 | } else if (strcmp(*argv, "--tiledPipe") == 0) { |
| 877 | doTiledPipe = true; |
reed@google.com | b8b0983 | 2011-05-26 15:57:56 +0000 | [diff] [blame] | 878 | } else if (strcmp(*argv, "--noreplay") == 0) { |
| 879 | doReplay = false; |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 880 | } else if (strcmp(*argv, "--nopdf") == 0) { |
| 881 | doPDF = false; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 882 | } else if (strcmp(*argv, "--nodeferred") == 0) { |
| 883 | doDeferred = false; |
reed@google.com | e8fcb50 | 2012-05-17 15:28:20 +0000 | [diff] [blame] | 884 | } else if (strcmp(*argv, "--disable-missing-warning") == 0) { |
| 885 | gNotifyMissingReadReference = false; |
| 886 | } else if (strcmp(*argv, "--enable-missing-warning") == 0) { |
| 887 | gNotifyMissingReadReference = true; |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 888 | } else if (strcmp(*argv, "--serialize") == 0) { |
borenet@google.com | 14ca1d3 | 2012-06-15 13:46:44 +0000 | [diff] [blame] | 889 | doSerialize = true; |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 890 | } else if (strcmp(*argv, "--match") == 0) { |
| 891 | ++argv; |
| 892 | if (argv < stop && **argv) { |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 893 | // just record the ptr, no need for a deep copy |
| 894 | *fMatches.append() = *argv; |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 895 | } |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 896 | } else if (strcmp(*argv, "--notexturecache") == 0) { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 897 | disableTextureCache = true; |
reed@google.com | e5f48b9 | 2012-06-22 15:27:39 +0000 | [diff] [blame] | 898 | } else if (strcmp(*argv, "--config") == 0) { |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 899 | argv++; |
| 900 | if (argv < stop) { |
| 901 | int index = findConfig(*argv); |
| 902 | if (index >= 0) { |
| 903 | *configs.append() = index; |
| 904 | userConfig = true; |
| 905 | } else { |
| 906 | SkString str; |
| 907 | str.printf("unrecognized config %s\n", *argv); |
| 908 | SkDebugf(str.c_str()); |
| 909 | usage(commandName); |
| 910 | return -1; |
| 911 | } |
| 912 | } else { |
reed@google.com | e5f48b9 | 2012-06-22 15:27:39 +0000 | [diff] [blame] | 913 | SkDebugf("missing arg for --config\n"); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 914 | usage(commandName); |
| 915 | return -1; |
| 916 | } |
| 917 | } else if (strcmp(*argv, "--help") == 0 || strcmp(*argv, "-h") == 0) { |
| 918 | usage(commandName); |
| 919 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 920 | } else { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 921 | usage(commandName); |
| 922 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 923 | } |
| 924 | } |
| 925 | if (argv != stop) { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 926 | usage(commandName); |
| 927 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 928 | } |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 929 | |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 930 | if (!userConfig) { |
| 931 | // if no config is specified by user, we add them all. |
| 932 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 933 | *configs.append() = i; |
| 934 | } |
| 935 | } |
| 936 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 937 | GM::SetResourcePath(resourcePath); |
| 938 | |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 939 | GrContextFactory* grFactory = new GrContextFactory; |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 940 | |
reed@android.com | 00f883e | 2010-12-14 17:46:14 +0000 | [diff] [blame] | 941 | if (readPath) { |
| 942 | fprintf(stderr, "reading from %s\n", readPath); |
epoger@google.com | 9284ccd | 2012-04-18 13:36:54 +0000 | [diff] [blame] | 943 | } |
| 944 | if (writePath) { |
reed@android.com | 00f883e | 2010-12-14 17:46:14 +0000 | [diff] [blame] | 945 | fprintf(stderr, "writing to %s\n", writePath); |
| 946 | } |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 947 | if (writePicturePath) { |
| 948 | fprintf(stderr, "writing pictures to %s\n", writePicturePath); |
| 949 | } |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 950 | if (resourcePath) { |
| 951 | fprintf(stderr, "reading resources from %s\n", resourcePath); |
| 952 | } |
| 953 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 954 | // Accumulate success of all tests. |
| 955 | int testsRun = 0; |
| 956 | int testsPassed = 0; |
| 957 | int testsFailed = 0; |
| 958 | int testsMissingReferenceImages = 0; |
| 959 | |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 960 | if (disableTextureCache) { |
| 961 | skiagm::GetGr()->setTextureCacheLimits(0, 0); |
| 962 | } |
| 963 | |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 964 | Iter iter; |
| 965 | GM* gm; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 966 | while ((gm = iter.next()) != NULL) { |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 967 | const char* shortName = gm->shortName(); |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 968 | if (skip_name(fMatches, shortName)) { |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 969 | SkDELETE(gm); |
| 970 | continue; |
| 971 | } |
| 972 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 973 | SkISize size = gm->getISize(); |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 974 | SkDebugf("drawing... %s [%d %d]\n", shortName, |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 975 | size.width(), size.height()); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 976 | SkBitmap forwardRenderedBitmap; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 977 | |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 978 | for (int i = 0; i < configs.count(); i++) { |
| 979 | ConfigData config = gRec[configs[i]]; |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 980 | SkAutoTUnref<GrRenderTarget> rt; |
| 981 | AutoResetGr autogr; |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 982 | if (kGPU_Backend == config.fBackend) { |
| 983 | GrContext* gr = grFactory->get(config.fGLContextType); |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 984 | if (!gr) { |
| 985 | continue; |
| 986 | } |
| 987 | |
| 988 | // create a render target to back the device |
| 989 | GrTextureDesc desc; |
| 990 | desc.fConfig = kSkia8888_PM_GrPixelConfig; |
| 991 | desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 992 | desc.fWidth = gm->getISize().width(); |
| 993 | desc.fHeight = gm->getISize().height(); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 994 | desc.fSampleCnt = config.fSampleCnt; |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 995 | GrTexture* tex = gr->createUncachedTexture(desc, NULL, 0); |
| 996 | if (!tex) { |
bsalomon@google.com | daf12bb | 2012-04-20 19:08:44 +0000 | [diff] [blame] | 997 | continue; |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 998 | } |
| 999 | rt.reset(tex->asRenderTarget()); |
| 1000 | rt.get()->ref(); |
| 1001 | tex->unref(); |
| 1002 | |
| 1003 | autogr.set(gr); |
| 1004 | } |
| 1005 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1006 | // Skip any tests that we don't even need to try. |
bsalomon@google.com | 29d3501 | 2011-11-30 16:57:21 +0000 | [diff] [blame] | 1007 | uint32_t gmFlags = gm->getFlags(); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1008 | if ((kPDF_Backend == config.fBackend) && |
bungeman@google.com | 64e011a | 2011-09-19 19:31:04 +0000 | [diff] [blame] | 1009 | (!doPDF || (gmFlags & GM::kSkipPDF_Flag))) |
| 1010 | { |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 1011 | continue; |
| 1012 | } |
| 1013 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1014 | // Now we know that we want to run this test and record its |
| 1015 | // success or failure. |
| 1016 | ErrorBitfield testErrors = ERROR_NONE; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1017 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1018 | if ((ERROR_NONE == testErrors) && |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1019 | (kGPU_Backend == config.fBackend) && |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1020 | (NULL == rt.get())) { |
| 1021 | fprintf(stderr, "Could not create render target for gpu.\n"); |
| 1022 | testErrors |= ERROR_NO_GPU_CONTEXT; |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 1023 | } |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 1024 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1025 | if (ERROR_NONE == testErrors) { |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1026 | testErrors |= test_drawing(gm, config, |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1027 | writePath, readPath, diffPath, |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1028 | GetGr(), |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1029 | rt.get(), &forwardRenderedBitmap); |
| 1030 | } |
| 1031 | |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 1032 | if (doDeferred && !testErrors && |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1033 | (kGPU_Backend == config.fBackend || |
| 1034 | kRaster_Backend == config.fBackend)) { |
| 1035 | testErrors |= test_deferred_drawing(gm, config, |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 1036 | forwardRenderedBitmap, |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1037 | diffPath, GetGr(), rt.get()); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 1038 | } |
| 1039 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1040 | if ((ERROR_NONE == testErrors) && doReplay && |
| 1041 | !(gmFlags & GM::kSkipPicture_Flag)) { |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1042 | testErrors |= test_picture_playback(gm, config, |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1043 | forwardRenderedBitmap, |
| 1044 | readPath, diffPath); |
| 1045 | } |
| 1046 | |
scroggo@google.com | 5af9b20 | 2012-06-04 17:17:36 +0000 | [diff] [blame] | 1047 | if ((ERROR_NONE == testErrors) && doPipe && |
| 1048 | !(gmFlags & GM::kSkipPipe_Flag)) { |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1049 | testErrors |= test_pipe_playback(gm, config, |
scroggo@google.com | 5af9b20 | 2012-06-04 17:17:36 +0000 | [diff] [blame] | 1050 | forwardRenderedBitmap, |
| 1051 | readPath, diffPath); |
| 1052 | } |
| 1053 | |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 1054 | if ((ERROR_NONE == testErrors) && doTiledPipe && |
| 1055 | !(gmFlags & GM::kSkipPipe_Flag)) { |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1056 | testErrors |= test_tiled_pipe_playback(gm, config, |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 1057 | forwardRenderedBitmap, |
| 1058 | readPath, diffPath); |
| 1059 | } |
| 1060 | |
djsollen@google.com | a2ca41e | 2012-03-23 19:00:34 +0000 | [diff] [blame] | 1061 | if ((ERROR_NONE == testErrors) && doSerialize && |
| 1062 | !(gmFlags & GM::kSkipPicture_Flag)) { |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1063 | testErrors |= test_picture_serialization(gm, config, |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1064 | forwardRenderedBitmap, |
| 1065 | readPath, diffPath); |
| 1066 | } |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 1067 | |
| 1068 | if (!(gmFlags & GM::kSkipPicture_Flag) && writePicturePath) { |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1069 | write_picture_serialization(gm, config, writePicturePath); |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 1070 | } |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1071 | |
| 1072 | // Update overall results. |
| 1073 | // We only tabulate the particular error types that we currently |
| 1074 | // care about (e.g., missing reference images). Later on, if we |
| 1075 | // want to also tabulate pixel mismatches vs dimension mistmatches |
| 1076 | // (or whatever else), we can do so. |
| 1077 | testsRun++; |
| 1078 | if (ERROR_NONE == testErrors) { |
| 1079 | testsPassed++; |
| 1080 | } else if (ERROR_READING_REFERENCE_IMAGE & testErrors) { |
| 1081 | testsMissingReferenceImages++; |
| 1082 | } else { |
| 1083 | testsFailed++; |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 1084 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1085 | } |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1086 | SkDELETE(gm); |
| 1087 | } |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1088 | printf("Ran %d tests: %d passed, %d failed, %d missing reference images\n", |
| 1089 | testsRun, testsPassed, testsFailed, testsMissingReferenceImages); |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 1090 | |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 1091 | delete grFactory; |
| 1092 | SkGraphics::Term(); |
| 1093 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1094 | return (0 == testsFailed) ? 0 : -1; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1095 | } |