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 | */ |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 8 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | #include "SkDumpCanvas.h" |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 10 | |
| 11 | #ifdef SK_DEVELOPER |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 12 | #include "SkPicture.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 13 | #include "SkPixelRef.h" |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 14 | #include "SkRRect.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 15 | #include "SkString.h" |
| 16 | #include <stdarg.h> |
| 17 | |
| 18 | // needed just to know that these are all subclassed from SkFlattenable |
| 19 | #include "SkShader.h" |
| 20 | #include "SkPathEffect.h" |
| 21 | #include "SkXfermode.h" |
| 22 | #include "SkColorFilter.h" |
| 23 | #include "SkPathEffect.h" |
| 24 | #include "SkMaskFilter.h" |
| 25 | |
reed@google.com | 563a3b4 | 2012-06-26 19:24:50 +0000 | [diff] [blame] | 26 | SK_DEFINE_INST_COUNT(SkDumpCanvas::Dumper) |
| 27 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | static void toString(const SkRect& r, SkString* str) { |
reed@google.com | 4258c2c | 2012-08-31 15:41:10 +0000 | [diff] [blame] | 29 | str->appendf("[%g,%g %g:%g]", |
| 30 | SkScalarToFloat(r.fLeft), SkScalarToFloat(r.fTop), |
| 31 | SkScalarToFloat(r.width()), SkScalarToFloat(r.height())); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | static void toString(const SkIRect& r, SkString* str) { |
reed@google.com | 4258c2c | 2012-08-31 15:41:10 +0000 | [diff] [blame] | 35 | str->appendf("[%d,%d %d:%d]", r.fLeft, r.fTop, r.width(), r.height()); |
reed@android.com | 0becfc5b | 2009-01-13 13:26:44 +0000 | [diff] [blame] | 36 | } |
| 37 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 38 | static void toString(const SkRRect& rrect, SkString* str) { |
| 39 | SkRect r = rrect.getBounds(); |
| 40 | str->appendf("[%g,%g %g:%g]", |
| 41 | SkScalarToFloat(r.fLeft), SkScalarToFloat(r.fTop), |
| 42 | SkScalarToFloat(r.width()), SkScalarToFloat(r.height())); |
| 43 | if (rrect.isOval()) { |
| 44 | str->append("()"); |
| 45 | } else if (rrect.isSimple()) { |
| 46 | const SkVector& rad = rrect.getSimpleRadii(); |
| 47 | str->appendf("(%g,%g)", rad.x(), rad.y()); |
| 48 | } else if (rrect.isComplex()) { |
| 49 | SkVector radii[4] = { |
| 50 | rrect.radii(SkRRect::kUpperLeft_Corner), |
| 51 | rrect.radii(SkRRect::kUpperRight_Corner), |
| 52 | rrect.radii(SkRRect::kLowerRight_Corner), |
| 53 | rrect.radii(SkRRect::kLowerLeft_Corner), |
| 54 | }; |
| 55 | str->appendf("(%g,%g %g,%g %g,%g %g,%g)", |
| 56 | radii[0].x(), radii[0].y(), |
| 57 | radii[1].x(), radii[1].y(), |
| 58 | radii[2].x(), radii[2].y(), |
| 59 | radii[3].x(), radii[3].y()); |
| 60 | } |
| 61 | } |
| 62 | |
reed@android.com | 0becfc5b | 2009-01-13 13:26:44 +0000 | [diff] [blame] | 63 | static void dumpVerbs(const SkPath& path, SkString* str) { |
| 64 | SkPath::Iter iter(path, false); |
| 65 | SkPoint pts[4]; |
| 66 | for (;;) { |
reed@google.com | 4a3b714 | 2012-05-16 17:16:46 +0000 | [diff] [blame] | 67 | switch (iter.next(pts, false)) { |
reed@android.com | 0becfc5b | 2009-01-13 13:26:44 +0000 | [diff] [blame] | 68 | case SkPath::kMove_Verb: |
| 69 | str->appendf(" M%g,%g", pts[0].fX, pts[0].fY); |
| 70 | break; |
| 71 | case SkPath::kLine_Verb: |
| 72 | str->appendf(" L%g,%g", pts[0].fX, pts[0].fY); |
| 73 | break; |
| 74 | case SkPath::kQuad_Verb: |
| 75 | str->appendf(" Q%g,%g,%g,%g", pts[1].fX, pts[1].fY, |
| 76 | pts[2].fX, pts[2].fY); |
| 77 | break; |
| 78 | case SkPath::kCubic_Verb: |
| 79 | str->appendf(" C%g,%g,%g,%g,%g,%g", pts[1].fX, pts[1].fY, |
| 80 | pts[2].fX, pts[2].fY, pts[3].fX, pts[3].fY); |
| 81 | break; |
| 82 | case SkPath::kClose_Verb: |
vandebo@chromium.org | b9682d3 | 2012-02-21 18:53:39 +0000 | [diff] [blame] | 83 | str->append("X"); |
reed@android.com | 0becfc5b | 2009-01-13 13:26:44 +0000 | [diff] [blame] | 84 | break; |
| 85 | case SkPath::kDone_Verb: |
| 86 | return; |
| 87 | } |
| 88 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | static void toString(const SkPath& path, SkString* str) { |
| 92 | if (path.isEmpty()) { |
reed@google.com | 4258c2c | 2012-08-31 15:41:10 +0000 | [diff] [blame] | 93 | str->append("path:empty"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 94 | } else { |
reed@android.com | d252db0 | 2009-04-01 18:31:44 +0000 | [diff] [blame] | 95 | toString(path.getBounds(), str); |
reed@android.com | 0becfc5b | 2009-01-13 13:26:44 +0000 | [diff] [blame] | 96 | #if 1 |
| 97 | SkString s; |
| 98 | dumpVerbs(path, &s); |
| 99 | str->append(s.c_str()); |
| 100 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 101 | str->append("]"); |
| 102 | str->prepend("path:["); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | static const char* toString(SkRegion::Op op) { |
| 107 | static const char* gOpNames[] = { |
| 108 | "DIFF", "SECT", "UNION", "XOR", "RDIFF", "REPLACE" |
| 109 | }; |
| 110 | return gOpNames[op]; |
| 111 | } |
| 112 | |
| 113 | static void toString(const SkRegion& rgn, SkString* str) { |
reed@google.com | 4258c2c | 2012-08-31 15:41:10 +0000 | [diff] [blame] | 114 | str->append("Region:["); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 115 | toString(rgn.getBounds(), str); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 116 | str->append("]"); |
| 117 | if (rgn.isComplex()) { |
| 118 | str->append(".complex"); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | static const char* toString(SkCanvas::VertexMode vm) { |
| 123 | static const char* gVMNames[] = { |
| 124 | "TRIANGLES", "STRIP", "FAN" |
| 125 | }; |
| 126 | return gVMNames[vm]; |
| 127 | } |
| 128 | |
| 129 | static const char* toString(SkCanvas::PointMode pm) { |
| 130 | static const char* gPMNames[] = { |
| 131 | "POINTS", "LINES", "POLYGON" |
| 132 | }; |
| 133 | return gPMNames[pm]; |
| 134 | } |
| 135 | |
tomhudson@google.com | 8afae61 | 2012-08-14 15:03:35 +0000 | [diff] [blame] | 136 | static void toString(const void* text, size_t byteLen, SkPaint::TextEncoding enc, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 137 | SkString* str) { |
tomhudson@google.com | 8afae61 | 2012-08-14 15:03:35 +0000 | [diff] [blame] | 138 | // FIXME: this code appears to be untested - and probably unused - and probably wrong |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 139 | switch (enc) { |
| 140 | case SkPaint::kUTF8_TextEncoding: |
reed@google.com | 4258c2c | 2012-08-31 15:41:10 +0000 | [diff] [blame] | 141 | str->appendf("\"%.*s\"%s", SkMax32(byteLen, 32), (const char*) text, |
tomhudson@google.com | 8afae61 | 2012-08-14 15:03:35 +0000 | [diff] [blame] | 142 | byteLen > 32 ? "..." : ""); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 143 | break; |
| 144 | case SkPaint::kUTF16_TextEncoding: |
caryclark@google.com | 867cbd8 | 2012-09-20 15:45:41 +0000 | [diff] [blame] | 145 | str->appendf("\"%.*ls\"%s", SkMax32(byteLen, 32), (const wchar_t*) text, |
tomhudson@google.com | 8afae61 | 2012-08-14 15:03:35 +0000 | [diff] [blame] | 146 | byteLen > 64 ? "..." : ""); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 147 | break; |
robertphillips@google.com | 6970557 | 2012-03-21 19:46:50 +0000 | [diff] [blame] | 148 | case SkPaint::kUTF32_TextEncoding: |
caryclark@google.com | 867cbd8 | 2012-09-20 15:45:41 +0000 | [diff] [blame] | 149 | str->appendf("\"%.*ls\"%s", SkMax32(byteLen, 32), (const wchar_t*) text, |
tomhudson@google.com | 8afae61 | 2012-08-14 15:03:35 +0000 | [diff] [blame] | 150 | byteLen > 128 ? "..." : ""); |
robertphillips@google.com | 6970557 | 2012-03-21 19:46:50 +0000 | [diff] [blame] | 151 | break; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 152 | case SkPaint::kGlyphID_TextEncoding: |
reed@google.com | 4258c2c | 2012-08-31 15:41:10 +0000 | [diff] [blame] | 153 | str->append("<glyphs>"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 154 | break; |
robertphillips@google.com | 6970557 | 2012-03-21 19:46:50 +0000 | [diff] [blame] | 155 | |
| 156 | default: |
| 157 | SkASSERT(false); |
| 158 | break; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | |
| 162 | /////////////////////////////////////////////////////////////////////////////// |
| 163 | |
reed@google.com | 6ae24e0 | 2012-09-26 13:44:13 +0000 | [diff] [blame] | 164 | static SkBitmap make_wideopen_bm() { |
| 165 | static const int WIDE_OPEN = 16384; |
skia.committer@gmail.com | 44d4988 | 2012-09-27 02:01:04 +0000 | [diff] [blame] | 166 | |
reed@google.com | 6ae24e0 | 2012-09-26 13:44:13 +0000 | [diff] [blame] | 167 | SkBitmap bm; |
| 168 | bm.setConfig(SkBitmap::kNo_Config, WIDE_OPEN, WIDE_OPEN); |
| 169 | return bm; |
| 170 | } |
| 171 | |
| 172 | SkDumpCanvas::SkDumpCanvas(Dumper* dumper) : INHERITED(make_wideopen_bm()) { |
| 173 | fNestLevel = 0; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 174 | SkSafeRef(dumper); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 175 | fDumper = dumper; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | SkDumpCanvas::~SkDumpCanvas() { |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 179 | SkSafeUnref(fDumper); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | void SkDumpCanvas::dump(Verb verb, const SkPaint* paint, |
| 183 | const char format[], ...) { |
| 184 | static const size_t BUFFER_SIZE = 1024; |
| 185 | |
| 186 | char buffer[BUFFER_SIZE]; |
| 187 | va_list args; |
| 188 | va_start(args, format); |
| 189 | vsnprintf(buffer, BUFFER_SIZE, format, args); |
| 190 | va_end(args); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 191 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 192 | if (fDumper) { |
| 193 | fDumper->dump(this, verb, buffer, paint); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | /////////////////////////////////////////////////////////////////////////////// |
| 198 | |
| 199 | int SkDumpCanvas::save(SaveFlags flags) { |
| 200 | this->dump(kSave_Verb, NULL, "save(0x%X)", flags); |
| 201 | return this->INHERITED::save(flags); |
| 202 | } |
| 203 | |
| 204 | int SkDumpCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, |
| 205 | SaveFlags flags) { |
reed@google.com | 4258c2c | 2012-08-31 15:41:10 +0000 | [diff] [blame] | 206 | SkString str; |
| 207 | str.printf("saveLayer(0x%X)", flags); |
| 208 | if (bounds) { |
| 209 | str.append(" bounds"); |
| 210 | toString(*bounds, &str); |
| 211 | } |
| 212 | if (paint) { |
| 213 | if (paint->getAlpha() != 0xFF) { |
| 214 | str.appendf(" alpha:0x%02X", paint->getAlpha()); |
| 215 | } |
| 216 | if (paint->getXfermode()) { |
| 217 | str.appendf(" xfermode:%p", paint->getXfermode()); |
| 218 | } |
| 219 | } |
| 220 | this->dump(kSave_Verb, paint, str.c_str()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 221 | return this->INHERITED::saveLayer(bounds, paint, flags); |
| 222 | } |
| 223 | |
| 224 | void SkDumpCanvas::restore() { |
| 225 | this->INHERITED::restore(); |
| 226 | this->dump(kRestore_Verb, NULL, "restore"); |
| 227 | } |
| 228 | |
| 229 | bool SkDumpCanvas::translate(SkScalar dx, SkScalar dy) { |
| 230 | this->dump(kMatrix_Verb, NULL, "translate(%g %g)", |
| 231 | SkScalarToFloat(dx), SkScalarToFloat(dy)); |
| 232 | return this->INHERITED::translate(dx, dy); |
| 233 | } |
| 234 | |
| 235 | bool SkDumpCanvas::scale(SkScalar sx, SkScalar sy) { |
| 236 | this->dump(kMatrix_Verb, NULL, "scale(%g %g)", |
| 237 | SkScalarToFloat(sx), SkScalarToFloat(sy)); |
| 238 | return this->INHERITED::scale(sx, sy); |
| 239 | } |
| 240 | |
| 241 | bool SkDumpCanvas::rotate(SkScalar degrees) { |
| 242 | this->dump(kMatrix_Verb, NULL, "rotate(%g)", SkScalarToFloat(degrees)); |
| 243 | return this->INHERITED::rotate(degrees); |
| 244 | } |
| 245 | |
| 246 | bool SkDumpCanvas::skew(SkScalar sx, SkScalar sy) { |
| 247 | this->dump(kMatrix_Verb, NULL, "skew(%g %g)", |
| 248 | SkScalarToFloat(sx), SkScalarToFloat(sy)); |
| 249 | return this->INHERITED::skew(sx, sy); |
| 250 | } |
| 251 | |
| 252 | bool SkDumpCanvas::concat(const SkMatrix& matrix) { |
| 253 | SkString str; |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 254 | matrix.toString(&str); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 255 | this->dump(kMatrix_Verb, NULL, "concat(%s)", str.c_str()); |
| 256 | return this->INHERITED::concat(matrix); |
| 257 | } |
| 258 | |
| 259 | void SkDumpCanvas::setMatrix(const SkMatrix& matrix) { |
| 260 | SkString str; |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 261 | matrix.toString(&str); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 262 | this->dump(kMatrix_Verb, NULL, "setMatrix(%s)", str.c_str()); |
| 263 | this->INHERITED::setMatrix(matrix); |
| 264 | } |
| 265 | |
| 266 | /////////////////////////////////////////////////////////////////////////////// |
| 267 | |
reed@google.com | 071eef9 | 2011-10-12 11:52:53 +0000 | [diff] [blame] | 268 | static const char* bool_to_aastring(bool doAA) { |
| 269 | return doAA ? "AA" : "BW"; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 270 | } |
| 271 | |
reed@google.com | 071eef9 | 2011-10-12 11:52:53 +0000 | [diff] [blame] | 272 | bool SkDumpCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { |
| 273 | SkString str; |
| 274 | toString(rect, &str); |
| 275 | this->dump(kClip_Verb, NULL, "clipRect(%s %s %s)", str.c_str(), toString(op), |
| 276 | bool_to_aastring(doAA)); |
| 277 | return this->INHERITED::clipRect(rect, op, doAA); |
| 278 | } |
| 279 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 280 | bool SkDumpCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) { |
| 281 | SkString str; |
| 282 | toString(rrect, &str); |
| 283 | this->dump(kClip_Verb, NULL, "clipRRect(%s %s %s)", str.c_str(), toString(op), |
| 284 | bool_to_aastring(doAA)); |
| 285 | return this->INHERITED::clipRRect(rrect, op, doAA); |
| 286 | } |
| 287 | |
reed@google.com | 071eef9 | 2011-10-12 11:52:53 +0000 | [diff] [blame] | 288 | bool SkDumpCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 289 | SkString str; |
| 290 | toString(path, &str); |
reed@google.com | 071eef9 | 2011-10-12 11:52:53 +0000 | [diff] [blame] | 291 | this->dump(kClip_Verb, NULL, "clipPath(%s %s %s)", str.c_str(), toString(op), |
| 292 | bool_to_aastring(doAA)); |
| 293 | return this->INHERITED::clipPath(path, op, doAA); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | bool SkDumpCanvas::clipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { |
| 297 | SkString str; |
| 298 | toString(deviceRgn, &str); |
| 299 | this->dump(kClip_Verb, NULL, "clipRegion(%s %s)", str.c_str(), |
| 300 | toString(op)); |
| 301 | return this->INHERITED::clipRegion(deviceRgn, op); |
| 302 | } |
| 303 | |
| 304 | /////////////////////////////////////////////////////////////////////////////// |
| 305 | |
| 306 | void SkDumpCanvas::drawPaint(const SkPaint& paint) { |
| 307 | this->dump(kDrawPaint_Verb, &paint, "drawPaint()"); |
| 308 | } |
| 309 | |
| 310 | void SkDumpCanvas::drawPoints(PointMode mode, size_t count, |
| 311 | const SkPoint pts[], const SkPaint& paint) { |
| 312 | this->dump(kDrawPoints_Verb, &paint, "drawPoints(%s, %d)", toString(mode), |
| 313 | count); |
| 314 | } |
| 315 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 316 | void SkDumpCanvas::drawOval(const SkRect& rect, const SkPaint& paint) { |
| 317 | SkString str; |
| 318 | toString(rect, &str); |
| 319 | this->dump(kDrawOval_Verb, &paint, "drawOval(%s)", str.c_str()); |
| 320 | } |
| 321 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 322 | void SkDumpCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { |
| 323 | SkString str; |
| 324 | toString(rect, &str); |
| 325 | this->dump(kDrawRect_Verb, &paint, "drawRect(%s)", str.c_str()); |
| 326 | } |
| 327 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 328 | void SkDumpCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
| 329 | SkString str; |
| 330 | toString(rrect, &str); |
| 331 | this->dump(kDrawRRect_Verb, &paint, "drawRRect(%s)", str.c_str()); |
| 332 | } |
| 333 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 334 | void SkDumpCanvas::drawPath(const SkPath& path, const SkPaint& paint) { |
| 335 | SkString str; |
| 336 | toString(path, &str); |
| 337 | this->dump(kDrawPath_Verb, &paint, "drawPath(%s)", str.c_str()); |
| 338 | } |
| 339 | |
| 340 | void SkDumpCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y, |
| 341 | const SkPaint* paint) { |
| 342 | SkString str; |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 343 | bitmap.toString(&str); |
reed@android.com | 0becfc5b | 2009-01-13 13:26:44 +0000 | [diff] [blame] | 344 | this->dump(kDrawBitmap_Verb, paint, "drawBitmap(%s %g %g)", str.c_str(), |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 345 | SkScalarToFloat(x), SkScalarToFloat(y)); |
| 346 | } |
| 347 | |
reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 348 | void SkDumpCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, |
| 349 | const SkRect& dst, const SkPaint* paint) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 350 | SkString bs, rs; |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 351 | bitmap.toString(&bs); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 352 | toString(dst, &rs); |
| 353 | // show the src-rect only if its not everything |
| 354 | if (src && (src->fLeft > 0 || src->fTop > 0 || |
reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 355 | src->fRight < SkIntToScalar(bitmap.width()) || |
| 356 | src->fBottom < SkIntToScalar(bitmap.height()))) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 357 | SkString ss; |
| 358 | toString(*src, &ss); |
| 359 | rs.prependf("%s ", ss.c_str()); |
| 360 | } |
| 361 | |
reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 362 | this->dump(kDrawBitmap_Verb, paint, "drawBitmapRectToRect(%s %s)", |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 363 | bs.c_str(), rs.c_str()); |
| 364 | } |
| 365 | |
| 366 | void SkDumpCanvas::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m, |
| 367 | const SkPaint* paint) { |
| 368 | SkString bs, ms; |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 369 | bitmap.toString(&bs); |
| 370 | m.toString(&ms); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 371 | this->dump(kDrawBitmap_Verb, paint, "drawBitmapMatrix(%s %s)", |
| 372 | bs.c_str(), ms.c_str()); |
| 373 | } |
| 374 | |
| 375 | void SkDumpCanvas::drawSprite(const SkBitmap& bitmap, int x, int y, |
| 376 | const SkPaint* paint) { |
| 377 | SkString str; |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 378 | bitmap.toString(&str); |
reed@android.com | 0becfc5b | 2009-01-13 13:26:44 +0000 | [diff] [blame] | 379 | this->dump(kDrawBitmap_Verb, paint, "drawSprite(%s %d %d)", str.c_str(), |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 380 | x, y); |
| 381 | } |
| 382 | |
| 383 | void SkDumpCanvas::drawText(const void* text, size_t byteLength, SkScalar x, |
| 384 | SkScalar y, const SkPaint& paint) { |
| 385 | SkString str; |
| 386 | toString(text, byteLength, paint.getTextEncoding(), &str); |
reed@android.com | 0becfc5b | 2009-01-13 13:26:44 +0000 | [diff] [blame] | 387 | this->dump(kDrawText_Verb, &paint, "drawText(%s [%d] %g %g)", str.c_str(), |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 388 | byteLength, SkScalarToFloat(x), SkScalarToFloat(y)); |
| 389 | } |
| 390 | |
| 391 | void SkDumpCanvas::drawPosText(const void* text, size_t byteLength, |
| 392 | const SkPoint pos[], const SkPaint& paint) { |
| 393 | SkString str; |
| 394 | toString(text, byteLength, paint.getTextEncoding(), &str); |
reed@android.com | 0becfc5b | 2009-01-13 13:26:44 +0000 | [diff] [blame] | 395 | this->dump(kDrawText_Verb, &paint, "drawPosText(%s [%d] %g %g ...)", |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 396 | str.c_str(), byteLength, SkScalarToFloat(pos[0].fX), |
| 397 | SkScalarToFloat(pos[0].fY)); |
| 398 | } |
| 399 | |
| 400 | void SkDumpCanvas::drawPosTextH(const void* text, size_t byteLength, |
| 401 | const SkScalar xpos[], SkScalar constY, |
| 402 | const SkPaint& paint) { |
| 403 | SkString str; |
| 404 | toString(text, byteLength, paint.getTextEncoding(), &str); |
reed@android.com | 0becfc5b | 2009-01-13 13:26:44 +0000 | [diff] [blame] | 405 | this->dump(kDrawText_Verb, &paint, "drawPosTextH(%s [%d] %g %g ...)", |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 406 | str.c_str(), byteLength, SkScalarToFloat(xpos[0]), |
| 407 | SkScalarToFloat(constY)); |
| 408 | } |
| 409 | |
| 410 | void SkDumpCanvas::drawTextOnPath(const void* text, size_t byteLength, |
| 411 | const SkPath& path, const SkMatrix* matrix, |
| 412 | const SkPaint& paint) { |
| 413 | SkString str; |
| 414 | toString(text, byteLength, paint.getTextEncoding(), &str); |
| 415 | this->dump(kDrawText_Verb, &paint, "drawTextOnPath(%s [%d])", |
| 416 | str.c_str(), byteLength); |
| 417 | } |
| 418 | |
| 419 | void SkDumpCanvas::drawPicture(SkPicture& picture) { |
reed@android.com | 9b46e77 | 2009-06-05 12:24:41 +0000 | [diff] [blame] | 420 | this->dump(kDrawPicture_Verb, NULL, "drawPicture(%p) %d:%d", &picture, |
| 421 | picture.width(), picture.height()); |
| 422 | fNestLevel += 1; |
| 423 | this->INHERITED::drawPicture(picture); |
| 424 | fNestLevel -= 1; |
| 425 | this->dump(kDrawPicture_Verb, NULL, "endPicture(%p) %d:%d", &picture, |
| 426 | picture.width(), picture.height()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | void SkDumpCanvas::drawVertices(VertexMode vmode, int vertexCount, |
| 430 | const SkPoint vertices[], const SkPoint texs[], |
| 431 | const SkColor colors[], SkXfermode* xmode, |
| 432 | const uint16_t indices[], int indexCount, |
| 433 | const SkPaint& paint) { |
reed@android.com | 0becfc5b | 2009-01-13 13:26:44 +0000 | [diff] [blame] | 434 | this->dump(kDrawVertices_Verb, &paint, "drawVertices(%s [%d] %g %g ...)", |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 435 | toString(vmode), vertexCount, SkScalarToFloat(vertices[0].fX), |
| 436 | SkScalarToFloat(vertices[0].fY)); |
| 437 | } |
| 438 | |
reed@android.com | cb60844 | 2009-12-04 21:32:27 +0000 | [diff] [blame] | 439 | void SkDumpCanvas::drawData(const void* data, size_t length) { |
| 440 | // this->dump(kDrawData_Verb, NULL, "drawData(%d)", length); |
| 441 | this->dump(kDrawData_Verb, NULL, "drawData(%d) %.*s", length, |
| 442 | SkMin32(length, 64), data); |
| 443 | } |
| 444 | |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame^] | 445 | void SkDumpCanvas::beginCommentGroup(const char* description) { |
| 446 | this->dump(kBeginCommentGroup_Verb, NULL, "beginCommentGroup(%s)", description); |
| 447 | } |
| 448 | |
| 449 | void SkDumpCanvas::addComment(const char* kywd, const char* value) { |
| 450 | this->dump(kAddComment_Verb, NULL, "addComment(%s, %s)", kywd, value); |
| 451 | } |
| 452 | |
| 453 | void SkDumpCanvas::endCommentGroup() { |
| 454 | this->dump(kEndCommentGroup_Verb, NULL, "endCommentGroup()"); |
| 455 | } |
| 456 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 457 | /////////////////////////////////////////////////////////////////////////////// |
| 458 | /////////////////////////////////////////////////////////////////////////////// |
| 459 | |
| 460 | SkFormatDumper::SkFormatDumper(void (*proc)(const char*, void*), void* refcon) { |
| 461 | fProc = proc; |
| 462 | fRefcon = refcon; |
| 463 | } |
| 464 | |
| 465 | static void appendPtr(SkString* str, const void* ptr, const char name[]) { |
| 466 | if (ptr) { |
| 467 | str->appendf(" %s:%p", name, ptr); |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | static void appendFlattenable(SkString* str, const SkFlattenable* ptr, |
| 472 | const char name[]) { |
| 473 | if (ptr) { |
djsollen@google.com | a2ca41e | 2012-03-23 19:00:34 +0000 | [diff] [blame] | 474 | str->appendf(" %s:%p", name, ptr); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 475 | } |
| 476 | } |
| 477 | |
| 478 | void SkFormatDumper::dump(SkDumpCanvas* canvas, SkDumpCanvas::Verb verb, |
| 479 | const char str[], const SkPaint* p) { |
| 480 | SkString msg, tab; |
reed@android.com | 9b46e77 | 2009-06-05 12:24:41 +0000 | [diff] [blame] | 481 | const int level = canvas->getNestLevel() + canvas->getSaveCount() - 1; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 482 | SkASSERT(level >= 0); |
| 483 | for (int i = 0; i < level; i++) { |
reed@google.com | 4258c2c | 2012-08-31 15:41:10 +0000 | [diff] [blame] | 484 | #if 0 |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 485 | tab.append("\t"); |
reed@google.com | 4258c2c | 2012-08-31 15:41:10 +0000 | [diff] [blame] | 486 | #else |
| 487 | tab.append(" "); // tabs are often too wide to be useful |
| 488 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 489 | } |
| 490 | msg.printf("%s%s", tab.c_str(), str); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 491 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 492 | if (p) { |
| 493 | msg.appendf(" color:0x%08X flags:%X", p->getColor(), p->getFlags()); |
| 494 | appendFlattenable(&msg, p->getShader(), "shader"); |
| 495 | appendFlattenable(&msg, p->getXfermode(), "xfermode"); |
| 496 | appendFlattenable(&msg, p->getPathEffect(), "pathEffect"); |
| 497 | appendFlattenable(&msg, p->getMaskFilter(), "maskFilter"); |
| 498 | appendFlattenable(&msg, p->getPathEffect(), "pathEffect"); |
| 499 | appendFlattenable(&msg, p->getColorFilter(), "filter"); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 500 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 501 | if (SkDumpCanvas::kDrawText_Verb == verb) { |
| 502 | msg.appendf(" textSize:%g", SkScalarToFloat(p->getTextSize())); |
| 503 | appendPtr(&msg, p->getTypeface(), "typeface"); |
| 504 | } |
| 505 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 506 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 507 | fProc(msg.c_str(), fRefcon); |
| 508 | } |
| 509 | |
| 510 | /////////////////////////////////////////////////////////////////////////////// |
| 511 | |
| 512 | static void dumpToDebugf(const char text[], void*) { |
| 513 | SkDebugf("%s\n", text); |
| 514 | } |
| 515 | |
| 516 | SkDebugfDumper::SkDebugfDumper() : INHERITED(dumpToDebugf, NULL) {} |
| 517 | |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 518 | #endif |