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 | |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 623 | struct PipeFlagComboData { |
| 624 | const char* name; |
| 625 | uint32_t flags; |
| 626 | }; |
| 627 | |
| 628 | static PipeFlagComboData gPipeWritingFlagCombos[] = { |
| 629 | { "", 0 }, |
| 630 | { " cross-process", SkGPipeWriter::kCrossProcess_Flag }, |
scroggo | b3c0f48 | 2012-07-02 19:07:57 +0000 | [diff] [blame] | 631 | { " cross-process, shared address", SkGPipeWriter::kCrossProcess_Flag |
scroggo@google.com | 15011ee | 2012-07-26 20:03:32 +0000 | [diff] [blame] | 632 | | SkGPipeWriter::kSharedAddressSpace_Flag } |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 633 | }; |
| 634 | |
scroggo@google.com | 5af9b20 | 2012-06-04 17:17:36 +0000 | [diff] [blame] | 635 | static ErrorBitfield test_pipe_playback(GM* gm, |
| 636 | const ConfigData& gRec, |
epoger@google.com | f28dd8a | 2012-10-25 16:27:34 +0000 | [diff] [blame] | 637 | const SkBitmap& referenceBitmap, |
scroggo@google.com | 5af9b20 | 2012-06-04 17:17:36 +0000 | [diff] [blame] | 638 | const char readPath [], |
| 639 | const char diffPath []) { |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 640 | ErrorBitfield errors = ERROR_NONE; |
| 641 | for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) { |
| 642 | SkBitmap bitmap; |
| 643 | SkISize size = gm->getISize(); |
| 644 | setup_bitmap(gRec, size, &bitmap); |
| 645 | SkCanvas canvas(bitmap); |
| 646 | PipeController pipeController(&canvas); |
| 647 | SkGPipeWriter writer; |
epoger@google.com | f28dd8a | 2012-10-25 16:27:34 +0000 | [diff] [blame] | 648 | SkCanvas* pipeCanvas = writer.startRecording( |
| 649 | &pipeController, gPipeWritingFlagCombos[i].flags); |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 650 | invokeGM(gm, pipeCanvas); |
| 651 | writer.endRecording(); |
| 652 | SkString string("-pipe"); |
| 653 | string.append(gPipeWritingFlagCombos[i].name); |
| 654 | errors |= handle_test_results(gm, gRec, NULL, NULL, diffPath, |
epoger@google.com | f28dd8a | 2012-10-25 16:27:34 +0000 | [diff] [blame] | 655 | string.c_str(), bitmap, NULL, |
| 656 | &referenceBitmap); |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 657 | if (errors != ERROR_NONE) { |
| 658 | break; |
| 659 | } |
| 660 | } |
| 661 | return errors; |
scroggo@google.com | 5af9b20 | 2012-06-04 17:17:36 +0000 | [diff] [blame] | 662 | } |
| 663 | |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 664 | static ErrorBitfield test_tiled_pipe_playback(GM* gm, |
| 665 | const ConfigData& gRec, |
epoger@google.com | f28dd8a | 2012-10-25 16:27:34 +0000 | [diff] [blame] | 666 | const SkBitmap& referenceBitmap, |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 667 | const char readPath [], |
| 668 | const char diffPath []) { |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 669 | ErrorBitfield errors = ERROR_NONE; |
| 670 | for (size_t i = 0; i < SK_ARRAY_COUNT(gPipeWritingFlagCombos); ++i) { |
| 671 | SkBitmap bitmap; |
| 672 | SkISize size = gm->getISize(); |
| 673 | setup_bitmap(gRec, size, &bitmap); |
| 674 | SkCanvas canvas(bitmap); |
| 675 | TiledPipeController pipeController(bitmap); |
| 676 | SkGPipeWriter writer; |
epoger@google.com | f28dd8a | 2012-10-25 16:27:34 +0000 | [diff] [blame] | 677 | SkCanvas* pipeCanvas = writer.startRecording( |
| 678 | &pipeController, gPipeWritingFlagCombos[i].flags); |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 679 | invokeGM(gm, pipeCanvas); |
| 680 | writer.endRecording(); |
scroggo@google.com | d3ba5cc | 2012-07-09 16:05:53 +0000 | [diff] [blame] | 681 | SkString string("-tiled pipe"); |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 682 | string.append(gPipeWritingFlagCombos[i].name); |
| 683 | errors |= handle_test_results(gm, gRec, NULL, NULL, diffPath, |
epoger@google.com | f28dd8a | 2012-10-25 16:27:34 +0000 | [diff] [blame] | 684 | string.c_str(), bitmap, NULL, |
| 685 | &referenceBitmap); |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 686 | if (errors != ERROR_NONE) { |
| 687 | break; |
| 688 | } |
| 689 | } |
| 690 | return errors; |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 691 | } |
| 692 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 693 | #if SK_SUPPORT_GPU |
| 694 | static const GLContextType kDontCare_GLContextType = GrContextFactory::kNative_GLContextType; |
| 695 | #else |
| 696 | static const GLContextType kDontCare_GLContextType = 0; |
| 697 | #endif |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 698 | |
| 699 | // 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] | 700 | // 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] | 701 | static const ConfigFlags kPDFConfigFlags = CAN_IMAGE_PDF ? kRW_ConfigFlag : |
| 702 | kWrite_ConfigFlag; |
| 703 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 704 | static const ConfigData gRec[] = { |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 705 | { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "8888" }, |
| 706 | { SkBitmap::kARGB_4444_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "4444" }, |
| 707 | { 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] | 708 | #if defined(SK_SCALAR_IS_FLOAT) && SK_SUPPORT_GPU |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 709 | { 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] | 710 | #ifndef SK_BUILD_FOR_ANDROID |
| 711 | // currently we don't want to run MSAA tests on Android |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 712 | { 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] | 713 | #endif |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 714 | /* The debug context does not generate images */ |
| 715 | { 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] | 716 | #if SK_ANGLE |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 717 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, GrContextFactory::kANGLE_GLContextType, 0, kRW_ConfigFlag, "angle" }, |
| 718 | { 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] | 719 | #endif // SK_ANGLE |
| 720 | #ifdef SK_MESA |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 721 | { 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] | 722 | #endif // SK_MESA |
robertphillips@google.com | a73e860 | 2012-08-02 17:56:02 +0000 | [diff] [blame] | 723 | #endif // defined(SK_SCALAR_IS_FLOAT) && SK_SUPPORT_GPU |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 724 | #ifdef SK_SUPPORT_XPS |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 725 | /* At present we have no way of comparing XPS files (either natively or by converting to PNG). */ |
| 726 | { 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] | 727 | #endif // SK_SUPPORT_XPS |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 728 | #ifdef SK_SUPPORT_PDF |
| 729 | { SkBitmap::kARGB_8888_Config, kPDF_Backend, kDontCare_GLContextType, 0, kPDFConfigFlags, "pdf" }, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 730 | #endif // SK_SUPPORT_PDF |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 731 | }; |
| 732 | |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 733 | static void usage(const char * argv0) { |
| 734 | SkDebugf("%s\n", argv0); |
| 735 | SkDebugf(" [-w writePath] [-r readPath] [-d diffPath] [-i resourcePath]\n"); |
chudy@google.com | f32f6e8 | 2012-07-12 15:42:37 +0000 | [diff] [blame] | 736 | SkDebugf(" [-wp writePicturePath]\n"); |
reed@google.com | e5f48b9 | 2012-06-22 15:27:39 +0000 | [diff] [blame] | 737 | SkDebugf(" [--config "); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 738 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 739 | if (i > 0) { |
| 740 | SkDebugf("|"); |
| 741 | } |
| 742 | SkDebugf(gRec[i].fName); |
| 743 | } |
| 744 | SkDebugf(" ]\n"); |
scroggo@google.com | 3936252 | 2012-09-14 17:37:46 +0000 | [diff] [blame] | 745 | SkDebugf(" [--noreplay] [--nopipe] [--noserialize] [--forceBWtext] [--nopdf] \n" |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 746 | " [--tiledPipe] \n" |
| 747 | " [--nodeferred] [--match substring] [--notexturecache]\n" |
| 748 | " [-h|--help]\n" |
| 749 | ); |
| 750 | SkDebugf(" writePath: directory to write rendered images in.\n"); |
chudy@google.com | f32f6e8 | 2012-07-12 15:42:37 +0000 | [diff] [blame] | 751 | SkDebugf(" writePicturePath: directory to write images to in .skp format.\n"); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 752 | SkDebugf( |
| 753 | " readPath: directory to read reference images from;\n" |
| 754 | " reports if any pixels mismatch between reference and new images\n"); |
| 755 | SkDebugf(" diffPath: directory to write difference images in.\n"); |
| 756 | SkDebugf(" resourcePath: directory that stores image resources.\n"); |
| 757 | SkDebugf(" --noreplay: do not exercise SkPicture replay.\n"); |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 758 | SkDebugf(" --nopipe: Skip SkGPipe replay.\n"); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 759 | SkDebugf(" --tiledPipe: Exercise tiled SkGPipe replay.\n"); |
| 760 | SkDebugf( |
scroggo@google.com | 3936252 | 2012-09-14 17:37:46 +0000 | [diff] [blame] | 761 | " --noserialize: do not exercise SkPicture serialization & deserialization.\n"); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 762 | SkDebugf(" --forceBWtext: disable text anti-aliasing.\n"); |
| 763 | SkDebugf(" --nopdf: skip the pdf rendering test pass.\n"); |
| 764 | SkDebugf(" --nodeferred: skip the deferred rendering test pass.\n"); |
| 765 | SkDebugf(" --match foo: will only run tests that substring match foo.\n"); |
| 766 | SkDebugf(" --notexturecache: disable the gpu texture cache.\n"); |
| 767 | SkDebugf(" -h|--help : Show this help message. \n"); |
| 768 | } |
| 769 | |
| 770 | static int findConfig(const char config[]) { |
| 771 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { |
| 772 | if (!strcmp(config, gRec[i].fName)) { |
| 773 | return i; |
| 774 | } |
| 775 | } |
| 776 | return -1; |
| 777 | } |
| 778 | |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 779 | static bool skip_name(const SkTDArray<const char*> array, const char name[]) { |
| 780 | if (0 == array.count()) { |
| 781 | // no names, so don't skip anything |
| 782 | return false; |
| 783 | } |
| 784 | for (int i = 0; i < array.count(); ++i) { |
| 785 | if (strstr(name, array[i])) { |
| 786 | // found the name, so don't skip |
| 787 | return false; |
| 788 | } |
| 789 | } |
| 790 | return true; |
| 791 | } |
| 792 | |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 793 | namespace skiagm { |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 794 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 795 | SkAutoTUnref<GrContext> gGrContext; |
| 796 | /** |
| 797 | * Sets the global GrContext, accessible by indivual GMs |
| 798 | */ |
caryclark@google.com | 1313086 | 2012-06-06 12:10:45 +0000 | [diff] [blame] | 799 | static void SetGr(GrContext* grContext) { |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 800 | SkSafeRef(grContext); |
| 801 | gGrContext.reset(grContext); |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 802 | } |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 803 | |
| 804 | /** |
| 805 | * Gets the global GrContext, can be called by GM tests. |
| 806 | */ |
caryclark@google.com | 1313086 | 2012-06-06 12:10:45 +0000 | [diff] [blame] | 807 | GrContext* GetGr(); |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 808 | GrContext* GetGr() { |
| 809 | return gGrContext.get(); |
| 810 | } |
| 811 | |
| 812 | /** |
| 813 | * Sets the global GrContext and then resets it to its previous value at |
| 814 | * destruction. |
| 815 | */ |
| 816 | class AutoResetGr : SkNoncopyable { |
| 817 | public: |
| 818 | AutoResetGr() : fOld(NULL) {} |
| 819 | void set(GrContext* context) { |
| 820 | SkASSERT(NULL == fOld); |
| 821 | fOld = GetGr(); |
| 822 | SkSafeRef(fOld); |
| 823 | SetGr(context); |
| 824 | } |
| 825 | ~AutoResetGr() { SetGr(fOld); SkSafeUnref(fOld); } |
| 826 | private: |
| 827 | GrContext* fOld; |
| 828 | }; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 829 | #else |
| 830 | GrContext* GetGr() { return NULL; } |
| 831 | #endif |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 832 | } |
| 833 | |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 834 | static bool is_recordable_failure(ErrorBitfield errorCode) { |
| 835 | return ERROR_NONE != errorCode && !(ERROR_READING_REFERENCE_IMAGE & errorCode); |
| 836 | } |
| 837 | |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 838 | int tool_main(int argc, char** argv); |
| 839 | int tool_main(int argc, char** argv) { |
robertphillips@google.com | b74af87 | 2012-06-27 19:41:42 +0000 | [diff] [blame] | 840 | |
| 841 | #ifdef SK_ENABLE_INST_COUNT |
| 842 | gPrintInstCount = true; |
| 843 | #endif |
| 844 | |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 845 | SkGraphics::Init(); |
reed@google.com | 8923c6c | 2011-11-08 14:59:38 +0000 | [diff] [blame] | 846 | // we don't need to see this during a run |
| 847 | gSkSuppressFontCachePurgeSpew = true; |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 848 | |
epoger@google.com | 7bc13a6 | 2012-02-14 14:53:59 +0000 | [diff] [blame] | 849 | setSystemPreferences(); |
| 850 | |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 851 | 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] | 852 | 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] | 853 | 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] | 854 | 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] | 855 | 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] | 856 | |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 857 | SkTDArray<const char*> fMatches; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 858 | |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 859 | bool doPDF = true; |
reed@google.com | b8b0983 | 2011-05-26 15:57:56 +0000 | [diff] [blame] | 860 | bool doReplay = true; |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 861 | bool doPipe = true; |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 862 | bool doTiledPipe = false; |
scroggo@google.com | 3936252 | 2012-09-14 17:37:46 +0000 | [diff] [blame] | 863 | bool doSerialize = true; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 864 | bool doDeferred = true; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 865 | bool disableTextureCache = false; |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 866 | SkTDArray<size_t> configs; |
| 867 | bool userConfig = false; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 868 | |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 869 | int moduloIndex = -1; |
| 870 | int moduloCount = -1; |
| 871 | |
reed@google.com | e8fcb50 | 2012-05-17 15:28:20 +0000 | [diff] [blame] | 872 | gNotifyMissingReadReference = true; |
| 873 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 874 | const char* const commandName = argv[0]; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 875 | char* const* stop = argv + argc; |
| 876 | for (++argv; argv < stop; ++argv) { |
| 877 | if (strcmp(*argv, "-w") == 0) { |
| 878 | argv++; |
| 879 | if (argv < stop && **argv) { |
| 880 | writePath = *argv; |
| 881 | } |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 882 | } else if (strcmp(*argv, "-wp") == 0) { |
| 883 | argv++; |
| 884 | if (argv < stop && **argv) { |
| 885 | writePicturePath = *argv; |
| 886 | } |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 887 | } else if (strcmp(*argv, "-r") == 0) { |
| 888 | argv++; |
| 889 | if (argv < stop && **argv) { |
| 890 | readPath = *argv; |
| 891 | } |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 892 | } else if (strcmp(*argv, "-d") == 0) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 893 | argv++; |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 894 | if (argv < stop && **argv) { |
| 895 | diffPath = *argv; |
| 896 | } |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 897 | } else if (strcmp(*argv, "-i") == 0) { |
| 898 | argv++; |
| 899 | if (argv < stop && **argv) { |
| 900 | resourcePath = *argv; |
| 901 | } |
mike@reedtribe.org | 10afbef | 2011-12-30 16:02:53 +0000 | [diff] [blame] | 902 | } else if (strcmp(*argv, "--forceBWtext") == 0) { |
| 903 | gForceBWtext = true; |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 904 | } else if (strcmp(*argv, "--nopipe") == 0) { |
| 905 | doPipe = false; |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 906 | } else if (strcmp(*argv, "--tiledPipe") == 0) { |
| 907 | doTiledPipe = true; |
reed@google.com | b8b0983 | 2011-05-26 15:57:56 +0000 | [diff] [blame] | 908 | } else if (strcmp(*argv, "--noreplay") == 0) { |
| 909 | doReplay = false; |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 910 | } else if (strcmp(*argv, "--nopdf") == 0) { |
| 911 | doPDF = false; |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 912 | } else if (strcmp(*argv, "--nodeferred") == 0) { |
| 913 | doDeferred = false; |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 914 | } else if (strcmp(*argv, "--modulo") == 0) { |
| 915 | ++argv; |
| 916 | if (argv >= stop) { |
| 917 | continue; |
| 918 | } |
| 919 | moduloIndex = atoi(*argv); |
skia.committer@gmail.com | 6a748ad | 2012-10-19 02:01:19 +0000 | [diff] [blame] | 920 | |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 921 | ++argv; |
| 922 | if (argv >= stop) { |
| 923 | continue; |
| 924 | } |
| 925 | moduloCount = atoi(*argv); |
reed@google.com | e8fcb50 | 2012-05-17 15:28:20 +0000 | [diff] [blame] | 926 | } else if (strcmp(*argv, "--disable-missing-warning") == 0) { |
| 927 | gNotifyMissingReadReference = false; |
| 928 | } else if (strcmp(*argv, "--enable-missing-warning") == 0) { |
| 929 | gNotifyMissingReadReference = true; |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 930 | } else if (strcmp(*argv, "--serialize") == 0) { |
scroggo@google.com | 3936252 | 2012-09-14 17:37:46 +0000 | [diff] [blame] | 931 | // Leaving in this option so that a user need not modify their command line arguments |
| 932 | // to still run. |
borenet@google.com | 14ca1d3 | 2012-06-15 13:46:44 +0000 | [diff] [blame] | 933 | doSerialize = true; |
scroggo@google.com | 3936252 | 2012-09-14 17:37:46 +0000 | [diff] [blame] | 934 | } else if (strcmp(*argv, "--noserialize") == 0) { |
| 935 | doSerialize = false; |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 936 | } else if (strcmp(*argv, "--match") == 0) { |
| 937 | ++argv; |
| 938 | if (argv < stop && **argv) { |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 939 | // just record the ptr, no need for a deep copy |
| 940 | *fMatches.append() = *argv; |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 941 | } |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 942 | } else if (strcmp(*argv, "--notexturecache") == 0) { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 943 | disableTextureCache = true; |
reed@google.com | e5f48b9 | 2012-06-22 15:27:39 +0000 | [diff] [blame] | 944 | } else if (strcmp(*argv, "--config") == 0) { |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 945 | argv++; |
| 946 | if (argv < stop) { |
| 947 | int index = findConfig(*argv); |
| 948 | if (index >= 0) { |
| 949 | *configs.append() = index; |
| 950 | userConfig = true; |
| 951 | } else { |
| 952 | SkString str; |
| 953 | str.printf("unrecognized config %s\n", *argv); |
| 954 | SkDebugf(str.c_str()); |
| 955 | usage(commandName); |
| 956 | return -1; |
| 957 | } |
| 958 | } else { |
reed@google.com | e5f48b9 | 2012-06-22 15:27:39 +0000 | [diff] [blame] | 959 | SkDebugf("missing arg for --config\n"); |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 960 | usage(commandName); |
| 961 | return -1; |
| 962 | } |
| 963 | } else if (strcmp(*argv, "--help") == 0 || strcmp(*argv, "-h") == 0) { |
| 964 | usage(commandName); |
| 965 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 966 | } else { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 967 | usage(commandName); |
| 968 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 969 | } |
| 970 | } |
| 971 | if (argv != stop) { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 972 | usage(commandName); |
| 973 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 974 | } |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 975 | |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 976 | if (!userConfig) { |
| 977 | // if no config is specified by user, we add them all. |
| 978 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 979 | *configs.append() = i; |
| 980 | } |
| 981 | } |
| 982 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 983 | GM::SetResourcePath(resourcePath); |
| 984 | |
reed@android.com | 00f883e | 2010-12-14 17:46:14 +0000 | [diff] [blame] | 985 | if (readPath) { |
| 986 | fprintf(stderr, "reading from %s\n", readPath); |
chudy@google.com | f32f6e8 | 2012-07-12 15:42:37 +0000 | [diff] [blame] | 987 | } |
epoger@google.com | 9284ccd | 2012-04-18 13:36:54 +0000 | [diff] [blame] | 988 | if (writePath) { |
reed@android.com | 00f883e | 2010-12-14 17:46:14 +0000 | [diff] [blame] | 989 | fprintf(stderr, "writing to %s\n", writePath); |
| 990 | } |
mike@reedtribe.org | 5d0c62f | 2012-06-02 14:50:13 +0000 | [diff] [blame] | 991 | if (writePicturePath) { |
| 992 | fprintf(stderr, "writing pictures to %s\n", writePicturePath); |
| 993 | } |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 994 | if (resourcePath) { |
| 995 | fprintf(stderr, "reading resources from %s\n", resourcePath); |
| 996 | } |
| 997 | |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 998 | if (moduloCount <= 0) { |
| 999 | moduloIndex = -1; |
| 1000 | } |
| 1001 | if (moduloIndex < 0 || moduloIndex >= moduloCount) { |
| 1002 | moduloIndex = -1; |
| 1003 | } |
| 1004 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1005 | // Accumulate success of all tests. |
| 1006 | int testsRun = 0; |
| 1007 | int testsPassed = 0; |
| 1008 | int testsFailed = 0; |
| 1009 | int testsMissingReferenceImages = 0; |
| 1010 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1011 | #if SK_SUPPORT_GPU |
| 1012 | GrContextFactory* grFactory = new GrContextFactory; |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 1013 | if (disableTextureCache) { |
| 1014 | skiagm::GetGr()->setTextureCacheLimits(0, 0); |
| 1015 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1016 | #endif |
twiz@google.com | e24a079 | 2012-01-31 18:35:30 +0000 | [diff] [blame] | 1017 | |
robertphillips@google.com | a2f8008 | 2012-08-02 16:22:47 +0000 | [diff] [blame] | 1018 | SkTArray<SkString> failedTests; |
| 1019 | |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1020 | int gmIndex = -1; |
| 1021 | SkString moduloStr; |
| 1022 | |
bsalomon@google.com | 7361f54 | 2012-04-19 19:15:35 +0000 | [diff] [blame] | 1023 | Iter iter; |
| 1024 | GM* gm; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1025 | while ((gm = iter.next()) != NULL) { |
skia.committer@gmail.com | 6a748ad | 2012-10-19 02:01:19 +0000 | [diff] [blame] | 1026 | |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1027 | ++gmIndex; |
| 1028 | if (moduloIndex >= 0) { |
| 1029 | if ((gmIndex % moduloCount) != moduloIndex) { |
| 1030 | continue; |
| 1031 | } |
reed@google.com | b5a5a9d | 2012-10-25 17:58:23 +0000 | [diff] [blame] | 1032 | moduloStr.printf("[%d.%d] ", gmIndex, moduloCount); |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1033 | } |
| 1034 | |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 1035 | const char* shortName = gm->shortName(); |
reed@google.com | b2a5162 | 2011-10-31 16:30:04 +0000 | [diff] [blame] | 1036 | if (skip_name(fMatches, shortName)) { |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 1037 | SkDELETE(gm); |
| 1038 | continue; |
| 1039 | } |
| 1040 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1041 | SkISize size = gm->getISize(); |
reed@google.com | ae7b8f3 | 2012-10-18 21:30:57 +0000 | [diff] [blame] | 1042 | SkDebugf("%sdrawing... %s [%d %d]\n", moduloStr.c_str(), shortName, |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 1043 | size.width(), size.height()); |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1044 | |
| 1045 | ErrorBitfield testErrors = ERROR_NONE; |
| 1046 | uint32_t gmFlags = gm->getFlags(); |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 1047 | |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1048 | for (int i = 0; i < configs.count(); i++) { |
| 1049 | ConfigData config = gRec[configs[i]]; |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1050 | // Skip any tests that we don't even need to try. |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1051 | if ((kPDF_Backend == config.fBackend) && |
bungeman@google.com | 64e011a | 2011-09-19 19:31:04 +0000 | [diff] [blame] | 1052 | (!doPDF || (gmFlags & GM::kSkipPDF_Flag))) |
| 1053 | { |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 1054 | continue; |
| 1055 | } |
reed@google.com | 1b6c73d | 2012-10-10 15:17:24 +0000 | [diff] [blame] | 1056 | if ((gmFlags & GM::kSkip565_Flag) && |
| 1057 | (kRaster_Backend == config.fBackend) && |
| 1058 | (SkBitmap::kRGB_565_Config == config.fConfig)) { |
| 1059 | continue; |
| 1060 | } |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame] | 1061 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1062 | // Now we know that we want to run this test and record its |
| 1063 | // success or failure. |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1064 | ErrorBitfield renderErrors = ERROR_NONE; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1065 | GrRenderTarget* renderTarget = NULL; |
| 1066 | #if SK_SUPPORT_GPU |
| 1067 | SkAutoTUnref<GrRenderTarget> rt; |
| 1068 | AutoResetGr autogr; |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1069 | if ((ERROR_NONE == renderErrors) && |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1070 | kGPU_Backend == config.fBackend) { |
| 1071 | GrContext* gr = grFactory->get(config.fGLContextType); |
| 1072 | bool grSuccess = false; |
| 1073 | if (gr) { |
| 1074 | // create a render target to back the device |
| 1075 | GrTextureDesc desc; |
| 1076 | desc.fConfig = kSkia8888_PM_GrPixelConfig; |
| 1077 | desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 1078 | desc.fWidth = gm->getISize().width(); |
| 1079 | desc.fHeight = gm->getISize().height(); |
| 1080 | desc.fSampleCnt = config.fSampleCnt; |
| 1081 | GrTexture* tex = gr->createUncachedTexture(desc, NULL, 0); |
| 1082 | if (tex) { |
| 1083 | rt.reset(tex->asRenderTarget()); |
| 1084 | rt.get()->ref(); |
| 1085 | tex->unref(); |
| 1086 | autogr.set(gr); |
| 1087 | renderTarget = rt.get(); |
| 1088 | grSuccess = NULL != renderTarget; |
| 1089 | } |
| 1090 | } |
| 1091 | if (!grSuccess) { |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1092 | renderErrors |= ERROR_NO_GPU_CONTEXT; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1093 | } |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 1094 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1095 | #endif |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 1096 | |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1097 | SkBitmap comparisonBitmap; |
| 1098 | |
| 1099 | if (ERROR_NONE == renderErrors) { |
| 1100 | renderErrors |= test_drawing(gm, config, |
| 1101 | writePath, readPath, diffPath, |
| 1102 | GetGr(), renderTarget, &comparisonBitmap); |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1103 | } |
| 1104 | |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1105 | if (doDeferred && !renderErrors && |
scroggo@google.com | 5867c0f | 2012-06-07 17:39:48 +0000 | [diff] [blame] | 1106 | (kGPU_Backend == config.fBackend || |
| 1107 | kRaster_Backend == config.fBackend)) { |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1108 | renderErrors |= test_deferred_drawing(gm, config, comparisonBitmap, |
| 1109 | diffPath, GetGr(), renderTarget); |
junov@google.com | 4370aed | 2012-01-18 16:21:08 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1112 | testErrors |= renderErrors; |
| 1113 | if (is_recordable_failure(renderErrors)) { |
robertphillips@google.com | a2f8008 | 2012-08-02 16:22:47 +0000 | [diff] [blame] | 1114 | failedTests.push_back(make_name(shortName, config.fName)); |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 1115 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 1116 | } |
djsollen@google.com | ebce16d | 2012-10-26 14:07:13 +0000 | [diff] [blame] | 1117 | |
| 1118 | SkBitmap comparisonBitmap; |
| 1119 | const ConfigData compareConfig = |
| 1120 | { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextType, 0, kRW_ConfigFlag, "comparison" }; |
| 1121 | testErrors |= generate_image(gm, compareConfig, NULL, NULL, &comparisonBitmap, false); |
| 1122 | |
| 1123 | // run the picture centric GM steps |
| 1124 | if (!(gmFlags & GM::kSkipPicture_Flag)) { |
| 1125 | |
| 1126 | ErrorBitfield pictErrors = ERROR_NONE; |
| 1127 | |
| 1128 | //SkAutoTUnref<SkPicture> pict(generate_new_picture(gm)); |
| 1129 | SkPicture* pict = generate_new_picture(gm); |
| 1130 | SkAutoUnref aur(pict); |
| 1131 | |
| 1132 | if ((ERROR_NONE == testErrors) && doReplay) { |
| 1133 | SkBitmap bitmap; |
| 1134 | generate_image_from_picture(gm, compareConfig, pict, &bitmap); |
| 1135 | pictErrors |= handle_test_results(gm, compareConfig, NULL, NULL, diffPath, |
| 1136 | "-replay", bitmap, NULL, &comparisonBitmap); |
| 1137 | if (is_recordable_failure(pictErrors)) { |
| 1138 | failedTests.push_back(make_name(shortName, "pict-replay")); |
| 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | if ((ERROR_NONE == testErrors) && (ERROR_NONE == pictErrors) && doSerialize) { |
| 1143 | SkPicture* repict = stream_to_new_picture(*pict); |
| 1144 | SkAutoUnref aurr(repict); |
| 1145 | |
| 1146 | SkBitmap bitmap; |
| 1147 | generate_image_from_picture(gm, compareConfig, repict, &bitmap); |
| 1148 | pictErrors |= handle_test_results(gm, compareConfig, NULL, NULL, diffPath, |
| 1149 | "-serialize", bitmap, NULL, &comparisonBitmap); |
| 1150 | if (is_recordable_failure(pictErrors)) { |
| 1151 | failedTests.push_back(make_name(shortName, "pict-serialize")); |
| 1152 | } |
| 1153 | } |
| 1154 | |
| 1155 | if (writePicturePath) { |
| 1156 | const char* pictureSuffix = "skp"; |
| 1157 | SkString path = make_filename(writePicturePath, "", |
| 1158 | SkString(gm->shortName()), pictureSuffix); |
| 1159 | SkFILEWStream stream(path.c_str()); |
| 1160 | pict->serialize(&stream); |
| 1161 | } |
| 1162 | |
| 1163 | testErrors |= pictErrors; |
| 1164 | } |
| 1165 | |
| 1166 | // run the pipe centric GM steps |
| 1167 | if (!(gmFlags & GM::kSkipPipe_Flag)) { |
| 1168 | |
| 1169 | ErrorBitfield pipeErrors = ERROR_NONE; |
| 1170 | |
| 1171 | if ((ERROR_NONE == testErrors) && doPipe) { |
| 1172 | pipeErrors |= test_pipe_playback(gm, compareConfig, |
| 1173 | comparisonBitmap, |
| 1174 | readPath, diffPath); |
| 1175 | if (is_recordable_failure(pipeErrors)) { |
| 1176 | failedTests.push_back(make_name(shortName, "pipe")); |
| 1177 | } |
| 1178 | } |
| 1179 | |
| 1180 | if ((ERROR_NONE == testErrors) && |
| 1181 | (ERROR_NONE == pipeErrors) && |
| 1182 | doTiledPipe && !(gmFlags & GM::kSkipTiled_Flag)) { |
| 1183 | pipeErrors |= test_tiled_pipe_playback(gm, compareConfig, |
| 1184 | comparisonBitmap, |
| 1185 | readPath, diffPath); |
| 1186 | if (is_recordable_failure(pipeErrors)) { |
| 1187 | failedTests.push_back(make_name(shortName, "pipe-tiled")); |
| 1188 | } |
| 1189 | } |
| 1190 | |
| 1191 | testErrors |= pipeErrors; |
| 1192 | } |
| 1193 | |
| 1194 | // Update overall results. |
| 1195 | // We only tabulate the particular error types that we currently |
| 1196 | // care about (e.g., missing reference images). Later on, if we |
| 1197 | // want to also tabulate pixel mismatches vs dimension mistmatches |
| 1198 | // (or whatever else), we can do so. |
| 1199 | testsRun++; |
| 1200 | if (ERROR_NONE == testErrors) { |
| 1201 | testsPassed++; |
| 1202 | } else if (ERROR_READING_REFERENCE_IMAGE & testErrors) { |
| 1203 | testsMissingReferenceImages++; |
| 1204 | } else { |
| 1205 | testsFailed++; |
| 1206 | } |
| 1207 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1208 | SkDELETE(gm); |
| 1209 | } |
robertphillips@google.com | a2f8008 | 2012-08-02 16:22:47 +0000 | [diff] [blame] | 1210 | SkDebugf("Ran %d tests: %d passed, %d failed, %d missing reference images\n", |
| 1211 | testsRun, testsPassed, testsFailed, testsMissingReferenceImages); |
| 1212 | for (int i = 0; i < failedTests.count(); ++i) { |
| 1213 | SkDebugf("\t\t%s\n", failedTests[i].c_str()); |
| 1214 | } |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 1215 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1216 | #if SK_SUPPORT_GPU |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 1217 | |
robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 1218 | #if GR_CACHE_STATS |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 1219 | for (int i = 0; i < configs.count(); i++) { |
| 1220 | ConfigData config = gRec[configs[i]]; |
| 1221 | |
| 1222 | if (kGPU_Backend == config.fBackend) { |
| 1223 | GrContext* gr = grFactory->get(config.fGLContextType); |
| 1224 | |
| 1225 | SkDebugf("config: %s %x\n", config.fName, gr); |
| 1226 | gr->printCacheStats(); |
| 1227 | } |
| 1228 | } |
| 1229 | #endif |
| 1230 | |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 1231 | delete grFactory; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 1232 | #endif |
robertphillips@google.com | 977b9c8 | 2012-06-05 19:35:09 +0000 | [diff] [blame] | 1233 | SkGraphics::Term(); |
| 1234 | |
epoger@google.com | c7cf2b3 | 2011-12-28 19:31:01 +0000 | [diff] [blame] | 1235 | return (0 == testsFailed) ? 0 : -1; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1236 | } |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 1237 | |
| 1238 | #if !defined SK_BUILD_FOR_IOS |
| 1239 | int main(int argc, char * const argv[]) { |
| 1240 | return tool_main(argc, (char**) argv); |
| 1241 | } |
| 1242 | #endif |