blob: d06e7fe2b8535837ea07559b04edeb0043973ad4 [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;
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +000095
96 const SkRect& rect() const { return *fRect; }
97 SkRegion::Op op() const { return fOp; }
98 bool doAA() const { return fDoAA; }
99
chudy@google.com902ebe52012-06-29 14:21:22 +0000100private:
101 const SkRect* fRect;
102 SkRegion::Op fOp;
103 bool fDoAA;
104};
105
robertphillips@google.com67baba42013-01-02 20:20:31 +0000106class ClipRRect : public SkDrawCommand {
107public:
108 ClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA);
109 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000110
111 const SkRRect& rrect() const { return fRRect; }
112 SkRegion::Op op() const { return fOp; }
113 bool doAA() const { return fDoAA; }
114
robertphillips@google.com67baba42013-01-02 20:20:31 +0000115private:
robertphillips@google.com2da95b22013-01-17 16:07:04 +0000116 SkRRect fRRect;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000117 SkRegion::Op fOp;
118 bool fDoAA;
119};
120
chudy@google.com902ebe52012-06-29 14:21:22 +0000121class Concat : public SkDrawCommand {
122public:
123 Concat(const SkMatrix& matrix);
124 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
125private:
126 const SkMatrix* fMatrix;
127};
128
129class DrawBitmap : public SkDrawCommand {
130public:
131 DrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000132 const SkPaint* paint, SkBitmap& resizedBitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000133 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000134 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000135private:
136 const SkPaint* fPaint;
137 const SkBitmap* fBitmap;
138 SkScalar fLeft;
139 SkScalar fTop;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000140 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000141};
142
143class DrawBitmapMatrix : public SkDrawCommand {
144public:
145 DrawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& matrix,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000146 const SkPaint* paint, SkBitmap& resizedBitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000147 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000148 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000149private:
150 const SkPaint* fPaint;
151 const SkBitmap* fBitmap;
152 const SkMatrix* fMatrix;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000153 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000154};
155
156class DrawBitmapNine : public SkDrawCommand {
157public:
158 DrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000159 const SkRect& dst, const SkPaint* paint, SkBitmap& resizedBitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000160 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000161 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000162private:
163 const SkBitmap* fBitmap;
164 const SkIRect* fCenter;
165 const SkRect* fDst;
166 const SkPaint* fPaint;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000167 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000168};
169
170class DrawBitmapRect : public SkDrawCommand {
171public:
reed@google.com71121732012-09-18 15:14:33 +0000172 DrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000173 const SkRect& dst, const SkPaint* paint, SkBitmap& resizedBitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000174 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000175 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000176
177 // The non-const 'paint' method allows modification of this object's
178 // SkPaint. For this reason the ctor and setPaint method make a local copy.
179 // The 'fPaintPtr' member acts a signal that the local SkPaint is valid
180 // (since only an SkPaint* is passed into the ctor).
181 const SkPaint* paint() const { return fPaintPtr; }
182 SkPaint* paint() { return fPaintPtr; }
183
184 void setPaint(const SkPaint& paint) { fPaint = paint; fPaintPtr = &fPaint; }
185
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000186 const SkRect& dstRect() { return *fDst; }
187
chudy@google.com902ebe52012-06-29 14:21:22 +0000188private:
reed@google.com71121732012-09-18 15:14:33 +0000189 const SkRect* fSrc;
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000190 SkPaint fPaint;
191 SkPaint* fPaintPtr;
chudy@google.com902ebe52012-06-29 14:21:22 +0000192 const SkBitmap* fBitmap;
193 const SkRect* fDst;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000194 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000195};
196
197class DrawData : public SkDrawCommand {
198public:
199 DrawData(const void* data, size_t length);
200 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
201private:
202 const void* fData;
203 size_t fLength;
204};
205
robertphillips@google.com67baba42013-01-02 20:20:31 +0000206class DrawOval : public SkDrawCommand {
207public:
208 DrawOval(const SkRect& oval, const SkPaint& paint);
209 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
210private:
211 const SkRect* fOval;
212 const SkPaint* fPaint;
213};
214
chudy@google.com902ebe52012-06-29 14:21:22 +0000215class DrawPaint : public SkDrawCommand {
216public:
217 DrawPaint(const SkPaint& paint);
218 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
219private:
220 const SkPaint* fPaint;
221};
222
223class DrawPath : public SkDrawCommand {
224public:
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000225 DrawPath(const SkPath& path, const SkPaint& paint, SkBitmap& bitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000226 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
rmistry@google.com44737652012-11-21 18:37:58 +0000227 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000228
chudy@google.com902ebe52012-06-29 14:21:22 +0000229private:
230 const SkPath* fPath;
231 const SkPaint* fPaint;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000232 SkBitmap fBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000233};
234
235class DrawPicture : public SkDrawCommand {
236public:
237 DrawPicture(SkPicture& picture);
238 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
239private:
240 SkPicture* fPicture;
241};
242
243class DrawPoints : public SkDrawCommand {
244public:
245 DrawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[],
246 const SkPaint& paint);
247 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
248private:
249 const SkPoint* fPts;
250 SkCanvas::PointMode fMode;
251 size_t fCount;
252 const SkPaint* fPaint;
253};
254
255/* TODO(chudy): DrawText is a predefined macro and was breaking something
256 * in the windows build of the debugger.
257 */
258class DrawTextC : public SkDrawCommand {
259public:
260 DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y,
261 const SkPaint& paint);
262 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
263private:
264 const void* fText;
265 size_t fByteLength;
266 SkScalar fX;
267 SkScalar fY;
268 const SkPaint* fPaint;
269};
270
271class DrawPosText : public SkDrawCommand {
272public:
273 DrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
274 const SkPaint& paint);
275 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
276private:
277 const SkPoint* fPos;
278 const void* fText;
279 size_t fByteLength;
280 const SkPaint* fPaint;
281};
282
283class DrawTextOnPath : public SkDrawCommand {
284public:
285 DrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
286 const SkMatrix* matrix, const SkPaint& paint);
287 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
288private:
289 const SkMatrix* fMatrix;
290 const void* fText;
291 size_t fByteLength;
292 const SkPath* fPath;
293 const SkPaint* fPaint;
294};
295
296class DrawPosTextH : public SkDrawCommand {
297public:
298 DrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
299 SkScalar constY, const SkPaint& paint);
300 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
301private:
302 const SkScalar* fXpos;
303 const void* fText;
304 size_t fByteLength;
305 SkScalar fConstY;
306 const SkPaint* fPaint;
307};
308
309class DrawRectC : public SkDrawCommand {
310public:
311 DrawRectC(const SkRect& rect, const SkPaint& paint);
312 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000313
314 const SkRect& rect() const { return *fRect; }
315 const SkPaint* paint() const { return fPaint; }
chudy@google.com902ebe52012-06-29 14:21:22 +0000316private:
317 const SkRect* fRect;
318 const SkPaint* fPaint;
319};
320
robertphillips@google.com67baba42013-01-02 20:20:31 +0000321class DrawRRect : public SkDrawCommand {
322public:
323 DrawRRect(const SkRRect& rrect, const SkPaint& paint);
324 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
325private:
326 SkRRect fRRect;
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000327 SkPaint fPaint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000328};
329
chudy@google.com902ebe52012-06-29 14:21:22 +0000330class DrawSprite : public SkDrawCommand {
331public:
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000332 DrawSprite(const SkBitmap& bitmap, int left, int top, const SkPaint* paint,
333 SkBitmap& resizedBitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000334 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000335 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000336private:
337 const SkPaint* fPaint;
338 int fLeft;
339 int fTop;
340 const SkBitmap* fBitmap;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000341 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000342};
343
344class DrawVertices : public SkDrawCommand {
345public:
346 DrawVertices(SkCanvas::VertexMode vmode, int vertexCount,
347 const SkPoint vertices[], const SkPoint texs[], const SkColor colors[],
348 SkXfermode* xfermode, const uint16_t indices[], int indexCount,
349 const SkPaint& paint);
350 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
351private:
352 SkCanvas::VertexMode fVmode;
353 int fVertexCount;
354 int fIndexCount;
355 const SkPoint* fVertices;
356 const SkPoint* fTexs;
357 const SkColor* fColors;
358 const uint16_t* fIndices;
359 SkXfermode* fXfermode;
360 const SkPaint* fPaint;
361};
362
363class Rotate : public SkDrawCommand {
364public:
365 Rotate(SkScalar degrees);
366 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
367private:
368 SkScalar fDegrees;
369};
370
371class Save : public SkDrawCommand {
372public:
373 Save(SkCanvas::SaveFlags flags);
374 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
tomhudson@google.com0699e022012-11-27 16:09:42 +0000375 virtual void trackSaveState(int* state) SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000376private:
377 SkCanvas::SaveFlags fFlags;
378};
379
380class SaveLayer : public SkDrawCommand {
381public:
382 SaveLayer(const SkRect* bounds, const SkPaint* paint,
383 SkCanvas::SaveFlags flags);
384 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
tomhudson@google.com0699e022012-11-27 16:09:42 +0000385 virtual void trackSaveState(int* state) SK_OVERRIDE;
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000386
387 const SkPaint* paint() const { return fPaint; }
388
chudy@google.com902ebe52012-06-29 14:21:22 +0000389private:
390 const SkRect* fBounds;
391 const SkPaint* fPaint;
392 SkCanvas::SaveFlags fFlags;
393};
394
395class Scale : public SkDrawCommand {
396public:
397 Scale(SkScalar sx, SkScalar sy);
398 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
399private:
400 SkScalar fSx;
401 SkScalar fSy;
402};
403
404class SetMatrix : public SkDrawCommand {
405public:
406 SetMatrix(const SkMatrix& matrix);
407 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
408private:
robertphillips@google.comb94b1e72013-02-19 21:00:26 +0000409 SkMatrix fMatrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000410};
411
412class Skew : public SkDrawCommand {
413public:
414 Skew(SkScalar sx, SkScalar sy);
415 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
416private:
417 SkScalar fSx;
418 SkScalar fSy;
419};
420
421class Translate : public SkDrawCommand {
422public:
423 Translate(SkScalar dx, SkScalar dy);
424 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
425private:
426 SkScalar fDx;
427 SkScalar fDy;
428};
429
430#endif