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 []) { |
reed@google.com | 30db599 | 2011-08-29 17:41:02 +0000 | [diff] [blame] | 438 | if (!gm->validForPicture()) { |
| 439 | return true; |
| 440 | } |
| 441 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 442 | SkPicture* pict = generate_new_picture(gm); |
| 443 | SkAutoUnref aur(pict); |
| 444 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 445 | if (kRaster_Backend == gRec.fBackend) { |
| 446 | SkBitmap bitmap; |
| 447 | generate_image_from_picture(gm, gRec, pict, &bitmap); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 448 | return handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 449 | "-replay", bitmap, NULL, &comparisonBitmap); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 450 | } |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 451 | return true; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 452 | } |
| 453 | |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 454 | static bool test_picture_serialization(GM* gm, |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 455 | const ConfigData& gRec, |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 456 | const SkBitmap& comparisonBitmap, |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 457 | const char readPath [], |
| 458 | const char diffPath []) { |
| 459 | SkPicture* pict = generate_new_picture(gm); |
| 460 | SkAutoUnref aurp(pict); |
| 461 | SkPicture* repict = stream_to_new_picture(*pict); |
| 462 | SkAutoUnref aurr(repict); |
| 463 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 464 | if (kRaster_Backend == gRec.fBackend) { |
| 465 | SkBitmap bitmap; |
| 466 | generate_image_from_picture(gm, gRec, repict, &bitmap); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 467 | return handle_test_results(gm, gRec, NULL, NULL, diffPath, |
| 468 | "-serialize", bitmap, NULL, &comparisonBitmap); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 469 | } |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 470 | return true; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | static void usage(const char * argv0) { |
| 474 | SkDebugf("%s [-w writePath] [-r readPath] [-d diffPath]\n", argv0); |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 475 | SkDebugf(" [--replay] [--serialize]\n"); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 476 | SkDebugf(" writePath: directory to write rendered images in.\n"); |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 477 | SkDebugf( |
| 478 | " readPath: directory to read reference images from;\n" |
| 479 | " reports if any pixels mismatch between reference and new images\n"); |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 480 | SkDebugf(" diffPath: directory to write difference images in.\n"); |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 481 | SkDebugf(" --replay: exercise SkPicture replay.\n"); |
| 482 | SkDebugf( |
| 483 | " --serialize: exercise SkPicture serialization & deserialization.\n"); |
reed@google.com | e6a5c4d | 2011-07-25 14:30:54 +0000 | [diff] [blame] | 484 | 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] | 485 | } |
| 486 | |
| 487 | static const ConfigData gRec[] = { |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 488 | { SkBitmap::kARGB_8888_Config, kRaster_Backend, "8888" }, |
| 489 | { SkBitmap::kARGB_4444_Config, kRaster_Backend, "4444" }, |
| 490 | { SkBitmap::kRGB_565_Config, kRaster_Backend, "565" }, |
reed@google.com | 1a7e946 | 2011-06-20 13:21:24 +0000 | [diff] [blame] | 491 | #ifdef SK_SCALAR_IS_FLOAT |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 492 | { SkBitmap::kARGB_8888_Config, kGPU_Backend, "gpu" }, |
reed@google.com | 1a7e946 | 2011-06-20 13:21:24 +0000 | [diff] [blame] | 493 | #endif |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 494 | #ifdef SK_SUPPORT_PDF |
| 495 | { SkBitmap::kARGB_8888_Config, kPDF_Backend, "pdf" }, |
| 496 | #endif |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 497 | }; |
| 498 | |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 499 | namespace skiagm { |
| 500 | static GrContext* gGrContext; |
| 501 | GrContext* GetGr() { |
| 502 | return gGrContext; |
| 503 | } |
| 504 | } |
| 505 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 506 | int main(int argc, char * const argv[]) { |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 507 | SkAutoGraphics ag; |
reed@google.com | d4dfd10 | 2011-01-18 21:05:42 +0000 | [diff] [blame] | 508 | |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 509 | const char* writePath = NULL; // if non-null, where we write the originals |
| 510 | 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] | 511 | 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] | 512 | const char* matchStr = NULL; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 513 | |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame^] | 514 | bool doPDF = true; |
reed@google.com | b8b0983 | 2011-05-26 15:57:56 +0000 | [diff] [blame] | 515 | bool doReplay = true; |
tomhudson@google.com | 6abfa49 | 2011-04-26 14:59:32 +0000 | [diff] [blame] | 516 | bool doSerialize = false; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 517 | const char* const commandName = argv[0]; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 518 | char* const* stop = argv + argc; |
| 519 | for (++argv; argv < stop; ++argv) { |
| 520 | if (strcmp(*argv, "-w") == 0) { |
| 521 | argv++; |
| 522 | if (argv < stop && **argv) { |
| 523 | writePath = *argv; |
| 524 | } |
| 525 | } else if (strcmp(*argv, "-r") == 0) { |
| 526 | argv++; |
| 527 | if (argv < stop && **argv) { |
| 528 | readPath = *argv; |
| 529 | } |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 530 | } else if (strcmp(*argv, "-d") == 0) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 531 | argv++; |
reed@google.com | 3d3f092 | 2010-12-20 21:10:29 +0000 | [diff] [blame] | 532 | if (argv < stop && **argv) { |
| 533 | diffPath = *argv; |
| 534 | } |
reed@google.com | b8b0983 | 2011-05-26 15:57:56 +0000 | [diff] [blame] | 535 | } else if (strcmp(*argv, "--noreplay") == 0) { |
| 536 | doReplay = false; |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame^] | 537 | } else if (strcmp(*argv, "--nopdf") == 0) { |
| 538 | doPDF = false; |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 539 | } else if (strcmp(*argv, "--serialize") == 0) { |
| 540 | doSerialize = true; |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 541 | } else if (strcmp(*argv, "--match") == 0) { |
| 542 | ++argv; |
| 543 | if (argv < stop && **argv) { |
| 544 | matchStr = *argv; |
| 545 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 546 | } else { |
| 547 | usage(commandName); |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 548 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 549 | } |
| 550 | } |
| 551 | if (argv != stop) { |
| 552 | usage(commandName); |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 553 | return -1; |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 554 | } |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 555 | |
bsalomon@google.com | 3914958 | 2011-06-13 21:55:32 +0000 | [diff] [blame] | 556 | int maxW = -1; |
| 557 | int maxH = -1; |
| 558 | Iter iter; |
| 559 | GM* gm; |
| 560 | while ((gm = iter.next()) != NULL) { |
| 561 | SkISize size = gm->getISize(); |
| 562 | maxW = SkMax32(size.width(), maxW); |
| 563 | maxH = SkMax32(size.height(), maxH); |
| 564 | } |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 565 | // setup a GL context for drawing offscreen |
| 566 | SkEGLContext eglContext; |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 567 | GrRenderTarget* rt = NULL; |
bsalomon@google.com | 3914958 | 2011-06-13 21:55:32 +0000 | [diff] [blame] | 568 | if (eglContext.init(maxW, maxH)) { |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 569 | gGrContext = GrContext::CreateGLShaderContext(); |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 570 | if (NULL != gGrContext) { |
| 571 | GrPlatformSurfaceDesc desc; |
| 572 | desc.reset(); |
| 573 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 574 | desc.fWidth = maxW; |
| 575 | desc.fHeight = maxH; |
| 576 | desc.fStencilBits = 8; |
| 577 | desc.fPlatformRenderTarget = eglContext.getFBOID(); |
| 578 | desc.fSurfaceType = kRenderTarget_GrPlatformSurfaceType; |
| 579 | rt = static_cast<GrRenderTarget*>(gGrContext->createPlatformSurface(desc)); |
| 580 | if (NULL == rt) { |
| 581 | gGrContext->unref(); |
| 582 | gGrContext = NULL; |
| 583 | } |
| 584 | } |
reed@google.com | 37df17d | 2010-12-23 20:20:51 +0000 | [diff] [blame] | 585 | } |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 586 | |
reed@android.com | 00f883e | 2010-12-14 17:46:14 +0000 | [diff] [blame] | 587 | if (readPath) { |
| 588 | fprintf(stderr, "reading from %s\n", readPath); |
| 589 | } else if (writePath) { |
| 590 | fprintf(stderr, "writing to %s\n", writePath); |
| 591 | } |
| 592 | |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 593 | // Accumulate success of all tests so we can flag error in any |
| 594 | // one with the return value. |
bsalomon@google.com | 3914958 | 2011-06-13 21:55:32 +0000 | [diff] [blame] | 595 | iter.reset(); |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 596 | bool overallSuccess = true; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 597 | while ((gm = iter.next()) != NULL) { |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 598 | const char* shortName = gm->shortName(); |
| 599 | if (matchStr && !strstr(shortName, matchStr)) { |
| 600 | SkDELETE(gm); |
| 601 | continue; |
| 602 | } |
| 603 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 604 | SkISize size = gm->getISize(); |
reed@google.com | ece2b02 | 2011-07-25 14:28:57 +0000 | [diff] [blame] | 605 | SkDebugf("drawing... %s [%d %d]\n", shortName, |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 606 | size.width(), size.height()); |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 607 | SkBitmap forwardRenderedBitmap; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 608 | |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 609 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { |
reed@google.com | ab97397 | 2011-09-19 19:01:38 +0000 | [diff] [blame^] | 610 | if ((kPDF_Backend == gRec[i].fBackend) && !doPDF) { |
| 611 | continue; |
| 612 | } |
| 613 | |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 614 | bool testSuccess = test_drawing(gm, gRec[i], |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 615 | writePath, readPath, diffPath, gGrContext, |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 616 | rt, &forwardRenderedBitmap); |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 617 | overallSuccess &= testSuccess; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 618 | |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 619 | if (doReplay && testSuccess) { |
| 620 | testSuccess = test_picture_playback(gm, gRec[i], |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 621 | forwardRenderedBitmap, |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 622 | readPath, diffPath); |
| 623 | overallSuccess &= testSuccess; |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 624 | } |
vandebo@chromium.org | 686abdf | 2011-02-03 23:00:40 +0000 | [diff] [blame] | 625 | |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 626 | if (doSerialize && testSuccess) { |
tomhudson@google.com | cae6b3f | 2011-06-17 13:11:45 +0000 | [diff] [blame] | 627 | testSuccess &= test_picture_serialization(gm, gRec[i], |
| 628 | forwardRenderedBitmap, |
| 629 | readPath, diffPath); |
| 630 | overallSuccess &= testSuccess; |
tomhudson@google.com | 73fb042 | 2011-04-25 19:20:54 +0000 | [diff] [blame] | 631 | } |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 632 | } |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 633 | SkDELETE(gm); |
| 634 | } |
tomhudson@google.com | ea32543 | 2011-06-09 20:30:03 +0000 | [diff] [blame] | 635 | if (false == overallSuccess) { |
tomhudson@google.com | 8e728d7 | 2011-04-26 20:22:57 +0000 | [diff] [blame] | 636 | return -1; |
| 637 | } |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 638 | return 0; |
| 639 | } |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 640 | |
| 641 | /////////////////////////////////////////////////////////////////////////////// |
| 642 | |
| 643 | using namespace skiagm; |
| 644 | |
| 645 | GM::GM() {} |
| 646 | GM::~GM() {} |
| 647 | |
| 648 | void GM::draw(SkCanvas* canvas) { |
tomhudson@google.com | 9875dd1 | 2011-04-25 15:49:53 +0000 | [diff] [blame] | 649 | this->onDraw(canvas); |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 650 | } |