blob: fba5a01fbd8184f2789cedd7460dc651c296c1a0 [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
robertphillips@google.com67baba42013-01-02 20:20:31 +0000101class ClipRRect : public SkDrawCommand {
102public:
103 ClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA);
104 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
105private:
robertphillips@google.com2da95b22013-01-17 16:07:04 +0000106 SkRRect fRRect;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000107 SkRegion::Op fOp;
108 bool fDoAA;
109};
110
chudy@google.com902ebe52012-06-29 14:21:22 +0000111class Concat : public SkDrawCommand {
112public:
113 Concat(const SkMatrix& matrix);
114 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
115private:
116 const SkMatrix* fMatrix;
117};
118
119class DrawBitmap : public SkDrawCommand {
120public:
121 DrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
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 SkScalar fLeft;
129 SkScalar fTop;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000130 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000131};
132
133class DrawBitmapMatrix : public SkDrawCommand {
134public:
135 DrawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& matrix,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000136 const SkPaint* paint, SkBitmap& resizedBitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000137 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000138 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000139private:
140 const SkPaint* fPaint;
141 const SkBitmap* fBitmap;
142 const SkMatrix* fMatrix;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000143 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000144};
145
146class DrawBitmapNine : public SkDrawCommand {
147public:
148 DrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
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:
153 const SkBitmap* fBitmap;
154 const SkIRect* fCenter;
155 const SkRect* fDst;
156 const SkPaint* fPaint;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000157 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000158};
159
160class DrawBitmapRect : public SkDrawCommand {
161public:
reed@google.com71121732012-09-18 15:14:33 +0000162 DrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000163 const SkRect& dst, const SkPaint* paint, SkBitmap& resizedBitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000164 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000165 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000166
167 // The non-const 'paint' method allows modification of this object's
168 // SkPaint. For this reason the ctor and setPaint method make a local copy.
169 // The 'fPaintPtr' member acts a signal that the local SkPaint is valid
170 // (since only an SkPaint* is passed into the ctor).
171 const SkPaint* paint() const { return fPaintPtr; }
172 SkPaint* paint() { return fPaintPtr; }
173
174 void setPaint(const SkPaint& paint) { fPaint = paint; fPaintPtr = &fPaint; }
175
chudy@google.com902ebe52012-06-29 14:21:22 +0000176private:
reed@google.com71121732012-09-18 15:14:33 +0000177 const SkRect* fSrc;
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000178 SkPaint fPaint;
179 SkPaint* fPaintPtr;
chudy@google.com902ebe52012-06-29 14:21:22 +0000180 const SkBitmap* fBitmap;
181 const SkRect* fDst;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000182 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000183};
184
185class DrawData : public SkDrawCommand {
186public:
187 DrawData(const void* data, size_t length);
188 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
189private:
190 const void* fData;
191 size_t fLength;
192};
193
robertphillips@google.com67baba42013-01-02 20:20:31 +0000194class DrawOval : public SkDrawCommand {
195public:
196 DrawOval(const SkRect& oval, const SkPaint& paint);
197 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
198private:
199 const SkRect* fOval;
200 const SkPaint* fPaint;
201};
202
chudy@google.com902ebe52012-06-29 14:21:22 +0000203class DrawPaint : public SkDrawCommand {
204public:
205 DrawPaint(const SkPaint& paint);
206 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
207private:
208 const SkPaint* fPaint;
209};
210
211class DrawPath : public SkDrawCommand {
212public:
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000213 DrawPath(const SkPath& path, const SkPaint& paint, SkBitmap& bitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000214 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
rmistry@google.com44737652012-11-21 18:37:58 +0000215 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000216
chudy@google.com902ebe52012-06-29 14:21:22 +0000217private:
218 const SkPath* fPath;
219 const SkPaint* fPaint;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000220 SkBitmap fBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000221};
222
223class DrawPicture : public SkDrawCommand {
224public:
225 DrawPicture(SkPicture& picture);
226 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
227private:
228 SkPicture* fPicture;
229};
230
231class DrawPoints : public SkDrawCommand {
232public:
233 DrawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[],
234 const SkPaint& paint);
235 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
236private:
237 const SkPoint* fPts;
238 SkCanvas::PointMode fMode;
239 size_t fCount;
240 const SkPaint* fPaint;
241};
242
243/* TODO(chudy): DrawText is a predefined macro and was breaking something
244 * in the windows build of the debugger.
245 */
246class DrawTextC : public SkDrawCommand {
247public:
248 DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y,
249 const SkPaint& paint);
250 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
251private:
252 const void* fText;
253 size_t fByteLength;
254 SkScalar fX;
255 SkScalar fY;
256 const SkPaint* fPaint;
257};
258
259class DrawPosText : public SkDrawCommand {
260public:
261 DrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
262 const SkPaint& paint);
263 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
264private:
265 const SkPoint* fPos;
266 const void* fText;
267 size_t fByteLength;
268 const SkPaint* fPaint;
269};
270
271class DrawTextOnPath : public SkDrawCommand {
272public:
273 DrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
274 const SkMatrix* matrix, const SkPaint& paint);
275 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
276private:
277 const SkMatrix* fMatrix;
278 const void* fText;
279 size_t fByteLength;
280 const SkPath* fPath;
281 const SkPaint* fPaint;
282};
283
284class DrawPosTextH : public SkDrawCommand {
285public:
286 DrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
287 SkScalar constY, const SkPaint& paint);
288 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
289private:
290 const SkScalar* fXpos;
291 const void* fText;
292 size_t fByteLength;
293 SkScalar fConstY;
294 const SkPaint* fPaint;
295};
296
297class DrawRectC : public SkDrawCommand {
298public:
299 DrawRectC(const SkRect& rect, const SkPaint& paint);
300 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
301private:
302 const SkRect* fRect;
303 const SkPaint* fPaint;
304};
305
robertphillips@google.com67baba42013-01-02 20:20:31 +0000306class DrawRRect : public SkDrawCommand {
307public:
308 DrawRRect(const SkRRect& rrect, const SkPaint& paint);
309 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
310private:
311 SkRRect fRRect;
312 const SkPaint* fPaint;
313};
314
chudy@google.com902ebe52012-06-29 14:21:22 +0000315class DrawSprite : public SkDrawCommand {
316public:
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000317 DrawSprite(const SkBitmap& bitmap, int left, int top, const SkPaint* paint,
318 SkBitmap& resizedBitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000319 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000320 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000321private:
322 const SkPaint* fPaint;
323 int fLeft;
324 int fTop;
325 const SkBitmap* fBitmap;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000326 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000327};
328
329class DrawVertices : public SkDrawCommand {
330public:
331 DrawVertices(SkCanvas::VertexMode vmode, int vertexCount,
332 const SkPoint vertices[], const SkPoint texs[], const SkColor colors[],
333 SkXfermode* xfermode, const uint16_t indices[], int indexCount,
334 const SkPaint& paint);
335 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
336private:
337 SkCanvas::VertexMode fVmode;
338 int fVertexCount;
339 int fIndexCount;
340 const SkPoint* fVertices;
341 const SkPoint* fTexs;
342 const SkColor* fColors;
343 const uint16_t* fIndices;
344 SkXfermode* fXfermode;
345 const SkPaint* fPaint;
346};
347
348class Rotate : public SkDrawCommand {
349public:
350 Rotate(SkScalar degrees);
351 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
352private:
353 SkScalar fDegrees;
354};
355
356class Save : public SkDrawCommand {
357public:
358 Save(SkCanvas::SaveFlags flags);
359 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
tomhudson@google.com0699e022012-11-27 16:09:42 +0000360 virtual void trackSaveState(int* state) SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000361private:
362 SkCanvas::SaveFlags fFlags;
363};
364
365class SaveLayer : public SkDrawCommand {
366public:
367 SaveLayer(const SkRect* bounds, const SkPaint* paint,
368 SkCanvas::SaveFlags flags);
369 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
tomhudson@google.com0699e022012-11-27 16:09:42 +0000370 virtual void trackSaveState(int* state) SK_OVERRIDE;
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000371
372 const SkPaint* paint() const { return fPaint; }
373
chudy@google.com902ebe52012-06-29 14:21:22 +0000374private:
375 const SkRect* fBounds;
376 const SkPaint* fPaint;
377 SkCanvas::SaveFlags fFlags;
378};
379
380class Scale : public SkDrawCommand {
381public:
382 Scale(SkScalar sx, SkScalar sy);
383 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
384private:
385 SkScalar fSx;
386 SkScalar fSy;
387};
388
389class SetMatrix : public SkDrawCommand {
390public:
391 SetMatrix(const SkMatrix& matrix);
392 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
393private:
394 const SkMatrix* fMatrix;
395};
396
397class Skew : public SkDrawCommand {
398public:
399 Skew(SkScalar sx, SkScalar sy);
400 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
401private:
402 SkScalar fSx;
403 SkScalar fSy;
404};
405
406class Translate : public SkDrawCommand {
407public:
408 Translate(SkScalar dx, SkScalar dy);
409 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
410private:
411 SkScalar fDx;
412 SkScalar fDy;
413};
414
415#endif