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