blob: c6811f68f92126766e1fbf2694b79b8938524fb2 [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;
tomhudson@google.com0699e022012-11-27 16:09:42 +000038 /** Does nothing by default, but used by save() and restore()-type
39 subclassse to track unresolved save() calls. */
40 virtual void trackSaveState(int* state) { };
chudy@google.com902ebe52012-06-29 14:21:22 +000041 DrawType getType() { return fDrawType; };
42
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000043 virtual const SkBitmap* getBitmap() const { return NULL; }
44
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +000045 static const char* GetCommandString(DrawType type);
46
chudy@google.com902ebe52012-06-29 14:21:22 +000047protected:
48 DrawType fDrawType;
chudy@google.com97cee972012-08-07 20:41:37 +000049 SkTDArray<SkString*> fInfo;
chudy@google.com902ebe52012-06-29 14:21:22 +000050
51private:
52 bool fVisible;
chudy@google.com902ebe52012-06-29 14:21:22 +000053};
54
55class Restore : public SkDrawCommand {
56public:
57 Restore();
58 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
tomhudson@google.com0699e022012-11-27 16:09:42 +000059 virtual void trackSaveState(int* state) SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +000060};
61
62class Clear : public SkDrawCommand {
63public:
64 Clear(SkColor color);
65 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
66private:
67 SkColor fColor;
68};
69
70class ClipPath : public SkDrawCommand {
71public:
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000072 ClipPath(const SkPath& path, SkRegion::Op op, bool doAA, SkBitmap& bitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +000073 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000074 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +000075private:
76 const SkPath* fPath;
77 SkRegion::Op fOp;
78 bool fDoAA;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000079 SkBitmap fBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +000080};
81
82class ClipRegion : public SkDrawCommand {
83public:
84 ClipRegion(const SkRegion& region, SkRegion::Op op);
85 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
86private:
87 const SkRegion* fRegion;
88 SkRegion::Op fOp;
89};
90
91class ClipRect : public SkDrawCommand {
92public:
93 ClipRect(const SkRect& rect, SkRegion::Op op, bool doAA);
94 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
95private:
96 const SkRect* fRect;
97 SkRegion::Op fOp;
98 bool fDoAA;
99};
100
101class Concat : public SkDrawCommand {
102public:
103 Concat(const SkMatrix& matrix);
104 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
105private:
106 const SkMatrix* fMatrix;
107};
108
109class DrawBitmap : public SkDrawCommand {
110public:
111 DrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000112 const SkPaint* paint, SkBitmap& resizedBitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000113 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000114 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000115private:
116 const SkPaint* fPaint;
117 const SkBitmap* fBitmap;
118 SkScalar fLeft;
119 SkScalar fTop;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000120 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000121};
122
123class DrawBitmapMatrix : public SkDrawCommand {
124public:
125 DrawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& matrix,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000126 const SkPaint* paint, SkBitmap& resizedBitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000127 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000128 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000129private:
130 const SkPaint* fPaint;
131 const SkBitmap* fBitmap;
132 const SkMatrix* fMatrix;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000133 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000134};
135
136class DrawBitmapNine : public SkDrawCommand {
137public:
138 DrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000139 const SkRect& dst, const SkPaint* paint, SkBitmap& resizedBitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000140 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000141 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000142private:
143 const SkBitmap* fBitmap;
144 const SkIRect* fCenter;
145 const SkRect* fDst;
146 const SkPaint* fPaint;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000147 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000148};
149
150class DrawBitmapRect : public SkDrawCommand {
151public:
reed@google.com71121732012-09-18 15:14:33 +0000152 DrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000153 const SkRect& dst, const SkPaint* paint, SkBitmap& resizedBitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000154 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000155 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000156private:
reed@google.com71121732012-09-18 15:14:33 +0000157 const SkRect* fSrc;
chudy@google.com902ebe52012-06-29 14:21:22 +0000158 const SkPaint* fPaint;
159 const SkBitmap* fBitmap;
160 const SkRect* fDst;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000161 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000162};
163
164class DrawData : public SkDrawCommand {
165public:
166 DrawData(const void* data, size_t length);
167 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
168private:
169 const void* fData;
170 size_t fLength;
171};
172
173class DrawPaint : public SkDrawCommand {
174public:
175 DrawPaint(const SkPaint& paint);
176 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
177private:
178 const SkPaint* fPaint;
179};
180
181class DrawPath : public SkDrawCommand {
182public:
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000183 DrawPath(const SkPath& path, const SkPaint& paint, SkBitmap& bitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000184 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
rmistry@google.com44737652012-11-21 18:37:58 +0000185 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000186
chudy@google.com902ebe52012-06-29 14:21:22 +0000187private:
188 const SkPath* fPath;
189 const SkPaint* fPaint;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000190 SkBitmap fBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000191};
192
193class DrawPicture : public SkDrawCommand {
194public:
195 DrawPicture(SkPicture& picture);
196 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
197private:
198 SkPicture* fPicture;
199};
200
201class DrawPoints : public SkDrawCommand {
202public:
203 DrawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[],
204 const SkPaint& paint);
205 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
206private:
207 const SkPoint* fPts;
208 SkCanvas::PointMode fMode;
209 size_t fCount;
210 const SkPaint* fPaint;
211};
212
213/* TODO(chudy): DrawText is a predefined macro and was breaking something
214 * in the windows build of the debugger.
215 */
216class DrawTextC : public SkDrawCommand {
217public:
218 DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y,
219 const SkPaint& paint);
220 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
221private:
222 const void* fText;
223 size_t fByteLength;
224 SkScalar fX;
225 SkScalar fY;
226 const SkPaint* fPaint;
227};
228
229class DrawPosText : public SkDrawCommand {
230public:
231 DrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
232 const SkPaint& paint);
233 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
234private:
235 const SkPoint* fPos;
236 const void* fText;
237 size_t fByteLength;
238 const SkPaint* fPaint;
239};
240
241class DrawTextOnPath : public SkDrawCommand {
242public:
243 DrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
244 const SkMatrix* matrix, const SkPaint& paint);
245 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
246private:
247 const SkMatrix* fMatrix;
248 const void* fText;
249 size_t fByteLength;
250 const SkPath* fPath;
251 const SkPaint* fPaint;
252};
253
254class DrawPosTextH : public SkDrawCommand {
255public:
256 DrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
257 SkScalar constY, const SkPaint& paint);
258 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
259private:
260 const SkScalar* fXpos;
261 const void* fText;
262 size_t fByteLength;
263 SkScalar fConstY;
264 const SkPaint* fPaint;
265};
266
267class DrawRectC : public SkDrawCommand {
268public:
269 DrawRectC(const SkRect& rect, const SkPaint& paint);
270 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
271private:
272 const SkRect* fRect;
273 const SkPaint* fPaint;
274};
275
276class DrawSprite : public SkDrawCommand {
277public:
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000278 DrawSprite(const SkBitmap& bitmap, int left, int top, const SkPaint* paint,
279 SkBitmap& resizedBitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000280 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000281 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000282private:
283 const SkPaint* fPaint;
284 int fLeft;
285 int fTop;
286 const SkBitmap* fBitmap;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000287 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000288};
289
290class DrawVertices : public SkDrawCommand {
291public:
292 DrawVertices(SkCanvas::VertexMode vmode, int vertexCount,
293 const SkPoint vertices[], const SkPoint texs[], const SkColor colors[],
294 SkXfermode* xfermode, const uint16_t indices[], int indexCount,
295 const SkPaint& paint);
296 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
297private:
298 SkCanvas::VertexMode fVmode;
299 int fVertexCount;
300 int fIndexCount;
301 const SkPoint* fVertices;
302 const SkPoint* fTexs;
303 const SkColor* fColors;
304 const uint16_t* fIndices;
305 SkXfermode* fXfermode;
306 const SkPaint* fPaint;
307};
308
309class Rotate : public SkDrawCommand {
310public:
311 Rotate(SkScalar degrees);
312 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
313private:
314 SkScalar fDegrees;
315};
316
317class Save : public SkDrawCommand {
318public:
319 Save(SkCanvas::SaveFlags flags);
320 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
tomhudson@google.com0699e022012-11-27 16:09:42 +0000321 virtual void trackSaveState(int* state) SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000322private:
323 SkCanvas::SaveFlags fFlags;
324};
325
326class SaveLayer : public SkDrawCommand {
327public:
328 SaveLayer(const SkRect* bounds, const SkPaint* paint,
329 SkCanvas::SaveFlags flags);
330 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
tomhudson@google.com0699e022012-11-27 16:09:42 +0000331 virtual void trackSaveState(int* state) SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000332private:
333 const SkRect* fBounds;
334 const SkPaint* fPaint;
335 SkCanvas::SaveFlags fFlags;
336};
337
338class Scale : public SkDrawCommand {
339public:
340 Scale(SkScalar sx, SkScalar sy);
341 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
342private:
343 SkScalar fSx;
344 SkScalar fSy;
345};
346
347class SetMatrix : public SkDrawCommand {
348public:
349 SetMatrix(const SkMatrix& matrix);
350 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
351private:
352 const SkMatrix* fMatrix;
353};
354
355class Skew : public SkDrawCommand {
356public:
357 Skew(SkScalar sx, SkScalar sy);
358 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
359private:
360 SkScalar fSx;
361 SkScalar fSy;
362};
363
364class Translate : public SkDrawCommand {
365public:
366 Translate(SkScalar dx, SkScalar dy);
367 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
368private:
369 SkScalar fDx;
370 SkScalar fDy;
371};
372
373#endif