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 "SkPathOps.h"
16 #include "SkPicture.h"
20 class SkTexOverrideFilter;
22 class SK_API SkDebugCanvas : public SkCanvas {
24 SkDebugCanvas(int width, int height);
25 virtual ~SkDebugCanvas();
27 void toggleFilter(bool toggle) { fFilter = toggle; }
29 void setMegaVizMode(bool megaVizMode) { fMegaVizMode = megaVizMode; }
30 bool getMegaVizMode() const { return fMegaVizMode; }
33 * Enable or disable overdraw visualization
35 void setOverdrawViz(bool overdrawViz) { fOverdrawViz = overdrawViz; }
36 bool getOverdrawViz() const { return fOverdrawViz; }
38 void setOutstandingSaveCount(int saveCount) { fOutstandingSaveCount = saveCount; }
39 int getOutstandingSaveCount() const { return fOutstandingSaveCount; }
41 bool getAllowSimplifyClip() const { return fAllowSimplifyClip; }
43 void setPicture(SkPicture* picture) { fPicture = picture; }
46 * Enable or disable texure filtering override
48 void overrideTexFiltering(bool overrideTexFiltering, SkPaint::FilterLevel level);
51 Executes all draw calls to the canvas.
52 @param canvas The canvas being drawn to
54 void draw(SkCanvas* canvas);
57 Executes the draw calls up to the specified index.
58 @param canvas The canvas being drawn to
59 @param index The index of the final command being executed
61 void drawTo(SkCanvas* canvas, int index);
64 Returns the most recently calculated transformation matrix
66 const SkMatrix& getCurrentMatrix() {
71 Returns the most recently calculated clip
73 const SkIRect& getCurrentClip() {
78 Returns the index of the last draw command to write to the pixel at (x,y)
80 int getCommandAtPoint(int x, int y, int index);
83 Removes the command at the specified index
84 @param index The index of the command to delete
86 void deleteDrawCommandAt(int index);
89 Returns the draw command at the given index.
90 @param index The index of the command
92 SkDrawCommand* getDrawCommandAt(int index);
95 Sets the draw command for a given index.
96 @param index The index to overwrite
97 @param command The new command
99 void setDrawCommandAt(int index, SkDrawCommand* command);
102 Returns information about the command at the given index.
103 @param index The index of the command
105 SkTDArray<SkString*>* getCommandInfo(int index);
108 Returns the visibility of the command at the given index.
109 @param index The index of the command
111 bool getDrawCommandVisibilityAt(int index);
114 Returns the vector of draw commands
116 SK_ATTR_DEPRECATED("please use getDrawCommandAt and getSize instead")
117 const SkTDArray<SkDrawCommand*>& getDrawCommands() const;
120 Returns the vector of draw commands. Do not use this entry
121 point - it is going away!
123 SkTDArray<SkDrawCommand*>& getDrawCommands();
126 * Returns the string vector of draw commands
128 SkTArray<SkString>* getDrawCommandsAsStrings() const;
131 * Returns an array containing an offset (in the SkPicture) for each command
133 SkTDArray<size_t>* getDrawCommandOffsets() const;
136 Returns length of draw command vector.
138 int getSize() const {
139 return fCommandVector.count();
143 Toggles the visibility / execution of the draw command at index i with
146 void toggleCommand(int index, bool toggle);
148 void setBounds(int width, int height) {
153 void setUserMatrix(SkMatrix matrix) {
154 fUserMatrix = matrix;
157 SkString clipStackData() const { return fClipStackData; }
159 ////////////////////////////////////////////////////////////////////////////////
160 // Inherited from SkCanvas
161 ////////////////////////////////////////////////////////////////////////////////
163 virtual void clear(SkColor) SK_OVERRIDE;
165 virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top,
166 const SkPaint*) SK_OVERRIDE;
168 virtual void drawBitmapRectToRect(const SkBitmap&, const SkRect* src,
169 const SkRect& dst, const SkPaint* paint,
170 DrawBitmapRectFlags flags) SK_OVERRIDE;
172 virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&,
173 const SkPaint*) SK_OVERRIDE;
175 virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
176 const SkRect& dst, const SkPaint*) SK_OVERRIDE;
178 virtual void drawData(const void*, size_t) SK_OVERRIDE;
180 virtual void beginCommentGroup(const char* description) SK_OVERRIDE;
182 virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE;
184 virtual void endCommentGroup() SK_OVERRIDE;
186 virtual void drawOval(const SkRect& oval, const SkPaint&) SK_OVERRIDE;
188 virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
190 virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE;
192 virtual void drawPoints(PointMode, size_t count, const SkPoint pts[],
193 const SkPaint&) SK_OVERRIDE;
195 virtual void drawRect(const SkRect& rect, const SkPaint&) SK_OVERRIDE;
197 virtual void drawRRect(const SkRRect& rrect, const SkPaint& paint) SK_OVERRIDE;
199 virtual void drawSprite(const SkBitmap&, int left, int top,
200 const SkPaint*) SK_OVERRIDE;
202 virtual void drawVertices(VertexMode, int vertexCount,
203 const SkPoint vertices[], const SkPoint texs[],
204 const SkColor colors[], SkXfermode*,
205 const uint16_t indices[], int indexCount,
206 const SkPaint&) SK_OVERRIDE;
208 static const int kVizImageHeight = 256;
209 static const int kVizImageWidth = 256;
211 virtual bool isClipEmpty() const SK_OVERRIDE { return false; }
212 virtual bool isClipRect() const SK_OVERRIDE { return true; }
213 #ifdef SK_SUPPORT_LEGACY_GETCLIPTYPE
214 virtual ClipType getClipType() const SK_OVERRIDE {
215 return kRect_ClipType;
218 virtual bool getClipBounds(SkRect* bounds) const SK_OVERRIDE {
219 if (NULL != bounds) {
220 bounds->setXYWH(0, 0,
221 SkIntToScalar(this->imageInfo().fWidth),
222 SkIntToScalar(this->imageInfo().fHeight));
226 virtual bool getClipDeviceBounds(SkIRect* bounds) const SK_OVERRIDE {
227 if (NULL != bounds) {
228 bounds->setLargest();
234 virtual void willSave() SK_OVERRIDE;
235 virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE;
236 virtual void willRestore() SK_OVERRIDE;
238 virtual void didConcat(const SkMatrix&) SK_OVERRIDE;
239 virtual void didSetMatrix(const SkMatrix&) SK_OVERRIDE;
241 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
242 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
243 const SkPaint&) SK_OVERRIDE;
244 virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
245 const SkPaint&) SK_OVERRIDE;
246 virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
247 SkScalar constY, const SkPaint&) SK_OVERRIDE;
248 virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
249 const SkMatrix* matrix, const SkPaint&) SK_OVERRIDE;
250 virtual void onPushCull(const SkRect& cullRect) SK_OVERRIDE;
251 virtual void onPopCull() SK_OVERRIDE;
253 virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
254 virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
255 virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
256 virtual void onClipRegion(const SkRegion& region, SkRegion::Op) SK_OVERRIDE;
258 virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) SK_OVERRIDE;
260 void markActiveCommands(int index);
263 SkTDArray<SkDrawCommand*> fCommandVector;
270 SkMatrix fUserMatrix;
274 SkString fClipStackData;
275 bool fCalledAddStackData;
279 SkDrawFilter* fOverdrawFilter;
281 bool fOverrideTexFiltering;
282 SkTexOverrideFilter* fTexOverrideFilter;
285 Number of unmatched save() calls at any point during a draw.
286 If there are any saveLayer() calls outstanding, we need to resolve
287 all of them, which in practice means resolving all save() calls,
288 to avoid corruption of our canvas.
290 int fOutstandingSaveCount;
293 The active saveLayer commands at a given point in the renderering.
294 Only used when "mega" visualization is enabled.
296 SkTDArray<SkDrawCommand*> fActiveLayers;
299 The active cull commands at a given point in the rendering.
300 Only used when "mega" visualization is enabled.
302 SkTDArray<SkDrawCommand*> fActiveCulls;
305 Adds the command to the classes vector of commands.
306 @param command The draw command for execution
308 void addDrawCommand(SkDrawCommand* command);
311 Applies any panning and zooming the user has specified before
312 drawing anything else into the canvas.
314 void applyUserTransform(SkCanvas* canvas);
316 size_t getOpID() const {
318 if (NULL != fPicture) {
319 return fPicture->EXPERIMENTAL_curOpID();
325 void resetClipStackData() { fClipStackData.reset(); fCalledAddStackData = false; }
327 void addClipStackData(const SkPath& devPath, const SkPath& operand, SkRegion::Op elementOp);
328 void addPathData(const SkPath& path, const char* pathName);
329 bool lastClipStackData(const SkPath& devPath);
330 void outputConicPoints(const SkPoint* pts, SkScalar weight);
331 void outputPoints(const SkPoint* pts, int count);
332 void outputPointsCommon(const SkPoint* pts, int count);
333 void outputScalar(SkScalar num);
335 typedef SkCanvas INHERITED;