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