blob: a6afec38757aa5e679639715481e495bc239a193 [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
19class SkDebugCanvas : public SkCanvas {
20public:
chudy@google.com80a4a602012-07-30 18:54:07 +000021 SkDebugCanvas(int width, int height);
robertphillips@google.comf4741c12013-02-06 20:13:54 +000022 virtual ~SkDebugCanvas();
chudy@google.com902ebe52012-06-29 14:21:22 +000023
24 void toggleFilter(bool toggle);
25
26 /**
robertphillips@google.comf4741c12013-02-06 20:13:54 +000027 * Enable or disable overdraw visualization
28 */
29 void setOverdrawViz(bool overdrawViz) { fOverdrawViz = overdrawViz; }
30
31 /**
chudy@google.com902ebe52012-06-29 14:21:22 +000032 Executes all draw calls to the canvas.
33 @param canvas The canvas being drawn to
34 */
35 void draw(SkCanvas* canvas);
36
37 /**
38 Executes the draw calls in the specified range.
39 @param canvas The canvas being drawn to
40 @param i The beginning of the range
41 @param j The end of the range
42 TODO(chudy): Implement
43 */
44 void drawRange(SkCanvas* canvas, int i, int j);
45
46 /**
47 Executes the draw calls up to the specified index.
48 @param canvas The canvas being drawn to
49 @param index The index of the final command being executed
50 */
chudy@google.com0b5bbb02012-07-31 19:55:32 +000051 void drawTo(SkCanvas* canvas, int index);
52
53 /**
chudy@google.coma9e937c2012-08-03 17:32:05 +000054 Returns the most recently calculated transformation matrix
55 */
56 const SkMatrix& getCurrentMatrix() {
57 return fMatrix;
58 }
59
60 /**
61 Returns the most recently calculated clip
62 */
63 const SkIRect& getCurrentClip() {
64 return fClip;
65 }
66
67 /**
chudy@google.com0b5bbb02012-07-31 19:55:32 +000068 Returns the index of the last draw command to write to the pixel at (x,y)
69 */
chudy@google.com830b8792012-08-01 15:57:52 +000070 int getCommandAtPoint(int x, int y, int index);
chudy@google.com902ebe52012-06-29 14:21:22 +000071
72 /**
73 Returns the draw command at the given index.
74 @param index The index of the command
75 */
76 SkDrawCommand* getDrawCommandAt(int index);
77
78 /**
79 Returns information about the command at the given index.
80 @param index The index of the command
81 */
chudy@google.com97cee972012-08-07 20:41:37 +000082 SkTDArray<SkString*>* getCommandInfo(int index);
chudy@google.com902ebe52012-06-29 14:21:22 +000083
84 /**
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000085 Returns the visibility of the command at the given index.
86 @param index The index of the command
87 */
88 bool getDrawCommandVisibilityAt(int index);
89
90 /**
chudy@google.com902ebe52012-06-29 14:21:22 +000091 Returns the vector of draw commands
92 */
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +000093 const SkTDArray<SkDrawCommand*>& getDrawCommands() const;
skia.committer@gmail.com2e71f162013-03-12 07:12:32 +000094
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +000095 /**
96 Returns the vector of draw commands. Do not use this entry
97 point - it is going away!
98 */
99 SkTDArray<SkDrawCommand*>& getDrawCommands();
chudy@google.com902ebe52012-06-29 14:21:22 +0000100
101 /**
102 * Returns the string vector of draw commands
103 */
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000104 SkTArray<SkString>* getDrawCommandsAsStrings() const;
chudy@google.com902ebe52012-06-29 14:21:22 +0000105
106 /**
chudy@google.comf1414322012-07-03 20:28:14 +0000107 Returns length of draw command vector.
108 */
109 int getSize() {
robertphillips@google.com67baba42013-01-02 20:20:31 +0000110 return fCommandVector.count();
chudy@google.comf1414322012-07-03 20:28:14 +0000111 }
112
chudy@google.com902ebe52012-06-29 14:21:22 +0000113 /**
114 Toggles the visibility / execution of the draw command at index i with
115 the value of toggle.
116 */
117 void toggleCommand(int index, bool toggle);
118
chudy@google.comb9ddd4e2012-07-10 14:14:50 +0000119 void setBounds(int width, int height) {
120 fWidth = width;
121 fHeight = height;
122 }
123
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000124 void setUserMatrix(SkMatrix matrix) {
125 fUserMatrix = matrix;
chudy@google.com830b8792012-08-01 15:57:52 +0000126 }
127
chudy@google.com902ebe52012-06-29 14:21:22 +0000128////////////////////////////////////////////////////////////////////////////////
129// Inherited from SkCanvas
130////////////////////////////////////////////////////////////////////////////////
131
132 virtual void clear(SkColor) SK_OVERRIDE;
133
134 virtual bool clipPath(const SkPath&, SkRegion::Op, bool) SK_OVERRIDE;
135
136 virtual bool clipRect(const SkRect&, SkRegion::Op, bool) SK_OVERRIDE;
137
robertphillips@google.com67baba42013-01-02 20:20:31 +0000138 virtual bool clipRRect(const SkRRect& rrect,
139 SkRegion::Op op = SkRegion::kIntersect_Op,
140 bool doAntiAlias = false) SK_OVERRIDE;
141
chudy@google.com902ebe52012-06-29 14:21:22 +0000142 virtual bool clipRegion(const SkRegion& region, SkRegion::Op op) SK_OVERRIDE;
143
144 virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE;
145
146 virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top,
147 const SkPaint*) SK_OVERRIDE;
148
reed@google.com71121732012-09-18 15:14:33 +0000149 virtual void drawBitmapRectToRect(const SkBitmap&, const SkRect* src,
150 const SkRect& dst, const SkPaint*) SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000151
152 virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&,
153 const SkPaint*) SK_OVERRIDE;
154
155 virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
156 const SkRect& dst, const SkPaint*) SK_OVERRIDE;
157
158 virtual void drawData(const void*, size_t) SK_OVERRIDE;
159
robertphillips@google.com67baba42013-01-02 20:20:31 +0000160 virtual void drawOval(const SkRect& oval, const SkPaint&) SK_OVERRIDE;
161
chudy@google.com902ebe52012-06-29 14:21:22 +0000162 virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
163
164 virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE;
165
166 virtual void drawPicture(SkPicture& picture) SK_OVERRIDE;
167
168 virtual void drawPoints(PointMode, size_t count, const SkPoint pts[],
169 const SkPaint&) SK_OVERRIDE;
170
171 virtual void drawPosText(const void* text, size_t byteLength,
172 const SkPoint pos[], const SkPaint&) SK_OVERRIDE;
173
174 virtual void drawPosTextH(const void* text, size_t byteLength,
skia.committer@gmail.com422188f2013-01-03 02:01:32 +0000175 const SkScalar xpos[], SkScalar constY,
robertphillips@google.com67baba42013-01-02 20:20:31 +0000176 const SkPaint&) SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000177
178 virtual void drawRect(const SkRect& rect, const SkPaint&) SK_OVERRIDE;
179
robertphillips@google.com67baba42013-01-02 20:20:31 +0000180 virtual void drawRRect(const SkRRect& rrect, const SkPaint& paint) SK_OVERRIDE;
181
chudy@google.com902ebe52012-06-29 14:21:22 +0000182 virtual void drawSprite(const SkBitmap&, int left, int top,
183 const SkPaint*) SK_OVERRIDE;
184
185 virtual void drawText(const void* text, size_t byteLength, SkScalar x,
186 SkScalar y, const SkPaint&) SK_OVERRIDE;
187
188 virtual void drawTextOnPath(const void* text, size_t byteLength,
robertphillips@google.com67baba42013-01-02 20:20:31 +0000189 const SkPath& path, const SkMatrix* matrix,
chudy@google.com902ebe52012-06-29 14:21:22 +0000190 const SkPaint&) SK_OVERRIDE;
191
192 virtual void drawVertices(VertexMode, int vertexCount,
robertphillips@google.com67baba42013-01-02 20:20:31 +0000193 const SkPoint vertices[], const SkPoint texs[],
194 const SkColor colors[], SkXfermode*,
195 const uint16_t indices[], int indexCount,
chudy@google.com902ebe52012-06-29 14:21:22 +0000196 const SkPaint&) SK_OVERRIDE;
197
198 virtual void restore() SK_OVERRIDE;
199
200 virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
201
202 virtual int save(SaveFlags) SK_OVERRIDE;
203
204 virtual int saveLayer(const SkRect* bounds, const SkPaint*, SaveFlags) SK_OVERRIDE;
205
206 virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
207
208 virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE;
209
210 virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE;
211
212 virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
213
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000214 static const int kVizImageHeight = 256;
215 static const int kVizImageWidth = 256;
216
chudy@google.com902ebe52012-06-29 14:21:22 +0000217private:
robertphillips@google.com67baba42013-01-02 20:20:31 +0000218 SkTDArray<SkDrawCommand*> fCommandVector;
chudy@google.comb9ddd4e2012-07-10 14:14:50 +0000219 int fHeight;
220 int fWidth;
chudy@google.com902ebe52012-06-29 14:21:22 +0000221 SkBitmap fBm;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000222 bool fFilter;
chudy@google.com830b8792012-08-01 15:57:52 +0000223 int fIndex;
bungeman@google.come8cc6e82013-01-17 16:30:56 +0000224 SkMatrix fUserMatrix;
chudy@google.coma9e937c2012-08-03 17:32:05 +0000225 SkMatrix fMatrix;
226 SkIRect fClip;
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000227 bool fOverdrawViz;
228 SkDrawFilter* fOverdrawFilter;
chudy@google.com902ebe52012-06-29 14:21:22 +0000229
230 /**
tomhudson@google.com0699e022012-11-27 16:09:42 +0000231 Number of unmatched save() calls at any point during a draw.
232 If there are any saveLayer() calls outstanding, we need to resolve
233 all of them, which in practice means resolving all save() calls,
234 to avoid corruption of our canvas.
235 */
236 int fOutstandingSaveCount;
237
238 /**
chudy@google.com902ebe52012-06-29 14:21:22 +0000239 Adds the command to the classes vector of commands.
240 @param command The draw command for execution
241 */
242 void addDrawCommand(SkDrawCommand* command);
chudy@google.com830b8792012-08-01 15:57:52 +0000243
244 /**
245 Applies any panning and zooming the user has specified before
246 drawing anything else into the canvas.
247 */
248 void applyUserTransform(SkCanvas* canvas);
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000249
250 typedef SkCanvas INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000251};
252
253#endif