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