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