blob: 94316d5f59f1928741316efe4696078147649427 [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"
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +000016#include "SkTArray.h"
chudy@google.com97cee972012-08-07 20:41:37 +000017#include "SkString.h"
chudy@google.com902ebe52012-06-29 14:21:22 +000018
robertphillips@google.com32bbcf82013-10-17 17:56:10 +000019class SkTexOverrideFilter;
20
fmalita@google.com86681b32013-06-13 20:59:14 +000021class SK_API SkDebugCanvas : public SkCanvas {
chudy@google.com902ebe52012-06-29 14:21:22 +000022public:
chudy@google.com80a4a602012-07-30 18:54:07 +000023 SkDebugCanvas(int width, int height);
robertphillips@google.comf4741c12013-02-06 20:13:54 +000024 virtual ~SkDebugCanvas();
chudy@google.com902ebe52012-06-29 14:21:22 +000025
26 void toggleFilter(bool toggle);
27
28 /**
robertphillips@google.comf4741c12013-02-06 20:13:54 +000029 * Enable or disable overdraw visualization
30 */
31 void setOverdrawViz(bool overdrawViz) { fOverdrawViz = overdrawViz; }
32
33 /**
robertphillips@google.com32bbcf82013-10-17 17:56:10 +000034 * Enable or disable texure filtering override
35 */
skia.committer@gmail.comf84ad8f2013-10-18 07:01:59 +000036 void overrideTexFiltering(bool overrideTexFiltering, SkPaint::FilterLevel level);
robertphillips@google.com32bbcf82013-10-17 17:56:10 +000037
38 /**
chudy@google.com902ebe52012-06-29 14:21:22 +000039 Executes all draw calls to the canvas.
40 @param canvas The canvas being drawn to
41 */
42 void draw(SkCanvas* canvas);
43
44 /**
chudy@google.com902ebe52012-06-29 14:21:22 +000045 Executes the draw calls up to the specified index.
46 @param canvas The canvas being drawn to
47 @param index The index of the final command being executed
48 */
chudy@google.com0b5bbb02012-07-31 19:55:32 +000049 void drawTo(SkCanvas* canvas, int index);
50
51 /**
chudy@google.coma9e937c2012-08-03 17:32:05 +000052 Returns the most recently calculated transformation matrix
53 */
54 const SkMatrix& getCurrentMatrix() {
55 return fMatrix;
56 }
57
58 /**
59 Returns the most recently calculated clip
60 */
61 const SkIRect& getCurrentClip() {
62 return fClip;
63 }
64
65 /**
chudy@google.com0b5bbb02012-07-31 19:55:32 +000066 Returns the index of the last draw command to write to the pixel at (x,y)
67 */
chudy@google.com830b8792012-08-01 15:57:52 +000068 int getCommandAtPoint(int x, int y, int index);
chudy@google.com902ebe52012-06-29 14:21:22 +000069
70 /**
robertphillips@google.com50c84da2013-04-01 18:18:49 +000071 Removes the command at the specified index
72 @param index The index of the command to delete
73 */
74 void deleteDrawCommandAt(int index);
75
76 /**
chudy@google.com902ebe52012-06-29 14:21:22 +000077 Returns the draw command at the given index.
78 @param index The index of the command
79 */
80 SkDrawCommand* getDrawCommandAt(int index);
81
82 /**
robertphillips@google.com50c84da2013-04-01 18:18:49 +000083 Sets the draw command for a given index.
84 @param index The index to overwrite
85 @param command The new command
86 */
87 void setDrawCommandAt(int index, SkDrawCommand* command);
88
89 /**
chudy@google.com902ebe52012-06-29 14:21:22 +000090 Returns information about the command at the given index.
91 @param index The index of the command
92 */
chudy@google.com97cee972012-08-07 20:41:37 +000093 SkTDArray<SkString*>* getCommandInfo(int index);
chudy@google.com902ebe52012-06-29 14:21:22 +000094
95 /**
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000096 Returns the visibility of the command at the given index.
97 @param index The index of the command
98 */
99 bool getDrawCommandVisibilityAt(int index);
100
101 /**
chudy@google.com902ebe52012-06-29 14:21:22 +0000102 Returns the vector of draw commands
103 */
reed@google.com44699382013-10-31 17:28:30 +0000104 SK_ATTR_DEPRECATED("please use getDrawCommandAt and getSize instead")
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000105 const SkTDArray<SkDrawCommand*>& getDrawCommands() const;
skia.committer@gmail.com2e71f162013-03-12 07:12:32 +0000106
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000107 /**
108 Returns the vector of draw commands. Do not use this entry
109 point - it is going away!
110 */
111 SkTDArray<SkDrawCommand*>& getDrawCommands();
chudy@google.com902ebe52012-06-29 14:21:22 +0000112
113 /**
114 * Returns the string vector of draw commands
115 */
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000116 SkTArray<SkString>* getDrawCommandsAsStrings() const;
chudy@google.com902ebe52012-06-29 14:21:22 +0000117
118 /**
chudy@google.comf1414322012-07-03 20:28:14 +0000119 Returns length of draw command vector.
120 */
commit-bot@chromium.org0d4fe142013-07-15 22:47:14 +0000121 int getSize() const {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000122 return fCommandVector.count();
chudy@google.comf1414322012-07-03 20:28:14 +0000123 }
124
chudy@google.com902ebe52012-06-29 14:21:22 +0000125 /**
126 Toggles the visibility / execution of the draw command at index i with
127 the value of toggle.
128 */
129 void toggleCommand(int index, bool toggle);
130
chudy@google.comb9ddd4e2012-07-10 14:14:50 +0000131 void setBounds(int width, int height) {
132 fWidth = width;
133 fHeight = height;
134 }
135
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000136 void setUserMatrix(SkMatrix matrix) {
137 fUserMatrix = matrix;
chudy@google.com830b8792012-08-01 15:57:52 +0000138 }
139
chudy@google.com902ebe52012-06-29 14:21:22 +0000140////////////////////////////////////////////////////////////////////////////////
141// Inherited from SkCanvas
142////////////////////////////////////////////////////////////////////////////////
143
144 virtual void clear(SkColor) SK_OVERRIDE;
145
146 virtual bool clipPath(const SkPath&, SkRegion::Op, bool) SK_OVERRIDE;
147
148 virtual bool clipRect(const SkRect&, SkRegion::Op, bool) SK_OVERRIDE;
149
robertphillips@google.com67baba42013-01-02 20:20:31 +0000150 virtual bool clipRRect(const SkRRect& rrect,
151 SkRegion::Op op = SkRegion::kIntersect_Op,
152 bool doAntiAlias = false) SK_OVERRIDE;
153
chudy@google.com902ebe52012-06-29 14:21:22 +0000154 virtual bool clipRegion(const SkRegion& region, SkRegion::Op op) SK_OVERRIDE;
155
156 virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE;
157
158 virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top,
159 const SkPaint*) SK_OVERRIDE;
160
reed@google.com71121732012-09-18 15:14:33 +0000161 virtual void drawBitmapRectToRect(const SkBitmap&, const SkRect* src,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000162 const SkRect& dst, const SkPaint* paint,
163 DrawBitmapRectFlags flags) SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000164
165 virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&,
166 const SkPaint*) SK_OVERRIDE;
167
168 virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
169 const SkRect& dst, const SkPaint*) SK_OVERRIDE;
170
171 virtual void drawData(const void*, size_t) SK_OVERRIDE;
172
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000173 virtual void beginCommentGroup(const char* description) SK_OVERRIDE;
174
175 virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE;
176
177 virtual void endCommentGroup() SK_OVERRIDE;
178
robertphillips@google.com67baba42013-01-02 20:20:31 +0000179 virtual void drawOval(const SkRect& oval, const SkPaint&) SK_OVERRIDE;
180
chudy@google.com902ebe52012-06-29 14:21:22 +0000181 virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
182
bsalomon@google.com7ce564c2013-10-22 16:54:15 +0000183 virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE;
184
chudy@google.com902ebe52012-06-29 14:21:22 +0000185 virtual void drawPicture(SkPicture& picture) SK_OVERRIDE;
186
187 virtual void drawPoints(PointMode, size_t count, const SkPoint pts[],
188 const SkPaint&) SK_OVERRIDE;
189
190 virtual void drawPosText(const void* text, size_t byteLength,
191 const SkPoint pos[], const SkPaint&) SK_OVERRIDE;
192
193 virtual void drawPosTextH(const void* text, size_t byteLength,
skia.committer@gmail.com422188f2013-01-03 02:01:32 +0000194 const SkScalar xpos[], SkScalar constY,
robertphillips@google.com67baba42013-01-02 20:20:31 +0000195 const SkPaint&) SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000196
bsalomon@google.com7ce564c2013-10-22 16:54:15 +0000197 virtual void drawRect(const SkRect& rect, const SkPaint&) SK_OVERRIDE;
198
robertphillips@google.com67baba42013-01-02 20:20:31 +0000199 virtual void drawRRect(const SkRRect& rrect, const SkPaint& paint) SK_OVERRIDE;
200
chudy@google.com902ebe52012-06-29 14:21:22 +0000201 virtual void drawSprite(const SkBitmap&, int left, int top,
202 const SkPaint*) SK_OVERRIDE;
203
204 virtual void drawText(const void* text, size_t byteLength, SkScalar x,
205 SkScalar y, const SkPaint&) SK_OVERRIDE;
206
207 virtual void drawTextOnPath(const void* text, size_t byteLength,
robertphillips@google.com67baba42013-01-02 20:20:31 +0000208 const SkPath& path, const SkMatrix* matrix,
chudy@google.com902ebe52012-06-29 14:21:22 +0000209 const SkPaint&) SK_OVERRIDE;
210
211 virtual void drawVertices(VertexMode, int vertexCount,
robertphillips@google.com67baba42013-01-02 20:20:31 +0000212 const SkPoint vertices[], const SkPoint texs[],
213 const SkColor colors[], SkXfermode*,
214 const uint16_t indices[], int indexCount,
chudy@google.com902ebe52012-06-29 14:21:22 +0000215 const SkPaint&) SK_OVERRIDE;
216
217 virtual void restore() SK_OVERRIDE;
218
219 virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
220
221 virtual int save(SaveFlags) SK_OVERRIDE;
222
223 virtual int saveLayer(const SkRect* bounds, const SkPaint*, SaveFlags) SK_OVERRIDE;
224
225 virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
226
227 virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE;
228
229 virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE;
230
231 virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
232
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000233 static const int kVizImageHeight = 256;
234 static const int kVizImageWidth = 256;
235
commit-bot@chromium.orgab582732014-02-21 12:20:45 +0000236protected:
237 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
238
chudy@google.com902ebe52012-06-29 14:21:22 +0000239private:
robertphillips@google.com67baba42013-01-02 20:20:31 +0000240 SkTDArray<SkDrawCommand*> fCommandVector;
chudy@google.comb9ddd4e2012-07-10 14:14:50 +0000241 int fWidth;
commit-bot@chromium.org1735d662013-12-04 13:42:46 +0000242 int fHeight;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000243 bool fFilter;
chudy@google.com830b8792012-08-01 15:57:52 +0000244 int fIndex;
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000245 SkMatrix fUserMatrix;
chudy@google.coma9e937c2012-08-03 17:32:05 +0000246 SkMatrix fMatrix;
247 SkIRect fClip;
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000248
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000249 bool fOverdrawViz;
250 SkDrawFilter* fOverdrawFilter;
chudy@google.com902ebe52012-06-29 14:21:22 +0000251
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000252 bool fOverrideTexFiltering;
253 SkTexOverrideFilter* fTexOverrideFilter;
254
chudy@google.com902ebe52012-06-29 14:21:22 +0000255 /**
tomhudson@google.com0699e022012-11-27 16:09:42 +0000256 Number of unmatched save() calls at any point during a draw.
257 If there are any saveLayer() calls outstanding, we need to resolve
258 all of them, which in practice means resolving all save() calls,
259 to avoid corruption of our canvas.
260 */
261 int fOutstandingSaveCount;
262
263 /**
chudy@google.com902ebe52012-06-29 14:21:22 +0000264 Adds the command to the classes vector of commands.
265 @param command The draw command for execution
266 */
267 void addDrawCommand(SkDrawCommand* command);
chudy@google.com830b8792012-08-01 15:57:52 +0000268
269 /**
270 Applies any panning and zooming the user has specified before
271 drawing anything else into the canvas.
272 */
273 void applyUserTransform(SkCanvas* canvas);
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000274
275 typedef SkCanvas INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000276};
277
278#endif