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) { |
reed@google.com | 778e163 | 2012-06-04 20:00:01 +0000 | [diff] [blame] | 280 | SkAutoCanvasRestore acr(canvas, true); |
| 281 | |
vandebo@chromium.org | 79d3cb4 | 2012-03-21 17:34:30 +0000 | [diff] [blame] | 282 | if (!isPDF) { |
reed@google.com | 778e163 | 2012-06-04 20:00:01 +0000 | [diff] [blame] | 283 | canvas->concat(gm->getInitialTransform()); |
vandebo@chromium.org | 79d3cb4 | 2012-03-21 17:34:30 +0000 | [diff] [blame] | 284 | } |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 285 | installFilter(canvas); |
| 286 | gm->draw(canvas); |
| 287 | canvas->setDrawFilter(NULL); |
| 288 | } |
| 289 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 290 | static ErrorBitfield generate_image(GM* gm, const ConfigData& gRec, |
| 291 | GrContext* context, |
| 292 | GrRenderTarget* rt, |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 293 | SkBitmap* bitmap, |
| 294 | bool deferred) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 295 | SkISize size (gm->getISize()); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 296 | setup_bitmap(gRec, size, bitmap); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 297 | |
| 298 | if (gRec.fBackend == kRaster_Backend) { |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 299 | SkCanvas* canvas; |
| 300 | if (deferred) { |
| 301 | canvas = new SkDeferredCanvas; |
| 302 | canvas->setDevice(new SkDevice(*bitmap))->unref(); |
| 303 | } else { |
| 304 | canvas = new SkCanvas(*bitmap); |
| 305 | } |
| 306 | SkAutoUnref canvasUnref(canvas); |
| 307 | invokeGM(gm, canvas); |
junov@chromium.org | bf6c1e4 | 2012-01-30 14:53:22 +0000 | [diff] [blame] | 308 | canvas->flush(); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 309 | } else { // GPU |
| 310 | if (NULL == context) { |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 311 | return ERROR_NO_GPU_CONTEXT; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 312 | } |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 313 | SkCanvas* gc; |
| 314 | if (deferred) { |
| 315 | gc = new SkDeferredCanvas; |
| 316 | } else { |
| 317 | gc = new SkGpuCanvas(context, rt); |
| 318 | } |
| 319 | SkAutoUnref gcUnref(gc); |
| 320 | gc->setDevice(new SkGpuDevice(context, rt))->unref(); |
| 321 | invokeGM(gm, gc); |
reed@google.com | af951c9 | 2011-06-16 19:10:39 +0000 | [diff] [blame] | 322 | // the device is as large as the current rendertarget, so we explicitly |
| 323 | // only readback the amount we expect (in size) |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 324 | // overwrite our previous allocation |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 325 | bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth, |
| 326 | size.fHeight); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 327 | gc->readPixels(bitmap, 0, 0); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 328 | } |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 329 | return ERROR_NONE; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | static void generate_image_from_picture(GM* gm, const ConfigData& gRec, |
| 333 | SkPicture* pict, SkBitmap* bitmap) { |
| 334 | SkISize size = gm->getISize(); |
| 335 | setup_bitmap(gRec, size, bitmap); |
| 336 | SkCanvas canvas(*bitmap); |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 337 | installFilter(&canvas); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 338 | canvas.drawPicture(*pict); |
| 339 | } |
| 340 | |
| 341 | static void generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) { |
| 342 | #ifdef SK_SUPPORT_PDF |
vandebo@chromium.org | 79d3cb4 | 2012-03-21 17:34:30 +0000 | [diff] [blame] | 343 | SkMatrix initialTransform = gm->getInitialTransform(); |
| 344 | SkISize pageSize = gm->getISize(); |
| 345 | SkPDFDevice* dev = NULL; |
| 346 | if (initialTransform.isIdentity()) { |
| 347 | dev = new SkPDFDevice(pageSize, pageSize, initialTransform); |
| 348 | } else { |
| 349 | SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()), |
| 350 | SkIntToScalar(pageSize.height())); |
| 351 | initialTransform.mapRect(&content); |
| 352 | content.intersect(0, 0, SkIntToScalar(pageSize.width()), |
| 353 | SkIntToScalar(pageSize.height())); |
| 354 | SkISize contentSize = |
| 355 | SkISize::Make(SkScalarRoundToInt(content.width()), |
| 356 | SkScalarRoundToInt(content.height())); |
| 357 | dev = new SkPDFDevice(pageSize, contentSize, initialTransform); |
| 358 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 359 | SkAutoUnref aur(dev); |
| 360 | |
| 361 | SkCanvas c(dev); |
vandebo@chromium.org | 79d3cb4 | 2012-03-21 17:34:30 +0000 | [diff] [blame] | 362 | invokeGM(gm, &c, true); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 363 | |
| 364 | SkPDFDocument doc; |
| 365 | doc.appendPage(dev); |
| 366 | doc.emitPDF(&pdf); |
| 367 | #endif |
| 368 | } |
| 369 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 370 | static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) { |
| 371 | #ifdef SK_SUPPORT_XPS |
| 372 | SkISize size = gm->getISize(); |
| 373 | |
| 374 | SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()), |
| 375 | SkIntToScalar(size.height())); |
bungeman@google.com | dc9a695 | 2012-01-05 16:56:29 +0000 | [diff] [blame] | 376 | static const SkScalar inchesPerMeter = SkScalarDiv(10000, 254); |
| 377 | static const SkScalar upm = 72 * inchesPerMeter; |
| 378 | SkVector unitsPerMeter = SkPoint::Make(upm, upm); |
| 379 | static const SkScalar ppm = 200 * inchesPerMeter; |
| 380 | SkVector pixelsPerMeter = SkPoint::Make(ppm, ppm); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 381 | |
| 382 | SkXPSDevice* dev = new SkXPSDevice(); |
| 383 | SkAutoUnref aur(dev); |
| 384 | |
| 385 | SkCanvas c(dev); |
| 386 | dev->beginPortfolio(&xps); |
| 387 | dev->beginSheet(unitsPerMeter, pixelsPerMeter, trimSize); |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 388 | invokeGM(gm, &c); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 389 | dev->endSheet(); |
| 390 | dev->endPortfolio(); |
| 391 | |
| 392 | #endif |
| 393 | } |
| 394 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 395 | static ErrorBitfield write_reference_image(const ConfigData& gRec, |
| 396 | const char writePath [], |
| 397 | const char renderModeDescriptor [], |
| 398 | const SkString& name, |
| 399 | SkBitmap& bitmap, |
| 400 | SkDynamicMemoryWStream* document) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 401 | SkString path; |
| 402 | bool success = false; |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 403 | if (gRec.fBackend == kRaster_Backend || |
| 404 | gRec.fBackend == kGPU_Backend || |
| 405 | (gRec.fBackend == kPDF_Backend && CAN_IMAGE_PDF)) { |
| 406 | |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 407 | path = make_filename(writePath, renderModeDescriptor, name, "png"); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 408 | success = write_bitmap(path, bitmap); |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 409 | } |
| 410 | if (kPDF_Backend == gRec.fBackend) { |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 411 | path = make_filename(writePath, renderModeDescriptor, name, "pdf"); |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 412 | success = write_document(path, *document); |
| 413 | } |
| 414 | if (kXPS_Backend == gRec.fBackend) { |
| 415 | path = make_filename(writePath, renderModeDescriptor, name, "xps"); |
| 416 | success = write_document(path, *document); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 417 | } |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 418 | if (success) { |
| 419 | return ERROR_NONE; |
| 420 | } else { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 421 | fprintf(stderr, "FAILED to write %s\n", path.c_str()); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 422 | return ERROR_WRITING_REFERENCE_IMAGE; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 423 | } |
| 424 | } |
| 425 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 426 | static ErrorBitfield compare_to_reference_image(const SkString& name, |
| 427 | SkBitmap &bitmap, |
| 428 | const SkBitmap& comparisonBitmap, |
| 429 | const char diffPath [], |
| 430 | const char renderModeDescriptor []) { |
| 431 | ErrorBitfield errors; |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 432 | SkBitmap diffBitmap; |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 433 | errors = compare(bitmap, comparisonBitmap, name, renderModeDescriptor, |
| 434 | diffPath ? &diffBitmap : NULL); |
reed@google.com | 8e529b7 | 2012-04-09 20:20:10 +0000 | [diff] [blame] | 435 | if ((ERROR_NONE != errors) && diffPath) { |
| 436 | // write out the generated image |
| 437 | SkString genName = make_filename(diffPath, "", name, "png"); |
| 438 | if (!write_bitmap(genName, bitmap)) { |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 439 | errors |= ERROR_WRITING_REFERENCE_IMAGE; |
| 440 | } |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 441 | } |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 442 | return errors; |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 443 | } |
| 444 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 445 | static ErrorBitfield compare_to_reference_image(const char readPath [], |
| 446 | const SkString& name, |
| 447 | SkBitmap &bitmap, |
| 448 | const char diffPath [], |
| 449 | const char renderModeDescriptor []) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 450 | SkString path = make_filename(readPath, "", name, "png"); |
| 451 | SkBitmap orig; |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 452 | if (SkImageDecoder::DecodeFile(path.c_str(), &orig, |
| 453 | SkBitmap::kARGB_8888_Config, |
| 454 | SkImageDecoder::kDecodePixels_Mode, NULL)) { |
| 455 | return compare_to_reference_image(name, bitmap, |
| 456 | orig, diffPath, |
| 457 | renderModeDescriptor); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 458 | } else { |
reed@google.com | e8fcb50 | 2012-05-17 15:28:20 +0000 | [diff] [blame] | 459 | if (gNotifyMissingReadReference) { |
| 460 | fprintf(stderr, "FAILED to read %s\n", path.c_str()); |
| 461 | } |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 462 | return ERROR_READING_REFERENCE_IMAGE; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 463 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 464 | } |
| 465 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 466 | static ErrorBitfield handle_test_results(GM* gm, |
| 467 | const ConfigData& gRec, |
| 468 | const char writePath [], |
| 469 | const char readPath [], |
| 470 | const char diffPath [], |
| 471 | const char renderModeDescriptor [], |
| 472 | SkBitmap& bitmap, |
| 473 | SkDynamicMemoryWStream* pdf, |
| 474 | const SkBitmap* comparisonBitmap) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 475 | SkString name = make_name(gm->shortName(), gRec.fName); |
epoger@google.com | 9284ccd | 2012-04-18 13:36:54 +0000 | [diff] [blame] | 476 | ErrorBitfield retval = ERROR_NONE; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 477 | |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 478 | if (readPath && (gRec.fFlags & kRead_ConfigFlag)) { |
epoger@google.com | 9284ccd | 2012-04-18 13:36:54 +0000 | [diff] [blame] | 479 | retval |= compare_to_reference_image(readPath, name, bitmap, |
| 480 | diffPath, renderModeDescriptor); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 481 | } |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 482 | if (writePath && (gRec.fFlags & kWrite_ConfigFlag)) { |
epoger@google.com | 9284ccd | 2012-04-18 13:36:54 +0000 | [diff] [blame] | 483 | retval |= write_reference_image(gRec, writePath, renderModeDescriptor, |
| 484 | name, bitmap, pdf); |
| 485 | } |
| 486 | if (comparisonBitmap) { |
| 487 | retval |= compare_to_reference_image(name, bitmap, |
| 488 | *comparisonBitmap, diffPath, |
| 489 | renderModeDescriptor); |
| 490 | } |
| 491 | return retval; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | static SkPicture* generate_new_picture(GM* gm) { |
| 495 | // Pictures are refcounted so must be on heap |
| 496 | SkPicture* pict = new SkPicture; |
| 497 | SkCanvas* cv = pict->beginRecording(1000, 1000); |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 498 | invokeGM(gm, cv); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 499 | pict->endRecording(); |
| 500 | |
| 501 | return pict; |
| 502 | } |
| 503 | |
| 504 | static SkPicture* stream_to_new_picture(const SkPicture& src) { |
| 505 | |
| 506 | // To do in-memory commiunications with a stream, we need to: |
| 507 | // * create a dynamic memory stream |
| 508 | // * copy it into a buffer |
| 509 | // * create a read stream from it |
| 510 | // ?!?! |
| 511 | |
| 512 | SkDynamicMemoryWStream storage; |
| 513 | src.serialize(&storage); |
| 514 | |
| 515 | int streamSize = storage.getOffset(); |
| 516 | SkAutoMalloc dstStorage(streamSize); |
| 517 | void* dst = dstStorage.get(); |
| 518 | //char* dst = new char [streamSize]; |
| 519 | //@todo thudson 22 April 2011 when can we safely delete [] dst? |
| 520 | storage.copyTo(dst); |
| 521 | SkMemoryStream pictReadback(dst, streamSize); |
| 522 | SkPicture* retval = new SkPicture (&pictReadback); |
| 523 | return retval; |
| 524 | } |
| 525 | |
| 526 | // Test: draw into a bitmap or pdf. |
| 527 | // Depending on flags, possibly compare to an expected image |
| 528 | // and possibly output a diff image if it fails to match. |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 529 | static ErrorBitfield test_drawing(GM* gm, |
| 530 | const ConfigData& gRec, |
| 531 | const char writePath [], |
| 532 | const char readPath [], |
| 533 | const char diffPath [], |
| 534 | GrContext* context, |
| 535 | GrRenderTarget* rt, |
| 536 | SkBitmap* bitmap) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 537 | SkDynamicMemoryWStream document; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 538 | |
| 539 | if (gRec.fBackend == kRaster_Backend || |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 540 | gRec.fBackend == kGPU_Backend) { |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 541 | // Early exit if we can't generate the image. |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 542 | ErrorBitfield errors = generate_image(gm, gRec, context, rt, bitmap, |
| 543 | false); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 544 | if (ERROR_NONE != errors) { |
| 545 | return errors; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 546 | } |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 547 | } else if (gRec.fBackend == kPDF_Backend) { |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 548 | generate_pdf(gm, document); |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 549 | #if CAN_IMAGE_PDF |
bungeman@google.com | 0f1541f | 2011-10-10 13:47:06 +0000 | [diff] [blame] | 550 | SkAutoDataUnref data(document.copyToData()); |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 551 | SkMemoryStream stream(data.data(), data.size()); |
| 552 | SkPDFDocumentToBitmap(&stream, bitmap); |
| 553 | #endif |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 554 | } else if (gRec.fBackend == kXPS_Backend) { |
| 555 | generate_xps(gm, document); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 556 | } |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 557 | return handle_test_results(gm, gRec, writePath, readPath, diffPath, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 558 | "", *bitmap, &document, NULL); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 559 | } |
| 560 | |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 561 | static ErrorBitfield test_deferred_drawing(GM* gm, |
| 562 | const ConfigData& gRec, |
| 563 | const SkBitmap& comparisonBitmap, |
| 564 | const char diffPath [], |
| 565 | GrContext* context, |
| 566 | GrRenderTarget* rt) { |
| 567 | SkDynamicMemoryWStream document; |
| 568 | |
| 569 | if (gRec.fBackend == kRaster_Backend || |
| 570 | gRec.fBackend == kGPU_Backend) { |
| 571 | SkBitmap bitmap; |
| 572 | // Early exit if we can't generate the image, but this is |
| 573 | // expected in some cases, so don't report a test failure. |
| 574 | if (!generate_image(gm, gRec, context, rt, &bitmap, true)) { |
| 575 | return ERROR_NONE; |
| 576 | } |
| 577 | return handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 578 | "-deferred", bitmap, NULL, &comparisonBitmap); |
| 579 | } |
| 580 | return ERROR_NONE; |
| 581 | } |
| 582 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 583 | static ErrorBitfield test_picture_playback(GM* gm, |
| 584 | const ConfigData& gRec, |
| 585 | const SkBitmap& comparisonBitmap, |
| 586 | const char readPath [], |
| 587 | const char diffPath []) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 588 | SkPicture* pict = generate_new_picture(gm); |
| 589 | SkAutoUnref aur(pict); |
| 590 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 591 | if (kRaster_Backend == gRec.fBackend) { |
| 592 | SkBitmap bitmap; |
| 593 | generate_image_from_picture(gm, gRec, pict, &bitmap); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 594 | return handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 595 | "-replay", bitmap, NULL, &comparisonBitmap); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 596 | } else { |
| 597 | return ERROR_NONE; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 598 | } |
| 599 | } |
| 600 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 601 | static ErrorBitfield test_picture_serialization(GM* gm, |
| 602 | const ConfigData& gRec, |
| 603 | const SkBitmap& comparisonBitmap, |
| 604 | const char readPath [], |
| 605 | const char diffPath []) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 606 | SkPicture* pict = generate_new_picture(gm); |
| 607 | SkAutoUnref aurp(pict); |
| 608 | SkPicture* repict = stream_to_new_picture(*pict); |
| 609 | SkAutoUnref aurr(repict); |
| 610 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 611 | if (kRaster_Backend == gRec.fBackend) { |
| 612 | SkBitmap bitmap; |
| 613 | generate_image_from_picture(gm, gRec, repict, &bitmap); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 614 | return handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 615 | "-serialize", bitmap, NULL, &comparisonBitmap); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 616 | } else { |
| 617 | return ERROR_NONE; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 618 | } |
| 619 | } |
| 620 | |
scroggo@google.com | 5af9b20 | 2012-06-04 17:17:36 +0000 | [diff] [blame] | 621 | class PipeController : public SkGPipeController { |
| 622 | public: |
| 623 | PipeController(SkCanvas* target); |
| 624 | ~PipeController(); |
| 625 | virtual void* requestBlock(size_t minRequest, size_t* actual); |
| 626 | virtual void notifyWritten(size_t bytes); |
| 627 | private: |
| 628 | SkGPipeReader fReader; |
| 629 | void* fBlock; |
| 630 | size_t fBlockSize; |
| 631 | size_t fBytesWritten; |
| 632 | SkGPipeReader::Status fStatus; |
| 633 | }; |
| 634 | |
| 635 | PipeController::PipeController(SkCanvas* target) |
| 636 | :fReader(target) { |
| 637 | fBlock = NULL; |
| 638 | fBlockSize = fBytesWritten = 0; |
| 639 | } |
| 640 | |
| 641 | PipeController::~PipeController() { |
| 642 | sk_free(fBlock); |
| 643 | } |
| 644 | |
| 645 | void* PipeController::requestBlock(size_t minRequest, size_t *actual) { |
| 646 | sk_free(fBlock); |
| 647 | fBlockSize = minRequest * 4; |
| 648 | fBlock = sk_malloc_throw(fBlockSize); |
| 649 | fBytesWritten = 0; |
| 650 | *actual = fBlockSize; |
| 651 | return fBlock; |
| 652 | } |
| 653 | |
| 654 | void PipeController::notifyWritten(size_t bytes) { |
| 655 | fStatus = fReader.playback((const char*)fBlock + fBytesWritten, bytes); |
| 656 | SkASSERT(SkGPipeReader::kError_Status != fStatus); |
| 657 | fBytesWritten += bytes; |
| 658 | } |
| 659 | |
| 660 | static ErrorBitfield test_pipe_playback(GM* gm, |
| 661 | const ConfigData& gRec, |
| 662 | const SkBitmap& comparisonBitmap, |
| 663 | const char readPath [], |
| 664 | const char diffPath []) { |
| 665 | if (kRaster_Backend != gRec.fBackend) { |
| 666 | return ERROR_NONE; |
| 667 | } |
| 668 | SkBitmap bitmap; |
| 669 | SkISize size = gm->getISize(); |
| 670 | setup_bitmap(gRec, size, &bitmap); |
| 671 | SkCanvas canvas(bitmap); |
| 672 | PipeController pipeController(&canvas); |
| 673 | SkGPipeWriter writer; |
| 674 | SkCanvas* pipeCanvas = writer.startRecording(&pipeController, |
| 675 | SkGPipeWriter::kCrossProcess_Flag); |
| 676 | invokeGM(gm, pipeCanvas); |
| 677 | writer.endRecording(); |
| 678 | return handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 679 | "-pipe", bitmap, NULL, &comparisonBitmap); |
| 680 | } |
| 681 | |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 682 | static void write_picture_serialization(GM* gm, const ConfigData& rec, |
| 683 | const char writePicturePath[]) { |
| 684 | // only do this once, so we pick raster |
| 685 | if (kRaster_Backend == rec.fBackend && |
| 686 | SkBitmap::kARGB_8888_Config == rec.fConfig) { |
| 687 | |
| 688 | SkAutoTUnref<SkPicture> pict(generate_new_picture(gm)); |
| 689 | |
| 690 | const char* pictureSuffix = "skp"; |
| 691 | SkString path = make_filename(writePicturePath, "", |
| 692 | SkString(gm->shortName()), pictureSuffix); |
| 693 | |
| 694 | SkFILEWStream stream(path.c_str()); |
| 695 | pict->serialize(&stream); |
| 696 | } |
| 697 | } |
| 698 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 699 | static void usage(const char * argv0) { |
junov@google.com | 77e498e | 2012-01-18 18:56:34 +0000 | [diff] [blame] | 700 | SkDebugf( |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 701 | "%s [-w writePath] [-r readPath] [-d diffPath] [-i resourcePath]\n" |
scroggo@google.com | d13bdfb | 2012-06-04 17:45:54 +0000 | [diff] [blame] | 702 | " [--noreplay] [--pipe] [--serialize] [--forceBWtext] [--nopdf] \n" |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 703 | " [--nodeferred] [--match substring] [--notexturecache]\n" |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 704 | , argv0); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 705 | SkDebugf(" writePath: directory to write rendered images in.\n"); |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 706 | SkDebugf( |
| 707 | " readPath: directory to read reference images from;\n" |
| 708 | " reports if any pixels mismatch between reference and new images\n"); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 709 | SkDebugf(" diffPath: directory to write difference images in.\n"); |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 710 | SkDebugf(" resourcePath: directory that stores image resources.\n"); |
junov@google.com | 77e498e | 2012-01-18 18:56:34 +0000 | [diff] [blame] | 711 | SkDebugf(" --noreplay: do not exercise SkPicture replay.\n"); |
scroggo@google.com | d13bdfb | 2012-06-04 17:45:54 +0000 | [diff] [blame] | 712 | SkDebugf(" --pipe: Exercise SkGPipe replay.\n"); |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 713 | SkDebugf( |
| 714 | " --serialize: exercise SkPicture serialization & deserialization.\n"); |
junov@google.com | 77e498e | 2012-01-18 18:56:34 +0000 | [diff] [blame] | 715 | SkDebugf(" --forceBWtext: disable text anti-aliasing.\n"); |
| 716 | SkDebugf(" --nopdf: skip the pdf rendering test pass.\n"); |
| 717 | SkDebugf(" --nodeferred: skip the deferred rendering test pass.\n"); |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 718 | 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] | 719 | SkDebugf(" --notexturecache: disable the gpu texture cache.\n"); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 720 | } |
| 721 | |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 722 | static const GrContextFactory::GLContextType kDontCare_GLContextType = |
| 723 | GrContextFactory::kNative_GLContextType; |
| 724 | |
| 725 | // If the platform does not support writing PNGs of PDFs then there will be no |
| 726 | // comparison images to read. However, we can always write the .pdf files |
| 727 | static const ConfigFlags kPDFConfigFlags = CAN_IMAGE_PDF ? kRW_ConfigFlag : |
| 728 | kWrite_ConfigFlag; |
| 729 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 730 | static const ConfigData gRec[] = { |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 731 | { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "8888" }, |
| 732 | { SkBitmap::kARGB_4444_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "4444" }, |
| 733 | { 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] | 734 | #ifdef SK_SCALAR_IS_FLOAT |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 735 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 0, kRW_ConfigFlag, "gpu" }, |
| 736 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kNative_GLContextType, 16, kRW_ConfigFlag, "msaa16" }, |
| 737 | /* The debug context does not generate images */ |
| 738 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kDebug_GLContextType, 0, kNone_ConfigFlag, "debug" }, |
| 739 | #ifdef SK_ANGLE |
| 740 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 0, kRW_ConfigFlag, "angle" }, |
| 741 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 16, kRW_ConfigFlag, "anglemsaa16" }, |
| 742 | #endif |
| 743 | #ifdef SK_MESA |
| 744 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kMESA_GLContextType, 0, kRW_ConfigFlag, "mesa" }, |
| 745 | #endif |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 746 | #endif |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 747 | #ifdef SK_SUPPORT_XPS |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 748 | /* At present we have no way of comparing XPS files (either natively or by converting to PNG). */ |
| 749 | { SkBitmap::kARGB_8888_Config, kXPS_Backend, kDontCare_GLContextType, 0, kWrite_ConfigFlag, "xps" }, |
| 750 | #endif |
| 751 | #ifdef SK_SUPPORT_PDF |
| 752 | { SkBitmap::kARGB_8888_Config, kPDF_Backend, kDontCare_GLContextType, 0, kPDFConfigFlags, "pdf" }, |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 753 | #endif |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 754 | }; |
| 755 | |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 756 | static bool skip_name(const SkTDArray<const char*> array, const char name[]) { |
| 757 | if (0 == array.count()) { |
| 758 | // no names, so don't skip anything |
| 759 | return false; |
| 760 | } |
| 761 | for (int i = 0; i < array.count(); ++i) { |
| 762 | if (strstr(name, array[i])) { |
| 763 | // found the name, so don't skip |
| 764 | return false; |
| 765 | } |
| 766 | } |
| 767 | return true; |
| 768 | } |
| 769 | |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 770 | namespace skiagm { |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 771 | SkAutoTUnref<GrContext> gGrContext; |
| 772 | /** |
| 773 | * Sets the global GrContext, accessible by indivual GMs |
| 774 | */ |
| 775 | void SetGr(GrContext* grContext) { |
| 776 | SkSafeRef(grContext); |
| 777 | gGrContext.reset(grContext); |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 778 | } |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 779 | |
| 780 | /** |
| 781 | * Gets the global GrContext, can be called by GM tests. |
| 782 | */ |
| 783 | GrContext* GetGr() { |
| 784 | return gGrContext.get(); |
| 785 | } |
| 786 | |
| 787 | /** |
| 788 | * Sets the global GrContext and then resets it to its previous value at |
| 789 | * destruction. |
| 790 | */ |
| 791 | class AutoResetGr : SkNoncopyable { |
| 792 | public: |
| 793 | AutoResetGr() : fOld(NULL) {} |
| 794 | void set(GrContext* context) { |
| 795 | SkASSERT(NULL == fOld); |
| 796 | fOld = GetGr(); |
| 797 | SkSafeRef(fOld); |
| 798 | SetGr(context); |
| 799 | } |
| 800 | ~AutoResetGr() { SetGr(fOld); SkSafeUnref(fOld); } |
| 801 | private: |
| 802 | GrContext* fOld; |
| 803 | }; |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 804 | } |
| 805 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 806 | int main(int argc, char * const argv[]) { |
robertphillips@google.com | 25c1993 | 2012-06-05 16:24:32 +0000 | [diff] [blame] | 807 | SkAutoGraphics ag; |
reed@google.com | 8923c6c | 2011-11-08 14:59:38 +0000 | [diff] [blame] | 808 | // we don't need to see this during a run |
| 809 | gSkSuppressFontCachePurgeSpew = true; |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 810 | |
epoger@google.com | 7bc13a6 | 2012-02-14 14:53:59 +0000 | [diff] [blame] | 811 | setSystemPreferences(); |
| 812 | |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 813 | 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] | 814 | 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] | 815 | 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] | 816 | 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] | 817 | 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] | 818 | |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 819 | SkTDArray<const char*> fMatches; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 820 | |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 821 | bool doPDF = true; |
reed@google.com | b8b0983 | 2011-05-26 15:57:56 +0000 | [diff] [blame] | 822 | bool doReplay = true; |
scroggo@google.com | d13bdfb | 2012-06-04 17:45:54 +0000 | [diff] [blame] | 823 | bool doPipe = false; |
tomhudson@google.com | 6abfa49 | 2011-04-26 14:59:32 +0000 | [diff] [blame] | 824 | bool doSerialize = false; |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 825 | bool useDebugGL = false; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 826 | bool doDeferred = true; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 827 | bool disableTextureCache = false; |
| 828 | |
reed@google.com | e8fcb50 | 2012-05-17 15:28:20 +0000 | [diff] [blame] | 829 | gNotifyMissingReadReference = true; |
| 830 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 831 | const char* const commandName = argv[0]; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 832 | char* const* stop = argv + argc; |
| 833 | for (++argv; argv < stop; ++argv) { |
| 834 | if (strcmp(*argv, "-w") == 0) { |
| 835 | argv++; |
| 836 | if (argv < stop && **argv) { |
| 837 | writePath = *argv; |
| 838 | } |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 839 | } else if (strcmp(*argv, "-wp") == 0) { |
| 840 | argv++; |
| 841 | if (argv < stop && **argv) { |
| 842 | writePicturePath = *argv; |
| 843 | } |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 844 | } else if (strcmp(*argv, "-r") == 0) { |
| 845 | argv++; |
| 846 | if (argv < stop && **argv) { |
| 847 | readPath = *argv; |
| 848 | } |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 849 | } else if (strcmp(*argv, "-d") == 0) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 850 | argv++; |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 851 | if (argv < stop && **argv) { |
| 852 | diffPath = *argv; |
| 853 | } |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 854 | } else if (strcmp(*argv, "-i") == 0) { |
| 855 | argv++; |
| 856 | if (argv < stop && **argv) { |
| 857 | resourcePath = *argv; |
| 858 | } |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 859 | } else if (strcmp(*argv, "--forceBWtext") == 0) { |
| 860 | gForceBWtext = true; |
scroggo@google.com | d13bdfb | 2012-06-04 17:45:54 +0000 | [diff] [blame] | 861 | } else if (strcmp(*argv, "--pipe") == 0) { |
| 862 | doPipe = true; |
reed@google.com | b8b0983 | 2011-05-26 15:57:56 +0000 | [diff] [blame] | 863 | } else if (strcmp(*argv, "--noreplay") == 0) { |
| 864 | doReplay = false; |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 865 | } else if (strcmp(*argv, "--nopdf") == 0) { |
| 866 | doPDF = false; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 867 | } else if (strcmp(*argv, "--nodeferred") == 0) { |
| 868 | doDeferred = false; |
reed@google.com | e8fcb50 | 2012-05-17 15:28:20 +0000 | [diff] [blame] | 869 | } else if (strcmp(*argv, "--disable-missing-warning") == 0) { |
| 870 | gNotifyMissingReadReference = false; |
| 871 | } else if (strcmp(*argv, "--enable-missing-warning") == 0) { |
| 872 | gNotifyMissingReadReference = true; |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 873 | } else if (strcmp(*argv, "--serialize") == 0) { |
| 874 | doSerialize = true; |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 875 | } else if (strcmp(*argv, "--match") == 0) { |
| 876 | ++argv; |
| 877 | if (argv < stop && **argv) { |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 878 | // just record the ptr, no need for a deep copy |
| 879 | *fMatches.append() = *argv; |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 880 | } |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 881 | } else if (strcmp(*argv, "--notexturecache") == 0) { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 882 | disableTextureCache = true; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 883 | } else { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 884 | usage(commandName); |
| 885 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 886 | } |
| 887 | } |
| 888 | if (argv != stop) { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 889 | usage(commandName); |
| 890 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 891 | } |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 892 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 893 | GM::SetResourcePath(resourcePath); |
| 894 | |
robertphillips@google.com | 25c1993 | 2012-06-05 16:24:32 +0000 | [diff] [blame] | 895 | GrContextFactory grFactory; |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 896 | |
reed@android.com | 00f883e | 2010-12-14 17:46:14 +0000 | [diff] [blame] | 897 | if (readPath) { |
| 898 | fprintf(stderr, "reading from %s\n", readPath); |
epoger@google.com | 9284ccd | 2012-04-18 13:36:54 +0000 | [diff] [blame] | 899 | } |
| 900 | if (writePath) { |
reed@android.com | 00f883e | 2010-12-14 17:46:14 +0000 | [diff] [blame] | 901 | fprintf(stderr, "writing to %s\n", writePath); |
| 902 | } |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 903 | if (writePicturePath) { |
| 904 | fprintf(stderr, "writing pictures to %s\n", writePicturePath); |
| 905 | } |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 906 | if (resourcePath) { |
| 907 | fprintf(stderr, "reading resources from %s\n", resourcePath); |
| 908 | } |
| 909 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 910 | // Accumulate success of all tests. |
| 911 | int testsRun = 0; |
| 912 | int testsPassed = 0; |
| 913 | int testsFailed = 0; |
| 914 | int testsMissingReferenceImages = 0; |
| 915 | |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 916 | if (disableTextureCache) { |
| 917 | skiagm::GetGr()->setTextureCacheLimits(0, 0); |
| 918 | } |
| 919 | |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 920 | Iter iter; |
| 921 | GM* gm; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 922 | while ((gm = iter.next()) != NULL) { |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 923 | const char* shortName = gm->shortName(); |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 924 | if (skip_name(fMatches, shortName)) { |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 925 | SkDELETE(gm); |
| 926 | continue; |
| 927 | } |
| 928 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 929 | SkISize size = gm->getISize(); |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 930 | SkDebugf("drawing... %s [%d %d]\n", shortName, |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 931 | size.width(), size.height()); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 932 | SkBitmap forwardRenderedBitmap; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 933 | |
bsalomon@google.com | 29d3501 | 2011-11-30 16:57:21 +0000 | [diff] [blame] | 934 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 935 | SkAutoTUnref<GrRenderTarget> rt; |
| 936 | AutoResetGr autogr; |
| 937 | if (kGPU_Backend == gRec[i].fBackend) { |
robertphillips@google.com | 25c1993 | 2012-06-05 16:24:32 +0000 | [diff] [blame] | 938 | GrContext* gr = grFactory.get(gRec[i].fGLContextType); |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 939 | if (!gr) { |
| 940 | continue; |
| 941 | } |
| 942 | |
| 943 | // create a render target to back the device |
| 944 | GrTextureDesc desc; |
| 945 | desc.fConfig = kSkia8888_PM_GrPixelConfig; |
| 946 | desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 947 | desc.fWidth = gm->getISize().width(); |
| 948 | desc.fHeight = gm->getISize().height(); |
| 949 | desc.fSampleCnt = gRec[i].fSampleCnt; |
| 950 | GrTexture* tex = gr->createUncachedTexture(desc, NULL, 0); |
| 951 | if (!tex) { |
bsalomon@google.com | daf12bb | 2012-04-20 19:08:44 +0000 | [diff] [blame] | 952 | continue; |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 953 | } |
| 954 | rt.reset(tex->asRenderTarget()); |
| 955 | rt.get()->ref(); |
| 956 | tex->unref(); |
| 957 | |
| 958 | autogr.set(gr); |
| 959 | } |
| 960 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 961 | // Skip any tests that we don't even need to try. |
bsalomon@google.com | 29d3501 | 2011-11-30 16:57:21 +0000 | [diff] [blame] | 962 | uint32_t gmFlags = gm->getFlags(); |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 963 | if ((kPDF_Backend == gRec[i].fBackend) && |
bungeman@google.com | 64e011a | 2011-09-19 19:31:04 +0000 | [diff] [blame] | 964 | (!doPDF || (gmFlags & GM::kSkipPDF_Flag))) |
| 965 | { |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 966 | continue; |
| 967 | } |
| 968 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 969 | // Now we know that we want to run this test and record its |
| 970 | // success or failure. |
| 971 | ErrorBitfield testErrors = ERROR_NONE; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 972 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 973 | if ((ERROR_NONE == testErrors) && |
| 974 | (kGPU_Backend == gRec[i].fBackend) && |
| 975 | (NULL == rt.get())) { |
| 976 | fprintf(stderr, "Could not create render target for gpu.\n"); |
| 977 | testErrors |= ERROR_NO_GPU_CONTEXT; |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 978 | } |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 979 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 980 | if (ERROR_NONE == testErrors) { |
| 981 | testErrors |= test_drawing(gm, gRec[i], |
| 982 | writePath, readPath, diffPath, |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 983 | GetGr(), |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 984 | rt.get(), &forwardRenderedBitmap); |
| 985 | } |
| 986 | |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 987 | if (doDeferred && !testErrors && |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 988 | (kGPU_Backend == gRec[i].fBackend || |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 989 | kRaster_Backend == gRec[i].fBackend)) { |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 990 | testErrors |= test_deferred_drawing(gm, gRec[i], |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 991 | forwardRenderedBitmap, |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 992 | diffPath, GetGr(), rt.get()); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 993 | } |
| 994 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 995 | if ((ERROR_NONE == testErrors) && doReplay && |
| 996 | !(gmFlags & GM::kSkipPicture_Flag)) { |
| 997 | testErrors |= test_picture_playback(gm, gRec[i], |
| 998 | forwardRenderedBitmap, |
| 999 | readPath, diffPath); |
| 1000 | } |
| 1001 | |
scroggo@google.com | 5af9b20 | 2012-06-04 17:17:36 +0000 | [diff] [blame] | 1002 | if ((ERROR_NONE == testErrors) && doPipe && |
| 1003 | !(gmFlags & GM::kSkipPipe_Flag)) { |
| 1004 | testErrors |= test_pipe_playback(gm, gRec[i], |
| 1005 | forwardRenderedBitmap, |
| 1006 | readPath, diffPath); |
| 1007 | } |
| 1008 | |
djsollen@google.com | a2ca41e | 2012-03-23 19:00:34 +0000 | [diff] [blame] | 1009 | if ((ERROR_NONE == testErrors) && doSerialize && |
| 1010 | !(gmFlags & GM::kSkipPicture_Flag)) { |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1011 | testErrors |= test_picture_serialization(gm, gRec[i], |
| 1012 | forwardRenderedBitmap, |
| 1013 | readPath, diffPath); |
| 1014 | } |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 1015 | |
| 1016 | if (!(gmFlags & GM::kSkipPicture_Flag) && writePicturePath) { |
| 1017 | write_picture_serialization(gm, gRec[i], writePicturePath); |
| 1018 | } |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1019 | |
| 1020 | // Update overall results. |
| 1021 | // We only tabulate the particular error types that we currently |
| 1022 | // care about (e.g., missing reference images). Later on, if we |
| 1023 | // want to also tabulate pixel mismatches vs dimension mistmatches |
| 1024 | // (or whatever else), we can do so. |
| 1025 | testsRun++; |
| 1026 | if (ERROR_NONE == testErrors) { |
| 1027 | testsPassed++; |
| 1028 | } else if (ERROR_READING_REFERENCE_IMAGE & testErrors) { |
| 1029 | testsMissingReferenceImages++; |
| 1030 | } else { |
| 1031 | testsFailed++; |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 1032 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1033 | } |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1034 | SkDELETE(gm); |
| 1035 | } |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1036 | printf("Ran %d tests: %d passed, %d failed, %d missing reference images\n", |
| 1037 | testsRun, testsPassed, testsFailed, testsMissingReferenceImages); |
robertphillips@google.com | f6f123d | 2012-03-21 17:57:55 +0000 | [diff] [blame] | 1038 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1039 | return (0 == testsFailed) ? 0 : -1; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1040 | } |