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();
50 kDrawData_Verb, // obsolete
52 kBeginCommentGroup_Verb,
54 kEndCommentGroup_Verb,
59 /** Subclasses of this are installed on the DumpCanvas, and then called for
62 class Dumper : public SkRefCnt {
64 SK_DECLARE_INST_COUNT(Dumper)
66 virtual void dump(SkDumpCanvas*, SkDumpCanvas::Verb, const char str[],
70 typedef SkRefCnt INHERITED;
73 Dumper* getDumper() const { return fDumper; }
74 void setDumper(Dumper*);
76 int getNestLevel() const { return fNestLevel; }
78 void beginCommentGroup(const char* description) override;
79 void addComment(const char* kywd, const char* value) override;
80 void endCommentGroup() override;
83 void willSave() override;
84 SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) override;
85 void willRestore() override;
87 void didConcat(const SkMatrix&) override;
88 void didSetMatrix(const SkMatrix&) override;
90 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
91 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
92 const SkPaint&) override;
93 virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
94 const SkPaint&) override;
95 virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
96 SkScalar constY, const SkPaint&) override;
97 virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
98 const SkMatrix* matrix, const SkPaint&) override;
99 virtual void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
100 const SkPaint& paint) override;
101 virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
102 const SkPoint texCoords[4], SkXfermode* xmode,
103 const SkPaint& paint) override;
105 void onDrawPaint(const SkPaint&) override;
106 void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override;
107 void onDrawRect(const SkRect&, const SkPaint&) override;
108 void onDrawOval(const SkRect&, const SkPaint&) override;
109 void onDrawRRect(const SkRRect&, const SkPaint&) override;
110 void onDrawPath(const SkPath&, const SkPaint&) override;
111 void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) override;
112 void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*,
113 DrawBitmapRectFlags flags) override;
114 void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint*) override;
115 void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
116 const SkPaint*) override;
117 void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
118 const SkPaint*) override;
119 void onDrawSprite(const SkBitmap&, int left, int top, const SkPaint*) override;
120 void onDrawVertices(VertexMode vmode, int vertexCount,
121 const SkPoint vertices[], const SkPoint texs[],
122 const SkColor colors[], SkXfermode* xmode,
123 const uint16_t indices[], int indexCount,
124 const SkPaint&) override;
126 void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) override;
127 void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) override;
128 void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) override;
129 void onClipRegion(const SkRegion&, SkRegion::Op) override;
131 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
133 static const char* EdgeStyleToAAString(ClipEdgeStyle edgeStyle);
137 int fNestLevel; // for nesting recursive elements like pictures
139 void dump(Verb, const SkPaint*, const char format[], ...);
141 typedef SkCanvas INHERITED;
144 /** Formats the draw commands, and send them to a function-pointer provided
147 class SkFormatDumper : public SkDumpCanvas::Dumper {
149 SkFormatDumper(void (*)(const char text[], void* refcon), void* refcon);
151 // override from baseclass that does the formatting, and in turn calls
152 // the function pointer that was passed to the constructor
153 virtual void dump(SkDumpCanvas*, SkDumpCanvas::Verb, const char str[],
154 const SkPaint*) override;
157 void (*fProc)(const char*, void*);
160 typedef SkDumpCanvas::Dumper INHERITED;
163 /** Subclass of Dumper that dumps the drawing command to SkDebugf
165 class SkDebugfDumper : public SkFormatDumper {
170 typedef SkFormatDumper INHERITED;