3 * Copyright 2012 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
10 #ifndef SKDEBUGCANVAS_H_
11 #define SKDEBUGCANVAS_H_
14 #include "SkDrawCommand.h"
15 #include "SkPicture.h"
19 class SkTexOverrideFilter;
21 class SK_API SkDebugCanvas : public SkCanvas {
23 SkDebugCanvas(int width, int height);
24 virtual ~SkDebugCanvas();
26 void toggleFilter(bool toggle) { fFilter = toggle; }
28 void setMegaVizMode(bool megaVizMode) { fMegaVizMode = megaVizMode; }
29 bool getMegaVizMode() const { return fMegaVizMode; }
32 * Enable or disable overdraw visualization
34 void setOverdrawViz(bool overdrawViz) { fOverdrawViz = overdrawViz; }
35 bool getOverdrawViz() const { return fOverdrawViz; }
37 void setOutstandingSaveCount(int saveCount) { fOutstandingSaveCount = saveCount; }
38 int getOutstandingSaveCount() const { return fOutstandingSaveCount; }
40 void setPicture(SkPicture* picture) { fPicture = picture; }
43 * Enable or disable texure filtering override
45 void overrideTexFiltering(bool overrideTexFiltering, SkPaint::FilterLevel level);
48 Executes all draw calls to the canvas.
49 @param canvas The canvas being drawn to
51 void draw(SkCanvas* canvas);
54 Executes the draw calls up to the specified index.
55 @param canvas The canvas being drawn to
56 @param index The index of the final command being executed
58 void drawTo(SkCanvas* canvas, int index);
61 Returns the most recently calculated transformation matrix
63 const SkMatrix& getCurrentMatrix() {
68 Returns the most recently calculated clip
70 const SkIRect& getCurrentClip() {
75 Returns the index of the last draw command to write to the pixel at (x,y)
77 int getCommandAtPoint(int x, int y, int index);
80 Removes the command at the specified index
81 @param index The index of the command to delete
83 void deleteDrawCommandAt(int index);
86 Returns the draw command at the given index.
87 @param index The index of the command
89 SkDrawCommand* getDrawCommandAt(int index);
92 Sets the draw command for a given index.
93 @param index The index to overwrite
94 @param command The new command
96 void setDrawCommandAt(int index, SkDrawCommand* command);
99 Returns information about the command at the given index.
100 @param index The index of the command
102 SkTDArray<SkString*>* getCommandInfo(int index);
105 Returns the visibility of the command at the given index.
106 @param index The index of the command
108 bool getDrawCommandVisibilityAt(int index);
111 Returns the vector of draw commands
113 SK_ATTR_DEPRECATED("please use getDrawCommandAt and getSize instead")
114 const SkTDArray<SkDrawCommand*>& getDrawCommands() const;
117 Returns the vector of draw commands. Do not use this entry
118 point - it is going away!
120 SkTDArray<SkDrawCommand*>& getDrawCommands();
123 * Returns the string vector of draw commands
125 SkTArray<SkString>* getDrawCommandsAsStrings() const;
128 * Returns an array containing an offset (in the SkPicture) for each command
130 SkTDArray<size_t>* getDrawCommandOffsets() const;
133 Returns length of draw command vector.
135 int getSize() const {
136 return fCommandVector.count();
140 Toggles the visibility / execution of the draw command at index i with
143 void toggleCommand(int index, bool toggle);
145 void setBounds(int width, int height) {
150 void setUserMatrix(SkMatrix matrix) {
151 fUserMatrix = matrix;
154 ////////////////////////////////////////////////////////////////////////////////
155 // Inherited from SkCanvas
156 ////////////////////////////////////////////////////////////////////////////////
158 virtual void clear(SkColor) SK_OVERRIDE;
160 virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top,
161 const SkPaint*) SK_OVERRIDE;
163 virtual void drawBitmapRectToRect(const SkBitmap&, const SkRect* src,
164 const SkRect& dst, const SkPaint* paint,
165 DrawBitmapRectFlags flags) SK_OVERRIDE;
167 virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&,
168 const SkPaint*) SK_OVERRIDE;
170 virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
171 const SkRect& dst, const SkPaint*) SK_OVERRIDE;
173 virtual void drawData(const void*, size_t) SK_OVERRIDE;
175 virtual void beginCommentGroup(const char* description) SK_OVERRIDE;
177 virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE;
179 virtual void endCommentGroup() SK_OVERRIDE;
181 virtual void drawOval(const SkRect& oval, const SkPaint&) SK_OVERRIDE;
183 virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
185 virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE;
187 virtual void drawPicture(SkPicture& picture) SK_OVERRIDE;
189 virtual void drawPoints(PointMode, size_t count, const SkPoint pts[],
190 const SkPaint&) SK_OVERRIDE;
192 virtual void drawRect(const SkRect& rect, const SkPaint&) SK_OVERRIDE;
194 virtual void drawRRect(const SkRRect& rrect, const SkPaint& paint) SK_OVERRIDE;
196 virtual void drawSprite(const SkBitmap&, int left, int top,
197 const SkPaint*) SK_OVERRIDE;
199 virtual void drawVertices(VertexMode, int vertexCount,
200 const SkPoint vertices[], const SkPoint texs[],
201 const SkColor colors[], SkXfermode*,
202 const uint16_t indices[], int indexCount,
203 const SkPaint&) SK_OVERRIDE;
205 static const int kVizImageHeight = 256;
206 static const int kVizImageWidth = 256;
208 virtual bool isClipEmpty() const SK_OVERRIDE { return false; }
209 virtual bool isClipRect() const SK_OVERRIDE { return true; }
210 #ifdef SK_SUPPORT_LEGACY_GETCLIPTYPE
211 virtual ClipType getClipType() const SK_OVERRIDE {
212 return kRect_ClipType;
215 virtual bool getClipBounds(SkRect* bounds) const SK_OVERRIDE {
216 if (NULL != bounds) {
217 bounds->setXYWH(0, 0,
218 SkIntToScalar(this->imageInfo().fWidth),
219 SkIntToScalar(this->imageInfo().fHeight));
223 virtual bool getClipDeviceBounds(SkIRect* bounds) const SK_OVERRIDE {
224 if (NULL != bounds) {
225 bounds->setLargest();
231 virtual void willSave(SaveFlags) SK_OVERRIDE;
232 virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE;
233 virtual void willRestore() SK_OVERRIDE;
235 virtual void didConcat(const SkMatrix&) SK_OVERRIDE;
236 virtual void didSetMatrix(const SkMatrix&) SK_OVERRIDE;
238 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
239 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
240 const SkPaint&) SK_OVERRIDE;
241 virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
242 const SkPaint&) SK_OVERRIDE;
243 virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
244 SkScalar constY, const SkPaint&) SK_OVERRIDE;
245 virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
246 const SkMatrix* matrix, const SkPaint&) SK_OVERRIDE;
247 virtual void onPushCull(const SkRect& cullRect) SK_OVERRIDE;
248 virtual void onPopCull() SK_OVERRIDE;
250 virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
251 virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
252 virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
253 virtual void onClipRegion(const SkRegion& region, SkRegion::Op) SK_OVERRIDE;
255 void markActiveCommands(int index);
258 SkTDArray<SkDrawCommand*> fCommandVector;
265 SkMatrix fUserMatrix;
270 SkDrawFilter* fOverdrawFilter;
272 bool fOverrideTexFiltering;
273 SkTexOverrideFilter* fTexOverrideFilter;
276 Number of unmatched save() calls at any point during a draw.
277 If there are any saveLayer() calls outstanding, we need to resolve
278 all of them, which in practice means resolving all save() calls,
279 to avoid corruption of our canvas.
281 int fOutstandingSaveCount;
284 The active saveLayer commands at a given point in the renderering.
285 Only used when "mega" visualization is enabled.
287 SkTDArray<SkDrawCommand*> fActiveLayers;
290 The active cull commands at a given point in the rendering.
291 Only used when "mega" visualization is enabled.
293 SkTDArray<SkDrawCommand*> fActiveCulls;
296 Adds the command to the classes vector of commands.
297 @param command The draw command for execution
299 void addDrawCommand(SkDrawCommand* command);
302 Applies any panning and zooming the user has specified before
303 drawing anything else into the canvas.
305 void applyUserTransform(SkCanvas* canvas);
307 size_t getOpID() const {
308 if (NULL != fPicture) {
309 return fPicture->EXPERIMENTAL_curOpID();
314 typedef SkCanvas INHERITED;