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