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