blob: 0504fb51749367acff9da21526a94467fd8977b3 [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
chudy@google.com902ebe52012-06-29 14:21:22 +000010#include "SkDrawCommand.h"
11#include "SkObjectParser.h"
12
13// TODO(chudy): Refactor into non subclass model.
14
robertphillips@google.com0a4805e2013-05-29 13:24:23 +000015SkDrawCommand::SkDrawCommand(DrawType type)
16 : fDrawType(type)
17 , fVisible(true) {
18}
19
chudy@google.com902ebe52012-06-29 14:21:22 +000020SkDrawCommand::SkDrawCommand() {
21 fVisible = true;
22}
23
24SkDrawCommand::~SkDrawCommand() {
chudy@google.com97cee972012-08-07 20:41:37 +000025 fInfo.deleteAll();
chudy@google.com902ebe52012-06-29 14:21:22 +000026}
27
28const char* SkDrawCommand::GetCommandString(DrawType type) {
29 switch (type) {
30 case UNUSED: SkDEBUGFAIL("DrawType UNUSED\n"); break;
31 case DRAW_CLEAR: return "Clear";
32 case CLIP_PATH: return "Clip Path";
33 case CLIP_REGION: return "Clip Region";
34 case CLIP_RECT: return "Clip Rect";
robertphillips@google.com67baba42013-01-02 20:20:31 +000035 case CLIP_RRECT: return "Clip RRect";
chudy@google.com902ebe52012-06-29 14:21:22 +000036 case CONCAT: return "Concat";
37 case DRAW_BITMAP: return "Draw Bitmap";
38 case DRAW_BITMAP_MATRIX: return "Draw Bitmap Matrix";
39 case DRAW_BITMAP_NINE: return "Draw Bitmap Nine";
robertphillips@google.com84d320e2012-09-20 19:09:17 +000040 case DRAW_BITMAP_RECT_TO_RECT: return "Draw Bitmap Rect";
chudy@google.com902ebe52012-06-29 14:21:22 +000041 case DRAW_DATA: return "Draw Data";
robertphillips@google.com67baba42013-01-02 20:20:31 +000042 case DRAW_OVAL: return "Draw Oval";
chudy@google.com902ebe52012-06-29 14:21:22 +000043 case DRAW_PAINT: return "Draw Paint";
44 case DRAW_PATH: return "Draw Path";
45 case DRAW_PICTURE: return "Draw Picture";
46 case DRAW_POINTS: return "Draw Points";
47 case DRAW_POS_TEXT: return "Draw Pos Text";
48 case DRAW_POS_TEXT_H: return "Draw Pos Text H";
49 case DRAW_RECT: return "Draw Rect";
robertphillips@google.com67baba42013-01-02 20:20:31 +000050 case DRAW_RRECT: return "Draw RRect";
chudy@google.com902ebe52012-06-29 14:21:22 +000051 case DRAW_SPRITE: return "Draw Sprite";
52 case DRAW_TEXT: return "Draw Text";
53 case DRAW_TEXT_ON_PATH: return "Draw Text On Path";
54 case DRAW_VERTICES: return "Draw Vertices";
55 case RESTORE: return "Restore";
56 case ROTATE: return "Rotate";
57 case SAVE: return "Save";
58 case SAVE_LAYER: return "Save Layer";
59 case SCALE: return "Scale";
60 case SET_MATRIX: return "Set Matrix";
61 case SKEW: return "Skew";
62 case TRANSLATE: return "Translate";
robertphillips@google.come4ce5b82013-02-15 17:19:15 +000063 case NOOP: return "NoOp";
robertphillips@google.com0a4805e2013-05-29 13:24:23 +000064 case BEGIN_COMMENT_GROUP: return "BeginCommentGroup";
65 case COMMENT: return "Comment";
66 case END_COMMENT_GROUP: return "EndCommentGroup";
chudy@google.com902ebe52012-06-29 14:21:22 +000067 default:
68 SkDebugf("DrawType error 0x%08x\n", type);
69 SkASSERT(0);
70 break;
71 }
72 SkDEBUGFAIL("DrawType UNUSED\n");
73 return NULL;
74}
75
chudy@google.com97cee972012-08-07 20:41:37 +000076SkString SkDrawCommand::toString() {
77 return SkString(GetCommandString(fDrawType));
chudy@google.com902ebe52012-06-29 14:21:22 +000078}
79
80Clear::Clear(SkColor color) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000081 fColor = color;
82 fDrawType = DRAW_CLEAR;
83 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +000084}
85
86void Clear::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000087 canvas->clear(fColor);
chudy@google.com902ebe52012-06-29 14:21:22 +000088}
89
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000090ClipPath::ClipPath(const SkPath& path, SkRegion::Op op, bool doAA, SkBitmap& bitmap) {
robertphillips@google.com91217d02013-03-17 18:33:46 +000091 fPath = path;
92 fOp = op;
93 fDoAA = doAA;
94 fDrawType = CLIP_PATH;
95 fBitmap = bitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +000096
robertphillips@google.com91217d02013-03-17 18:33:46 +000097 fInfo.push(SkObjectParser::PathToString(path));
98 fInfo.push(SkObjectParser::RegionOpToString(op));
99 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000100}
101
102void ClipPath::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000103 canvas->clipPath(fPath, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000104}
105
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000106const SkBitmap* ClipPath::getBitmap() const {
107 return &fBitmap;
108}
109
chudy@google.com902ebe52012-06-29 14:21:22 +0000110ClipRegion::ClipRegion(const SkRegion& region, SkRegion::Op op) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000111 fRegion = region;
112 fOp = op;
113 fDrawType = CLIP_REGION;
chudy@google.com902ebe52012-06-29 14:21:22 +0000114
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000115 fInfo.push(SkObjectParser::RegionToString(region));
116 fInfo.push(SkObjectParser::RegionOpToString(op));
chudy@google.com902ebe52012-06-29 14:21:22 +0000117}
118
119void ClipRegion::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000120 canvas->clipRegion(fRegion, fOp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000121}
122
123ClipRect::ClipRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000124 fRect = rect;
125 fOp = op;
126 fDoAA = doAA;
127 fDrawType = CLIP_RECT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000128
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000129 fInfo.push(SkObjectParser::RectToString(rect));
130 fInfo.push(SkObjectParser::RegionOpToString(op));
131 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000132}
133
134void ClipRect::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000135 canvas->clipRect(fRect, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000136}
137
robertphillips@google.com67baba42013-01-02 20:20:31 +0000138ClipRRect::ClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000139 fRRect = rrect;
140 fOp = op;
141 fDoAA = doAA;
142 fDrawType = CLIP_RRECT;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000143
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000144 fInfo.push(SkObjectParser::RRectToString(rrect));
145 fInfo.push(SkObjectParser::RegionOpToString(op));
146 fInfo.push(SkObjectParser::BoolToString(doAA));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000147}
148
149void ClipRRect::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000150 canvas->clipRRect(fRRect, fOp, fDoAA);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000151}
152
chudy@google.com902ebe52012-06-29 14:21:22 +0000153Concat::Concat(const SkMatrix& matrix) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000154 fMatrix = matrix;
155 fDrawType = CONCAT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000156
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000157 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000158}
159
160void Concat::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000161 canvas->concat(fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000162}
163
164DrawBitmap::DrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000165 const SkPaint* paint, SkBitmap& resizedBitmap) {
166 fBitmap = bitmap;
167 fLeft = left;
168 fTop = top;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000169 if (NULL != paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000170 fPaint = *paint;
171 fPaintPtr = &fPaint;
172 } else {
173 fPaintPtr = NULL;
174 }
175 fDrawType = DRAW_BITMAP;
176 fResizedBitmap = resizedBitmap;
177
178 fInfo.push(SkObjectParser::BitmapToString(bitmap));
179 fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
180 fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: "));
181 if (NULL != paint) {
182 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000183 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000184}
185
186void DrawBitmap::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000187 canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000188}
189
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000190const SkBitmap* DrawBitmap::getBitmap() const {
191 return &fResizedBitmap;
192}
193
chudy@google.com902ebe52012-06-29 14:21:22 +0000194DrawBitmapMatrix::DrawBitmapMatrix(const SkBitmap& bitmap,
skia.committer@gmail.com7e328512013-03-23 07:01:28 +0000195 const SkMatrix& matrix,
196 const SkPaint* paint,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000197 SkBitmap& resizedBitmap) {
198 fBitmap = bitmap;
199 fMatrix = matrix;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000200 if (NULL != paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000201 fPaint = *paint;
202 fPaintPtr = &fPaint;
203 } else {
204 fPaintPtr = NULL;
205 }
206 fDrawType = DRAW_BITMAP_MATRIX;
207 fResizedBitmap = resizedBitmap;
208
209 fInfo.push(SkObjectParser::BitmapToString(bitmap));
210 fInfo.push(SkObjectParser::MatrixToString(matrix));
211 if (NULL != paint) {
212 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000213 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000214}
215
216void DrawBitmapMatrix::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000217 canvas->drawBitmapMatrix(fBitmap, fMatrix, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000218}
219
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000220const SkBitmap* DrawBitmapMatrix::getBitmap() const {
221 return &fResizedBitmap;
222}
223
chudy@google.com902ebe52012-06-29 14:21:22 +0000224DrawBitmapNine::DrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
skia.committer@gmail.com7e328512013-03-23 07:01:28 +0000225 const SkRect& dst, const SkPaint* paint,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000226 SkBitmap& resizedBitmap) {
227 fBitmap = bitmap;
228 fCenter = center;
229 fDst = dst;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000230 if (NULL != paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000231 fPaint = *paint;
232 fPaintPtr = &fPaint;
233 } else {
234 fPaintPtr = NULL;
235 }
236 fDrawType = DRAW_BITMAP_NINE;
237 fResizedBitmap = resizedBitmap;
238
239 fInfo.push(SkObjectParser::BitmapToString(bitmap));
240 fInfo.push(SkObjectParser::IRectToString(center));
241 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
242 if (NULL != paint) {
243 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000244 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000245}
246
247void DrawBitmapNine::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000248 canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000249}
250
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000251const SkBitmap* DrawBitmapNine::getBitmap() const {
252 return &fResizedBitmap;
253}
254
reed@google.com71121732012-09-18 15:14:33 +0000255DrawBitmapRect::DrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
skia.committer@gmail.comc76bb232013-03-18 07:01:03 +0000256 const SkRect& dst, const SkPaint* paint,
robertphillips@google.com91217d02013-03-17 18:33:46 +0000257 SkBitmap& resizedBitmap) {
258 fBitmap = bitmap;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000259 if (NULL != src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000260 fSrc = *src;
261 } else {
262 fSrc.setEmpty();
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000263 }
robertphillips@google.com91217d02013-03-17 18:33:46 +0000264 fDst = dst;
265
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000266 if (NULL != paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000267 fPaint = *paint;
268 fPaintPtr = &fPaint;
269 } else {
270 fPaintPtr = NULL;
271 }
272 fDrawType = DRAW_BITMAP_RECT_TO_RECT;
273 fResizedBitmap = resizedBitmap;
274
275 fInfo.push(SkObjectParser::BitmapToString(bitmap));
276 if (NULL != src) {
277 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
278 }
279 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
280 if (NULL != paint) {
281 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000282 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000283}
284
285void DrawBitmapRect::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000286 canvas->drawBitmapRectToRect(fBitmap, this->srcRect(), fDst, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000287}
288
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000289const SkBitmap* DrawBitmapRect::getBitmap() const {
290 return &fResizedBitmap;
291}
292
chudy@google.com902ebe52012-06-29 14:21:22 +0000293DrawData::DrawData(const void* data, size_t length) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000294 fData = new char[length];
295 memcpy(fData, data, length);
296 fLength = length;
297 fDrawType = DRAW_DATA;
298
299 // TODO: add display of actual data?
300 SkString* str = new SkString;
robertphillips@google.com77279cb2013-03-25 12:01:45 +0000301 str->appendf("length: %d", (int) length);
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000302 fInfo.push(str);
chudy@google.com902ebe52012-06-29 14:21:22 +0000303}
304
305void DrawData::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000306 canvas->drawData(fData, fLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000307}
308
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000309BeginCommentGroup::BeginCommentGroup(const char* description)
310 : INHERITED(BEGIN_COMMENT_GROUP)
311 , fDescription(description) {
312 SkString* temp = new SkString;
313 temp->appendf("Description: %s", description);
314 fInfo.push(temp);
315}
316
317Comment::Comment(const char* kywd, const char* value)
318 : INHERITED(COMMENT)
319 , fKywd(kywd)
320 , fValue(value) {
321 SkString* temp = new SkString;
322 temp->appendf("%s: %s", kywd, value);
323 fInfo.push(temp);
324}
325
326EndCommentGroup::EndCommentGroup() : INHERITED(END_COMMENT_GROUP) {
327}
328
robertphillips@google.com67baba42013-01-02 20:20:31 +0000329DrawOval::DrawOval(const SkRect& oval, const SkPaint& paint) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000330 fOval = oval;
331 fPaint = paint;
332 fDrawType = DRAW_OVAL;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000333
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000334 fInfo.push(SkObjectParser::RectToString(oval));
335 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000336}
337
338void DrawOval::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000339 canvas->drawOval(fOval, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000340}
341
chudy@google.com902ebe52012-06-29 14:21:22 +0000342DrawPaint::DrawPaint(const SkPaint& paint) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000343 fPaint = paint;
344 fDrawType = DRAW_PAINT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000345
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000346 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000347}
348
349void DrawPaint::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000350 canvas->drawPaint(fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000351}
352
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000353DrawPath::DrawPath(const SkPath& path, const SkPaint& paint, SkBitmap& bitmap) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000354 fPath = path;
355 fPaint = paint;
356 fBitmap = bitmap;
357 fDrawType = DRAW_PATH;
chudy@google.com902ebe52012-06-29 14:21:22 +0000358
robertphillips@google.com91217d02013-03-17 18:33:46 +0000359 fInfo.push(SkObjectParser::PathToString(path));
360 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000361}
362
363void DrawPath::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000364 canvas->drawPath(fPath, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000365}
366
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000367const SkBitmap* DrawPath::getBitmap() const {
368 return &fBitmap;
369}
370
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000371DrawPicture::DrawPicture(SkPicture& picture) :
372 fPicture(picture) {
373 fDrawType = DRAW_PICTURE;
374 fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
chudy@google.com902ebe52012-06-29 14:21:22 +0000375}
376
377void DrawPicture::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000378 canvas->drawPicture(fPicture);
chudy@google.com902ebe52012-06-29 14:21:22 +0000379}
380
381DrawPoints::DrawPoints(SkCanvas::PointMode mode, size_t count,
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000382 const SkPoint pts[], const SkPaint& paint) {
383 fMode = mode;
384 fCount = count;
385 fPts = new SkPoint[count];
386 memcpy(fPts, pts, count * sizeof(SkPoint));
387 fPaint = paint;
388 fDrawType = DRAW_POINTS;
chudy@google.com902ebe52012-06-29 14:21:22 +0000389
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000390 fInfo.push(SkObjectParser::PointsToString(pts, count));
391 fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
392 "Points: "));
393 fInfo.push(SkObjectParser::PointModeToString(mode));
394 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000395}
396
397void DrawPoints::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000398 canvas->drawPoints(fMode, fCount, fPts, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000399}
400
401DrawPosText::DrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000402 const SkPaint& paint) {
403 size_t numPts = paint.countText(text, byteLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000404
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000405 fText = new char[byteLength];
406 memcpy(fText, text, byteLength);
407 fByteLength = byteLength;
408
409 fPos = new SkPoint[numPts];
410 memcpy(fPos, pos, numPts * sizeof(SkPoint));
411
412 fPaint = paint;
413 fDrawType = DRAW_POS_TEXT;
414
415 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000416 // TODO(chudy): Test that this works.
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000417 fInfo.push(SkObjectParser::PointsToString(pos, 1));
418 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000419}
420
421void DrawPosText::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000422 canvas->drawPosText(fText, fByteLength, fPos, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000423}
424
425
426DrawPosTextH::DrawPosTextH(const void* text, size_t byteLength,
skia.committer@gmail.comc76bb232013-03-18 07:01:03 +0000427 const SkScalar xpos[], SkScalar constY,
robertphillips@google.com91217d02013-03-17 18:33:46 +0000428 const SkPaint& paint) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000429 size_t numPts = paint.countText(text, byteLength);
430
431 fText = new char[byteLength];
432 memcpy(fText, text, byteLength);
robertphillips@google.com91217d02013-03-17 18:33:46 +0000433 fByteLength = byteLength;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000434
435 fXpos = new SkScalar[numPts];
436 memcpy(fXpos, xpos, numPts * sizeof(SkScalar));
437
robertphillips@google.com91217d02013-03-17 18:33:46 +0000438 fConstY = constY;
439 fPaint = paint;
440 fDrawType = DRAW_POS_TEXT_H;
chudy@google.com902ebe52012-06-29 14:21:22 +0000441
robertphillips@google.com91217d02013-03-17 18:33:46 +0000442 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
443 fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
444 fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
445 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000446}
447
448void DrawPosTextH::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000449 canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000450}
451
452DrawRectC::DrawRectC(const SkRect& rect, const SkPaint& paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000453 fRect = rect;
454 fPaint = paint;
455 fDrawType = DRAW_RECT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000456
robertphillips@google.com91217d02013-03-17 18:33:46 +0000457 fInfo.push(SkObjectParser::RectToString(rect));
458 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000459}
460
461void DrawRectC::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000462 canvas->drawRect(fRect, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000463}
464
robertphillips@google.com67baba42013-01-02 20:20:31 +0000465DrawRRect::DrawRRect(const SkRRect& rrect, const SkPaint& paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000466 fRRect = rrect;
467 fPaint = paint;
468 fDrawType = DRAW_RRECT;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000469
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000470 fInfo.push(SkObjectParser::RRectToString(rrect));
471 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000472}
473
474void DrawRRect::execute(SkCanvas* canvas) {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000475 canvas->drawRRect(fRRect, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000476}
477
chudy@google.com902ebe52012-06-29 14:21:22 +0000478DrawSprite::DrawSprite(const SkBitmap& bitmap, int left, int top,
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000479 const SkPaint* paint, SkBitmap& resizedBitmap) {
480 fBitmap = bitmap;
481 fLeft = left;
482 fTop = top;
483 if (NULL != paint) {
484 fPaint = *paint;
485 fPaintPtr = &fPaint;
486 } else {
487 fPaintPtr = NULL;
488 }
489 fDrawType = DRAW_SPRITE;
490 fResizedBitmap = resizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000491
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000492 fInfo.push(SkObjectParser::BitmapToString(bitmap));
493 fInfo.push(SkObjectParser::IntToString(left, "Left: "));
494 fInfo.push(SkObjectParser::IntToString(top, "Top: "));
495 if (NULL != paint) {
496 fInfo.push(SkObjectParser::PaintToString(*paint));
497 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000498}
499
500void DrawSprite::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000501 canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000502}
503
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000504const SkBitmap* DrawSprite::getBitmap() const {
505 return &fResizedBitmap;
506}
507
chudy@google.com902ebe52012-06-29 14:21:22 +0000508DrawTextC::DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y,
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000509 const SkPaint& paint) {
510 fText = new char[byteLength];
511 memcpy(fText, text, byteLength);
512 fByteLength = byteLength;
513 fX = x;
514 fY = y;
515 fPaint = paint;
516 fDrawType = DRAW_TEXT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000517
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000518 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
519 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
520 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
521 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000522}
523
524void DrawTextC::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000525 canvas->drawText(fText, fByteLength, fX, fY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000526}
527
528DrawTextOnPath::DrawTextOnPath(const void* text, size_t byteLength,
skia.committer@gmail.come60ed082013-03-26 07:01:04 +0000529 const SkPath& path, const SkMatrix* matrix,
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000530 const SkPaint& paint) {
531 fText = new char[byteLength];
532 memcpy(fText, text, byteLength);
533 fByteLength = byteLength;
534 fPath = path;
535 if (NULL != matrix) {
536 fMatrix = *matrix;
537 } else {
538 fMatrix.setIdentity();
539 }
540 fPaint = paint;
541 fDrawType = DRAW_TEXT_ON_PATH;
chudy@google.com902ebe52012-06-29 14:21:22 +0000542
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000543 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
544 fInfo.push(SkObjectParser::PathToString(path));
545 if (NULL != matrix) {
546 fInfo.push(SkObjectParser::MatrixToString(*matrix));
547 }
548 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000549}
550
551void DrawTextOnPath::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000552 canvas->drawTextOnPath(fText, fByteLength, fPath,
553 fMatrix.isIdentity() ? NULL : &fMatrix,
554 fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000555}
556
557DrawVertices::DrawVertices(SkCanvas::VertexMode vmode, int vertexCount,
skia.committer@gmail.come60ed082013-03-26 07:01:04 +0000558 const SkPoint vertices[], const SkPoint texs[],
559 const SkColor colors[], SkXfermode* xfermode,
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000560 const uint16_t indices[], int indexCount,
561 const SkPaint& paint) {
562 fVmode = vmode;
563
564 fVertexCount = vertexCount;
565
566 fVertices = new SkPoint[vertexCount];
567 memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
568
569 if (NULL != texs) {
570 fTexs = new SkPoint[vertexCount];
571 memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
572 } else {
573 fTexs = NULL;
574 }
575
576 if (NULL != colors) {
577 fColors = new SkColor[vertexCount];
578 memcpy(fColors, colors, vertexCount * sizeof(SkColor));
579 } else {
580 fColors = NULL;
581 }
582
583 fXfermode = xfermode;
584 if (NULL != fXfermode) {
585 fXfermode->ref();
586 }
587
588 if (indexCount > 0) {
589 fIndices = new uint16_t[indexCount];
590 memcpy(fIndices, indices, indexCount * sizeof(uint16_t));
591 } else {
592 fIndices = NULL;
593 }
594
595 fIndexCount = indexCount;
596 fPaint = paint;
597 fDrawType = DRAW_VERTICES;
598
chudy@google.com902ebe52012-06-29 14:21:22 +0000599 // TODO(chudy)
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000600 fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
601 fInfo.push(SkObjectParser::PaintToString(paint));
602}
603
604DrawVertices::~DrawVertices() {
605 delete [] fVertices;
606 delete [] fTexs;
607 delete [] fColors;
608 SkSafeUnref(fXfermode);
609 delete [] fIndices;
chudy@google.com902ebe52012-06-29 14:21:22 +0000610}
611
612void DrawVertices::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000613 canvas->drawVertices(fVmode, fVertexCount, fVertices,
614 fTexs, fColors, fXfermode, fIndices,
615 fIndexCount, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000616}
617
618Restore::Restore() {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000619 fDrawType = RESTORE;
620 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000621}
622
623void Restore::execute(SkCanvas* canvas) {
624 canvas->restore();
625}
626
tomhudson@google.com0699e022012-11-27 16:09:42 +0000627void Restore::trackSaveState(int* state) {
628 (*state)--;
629}
630
chudy@google.com902ebe52012-06-29 14:21:22 +0000631Rotate::Rotate(SkScalar degrees) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000632 fDegrees = degrees;
633 fDrawType = ROTATE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000634
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000635 fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000636}
637
638void Rotate::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000639 canvas->rotate(fDegrees);
chudy@google.com902ebe52012-06-29 14:21:22 +0000640}
641
642Save::Save(SkCanvas::SaveFlags flags) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000643 fFlags = flags;
644 fDrawType = SAVE;
645 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000646}
647
648void Save::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000649 canvas->save(fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000650}
651
tomhudson@google.com0699e022012-11-27 16:09:42 +0000652void Save::trackSaveState(int* state) {
653 (*state)++;
654}
655
chudy@google.com902ebe52012-06-29 14:21:22 +0000656SaveLayer::SaveLayer(const SkRect* bounds, const SkPaint* paint,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000657 SkCanvas::SaveFlags flags) {
658 if (NULL != bounds) {
659 fBounds = *bounds;
660 } else {
661 fBounds.setEmpty();
662 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000663
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000664 if (NULL != paint) {
665 fPaint = *paint;
666 fPaintPtr = &fPaint;
667 } else {
668 fPaintPtr = NULL;
669 }
670 fFlags = flags;
671 fDrawType = SAVE_LAYER;
672
673 if (NULL != bounds) {
674 fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
675 }
676 if (NULL != paint) {
677 fInfo.push(SkObjectParser::PaintToString(*paint));
678 }
679 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000680}
681
682void SaveLayer::execute(SkCanvas* canvas) {
skia.committer@gmail.com7e328512013-03-23 07:01:28 +0000683 canvas->saveLayer(fBounds.isEmpty() ? NULL : &fBounds,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000684 fPaintPtr,
685 fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000686}
687
tomhudson@google.com0699e022012-11-27 16:09:42 +0000688void SaveLayer::trackSaveState(int* state) {
689 (*state)++;
690}
691
chudy@google.com902ebe52012-06-29 14:21:22 +0000692Scale::Scale(SkScalar sx, SkScalar sy) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000693 fSx = sx;
694 fSy = sy;
695 fDrawType = SCALE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000696
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000697 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
698 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000699}
700
701void Scale::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000702 canvas->scale(fSx, fSy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000703}
704
705SetMatrix::SetMatrix(const SkMatrix& matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000706 fMatrix = matrix;
707 fDrawType = SET_MATRIX;
chudy@google.com902ebe52012-06-29 14:21:22 +0000708
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000709 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000710}
711
712void SetMatrix::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000713 canvas->setMatrix(fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000714}
715
716Skew::Skew(SkScalar sx, SkScalar sy) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000717 fSx = sx;
718 fSy = sy;
719 fDrawType = SKEW;
chudy@google.com902ebe52012-06-29 14:21:22 +0000720
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000721 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
722 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000723}
724
725void Skew::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000726 canvas->skew(fSx, fSy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000727}
728
729Translate::Translate(SkScalar dx, SkScalar dy) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000730 fDx = dx;
731 fDy = dy;
732 fDrawType = TRANSLATE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000733
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000734 fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: "));
735 fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000736}
737
738void Translate::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000739 canvas->translate(fDx, fDy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000740}