blob: 36459023acaacd79ad5fe01397096f0fbdc6e6a6 [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,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000187 const SkMatrix& matrix,
188 const SkPaint* paint,
189 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,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000217 const SkRect& dst, const SkPaint* paint,
218 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) {
286 this->fData = data;
287 this->fLength = length;
288 this->fDrawType = DRAW_DATA;
289 // TODO(chudy): See if we can't display data and length.
290}
291
292void DrawData::execute(SkCanvas* canvas) {
293 canvas->drawData(this->fData, this->fLength);
294}
295
robertphillips@google.com67baba42013-01-02 20:20:31 +0000296DrawOval::DrawOval(const SkRect& oval, const SkPaint& paint) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000297 fOval = oval;
298 fPaint = paint;
299 fDrawType = DRAW_OVAL;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000300
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000301 fInfo.push(SkObjectParser::RectToString(oval));
302 fInfo.push(SkObjectParser::PaintToString(paint));
robertphillips@google.com67baba42013-01-02 20:20:31 +0000303}
304
305void DrawOval::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000306 canvas->drawOval(fOval, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000307}
308
chudy@google.com902ebe52012-06-29 14:21:22 +0000309DrawPaint::DrawPaint(const SkPaint& paint) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000310 fPaint = paint;
311 fDrawType = DRAW_PAINT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000312
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000313 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000314}
315
316void DrawPaint::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000317 canvas->drawPaint(fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000318}
319
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000320DrawPath::DrawPath(const SkPath& path, const SkPaint& paint, SkBitmap& bitmap) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000321 fPath = path;
322 fPaint = paint;
323 fBitmap = bitmap;
324 fDrawType = DRAW_PATH;
chudy@google.com902ebe52012-06-29 14:21:22 +0000325
robertphillips@google.com91217d02013-03-17 18:33:46 +0000326 fInfo.push(SkObjectParser::PathToString(path));
327 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000328}
329
330void DrawPath::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000331 canvas->drawPath(fPath, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000332}
333
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000334const SkBitmap* DrawPath::getBitmap() const {
335 return &fBitmap;
336}
337
chudy@google.com902ebe52012-06-29 14:21:22 +0000338DrawPicture::DrawPicture(SkPicture& picture) {
339 this->fPicture = &picture;
340 this->fDrawType = DRAW_PICTURE;
chudy@google.com97cee972012-08-07 20:41:37 +0000341 this->fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
chudy@google.com902ebe52012-06-29 14:21:22 +0000342}
343
344void DrawPicture::execute(SkCanvas* canvas) {
345 canvas->drawPicture(*this->fPicture);
346}
347
348DrawPoints::DrawPoints(SkCanvas::PointMode mode, size_t count,
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000349 const SkPoint pts[], const SkPaint& paint) {
350 fMode = mode;
351 fCount = count;
352 fPts = new SkPoint[count];
353 memcpy(fPts, pts, count * sizeof(SkPoint));
354 fPaint = paint;
355 fDrawType = DRAW_POINTS;
chudy@google.com902ebe52012-06-29 14:21:22 +0000356
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000357 fInfo.push(SkObjectParser::PointsToString(pts, count));
358 fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
359 "Points: "));
360 fInfo.push(SkObjectParser::PointModeToString(mode));
361 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000362}
363
364void DrawPoints::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000365 canvas->drawPoints(fMode, fCount, fPts, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000366}
367
368DrawPosText::DrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000369 const SkPaint& paint) {
370 size_t numPts = paint.countText(text, byteLength);
chudy@google.com902ebe52012-06-29 14:21:22 +0000371
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000372 fText = new char[byteLength];
373 memcpy(fText, text, byteLength);
374 fByteLength = byteLength;
375
376 fPos = new SkPoint[numPts];
377 memcpy(fPos, pos, numPts * sizeof(SkPoint));
378
379 fPaint = paint;
380 fDrawType = DRAW_POS_TEXT;
381
382 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000383 // TODO(chudy): Test that this works.
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000384 fInfo.push(SkObjectParser::PointsToString(pos, 1));
385 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000386}
387
388void DrawPosText::execute(SkCanvas* canvas) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000389 canvas->drawPosText(fText, fByteLength, fPos, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000390}
391
392
393DrawPosTextH::DrawPosTextH(const void* text, size_t byteLength,
skia.committer@gmail.comc76bb232013-03-18 07:01:03 +0000394 const SkScalar xpos[], SkScalar constY,
robertphillips@google.com91217d02013-03-17 18:33:46 +0000395 const SkPaint& paint) {
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000396 size_t numPts = paint.countText(text, byteLength);
397
398 fText = new char[byteLength];
399 memcpy(fText, text, byteLength);
robertphillips@google.com91217d02013-03-17 18:33:46 +0000400 fByteLength = byteLength;
robertphillips@google.coma3a09ab2013-03-22 12:25:30 +0000401
402 fXpos = new SkScalar[numPts];
403 memcpy(fXpos, xpos, numPts * sizeof(SkScalar));
404
robertphillips@google.com91217d02013-03-17 18:33:46 +0000405 fConstY = constY;
406 fPaint = paint;
407 fDrawType = DRAW_POS_TEXT_H;
chudy@google.com902ebe52012-06-29 14:21:22 +0000408
robertphillips@google.com91217d02013-03-17 18:33:46 +0000409 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
410 fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
411 fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
412 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000413}
414
415void DrawPosTextH::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000416 canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000417}
418
419DrawRectC::DrawRectC(const SkRect& rect, const SkPaint& paint) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000420 fRect = rect;
421 fPaint = paint;
422 fDrawType = DRAW_RECT;
chudy@google.com902ebe52012-06-29 14:21:22 +0000423
robertphillips@google.com91217d02013-03-17 18:33:46 +0000424 fInfo.push(SkObjectParser::RectToString(rect));
425 fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000426}
427
428void DrawRectC::execute(SkCanvas* canvas) {
robertphillips@google.com91217d02013-03-17 18:33:46 +0000429 canvas->drawRect(fRect, fPaint);
chudy@google.com902ebe52012-06-29 14:21:22 +0000430}
431
robertphillips@google.com67baba42013-01-02 20:20:31 +0000432DrawRRect::DrawRRect(const SkRRect& rrect, const SkPaint& paint) {
433 this->fRRect = rrect;
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000434 this->fPaint = paint;
robertphillips@google.com67baba42013-01-02 20:20:31 +0000435 this->fDrawType = DRAW_RRECT;
436
437 this->fInfo.push(SkObjectParser::RRectToString(rrect));
438 this->fInfo.push(SkObjectParser::PaintToString(paint));
439}
440
441void DrawRRect::execute(SkCanvas* canvas) {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000442 canvas->drawRRect(fRRect, fPaint);
robertphillips@google.com67baba42013-01-02 20:20:31 +0000443}
444
chudy@google.com902ebe52012-06-29 14:21:22 +0000445DrawSprite::DrawSprite(const SkBitmap& bitmap, int left, int top,
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000446 const SkPaint* paint, SkBitmap& resizedBitmap) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000447 this->fBitmap = &bitmap;
448 this->fLeft = left;
449 this->fTop = top;
450 this->fPaint = paint;
451 this->fDrawType = DRAW_SPRITE;
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000452 this->fResizedBitmap = resizedBitmap;
chudy@google.com902ebe52012-06-29 14:21:22 +0000453
chudy@google.com97cee972012-08-07 20:41:37 +0000454 this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
455 this->fInfo.push(SkObjectParser::IntToString(left, "Left: "));
456 this->fInfo.push(SkObjectParser::IntToString(top, "Top: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000457}
458
459void DrawSprite::execute(SkCanvas* canvas) {
460 canvas->drawSprite(*this->fBitmap, this->fLeft, this->fTop, this->fPaint);
461}
462
robertphillips@google.com53ec73d2012-11-26 13:09:17 +0000463const SkBitmap* DrawSprite::getBitmap() const {
464 return &fResizedBitmap;
465}
466
chudy@google.com902ebe52012-06-29 14:21:22 +0000467DrawTextC::DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y,
468 const SkPaint& paint) {
469 this->fText = text;
470 this->fByteLength = byteLength;
471 this->fX = x;
472 this->fY = y;
473 this->fPaint = &paint;
474 this->fDrawType = DRAW_TEXT;
475
bungeman@google.com428fc4a2013-03-07 20:30:32 +0000476 this->fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com97cee972012-08-07 20:41:37 +0000477 this->fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
478 this->fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
479 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000480}
481
482void DrawTextC::execute(SkCanvas* canvas) {
483 canvas->drawText(this->fText, this->fByteLength, this->fX, this->fY, *this->fPaint);
484}
485
486DrawTextOnPath::DrawTextOnPath(const void* text, size_t byteLength,
487 const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) {
488 this->fText = text;
489 this->fByteLength = byteLength;
490 this->fPath = &path;
491 this->fMatrix = matrix;
492 this->fPaint = &paint;
493 this->fDrawType = DRAW_TEXT_ON_PATH;
494
bungeman@google.com428fc4a2013-03-07 20:30:32 +0000495 this->fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
chudy@google.com97cee972012-08-07 20:41:37 +0000496 this->fInfo.push(SkObjectParser::PathToString(path));
497 if (matrix) this->fInfo.push(SkObjectParser::MatrixToString(*matrix));
498 this->fInfo.push(SkObjectParser::PaintToString(paint));
chudy@google.com902ebe52012-06-29 14:21:22 +0000499}
500
501void DrawTextOnPath::execute(SkCanvas* canvas) {
502 canvas->drawTextOnPath(this->fText, this->fByteLength, *this->fPath,
503 this->fMatrix, *this->fPaint);
504}
505
506DrawVertices::DrawVertices(SkCanvas::VertexMode vmode, int vertexCount,
507 const SkPoint vertices[], const SkPoint texs[], const SkColor colors[],
508 SkXfermode* xfermode, const uint16_t indices[], int indexCount,
509 const SkPaint& paint) {
510 this->fVmode = vmode;
511 this->fVertexCount = vertexCount;
512 this->fTexs = texs;
513 this->fColors = colors;
514 this->fXfermode = xfermode;
515 this->fIndices = indices;
516 this->fIndexCount = indexCount;
517 this->fPaint = &paint;
518 this->fDrawType = DRAW_VERTICES;
519 // TODO(chudy)
chudy@google.com97cee972012-08-07 20:41:37 +0000520 this->fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
chudy@google.com902ebe52012-06-29 14:21:22 +0000521}
522
523void DrawVertices::execute(SkCanvas* canvas) {
524 canvas->drawVertices(this->fVmode, this->fVertexCount, this->fVertices,
525 this->fTexs, this->fColors, this->fXfermode, this->fIndices,
526 this->fIndexCount, *this->fPaint);
527}
528
529Restore::Restore() {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000530 fDrawType = RESTORE;
531 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000532}
533
534void Restore::execute(SkCanvas* canvas) {
535 canvas->restore();
536}
537
tomhudson@google.com0699e022012-11-27 16:09:42 +0000538void Restore::trackSaveState(int* state) {
539 (*state)--;
540}
541
chudy@google.com902ebe52012-06-29 14:21:22 +0000542Rotate::Rotate(SkScalar degrees) {
543 this->fDegrees = degrees;
544 this->fDrawType = ROTATE;
545
chudy@google.com97cee972012-08-07 20:41:37 +0000546 this->fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000547}
548
549void Rotate::execute(SkCanvas* canvas) {
550 canvas->rotate(this->fDegrees);
551}
552
553Save::Save(SkCanvas::SaveFlags flags) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000554 fFlags = flags;
555 fDrawType = SAVE;
556 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000557}
558
559void Save::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000560 canvas->save(fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000561}
562
tomhudson@google.com0699e022012-11-27 16:09:42 +0000563void Save::trackSaveState(int* state) {
564 (*state)++;
565}
566
chudy@google.com902ebe52012-06-29 14:21:22 +0000567SaveLayer::SaveLayer(const SkRect* bounds, const SkPaint* paint,
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000568 SkCanvas::SaveFlags flags) {
569 if (NULL != bounds) {
570 fBounds = *bounds;
571 } else {
572 fBounds.setEmpty();
573 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000574
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000575 if (NULL != paint) {
576 fPaint = *paint;
577 fPaintPtr = &fPaint;
578 } else {
579 fPaintPtr = NULL;
580 }
581 fFlags = flags;
582 fDrawType = SAVE_LAYER;
583
584 if (NULL != bounds) {
585 fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
586 }
587 if (NULL != paint) {
588 fInfo.push(SkObjectParser::PaintToString(*paint));
589 }
590 fInfo.push(SkObjectParser::SaveFlagsToString(flags));
chudy@google.com902ebe52012-06-29 14:21:22 +0000591}
592
593void SaveLayer::execute(SkCanvas* canvas) {
robertphillips@google.com24bfdac2013-03-22 16:33:31 +0000594 canvas->saveLayer(fBounds.isEmpty() ? NULL : &fBounds,
595 fPaintPtr,
596 fFlags);
chudy@google.com902ebe52012-06-29 14:21:22 +0000597}
598
tomhudson@google.com0699e022012-11-27 16:09:42 +0000599void SaveLayer::trackSaveState(int* state) {
600 (*state)++;
601}
602
chudy@google.com902ebe52012-06-29 14:21:22 +0000603Scale::Scale(SkScalar sx, SkScalar sy) {
604 this->fSx = sx;
605 this->fSy = sy;
606 this->fDrawType = SCALE;
607
chudy@google.com97cee972012-08-07 20:41:37 +0000608 this->fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
609 this->fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000610}
611
612void Scale::execute(SkCanvas* canvas) {
613 canvas->scale(this->fSx, this->fSy);
614}
615
616SetMatrix::SetMatrix(const SkMatrix& matrix) {
robertphillips@google.comb94b1e72013-02-19 21:00:26 +0000617 this->fMatrix = matrix;
chudy@google.com902ebe52012-06-29 14:21:22 +0000618 this->fDrawType = SET_MATRIX;
619
chudy@google.com97cee972012-08-07 20:41:37 +0000620 this->fInfo.push(SkObjectParser::MatrixToString(matrix));
chudy@google.com902ebe52012-06-29 14:21:22 +0000621}
622
623void SetMatrix::execute(SkCanvas* canvas) {
robertphillips@google.comb94b1e72013-02-19 21:00:26 +0000624 canvas->setMatrix(this->fMatrix);
chudy@google.com902ebe52012-06-29 14:21:22 +0000625}
626
627Skew::Skew(SkScalar sx, SkScalar sy) {
628 this->fSx = sx;
629 this->fSy = sy;
630 this->fDrawType = SKEW;
631
chudy@google.com97cee972012-08-07 20:41:37 +0000632 this->fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
633 this->fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000634}
635
636void Skew::execute(SkCanvas* canvas) {
637 canvas->skew(this->fSx, this->fSy);
638}
639
640Translate::Translate(SkScalar dx, SkScalar dy) {
641 this->fDx = dx;
642 this->fDy = dy;
643 this->fDrawType = TRANSLATE;
644
chudy@google.com97cee972012-08-07 20:41:37 +0000645 this->fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: "));
646 this->fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: "));
chudy@google.com902ebe52012-06-29 14:21:22 +0000647}
648
649void Translate::execute(SkCanvas* canvas) {
650 canvas->translate(this->fDx, this->fDy);
651}