3 * Copyright 2011 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
8 #ifndef SkDumpCanvas_DEFINED
9 #define SkDumpCanvas_DEFINED
15 /** This class overrides all the draw methods on SkCanvas, and formats them
16 as text, and then sends that to a Dumper helper object.
18 Typical use might be to dump a display list to a log file to see what is
21 class SkDumpCanvas : public SkCanvas {
25 explicit SkDumpCanvas(Dumper* = 0);
26 virtual ~SkDumpCanvas();
51 kBeginCommentGroup_Verb,
53 kEndCommentGroup_Verb,
58 /** Subclasses of this are installed on the DumpCanvas, and then called for
61 class Dumper : public SkRefCnt {
63 SK_DECLARE_INST_COUNT(Dumper)
65 virtual void dump(SkDumpCanvas*, SkDumpCanvas::Verb, const char str[],
69 typedef SkRefCnt INHERITED;
72 Dumper* getDumper() const { return fDumper; }
73 void setDumper(Dumper*);
75 int getNestLevel() const { return fNestLevel; }
77 virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
78 virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[],
79 const SkPaint& paint) SK_OVERRIDE;
80 virtual void drawOval(const SkRect&, const SkPaint& paint) SK_OVERRIDE;
81 virtual void drawRect(const SkRect&, const SkPaint& paint) SK_OVERRIDE;
82 virtual void drawRRect(const SkRRect&, const SkPaint& paint) SK_OVERRIDE;
83 virtual void drawPath(const SkPath& path, const SkPaint& paint) SK_OVERRIDE;
84 virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
85 const SkPaint* paint) SK_OVERRIDE;
86 virtual void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src,
87 const SkRect& dst, const SkPaint* paint,
88 DrawBitmapRectFlags flags) SK_OVERRIDE;
89 virtual void drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m,
90 const SkPaint* paint) SK_OVERRIDE;
91 virtual void drawSprite(const SkBitmap& bitmap, int left, int top,
92 const SkPaint* paint) SK_OVERRIDE;
93 virtual void drawPicture(SkPicture&) SK_OVERRIDE;
94 virtual void drawVertices(VertexMode vmode, int vertexCount,
95 const SkPoint vertices[], const SkPoint texs[],
96 const SkColor colors[], SkXfermode* xmode,
97 const uint16_t indices[], int indexCount,
98 const SkPaint& paint) SK_OVERRIDE;
99 virtual void drawData(const void*, size_t) SK_OVERRIDE;
100 virtual void beginCommentGroup(const char* description) SK_OVERRIDE;
101 virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE;
102 virtual void endCommentGroup() SK_OVERRIDE;
105 virtual void willSave(SaveFlags) SK_OVERRIDE;
106 virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE;
107 virtual void willRestore() SK_OVERRIDE;
109 virtual void didConcat(const SkMatrix&) SK_OVERRIDE;
110 virtual void didSetMatrix(const SkMatrix&) SK_OVERRIDE;
112 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
113 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
114 const SkPaint&) SK_OVERRIDE;
115 virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
116 const SkPaint&) SK_OVERRIDE;
117 virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
118 SkScalar constY, const SkPaint&) SK_OVERRIDE;
119 virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
120 const SkMatrix* matrix, const SkPaint&) SK_OVERRIDE;
121 virtual void onPushCull(const SkRect& cullRect) SK_OVERRIDE;
122 virtual void onPopCull() SK_OVERRIDE;
124 virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
125 virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
126 virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
127 virtual void onClipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE;
129 static const char* EdgeStyleToAAString(ClipEdgeStyle edgeStyle);
133 int fNestLevel; // for nesting recursive elements like pictures
135 void dump(Verb, const SkPaint*, const char format[], ...);
137 typedef SkCanvas INHERITED;
140 /** Formats the draw commands, and send them to a function-pointer provided
143 class SkFormatDumper : public SkDumpCanvas::Dumper {
145 SkFormatDumper(void (*)(const char text[], void* refcon), void* refcon);
147 // override from baseclass that does the formatting, and in turn calls
148 // the function pointer that was passed to the constructor
149 virtual void dump(SkDumpCanvas*, SkDumpCanvas::Verb, const char str[],
150 const SkPaint*) SK_OVERRIDE;
153 void (*fProc)(const char*, void*);
156 typedef SkDumpCanvas::Dumper INHERITED;
159 /** Subclass of Dumper that dumps the drawing command to SkDebugf
161 class SkDebugfDumper : public SkFormatDumper {
166 typedef SkFormatDumper INHERITED;