blob: 4f3edb750a6f6d81d8cd848327cf4a8d183ef5e7 [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
13#include <iostream>
14#include "SkCanvas.h"
15#include "SkDrawCommand.h"
16#include "SkPicture.h"
17#include <vector>
18
19class SkDebugCanvas : public SkCanvas {
20public:
21 bool fFilter;
22
23 SkDebugCanvas();
24 ~SkDebugCanvas();
25
26 void toggleFilter(bool toggle);
27
28 /**
29 Executes all draw calls to the canvas.
30 @param canvas The canvas being drawn to
31 */
32 void draw(SkCanvas* canvas);
33
34 /**
35 Executes the draw calls in the specified range.
36 @param canvas The canvas being drawn to
37 @param i The beginning of the range
38 @param j The end of the range
39 TODO(chudy): Implement
40 */
41 void drawRange(SkCanvas* canvas, int i, int j);
42
43 /**
44 Executes the draw calls up to the specified index.
45 @param canvas The canvas being drawn to
46 @param index The index of the final command being executed
47 */
48 void drawTo(SkCanvas* canvas, int index);
49
50 /**
51 Returns the draw command at the given index.
52 @param index The index of the command
53 */
54 SkDrawCommand* getDrawCommandAt(int index);
55
56 /**
57 Returns information about the command at the given index.
58 @param index The index of the command
59 */
60 std::vector<std::string>* getCommandInfoAt(int index);
61
62 /**
63 Returns the vector of draw commands
64 */
65 std::vector<SkDrawCommand*> getDrawCommands();
66
67 /**
68 * Returns the string vector of draw commands
69 */
70 std::vector<std::string>* getDrawCommandsAsStrings();
71
72 /**
chudy@google.comf1414322012-07-03 20:28:14 +000073 Returns length of draw command vector.
74 */
75 int getSize() {
76 return commandVector.size();
77 }
78
79 /**
chudy@google.com902ebe52012-06-29 14:21:22 +000080 Toggles the execution of the draw command at index i.
81 */
82 void toggleCommand(int index);
83
84 /**
85 Toggles the visibility / execution of the draw command at index i with
86 the value of toggle.
87 */
88 void toggleCommand(int index, bool toggle);
89
90////////////////////////////////////////////////////////////////////////////////
91// Inherited from SkCanvas
92////////////////////////////////////////////////////////////////////////////////
93
94 virtual void clear(SkColor) SK_OVERRIDE;
95
96 virtual bool clipPath(const SkPath&, SkRegion::Op, bool) SK_OVERRIDE;
97
98 virtual bool clipRect(const SkRect&, SkRegion::Op, bool) SK_OVERRIDE;
99
100 virtual bool clipRegion(const SkRegion& region, SkRegion::Op op) SK_OVERRIDE;
101
102 virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE;
103
104 virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top,
105 const SkPaint*) SK_OVERRIDE;
106
107 virtual void drawBitmapRect(const SkBitmap&, const SkIRect* src,
108 const SkRect& dst, const SkPaint*) SK_OVERRIDE;
109
110 virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&,
111 const SkPaint*) SK_OVERRIDE;
112
113 virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
114 const SkRect& dst, const SkPaint*) SK_OVERRIDE;
115
116 virtual void drawData(const void*, size_t) SK_OVERRIDE;
117
118 virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
119
120 virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE;
121
122 virtual void drawPicture(SkPicture& picture) SK_OVERRIDE;
123
124 virtual void drawPoints(PointMode, size_t count, const SkPoint pts[],
125 const SkPaint&) SK_OVERRIDE;
126
127 virtual void drawPosText(const void* text, size_t byteLength,
128 const SkPoint pos[], const SkPaint&) SK_OVERRIDE;
129
130 virtual void drawPosTextH(const void* text, size_t byteLength,
131 const SkScalar xpos[], SkScalar constY, const SkPaint&) SK_OVERRIDE;
132
133 virtual void drawRect(const SkRect& rect, const SkPaint&) SK_OVERRIDE;
134
135 virtual void drawSprite(const SkBitmap&, int left, int top,
136 const SkPaint*) SK_OVERRIDE;
137
138 virtual void drawText(const void* text, size_t byteLength, SkScalar x,
139 SkScalar y, const SkPaint&) SK_OVERRIDE;
140
141 virtual void drawTextOnPath(const void* text, size_t byteLength,
142 const SkPath& path, const SkMatrix* matrix,
143 const SkPaint&) SK_OVERRIDE;
144
145 virtual void drawVertices(VertexMode, int vertexCount,
146 const SkPoint vertices[], const SkPoint texs[],
147 const SkColor colors[], SkXfermode*,
148 const uint16_t indices[], int indexCount,
149 const SkPaint&) SK_OVERRIDE;
150
151 virtual void restore() SK_OVERRIDE;
152
153 virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
154
155 virtual int save(SaveFlags) SK_OVERRIDE;
156
157 virtual int saveLayer(const SkRect* bounds, const SkPaint*, SaveFlags) SK_OVERRIDE;
158
159 virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
160
161 virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE;
162
163 virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE;
164
165 virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
166
167private:
168 typedef SkCanvas INHERITED;
169 std::vector<SkDrawCommand*> commandVector;
170 std::vector<SkDrawCommand*>::const_iterator it;
171
172 SkBitmap fBm;
173
174 /**
175 Adds the command to the classes vector of commands.
176 @param command The draw command for execution
177 */
178 void addDrawCommand(SkDrawCommand* command);
179};
180
181#endif