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