blob: e1bb2ab90b7fd62f367f5caccda36fb52e232f87 [file] [log] [blame]
chudy@google.com902ebe52012-06-29 14:21:22 +00001
2/*
3 * Copyright 2012 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10#ifndef SKDEBUGCANVAS_H_
11#define SKDEBUGCANVAS_H_
12
13#include <iostream>
14#include "SkCanvas.h"
15#include "SkDrawCommand.h"
16#include "SkPicture.h"
17#include <vector>
18
19class SkDebugCanvas : public SkCanvas {
20public:
21 bool fFilter;
22
23 SkDebugCanvas();
24 ~SkDebugCanvas();
25
26 void toggleFilter(bool toggle);
27
28 /**
29 Executes all draw calls to the canvas.
30 @param canvas The canvas being drawn to
31 */
32 void draw(SkCanvas* canvas);
33
34 /**
35 Executes the draw calls in the specified range.
36 @param canvas The canvas being drawn to
37 @param i The beginning of the range
38 @param j The end of the range
39 TODO(chudy): Implement
40 */
41 void drawRange(SkCanvas* canvas, int i, int j);
42
43 /**
44 Executes the draw calls up to the specified index.
45 @param canvas The canvas being drawn to
46 @param index The index of the final command being executed
47 */
48 void drawTo(SkCanvas* canvas, int index);
49
50 /**
51 Returns the draw command at the given index.
52 @param index The index of the command
53 */
54 SkDrawCommand* getDrawCommandAt(int index);
55
56 /**
57 Returns information about the command at the given index.
58 @param index The index of the command
59 */
60 std::vector<std::string>* getCommandInfoAt(int index);
61
62 /**
63 Returns the vector of draw commands
64 */
65 std::vector<SkDrawCommand*> getDrawCommands();
66
67 /**
68 * Returns the string vector of draw commands
69 */
70 std::vector<std::string>* getDrawCommandsAsStrings();
71
72 /**
73 Toggles the execution of the draw command at index i.
74 */
75 void toggleCommand(int index);
76
77 /**
78 Toggles the visibility / execution of the draw command at index i with
79 the value of toggle.
80 */
81 void toggleCommand(int index, bool toggle);
82
83////////////////////////////////////////////////////////////////////////////////
84// Inherited from SkCanvas
85////////////////////////////////////////////////////////////////////////////////
86
87 virtual void clear(SkColor) SK_OVERRIDE;
88
89 virtual bool clipPath(const SkPath&, SkRegion::Op, bool) SK_OVERRIDE;
90
91 virtual bool clipRect(const SkRect&, SkRegion::Op, bool) SK_OVERRIDE;
92
93 virtual bool clipRegion(const SkRegion& region, SkRegion::Op op) SK_OVERRIDE;
94
95 virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE;
96
97 virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top,
98 const SkPaint*) SK_OVERRIDE;
99
100 virtual void drawBitmapRect(const SkBitmap&, const SkIRect* src,
101 const SkRect& dst, const SkPaint*) SK_OVERRIDE;
102
103 virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&,
104 const SkPaint*) SK_OVERRIDE;
105
106 virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
107 const SkRect& dst, const SkPaint*) SK_OVERRIDE;
108
109 virtual void drawData(const void*, size_t) SK_OVERRIDE;
110
111 virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
112
113 virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE;
114
115 virtual void drawPicture(SkPicture& picture) SK_OVERRIDE;
116
117 virtual void drawPoints(PointMode, size_t count, const SkPoint pts[],
118 const SkPaint&) SK_OVERRIDE;
119
120 virtual void drawPosText(const void* text, size_t byteLength,
121 const SkPoint pos[], const SkPaint&) SK_OVERRIDE;
122
123 virtual void drawPosTextH(const void* text, size_t byteLength,
124 const SkScalar xpos[], SkScalar constY, const SkPaint&) SK_OVERRIDE;
125
126 virtual void drawRect(const SkRect& rect, const SkPaint&) SK_OVERRIDE;
127
128 virtual void drawSprite(const SkBitmap&, int left, int top,
129 const SkPaint*) SK_OVERRIDE;
130
131 virtual void drawText(const void* text, size_t byteLength, SkScalar x,
132 SkScalar y, const SkPaint&) SK_OVERRIDE;
133
134 virtual void drawTextOnPath(const void* text, size_t byteLength,
135 const SkPath& path, const SkMatrix* matrix,
136 const SkPaint&) SK_OVERRIDE;
137
138 virtual void drawVertices(VertexMode, int vertexCount,
139 const SkPoint vertices[], const SkPoint texs[],
140 const SkColor colors[], SkXfermode*,
141 const uint16_t indices[], int indexCount,
142 const SkPaint&) SK_OVERRIDE;
143
144 virtual void restore() SK_OVERRIDE;
145
146 virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
147
148 virtual int save(SaveFlags) SK_OVERRIDE;
149
150 virtual int saveLayer(const SkRect* bounds, const SkPaint*, SaveFlags) SK_OVERRIDE;
151
152 virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
153
154 virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE;
155
156 virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE;
157
158 virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
159
160private:
161 typedef SkCanvas INHERITED;
162 std::vector<SkDrawCommand*> commandVector;
163 std::vector<SkDrawCommand*>::const_iterator it;
164
165 SkBitmap fBm;
166
167 /**
168 Adds the command to the classes vector of commands.
169 @param command The draw command for execution
170 */
171 void addDrawCommand(SkDrawCommand* command);
172};
173
174#endif