blob: 5347309e72c8d77dae9ea914784ec8248ddafa24 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001#ifndef SkDumpCanvas_DEFINED
2#define SkDumpCanvas_DEFINED
3
4#include "SkCanvas.h"
5
6/** This class overrides all the draw methods on SkCanvas, and formats them
7 as text, and then sends that to a Dumper helper object.
8
9 Typical use might be to dump a display list to a log file to see what is
10 being drawn.
11 */
12class SkDumpCanvas : public SkCanvas {
13public:
14 class Dumper;
15
16 explicit SkDumpCanvas(Dumper* = 0);
17 virtual ~SkDumpCanvas();
18
19 enum Verb {
20 kNULL_Verb,
21
22 kSave_Verb,
23 kRestore_Verb,
24
25 kMatrix_Verb,
26
27 kClip_Verb,
28
29 kDrawPaint_Verb,
30 kDrawPoints_Verb,
31 kDrawRect_Verb,
32 kDrawPath_Verb,
33 kDrawBitmap_Verb,
34 kDrawText_Verb,
35 kDrawPicture_Verb,
reed@android.comf76bacf2009-05-13 14:00:33 +000036 kDrawShape_Verb,
reed@android.com8a1c16f2008-12-17 15:59:43 +000037 kDrawVertices_Verb
38 };
39
40 /** Subclasses of this are installed on the DumpCanvas, and then called for
41 each drawing command.
42 */
43 class Dumper : public SkRefCnt {
44 public:
45 virtual void dump(SkDumpCanvas*, SkDumpCanvas::Verb, const char str[],
46 const SkPaint*) = 0;
47 };
48
49 Dumper* getDumper() const { return fDumper; }
50 void setDumper(Dumper*);
51
52 // overrides from SkCanvas
53
54 virtual int save(SaveFlags flags = kMatrixClip_SaveFlag);
55 virtual int saveLayer(const SkRect* bounds, const SkPaint* paint,
56 SaveFlags flags = kARGB_ClipLayer_SaveFlag);
57 virtual void restore();
58
59 virtual bool translate(SkScalar dx, SkScalar dy);
60 virtual bool scale(SkScalar sx, SkScalar sy);
61 virtual bool rotate(SkScalar degrees);
62 virtual bool skew(SkScalar sx, SkScalar sy);
63 virtual bool concat(const SkMatrix& matrix);
64 virtual void setMatrix(const SkMatrix& matrix);
65
66 virtual bool clipRect(const SkRect& rect,
67 SkRegion::Op op = SkRegion::kIntersect_Op);
68 virtual bool clipPath(const SkPath& path,
69 SkRegion::Op op = SkRegion::kIntersect_Op);
70 virtual bool clipRegion(const SkRegion& deviceRgn,
71 SkRegion::Op op = SkRegion::kIntersect_Op);
72
73 virtual void drawPaint(const SkPaint& paint);
74 virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[],
75 const SkPaint& paint);
76 virtual void drawRect(const SkRect& rect, const SkPaint& paint);
77 virtual void drawPath(const SkPath& path, const SkPaint& paint);
78 virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
79 const SkPaint* paint = NULL);
80 virtual void drawBitmapRect(const SkBitmap& bitmap, const SkIRect* src,
81 const SkRect& dst, const SkPaint* paint = NULL);
82 virtual void drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m,
83 const SkPaint* paint = NULL);
84 virtual void drawSprite(const SkBitmap& bitmap, int left, int top,
85 const SkPaint* paint = NULL);
86 virtual void drawText(const void* text, size_t byteLength, SkScalar x,
87 SkScalar y, const SkPaint& paint);
88 virtual void drawPosText(const void* text, size_t byteLength,
89 const SkPoint pos[], const SkPaint& paint);
90 virtual void drawPosTextH(const void* text, size_t byteLength,
91 const SkScalar xpos[], SkScalar constY,
92 const SkPaint& paint);
93 virtual void drawTextOnPath(const void* text, size_t byteLength,
94 const SkPath& path, const SkMatrix* matrix,
95 const SkPaint& paint);
reed@android.comf76bacf2009-05-13 14:00:33 +000096 virtual void drawPicture(SkPicture&);
97 virtual void drawShape(SkShape*);
reed@android.com8a1c16f2008-12-17 15:59:43 +000098 virtual void drawVertices(VertexMode vmode, int vertexCount,
99 const SkPoint vertices[], const SkPoint texs[],
100 const SkColor colors[], SkXfermode* xmode,
101 const uint16_t indices[], int indexCount,
102 const SkPaint& paint);
103
104private:
105 Dumper* fDumper;
106
107 void dump(Verb, const SkPaint*, const char format[], ...);
108
109 typedef SkCanvas INHERITED;
110};
111
112/** Formats the draw commands, and send them to a function-pointer provided
113 by the caller.
114 */
115class SkFormatDumper : public SkDumpCanvas::Dumper {
116public:
117 SkFormatDumper(void (*)(const char text[], void* refcon), void* refcon);
118
119 // override from baseclass that does the formatting, and in turn calls
120 // the function pointer that was passed to the constructor
121 virtual void dump(SkDumpCanvas*, SkDumpCanvas::Verb, const char str[],
122 const SkPaint*);
123
124private:
125 void (*fProc)(const char*, void*);
126 void* fRefcon;
127
128 typedef SkDumpCanvas::Dumper INHERITED;
129};
130
131/** Subclass of Dumper that dumps the drawing command to SkDebugf
132 */
133class SkDebugfDumper : public SkFormatDumper {
134public:
135 SkDebugfDumper();
136
137private:
138 typedef SkFormatDumper INHERITED;
139};
140
141#endif