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