blob: e02c34c4f8eececab91d5374a4df9a4d48570d42 [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
chudy@google.com902ebe52012-06-29 14:21:22 +000013#include "SkCanvas.h"
14#include "SkDrawCommand.h"
15#include "SkPicture.h"
16#include <vector>
17
18class SkDebugCanvas : public SkCanvas {
19public:
chudy@google.com80a4a602012-07-30 18:54:07 +000020 SkDebugCanvas(int width, int height);
chudy@google.com902ebe52012-06-29 14:21:22 +000021 ~SkDebugCanvas();
22
23 void toggleFilter(bool toggle);
24
25 /**
26 Executes all draw calls to the canvas.
27 @param canvas The canvas being drawn to
28 */
29 void draw(SkCanvas* canvas);
30
31 /**
32 Executes the draw calls in the specified range.
33 @param canvas The canvas being drawn to
34 @param i The beginning of the range
35 @param j The end of the range
36 TODO(chudy): Implement
37 */
38 void drawRange(SkCanvas* canvas, int i, int j);
39
40 /**
41 Executes the draw calls up to the specified index.
42 @param canvas The canvas being drawn to
43 @param index The index of the final command being executed
44 */
chudy@google.com0b5bbb02012-07-31 19:55:32 +000045 void drawTo(SkCanvas* canvas, int index);
46
47 /**
chudy@google.coma9e937c2012-08-03 17:32:05 +000048 Returns the most recently calculated transformation matrix
49 */
50 const SkMatrix& getCurrentMatrix() {
51 return fMatrix;
52 }
53
54 /**
55 Returns the most recently calculated clip
56 */
57 const SkIRect& getCurrentClip() {
58 return fClip;
59 }
60
61 /**
chudy@google.com0b5bbb02012-07-31 19:55:32 +000062 Returns the index of the last draw command to write to the pixel at (x,y)
63 */
chudy@google.com830b8792012-08-01 15:57:52 +000064 int getCommandAtPoint(int x, int y, int index);
chudy@google.com902ebe52012-06-29 14:21:22 +000065
66 /**
67 Returns the draw command at the given index.
68 @param index The index of the command
69 */
70 SkDrawCommand* getDrawCommandAt(int index);
71
72 /**
73 Returns information about the command at the given index.
74 @param index The index of the command
75 */
76 std::vector<std::string>* getCommandInfoAt(int index);
77
78 /**
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000079 Returns the visibility of the command at the given index.
80 @param index The index of the command
81 */
82 bool getDrawCommandVisibilityAt(int index);
83
84 /**
chudy@google.com902ebe52012-06-29 14:21:22 +000085 Returns the vector of draw commands
86 */
87 std::vector<SkDrawCommand*> getDrawCommands();
88
89 /**
90 * Returns the string vector of draw commands
91 */
92 std::vector<std::string>* getDrawCommandsAsStrings();
93
94 /**
chudy@google.comf1414322012-07-03 20:28:14 +000095 Returns length of draw command vector.
96 */
97 int getSize() {
98 return commandVector.size();
99 }
100
chudy@google.com902ebe52012-06-29 14:21:22 +0000101 /**
102 Toggles the visibility / execution of the draw command at index i with
103 the value of toggle.
104 */
105 void toggleCommand(int index, bool toggle);
106
chudy@google.comb9ddd4e2012-07-10 14:14:50 +0000107 void setBounds(int width, int height) {
108 fWidth = width;
109 fHeight = height;
110 }
111
chudy@google.com830b8792012-08-01 15:57:52 +0000112 void setUserOffset(SkIPoint offset) {
113 fUserOffset = offset;
114 }
115
116 void setUserScale(float scale) {
117 fUserScale = scale;
118 }
119
chudy@google.com902ebe52012-06-29 14:21:22 +0000120////////////////////////////////////////////////////////////////////////////////
121// Inherited from SkCanvas
122////////////////////////////////////////////////////////////////////////////////
123
124 virtual void clear(SkColor) SK_OVERRIDE;
125
126 virtual bool clipPath(const SkPath&, SkRegion::Op, bool) SK_OVERRIDE;
127
128 virtual bool clipRect(const SkRect&, SkRegion::Op, bool) SK_OVERRIDE;
129
130 virtual bool clipRegion(const SkRegion& region, SkRegion::Op op) SK_OVERRIDE;
131
132 virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE;
133
134 virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top,
135 const SkPaint*) SK_OVERRIDE;
136
137 virtual void drawBitmapRect(const SkBitmap&, const SkIRect* src,
138 const SkRect& dst, const SkPaint*) SK_OVERRIDE;
139
140 virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&,
141 const SkPaint*) SK_OVERRIDE;
142
143 virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
144 const SkRect& dst, const SkPaint*) SK_OVERRIDE;
145
146 virtual void drawData(const void*, size_t) SK_OVERRIDE;
147
148 virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
149
150 virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE;
151
152 virtual void drawPicture(SkPicture& picture) SK_OVERRIDE;
153
154 virtual void drawPoints(PointMode, size_t count, const SkPoint pts[],
155 const SkPaint&) SK_OVERRIDE;
156
157 virtual void drawPosText(const void* text, size_t byteLength,
158 const SkPoint pos[], const SkPaint&) SK_OVERRIDE;
159
160 virtual void drawPosTextH(const void* text, size_t byteLength,
161 const SkScalar xpos[], SkScalar constY, const SkPaint&) SK_OVERRIDE;
162
163 virtual void drawRect(const SkRect& rect, const SkPaint&) SK_OVERRIDE;
164
165 virtual void drawSprite(const SkBitmap&, int left, int top,
166 const SkPaint*) SK_OVERRIDE;
167
168 virtual void drawText(const void* text, size_t byteLength, SkScalar x,
169 SkScalar y, const SkPaint&) SK_OVERRIDE;
170
171 virtual void drawTextOnPath(const void* text, size_t byteLength,
172 const SkPath& path, const SkMatrix* matrix,
173 const SkPaint&) SK_OVERRIDE;
174
175 virtual void drawVertices(VertexMode, int vertexCount,
176 const SkPoint vertices[], const SkPoint texs[],
177 const SkColor colors[], SkXfermode*,
178 const uint16_t indices[], int indexCount,
179 const SkPaint&) SK_OVERRIDE;
180
181 virtual void restore() SK_OVERRIDE;
182
183 virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
184
185 virtual int save(SaveFlags) SK_OVERRIDE;
186
187 virtual int saveLayer(const SkRect* bounds, const SkPaint*, SaveFlags) SK_OVERRIDE;
188
189 virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
190
191 virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE;
192
193 virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE;
194
195 virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
196
197private:
198 typedef SkCanvas INHERITED;
199 std::vector<SkDrawCommand*> commandVector;
200 std::vector<SkDrawCommand*>::const_iterator it;
chudy@google.comb9ddd4e2012-07-10 14:14:50 +0000201 int fHeight;
202 int fWidth;
chudy@google.com902ebe52012-06-29 14:21:22 +0000203 SkBitmap fBm;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000204 bool fFilter;
chudy@google.com830b8792012-08-01 15:57:52 +0000205 int fIndex;
206 SkIPoint fUserOffset;
207 float fUserScale;
chudy@google.coma9e937c2012-08-03 17:32:05 +0000208 SkMatrix fMatrix;
209 SkIRect fClip;
chudy@google.com902ebe52012-06-29 14:21:22 +0000210
211 /**
212 Adds the command to the classes vector of commands.
213 @param command The draw command for execution
214 */
215 void addDrawCommand(SkDrawCommand* command);
chudy@google.com830b8792012-08-01 15:57:52 +0000216
217 /**
218 Applies any panning and zooming the user has specified before
219 drawing anything else into the canvas.
220 */
221 void applyUserTransform(SkCanvas* canvas);
chudy@google.com902ebe52012-06-29 14:21:22 +0000222};
223
224#endif