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; |
| 511 | SkCanvas* cv = pict->beginRecording(1000, 1000); |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 512 | invokeGM(gm, cv); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 513 | pict->endRecording(); |
| 514 | |
| 515 | return pict; |
| 516 | } |
| 517 | |
| 518 | static SkPicture* stream_to_new_picture(const SkPicture& src) { |
| 519 | |
| 520 | // To do in-memory commiunications with a stream, we need to: |
| 521 | // * create a dynamic memory stream |
| 522 | // * copy it into a buffer |
| 523 | // * create a read stream from it |
| 524 | // ?!?! |
| 525 | |
| 526 | SkDynamicMemoryWStream storage; |
| 527 | src.serialize(&storage); |
| 528 | |
| 529 | int streamSize = storage.getOffset(); |
| 530 | SkAutoMalloc dstStorage(streamSize); |
| 531 | void* dst = dstStorage.get(); |
| 532 | //char* dst = new char [streamSize]; |
| 533 | //@todo thudson 22 April 2011 when can we safely delete [] dst? |
| 534 | storage.copyTo(dst); |
| 535 | SkMemoryStream pictReadback(dst, streamSize); |
| 536 | SkPicture* retval = new SkPicture (&pictReadback); |
| 537 | return retval; |
| 538 | } |
| 539 | |
| 540 | // Test: draw into a bitmap or pdf. |
| 541 | // Depending on flags, possibly compare to an expected image |
| 542 | // and possibly output a diff image if it fails to match. |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 543 | static ErrorBitfield test_drawing(GM* gm, |
| 544 | const ConfigData& gRec, |
| 545 | const char writePath [], |
| 546 | const char readPath [], |
| 547 | const char diffPath [], |
| 548 | GrContext* context, |
| 549 | GrRenderTarget* rt, |
| 550 | SkBitmap* bitmap) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 551 | SkDynamicMemoryWStream document; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 552 | |
| 553 | if (gRec.fBackend == kRaster_Backend || |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 554 | gRec.fBackend == kGPU_Backend) { |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 555 | // Early exit if we can't generate the image. |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 556 | ErrorBitfield errors = generate_image(gm, gRec, context, rt, bitmap, |
| 557 | false); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 558 | if (ERROR_NONE != errors) { |
| 559 | return errors; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 560 | } |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 561 | } else if (gRec.fBackend == kPDF_Backend) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 562 | generate_pdf(gm, document); |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 563 | #if CAN_IMAGE_PDF |
bungeman@google.com | 0f1541f | 2011-10-10 13:47:06 +0000 | [diff] [blame] | 564 | SkAutoDataUnref data(document.copyToData()); |
robertphillips@google.com | 5c0b313 | 2012-07-10 17:50:00 +0000 | [diff] [blame] | 565 | SkMemoryStream stream(data->data(), data->size()); |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 566 | SkPDFDocumentToBitmap(&stream, bitmap); |
| 567 | #endif |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 568 | } else if (gRec.fBackend == kXPS_Backend) { |
| 569 | generate_xps(gm, document); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 570 | } |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 571 | return handle_test_results(gm, gRec, writePath, readPath, diffPath, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 572 | "", *bitmap, &document, NULL); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 573 | } |
| 574 | |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 575 | static ErrorBitfield test_deferred_drawing(GM* gm, |
| 576 | const ConfigData& gRec, |
| 577 | const SkBitmap& comparisonBitmap, |
| 578 | const char diffPath [], |
| 579 | GrContext* context, |
| 580 | GrRenderTarget* rt) { |
| 581 | SkDynamicMemoryWStream document; |
| 582 | |
| 583 | if (gRec.fBackend == kRaster_Backend || |
| 584 | gRec.fBackend == kGPU_Backend) { |
| 585 | SkBitmap bitmap; |
| 586 | // Early exit if we can't generate the image, but this is |
| 587 | // expected in some cases, so don't report a test failure. |
| 588 | if (!generate_image(gm, gRec, context, rt, &bitmap, true)) { |
| 589 | return ERROR_NONE; |
| 590 | } |
| 591 | return handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 592 | "-deferred", bitmap, NULL, &comparisonBitmap); |
| 593 | } |
| 594 | return ERROR_NONE; |
| 595 | } |
| 596 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 597 | static ErrorBitfield test_picture_playback(GM* gm, |
| 598 | const ConfigData& gRec, |
| 599 | const SkBitmap& comparisonBitmap, |
| 600 | const char readPath [], |
| 601 | const char diffPath []) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 602 | SkPicture* pict = generate_new_picture(gm); |
| 603 | SkAutoUnref aur(pict); |
| 604 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 605 | if (kRaster_Backend == gRec.fBackend) { |
| 606 | SkBitmap bitmap; |
| 607 | generate_image_from_picture(gm, gRec, pict, &bitmap); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 608 | return handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 609 | "-replay", bitmap, NULL, &comparisonBitmap); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 610 | } else { |
| 611 | return ERROR_NONE; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 612 | } |
| 613 | } |
| 614 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 615 | static ErrorBitfield test_picture_serialization(GM* gm, |
| 616 | const ConfigData& gRec, |
| 617 | const SkBitmap& comparisonBitmap, |
| 618 | const char readPath [], |
| 619 | const char diffPath []) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 620 | SkPicture* pict = generate_new_picture(gm); |
| 621 | SkAutoUnref aurp(pict); |
| 622 | SkPicture* repict = stream_to_new_picture(*pict); |
| 623 | SkAutoUnref aurr(repict); |
| 624 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 625 | if (kRaster_Backend == gRec.fBackend) { |
| 626 | SkBitmap bitmap; |
| 627 | generate_image_from_picture(gm, gRec, repict, &bitmap); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 628 | return handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 629 | "-serialize", bitmap, NULL, &comparisonBitmap); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 630 | } else { |
| 631 | return ERROR_NONE; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 632 | } |
| 633 | } |
| 634 | |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 635 | struct PipeFlagComboData { |
| 636 | const char* name; |
| 637 | uint32_t flags; |
| 638 | }; |
| 639 | |
| 640 | static PipeFlagComboData gPipeWritingFlagCombos[] = { |
| 641 | { "", 0 }, |
| 642 | { " cross-process", SkGPipeWriter::kCrossProcess_Flag }, |
scroggo | b3c0f48 | 2012-07-02 19:07:57 +0000 | [diff] [blame] | 643 | { " cross-process, shared address", SkGPipeWriter::kCrossProcess_Flag |
scroggo@google.com | 15011ee | 2012-07-26 20:03:32 +0000 | [diff] [blame] | 644 | | SkGPipeWriter::kSharedAddressSpace_Flag } |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 645 | }; |
| 646 | |
scroggo@google.com | 5af9b20 | 2012-06-04 17:17:36 +0000 | [diff] [blame] | 647 | static ErrorBitfield test_pipe_playback(GM* gm, |
| 648 | const ConfigData& gRec, |
| 649 | const SkBitmap& comparisonBitmap, |
| 650 | const char readPath [], |
| 651 | const char diffPath []) { |
| 652 | if (kRaster_Backend != gRec.fBackend) { |
| 653 | return ERROR_NONE; |
| 654 | } |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 655 | ErrorBitfield errors = ERROR_NONE; |
| 656 | for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) { |
| 657 | SkBitmap bitmap; |
| 658 | SkISize size = gm->getISize(); |
| 659 | setup_bitmap(gRec, size, &bitmap); |
| 660 | SkCanvas canvas(bitmap); |
| 661 | PipeController pipeController(&canvas); |
| 662 | SkGPipeWriter writer; |
| 663 | SkCanvas* pipeCanvas = writer.startRecording(&pipeController, |
| 664 | gPipeWritingFlagCombos[i].flags); |
| 665 | invokeGM(gm, pipeCanvas); |
| 666 | writer.endRecording(); |
| 667 | SkString string("-pipe"); |
| 668 | string.append(gPipeWritingFlagCombos[i].name); |
| 669 | errors |= handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 670 | string.c_str(), bitmap, NULL, &comparisonBitmap); |
| 671 | if (errors != ERROR_NONE) { |
| 672 | break; |
| 673 | } |
| 674 | } |
| 675 | return errors; |
scroggo@google.com | 5af9b20 | 2012-06-04 17:17:36 +0000 | [diff] [blame] | 676 | } |
| 677 | |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 678 | static ErrorBitfield test_tiled_pipe_playback(GM* gm, |
| 679 | const ConfigData& gRec, |
| 680 | const SkBitmap& comparisonBitmap, |
| 681 | const char readPath [], |
| 682 | const char diffPath []) { |
| 683 | if (kRaster_Backend != gRec.fBackend) { |
| 684 | return ERROR_NONE; |
| 685 | } |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 686 | ErrorBitfield errors = ERROR_NONE; |
| 687 | for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) { |
| 688 | SkBitmap bitmap; |
| 689 | SkISize size = gm->getISize(); |
| 690 | setup_bitmap(gRec, size, &bitmap); |
| 691 | SkCanvas canvas(bitmap); |
| 692 | TiledPipeController pipeController(bitmap); |
| 693 | SkGPipeWriter writer; |
| 694 | SkCanvas* pipeCanvas = writer.startRecording(&pipeController, |
| 695 | gPipeWritingFlagCombos[i].flags); |
| 696 | invokeGM(gm, pipeCanvas); |
| 697 | writer.endRecording(); |
scroggo@google.com | d3ba5cc | 2012-07-09 16:05:53 +0000 | [diff] [blame] | 698 | SkString string("-tiled pipe"); |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 699 | string.append(gPipeWritingFlagCombos[i].name); |
| 700 | errors |= handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 701 | string.c_str(), bitmap, NULL, &comparisonBitmap); |
| 702 | if (errors != ERROR_NONE) { |
| 703 | break; |
| 704 | } |
| 705 | } |
| 706 | return errors; |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 707 | } |
| 708 | |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 709 | static void write_picture_serialization(GM* gm, const ConfigData& rec, |
| 710 | const char writePicturePath[]) { |
| 711 | // only do this once, so we pick raster |
| 712 | if (kRaster_Backend == rec.fBackend && |
| 713 | SkBitmap::kARGB_8888_Config == rec.fConfig) { |
| 714 | |
| 715 | SkAutoTUnref<SkPicture> pict(generate_new_picture(gm)); |
chudy@google.com | f32f6e8 | 2012-07-12 15:42:37 +0000 | [diff] [blame] | 716 | |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 717 | const char* pictureSuffix = "skp"; |
| 718 | SkString path = make_filename(writePicturePath, "", |
| 719 | SkString(gm->shortName()), pictureSuffix); |
chudy@google.com | f32f6e8 | 2012-07-12 15:42:37 +0000 | [diff] [blame] | 720 | |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 721 | SkFILEWStream stream(path.c_str()); |
| 722 | pict->serialize(&stream); |
| 723 | } |
| 724 | } |
| 725 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 726 | #if SK_SUPPORT_GPU |
| 727 | static const GLContextType kDontCare_GLContextType = GrContextFactory::kNative_GLContextType; |
| 728 | #else |
| 729 | static const GLContextType kDontCare_GLContextType = 0; |
| 730 | #endif |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 731 | |
| 732 | // If the platform does not support writing PNGs of PDFs then there will be no |
| 733 | // comparison images to read. However, we can always write the .pdf files |
| 734 | static const ConfigFlags kPDFConfigFlags = CAN_IMAGE_PDF ? kRW_ConfigFlag : |
| 735 | kWrite_ConfigFlag; |
| 736 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 737 | static const ConfigData gRec[] = { |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 738 | { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "8888" }, |
| 739 | { SkBitmap::kARGB_4444_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "4444" }, |
| 740 | { 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] | 741 | #if defined(SK_SCALAR_IS_FLOAT) && SK_SUPPORT_GPU |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 742 | { 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] | 743 | #ifndef SK_BUILD_FOR_ANDROID |
| 744 | // currently we don't want to run MSAA tests on Android |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 745 | { 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] | 746 | #endif |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 747 | /* The debug context does not generate images */ |
| 748 | { 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] | 749 | #if SK_ANGLE |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 750 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 0, kRW_ConfigFlag, "angle" }, |
| 751 | { 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] | 752 | #endif // SK_ANGLE |
| 753 | #ifdef SK_MESA |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 754 | { 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] | 755 | #endif // SK_MESA |
robertphillips@google.com | a73e860 | 2012-08-02 17:56:02 +0000 | [diff] [blame] | 756 | #endif // defined(SK_SCALAR_IS_FLOAT) && SK_SUPPORT_GPU |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 757 | #ifdef SK_SUPPORT_XPS |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 758 | /* At present we have no way of comparing XPS files (either natively or by converting to PNG). */ |
| 759 | { 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] | 760 | #endif // SK_SUPPORT_XPS |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 761 | #ifdef SK_SUPPORT_PDF |
| 762 | { SkBitmap::kARGB_8888_Config, kPDF_Backend, kDontCare_GLContextType, 0, kPDFConfigFlags, "pdf" }, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 763 | #endif // SK_SUPPORT_PDF |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 764 | }; |
| 765 | |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 766 | static void usage(const char * argv0) { |
| 767 | SkDebugf("%s\n", argv0); |
| 768 | SkDebugf(" [-w writePath] [-r readPath] [-d diffPath] [-i resourcePath]\n"); |
chudy@google.com | f32f6e8 | 2012-07-12 15:42:37 +0000 | [diff] [blame] | 769 | SkDebugf(" [-wp writePicturePath]\n"); |
reed@google.com | e5f48b9 | 2012-06-22 15:27:39 +0000 | [diff] [blame] | 770 | SkDebugf(" [--config "); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 771 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 772 | if (i > 0) { |
| 773 | SkDebugf("|"); |
| 774 | } |
| 775 | SkDebugf(gRec[i].fName); |
| 776 | } |
| 777 | SkDebugf(" ]\n"); |
scroggo@google.com | 3936252 | 2012-09-14 17:37:46 +0000 | [diff] [blame] | 778 | SkDebugf(" [--noreplay] [--nopipe] [--noserialize] [--forceBWtext] [--nopdf] \n" |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 779 | " [--tiledPipe] \n" |
| 780 | " [--nodeferred] [--match substring] [--notexturecache]\n" |
| 781 | " [-h|--help]\n" |
| 782 | ); |
| 783 | SkDebugf(" writePath: directory to write rendered images in.\n"); |
chudy@google.com | f32f6e8 | 2012-07-12 15:42:37 +0000 | [diff] [blame] | 784 | SkDebugf(" writePicturePath: directory to write images to in .skp format.\n"); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 785 | SkDebugf( |
| 786 | " readPath: directory to read reference images from;\n" |
| 787 | " reports if any pixels mismatch between reference and new images\n"); |
| 788 | SkDebugf(" diffPath: directory to write difference images in.\n"); |
| 789 | SkDebugf(" resourcePath: directory that stores image resources.\n"); |
| 790 | SkDebugf(" --noreplay: do not exercise SkPicture replay.\n"); |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 791 | SkDebugf(" --nopipe: Skip SkGPipe replay.\n"); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 792 | SkDebugf(" --tiledPipe: Exercise tiled SkGPipe replay.\n"); |
| 793 | SkDebugf( |
scroggo@google.com | 3936252 | 2012-09-14 17:37:46 +0000 | [diff] [blame] | 794 | " --noserialize: do not exercise SkPicture serialization & deserialization.\n"); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 795 | SkDebugf(" --forceBWtext: disable text anti-aliasing.\n"); |
| 796 | SkDebugf(" --nopdf: skip the pdf rendering test pass.\n"); |
| 797 | SkDebugf(" --nodeferred: skip the deferred rendering test pass.\n"); |
| 798 | SkDebugf(" --match foo: will only run tests that substring match foo.\n"); |
| 799 | SkDebugf(" --notexturecache: disable the gpu texture cache.\n"); |
| 800 | SkDebugf(" -h|--help : Show this help message. \n"); |
| 801 | } |
| 802 | |
| 803 | static int findConfig(const char config[]) { |
| 804 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { |
| 805 | if (!strcmp(config, gRec[i].fName)) { |
| 806 | return i; |
| 807 | } |
| 808 | } |
| 809 | return -1; |
| 810 | } |
| 811 | |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 812 | static bool skip_name(const SkTDArray<const char*> array, const char name[]) { |
| 813 | if (0 == array.count()) { |
| 814 | // no names, so don't skip anything |
| 815 | return false; |
| 816 | } |
| 817 | for (int i = 0; i < array.count(); ++i) { |
| 818 | if (strstr(name, array[i])) { |
| 819 | // found the name, so don't skip |
| 820 | return false; |
| 821 | } |
| 822 | } |
| 823 | return true; |
| 824 | } |
| 825 | |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 826 | namespace skiagm { |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 827 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 828 | SkAutoTUnref<GrContext> gGrContext; |
| 829 | /** |
| 830 | * Sets the global GrContext, accessible by indivual GMs |
| 831 | */ |
caryclark@google.com | 1313086 | 2012-06-06 12:10:45 +0000 | [diff] [blame] | 832 | static void SetGr(GrContext* grContext) { |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 833 | SkSafeRef(grContext); |
| 834 | gGrContext.reset(grContext); |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 835 | } |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 836 | |
| 837 | /** |
| 838 | * Gets the global GrContext, can be called by GM tests. |
| 839 | */ |
caryclark@google.com | 1313086 | 2012-06-06 12:10:45 +0000 | [diff] [blame] | 840 | GrContext* GetGr(); |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 841 | GrContext* GetGr() { |
| 842 | return gGrContext.get(); |
| 843 | } |
| 844 | |
| 845 | /** |
| 846 | * Sets the global GrContext and then resets it to its previous value at |
| 847 | * destruction. |
| 848 | */ |
| 849 | class AutoResetGr : SkNoncopyable { |
| 850 | public: |
| 851 | AutoResetGr() : fOld(NULL) {} |
| 852 | void set(GrContext* context) { |
| 853 | SkASSERT(NULL == fOld); |
| 854 | fOld = GetGr(); |
| 855 | SkSafeRef(fOld); |
| 856 | SetGr(context); |
| 857 | } |
| 858 | ~AutoResetGr() { SetGr(fOld); SkSafeUnref(fOld); } |
| 859 | private: |
| 860 | GrContext* fOld; |
| 861 | }; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 862 | #else |
| 863 | GrContext* GetGr() { return NULL; } |
| 864 | #endif |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 865 | } |
| 866 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 867 | int main(int argc, char * const argv[]) { |
robertphillips@google.com | b74af87 | 2012-06-27 19:41:42 +0000 | [diff] [blame] | 868 | |
| 869 | #ifdef SK_ENABLE_INST_COUNT |
| 870 | gPrintInstCount = true; |
| 871 | #endif |
| 872 | |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 873 | SkGraphics::Init(); |
reed@google.com | 8923c6c | 2011-11-08 14:59:38 +0000 | [diff] [blame] | 874 | // we don't need to see this during a run |
| 875 | gSkSuppressFontCachePurgeSpew = true; |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 876 | |
epoger@google.com | 7bc13a6 | 2012-02-14 14:53:59 +0000 | [diff] [blame] | 877 | setSystemPreferences(); |
| 878 | |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 879 | 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] | 880 | 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] | 881 | 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] | 882 | 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] | 883 | 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] | 884 | |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 885 | SkTDArray<const char*> fMatches; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 886 | |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 887 | bool doPDF = true; |
reed@google.com | b8b0983 | 2011-05-26 15:57:56 +0000 | [diff] [blame] | 888 | bool doReplay = true; |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 889 | bool doPipe = true; |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 890 | bool doTiledPipe = false; |
scroggo@google.com | 3936252 | 2012-09-14 17:37:46 +0000 | [diff] [blame] | 891 | bool doSerialize = true; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 892 | bool doDeferred = true; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 893 | bool disableTextureCache = false; |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 894 | SkTDArray<size_t> configs; |
| 895 | bool userConfig = false; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 896 | |
reed@google.com | e8fcb50 | 2012-05-17 15:28:20 +0000 | [diff] [blame] | 897 | gNotifyMissingReadReference = true; |
| 898 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 899 | const char* const commandName = argv[0]; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 900 | char* const* stop = argv + argc; |
| 901 | for (++argv; argv < stop; ++argv) { |
| 902 | if (strcmp(*argv, "-w") == 0) { |
| 903 | argv++; |
| 904 | if (argv < stop && **argv) { |
| 905 | writePath = *argv; |
| 906 | } |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 907 | } else if (strcmp(*argv, "-wp") == 0) { |
| 908 | argv++; |
| 909 | if (argv < stop && **argv) { |
| 910 | writePicturePath = *argv; |
| 911 | } |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 912 | } else if (strcmp(*argv, "-r") == 0) { |
| 913 | argv++; |
| 914 | if (argv < stop && **argv) { |
| 915 | readPath = *argv; |
| 916 | } |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 917 | } else if (strcmp(*argv, "-d") == 0) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 918 | argv++; |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 919 | if (argv < stop && **argv) { |
| 920 | diffPath = *argv; |
| 921 | } |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 922 | } else if (strcmp(*argv, "-i") == 0) { |
| 923 | argv++; |
| 924 | if (argv < stop && **argv) { |
| 925 | resourcePath = *argv; |
| 926 | } |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 927 | } else if (strcmp(*argv, "--forceBWtext") == 0) { |
| 928 | gForceBWtext = true; |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 929 | } else if (strcmp(*argv, "--nopipe") == 0) { |
| 930 | doPipe = false; |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 931 | } else if (strcmp(*argv, "--tiledPipe") == 0) { |
| 932 | doTiledPipe = true; |
reed@google.com | b8b0983 | 2011-05-26 15:57:56 +0000 | [diff] [blame] | 933 | } else if (strcmp(*argv, "--noreplay") == 0) { |
| 934 | doReplay = false; |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 935 | } else if (strcmp(*argv, "--nopdf") == 0) { |
| 936 | doPDF = false; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 937 | } else if (strcmp(*argv, "--nodeferred") == 0) { |
| 938 | doDeferred = false; |
reed@google.com | e8fcb50 | 2012-05-17 15:28:20 +0000 | [diff] [blame] | 939 | } else if (strcmp(*argv, "--disable-missing-warning") == 0) { |
| 940 | gNotifyMissingReadReference = false; |
| 941 | } else if (strcmp(*argv, "--enable-missing-warning") == 0) { |
| 942 | gNotifyMissingReadReference = true; |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 943 | } else if (strcmp(*argv, "--serialize") == 0) { |
scroggo@google.com | 3936252 | 2012-09-14 17:37:46 +0000 | [diff] [blame] | 944 | // Leaving in this option so that a user need not modify their command line arguments |
| 945 | // to still run. |
borenet@google.com | 14ca1d3 | 2012-06-15 13:46:44 +0000 | [diff] [blame] | 946 | doSerialize = true; |
scroggo@google.com | 3936252 | 2012-09-14 17:37:46 +0000 | [diff] [blame] | 947 | } else if (strcmp(*argv, "--noserialize") == 0) { |
| 948 | doSerialize = false; |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 949 | } else if (strcmp(*argv, "--match") == 0) { |
| 950 | ++argv; |
| 951 | if (argv < stop && **argv) { |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 952 | // just record the ptr, no need for a deep copy |
| 953 | *fMatches.append() = *argv; |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 954 | } |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 955 | } else if (strcmp(*argv, "--notexturecache") == 0) { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 956 | disableTextureCache = true; |
reed@google.com | e5f48b9 | 2012-06-22 15:27:39 +0000 | [diff] [blame] | 957 | } else if (strcmp(*argv, "--config") == 0) { |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 958 | argv++; |
| 959 | if (argv < stop) { |
| 960 | int index = findConfig(*argv); |
| 961 | if (index >= 0) { |
| 962 | *configs.append() = index; |
| 963 | userConfig = true; |
| 964 | } else { |
| 965 | SkString str; |
| 966 | str.printf("unrecognized config %s\n", *argv); |
| 967 | SkDebugf(str.c_str()); |
| 968 | usage(commandName); |
| 969 | return -1; |
| 970 | } |
| 971 | } else { |
reed@google.com | e5f48b9 | 2012-06-22 15:27:39 +0000 | [diff] [blame] | 972 | SkDebugf("missing arg for --config\n"); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 973 | usage(commandName); |
| 974 | return -1; |
| 975 | } |
| 976 | } else if (strcmp(*argv, "--help") == 0 || strcmp(*argv, "-h") == 0) { |
| 977 | usage(commandName); |
| 978 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 979 | } else { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 980 | usage(commandName); |
| 981 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 982 | } |
| 983 | } |
| 984 | if (argv != stop) { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 985 | usage(commandName); |
| 986 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 987 | } |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 988 | |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 989 | if (!userConfig) { |
| 990 | // if no config is specified by user, we add them all. |
| 991 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 992 | *configs.append() = i; |
| 993 | } |
| 994 | } |
| 995 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 996 | GM::SetResourcePath(resourcePath); |
| 997 | |
reed@android.com | 00f883e | 2010-12-14 17:46:14 +0000 | [diff] [blame] | 998 | if (readPath) { |
| 999 | fprintf(stderr, "reading from %s\n", readPath); |
chudy@google.com | f32f6e8 | 2012-07-12 15:42:37 +0000 | [diff] [blame] | 1000 | } |
epoger@google.com | 9284ccd | 2012-04-18 13:36:54 +0000 | [diff] [blame] | 1001 | if (writePath) { |
reed@android.com | 00f883e | 2010-12-14 17:46:14 +0000 | [diff] [blame] | 1002 | fprintf(stderr, "writing to %s\n", writePath); |
| 1003 | } |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 1004 | if (writePicturePath) { |
| 1005 | fprintf(stderr, "writing pictures to %s\n", writePicturePath); |
| 1006 | } |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 1007 | if (resourcePath) { |
| 1008 | fprintf(stderr, "reading resources from %s\n", resourcePath); |
| 1009 | } |
| 1010 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1011 | // Accumulate success of all tests. |
| 1012 | int testsRun = 0; |
| 1013 | int testsPassed = 0; |
| 1014 | int testsFailed = 0; |
| 1015 | int testsMissingReferenceImages = 0; |
| 1016 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1017 | #if SK_SUPPORT_GPU |
| 1018 | GrContextFactory* grFactory = new GrContextFactory; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 1019 | if (disableTextureCache) { |
| 1020 | skiagm::GetGr()->setTextureCacheLimits(0, 0); |
| 1021 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1022 | #endif |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 1023 | |
robertphillips@google.com | a2f8008 | 2012-08-02 16:22:47 +0000 | [diff] [blame] | 1024 | SkTArray<SkString> failedTests; |
| 1025 | |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1026 | Iter iter; |
| 1027 | GM* gm; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1028 | while ((gm = iter.next()) != NULL) { |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 1029 | const char* shortName = gm->shortName(); |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 1030 | if (skip_name(fMatches, shortName)) { |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 1031 | SkDELETE(gm); |
| 1032 | continue; |
| 1033 | } |
| 1034 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1035 | SkISize size = gm->getISize(); |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 1036 | SkDebugf("drawing... %s [%d %d]\n", shortName, |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 1037 | size.width(), size.height()); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 1038 | SkBitmap forwardRenderedBitmap; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 1039 | |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1040 | for (int i = 0; i < configs.count(); i++) { |
| 1041 | ConfigData config = gRec[configs[i]]; |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1042 | // Skip any tests that we don't even need to try. |
bsalomon@google.com | 29d3501 | 2011-11-30 16:57:21 +0000 | [diff] [blame] | 1043 | uint32_t gmFlags = gm->getFlags(); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1044 | if ((kPDF_Backend == config.fBackend) && |
bungeman@google.com | 64e011a | 2011-09-19 19:31:04 +0000 | [diff] [blame] | 1045 | (!doPDF || (gmFlags & GM::kSkipPDF_Flag))) |
| 1046 | { |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 1047 | continue; |
| 1048 | } |
| 1049 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1050 | // Now we know that we want to run this test and record its |
| 1051 | // success or failure. |
| 1052 | ErrorBitfield testErrors = ERROR_NONE; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1053 | GrRenderTarget* renderTarget = NULL; |
| 1054 | #if SK_SUPPORT_GPU |
| 1055 | SkAutoTUnref<GrRenderTarget> rt; |
| 1056 | AutoResetGr autogr; |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1057 | if ((ERROR_NONE == testErrors) && |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1058 | kGPU_Backend == config.fBackend) { |
| 1059 | GrContext* gr = grFactory->get(config.fGLContextType); |
| 1060 | bool grSuccess = false; |
| 1061 | if (gr) { |
| 1062 | // create a render target to back the device |
| 1063 | GrTextureDesc desc; |
| 1064 | desc.fConfig = kSkia8888_PM_GrPixelConfig; |
| 1065 | desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 1066 | desc.fWidth = gm->getISize().width(); |
| 1067 | desc.fHeight = gm->getISize().height(); |
| 1068 | desc.fSampleCnt = config.fSampleCnt; |
| 1069 | GrTexture* tex = gr->createUncachedTexture(desc, NULL, 0); |
| 1070 | if (tex) { |
| 1071 | rt.reset(tex->asRenderTarget()); |
| 1072 | rt.get()->ref(); |
| 1073 | tex->unref(); |
| 1074 | autogr.set(gr); |
| 1075 | renderTarget = rt.get(); |
| 1076 | grSuccess = NULL != renderTarget; |
| 1077 | } |
| 1078 | } |
| 1079 | if (!grSuccess) { |
| 1080 | testErrors |= ERROR_NO_GPU_CONTEXT; |
| 1081 | } |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 1082 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1083 | #endif |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 1084 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1085 | if (ERROR_NONE == testErrors) { |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1086 | testErrors |= test_drawing(gm, config, |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1087 | writePath, readPath, diffPath, |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1088 | GetGr(), |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1089 | renderTarget, &forwardRenderedBitmap); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 1092 | if (doDeferred && !testErrors && |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1093 | (kGPU_Backend == config.fBackend || |
| 1094 | kRaster_Backend == config.fBackend)) { |
| 1095 | testErrors |= test_deferred_drawing(gm, config, |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 1096 | forwardRenderedBitmap, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1097 | diffPath, GetGr(), renderTarget); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1100 | if ((ERROR_NONE == testErrors) && doReplay && |
| 1101 | !(gmFlags & GM::kSkipPicture_Flag)) { |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1102 | testErrors |= test_picture_playback(gm, config, |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1103 | forwardRenderedBitmap, |
| 1104 | readPath, diffPath); |
| 1105 | } |
| 1106 | |
scroggo@google.com | 5af9b20 | 2012-06-04 17:17:36 +0000 | [diff] [blame] | 1107 | if ((ERROR_NONE == testErrors) && doPipe && |
| 1108 | !(gmFlags & GM::kSkipPipe_Flag)) { |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1109 | testErrors |= test_pipe_playback(gm, config, |
scroggo@google.com | 5af9b20 | 2012-06-04 17:17:36 +0000 | [diff] [blame] | 1110 | forwardRenderedBitmap, |
| 1111 | readPath, diffPath); |
| 1112 | } |
| 1113 | |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 1114 | if ((ERROR_NONE == testErrors) && doTiledPipe && |
scroggo@google.com | 6325886 | 2012-08-15 16:32:19 +0000 | [diff] [blame] | 1115 | !SkToBool(gmFlags & (GM::kSkipPipe_Flag | GM::kSkipTiled_Flag))) { |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1116 | testErrors |= test_tiled_pipe_playback(gm, config, |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 1117 | forwardRenderedBitmap, |
| 1118 | readPath, diffPath); |
| 1119 | } |
| 1120 | |
djsollen@google.com | a2ca41e | 2012-03-23 19:00:34 +0000 | [diff] [blame] | 1121 | if ((ERROR_NONE == testErrors) && doSerialize && |
| 1122 | !(gmFlags & GM::kSkipPicture_Flag)) { |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1123 | testErrors |= test_picture_serialization(gm, config, |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1124 | forwardRenderedBitmap, |
| 1125 | readPath, diffPath); |
| 1126 | } |
chudy@google.com | f32f6e8 | 2012-07-12 15:42:37 +0000 | [diff] [blame] | 1127 | |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 1128 | if (!(gmFlags & GM::kSkipPicture_Flag) && writePicturePath) { |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1129 | write_picture_serialization(gm, config, writePicturePath); |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 1130 | } |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1131 | |
| 1132 | // Update overall results. |
| 1133 | // We only tabulate the particular error types that we currently |
| 1134 | // care about (e.g., missing reference images). Later on, if we |
| 1135 | // want to also tabulate pixel mismatches vs dimension mistmatches |
| 1136 | // (or whatever else), we can do so. |
| 1137 | testsRun++; |
| 1138 | if (ERROR_NONE == testErrors) { |
| 1139 | testsPassed++; |
| 1140 | } else if (ERROR_READING_REFERENCE_IMAGE & testErrors) { |
| 1141 | testsMissingReferenceImages++; |
| 1142 | } else { |
| 1143 | testsFailed++; |
robertphillips@google.com | a2f8008 | 2012-08-02 16:22:47 +0000 | [diff] [blame] | 1144 | |
| 1145 | failedTests.push_back(make_name(shortName, config.fName)); |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 1146 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1147 | } |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1148 | SkDELETE(gm); |
| 1149 | } |
robertphillips@google.com | a2f8008 | 2012-08-02 16:22:47 +0000 | [diff] [blame] | 1150 | SkDebugf("Ran %d tests: %d passed, %d failed, %d missing reference images\n", |
| 1151 | testsRun, testsPassed, testsFailed, testsMissingReferenceImages); |
| 1152 | for (int i = 0; i < failedTests.count(); ++i) { |
| 1153 | SkDebugf("\t\t%s\n", failedTests[i].c_str()); |
| 1154 | } |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 1155 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1156 | #if SK_SUPPORT_GPU |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 1157 | |
robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 1158 | #if GR_CACHE_STATS |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 1159 | for (int i = 0; i < configs.count(); i++) { |
| 1160 | ConfigData config = gRec[configs[i]]; |
| 1161 | |
| 1162 | if (kGPU_Backend == config.fBackend) { |
| 1163 | GrContext* gr = grFactory->get(config.fGLContextType); |
| 1164 | |
| 1165 | SkDebugf("config: %s %x\n", config.fName, gr); |
| 1166 | gr->printCacheStats(); |
| 1167 | } |
| 1168 | } |
| 1169 | #endif |
| 1170 | |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 1171 | delete grFactory; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1172 | #endif |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 1173 | SkGraphics::Term(); |
| 1174 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1175 | return (0 == testsFailed) ? 0 : -1; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1176 | } |