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