blob: 3ede8ff908b6c0c7863c38cc5c0af5091440e129 [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:
robertphillips@google.com91217d02013-03-17 18:33:46 +000076 SkPath fPath;
chudy@google.com902ebe52012-06-29 14:21:22 +000077 SkRegion::Op fOp;
78 bool fDoAA;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000079 SkBitmap fBitmap;
robertphillips@google.com91217d02013-03-17 18:33:46 +000080
81 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +000082};
83
84class ClipRegion : public SkDrawCommand {
85public:
86 ClipRegion(const SkRegion& region, SkRegion::Op op);
87 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
88private:
89 const SkRegion* fRegion;
90 SkRegion::Op fOp;
91};
92
93class ClipRect : public SkDrawCommand {
94public:
95 ClipRect(const SkRect& rect, SkRegion::Op op, bool doAA);
96 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +000097
98 const SkRect& rect() const { return *fRect; }
99 SkRegion::Op op() const { return fOp; }
100 bool doAA() const { return fDoAA; }
101
chudy@google.com902ebe52012-06-29 14:21:22 +0000102private:
103 const SkRect* fRect;
104 SkRegion::Op fOp;
105 bool fDoAA;
106};
107
robertphillips@google.com67baba42013-01-02 20:20:31 +0000108class ClipRRect : public SkDrawCommand {
109public:
110 ClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA);
111 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000112
113 const SkRRect& rrect() const { return fRRect; }
114 SkRegion::Op op() const { return fOp; }
115 bool doAA() const { return fDoAA; }
116
robertphillips@google.com67baba42013-01-02 20:20:31 +0000117private:
robertphillips@google.com2da95b22013-01-17 16:07:04 +0000118 SkRRect fRRect;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000119 SkRegion::Op fOp;
120 bool fDoAA;
121};
122
chudy@google.com902ebe52012-06-29 14:21:22 +0000123class Concat : public SkDrawCommand {
124public:
125 Concat(const SkMatrix& matrix);
126 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
127private:
128 const SkMatrix* fMatrix;
129};
130
131class DrawBitmap : public SkDrawCommand {
132public:
133 DrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000134 const SkPaint* paint, SkBitmap& resizedBitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000135 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000136 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000137private:
138 const SkPaint* fPaint;
139 const SkBitmap* fBitmap;
140 SkScalar fLeft;
141 SkScalar fTop;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000142 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000143};
144
145class DrawBitmapMatrix : public SkDrawCommand {
146public:
147 DrawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& matrix,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000148 const SkPaint* paint, SkBitmap& resizedBitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000149 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000150 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000151private:
152 const SkPaint* fPaint;
153 const SkBitmap* fBitmap;
154 const SkMatrix* fMatrix;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000155 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000156};
157
158class DrawBitmapNine : public SkDrawCommand {
159public:
160 DrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000161 const SkRect& dst, const SkPaint* paint, SkBitmap& resizedBitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000162 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000163 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000164private:
165 const SkBitmap* fBitmap;
166 const SkIRect* fCenter;
167 const SkRect* fDst;
168 const SkPaint* fPaint;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000169 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000170};
171
172class DrawBitmapRect : public SkDrawCommand {
173public:
reed@google.com71121732012-09-18 15:14:33 +0000174 DrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
robertphillips@google.com91217d02013-03-17 18:33:46 +0000175 const SkRect& dst, const SkPaint* paint,
176 SkBitmap& resizedBitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000177 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000178 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000179
180 // The non-const 'paint' method allows modification of this object's
181 // SkPaint. For this reason the ctor and setPaint method make a local copy.
182 // The 'fPaintPtr' member acts a signal that the local SkPaint is valid
183 // (since only an SkPaint* is passed into the ctor).
184 const SkPaint* paint() const { return fPaintPtr; }
185 SkPaint* paint() { return fPaintPtr; }
186
187 void setPaint(const SkPaint& paint) { fPaint = paint; fPaintPtr = &fPaint; }
188
robertphillips@google.com91217d02013-03-17 18:33:46 +0000189 const SkRect* srcRect() const { return fSrc.isEmpty() ? NULL : &fSrc; }
190 const SkRect& dstRect() const { return fDst; }
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000191
chudy@google.com902ebe52012-06-29 14:21:22 +0000192private:
robertphillips@google.com91217d02013-03-17 18:33:46 +0000193 SkRect fSrc;
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000194 SkPaint fPaint;
195 SkPaint* fPaintPtr;
robertphillips@google.com91217d02013-03-17 18:33:46 +0000196 SkBitmap fBitmap;
197 SkRect fDst;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000198 SkBitmap fResizedBitmap;
robertphillips@google.com91217d02013-03-17 18:33:46 +0000199
200 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000201};
202
203class DrawData : public SkDrawCommand {
204public:
205 DrawData(const void* data, size_t length);
206 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
207private:
208 const void* fData;
209 size_t fLength;
210};
211
robertphillips@google.com67baba42013-01-02 20:20:31 +0000212class DrawOval : public SkDrawCommand {
213public:
214 DrawOval(const SkRect& oval, const SkPaint& paint);
215 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
216private:
217 const SkRect* fOval;
218 const SkPaint* fPaint;
219};
220
chudy@google.com902ebe52012-06-29 14:21:22 +0000221class DrawPaint : public SkDrawCommand {
222public:
223 DrawPaint(const SkPaint& paint);
224 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
225private:
226 const SkPaint* fPaint;
227};
228
229class DrawPath : public SkDrawCommand {
230public:
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000231 DrawPath(const SkPath& path, const SkPaint& paint, SkBitmap& bitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000232 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
rmistry@google.com44737652012-11-21 18:37:58 +0000233 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000234
chudy@google.com902ebe52012-06-29 14:21:22 +0000235private:
robertphillips@google.com91217d02013-03-17 18:33:46 +0000236 SkPath fPath;
237 SkPaint fPaint;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000238 SkBitmap fBitmap;
robertphillips@google.com91217d02013-03-17 18:33:46 +0000239
240 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000241};
242
243class DrawPicture : public SkDrawCommand {
244public:
245 DrawPicture(SkPicture& picture);
246 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
247private:
248 SkPicture* fPicture;
249};
250
251class DrawPoints : public SkDrawCommand {
252public:
253 DrawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[],
254 const SkPaint& paint);
255 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
256private:
257 const SkPoint* fPts;
258 SkCanvas::PointMode fMode;
259 size_t fCount;
260 const SkPaint* fPaint;
261};
262
263/* TODO(chudy): DrawText is a predefined macro and was breaking something
264 * in the windows build of the debugger.
265 */
266class DrawTextC : public SkDrawCommand {
267public:
268 DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y,
269 const SkPaint& paint);
270 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
271private:
272 const void* fText;
273 size_t fByteLength;
274 SkScalar fX;
275 SkScalar fY;
276 const SkPaint* fPaint;
277};
278
279class DrawPosText : public SkDrawCommand {
280public:
281 DrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
282 const SkPaint& paint);
283 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
284private:
285 const SkPoint* fPos;
286 const void* fText;
287 size_t fByteLength;
288 const SkPaint* fPaint;
289};
290
291class DrawTextOnPath : public SkDrawCommand {
292public:
293 DrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
294 const SkMatrix* matrix, const SkPaint& paint);
295 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
296private:
297 const SkMatrix* fMatrix;
298 const void* fText;
299 size_t fByteLength;
300 const SkPath* fPath;
301 const SkPaint* fPaint;
302};
303
304class DrawPosTextH : public SkDrawCommand {
305public:
306 DrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
robertphillips@google.com91217d02013-03-17 18:33:46 +0000307 SkScalar constY, const SkPaint& paint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000308 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
309private:
310 const SkScalar* fXpos;
311 const void* fText;
312 size_t fByteLength;
313 SkScalar fConstY;
robertphillips@google.com91217d02013-03-17 18:33:46 +0000314 SkPaint fPaint;
315
316 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000317};
318
319class DrawRectC : public SkDrawCommand {
320public:
321 DrawRectC(const SkRect& rect, const SkPaint& paint);
322 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000323
robertphillips@google.com91217d02013-03-17 18:33:46 +0000324 const SkRect& rect() const { return fRect; }
325 const SkPaint& paint() const { return fPaint; }
chudy@google.com902ebe52012-06-29 14:21:22 +0000326private:
robertphillips@google.com91217d02013-03-17 18:33:46 +0000327 SkRect fRect;
328 SkPaint fPaint;
329
330 typedef SkDrawCommand INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000331};
332
robertphillips@google.com67baba42013-01-02 20:20:31 +0000333class DrawRRect : public SkDrawCommand {
334public:
335 DrawRRect(const SkRRect& rrect, const SkPaint& paint);
336 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
337private:
338 SkRRect fRRect;
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000339 SkPaint fPaint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000340};
341
chudy@google.com902ebe52012-06-29 14:21:22 +0000342class DrawSprite : public SkDrawCommand {
343public:
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000344 DrawSprite(const SkBitmap& bitmap, int left, int top, const SkPaint* paint,
345 SkBitmap& resizedBitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000346 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000347 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000348private:
349 const SkPaint* fPaint;
350 int fLeft;
351 int fTop;
352 const SkBitmap* fBitmap;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000353 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000354};
355
356class DrawVertices : public SkDrawCommand {
357public:
358 DrawVertices(SkCanvas::VertexMode vmode, int vertexCount,
359 const SkPoint vertices[], const SkPoint texs[], const SkColor colors[],
360 SkXfermode* xfermode, const uint16_t indices[], int indexCount,
361 const SkPaint& paint);
362 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
363private:
364 SkCanvas::VertexMode fVmode;
365 int fVertexCount;
366 int fIndexCount;
367 const SkPoint* fVertices;
368 const SkPoint* fTexs;
369 const SkColor* fColors;
370 const uint16_t* fIndices;
371 SkXfermode* fXfermode;
372 const SkPaint* fPaint;
373};
374
375class Rotate : public SkDrawCommand {
376public:
377 Rotate(SkScalar degrees);
378 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
379private:
380 SkScalar fDegrees;
381};
382
383class Save : public SkDrawCommand {
384public:
385 Save(SkCanvas::SaveFlags flags);
386 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
tomhudson@google.com0699e022012-11-27 16:09:42 +0000387 virtual void trackSaveState(int* state) SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000388private:
389 SkCanvas::SaveFlags fFlags;
390};
391
392class SaveLayer : public SkDrawCommand {
393public:
394 SaveLayer(const SkRect* bounds, const SkPaint* paint,
395 SkCanvas::SaveFlags flags);
396 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
tomhudson@google.com0699e022012-11-27 16:09:42 +0000397 virtual void trackSaveState(int* state) SK_OVERRIDE;
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000398
399 const SkPaint* paint() const { return fPaint; }
400
chudy@google.com902ebe52012-06-29 14:21:22 +0000401private:
402 const SkRect* fBounds;
403 const SkPaint* fPaint;
404 SkCanvas::SaveFlags fFlags;
405};
406
407class Scale : public SkDrawCommand {
408public:
409 Scale(SkScalar sx, SkScalar sy);
410 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
411private:
412 SkScalar fSx;
413 SkScalar fSy;
414};
415
416class SetMatrix : public SkDrawCommand {
417public:
418 SetMatrix(const SkMatrix& matrix);
419 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
420private:
robertphillips@google.comb94b1e72013-02-19 21:00:26 +0000421 SkMatrix fMatrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000422};
423
424class Skew : public SkDrawCommand {
425public:
426 Skew(SkScalar sx, SkScalar sy);
427 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
428private:
429 SkScalar fSx;
430 SkScalar fSy;
431};
432
433class Translate : public SkDrawCommand {
434public:
435 Translate(SkScalar dx, SkScalar dy);
436 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
437private:
438 SkScalar fDx;
439 SkScalar fDy;
440};
441
442#endif