OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #ifndef SKDRAWCOMMAND_H_ | 9 #ifndef SKDRAWCOMMAND_H_ |
10 #define SKDRAWCOMMAND_H_ | 10 #define SKDRAWCOMMAND_H_ |
11 | 11 |
12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
13 #include "SkTLazy.h" | 13 #include "SkTLazy.h" |
14 #include "SkPath.h" | 14 #include "SkPath.h" |
15 #include "SkRRect.h" | 15 #include "SkRRect.h" |
16 #include "SkString.h" | 16 #include "SkString.h" |
17 #include "SkTDArray.h" | 17 #include "SkTDArray.h" |
| 18 #include "SkJSONCPP.h" |
18 | 19 |
19 class SK_API SkDrawCommand { | 20 class SK_API SkDrawCommand { |
20 public: | 21 public: |
21 enum OpType { | 22 enum OpType { |
22 kBeginDrawPicture_OpType, | 23 kBeginDrawPicture_OpType, |
23 kClipPath_OpType, | 24 kClipPath_OpType, |
24 kClipRegion_OpType, | 25 kClipRegion_OpType, |
25 kClipRect_OpType, | 26 kClipRect_OpType, |
26 kClipRRect_OpType, | 27 kClipRRect_OpType, |
27 kConcat_OpType, | 28 kConcat_OpType, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 kPushLayer_Action, | 93 kPushLayer_Action, |
93 }; | 94 }; |
94 virtual Action action() const { return kNone_Action; } | 95 virtual Action action() const { return kNone_Action; } |
95 virtual void setActive(bool active) {} | 96 virtual void setActive(bool active) {} |
96 virtual bool active() const { return false; } | 97 virtual bool active() const { return false; } |
97 | 98 |
98 OpType getType() const { return fOpType; } | 99 OpType getType() const { return fOpType; } |
99 | 100 |
100 virtual bool render(SkCanvas* canvas) const { return false; } | 101 virtual bool render(SkCanvas* canvas) const { return false; } |
101 | 102 |
| 103 virtual Json::Value toJSON() const; |
| 104 |
| 105 /* Converts a JSON representation of a command into a newly-allocated SkDraw
Command object. It |
| 106 * is the caller's responsibility to delete this object. This method may ret
urn null if an error |
| 107 * occurs. |
| 108 */ |
| 109 static SkDrawCommand* fromJSON(Json::Value& command); |
| 110 |
102 static const char* GetCommandString(OpType type); | 111 static const char* GetCommandString(OpType type); |
103 | 112 |
104 protected: | 113 protected: |
105 SkTDArray<SkString*> fInfo; | 114 SkTDArray<SkString*> fInfo; |
106 | 115 |
107 private: | 116 private: |
108 OpType fOpType; | 117 OpType fOpType; |
109 bool fVisible; | 118 bool fVisible; |
110 }; | 119 }; |
111 | 120 |
112 class SkRestoreCommand : public SkDrawCommand { | 121 class SkRestoreCommand : public SkDrawCommand { |
113 public: | 122 public: |
114 SkRestoreCommand(); | 123 SkRestoreCommand(); |
115 void execute(SkCanvas* canvas) const override; | 124 void execute(SkCanvas* canvas) const override; |
116 Action action() const override { return kPopLayer_Action; } | 125 Action action() const override { return kPopLayer_Action; } |
| 126 static SkRestoreCommand* fromJSON(Json::Value& command); |
117 | 127 |
118 private: | 128 private: |
119 typedef SkDrawCommand INHERITED; | 129 typedef SkDrawCommand INHERITED; |
120 }; | 130 }; |
121 | 131 |
122 class SkClearCommand : public SkDrawCommand { | 132 class SkClearCommand : public SkDrawCommand { |
123 public: | 133 public: |
124 SkClearCommand(SkColor color); | 134 SkClearCommand(SkColor color); |
125 void execute(SkCanvas* canvas) const override; | 135 void execute(SkCanvas* canvas) const override; |
| 136 Json::Value toJSON() const override; |
| 137 static SkClearCommand* fromJSON(Json::Value& command); |
| 138 |
126 private: | 139 private: |
127 SkColor fColor; | 140 SkColor fColor; |
128 | 141 |
129 typedef SkDrawCommand INHERITED; | 142 typedef SkDrawCommand INHERITED; |
130 }; | 143 }; |
131 | 144 |
132 class SkClipPathCommand : public SkDrawCommand { | 145 class SkClipPathCommand : public SkDrawCommand { |
133 public: | 146 public: |
134 SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool doAA); | 147 SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool doAA); |
135 void execute(SkCanvas* canvas) const override; | 148 void execute(SkCanvas* canvas) const override; |
136 bool render(SkCanvas* canvas) const override; | 149 bool render(SkCanvas* canvas) const override; |
| 150 Json::Value toJSON() const override; |
| 151 static SkClipPathCommand* fromJSON(Json::Value& command); |
| 152 |
137 private: | 153 private: |
138 SkPath fPath; | 154 SkPath fPath; |
139 SkRegion::Op fOp; | 155 SkRegion::Op fOp; |
140 bool fDoAA; | 156 bool fDoAA; |
141 | 157 |
142 typedef SkDrawCommand INHERITED; | 158 typedef SkDrawCommand INHERITED; |
143 }; | 159 }; |
144 | 160 |
145 class SkClipRegionCommand : public SkDrawCommand { | 161 class SkClipRegionCommand : public SkDrawCommand { |
146 public: | 162 public: |
147 SkClipRegionCommand(const SkRegion& region, SkRegion::Op op); | 163 SkClipRegionCommand(const SkRegion& region, SkRegion::Op op); |
148 void execute(SkCanvas* canvas) const override; | 164 void execute(SkCanvas* canvas) const override; |
| 165 Json::Value toJSON() const override; |
| 166 static SkClipRegionCommand* fromJSON(Json::Value& command); |
| 167 |
149 private: | 168 private: |
150 SkRegion fRegion; | 169 SkRegion fRegion; |
151 SkRegion::Op fOp; | 170 SkRegion::Op fOp; |
152 | 171 |
153 typedef SkDrawCommand INHERITED; | 172 typedef SkDrawCommand INHERITED; |
154 }; | 173 }; |
155 | 174 |
156 class SkClipRectCommand : public SkDrawCommand { | 175 class SkClipRectCommand : public SkDrawCommand { |
157 public: | 176 public: |
158 SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool doAA); | 177 SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool doAA); |
159 void execute(SkCanvas* canvas) const override; | 178 void execute(SkCanvas* canvas) const override; |
| 179 Json::Value toJSON() const override; |
| 180 static SkClipRectCommand* fromJSON(Json::Value& command); |
160 | 181 |
161 const SkRect& rect() const { return fRect; } | 182 const SkRect& rect() const { return fRect; } |
162 SkRegion::Op op() const { return fOp; } | 183 SkRegion::Op op() const { return fOp; } |
163 bool doAA() const { return fDoAA; } | 184 bool doAA() const { return fDoAA; } |
164 | 185 |
165 private: | 186 private: |
166 SkRect fRect; | 187 SkRect fRect; |
167 SkRegion::Op fOp; | 188 SkRegion::Op fOp; |
168 bool fDoAA; | 189 bool fDoAA; |
169 | 190 |
170 typedef SkDrawCommand INHERITED; | 191 typedef SkDrawCommand INHERITED; |
171 }; | 192 }; |
172 | 193 |
173 class SkClipRRectCommand : public SkDrawCommand { | 194 class SkClipRRectCommand : public SkDrawCommand { |
174 public: | 195 public: |
175 SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bool doAA); | 196 SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bool doAA); |
176 void execute(SkCanvas* canvas) const override; | 197 void execute(SkCanvas* canvas) const override; |
177 bool render(SkCanvas* canvas) const override; | 198 bool render(SkCanvas* canvas) const override; |
| 199 Json::Value toJSON() const override; |
| 200 static SkClipRRectCommand* fromJSON(Json::Value& command); |
178 | 201 |
179 const SkRRect& rrect() const { return fRRect; } | 202 const SkRRect& rrect() const { return fRRect; } |
180 SkRegion::Op op() const { return fOp; } | 203 SkRegion::Op op() const { return fOp; } |
181 bool doAA() const { return fDoAA; } | 204 bool doAA() const { return fDoAA; } |
182 | 205 |
183 private: | 206 private: |
184 SkRRect fRRect; | 207 SkRRect fRRect; |
185 SkRegion::Op fOp; | 208 SkRegion::Op fOp; |
186 bool fDoAA; | 209 bool fDoAA; |
187 | 210 |
188 typedef SkDrawCommand INHERITED; | 211 typedef SkDrawCommand INHERITED; |
189 }; | 212 }; |
190 | 213 |
191 class SkConcatCommand : public SkDrawCommand { | 214 class SkConcatCommand : public SkDrawCommand { |
192 public: | 215 public: |
193 SkConcatCommand(const SkMatrix& matrix); | 216 SkConcatCommand(const SkMatrix& matrix); |
194 void execute(SkCanvas* canvas) const override; | 217 void execute(SkCanvas* canvas) const override; |
| 218 Json::Value toJSON() const override; |
| 219 static SkConcatCommand* fromJSON(Json::Value& command); |
| 220 |
195 private: | 221 private: |
196 SkMatrix fMatrix; | 222 SkMatrix fMatrix; |
197 | 223 |
198 typedef SkDrawCommand INHERITED; | 224 typedef SkDrawCommand INHERITED; |
199 }; | 225 }; |
200 | 226 |
201 class SkDrawBitmapCommand : public SkDrawCommand { | 227 class SkDrawBitmapCommand : public SkDrawCommand { |
202 public: | 228 public: |
203 SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top, | 229 SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top, |
204 const SkPaint* paint); | 230 const SkPaint* paint); |
205 void execute(SkCanvas* canvas) const override; | 231 void execute(SkCanvas* canvas) const override; |
206 bool render(SkCanvas* canvas) const override; | 232 bool render(SkCanvas* canvas) const override; |
| 233 Json::Value toJSON() const override; |
| 234 static SkDrawBitmapCommand* fromJSON(Json::Value& command); |
| 235 |
207 private: | 236 private: |
208 SkBitmap fBitmap; | 237 SkBitmap fBitmap; |
209 SkScalar fLeft; | 238 SkScalar fLeft; |
210 SkScalar fTop; | 239 SkScalar fTop; |
211 SkPaint fPaint; | 240 SkPaint fPaint; |
212 SkPaint* fPaintPtr; | 241 SkPaint* fPaintPtr; |
213 | 242 |
214 typedef SkDrawCommand INHERITED; | 243 typedef SkDrawCommand INHERITED; |
215 }; | 244 }; |
216 | 245 |
217 class SkDrawBitmapNineCommand : public SkDrawCommand { | 246 class SkDrawBitmapNineCommand : public SkDrawCommand { |
218 public: | 247 public: |
219 SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center, | 248 SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center, |
220 const SkRect& dst, const SkPaint* paint); | 249 const SkRect& dst, const SkPaint* paint); |
221 void execute(SkCanvas* canvas) const override; | 250 void execute(SkCanvas* canvas) const override; |
222 bool render(SkCanvas* canvas) const override; | 251 bool render(SkCanvas* canvas) const override; |
| 252 Json::Value toJSON() const override; |
| 253 static SkDrawBitmapNineCommand* fromJSON(Json::Value& command); |
| 254 |
223 private: | 255 private: |
224 SkBitmap fBitmap; | 256 SkBitmap fBitmap; |
225 SkIRect fCenter; | 257 SkIRect fCenter; |
226 SkRect fDst; | 258 SkRect fDst; |
227 SkPaint fPaint; | 259 SkPaint fPaint; |
228 SkPaint* fPaintPtr; | 260 SkPaint* fPaintPtr; |
229 | 261 |
230 typedef SkDrawCommand INHERITED; | 262 typedef SkDrawCommand INHERITED; |
231 }; | 263 }; |
232 | 264 |
233 class SkDrawBitmapRectCommand : public SkDrawCommand { | 265 class SkDrawBitmapRectCommand : public SkDrawCommand { |
234 public: | 266 public: |
235 SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src, | 267 SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src, |
236 const SkRect& dst, const SkPaint* paint, | 268 const SkRect& dst, const SkPaint* paint, |
237 SkCanvas::SrcRectConstraint); | 269 SkCanvas::SrcRectConstraint); |
238 void execute(SkCanvas* canvas) const override; | 270 void execute(SkCanvas* canvas) const override; |
239 bool render(SkCanvas* canvas) const override; | 271 bool render(SkCanvas* canvas) const override; |
| 272 Json::Value toJSON() const override; |
| 273 static SkDrawBitmapRectCommand* fromJSON(Json::Value& command); |
240 | 274 |
241 const SkBitmap& bitmap() const { return fBitmap; } | 275 const SkBitmap& bitmap() const { return fBitmap; } |
242 | 276 |
243 // The non-const 'paint' method allows modification of this object's | 277 // The non-const 'paint' method allows modification of this object's |
244 // SkPaint. For this reason the ctor and setPaint method make a local copy. | 278 // SkPaint. For this reason the ctor and setPaint method make a local copy. |
245 // The 'fPaintPtr' member acts a signal that the local SkPaint is valid | 279 // The 'fPaintPtr' member acts a signal that the local SkPaint is valid |
246 // (since only an SkPaint* is passed into the ctor). | 280 // (since only an SkPaint* is passed into the ctor). |
247 const SkPaint* paint() const { return fPaintPtr; } | 281 const SkPaint* paint() const { return fPaintPtr; } |
248 SkPaint* paint() { return fPaintPtr; } | 282 SkPaint* paint() { return fPaintPtr; } |
249 | 283 |
(...skipping 17 matching lines...) Expand all Loading... |
267 SkCanvas::SrcRectConstraint fConstraint; | 301 SkCanvas::SrcRectConstraint fConstraint; |
268 | 302 |
269 typedef SkDrawCommand INHERITED; | 303 typedef SkDrawCommand INHERITED; |
270 }; | 304 }; |
271 | 305 |
272 class SkDrawImageCommand : public SkDrawCommand { | 306 class SkDrawImageCommand : public SkDrawCommand { |
273 public: | 307 public: |
274 SkDrawImageCommand(const SkImage* image, SkScalar left, SkScalar top, const
SkPaint* paint); | 308 SkDrawImageCommand(const SkImage* image, SkScalar left, SkScalar top, const
SkPaint* paint); |
275 void execute(SkCanvas* canvas) const override; | 309 void execute(SkCanvas* canvas) const override; |
276 bool render(SkCanvas* canvas) const override; | 310 bool render(SkCanvas* canvas) const override; |
| 311 Json::Value toJSON() const override; |
| 312 static SkDrawImageCommand* fromJSON(Json::Value& command); |
| 313 |
277 private: | 314 private: |
278 SkAutoTUnref<const SkImage> fImage; | 315 SkAutoTUnref<const SkImage> fImage; |
279 SkScalar fLeft; | 316 SkScalar fLeft; |
280 SkScalar fTop; | 317 SkScalar fTop; |
281 SkTLazy<SkPaint> fPaint; | 318 SkTLazy<SkPaint> fPaint; |
282 | 319 |
283 typedef SkDrawCommand INHERITED; | 320 typedef SkDrawCommand INHERITED; |
284 }; | 321 }; |
285 | 322 |
286 class SkDrawImageRectCommand : public SkDrawCommand { | 323 class SkDrawImageRectCommand : public SkDrawCommand { |
287 public: | 324 public: |
288 SkDrawImageRectCommand(const SkImage* image, const SkRect* src, const SkRect
& dst, | 325 SkDrawImageRectCommand(const SkImage* image, const SkRect* src, const SkRect
& dst, |
289 const SkPaint* paint, SkCanvas::SrcRectConstraint con
straint); | 326 const SkPaint* paint, SkCanvas::SrcRectConstraint con
straint); |
290 void execute(SkCanvas* canvas) const override; | 327 void execute(SkCanvas* canvas) const override; |
291 bool render(SkCanvas* canvas) const override; | 328 bool render(SkCanvas* canvas) const override; |
| 329 Json::Value toJSON() const override; |
| 330 static SkDrawImageRectCommand* fromJSON(Json::Value& command); |
| 331 |
292 private: | 332 private: |
293 SkAutoTUnref<const SkImage> fImage; | 333 SkAutoTUnref<const SkImage> fImage; |
294 SkTLazy<SkRect> fSrc; | 334 SkTLazy<SkRect> fSrc; |
295 SkRect fDst; | 335 SkRect fDst; |
296 SkTLazy<SkPaint> fPaint; | 336 SkTLazy<SkPaint> fPaint; |
297 SkCanvas::SrcRectConstraint fConstraint; | 337 SkCanvas::SrcRectConstraint fConstraint; |
298 | 338 |
299 typedef SkDrawCommand INHERITED; | 339 typedef SkDrawCommand INHERITED; |
300 }; | 340 }; |
301 | 341 |
302 class SkDrawOvalCommand : public SkDrawCommand { | 342 class SkDrawOvalCommand : public SkDrawCommand { |
303 public: | 343 public: |
304 SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint); | 344 SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint); |
305 void execute(SkCanvas* canvas) const override; | 345 void execute(SkCanvas* canvas) const override; |
306 bool render(SkCanvas* canvas) const override; | 346 bool render(SkCanvas* canvas) const override; |
| 347 Json::Value toJSON() const override; |
| 348 static SkDrawOvalCommand* fromJSON(Json::Value& command); |
| 349 |
307 private: | 350 private: |
308 SkRect fOval; | 351 SkRect fOval; |
309 SkPaint fPaint; | 352 SkPaint fPaint; |
310 | 353 |
311 typedef SkDrawCommand INHERITED; | 354 typedef SkDrawCommand INHERITED; |
312 }; | 355 }; |
313 | 356 |
314 class SkDrawPaintCommand : public SkDrawCommand { | 357 class SkDrawPaintCommand : public SkDrawCommand { |
315 public: | 358 public: |
316 SkDrawPaintCommand(const SkPaint& paint); | 359 SkDrawPaintCommand(const SkPaint& paint); |
317 void execute(SkCanvas* canvas) const override; | 360 void execute(SkCanvas* canvas) const override; |
318 bool render(SkCanvas* canvas) const override; | 361 bool render(SkCanvas* canvas) const override; |
| 362 Json::Value toJSON() const override; |
| 363 static SkDrawPaintCommand* fromJSON(Json::Value& command); |
| 364 |
319 private: | 365 private: |
320 SkPaint fPaint; | 366 SkPaint fPaint; |
321 | 367 |
322 typedef SkDrawCommand INHERITED; | 368 typedef SkDrawCommand INHERITED; |
323 }; | 369 }; |
324 | 370 |
325 class SkDrawPathCommand : public SkDrawCommand { | 371 class SkDrawPathCommand : public SkDrawCommand { |
326 public: | 372 public: |
327 SkDrawPathCommand(const SkPath& path, const SkPaint& paint); | 373 SkDrawPathCommand(const SkPath& path, const SkPaint& paint); |
328 void execute(SkCanvas* canvas) const override; | 374 void execute(SkCanvas* canvas) const override; |
329 bool render(SkCanvas* canvas) const override; | 375 bool render(SkCanvas* canvas) const override; |
| 376 Json::Value toJSON() const override; |
| 377 static SkDrawPathCommand* fromJSON(Json::Value& command); |
330 | 378 |
331 private: | 379 private: |
332 SkPath fPath; | 380 SkPath fPath; |
333 SkPaint fPaint; | 381 SkPaint fPaint; |
334 | 382 |
335 typedef SkDrawCommand INHERITED; | 383 typedef SkDrawCommand INHERITED; |
336 }; | 384 }; |
337 | 385 |
338 class SkBeginDrawPictureCommand : public SkDrawCommand { | 386 class SkBeginDrawPictureCommand : public SkDrawCommand { |
339 public: | 387 public: |
(...skipping 24 matching lines...) Expand all Loading... |
364 typedef SkDrawCommand INHERITED; | 412 typedef SkDrawCommand INHERITED; |
365 }; | 413 }; |
366 | 414 |
367 class SkDrawPointsCommand : public SkDrawCommand { | 415 class SkDrawPointsCommand : public SkDrawCommand { |
368 public: | 416 public: |
369 SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count, const SkPoint pt
s[], | 417 SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count, const SkPoint pt
s[], |
370 const SkPaint& paint); | 418 const SkPaint& paint); |
371 virtual ~SkDrawPointsCommand() { delete [] fPts; } | 419 virtual ~SkDrawPointsCommand() { delete [] fPts; } |
372 void execute(SkCanvas* canvas) const override; | 420 void execute(SkCanvas* canvas) const override; |
373 bool render(SkCanvas* canvas) const override; | 421 bool render(SkCanvas* canvas) const override; |
| 422 Json::Value toJSON() const override; |
| 423 static SkDrawPointsCommand* fromJSON(Json::Value& command); |
| 424 |
374 private: | 425 private: |
375 SkCanvas::PointMode fMode; | 426 SkCanvas::PointMode fMode; |
376 size_t fCount; | 427 size_t fCount; |
377 SkPoint* fPts; | 428 SkPoint* fPts; |
378 SkPaint fPaint; | 429 SkPaint fPaint; |
379 | 430 |
380 typedef SkDrawCommand INHERITED; | 431 typedef SkDrawCommand INHERITED; |
381 }; | 432 }; |
382 | 433 |
383 class SkDrawTextCommand : public SkDrawCommand { | 434 class SkDrawTextCommand : public SkDrawCommand { |
384 public: | 435 public: |
385 SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar
y, | 436 SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar
y, |
386 const SkPaint& paint); | 437 const SkPaint& paint); |
387 virtual ~SkDrawTextCommand() { delete [] fText; } | 438 virtual ~SkDrawTextCommand() { delete [] fText; } |
388 void execute(SkCanvas* canvas) const override; | 439 void execute(SkCanvas* canvas) const override; |
| 440 Json::Value toJSON() const override; |
| 441 static SkDrawTextCommand* fromJSON(Json::Value& command); |
| 442 |
389 private: | 443 private: |
390 char* fText; | 444 char* fText; |
391 size_t fByteLength; | 445 size_t fByteLength; |
392 SkScalar fX; | 446 SkScalar fX; |
393 SkScalar fY; | 447 SkScalar fY; |
394 SkPaint fPaint; | 448 SkPaint fPaint; |
395 | 449 |
396 typedef SkDrawCommand INHERITED; | 450 typedef SkDrawCommand INHERITED; |
397 }; | 451 }; |
398 | 452 |
399 class SkDrawPosTextCommand : public SkDrawCommand { | 453 class SkDrawPosTextCommand : public SkDrawCommand { |
400 public: | 454 public: |
401 SkDrawPosTextCommand(const void* text, size_t byteLength, const SkPoint pos[
], | 455 SkDrawPosTextCommand(const void* text, size_t byteLength, const SkPoint pos[
], |
402 const SkPaint& paint); | 456 const SkPaint& paint); |
403 virtual ~SkDrawPosTextCommand() { delete [] fPos; delete [] fText; } | 457 virtual ~SkDrawPosTextCommand() { delete [] fPos; delete [] fText; } |
404 void execute(SkCanvas* canvas) const override; | 458 void execute(SkCanvas* canvas) const override; |
| 459 Json::Value toJSON() const override; |
| 460 static SkDrawPosTextCommand* fromJSON(Json::Value& command); |
| 461 |
405 private: | 462 private: |
406 char* fText; | 463 char* fText; |
407 size_t fByteLength; | 464 size_t fByteLength; |
408 SkPoint* fPos; | 465 SkPoint* fPos; |
409 SkPaint fPaint; | 466 SkPaint fPaint; |
410 | 467 |
411 typedef SkDrawCommand INHERITED; | 468 typedef SkDrawCommand INHERITED; |
412 }; | 469 }; |
413 | 470 |
414 class SkDrawTextOnPathCommand : public SkDrawCommand { | 471 class SkDrawTextOnPathCommand : public SkDrawCommand { |
415 public: | 472 public: |
416 SkDrawTextOnPathCommand(const void* text, size_t byteLength, const SkPath& p
ath, | 473 SkDrawTextOnPathCommand(const void* text, size_t byteLength, const SkPath& p
ath, |
417 const SkMatrix* matrix, const SkPaint& paint); | 474 const SkMatrix* matrix, const SkPaint& paint); |
418 virtual ~SkDrawTextOnPathCommand() { delete [] fText; } | 475 virtual ~SkDrawTextOnPathCommand() { delete [] fText; } |
419 void execute(SkCanvas* canvas) const override; | 476 void execute(SkCanvas* canvas) const override; |
| 477 Json::Value toJSON() const override; |
| 478 static SkDrawTextOnPathCommand* fromJSON(Json::Value& command); |
| 479 |
420 private: | 480 private: |
421 char* fText; | 481 char* fText; |
422 size_t fByteLength; | 482 size_t fByteLength; |
423 SkPath fPath; | 483 SkPath fPath; |
424 SkMatrix fMatrix; | 484 SkMatrix fMatrix; |
425 SkPaint fPaint; | 485 SkPaint fPaint; |
426 | 486 |
427 typedef SkDrawCommand INHERITED; | 487 typedef SkDrawCommand INHERITED; |
428 }; | 488 }; |
429 | 489 |
430 class SkDrawPosTextHCommand : public SkDrawCommand { | 490 class SkDrawPosTextHCommand : public SkDrawCommand { |
431 public: | 491 public: |
432 SkDrawPosTextHCommand(const void* text, size_t byteLength, const SkScalar xp
os[], | 492 SkDrawPosTextHCommand(const void* text, size_t byteLength, const SkScalar xp
os[], |
433 SkScalar constY, const SkPaint& paint); | 493 SkScalar constY, const SkPaint& paint); |
434 virtual ~SkDrawPosTextHCommand() { delete [] fXpos; delete [] fText; } | 494 virtual ~SkDrawPosTextHCommand() { delete [] fXpos; delete [] fText; } |
435 void execute(SkCanvas* canvas) const override; | 495 void execute(SkCanvas* canvas) const override; |
| 496 |
436 private: | 497 private: |
437 SkScalar* fXpos; | 498 SkScalar* fXpos; |
438 char* fText; | 499 char* fText; |
439 size_t fByteLength; | 500 size_t fByteLength; |
440 SkScalar fConstY; | 501 SkScalar fConstY; |
441 SkPaint fPaint; | 502 SkPaint fPaint; |
442 | 503 |
443 typedef SkDrawCommand INHERITED; | 504 typedef SkDrawCommand INHERITED; |
444 }; | 505 }; |
445 | 506 |
446 class SkDrawTextBlobCommand : public SkDrawCommand { | 507 class SkDrawTextBlobCommand : public SkDrawCommand { |
447 public: | 508 public: |
448 SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y, const
SkPaint& paint); | 509 SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y, const
SkPaint& paint); |
449 | 510 |
450 void execute(SkCanvas* canvas) const override; | 511 void execute(SkCanvas* canvas) const override; |
451 bool render(SkCanvas* canvas) const override; | 512 bool render(SkCanvas* canvas) const override; |
| 513 Json::Value toJSON() const override; |
| 514 static SkDrawTextBlobCommand* fromJSON(Json::Value& command); |
452 | 515 |
453 private: | 516 private: |
454 SkAutoTUnref<const SkTextBlob> fBlob; | 517 SkAutoTUnref<const SkTextBlob> fBlob; |
455 SkScalar fXPos; | 518 SkScalar fXPos; |
456 SkScalar fYPos; | 519 SkScalar fYPos; |
457 SkPaint fPaint; | 520 SkPaint fPaint; |
458 | 521 |
459 typedef SkDrawCommand INHERITED; | 522 typedef SkDrawCommand INHERITED; |
460 }; | 523 }; |
461 | 524 |
(...skipping 12 matching lines...) Expand all Loading... |
474 SkPaint fPaint; | 537 SkPaint fPaint; |
475 | 538 |
476 typedef SkDrawCommand INHERITED; | 539 typedef SkDrawCommand INHERITED; |
477 }; | 540 }; |
478 | 541 |
479 | 542 |
480 class SkDrawRectCommand : public SkDrawCommand { | 543 class SkDrawRectCommand : public SkDrawCommand { |
481 public: | 544 public: |
482 SkDrawRectCommand(const SkRect& rect, const SkPaint& paint); | 545 SkDrawRectCommand(const SkRect& rect, const SkPaint& paint); |
483 void execute(SkCanvas* canvas) const override; | 546 void execute(SkCanvas* canvas) const override; |
| 547 Json::Value toJSON() const override; |
| 548 static SkDrawRectCommand* fromJSON(Json::Value& command); |
484 | 549 |
485 const SkRect& rect() const { return fRect; } | 550 const SkRect& rect() const { return fRect; } |
486 const SkPaint& paint() const { return fPaint; } | 551 const SkPaint& paint() const { return fPaint; } |
487 private: | 552 private: |
488 SkRect fRect; | 553 SkRect fRect; |
489 SkPaint fPaint; | 554 SkPaint fPaint; |
490 | 555 |
491 typedef SkDrawCommand INHERITED; | 556 typedef SkDrawCommand INHERITED; |
492 }; | 557 }; |
493 | 558 |
494 class SkDrawRRectCommand : public SkDrawCommand { | 559 class SkDrawRRectCommand : public SkDrawCommand { |
495 public: | 560 public: |
496 SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint); | 561 SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint); |
497 void execute(SkCanvas* canvas) const override; | 562 void execute(SkCanvas* canvas) const override; |
498 bool render(SkCanvas* canvas) const override; | 563 bool render(SkCanvas* canvas) const override; |
| 564 Json::Value toJSON() const override; |
| 565 static SkDrawRRectCommand* fromJSON(Json::Value& command); |
| 566 |
499 private: | 567 private: |
500 SkRRect fRRect; | 568 SkRRect fRRect; |
501 SkPaint fPaint; | 569 SkPaint fPaint; |
502 | 570 |
503 typedef SkDrawCommand INHERITED; | 571 typedef SkDrawCommand INHERITED; |
504 }; | 572 }; |
505 | 573 |
506 class SkDrawDRRectCommand : public SkDrawCommand { | 574 class SkDrawDRRectCommand : public SkDrawCommand { |
507 public: | 575 public: |
508 SkDrawDRRectCommand(const SkRRect& outer, const SkRRect& inner, | 576 SkDrawDRRectCommand(const SkRRect& outer, const SkRRect& inner, |
509 const SkPaint& paint); | 577 const SkPaint& paint); |
510 void execute(SkCanvas* canvas) const override; | 578 void execute(SkCanvas* canvas) const override; |
511 bool render(SkCanvas* canvas) const override; | 579 bool render(SkCanvas* canvas) const override; |
| 580 Json::Value toJSON() const override; |
| 581 static SkDrawDRRectCommand* fromJSON(Json::Value& command); |
| 582 |
512 private: | 583 private: |
513 SkRRect fOuter; | 584 SkRRect fOuter; |
514 SkRRect fInner; | 585 SkRRect fInner; |
515 SkPaint fPaint; | 586 SkPaint fPaint; |
516 | 587 |
517 typedef SkDrawCommand INHERITED; | 588 typedef SkDrawCommand INHERITED; |
518 }; | 589 }; |
519 | 590 |
520 class SkDrawVerticesCommand : public SkDrawCommand { | 591 class SkDrawVerticesCommand : public SkDrawCommand { |
521 public: | 592 public: |
522 SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount, | 593 SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount, |
523 const SkPoint vertices[], const SkPoint texs[], | 594 const SkPoint vertices[], const SkPoint texs[], |
524 const SkColor colors[], SkXfermode* xfermode, | 595 const SkColor colors[], SkXfermode* xfermode, |
525 const uint16_t indices[], int indexCount, | 596 const uint16_t indices[], int indexCount, |
526 const SkPaint& paint); | 597 const SkPaint& paint); |
527 virtual ~SkDrawVerticesCommand(); | 598 virtual ~SkDrawVerticesCommand(); |
528 void execute(SkCanvas* canvas) const override; | 599 void execute(SkCanvas* canvas) const override; |
| 600 |
529 private: | 601 private: |
530 SkCanvas::VertexMode fVmode; | 602 SkCanvas::VertexMode fVmode; |
531 int fVertexCount; | 603 int fVertexCount; |
532 SkPoint* fVertices; | 604 SkPoint* fVertices; |
533 SkPoint* fTexs; | 605 SkPoint* fTexs; |
534 SkColor* fColors; | 606 SkColor* fColors; |
535 SkXfermode* fXfermode; | 607 SkXfermode* fXfermode; |
536 uint16_t* fIndices; | 608 uint16_t* fIndices; |
537 int fIndexCount; | 609 int fIndexCount; |
538 SkPaint fPaint; | 610 SkPaint fPaint; |
539 | 611 |
540 typedef SkDrawCommand INHERITED; | 612 typedef SkDrawCommand INHERITED; |
541 }; | 613 }; |
542 | 614 |
543 class SkSaveCommand : public SkDrawCommand { | 615 class SkSaveCommand : public SkDrawCommand { |
544 public: | 616 public: |
545 SkSaveCommand(); | 617 SkSaveCommand(); |
546 void execute(SkCanvas* canvas) const override; | 618 void execute(SkCanvas* canvas) const override; |
547 Action action() const override { return kPushLayer_Action; } | 619 Action action() const override { return kPushLayer_Action; } |
| 620 static SkSaveCommand* fromJSON(Json::Value& command); |
| 621 |
548 private: | 622 private: |
549 typedef SkDrawCommand INHERITED; | 623 typedef SkDrawCommand INHERITED; |
550 }; | 624 }; |
551 | 625 |
552 class SkSaveLayerCommand : public SkDrawCommand { | 626 class SkSaveLayerCommand : public SkDrawCommand { |
553 public: | 627 public: |
554 SkSaveLayerCommand(const SkCanvas::SaveLayerRec&); | 628 SkSaveLayerCommand(const SkCanvas::SaveLayerRec&); |
| 629 virtual ~SkSaveLayerCommand(); |
555 void execute(SkCanvas* canvas) const override; | 630 void execute(SkCanvas* canvas) const override; |
| 631 Json::Value toJSON() const override; |
| 632 static SkSaveLayerCommand* fromJSON(Json::Value& command); |
556 void vizExecute(SkCanvas* canvas) const override; | 633 void vizExecute(SkCanvas* canvas) const override; |
557 Action action() const override{ return kPushLayer_Action; } | 634 Action action() const override{ return kPushLayer_Action; } |
558 void setActive(bool active) override { fActive = active; } | 635 void setActive(bool active) override { fActive = active; } |
559 bool active() const override { return fActive; } | 636 bool active() const override { return fActive; } |
560 | 637 |
561 const SkPaint* paint() const { return fPaintPtr; } | 638 const SkPaint* paint() const { return fPaintPtr; } |
562 | 639 |
563 private: | 640 private: |
564 SkRect fBounds; | 641 SkRect fBounds; |
565 SkPaint fPaint; | 642 SkPaint fPaint; |
566 SkPaint* fPaintPtr; | 643 SkPaint* fPaintPtr; |
567 uint32_t fSaveLayerFlags; | 644 const SkImageFilter* fBackdrop; |
| 645 uint32_t fSaveLayerFlags; |
568 | 646 |
569 bool fActive; | 647 bool fActive; |
570 | 648 |
571 typedef SkDrawCommand INHERITED; | 649 typedef SkDrawCommand INHERITED; |
572 }; | 650 }; |
573 | 651 |
574 class SkSetMatrixCommand : public SkDrawCommand { | 652 class SkSetMatrixCommand : public SkDrawCommand { |
575 public: | 653 public: |
576 SkSetMatrixCommand(const SkMatrix& matrix); | 654 SkSetMatrixCommand(const SkMatrix& matrix); |
577 void setUserMatrix(const SkMatrix&) override; | 655 void setUserMatrix(const SkMatrix&) override; |
578 void execute(SkCanvas* canvas) const override; | 656 void execute(SkCanvas* canvas) const override; |
| 657 Json::Value toJSON() const override; |
| 658 static SkSetMatrixCommand* fromJSON(Json::Value& command); |
| 659 |
579 private: | 660 private: |
580 SkMatrix fUserMatrix; | 661 SkMatrix fUserMatrix; |
581 SkMatrix fMatrix; | 662 SkMatrix fMatrix; |
582 | 663 |
583 typedef SkDrawCommand INHERITED; | 664 typedef SkDrawCommand INHERITED; |
584 }; | 665 }; |
585 | 666 |
586 #endif | 667 #endif |
OLD | NEW |