blob: cfb03e57377dd07ad47d5dc3d50290c7c61e7fad [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,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000108 const SkPaint* paint, SkBitmap& resizedBitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000109 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000110 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000111private:
112 const SkPaint* fPaint;
113 const SkBitmap* fBitmap;
114 SkScalar fLeft;
115 SkScalar fTop;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000116 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000117};
118
119class DrawBitmapMatrix : public SkDrawCommand {
120public:
121 DrawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& matrix,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000122 const SkPaint* paint, SkBitmap& resizedBitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000123 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000124 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000125private:
126 const SkPaint* fPaint;
127 const SkBitmap* fBitmap;
128 const SkMatrix* fMatrix;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000129 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000130};
131
132class DrawBitmapNine : public SkDrawCommand {
133public:
134 DrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000135 const SkRect& dst, const SkPaint* paint, SkBitmap& resizedBitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000136 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000137 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000138private:
139 const SkBitmap* fBitmap;
140 const SkIRect* fCenter;
141 const SkRect* fDst;
142 const SkPaint* fPaint;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000143 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000144};
145
146class DrawBitmapRect : public SkDrawCommand {
147public:
reed@google.com71121732012-09-18 15:14:33 +0000148 DrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000149 const SkRect& dst, const SkPaint* paint, SkBitmap& resizedBitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000150 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000151 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000152private:
reed@google.com71121732012-09-18 15:14:33 +0000153 const SkRect* fSrc;
chudy@google.com902ebe52012-06-29 14:21:22 +0000154 const SkPaint* fPaint;
155 const SkBitmap* fBitmap;
156 const SkRect* fDst;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000157 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000158};
159
160class DrawData : public SkDrawCommand {
161public:
162 DrawData(const void* data, size_t length);
163 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
164private:
165 const void* fData;
166 size_t fLength;
167};
168
169class DrawPaint : public SkDrawCommand {
170public:
171 DrawPaint(const SkPaint& paint);
172 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
173private:
174 const SkPaint* fPaint;
175};
176
177class DrawPath : public SkDrawCommand {
178public:
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000179 DrawPath(const SkPath& path, const SkPaint& paint, SkBitmap& bitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000180 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
rmistry@google.com44737652012-11-21 18:37:58 +0000181 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000182
chudy@google.com902ebe52012-06-29 14:21:22 +0000183private:
184 const SkPath* fPath;
185 const SkPaint* fPaint;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000186 SkBitmap fBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000187};
188
189class DrawPicture : public SkDrawCommand {
190public:
191 DrawPicture(SkPicture& picture);
192 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
193private:
194 SkPicture* fPicture;
195};
196
197class DrawPoints : public SkDrawCommand {
198public:
199 DrawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[],
200 const SkPaint& paint);
201 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
202private:
203 const SkPoint* fPts;
204 SkCanvas::PointMode fMode;
205 size_t fCount;
206 const SkPaint* fPaint;
207};
208
209/* TODO(chudy): DrawText is a predefined macro and was breaking something
210 * in the windows build of the debugger.
211 */
212class DrawTextC : public SkDrawCommand {
213public:
214 DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y,
215 const SkPaint& paint);
216 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
217private:
218 const void* fText;
219 size_t fByteLength;
220 SkScalar fX;
221 SkScalar fY;
222 const SkPaint* fPaint;
223};
224
225class DrawPosText : public SkDrawCommand {
226public:
227 DrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
228 const SkPaint& paint);
229 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
230private:
231 const SkPoint* fPos;
232 const void* fText;
233 size_t fByteLength;
234 const SkPaint* fPaint;
235};
236
237class DrawTextOnPath : public SkDrawCommand {
238public:
239 DrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
240 const SkMatrix* matrix, const SkPaint& paint);
241 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
242private:
243 const SkMatrix* fMatrix;
244 const void* fText;
245 size_t fByteLength;
246 const SkPath* fPath;
247 const SkPaint* fPaint;
248};
249
250class DrawPosTextH : public SkDrawCommand {
251public:
252 DrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
253 SkScalar constY, const SkPaint& paint);
254 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
255private:
256 const SkScalar* fXpos;
257 const void* fText;
258 size_t fByteLength;
259 SkScalar fConstY;
260 const SkPaint* fPaint;
261};
262
263class DrawRectC : public SkDrawCommand {
264public:
265 DrawRectC(const SkRect& rect, const SkPaint& paint);
266 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
267private:
268 const SkRect* fRect;
269 const SkPaint* fPaint;
270};
271
272class DrawSprite : public SkDrawCommand {
273public:
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000274 DrawSprite(const SkBitmap& bitmap, int left, int top, const SkPaint* paint,
275 SkBitmap& resizedBitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000276 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000277 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000278private:
279 const SkPaint* fPaint;
280 int fLeft;
281 int fTop;
282 const SkBitmap* fBitmap;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000283 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000284};
285
286class DrawVertices : public SkDrawCommand {
287public:
288 DrawVertices(SkCanvas::VertexMode vmode, int vertexCount,
289 const SkPoint vertices[], const SkPoint texs[], const SkColor colors[],
290 SkXfermode* xfermode, const uint16_t indices[], int indexCount,
291 const SkPaint& paint);
292 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
293private:
294 SkCanvas::VertexMode fVmode;
295 int fVertexCount;
296 int fIndexCount;
297 const SkPoint* fVertices;
298 const SkPoint* fTexs;
299 const SkColor* fColors;
300 const uint16_t* fIndices;
301 SkXfermode* fXfermode;
302 const SkPaint* fPaint;
303};
304
305class Rotate : public SkDrawCommand {
306public:
307 Rotate(SkScalar degrees);
308 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
309private:
310 SkScalar fDegrees;
311};
312
313class Save : public SkDrawCommand {
314public:
315 Save(SkCanvas::SaveFlags flags);
316 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
317private:
318 SkCanvas::SaveFlags fFlags;
319};
320
321class SaveLayer : public SkDrawCommand {
322public:
323 SaveLayer(const SkRect* bounds, const SkPaint* paint,
324 SkCanvas::SaveFlags flags);
325 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
326private:
327 const SkRect* fBounds;
328 const SkPaint* fPaint;
329 SkCanvas::SaveFlags fFlags;
330};
331
332class Scale : public SkDrawCommand {
333public:
334 Scale(SkScalar sx, SkScalar sy);
335 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
336private:
337 SkScalar fSx;
338 SkScalar fSy;
339};
340
341class SetMatrix : public SkDrawCommand {
342public:
343 SetMatrix(const SkMatrix& matrix);
344 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
345private:
346 const SkMatrix* fMatrix;
347};
348
349class Skew : public SkDrawCommand {
350public:
351 Skew(SkScalar sx, SkScalar sy);
352 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
353private:
354 SkScalar fSx;
355 SkScalar fSy;
356};
357
358class Translate : public SkDrawCommand {
359public:
360 Translate(SkScalar dx, SkScalar dy);
361 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
362private:
363 SkScalar fDx;
364 SkScalar fDy;
365};
366
367#endif