blob: e7936a2a21689ad7aa6367191eb060c195e397f9 [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
15SkDrawCommand::SkDrawCommand() {
16 fVisible = true;
17}
18
19SkDrawCommand::~SkDrawCommand() {
chudy@google.com97cee972012-08-07 20:41:37 +000020 fInfo.deleteAll();
chudy@google.com902ebe52012-06-29 14:21:22 +000021}
22
23const char* SkDrawCommand::GetCommandString(DrawType type) {
24 switch (type) {
25 case UNUSED: SkDEBUGFAIL("DrawType UNUSED\n"); break;
26 case DRAW_CLEAR: return "Clear";
27 case CLIP_PATH: return "Clip Path";
28 case CLIP_REGION: return "Clip Region";
29 case CLIP_RECT: return "Clip Rect";
robertphillips@google.com67baba42013-01-02 20:20:31 +000030 case CLIP_RRECT: return "Clip RRect";
chudy@google.com902ebe52012-06-29 14:21:22 +000031 case CONCAT: return "Concat";
32 case DRAW_BITMAP: return "Draw Bitmap";
33 case DRAW_BITMAP_MATRIX: return "Draw Bitmap Matrix";
34 case DRAW_BITMAP_NINE: return "Draw Bitmap Nine";
robertphillips@google.com84d320e2012-09-20 19:09:17 +000035 case DRAW_BITMAP_RECT_TO_RECT: return "Draw Bitmap Rect";
chudy@google.com902ebe52012-06-29 14:21:22 +000036 case DRAW_DATA: return "Draw Data";
robertphillips@google.com67baba42013-01-02 20:20:31 +000037 case DRAW_OVAL: return "Draw Oval";
chudy@google.com902ebe52012-06-29 14:21:22 +000038 case DRAW_PAINT: return "Draw Paint";
39 case DRAW_PATH: return "Draw Path";
40 case DRAW_PICTURE: return "Draw Picture";
41 case DRAW_POINTS: return "Draw Points";
42 case DRAW_POS_TEXT: return "Draw Pos Text";
43 case DRAW_POS_TEXT_H: return "Draw Pos Text H";
44 case DRAW_RECT: return "Draw Rect";
robertphillips@google.com67baba42013-01-02 20:20:31 +000045 case DRAW_RRECT: return "Draw RRect";
chudy@google.com902ebe52012-06-29 14:21:22 +000046 case DRAW_SPRITE: return "Draw Sprite";
47 case DRAW_TEXT: return "Draw Text";
48 case DRAW_TEXT_ON_PATH: return "Draw Text On Path";
49 case DRAW_VERTICES: return "Draw Vertices";
50 case RESTORE: return "Restore";
51 case ROTATE: return "Rotate";
52 case SAVE: return "Save";
53 case SAVE_LAYER: return "Save Layer";
54 case SCALE: return "Scale";
55 case SET_MATRIX: return "Set Matrix";
56 case SKEW: return "Skew";
57 case TRANSLATE: return "Translate";
robertphillips@google.come4ce5b82013-02-15 17:19:15 +000058 case NOOP: return "NoOp";
chudy@google.com902ebe52012-06-29 14:21:22 +000059 default:
60 SkDebugf("DrawType error 0x%08x\n", type);
61 SkASSERT(0);
62 break;
63 }
64 SkDEBUGFAIL("DrawType UNUSED\n");
65 return NULL;
66}
67
chudy@google.com97cee972012-08-07 20:41:37 +000068SkString SkDrawCommand::toString() {
69 return SkString(GetCommandString(fDrawType));
chudy@google.com902ebe52012-06-29 14:21:22 +000070}
71
72Clear::Clear(SkColor color) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000073 fColor = color;
74 fDrawType = DRAW_CLEAR;
75 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +000076}
77
78void Clear::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +000079 canvas->clear(fColor);
chudy@google.com902ebe52012-06-29 14:21:22 +000080}
81
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000082ClipPath::ClipPath(const SkPath& path, SkRegion::Op op, bool doAA, SkBitmap& bitmap) {
robertphillips@google.com91217d02013-03-17 18:33:46 +000083 fPath = path;
84 fOp = op;
85 fDoAA = doAA;
86 fDrawType = CLIP_PATH;
87 fBitmap = bitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +000088
robertphillips@google.com91217d02013-03-17 18:33:46 +000089 fInfo.push(SkObjectParser::PathToString(path));
90 fInfo.push(SkObjectParser::RegionOpToString(op));
91 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +000092}
93
94void ClipPath::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +000095 canvas->clipPath(fPath, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +000096}
97
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000098const SkBitmap* ClipPath::getBitmap() const {
99 return &fBitmap;
100}
101
chudy@google.com902ebe52012-06-29 14:21:22 +0000102ClipRegion::ClipRegion(const SkRegion& region, SkRegion::Op op) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000103 fRegion = region;
104 fOp = op;
105 fDrawType = CLIP_REGION;
chudy@google.com902ebe52012-06-29 14:21:22 +0000106
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000107 fInfo.push(SkObjectParser::RegionToString(region));
108 fInfo.push(SkObjectParser::RegionOpToString(op));
chudy@google.com902ebe52012-06-29 14:21:22 +0000109}
110
111void ClipRegion::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000112 canvas->clipRegion(fRegion, fOp);
chudy@google.com902ebe52012-06-29 14:21:22 +0000113}
114
115ClipRect::ClipRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000116 fRect = rect;
117 fOp = op;
118 fDoAA = doAA;
119 fDrawType = CLIP_RECT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000120
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000121 fInfo.push(SkObjectParser::RectToString(rect));
122 fInfo.push(SkObjectParser::RegionOpToString(op));
123 fInfo.push(SkObjectParser::BoolToString(doAA));
chudy@google.com902ebe52012-06-29 14:21:22 +0000124}
125
126void ClipRect::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000127 canvas->clipRect(fRect, fOp, fDoAA);
chudy@google.com902ebe52012-06-29 14:21:22 +0000128}
129
robertphillips@google.com67baba42013-01-02 20:20:31 +0000130ClipRRect::ClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000131 fRRect = rrect;
132 fOp = op;
133 fDoAA = doAA;
134 fDrawType = CLIP_RRECT;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000135
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000136 fInfo.push(SkObjectParser::RRectToString(rrect));
137 fInfo.push(SkObjectParser::RegionOpToString(op));
138 fInfo.push(SkObjectParser::BoolToString(doAA));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000139}
140
141void ClipRRect::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000142 canvas->clipRRect(fRRect, fOp, fDoAA);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000143}
144
chudy@google.com902ebe52012-06-29 14:21:22 +0000145Concat::Concat(const SkMatrix& matrix) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000146 fMatrix = matrix;
147 fDrawType = CONCAT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000148
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000149 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000150}
151
152void Concat::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000153 canvas->concat(fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000154}
155
156DrawBitmap::DrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000157 const SkPaint* paint, SkBitmap& resizedBitmap) {
158 fBitmap = bitmap;
159 fLeft = left;
160 fTop = top;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000161 if (NULL != paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000162 fPaint = *paint;
163 fPaintPtr = &fPaint;
164 } else {
165 fPaintPtr = NULL;
166 }
167 fDrawType = DRAW_BITMAP;
168 fResizedBitmap = resizedBitmap;
169
170 fInfo.push(SkObjectParser::BitmapToString(bitmap));
171 fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
172 fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: "));
173 if (NULL != paint) {
174 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000175 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000176}
177
178void DrawBitmap::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000179 canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000180}
181
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000182const SkBitmap* DrawBitmap::getBitmap() const {
183 return &fResizedBitmap;
184}
185
chudy@google.com902ebe52012-06-29 14:21:22 +0000186DrawBitmapMatrix::DrawBitmapMatrix(const SkBitmap& bitmap,
skia.committer@gmail.com7e328512013-03-23 07:01:28 +0000187 const SkMatrix& matrix,
188 const SkPaint* paint,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000189 SkBitmap& resizedBitmap) {
190 fBitmap = bitmap;
191 fMatrix = matrix;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000192 if (NULL != paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000193 fPaint = *paint;
194 fPaintPtr = &fPaint;
195 } else {
196 fPaintPtr = NULL;
197 }
198 fDrawType = DRAW_BITMAP_MATRIX;
199 fResizedBitmap = resizedBitmap;
200
201 fInfo.push(SkObjectParser::BitmapToString(bitmap));
202 fInfo.push(SkObjectParser::MatrixToString(matrix));
203 if (NULL != paint) {
204 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000205 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000206}
207
208void DrawBitmapMatrix::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000209 canvas->drawBitmapMatrix(fBitmap, fMatrix, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000210}
211
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000212const SkBitmap* DrawBitmapMatrix::getBitmap() const {
213 return &fResizedBitmap;
214}
215
chudy@google.com902ebe52012-06-29 14:21:22 +0000216DrawBitmapNine::DrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
skia.committer@gmail.com7e328512013-03-23 07:01:28 +0000217 const SkRect& dst, const SkPaint* paint,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000218 SkBitmap& resizedBitmap) {
219 fBitmap = bitmap;
220 fCenter = center;
221 fDst = dst;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000222 if (NULL != paint) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000223 fPaint = *paint;
224 fPaintPtr = &fPaint;
225 } else {
226 fPaintPtr = NULL;
227 }
228 fDrawType = DRAW_BITMAP_NINE;
229 fResizedBitmap = resizedBitmap;
230
231 fInfo.push(SkObjectParser::BitmapToString(bitmap));
232 fInfo.push(SkObjectParser::IRectToString(center));
233 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
234 if (NULL != paint) {
235 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000236 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000237}
238
239void DrawBitmapNine::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000240 canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000241}
242
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000243const SkBitmap* DrawBitmapNine::getBitmap() const {
244 return &fResizedBitmap;
245}
246
reed@google.com71121732012-09-18 15:14:33 +0000247DrawBitmapRect::DrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
skia.committer@gmail.comc76bb232013-03-18 07:01:03 +0000248 const SkRect& dst, const SkPaint* paint,
robertphillips@google.com91217d02013-03-17 18:33:46 +0000249 SkBitmap& resizedBitmap) {
250 fBitmap = bitmap;
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000251 if (NULL != src) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000252 fSrc = *src;
253 } else {
254 fSrc.setEmpty();
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000255 }
robertphillips@google.com91217d02013-03-17 18:33:46 +0000256 fDst = dst;
257
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000258 if (NULL != paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000259 fPaint = *paint;
260 fPaintPtr = &fPaint;
261 } else {
262 fPaintPtr = NULL;
263 }
264 fDrawType = DRAW_BITMAP_RECT_TO_RECT;
265 fResizedBitmap = resizedBitmap;
266
267 fInfo.push(SkObjectParser::BitmapToString(bitmap));
268 if (NULL != src) {
269 fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
270 }
271 fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
272 if (NULL != paint) {
273 fInfo.push(SkObjectParser::PaintToString(*paint));
robertphillips@google.comb83b6b42013-01-22 14:32:09 +0000274 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000275}
276
277void DrawBitmapRect::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000278 canvas->drawBitmapRectToRect(fBitmap, this->srcRect(), fDst, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000279}
280
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000281const SkBitmap* DrawBitmapRect::getBitmap() const {
282 return &fResizedBitmap;
283}
284
chudy@google.com902ebe52012-06-29 14:21:22 +0000285DrawData::DrawData(const void* data, size_t length) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000286 fData = new char[length];
287 memcpy(fData, data, length);
288 fLength = length;
289 fDrawType = DRAW_DATA;
290
291 // TODO: add display of actual data?
292 SkString* str = new SkString;
293 str->appendf("length: %d", length);
294 fInfo.push(str);
chudy@google.com902ebe52012-06-29 14:21:22 +0000295}
296
297void DrawData::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000298 canvas->drawData(fData, fLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000299}
300
robertphillips@google.com67baba42013-01-02 20:20:31 +0000301DrawOval::DrawOval(const SkRect& oval, const SkPaint& paint) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000302 fOval = oval;
303 fPaint = paint;
304 fDrawType = DRAW_OVAL;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000305
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000306 fInfo.push(SkObjectParser::RectToString(oval));
307 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000308}
309
310void DrawOval::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000311 canvas->drawOval(fOval, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000312}
313
chudy@google.com902ebe52012-06-29 14:21:22 +0000314DrawPaint::DrawPaint(const SkPaint& paint) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000315 fPaint = paint;
316 fDrawType = DRAW_PAINT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000317
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000318 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000319}
320
321void DrawPaint::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000322 canvas->drawPaint(fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000323}
324
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000325DrawPath::DrawPath(const SkPath& path, const SkPaint& paint, SkBitmap& bitmap) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000326 fPath = path;
327 fPaint = paint;
328 fBitmap = bitmap;
329 fDrawType = DRAW_PATH;
chudy@google.com902ebe52012-06-29 14:21:22 +0000330
robertphillips@google.com91217d02013-03-17 18:33:46 +0000331 fInfo.push(SkObjectParser::PathToString(path));
332 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000333}
334
335void DrawPath::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000336 canvas->drawPath(fPath, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000337}
338
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000339const SkBitmap* DrawPath::getBitmap() const {
340 return &fBitmap;
341}
342
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000343DrawPicture::DrawPicture(SkPicture& picture) :
344 fPicture(picture) {
345 fDrawType = DRAW_PICTURE;
346 fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
chudy@google.com902ebe52012-06-29 14:21:22 +0000347}
348
349void DrawPicture::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000350 canvas->drawPicture(fPicture);
chudy@google.com902ebe52012-06-29 14:21:22 +0000351}
352
353DrawPoints::DrawPoints(SkCanvas::PointMode mode, size_t count,
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000354 const SkPoint pts[], const SkPaint& paint) {
355 fMode = mode;
356 fCount = count;
357 fPts = new SkPoint[count];
358 memcpy(fPts, pts, count * sizeof(SkPoint));
359 fPaint = paint;
360 fDrawType = DRAW_POINTS;
chudy@google.com902ebe52012-06-29 14:21:22 +0000361
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000362 fInfo.push(SkObjectParser::PointsToString(pts, count));
363 fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
364 "Points: "));
365 fInfo.push(SkObjectParser::PointModeToString(mode));
366 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000367}
368
369void DrawPoints::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000370 canvas->drawPoints(fMode, fCount, fPts, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000371}
372
373DrawPosText::DrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000374 const SkPaint& paint) {
375 size_t numPts = paint.countText(text, byteLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000376
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000377 fText = new char[byteLength];
378 memcpy(fText, text, byteLength);
379 fByteLength = byteLength;
380
381 fPos = new SkPoint[numPts];
382 memcpy(fPos, pos, numPts * sizeof(SkPoint));
383
384 fPaint = paint;
385 fDrawType = DRAW_POS_TEXT;
386
387 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000388 // TODO(chudy): Test that this works.
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000389 fInfo.push(SkObjectParser::PointsToString(pos, 1));
390 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000391}
392
393void DrawPosText::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000394 canvas->drawPosText(fText, fByteLength, fPos, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000395}
396
397
398DrawPosTextH::DrawPosTextH(const void* text, size_t byteLength,
skia.committer@gmail.comc76bb232013-03-18 07:01:03 +0000399 const SkScalar xpos[], SkScalar constY,
robertphillips@google.com91217d02013-03-17 18:33:46 +0000400 const SkPaint& paint) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000401 size_t numPts = paint.countText(text, byteLength);
402
403 fText = new char[byteLength];
404 memcpy(fText, text, byteLength);
robertphillips@google.com91217d02013-03-17 18:33:46 +0000405 fByteLength = byteLength;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000406
407 fXpos = new SkScalar[numPts];
408 memcpy(fXpos, xpos, numPts * sizeof(SkScalar));
409
robertphillips@google.com91217d02013-03-17 18:33:46 +0000410 fConstY = constY;
411 fPaint = paint;
412 fDrawType = DRAW_POS_TEXT_H;
chudy@google.com902ebe52012-06-29 14:21:22 +0000413
robertphillips@google.com91217d02013-03-17 18:33:46 +0000414 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
415 fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
416 fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
417 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000418}
419
420void DrawPosTextH::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000421 canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000422}
423
424DrawRectC::DrawRectC(const SkRect& rect, const SkPaint& paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000425 fRect = rect;
426 fPaint = paint;
427 fDrawType = DRAW_RECT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000428
robertphillips@google.com91217d02013-03-17 18:33:46 +0000429 fInfo.push(SkObjectParser::RectToString(rect));
430 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000431}
432
433void DrawRectC::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000434 canvas->drawRect(fRect, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000435}
436
robertphillips@google.com67baba42013-01-02 20:20:31 +0000437DrawRRect::DrawRRect(const SkRRect& rrect, const SkPaint& paint) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000438 fRRect = rrect;
439 fPaint = paint;
440 fDrawType = DRAW_RRECT;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000441
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000442 fInfo.push(SkObjectParser::RRectToString(rrect));
443 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000444}
445
446void DrawRRect::execute(SkCanvas* canvas) {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000447 canvas->drawRRect(fRRect, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000448}
449
chudy@google.com902ebe52012-06-29 14:21:22 +0000450DrawSprite::DrawSprite(const SkBitmap& bitmap, int left, int top,
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000451 const SkPaint* paint, SkBitmap& resizedBitmap) {
452 fBitmap = bitmap;
453 fLeft = left;
454 fTop = top;
455 if (NULL != paint) {
456 fPaint = *paint;
457 fPaintPtr = &fPaint;
458 } else {
459 fPaintPtr = NULL;
460 }
461 fDrawType = DRAW_SPRITE;
462 fResizedBitmap = resizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000463
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000464 fInfo.push(SkObjectParser::BitmapToString(bitmap));
465 fInfo.push(SkObjectParser::IntToString(left, "Left: "));
466 fInfo.push(SkObjectParser::IntToString(top, "Top: "));
467 if (NULL != paint) {
468 fInfo.push(SkObjectParser::PaintToString(*paint));
469 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000470}
471
472void DrawSprite::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000473 canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr);
chudy@google.com902ebe52012-06-29 14:21:22 +0000474}
475
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000476const SkBitmap* DrawSprite::getBitmap() const {
477 return &fResizedBitmap;
478}
479
chudy@google.com902ebe52012-06-29 14:21:22 +0000480DrawTextC::DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y,
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000481 const SkPaint& paint) {
482 fText = new char[byteLength];
483 memcpy(fText, text, byteLength);
484 fByteLength = byteLength;
485 fX = x;
486 fY = y;
487 fPaint = paint;
488 fDrawType = DRAW_TEXT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000489
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000490 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
491 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
492 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
493 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000494}
495
496void DrawTextC::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000497 canvas->drawText(fText, fByteLength, fX, fY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000498}
499
500DrawTextOnPath::DrawTextOnPath(const void* text, size_t byteLength,
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000501 const SkPath& path, const SkMatrix* matrix,
502 const SkPaint& paint) {
503 fText = new char[byteLength];
504 memcpy(fText, text, byteLength);
505 fByteLength = byteLength;
506 fPath = path;
507 if (NULL != matrix) {
508 fMatrix = *matrix;
509 } else {
510 fMatrix.setIdentity();
511 }
512 fPaint = paint;
513 fDrawType = DRAW_TEXT_ON_PATH;
chudy@google.com902ebe52012-06-29 14:21:22 +0000514
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000515 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
516 fInfo.push(SkObjectParser::PathToString(path));
517 if (NULL != matrix) {
518 fInfo.push(SkObjectParser::MatrixToString(*matrix));
519 }
520 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000521}
522
523void DrawTextOnPath::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000524 canvas->drawTextOnPath(fText, fByteLength, fPath,
525 fMatrix.isIdentity() ? NULL : &fMatrix,
526 fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000527}
528
529DrawVertices::DrawVertices(SkCanvas::VertexMode vmode, int vertexCount,
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000530 const SkPoint vertices[], const SkPoint texs[],
531 const SkColor colors[], SkXfermode* xfermode,
532 const uint16_t indices[], int indexCount,
533 const SkPaint& paint) {
534 fVmode = vmode;
535
536 fVertexCount = vertexCount;
537
538 fVertices = new SkPoint[vertexCount];
539 memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
540
541 if (NULL != texs) {
542 fTexs = new SkPoint[vertexCount];
543 memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
544 } else {
545 fTexs = NULL;
546 }
547
548 if (NULL != colors) {
549 fColors = new SkColor[vertexCount];
550 memcpy(fColors, colors, vertexCount * sizeof(SkColor));
551 } else {
552 fColors = NULL;
553 }
554
555 fXfermode = xfermode;
556 if (NULL != fXfermode) {
557 fXfermode->ref();
558 }
559
560 if (indexCount > 0) {
561 fIndices = new uint16_t[indexCount];
562 memcpy(fIndices, indices, indexCount * sizeof(uint16_t));
563 } else {
564 fIndices = NULL;
565 }
566
567 fIndexCount = indexCount;
568 fPaint = paint;
569 fDrawType = DRAW_VERTICES;
570
chudy@google.com902ebe52012-06-29 14:21:22 +0000571 // TODO(chudy)
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000572 fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
573 fInfo.push(SkObjectParser::PaintToString(paint));
574}
575
576DrawVertices::~DrawVertices() {
577 delete [] fVertices;
578 delete [] fTexs;
579 delete [] fColors;
580 SkSafeUnref(fXfermode);
581 delete [] fIndices;
chudy@google.com902ebe52012-06-29 14:21:22 +0000582}
583
584void DrawVertices::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000585 canvas->drawVertices(fVmode, fVertexCount, fVertices,
586 fTexs, fColors, fXfermode, fIndices,
587 fIndexCount, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000588}
589
590Restore::Restore() {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000591 fDrawType = RESTORE;
592 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000593}
594
595void Restore::execute(SkCanvas* canvas) {
596 canvas->restore();
597}
598
tomhudson@google.com0699e022012-11-27 16:09:42 +0000599void Restore::trackSaveState(int* state) {
600 (*state)--;
601}
602
chudy@google.com902ebe52012-06-29 14:21:22 +0000603Rotate::Rotate(SkScalar degrees) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000604 fDegrees = degrees;
605 fDrawType = ROTATE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000606
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000607 fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000608}
609
610void Rotate::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000611 canvas->rotate(fDegrees);
chudy@google.com902ebe52012-06-29 14:21:22 +0000612}
613
614Save::Save(SkCanvas::SaveFlags flags) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000615 fFlags = flags;
616 fDrawType = SAVE;
617 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000618}
619
620void Save::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000621 canvas->save(fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000622}
623
tomhudson@google.com0699e022012-11-27 16:09:42 +0000624void Save::trackSaveState(int* state) {
625 (*state)++;
626}
627
chudy@google.com902ebe52012-06-29 14:21:22 +0000628SaveLayer::SaveLayer(const SkRect* bounds, const SkPaint* paint,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000629 SkCanvas::SaveFlags flags) {
630 if (NULL != bounds) {
631 fBounds = *bounds;
632 } else {
633 fBounds.setEmpty();
634 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000635
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000636 if (NULL != paint) {
637 fPaint = *paint;
638 fPaintPtr = &fPaint;
639 } else {
640 fPaintPtr = NULL;
641 }
642 fFlags = flags;
643 fDrawType = SAVE_LAYER;
644
645 if (NULL != bounds) {
646 fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
647 }
648 if (NULL != paint) {
649 fInfo.push(SkObjectParser::PaintToString(*paint));
650 }
651 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000652}
653
654void SaveLayer::execute(SkCanvas* canvas) {
skia.committer@gmail.com7e328512013-03-23 07:01:28 +0000655 canvas->saveLayer(fBounds.isEmpty() ? NULL : &fBounds,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000656 fPaintPtr,
657 fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000658}
659
tomhudson@google.com0699e022012-11-27 16:09:42 +0000660void SaveLayer::trackSaveState(int* state) {
661 (*state)++;
662}
663
chudy@google.com902ebe52012-06-29 14:21:22 +0000664Scale::Scale(SkScalar sx, SkScalar sy) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000665 fSx = sx;
666 fSy = sy;
667 fDrawType = SCALE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000668
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000669 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
670 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000671}
672
673void Scale::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000674 canvas->scale(fSx, fSy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000675}
676
677SetMatrix::SetMatrix(const SkMatrix& matrix) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000678 fMatrix = matrix;
679 fDrawType = SET_MATRIX;
chudy@google.com902ebe52012-06-29 14:21:22 +0000680
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000681 fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000682}
683
684void SetMatrix::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000685 canvas->setMatrix(fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000686}
687
688Skew::Skew(SkScalar sx, SkScalar sy) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000689 fSx = sx;
690 fSy = sy;
691 fDrawType = SKEW;
chudy@google.com902ebe52012-06-29 14:21:22 +0000692
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000693 fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
694 fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000695}
696
697void Skew::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000698 canvas->skew(fSx, fSy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000699}
700
701Translate::Translate(SkScalar dx, SkScalar dy) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000702 fDx = dx;
703 fDy = dy;
704 fDrawType = TRANSLATE;
chudy@google.com902ebe52012-06-29 14:21:22 +0000705
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000706 fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: "));
707 fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000708}
709
710void Translate::execute(SkCanvas* canvas) {
robertphillips@google.com0df2a9a2013-03-25 11:50:42 +0000711 canvas->translate(fDx, fDy);
chudy@google.com902ebe52012-06-29 14:21:22 +0000712}