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