blob: 33b735e51e21257d2adfb0ab4a6478aaf42d7a6b [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#ifndef SKDRAWCOMMAND_H_
10#define SKDRAWCOMMAND_H_
11
chudy@google.com902ebe52012-06-29 14:21:22 +000012#include "SkPictureFlat.h"
13#include "SkCanvas.h"
chudy@google.com902ebe52012-06-29 14:21:22 +000014
15class SkDrawCommand {
16public:
17 /* TODO(chudy): Remove subclasses. */
18 SkDrawCommand();
19
20 virtual ~SkDrawCommand();
21
chudy@google.com97cee972012-08-07 20:41:37 +000022 virtual SkString toString();
chudy@google.com902ebe52012-06-29 14:21:22 +000023
24 virtual const char* toCString() {
25 return GetCommandString(fDrawType);
26 }
27
chudy@google.com0b5bbb02012-07-31 19:55:32 +000028 bool isVisible() const {
29 return fVisible;
30 }
31
32 void setVisible(bool toggle) {
33 fVisible = toggle;
34 }
chudy@google.com902ebe52012-06-29 14:21:22 +000035
chudy@google.com97cee972012-08-07 20:41:37 +000036 SkTDArray<SkString*>* Info() {return &fInfo; };
chudy@google.com902ebe52012-06-29 14:21:22 +000037 virtual void execute(SkCanvas* canvas)=0;
38 DrawType getType() { return fDrawType; };
39
40protected:
41 DrawType fDrawType;
chudy@google.com97cee972012-08-07 20:41:37 +000042 SkTDArray<SkString*> fInfo;
chudy@google.com902ebe52012-06-29 14:21:22 +000043
44private:
45 bool fVisible;
46 static const char* GetCommandString(DrawType type);
47};
48
49class Restore : public SkDrawCommand {
50public:
51 Restore();
52 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
53};
54
55class Clear : public SkDrawCommand {
56public:
57 Clear(SkColor color);
58 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
59private:
60 SkColor fColor;
61};
62
63class ClipPath : public SkDrawCommand {
64public:
65 ClipPath(const SkPath& path, SkRegion::Op op, bool doAA);
66 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
67private:
68 const SkPath* fPath;
69 SkRegion::Op fOp;
70 bool fDoAA;
71};
72
73class ClipRegion : public SkDrawCommand {
74public:
75 ClipRegion(const SkRegion& region, SkRegion::Op op);
76 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
77private:
78 const SkRegion* fRegion;
79 SkRegion::Op fOp;
80};
81
82class ClipRect : public SkDrawCommand {
83public:
84 ClipRect(const SkRect& rect, SkRegion::Op op, bool doAA);
85 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
86private:
87 const SkRect* fRect;
88 SkRegion::Op fOp;
89 bool fDoAA;
90};
91
92class Concat : public SkDrawCommand {
93public:
94 Concat(const SkMatrix& matrix);
95 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
96private:
97 const SkMatrix* fMatrix;
98};
99
100class DrawBitmap : public SkDrawCommand {
101public:
102 DrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
103 const SkPaint* paint);
104 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
105private:
106 const SkPaint* fPaint;
107 const SkBitmap* fBitmap;
108 SkScalar fLeft;
109 SkScalar fTop;
110};
111
112class DrawBitmapMatrix : public SkDrawCommand {
113public:
114 DrawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& matrix,
115 const SkPaint* paint);
116 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
117private:
118 const SkPaint* fPaint;
119 const SkBitmap* fBitmap;
120 const SkMatrix* fMatrix;
121};
122
123class DrawBitmapNine : public SkDrawCommand {
124public:
125 DrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
126 const SkRect& dst, const SkPaint* paint);
127 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
128private:
129 const SkBitmap* fBitmap;
130 const SkIRect* fCenter;
131 const SkRect* fDst;
132 const SkPaint* fPaint;
133};
134
135class DrawBitmapRect : public SkDrawCommand {
136public:
137 DrawBitmapRect(const SkBitmap& bitmap, const SkIRect* src,
138 const SkRect& dst, const SkPaint* paint);
139 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
140private:
141 const SkIRect* fSrc;
142 const SkPaint* fPaint;
143 const SkBitmap* fBitmap;
144 const SkRect* fDst;
145};
146
147class DrawData : public SkDrawCommand {
148public:
149 DrawData(const void* data, size_t length);
150 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
151private:
152 const void* fData;
153 size_t fLength;
154};
155
156class DrawPaint : public SkDrawCommand {
157public:
158 DrawPaint(const SkPaint& paint);
159 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
160private:
161 const SkPaint* fPaint;
162};
163
164class DrawPath : public SkDrawCommand {
165public:
166 DrawPath(const SkPath& path, const SkPaint& paint);
167 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
168private:
169 const SkPath* fPath;
170 const SkPaint* fPaint;
171};
172
173class DrawPicture : public SkDrawCommand {
174public:
175 DrawPicture(SkPicture& picture);
176 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
177private:
178 SkPicture* fPicture;
179};
180
181class DrawPoints : public SkDrawCommand {
182public:
183 DrawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[],
184 const SkPaint& paint);
185 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
186private:
187 const SkPoint* fPts;
188 SkCanvas::PointMode fMode;
189 size_t fCount;
190 const SkPaint* fPaint;
191};
192
193/* TODO(chudy): DrawText is a predefined macro and was breaking something
194 * in the windows build of the debugger.
195 */
196class DrawTextC : public SkDrawCommand {
197public:
198 DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y,
199 const SkPaint& paint);
200 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
201private:
202 const void* fText;
203 size_t fByteLength;
204 SkScalar fX;
205 SkScalar fY;
206 const SkPaint* fPaint;
207};
208
209class DrawPosText : public SkDrawCommand {
210public:
211 DrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
212 const SkPaint& paint);
213 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
214private:
215 const SkPoint* fPos;
216 const void* fText;
217 size_t fByteLength;
218 const SkPaint* fPaint;
219};
220
221class DrawTextOnPath : public SkDrawCommand {
222public:
223 DrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
224 const SkMatrix* matrix, const SkPaint& paint);
225 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
226private:
227 const SkMatrix* fMatrix;
228 const void* fText;
229 size_t fByteLength;
230 const SkPath* fPath;
231 const SkPaint* fPaint;
232};
233
234class DrawPosTextH : public SkDrawCommand {
235public:
236 DrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
237 SkScalar constY, const SkPaint& paint);
238 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
239private:
240 const SkScalar* fXpos;
241 const void* fText;
242 size_t fByteLength;
243 SkScalar fConstY;
244 const SkPaint* fPaint;
245};
246
247class DrawRectC : public SkDrawCommand {
248public:
249 DrawRectC(const SkRect& rect, const SkPaint& paint);
250 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
251private:
252 const SkRect* fRect;
253 const SkPaint* fPaint;
254};
255
256class DrawSprite : public SkDrawCommand {
257public:
258 DrawSprite(const SkBitmap& bitmap, int left, int top, const SkPaint* paint);
259 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
260private:
261 const SkPaint* fPaint;
262 int fLeft;
263 int fTop;
264 const SkBitmap* fBitmap;
265};
266
267class DrawVertices : public SkDrawCommand {
268public:
269 DrawVertices(SkCanvas::VertexMode vmode, int vertexCount,
270 const SkPoint vertices[], const SkPoint texs[], const SkColor colors[],
271 SkXfermode* xfermode, const uint16_t indices[], int indexCount,
272 const SkPaint& paint);
273 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
274private:
275 SkCanvas::VertexMode fVmode;
276 int fVertexCount;
277 int fIndexCount;
278 const SkPoint* fVertices;
279 const SkPoint* fTexs;
280 const SkColor* fColors;
281 const uint16_t* fIndices;
282 SkXfermode* fXfermode;
283 const SkPaint* fPaint;
284};
285
286class Rotate : public SkDrawCommand {
287public:
288 Rotate(SkScalar degrees);
289 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
290private:
291 SkScalar fDegrees;
292};
293
294class Save : public SkDrawCommand {
295public:
296 Save(SkCanvas::SaveFlags flags);
297 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
298private:
299 SkCanvas::SaveFlags fFlags;
300};
301
302class SaveLayer : public SkDrawCommand {
303public:
304 SaveLayer(const SkRect* bounds, const SkPaint* paint,
305 SkCanvas::SaveFlags flags);
306 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
307private:
308 const SkRect* fBounds;
309 const SkPaint* fPaint;
310 SkCanvas::SaveFlags fFlags;
311};
312
313class Scale : public SkDrawCommand {
314public:
315 Scale(SkScalar sx, SkScalar sy);
316 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
317private:
318 SkScalar fSx;
319 SkScalar fSy;
320};
321
322class SetMatrix : public SkDrawCommand {
323public:
324 SetMatrix(const SkMatrix& matrix);
325 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
326private:
327 const SkMatrix* fMatrix;
328};
329
330class Skew : public SkDrawCommand {
331public:
332 Skew(SkScalar sx, SkScalar sy);
333 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
334private:
335 SkScalar fSx;
336 SkScalar fSy;
337};
338
339class Translate : public SkDrawCommand {
340public:
341 Translate(SkScalar dx, SkScalar dy);
342 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
343private:
344 SkScalar fDx;
345 SkScalar fDy;
346};
347
348#endif