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 bool getAllowSimplifyClip() const { return fAllowSimplifyClip; }
40 void setPicture(SkPicture* picture) { fPicture = picture; }
43 * Enable or disable texure filtering override
45 void overrideTexFiltering(bool overrideTexFiltering, SkFilterQuality);
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 const SkTDArray<SkString*>* getCommandInfo(int index) const;
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 length of draw command vector.
125 int getSize() const {
126 return fCommandVector.count();
130 Toggles the visibility / execution of the draw command at index i with
133 void toggleCommand(int index, bool toggle);
135 void setUserMatrix(SkMatrix matrix) {
136 fUserMatrix = matrix;
139 SkString clipStackData() const { return fClipStackData; }
141 ////////////////////////////////////////////////////////////////////////////////
142 // Inherited from SkCanvas
143 ////////////////////////////////////////////////////////////////////////////////
145 void beginCommentGroup(const char* description) SK_OVERRIDE;
146 void addComment(const char* kywd, const char* value) SK_OVERRIDE;
147 void endCommentGroup() SK_OVERRIDE;
149 static const int kVizImageHeight = 256;
150 static const int kVizImageWidth = 256;
152 bool isClipEmpty() const SK_OVERRIDE { return false; }
153 bool isClipRect() const SK_OVERRIDE { return true; }
154 bool getClipBounds(SkRect* bounds) const SK_OVERRIDE {
156 bounds->setXYWH(0, 0,
157 SkIntToScalar(this->imageInfo().width()),
158 SkIntToScalar(this->imageInfo().height()));
162 bool getClipDeviceBounds(SkIRect* bounds) const SK_OVERRIDE {
164 bounds->setLargest();
170 void willSave() SK_OVERRIDE;
171 SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE;
172 void willRestore() SK_OVERRIDE;
174 void didConcat(const SkMatrix&) SK_OVERRIDE;
175 void didSetMatrix(const SkMatrix&) SK_OVERRIDE;
177 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
178 void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
179 const SkPaint&) SK_OVERRIDE;
180 void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
181 const SkPaint&) SK_OVERRIDE;
182 void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
183 SkScalar constY, const SkPaint&) SK_OVERRIDE;
184 void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
185 const SkMatrix* matrix, const SkPaint&) SK_OVERRIDE;
186 void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
187 const SkPaint& paint) SK_OVERRIDE;
189 void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
190 const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint);
191 void onDrawPaint(const SkPaint&) SK_OVERRIDE;
193 void onDrawRect(const SkRect&, const SkPaint&) SK_OVERRIDE;
194 void onDrawOval(const SkRect&, const SkPaint&) SK_OVERRIDE;
195 void onDrawRRect(const SkRRect&, const SkPaint&) SK_OVERRIDE;
196 void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) SK_OVERRIDE;
197 void onDrawVertices(VertexMode vmode, int vertexCount,
198 const SkPoint vertices[], const SkPoint texs[],
199 const SkColor colors[], SkXfermode* xmode,
200 const uint16_t indices[], int indexCount,
201 const SkPaint&) SK_OVERRIDE;
202 void onDrawPath(const SkPath&, const SkPaint&) SK_OVERRIDE;
203 void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) SK_OVERRIDE;
204 void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*,
205 DrawBitmapRectFlags flags) SK_OVERRIDE;
206 void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint*) SK_OVERRIDE;
207 void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
208 const SkPaint*) SK_OVERRIDE;
209 void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
210 const SkPaint*) SK_OVERRIDE;
211 void onDrawSprite(const SkBitmap&, int left, int top, const SkPaint*) SK_OVERRIDE;
212 void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
213 void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
214 void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
215 void onClipRegion(const SkRegion& region, SkRegion::Op) SK_OVERRIDE;
217 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) SK_OVERRIDE;
219 void markActiveCommands(int index);
222 SkTDArray<SkDrawCommand*> fCommandVector;
226 SkMatrix fUserMatrix;
230 SkString fClipStackData;
231 bool fCalledAddStackData;
235 SkDrawFilter* fOverdrawFilter;
237 bool fOverrideTexFiltering;
238 SkTexOverrideFilter* fTexOverrideFilter;
241 The active saveLayer commands at a given point in the renderering.
242 Only used when "mega" visualization is enabled.
244 SkTDArray<SkDrawCommand*> fActiveLayers;
247 Adds the command to the classes vector of commands.
248 @param command The draw command for execution
250 void addDrawCommand(SkDrawCommand* command);
253 Applies any panning and zooming the user has specified before
254 drawing anything else into the canvas.
256 void applyUserTransform(SkCanvas* canvas);
258 size_t getOpID() const {
261 return fPicture->EXPERIMENTAL_curOpID();
267 void resetClipStackData() { fClipStackData.reset(); fCalledAddStackData = false; }
269 void addClipStackData(const SkPath& devPath, const SkPath& operand, SkRegion::Op elementOp);
270 void addPathData(const SkPath& path, const char* pathName);
271 bool lastClipStackData(const SkPath& devPath);
272 void outputConicPoints(const SkPoint* pts, SkScalar weight);
273 void outputPoints(const SkPoint* pts, int count);
274 void outputPointsCommon(const SkPoint* pts, int count);
275 void outputScalar(SkScalar num);
277 typedef SkCanvas INHERITED;