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