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