blob: 9e73ce1a384ba7c48b22b7a33748727245f09588 [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:
106 const SkRRect* fRRect;
107 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;
chudy@google.com902ebe52012-06-29 14:21:22 +0000166private:
reed@google.com71121732012-09-18 15:14:33 +0000167 const SkRect* fSrc;
chudy@google.com902ebe52012-06-29 14:21:22 +0000168 const SkPaint* fPaint;
169 const SkBitmap* fBitmap;
170 const SkRect* fDst;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000171 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000172};
173
174class DrawData : public SkDrawCommand {
175public:
176 DrawData(const void* data, size_t length);
177 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
178private:
179 const void* fData;
180 size_t fLength;
181};
182
robertphillips@google.com67baba42013-01-02 20:20:31 +0000183class DrawOval : public SkDrawCommand {
184public:
185 DrawOval(const SkRect& oval, const SkPaint& paint);
186 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
187private:
188 const SkRect* fOval;
189 const SkPaint* fPaint;
190};
191
chudy@google.com902ebe52012-06-29 14:21:22 +0000192class DrawPaint : public SkDrawCommand {
193public:
194 DrawPaint(const SkPaint& paint);
195 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
196private:
197 const SkPaint* fPaint;
198};
199
200class DrawPath : public SkDrawCommand {
201public:
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000202 DrawPath(const SkPath& path, const SkPaint& paint, SkBitmap& bitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000203 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
rmistry@google.com44737652012-11-21 18:37:58 +0000204 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000205
chudy@google.com902ebe52012-06-29 14:21:22 +0000206private:
207 const SkPath* fPath;
208 const SkPaint* fPaint;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000209 SkBitmap fBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000210};
211
212class DrawPicture : public SkDrawCommand {
213public:
214 DrawPicture(SkPicture& picture);
215 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
216private:
217 SkPicture* fPicture;
218};
219
220class DrawPoints : public SkDrawCommand {
221public:
222 DrawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[],
223 const SkPaint& paint);
224 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
225private:
226 const SkPoint* fPts;
227 SkCanvas::PointMode fMode;
228 size_t fCount;
229 const SkPaint* fPaint;
230};
231
232/* TODO(chudy): DrawText is a predefined macro and was breaking something
233 * in the windows build of the debugger.
234 */
235class DrawTextC : public SkDrawCommand {
236public:
237 DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y,
238 const SkPaint& paint);
239 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
240private:
241 const void* fText;
242 size_t fByteLength;
243 SkScalar fX;
244 SkScalar fY;
245 const SkPaint* fPaint;
246};
247
248class DrawPosText : public SkDrawCommand {
249public:
250 DrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
251 const SkPaint& paint);
252 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
253private:
254 const SkPoint* fPos;
255 const void* fText;
256 size_t fByteLength;
257 const SkPaint* fPaint;
258};
259
260class DrawTextOnPath : public SkDrawCommand {
261public:
262 DrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
263 const SkMatrix* matrix, const SkPaint& paint);
264 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
265private:
266 const SkMatrix* fMatrix;
267 const void* fText;
268 size_t fByteLength;
269 const SkPath* fPath;
270 const SkPaint* fPaint;
271};
272
273class DrawPosTextH : public SkDrawCommand {
274public:
275 DrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
276 SkScalar constY, const SkPaint& paint);
277 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
278private:
279 const SkScalar* fXpos;
280 const void* fText;
281 size_t fByteLength;
282 SkScalar fConstY;
283 const SkPaint* fPaint;
284};
285
286class DrawRectC : public SkDrawCommand {
287public:
288 DrawRectC(const SkRect& rect, const SkPaint& paint);
289 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
290private:
291 const SkRect* fRect;
292 const SkPaint* fPaint;
293};
294
robertphillips@google.com67baba42013-01-02 20:20:31 +0000295class DrawRRect : public SkDrawCommand {
296public:
297 DrawRRect(const SkRRect& rrect, const SkPaint& paint);
298 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
299private:
300 SkRRect fRRect;
301 const SkPaint* fPaint;
302};
303
chudy@google.com902ebe52012-06-29 14:21:22 +0000304class DrawSprite : public SkDrawCommand {
305public:
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000306 DrawSprite(const SkBitmap& bitmap, int left, int top, const SkPaint* paint,
307 SkBitmap& resizedBitmap);
chudy@google.com902ebe52012-06-29 14:21:22 +0000308 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000309 virtual const SkBitmap* getBitmap() const SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000310private:
311 const SkPaint* fPaint;
312 int fLeft;
313 int fTop;
314 const SkBitmap* fBitmap;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000315 SkBitmap fResizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000316};
317
318class DrawVertices : public SkDrawCommand {
319public:
320 DrawVertices(SkCanvas::VertexMode vmode, int vertexCount,
321 const SkPoint vertices[], const SkPoint texs[], const SkColor colors[],
322 SkXfermode* xfermode, const uint16_t indices[], int indexCount,
323 const SkPaint& paint);
324 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
325private:
326 SkCanvas::VertexMode fVmode;
327 int fVertexCount;
328 int fIndexCount;
329 const SkPoint* fVertices;
330 const SkPoint* fTexs;
331 const SkColor* fColors;
332 const uint16_t* fIndices;
333 SkXfermode* fXfermode;
334 const SkPaint* fPaint;
335};
336
337class Rotate : public SkDrawCommand {
338public:
339 Rotate(SkScalar degrees);
340 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
341private:
342 SkScalar fDegrees;
343};
344
345class Save : public SkDrawCommand {
346public:
347 Save(SkCanvas::SaveFlags flags);
348 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
tomhudson@google.com0699e022012-11-27 16:09:42 +0000349 virtual void trackSaveState(int* state) SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000350private:
351 SkCanvas::SaveFlags fFlags;
352};
353
354class SaveLayer : public SkDrawCommand {
355public:
356 SaveLayer(const SkRect* bounds, const SkPaint* paint,
357 SkCanvas::SaveFlags flags);
358 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
tomhudson@google.com0699e022012-11-27 16:09:42 +0000359 virtual void trackSaveState(int* state) SK_OVERRIDE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000360private:
361 const SkRect* fBounds;
362 const SkPaint* fPaint;
363 SkCanvas::SaveFlags fFlags;
364};
365
366class Scale : public SkDrawCommand {
367public:
368 Scale(SkScalar sx, SkScalar sy);
369 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
370private:
371 SkScalar fSx;
372 SkScalar fSy;
373};
374
375class SetMatrix : public SkDrawCommand {
376public:
377 SetMatrix(const SkMatrix& matrix);
378 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
379private:
380 const SkMatrix* fMatrix;
381};
382
383class Skew : public SkDrawCommand {
384public:
385 Skew(SkScalar sx, SkScalar sy);
386 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
387private:
388 SkScalar fSx;
389 SkScalar fSy;
390};
391
392class Translate : public SkDrawCommand {
393public:
394 Translate(SkScalar dx, SkScalar dy);
395 virtual void execute(SkCanvas* canvas) SK_OVERRIDE;
396private:
397 SkScalar fDx;
398 SkScalar fDy;
399};
400
401#endif