1 /*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkData.h"
9 #include "SkDumpCanvas.h"
10 #include "SkPatchUtils.h"
11 #include "SkPicture.h"
12 #include "SkPixelRef.h"
13 #include "SkRegion.h"
14 #include "SkRRect.h"
15 #include "SkString.h"
16 #include "SkTextBlob.h"
17 #include <stdarg.h>
18 #include <stdio.h>
19
20 // needed just to know that these are all subclassed from SkFlattenable
21 #include "SkShader.h"
22 #include "SkPathEffect.h"
23 #include "SkColorFilter.h"
24 #include "SkPathEffect.h"
25 #include "SkMaskFilter.h"
26
toString(const SkRect & r,SkString * str)27 static void toString(const SkRect& r, SkString* str) {
28 str->appendf("[%g,%g %g:%g]",
29 SkScalarToFloat(r.fLeft), SkScalarToFloat(r.fTop),
30 SkScalarToFloat(r.width()), SkScalarToFloat(r.height()));
31 }
32
toString(const SkIRect & r,SkString * str)33 static void toString(const SkIRect& r, SkString* str) {
34 str->appendf("[%d,%d %d:%d]", r.fLeft, r.fTop, r.width(), r.height());
35 }
36
toString(const SkRRect & rrect,SkString * str)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
dumpVerbs(const SkPath & path,SkString * str)62 static void dumpVerbs(const SkPath& path, SkString* str) {
63 SkPath::Iter iter(path, false);
64 SkPoint pts[4];
65 for (;;) {
66 switch (iter.next(pts, false)) {
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:
82 str->append("X");
83 break;
84 case SkPath::kDone_Verb:
85 return;
86 case SkPath::kConic_Verb:
87 SkASSERT(0);
88 break;
89 }
90 }
91 }
92
toString(const SkPath & path,SkString * str)93 static void toString(const SkPath& path, SkString* str) {
94 if (path.isEmpty()) {
95 str->append("path:empty");
96 } else {
97 toString(path.getBounds(), str);
98 #if 1
99 SkString s;
100 dumpVerbs(path, &s);
101 str->append(s.c_str());
102 #endif
103 str->append("]");
104 str->prepend("path:[");
105 }
106 }
107
toString(SkClipOp op)108 static const char* toString(SkClipOp op) {
109 static const char* gOpNames[] = {
110 "DIFF", "SECT", "UNION", "XOR", "RDIFF", "REPLACE"
111 };
112 return gOpNames[static_cast<int>(op)];
113 }
114
toString(const SkRegion & rgn,SkString * str)115 static void toString(const SkRegion& rgn, SkString* str) {
116 str->append("Region:[");
117 toString(rgn.getBounds(), str);
118 str->append("]");
119 if (rgn.isComplex()) {
120 str->append(".complex");
121 }
122 }
123
toString(SkCanvas::VertexMode vm)124 static const char* toString(SkCanvas::VertexMode vm) {
125 static const char* gVMNames[] = {
126 "TRIANGLES", "STRIP", "FAN"
127 };
128 return gVMNames[vm];
129 }
130
toString(SkCanvas::PointMode pm)131 static const char* toString(SkCanvas::PointMode pm) {
132 static const char* gPMNames[] = {
133 "POINTS", "LINES", "POLYGON"
134 };
135 return gPMNames[pm];
136 }
137
toString(const void * text,size_t byteLen,SkPaint::TextEncoding enc,SkString * str)138 static void toString(const void* text, size_t byteLen, SkPaint::TextEncoding enc,
139 SkString* str) {
140 // FIXME: this code appears to be untested - and probably unused - and probably wrong
141 switch (enc) {
142 case SkPaint::kUTF8_TextEncoding:
143 str->appendf("\"%.*s\"%s", (int)SkTMax<size_t>(byteLen, 32), (const char*) text,
144 byteLen > 32 ? "..." : "");
145 break;
146 case SkPaint::kUTF16_TextEncoding:
147 str->appendf("\"%.*ls\"%s", (int)SkTMax<size_t>(byteLen, 32), (const wchar_t*) text,
148 byteLen > 64 ? "..." : "");
149 break;
150 case SkPaint::kUTF32_TextEncoding:
151 str->appendf("\"%.*ls\"%s", (int)SkTMax<size_t>(byteLen, 32), (const wchar_t*) text,
152 byteLen > 128 ? "..." : "");
153 break;
154 case SkPaint::kGlyphID_TextEncoding:
155 str->append("<glyphs>");
156 break;
157
158 default:
159 SkASSERT(false);
160 break;
161 }
162 }
163
164 ///////////////////////////////////////////////////////////////////////////////
165
166 #define WIDE_OPEN 16384
167
SkDumpCanvas(Dumper * dumper)168 SkDumpCanvas::SkDumpCanvas(Dumper* dumper) : INHERITED(WIDE_OPEN, WIDE_OPEN) {
169 fNestLevel = 0;
170 SkSafeRef(dumper);
171 fDumper = dumper;
172 }
173
~SkDumpCanvas()174 SkDumpCanvas::~SkDumpCanvas() {
175 SkSafeUnref(fDumper);
176 }
177
dump(Verb verb,const SkPaint * paint,const char format[],...)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);
187
188 if (fDumper) {
189 fDumper->dump(this, verb, buffer, paint);
190 }
191 }
192
193 ///////////////////////////////////////////////////////////////////////////////
194
willSave()195 void SkDumpCanvas::willSave() {
196 this->dump(kSave_Verb, nullptr, "save()");
197 this->INHERITED::willSave();
198 }
199
getSaveLayerStrategy(const SaveLayerRec & rec)200 SkCanvas::SaveLayerStrategy SkDumpCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) {
201 SkString str;
202 str.printf("saveLayer(0x%X)", rec.fSaveLayerFlags);
203 if (rec.fBounds) {
204 str.append(" bounds");
205 toString(*rec.fBounds, &str);
206 }
207 const SkPaint* paint = rec.fPaint;
208 if (paint) {
209 if (paint->getAlpha() != 0xFF) {
210 str.appendf(" alpha:0x%02X", paint->getAlpha());
211 }
212 if (!paint->isSrcOver()) {
213 str.appendf(" blendmode:%d", (int)paint->getBlendMode());
214 }
215 }
216 this->dump(kSave_Verb, paint, str.c_str());
217 return this->INHERITED::getSaveLayerStrategy(rec);
218 }
219
willRestore()220 void SkDumpCanvas::willRestore() {
221 this->dump(kRestore_Verb, nullptr, "restore");
222 this->INHERITED::willRestore();
223 }
224
didConcat(const SkMatrix & matrix)225 void SkDumpCanvas::didConcat(const SkMatrix& matrix) {
226 SkString str;
227
228 switch (matrix.getType()) {
229 case SkMatrix::kTranslate_Mask:
230 this->dump(kMatrix_Verb, nullptr, "translate(%g %g)",
231 SkScalarToFloat(matrix.getTranslateX()),
232 SkScalarToFloat(matrix.getTranslateY()));
233 break;
234 case SkMatrix::kScale_Mask:
235 this->dump(kMatrix_Verb, nullptr, "scale(%g %g)",
236 SkScalarToFloat(matrix.getScaleX()),
237 SkScalarToFloat(matrix.getScaleY()));
238 break;
239 default:
240 matrix.toString(&str);
241 this->dump(kMatrix_Verb, nullptr, "concat(%s)", str.c_str());
242 break;
243 }
244
245 this->INHERITED::didConcat(matrix);
246 }
247
didSetMatrix(const SkMatrix & matrix)248 void SkDumpCanvas::didSetMatrix(const SkMatrix& matrix) {
249 SkString str;
250 matrix.toString(&str);
251 this->dump(kMatrix_Verb, nullptr, "setMatrix(%s)", str.c_str());
252 this->INHERITED::didSetMatrix(matrix);
253 }
254
255 ///////////////////////////////////////////////////////////////////////////////
256
EdgeStyleToAAString(ClipEdgeStyle edgeStyle)257 const char* SkDumpCanvas::EdgeStyleToAAString(ClipEdgeStyle edgeStyle) {
258 return kSoft_ClipEdgeStyle == edgeStyle ? "AA" : "BW";
259 }
260
onClipRect(const SkRect & rect,SkClipOp op,ClipEdgeStyle edgeStyle)261 void SkDumpCanvas::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle edgeStyle) {
262 SkString str;
263 toString(rect, &str);
264 this->dump(kClip_Verb, nullptr, "clipRect(%s %s %s)", str.c_str(), toString(op),
265 EdgeStyleToAAString(edgeStyle));
266 this->INHERITED::onClipRect(rect, op, edgeStyle);
267 }
268
onClipRRect(const SkRRect & rrect,SkClipOp op,ClipEdgeStyle edgeStyle)269 void SkDumpCanvas::onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle edgeStyle) {
270 SkString str;
271 toString(rrect, &str);
272 this->dump(kClip_Verb, nullptr, "clipRRect(%s %s %s)", str.c_str(), toString(op),
273 EdgeStyleToAAString(edgeStyle));
274 this->INHERITED::onClipRRect(rrect, op, edgeStyle);
275 }
276
onClipPath(const SkPath & path,SkClipOp op,ClipEdgeStyle edgeStyle)277 void SkDumpCanvas::onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle edgeStyle) {
278 SkString str;
279 toString(path, &str);
280 this->dump(kClip_Verb, nullptr, "clipPath(%s %s %s)", str.c_str(), toString(op),
281 EdgeStyleToAAString(edgeStyle));
282 this->INHERITED::onClipPath(path, op, edgeStyle);
283 }
284
onClipRegion(const SkRegion & deviceRgn,SkClipOp op)285 void SkDumpCanvas::onClipRegion(const SkRegion& deviceRgn, SkClipOp op) {
286 SkString str;
287 toString(deviceRgn, &str);
288 this->dump(kClip_Verb, nullptr, "clipRegion(%s %s)", str.c_str(), toString(op));
289 this->INHERITED::onClipRegion(deviceRgn, op);
290 }
291
292 ///////////////////////////////////////////////////////////////////////////////
293
onDrawPaint(const SkPaint & paint)294 void SkDumpCanvas::onDrawPaint(const SkPaint& paint) {
295 this->dump(kDrawPaint_Verb, &paint, "drawPaint()");
296 }
297
onDrawPoints(PointMode mode,size_t count,const SkPoint pts[],const SkPaint & paint)298 void SkDumpCanvas::onDrawPoints(PointMode mode, size_t count,
299 const SkPoint pts[], const SkPaint& paint) {
300 this->dump(kDrawPoints_Verb, &paint, "drawPoints(%s, %d)", toString(mode),
301 count);
302 }
303
onDrawOval(const SkRect & rect,const SkPaint & paint)304 void SkDumpCanvas::onDrawOval(const SkRect& rect, const SkPaint& paint) {
305 SkString str;
306 toString(rect, &str);
307 this->dump(kDrawOval_Verb, &paint, "drawOval(%s)", str.c_str());
308 }
309
onDrawArc(const SkRect & rect,SkScalar startAngle,SkScalar sweepAngle,bool useCenter,const SkPaint & paint)310 void SkDumpCanvas::onDrawArc(const SkRect& rect, SkScalar startAngle, SkScalar sweepAngle,
311 bool useCenter, const SkPaint& paint) {
312 SkString str;
313 toString(rect, &str);
314 this->dump(kDrawArc_Verb, &paint, "drawArc(%s, %g, %g, %d)", str.c_str(), startAngle,
315 sweepAngle, useCenter);
316 }
317
onDrawRect(const SkRect & rect,const SkPaint & paint)318 void SkDumpCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) {
319 SkString str;
320 toString(rect, &str);
321 this->dump(kDrawRect_Verb, &paint, "drawRect(%s)", str.c_str());
322 }
323
onDrawRRect(const SkRRect & rrect,const SkPaint & paint)324 void SkDumpCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
325 SkString str;
326 toString(rrect, &str);
327 this->dump(kDrawDRRect_Verb, &paint, "drawRRect(%s)", str.c_str());
328 }
329
onDrawDRRect(const SkRRect & outer,const SkRRect & inner,const SkPaint & paint)330 void SkDumpCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner,
331 const SkPaint& paint) {
332 SkString str0, str1;
333 toString(outer, &str0);
334 toString(inner, &str0);
335 this->dump(kDrawRRect_Verb, &paint, "drawDRRect(%s,%s)",
336 str0.c_str(), str1.c_str());
337 }
338
onDrawPath(const SkPath & path,const SkPaint & paint)339 void SkDumpCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
340 SkString str;
341 toString(path, &str);
342 this->dump(kDrawPath_Verb, &paint, "drawPath(%s)", str.c_str());
343 }
344
onDrawBitmap(const SkBitmap & bitmap,SkScalar x,SkScalar y,const SkPaint * paint)345 void SkDumpCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y,
346 const SkPaint* paint) {
347 SkString str;
348 bitmap.toString(&str);
349 this->dump(kDrawBitmap_Verb, paint, "drawBitmap(%s %g %g)", str.c_str(),
350 SkScalarToFloat(x), SkScalarToFloat(y));
351 }
352
onDrawBitmapRect(const SkBitmap & bitmap,const SkRect * src,const SkRect & dst,const SkPaint * paint,SrcRectConstraint)353 void SkDumpCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
354 const SkPaint* paint, SrcRectConstraint) {
355 SkString bs, rs;
356 bitmap.toString(&bs);
357 toString(dst, &rs);
358 // show the src-rect only if its not everything
359 if (src && (src->fLeft > 0 || src->fTop > 0 ||
360 src->fRight < SkIntToScalar(bitmap.width()) ||
361 src->fBottom < SkIntToScalar(bitmap.height()))) {
362 SkString ss;
363 toString(*src, &ss);
364 rs.prependf("%s ", ss.c_str());
365 }
366
367 this->dump(kDrawBitmap_Verb, paint, "drawBitmapRect(%s %s)", bs.c_str(), rs.c_str());
368 }
369
onDrawBitmapNine(const SkBitmap & bitmap,const SkIRect & center,const SkRect & dst,const SkPaint * paint)370 void SkDumpCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
371 const SkRect& dst, const SkPaint* paint) {
372 SkString str, centerStr, dstStr;
373 bitmap.toString(&str);
374 toString(center, ¢erStr);
375 toString(dst, &dstStr);
376 this->dump(kDrawBitmap_Verb, paint, "drawBitmapNine(%s %s %s)", str.c_str(),
377 centerStr.c_str(), dstStr.c_str());
378 }
379
onDrawImage(const SkImage * image,SkScalar x,SkScalar y,const SkPaint * paint)380 void SkDumpCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, const SkPaint* paint) {
381 SkString str;
382 image->toString(&str);
383 this->dump(kDrawBitmap_Verb, paint, "drawImage(%s %g %g)", str.c_str(),
384 SkScalarToFloat(x), SkScalarToFloat(y));
385 }
386
onDrawImageRect(const SkImage * image,const SkRect * src,const SkRect & dst,const SkPaint * paint,SrcRectConstraint)387 void SkDumpCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
388 const SkPaint* paint, SrcRectConstraint) {
389 SkString bs, rs;
390 image->toString(&bs);
391 toString(dst, &rs);
392 // show the src-rect only if its not everything
393 if (src && (src->fLeft > 0 || src->fTop > 0 ||
394 src->fRight < SkIntToScalar(image->width()) ||
395 src->fBottom < SkIntToScalar(image->height()))) {
396 SkString ss;
397 toString(*src, &ss);
398 rs.prependf("%s ", ss.c_str());
399 }
400
401 this->dump(kDrawBitmap_Verb, paint, "drawImageRectToRect(%s %s)",
402 bs.c_str(), rs.c_str());
403 }
404
onDrawText(const void * text,size_t byteLength,SkScalar x,SkScalar y,const SkPaint & paint)405 void SkDumpCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
406 const SkPaint& paint) {
407 SkString str;
408 toString(text, byteLength, paint.getTextEncoding(), &str);
409 this->dump(kDrawText_Verb, &paint, "drawText(%s [%d] %g %g)", str.c_str(),
410 byteLength, SkScalarToFloat(x), SkScalarToFloat(y));
411 }
412
onDrawPosText(const void * text,size_t byteLength,const SkPoint pos[],const SkPaint & paint)413 void SkDumpCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
414 const SkPaint& paint) {
415 SkString str;
416 toString(text, byteLength, paint.getTextEncoding(), &str);
417 this->dump(kDrawText_Verb, &paint, "drawPosText(%s [%d] %g %g ...)",
418 str.c_str(), byteLength, SkScalarToFloat(pos[0].fX),
419 SkScalarToFloat(pos[0].fY));
420 }
421
onDrawPosTextH(const void * text,size_t byteLength,const SkScalar xpos[],SkScalar constY,const SkPaint & paint)422 void SkDumpCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
423 SkScalar constY, const SkPaint& paint) {
424 SkString str;
425 toString(text, byteLength, paint.getTextEncoding(), &str);
426 this->dump(kDrawText_Verb, &paint, "drawPosTextH(%s [%d] %g %g ...)",
427 str.c_str(), byteLength, SkScalarToFloat(xpos[0]),
428 SkScalarToFloat(constY));
429 }
430
onDrawTextOnPath(const void * text,size_t byteLength,const SkPath & path,const SkMatrix * matrix,const SkPaint & paint)431 void SkDumpCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
432 const SkMatrix* matrix, const SkPaint& paint) {
433 SkString str;
434 toString(text, byteLength, paint.getTextEncoding(), &str);
435 this->dump(kDrawText_Verb, &paint, "drawTextOnPath(%s [%d])",
436 str.c_str(), byteLength);
437 }
438
onDrawTextRSXform(const void * text,size_t byteLength,const SkRSXform xform[],const SkRect * cull,const SkPaint & paint)439 void SkDumpCanvas::onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[],
440 const SkRect* cull, const SkPaint& paint) {
441 SkString str;
442 toString(text, byteLength, paint.getTextEncoding(), &str);
443 this->dump(kDrawText_Verb, &paint, "drawTextRSXform(%s [%d])",
444 str.c_str(), byteLength);
445 }
446
onDrawTextBlob(const SkTextBlob * blob,SkScalar x,SkScalar y,const SkPaint & paint)447 void SkDumpCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
448 const SkPaint& paint) {
449 SkString str;
450 toString(blob->bounds(), &str);
451 this->dump(kDrawText_Verb, &paint, "drawTextBlob(%p) [%s]", blob, str.c_str());
452 // FIXME: dump the actual blob content?
453 }
454
onDrawPicture(const SkPicture * picture,const SkMatrix * matrix,const SkPaint * paint)455 void SkDumpCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
456 const SkPaint* paint) {
457 this->dump(kDrawPicture_Verb, nullptr, "drawPicture(%p) %f:%f:%f:%f", picture,
458 picture->cullRect().fLeft, picture->cullRect().fTop,
459 picture->cullRect().fRight, picture->cullRect().fBottom);
460 fNestLevel += 1;
461 this->INHERITED::onDrawPicture(picture, matrix, paint);
462 fNestLevel -= 1;
463 this->dump(kDrawPicture_Verb, nullptr, "endPicture(%p) %f:%f:%f:%f", &picture,
464 picture->cullRect().fLeft, picture->cullRect().fTop,
465 picture->cullRect().fRight, picture->cullRect().fBottom);
466 }
467
onDrawVerticesObject(const SkVertices * vertices,SkBlendMode,const SkPaint & paint)468 void SkDumpCanvas::onDrawVerticesObject(const SkVertices* vertices, SkBlendMode,
469 const SkPaint& paint) {
470 this->dump(kDrawVertices_Verb, &paint, "drawVertices(%s [%d] ...)",
471 toString(vertices->mode()), vertices->vertexCount());
472 }
473
onDrawPatch(const SkPoint cubics[12],const SkColor colors[4],const SkPoint texCoords[4],SkBlendMode,const SkPaint & paint)474 void SkDumpCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
475 const SkPoint texCoords[4], SkBlendMode,
476 const SkPaint& paint) {
477 //dumps corner points and colors in clockwise order starting on upper-left corner
478 this->dump(kDrawPatch_Verb, &paint, "drawPatch(Vertices{[%f, %f], [%f, %f], [%f, %f], [%f, %f]}\
479 | Colors{[0x%x], [0x%x], [0x%x], [0x%x]} | TexCoords{[%f,%f], [%f,%f], [%f,%f], \
480 [%f,%f]})",
481 cubics[SkPatchUtils::kTopP0_CubicCtrlPts].fX,
482 cubics[SkPatchUtils::kTopP0_CubicCtrlPts].fY,
483 cubics[SkPatchUtils::kTopP3_CubicCtrlPts].fX,
484 cubics[SkPatchUtils::kTopP3_CubicCtrlPts].fY,
485 cubics[SkPatchUtils::kBottomP3_CubicCtrlPts].fX,
486 cubics[SkPatchUtils::kBottomP3_CubicCtrlPts].fY,
487 cubics[SkPatchUtils::kBottomP0_CubicCtrlPts].fX,
488 cubics[SkPatchUtils::kBottomP0_CubicCtrlPts].fY,
489 colors[0], colors[1], colors[2], colors[3],
490 texCoords[0].x(), texCoords[0].y(), texCoords[1].x(), texCoords[1].y(),
491 texCoords[2].x(), texCoords[2].y(), texCoords[3].x(), texCoords[3].y());
492 }
493
onDrawAnnotation(const SkRect & rect,const char key[],SkData * value)494 void SkDumpCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) {
495 SkString str;
496 toString(rect, &str);
497 this->dump(kDrawAnnotation_Verb, nullptr, "drawAnnotation(%s \"%s\" (%zu))",
498 str.c_str(), key, value ? value->size() : 0);
499 }
500
501 ///////////////////////////////////////////////////////////////////////////////
502 ///////////////////////////////////////////////////////////////////////////////
503
SkFormatDumper(void (* proc)(const char *,void *),void * refcon)504 SkFormatDumper::SkFormatDumper(void (*proc)(const char*, void*), void* refcon) {
505 fProc = proc;
506 fRefcon = refcon;
507 }
508
appendPtr(SkString * str,const void * ptr,const char name[])509 static void appendPtr(SkString* str, const void* ptr, const char name[]) {
510 if (ptr) {
511 str->appendf(" %s:%p", name, ptr);
512 }
513 }
514
appendFlattenable(SkString * str,const SkFlattenable * ptr,const char name[])515 static void appendFlattenable(SkString* str, const SkFlattenable* ptr,
516 const char name[]) {
517 if (ptr) {
518 str->appendf(" %s:%p", name, ptr);
519 }
520 }
521
dump(SkDumpCanvas * canvas,SkDumpCanvas::Verb verb,const char str[],const SkPaint * p)522 void SkFormatDumper::dump(SkDumpCanvas* canvas, SkDumpCanvas::Verb verb,
523 const char str[], const SkPaint* p) {
524 SkString msg, tab;
525 const int level = canvas->getNestLevel() + canvas->getSaveCount() - 1;
526 SkASSERT(level >= 0);
527 for (int i = 0; i < level; i++) {
528 #if 0
529 tab.append("\t");
530 #else
531 tab.append(" "); // tabs are often too wide to be useful
532 #endif
533 }
534 msg.printf("%s%s", tab.c_str(), str);
535
536 if (p) {
537 msg.appendf(" color:0x%08X flags:%X", p->getColor(), p->getFlags());
538 if (!p->isSrcOver()) {
539 msg.appendf(" blendmode:%d", (int)p->getBlendMode());
540 }
541 appendFlattenable(&msg, p->getShader(), "shader");
542 appendFlattenable(&msg, p->getPathEffect(), "pathEffect");
543 appendFlattenable(&msg, p->getMaskFilter(), "maskFilter");
544 appendFlattenable(&msg, p->getPathEffect(), "pathEffect");
545 appendFlattenable(&msg, p->getColorFilter(), "filter");
546
547 if (SkDumpCanvas::kDrawText_Verb == verb) {
548 msg.appendf(" textSize:%g", SkScalarToFloat(p->getTextSize()));
549 appendPtr(&msg, p->getTypeface(), "typeface");
550 }
551
552 if (p->getStyle() != SkPaint::kFill_Style) {
553 msg.appendf(" strokeWidth:%g", SkScalarToFloat(p->getStrokeWidth()));
554 }
555 }
556
557 fProc(msg.c_str(), fRefcon);
558 }
559
560 ///////////////////////////////////////////////////////////////////////////////
561
dumpToDebugf(const char text[],void *)562 static void dumpToDebugf(const char text[], void*) {
563 SkDebugf("%s\n", text);
564 }
565
SkDebugfDumper()566 SkDebugfDumper::SkDebugfDumper() : INHERITED(dumpToDebugf, nullptr) {}
567