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