blob: 373ef5df495d0e3bc84cd0347801e891ddb7a4b1 [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"
chudy@google.come606d6e2012-07-12 14:31:25 +000016#include "SkHitBox.h"
chudy@google.com902ebe52012-06-29 14:21:22 +000017#include <vector>
18
19class SkDebugCanvas : public SkCanvas {
20public:
chudy@google.com902ebe52012-06-29 14:21:22 +000021 SkDebugCanvas();
22 ~SkDebugCanvas();
23
24 void toggleFilter(bool toggle);
25
26 /**
27 Executes all draw calls to the canvas.
28 @param canvas The canvas being drawn to
29 */
30 void draw(SkCanvas* canvas);
31
32 /**
33 Executes the draw calls in the specified range.
34 @param canvas The canvas being drawn to
35 @param i The beginning of the range
36 @param j The end of the range
37 TODO(chudy): Implement
38 */
39 void drawRange(SkCanvas* canvas, int i, int j);
40
41 /**
42 Executes the draw calls up to the specified index.
43 @param canvas The canvas being drawn to
44 @param index The index of the final command being executed
45 */
chudy@google.come606d6e2012-07-12 14:31:25 +000046 void drawTo(SkCanvas* canvas, int index, SkBitmap* bitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +000047
48 /**
49 Returns the draw command at the given index.
50 @param index The index of the command
51 */
52 SkDrawCommand* getDrawCommandAt(int index);
53
54 /**
55 Returns information about the command at the given index.
56 @param index The index of the command
57 */
58 std::vector<std::string>* getCommandInfoAt(int index);
59
60 /**
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000061 Returns the visibility of the command at the given index.
62 @param index The index of the command
63 */
64 bool getDrawCommandVisibilityAt(int index);
65
66 /**
chudy@google.com902ebe52012-06-29 14:21:22 +000067 Returns the vector of draw commands
68 */
69 std::vector<SkDrawCommand*> getDrawCommands();
70
71 /**
72 * Returns the string vector of draw commands
73 */
74 std::vector<std::string>* getDrawCommandsAsStrings();
75
76 /**
chudy@google.come606d6e2012-07-12 14:31:25 +000077 Returns the mapping of all pixels to a layer value.
78 */
79 int* getHitBox() {
80 return fHitBox.getHitBox();
81 }
82
83 SkHitBox* getBoxClass() {
84 return &fHitBox;
85 }
86
87 int getHitBoxPoint() {
88 return fHitBox.getPoint();
89 }
90
91 /**
chudy@google.comf1414322012-07-03 20:28:14 +000092 Returns length of draw command vector.
93 */
94 int getSize() {
95 return commandVector.size();
96 }
97
chudy@google.come606d6e2012-07-12 14:31:25 +000098 void isCalculatingHits(bool isEnabled) {
99 fCalculateHits = isEnabled;
100 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000101
102 /**
103 Toggles the visibility / execution of the draw command at index i with
104 the value of toggle.
105 */
106 void toggleCommand(int index, bool toggle);
107
chudy@google.comb9ddd4e2012-07-10 14:14:50 +0000108 void setBounds(int width, int height) {
109 fWidth = width;
110 fHeight = height;
111 }
112
chudy@google.com902ebe52012-06-29 14:21:22 +0000113////////////////////////////////////////////////////////////////////////////////
114// Inherited from SkCanvas
115////////////////////////////////////////////////////////////////////////////////
116
117 virtual void clear(SkColor) SK_OVERRIDE;
118
119 virtual bool clipPath(const SkPath&, SkRegion::Op, bool) SK_OVERRIDE;
120
121 virtual bool clipRect(const SkRect&, SkRegion::Op, bool) SK_OVERRIDE;
122
123 virtual bool clipRegion(const SkRegion& region, SkRegion::Op op) SK_OVERRIDE;
124
125 virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE;
126
127 virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top,
128 const SkPaint*) SK_OVERRIDE;
129
130 virtual void drawBitmapRect(const SkBitmap&, const SkIRect* src,
131 const SkRect& dst, const SkPaint*) SK_OVERRIDE;
132
133 virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&,
134 const SkPaint*) SK_OVERRIDE;
135
136 virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
137 const SkRect& dst, const SkPaint*) SK_OVERRIDE;
138
139 virtual void drawData(const void*, size_t) SK_OVERRIDE;
140
141 virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
142
143 virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE;
144
145 virtual void drawPicture(SkPicture& picture) SK_OVERRIDE;
146
147 virtual void drawPoints(PointMode, size_t count, const SkPoint pts[],
148 const SkPaint&) SK_OVERRIDE;
149
150 virtual void drawPosText(const void* text, size_t byteLength,
151 const SkPoint pos[], const SkPaint&) SK_OVERRIDE;
152
153 virtual void drawPosTextH(const void* text, size_t byteLength,
154 const SkScalar xpos[], SkScalar constY, const SkPaint&) SK_OVERRIDE;
155
156 virtual void drawRect(const SkRect& rect, const SkPaint&) SK_OVERRIDE;
157
158 virtual void drawSprite(const SkBitmap&, int left, int top,
159 const SkPaint*) SK_OVERRIDE;
160
161 virtual void drawText(const void* text, size_t byteLength, SkScalar x,
162 SkScalar y, const SkPaint&) SK_OVERRIDE;
163
164 virtual void drawTextOnPath(const void* text, size_t byteLength,
165 const SkPath& path, const SkMatrix* matrix,
166 const SkPaint&) SK_OVERRIDE;
167
168 virtual void drawVertices(VertexMode, int vertexCount,
169 const SkPoint vertices[], const SkPoint texs[],
170 const SkColor colors[], SkXfermode*,
171 const uint16_t indices[], int indexCount,
172 const SkPaint&) SK_OVERRIDE;
173
174 virtual void restore() SK_OVERRIDE;
175
176 virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
177
178 virtual int save(SaveFlags) SK_OVERRIDE;
179
180 virtual int saveLayer(const SkRect* bounds, const SkPaint*, SaveFlags) SK_OVERRIDE;
181
182 virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
183
184 virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE;
185
186 virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE;
187
188 virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
189
190private:
191 typedef SkCanvas INHERITED;
192 std::vector<SkDrawCommand*> commandVector;
193 std::vector<SkDrawCommand*>::const_iterator it;
chudy@google.comb9ddd4e2012-07-10 14:14:50 +0000194 int fHeight;
195 int fWidth;
chudy@google.com902ebe52012-06-29 14:21:22 +0000196 SkBitmap fBm;
chudy@google.come606d6e2012-07-12 14:31:25 +0000197 SkHitBox fHitBox;
198 bool fCalculateHits;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000199 bool fFilter;
chudy@google.com902ebe52012-06-29 14:21:22 +0000200
201 /**
202 Adds the command to the classes vector of commands.
203 @param command The draw command for execution
204 */
205 void addDrawCommand(SkDrawCommand* command);
206};
207
208#endif