blob: 6375681cfc5ea7993d49c5f9822b109479b94a2a [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
chudy@google.comb9ddd4e2012-07-10 14:14:50 +000090 void setBounds(int width, int height) {
91 fWidth = width;
92 fHeight = height;
93 }
94
chudy@google.com902ebe52012-06-29 14:21:22 +000095////////////////////////////////////////////////////////////////////////////////
96// Inherited from SkCanvas
97////////////////////////////////////////////////////////////////////////////////
98
99 virtual void clear(SkColor) SK_OVERRIDE;
100
101 virtual bool clipPath(const SkPath&, SkRegion::Op, bool) SK_OVERRIDE;
102
103 virtual bool clipRect(const SkRect&, SkRegion::Op, bool) SK_OVERRIDE;
104
105 virtual bool clipRegion(const SkRegion& region, SkRegion::Op op) SK_OVERRIDE;
106
107 virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE;
108
109 virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top,
110 const SkPaint*) SK_OVERRIDE;
111
112 virtual void drawBitmapRect(const SkBitmap&, const SkIRect* src,
113 const SkRect& dst, const SkPaint*) SK_OVERRIDE;
114
115 virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&,
116 const SkPaint*) SK_OVERRIDE;
117
118 virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
119 const SkRect& dst, const SkPaint*) SK_OVERRIDE;
120
121 virtual void drawData(const void*, size_t) SK_OVERRIDE;
122
123 virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
124
125 virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE;
126
127 virtual void drawPicture(SkPicture& picture) SK_OVERRIDE;
128
129 virtual void drawPoints(PointMode, size_t count, const SkPoint pts[],
130 const SkPaint&) SK_OVERRIDE;
131
132 virtual void drawPosText(const void* text, size_t byteLength,
133 const SkPoint pos[], const SkPaint&) SK_OVERRIDE;
134
135 virtual void drawPosTextH(const void* text, size_t byteLength,
136 const SkScalar xpos[], SkScalar constY, const SkPaint&) SK_OVERRIDE;
137
138 virtual void drawRect(const SkRect& rect, const SkPaint&) SK_OVERRIDE;
139
140 virtual void drawSprite(const SkBitmap&, int left, int top,
141 const SkPaint*) SK_OVERRIDE;
142
143 virtual void drawText(const void* text, size_t byteLength, SkScalar x,
144 SkScalar y, const SkPaint&) SK_OVERRIDE;
145
146 virtual void drawTextOnPath(const void* text, size_t byteLength,
147 const SkPath& path, const SkMatrix* matrix,
148 const SkPaint&) SK_OVERRIDE;
149
150 virtual void drawVertices(VertexMode, int vertexCount,
151 const SkPoint vertices[], const SkPoint texs[],
152 const SkColor colors[], SkXfermode*,
153 const uint16_t indices[], int indexCount,
154 const SkPaint&) SK_OVERRIDE;
155
156 virtual void restore() SK_OVERRIDE;
157
158 virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
159
160 virtual int save(SaveFlags) SK_OVERRIDE;
161
162 virtual int saveLayer(const SkRect* bounds, const SkPaint*, SaveFlags) SK_OVERRIDE;
163
164 virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
165
166 virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE;
167
168 virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE;
169
170 virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
171
172private:
173 typedef SkCanvas INHERITED;
174 std::vector<SkDrawCommand*> commandVector;
175 std::vector<SkDrawCommand*>::const_iterator it;
chudy@google.comb9ddd4e2012-07-10 14:14:50 +0000176 int fHeight;
177 int fWidth;
chudy@google.com902ebe52012-06-29 14:21:22 +0000178 SkBitmap fBm;
179
180 /**
181 Adds the command to the classes vector of commands.
182 @param command The draw command for execution
183 */
184 void addDrawCommand(SkDrawCommand* command);
185};
186
187#endif