reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 1 | #include "gm.h" |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 2 | #include "SkColorPriv.h" |
reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 3 | #include "SkData.h" |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 4 | #include "SkGraphics.h" |
| 5 | #include "SkImageDecoder.h" |
| 6 | #include "SkImageEncoder.h" |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 7 | #include "SkPicture.h" |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 8 | #include "SkStream.h" |
| 9 | #include "SkRefCnt.h" |
| 10 | |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 11 | #include "GrContext.h" |
| 12 | #include "SkGpuCanvas.h" |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 13 | #include "SkGpuDevice.h" |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 14 | #include "SkEGLContext.h" |
| 15 | #include "SkDevice.h" |
| 16 | |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 17 | #ifdef SK_SUPPORT_PDF |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 18 | #include "SkPDFDevice.h" |
| 19 | #include "SkPDFDocument.h" |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 20 | #endif |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 21 | |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 22 | #ifdef SK_BUILD_FOR_MAC |
| 23 | #include "SkCGUtils.h" |
bsalomon@google.com | 0a09eef | 2011-06-29 19:42:58 +0000 | [diff] [blame] | 24 | #define CAN_IMAGE_PDF 1 |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 25 | #else |
bsalomon@google.com | 0a09eef | 2011-06-29 19:42:58 +0000 | [diff] [blame] | 26 | #define CAN_IMAGE_PDF 0 |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 27 | #endif |
| 28 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 29 | using namespace skiagm; |
| 30 | |
| 31 | // need to explicitly declare this, or we get some weird infinite loop llist |
tomhudson@google.com | a87cd2a | 2011-06-15 16:50:27 +0000 | [diff] [blame] | 32 | template GMRegistry* SkTRegistry<GM*, void*>::gHead; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 33 | |
| 34 | class Iter { |
| 35 | public: |
| 36 | Iter() { |
bsalomon@google.com | 3914958 | 2011-06-13 21:55:32 +0000 | [diff] [blame] | 37 | this->reset(); |
| 38 | } |
| 39 | |
| 40 | void reset() { |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 41 | fReg = GMRegistry::Head(); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 42 | } |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 43 | |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 44 | GM* next() { |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 45 | if (fReg) { |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 46 | GMRegistry::Factory fact = fReg->factory(); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 47 | fReg = fReg->next(); |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 48 | return fact(0); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 49 | } |
| 50 | return NULL; |
| 51 | } |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 52 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 53 | static int Count() { |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 54 | const GMRegistry* reg = GMRegistry::Head(); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 55 | int count = 0; |
| 56 | while (reg) { |
| 57 | count += 1; |
| 58 | reg = reg->next(); |
| 59 | } |
| 60 | return count; |
| 61 | } |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 62 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 63 | private: |
| 64 | const GMRegistry* fReg; |
| 65 | }; |
| 66 | |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 67 | static SkString make_name(const char shortName[], const char configName[]) { |
| 68 | SkString name(shortName); |
| 69 | name.appendf("_%s", configName); |
| 70 | return name; |
| 71 | } |
| 72 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 73 | static SkString make_filename(const char path[], |
| 74 | const char pathSuffix[], |
| 75 | const SkString& name, |
| 76 | const char suffix[]) { |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 77 | SkString filename(path); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 78 | if (filename.endsWith("/")) { |
| 79 | filename.remove(filename.size() - 1, 1); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 80 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 81 | filename.append(pathSuffix); |
| 82 | filename.append("/"); |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 83 | filename.appendf("%s.%s", name.c_str(), suffix); |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 84 | return filename; |
| 85 | } |
| 86 | |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 87 | /* since PNG insists on unpremultiplying our alpha, we take no precision chances |
| 88 | and force all pixels to be 100% opaque, otherwise on compare we may not get |
| 89 | a perfect match. |
| 90 | */ |
| 91 | static void force_all_opaque(const SkBitmap& bitmap) { |
| 92 | SkAutoLockPixels lock(bitmap); |
| 93 | for (int y = 0; y < bitmap.height(); y++) { |
| 94 | for (int x = 0; x < bitmap.width(); x++) { |
| 95 | *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT); |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | static bool write_bitmap(const SkString& path, const SkBitmap& bitmap) { |
| 101 | SkBitmap copy; |
| 102 | bitmap.copyTo(©, SkBitmap::kARGB_8888_Config); |
| 103 | force_all_opaque(copy); |
| 104 | return SkImageEncoder::EncodeFile(path.c_str(), copy, |
| 105 | SkImageEncoder::kPNG_Type, 100); |
| 106 | } |
| 107 | |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 108 | static inline SkPMColor compute_diff_pmcolor(SkPMColor c0, SkPMColor c1) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 109 | int dr = SkGetPackedR32(c0) - SkGetPackedR32(c1); |
| 110 | int dg = SkGetPackedG32(c0) - SkGetPackedG32(c1); |
| 111 | int db = SkGetPackedB32(c0) - SkGetPackedB32(c1); |
| 112 | return SkPackARGB32(0xFF, SkAbs32(dr), SkAbs32(dg), SkAbs32(db)); |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | static void compute_diff(const SkBitmap& target, const SkBitmap& base, |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 116 | SkBitmap* diff) { |
| 117 | SkAutoLockPixels alp(*diff); |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 118 | |
| 119 | const int w = target.width(); |
| 120 | const int h = target.height(); |
| 121 | for (int y = 0; y < h; y++) { |
| 122 | for (int x = 0; x < w; x++) { |
| 123 | SkPMColor c0 = *base.getAddr32(x, y); |
| 124 | SkPMColor c1 = *target.getAddr32(x, y); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 125 | SkPMColor d = 0; |
| 126 | if (c0 != c1) { |
| 127 | d = compute_diff_pmcolor(c0, c1); |
| 128 | } |
| 129 | *diff->getAddr32(x, y) = d; |
| 130 | } |
| 131 | } |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | static bool compare(const SkBitmap& target, const SkBitmap& base, |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 135 | const SkString& name, const char* renderModeDescriptor, |
tomhudson@google.com | 6abfa49 | 2011-04-26 14:59:32 +0000 | [diff] [blame] | 136 | SkBitmap* diff) { |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 137 | SkBitmap copy; |
| 138 | const SkBitmap* bm = ⌖ |
| 139 | if (target.config() != SkBitmap::kARGB_8888_Config) { |
| 140 | target.copyTo(©, SkBitmap::kARGB_8888_Config); |
| 141 | bm = © |
| 142 | } |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 143 | SkBitmap baseCopy; |
| 144 | const SkBitmap* bp = &base; |
| 145 | if (base.config() != SkBitmap::kARGB_8888_Config) { |
| 146 | base.copyTo(&baseCopy, SkBitmap::kARGB_8888_Config); |
| 147 | bp = &baseCopy; |
| 148 | } |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 149 | |
| 150 | force_all_opaque(*bm); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 151 | force_all_opaque(*bp); |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 152 | |
| 153 | const int w = bm->width(); |
| 154 | const int h = bm->height(); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 155 | if (w != bp->width() || h != bp->height()) { |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 156 | SkDebugf( |
| 157 | "---- %s dimensions mismatch for %s base [%d %d] current [%d %d]\n", |
| 158 | renderModeDescriptor, name.c_str(), |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 159 | bp->width(), bp->height(), w, h); |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 160 | return false; |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | SkAutoLockPixels bmLock(*bm); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 164 | SkAutoLockPixels baseLock(*bp); |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 165 | |
| 166 | for (int y = 0; y < h; y++) { |
| 167 | for (int x = 0; x < w; x++) { |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 168 | SkPMColor c0 = *bp->getAddr32(x, y); |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 169 | SkPMColor c1 = *bm->getAddr32(x, y); |
| 170 | if (c0 != c1) { |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 171 | SkDebugf( |
| 172 | "----- %s pixel mismatch for %s at [%d %d] base 0x%08X current 0x%08X\n", |
| 173 | renderModeDescriptor, name.c_str(), x, y, c0, c1); |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 174 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 175 | if (diff) { |
| 176 | diff->setConfig(SkBitmap::kARGB_8888_Config, w, h); |
| 177 | diff->allocPixels(); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 178 | compute_diff(*bm, *bp, diff); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 179 | } |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 180 | return false; |
reed@android.com | b9b9a18 | 2009-07-08 02:54:47 +0000 | [diff] [blame] | 181 | } |
| 182 | } |
| 183 | } |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 184 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 185 | // they're equal |
| 186 | return true; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 187 | } |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 188 | |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 189 | static bool write_pdf(const SkString& path, const SkDynamicMemoryWStream& pdf) { |
| 190 | SkFILEWStream stream(path.c_str()); |
reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 191 | SkAutoDataUnref data(pdf.copyToData()); |
| 192 | return stream.writeData(data.get()); |
reed@google.com | 0770044 | 2010-12-20 19:46:07 +0000 | [diff] [blame] | 193 | } |
| 194 | |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 195 | enum Backend { |
| 196 | kRaster_Backend, |
| 197 | kGPU_Backend, |
| 198 | kPDF_Backend, |
| 199 | }; |
| 200 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 201 | struct ConfigData { |
| 202 | SkBitmap::Config fConfig; |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 203 | Backend fBackend; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 204 | const char* fName; |
| 205 | }; |
| 206 | |
| 207 | /// Returns true if processing should continue, false to skip the |
| 208 | /// remainder of this config for this GM. |
| 209 | //@todo thudson 22 April 2011 - could refactor this to take in |
| 210 | // a factory to generate the context, always call readPixels() |
| 211 | // (logically a noop for rasters, if wasted time), and thus collapse the |
| 212 | // GPU special case and also let this be used for SkPicture testing. |
| 213 | static void setup_bitmap(const ConfigData& gRec, SkISize& size, |
| 214 | SkBitmap* bitmap) { |
| 215 | bitmap->setConfig(gRec.fConfig, size.width(), size.height()); |
| 216 | bitmap->allocPixels(); |
| 217 | bitmap->eraseColor(0); |
| 218 | } |
| 219 | |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 220 | // Returns true if the test should continue, false if the test should |
| 221 | // halt. |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 222 | static bool generate_image(GM* gm, const ConfigData& gRec, |
| 223 | GrContext* context, |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 224 | SkBitmap* bitmap) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 225 | SkISize size (gm->getISize()); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 226 | setup_bitmap(gRec, size, bitmap); |
| 227 | SkCanvas canvas(*bitmap); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 228 | |
| 229 | if (gRec.fBackend == kRaster_Backend) { |
| 230 | gm->draw(&canvas); |
| 231 | } else { // GPU |
| 232 | if (NULL == context) { |
| 233 | return false; |
| 234 | } |
reed@google.com | af951c9 | 2011-06-16 19:10:39 +0000 | [diff] [blame] | 235 | // not a real object, so don't unref it |
| 236 | GrRenderTarget* rt = SkGpuDevice::Current3DApiRenderTarget(); |
| 237 | SkGpuCanvas gc(context, rt); |
| 238 | gc.setDevice(new SkGpuDevice(context, rt))->unref(); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 239 | gm->draw(&gc); |
reed@google.com | af951c9 | 2011-06-16 19:10:39 +0000 | [diff] [blame] | 240 | // the device is as large as the current rendertarget, so we explicitly |
| 241 | // only readback the amount we expect (in size) |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 242 | // overwrite our previous allocation |
| 243 | gc.readPixels(SkIRect::MakeSize(size), bitmap); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 244 | } |
| 245 | return true; |
| 246 | } |
| 247 | |
| 248 | static void generate_image_from_picture(GM* gm, const ConfigData& gRec, |
| 249 | SkPicture* pict, SkBitmap* bitmap) { |
| 250 | SkISize size = gm->getISize(); |
| 251 | setup_bitmap(gRec, size, bitmap); |
| 252 | SkCanvas canvas(*bitmap); |
| 253 | canvas.drawPicture(*pict); |
| 254 | } |
| 255 | |
| 256 | static void generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) { |
| 257 | #ifdef SK_SUPPORT_PDF |
| 258 | SkISize size = gm->getISize(); |
| 259 | SkMatrix identity; |
| 260 | identity.reset(); |
ctguil@chromium.org | 1526129 | 2011-04-29 17:54:16 +0000 | [diff] [blame] | 261 | SkPDFDevice* dev = new SkPDFDevice(size, size, identity); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 262 | SkAutoUnref aur(dev); |
| 263 | |
| 264 | SkCanvas c(dev); |
| 265 | gm->draw(&c); |
| 266 | |
| 267 | SkPDFDocument doc; |
| 268 | doc.appendPage(dev); |
| 269 | doc.emitPDF(&pdf); |
| 270 | #endif |
| 271 | } |
| 272 | |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 273 | static bool write_reference_image(const ConfigData& gRec, |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 274 | const char writePath [], |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 275 | const char renderModeDescriptor [], |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 276 | const SkString& name, |
| 277 | SkBitmap& bitmap, |
| 278 | SkDynamicMemoryWStream* pdf) { |
| 279 | SkString path; |
| 280 | bool success = false; |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 281 | if (gRec.fBackend != kPDF_Backend || CAN_IMAGE_PDF) { |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 282 | path = make_filename(writePath, renderModeDescriptor, name, "png"); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 283 | success = write_bitmap(path, bitmap); |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 284 | } |
| 285 | if (kPDF_Backend == gRec.fBackend) { |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 286 | path = make_filename(writePath, renderModeDescriptor, name, "pdf"); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 287 | success = write_pdf(path, *pdf); |
| 288 | } |
| 289 | if (!success) { |
| 290 | fprintf(stderr, "FAILED to write %s\n", path.c_str()); |
| 291 | } |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 292 | return success; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 293 | } |
| 294 | |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 295 | static bool compare_to_reference_image(const SkString& name, |
| 296 | SkBitmap &bitmap, |
| 297 | const SkBitmap& comparisonBitmap, |
| 298 | const char diffPath [], |
| 299 | const char renderModeDescriptor []) { |
| 300 | bool success; |
| 301 | SkBitmap diffBitmap; |
| 302 | success = compare(bitmap, comparisonBitmap, name, renderModeDescriptor, |
| 303 | diffPath ? &diffBitmap : NULL); |
| 304 | if (!success && diffPath) { |
| 305 | SkString diffName = make_filename(diffPath, "", name, ".diff.png"); |
| 306 | write_bitmap(diffName, diffBitmap); |
| 307 | } |
| 308 | return success; |
| 309 | } |
| 310 | |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 311 | static bool compare_to_reference_image(const char readPath [], |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 312 | const SkString& name, |
| 313 | SkBitmap &bitmap, |
tomhudson@google.com | 6abfa49 | 2011-04-26 14:59:32 +0000 | [diff] [blame] | 314 | const char diffPath [], |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 315 | const char renderModeDescriptor []) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 316 | SkString path = make_filename(readPath, "", name, "png"); |
| 317 | SkBitmap orig; |
| 318 | bool success = SkImageDecoder::DecodeFile(path.c_str(), &orig, |
| 319 | SkBitmap::kARGB_8888_Config, |
| 320 | SkImageDecoder::kDecodePixels_Mode, NULL); |
| 321 | if (success) { |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 322 | success = compare_to_reference_image(name, bitmap, |
| 323 | orig, diffPath, |
| 324 | renderModeDescriptor); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 325 | } else { |
| 326 | fprintf(stderr, "FAILED to read %s\n", path.c_str()); |
reed@google.com | ac864a9 | 2011-06-27 18:11:17 +0000 | [diff] [blame] | 327 | // we lie here, and report succes, since we're just missing a master |
| 328 | // image. This way we can check in new tests, and not report failure. |
| 329 | // A real failure is to draw *differently* from the master image, but |
| 330 | // that's not the case here. |
| 331 | success = true; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 332 | } |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 333 | return success; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 334 | } |
| 335 | |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 336 | static bool handle_test_results(GM* gm, |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 337 | const ConfigData& gRec, |
| 338 | const char writePath [], |
| 339 | const char readPath [], |
| 340 | const char diffPath [], |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 341 | const char renderModeDescriptor [], |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 342 | SkBitmap& bitmap, |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 343 | SkDynamicMemoryWStream* pdf, |
| 344 | const SkBitmap* comparisonBitmap) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 345 | SkString name = make_name(gm->shortName(), gRec.fName); |
| 346 | |
| 347 | if (writePath) { |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 348 | write_reference_image(gRec, writePath, renderModeDescriptor, |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 349 | name, bitmap, pdf); |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 350 | } else if (readPath && (gRec.fBackend != kPDF_Backend || CAN_IMAGE_PDF)) { |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 351 | return compare_to_reference_image(readPath, name, bitmap, |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 352 | diffPath, renderModeDescriptor); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 353 | } else if (comparisonBitmap) { |
| 354 | return compare_to_reference_image(name, bitmap, |
| 355 | *comparisonBitmap, diffPath, |
| 356 | renderModeDescriptor); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 357 | } |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 358 | return true; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | static SkPicture* generate_new_picture(GM* gm) { |
| 362 | // Pictures are refcounted so must be on heap |
| 363 | SkPicture* pict = new SkPicture; |
| 364 | SkCanvas* cv = pict->beginRecording(1000, 1000); |
| 365 | gm->draw(cv); |
| 366 | pict->endRecording(); |
| 367 | |
| 368 | return pict; |
| 369 | } |
| 370 | |
| 371 | static SkPicture* stream_to_new_picture(const SkPicture& src) { |
| 372 | |
| 373 | // To do in-memory commiunications with a stream, we need to: |
| 374 | // * create a dynamic memory stream |
| 375 | // * copy it into a buffer |
| 376 | // * create a read stream from it |
| 377 | // ?!?! |
| 378 | |
| 379 | SkDynamicMemoryWStream storage; |
| 380 | src.serialize(&storage); |
| 381 | |
| 382 | int streamSize = storage.getOffset(); |
| 383 | SkAutoMalloc dstStorage(streamSize); |
| 384 | void* dst = dstStorage.get(); |
| 385 | //char* dst = new char [streamSize]; |
| 386 | //@todo thudson 22 April 2011 when can we safely delete [] dst? |
| 387 | storage.copyTo(dst); |
| 388 | SkMemoryStream pictReadback(dst, streamSize); |
| 389 | SkPicture* retval = new SkPicture (&pictReadback); |
| 390 | return retval; |
| 391 | } |
| 392 | |
| 393 | // Test: draw into a bitmap or pdf. |
| 394 | // Depending on flags, possibly compare to an expected image |
| 395 | // and possibly output a diff image if it fails to match. |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 396 | static bool test_drawing(GM* gm, |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 397 | const ConfigData& gRec, |
| 398 | const char writePath [], |
| 399 | const char readPath [], |
| 400 | const char diffPath [], |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 401 | GrContext* context, |
| 402 | SkBitmap* bitmap) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 403 | SkDynamicMemoryWStream pdf; |
| 404 | |
| 405 | if (gRec.fBackend == kRaster_Backend || |
| 406 | gRec.fBackend == kGPU_Backend) { |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 407 | // Early exit if we can't generate the image, but this is |
| 408 | // expected in some cases, so don't report a test failure. |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 409 | if (!generate_image(gm, gRec, context, bitmap)) { |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 410 | return true; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 411 | } |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 412 | } else if (gRec.fBackend == kPDF_Backend) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 413 | generate_pdf(gm, pdf); |
reed@google.com | 46cce91 | 2011-06-29 12:54:46 +0000 | [diff] [blame] | 414 | #if CAN_IMAGE_PDF |
| 415 | SkAutoDataUnref data(pdf.copyToData()); |
| 416 | SkMemoryStream stream(data.data(), data.size()); |
| 417 | SkPDFDocumentToBitmap(&stream, bitmap); |
| 418 | #endif |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 419 | } |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 420 | return handle_test_results(gm, gRec, writePath, readPath, diffPath, |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 421 | "", *bitmap, &pdf, NULL); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 422 | } |
| 423 | |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 424 | static bool test_picture_playback(GM* gm, |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 425 | const ConfigData& gRec, |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 426 | const SkBitmap& comparisonBitmap, |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 427 | const char readPath [], |
| 428 | const char diffPath []) { |
| 429 | SkPicture* pict = generate_new_picture(gm); |
| 430 | SkAutoUnref aur(pict); |
| 431 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 432 | if (kRaster_Backend == gRec.fBackend) { |
| 433 | SkBitmap bitmap; |
| 434 | generate_image_from_picture(gm, gRec, pict, &bitmap); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 435 | return handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 436 | "-replay", bitmap, NULL, &comparisonBitmap); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 437 | } |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 438 | return true; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 439 | } |
| 440 | |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 441 | static bool test_picture_serialization(GM* gm, |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 442 | const ConfigData& gRec, |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 443 | const SkBitmap& comparisonBitmap, |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 444 | const char readPath [], |
| 445 | const char diffPath []) { |
| 446 | SkPicture* pict = generate_new_picture(gm); |
| 447 | SkAutoUnref aurp(pict); |
| 448 | SkPicture* repict = stream_to_new_picture(*pict); |
| 449 | SkAutoUnref aurr(repict); |
| 450 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 451 | if (kRaster_Backend == gRec.fBackend) { |
| 452 | SkBitmap bitmap; |
| 453 | generate_image_from_picture(gm, gRec, repict, &bitmap); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 454 | return handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 455 | "-serialize", bitmap, NULL, &comparisonBitmap); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 456 | } |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 457 | return true; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | static void usage(const char * argv0) { |
| 461 | SkDebugf("%s [-w writePath] [-r readPath] [-d diffPath]\n", argv0); |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 462 | SkDebugf(" [--replay] [--serialize]\n"); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 463 | SkDebugf(" writePath: directory to write rendered images in.\n"); |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 464 | SkDebugf( |
| 465 | " readPath: directory to read reference images from;\n" |
| 466 | " reports if any pixels mismatch between reference and new images\n"); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 467 | SkDebugf(" diffPath: directory to write difference images in.\n"); |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 468 | SkDebugf(" --replay: exercise SkPicture replay.\n"); |
| 469 | SkDebugf( |
| 470 | " --serialize: exercise SkPicture serialization & deserialization.\n"); |
reed@google.com | e6a5c4d | 2011-07-25 14:30:54 +0000 | [diff] [blame^] | 471 | SkDebugf(" --match foo will only run tests that substring match foo.\n"); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | static const ConfigData gRec[] = { |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 475 | { SkBitmap::kARGB_8888_Config, kRaster_Backend, "8888" }, |
| 476 | { SkBitmap::kARGB_4444_Config, kRaster_Backend, "4444" }, |
| 477 | { SkBitmap::kRGB_565_Config, kRaster_Backend, "565" }, |
reed@google.com | 1a7e946 | 2011-06-20 13:21:24 +0000 | [diff] [blame] | 478 | #ifdef SK_SCALAR_IS_FLOAT |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 479 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, "gpu" }, |
reed@google.com | 1a7e946 | 2011-06-20 13:21:24 +0000 | [diff] [blame] | 480 | #endif |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 481 | #ifdef SK_SUPPORT_PDF |
| 482 | { SkBitmap::kARGB_8888_Config, kPDF_Backend, "pdf" }, |
| 483 | #endif |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 484 | }; |
| 485 | |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 486 | namespace skiagm { |
| 487 | static GrContext* gGrContext; |
| 488 | GrContext* GetGr() { |
| 489 | return gGrContext; |
| 490 | } |
| 491 | } |
| 492 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 493 | int main(int argc, char * const argv[]) { |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 494 | SkAutoGraphics ag; |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 495 | |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 496 | const char* writePath = NULL; // if non-null, where we write the originals |
| 497 | 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] | 498 | const char* diffPath = NULL; // if non-null, where we write our diffs (from compare) |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 499 | const char* matchStr = NULL; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 500 | |
reed@google.com | b8b0983 | 2011-05-26 15:57:56 +0000 | [diff] [blame] | 501 | bool doReplay = true; |
tomhudson@google.com | 6abfa49 | 2011-04-26 14:59:32 +0000 | [diff] [blame] | 502 | bool doSerialize = false; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 503 | const char* const commandName = argv[0]; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 504 | char* const* stop = argv + argc; |
| 505 | for (++argv; argv < stop; ++argv) { |
| 506 | if (strcmp(*argv, "-w") == 0) { |
| 507 | argv++; |
| 508 | if (argv < stop && **argv) { |
| 509 | writePath = *argv; |
| 510 | } |
| 511 | } else if (strcmp(*argv, "-r") == 0) { |
| 512 | argv++; |
| 513 | if (argv < stop && **argv) { |
| 514 | readPath = *argv; |
| 515 | } |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 516 | } else if (strcmp(*argv, "-d") == 0) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 517 | argv++; |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 518 | if (argv < stop && **argv) { |
| 519 | diffPath = *argv; |
| 520 | } |
reed@google.com | b8b0983 | 2011-05-26 15:57:56 +0000 | [diff] [blame] | 521 | } else if (strcmp(*argv, "--noreplay") == 0) { |
| 522 | doReplay = false; |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 523 | } else if (strcmp(*argv, "--serialize") == 0) { |
| 524 | doSerialize = true; |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 525 | } else if (strcmp(*argv, "--match") == 0) { |
| 526 | ++argv; |
| 527 | if (argv < stop && **argv) { |
| 528 | matchStr = *argv; |
| 529 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 530 | } else { |
| 531 | usage(commandName); |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 532 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | if (argv != stop) { |
| 536 | usage(commandName); |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 537 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 538 | } |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 539 | |
bsalomon@google.com | 3914958 | 2011-06-13 21:55:32 +0000 | [diff] [blame] | 540 | int maxW = -1; |
| 541 | int maxH = -1; |
| 542 | Iter iter; |
| 543 | GM* gm; |
| 544 | while ((gm = iter.next()) != NULL) { |
| 545 | SkISize size = gm->getISize(); |
| 546 | maxW = SkMax32(size.width(), maxW); |
| 547 | maxH = SkMax32(size.height(), maxH); |
| 548 | } |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 549 | // setup a GL context for drawing offscreen |
| 550 | SkEGLContext eglContext; |
bsalomon@google.com | 3914958 | 2011-06-13 21:55:32 +0000 | [diff] [blame] | 551 | if (eglContext.init(maxW, maxH)) { |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 552 | gGrContext = GrContext::CreateGLShaderContext(); |
reed@google.com | 37df17d | 2010-12-23 20:20:51 +0000 | [diff] [blame] | 553 | } |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 554 | |
reed@android.com | 00f883e | 2010-12-14 17:46:14 +0000 | [diff] [blame] | 555 | |
| 556 | if (readPath) { |
| 557 | fprintf(stderr, "reading from %s\n", readPath); |
| 558 | } else if (writePath) { |
| 559 | fprintf(stderr, "writing to %s\n", writePath); |
| 560 | } |
| 561 | |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 562 | // Accumulate success of all tests so we can flag error in any |
| 563 | // one with the return value. |
bsalomon@google.com | 3914958 | 2011-06-13 21:55:32 +0000 | [diff] [blame] | 564 | iter.reset(); |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 565 | bool overallSuccess = true; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 566 | while ((gm = iter.next()) != NULL) { |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 567 | const char* shortName = gm->shortName(); |
| 568 | if (matchStr && !strstr(shortName, matchStr)) { |
| 569 | SkDELETE(gm); |
| 570 | continue; |
| 571 | } |
| 572 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 573 | SkISize size = gm->getISize(); |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 574 | SkDebugf("drawing... %s [%d %d]\n", shortName, |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 575 | size.width(), size.height()); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 576 | SkBitmap forwardRenderedBitmap; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 577 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 578 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 579 | bool testSuccess = test_drawing(gm, gRec[i], |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 580 | writePath, readPath, diffPath, gGrContext, |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 581 | &forwardRenderedBitmap); |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 582 | overallSuccess &= testSuccess; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 583 | |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 584 | if (doReplay && testSuccess) { |
| 585 | testSuccess = test_picture_playback(gm, gRec[i], |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 586 | forwardRenderedBitmap, |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 587 | readPath, diffPath); |
| 588 | overallSuccess &= testSuccess; |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 589 | } |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 590 | |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 591 | if (doSerialize && testSuccess) { |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 592 | testSuccess &= test_picture_serialization(gm, gRec[i], |
| 593 | forwardRenderedBitmap, |
| 594 | readPath, diffPath); |
| 595 | overallSuccess &= testSuccess; |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 596 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 597 | } |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 598 | SkDELETE(gm); |
| 599 | } |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 600 | if (false == overallSuccess) { |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 601 | return -1; |
| 602 | } |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 603 | return 0; |
| 604 | } |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 605 | |
| 606 | /////////////////////////////////////////////////////////////////////////////// |
| 607 | |
| 608 | using namespace skiagm; |
| 609 | |
| 610 | GM::GM() {} |
| 611 | GM::~GM() {} |
| 612 | |
| 613 | void GM::draw(SkCanvas* canvas) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 614 | this->onDraw(canvas); |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 615 | } |