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 | 9 |
10 #include "SkDrawCommand.h" | 10 #include "SkDrawCommand.h" |
11 #include "SkBlurMaskFilter.h" | |
12 #include "SkColorFilter.h" | |
13 #include "SkDashPathEffect.h" | |
14 #include "SkImageFilter.h" | |
15 #include "SkMaskFilter.h" | |
16 #include "SkObjectParser.h" | 11 #include "SkObjectParser.h" |
17 #include "SkPaintDefaults.h" | |
18 #include "SkPathEffect.h" | |
19 #include "SkPicture.h" | 12 #include "SkPicture.h" |
20 #include "SkTextBlob.h" | 13 #include "SkTextBlob.h" |
21 #include "SkTextBlobRunIterator.h" | 14 #include "SkTextBlobRunIterator.h" |
22 #include "SkTHash.h" | |
23 #include "SkTypeface.h" | |
24 #include "SkValidatingReadBuffer.h" | |
25 #include "SkWriteBuffer.h" | |
26 | |
27 #define SKDEBUGCANVAS_SEND_BINARIES true | |
28 | |
29 #define SKDEBUGCANVAS_ATTRIBUTE_COMMAND "command" | |
30 #define SKDEBUGCANVAS_ATTRIBUTE_MATRIX "matrix" | |
31 #define SKDEBUGCANVAS_ATTRIBUTE_COORDS "coords" | |
32 #define SKDEBUGCANVAS_ATTRIBUTE_BOUNDS "bounds" | |
33 #define SKDEBUGCANVAS_ATTRIBUTE_PAINT "paint" | |
34 #define SKDEBUGCANVAS_ATTRIBUTE_OUTER "outer" | |
35 #define SKDEBUGCANVAS_ATTRIBUTE_INNER "inner" | |
36 #define SKDEBUGCANVAS_ATTRIBUTE_MODE "mode" | |
37 #define SKDEBUGCANVAS_ATTRIBUTE_POINTS "points" | |
38 #define SKDEBUGCANVAS_ATTRIBUTE_PATH "path" | |
39 #define SKDEBUGCANVAS_ATTRIBUTE_TEXT "text" | |
40 #define SKDEBUGCANVAS_ATTRIBUTE_COLOR "color" | |
41 #define SKDEBUGCANVAS_ATTRIBUTE_ALPHA "alpha" | |
42 #define SKDEBUGCANVAS_ATTRIBUTE_STYLE "style" | |
43 #define SKDEBUGCANVAS_ATTRIBUTE_STROKEWIDTH "strokeWidth" | |
44 #define SKDEBUGCANVAS_ATTRIBUTE_STROKEMITER "strokeMiter" | |
45 #define SKDEBUGCANVAS_ATTRIBUTE_CAP "cap" | |
46 #define SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS "antiAlias" | |
47 #define SKDEBUGCANVAS_ATTRIBUTE_REGION "region" | |
48 #define SKDEBUGCANVAS_ATTRIBUTE_REGIONOP "op" | |
49 #define SKDEBUGCANVAS_ATTRIBUTE_EDGESTYLE "edgeStyle" | |
50 #define SKDEBUGCANVAS_ATTRIBUTE_DEVICEREGION "deviceRegion" | |
51 #define SKDEBUGCANVAS_ATTRIBUTE_BLUR "blur" | |
52 #define SKDEBUGCANVAS_ATTRIBUTE_SIGMA "sigma" | |
53 #define SKDEBUGCANVAS_ATTRIBUTE_QUALITY "quality" | |
54 #define SKDEBUGCANVAS_ATTRIBUTE_TEXTALIGN "textAlign" | |
55 #define SKDEBUGCANVAS_ATTRIBUTE_TEXTSIZE "textSize" | |
56 #define SKDEBUGCANVAS_ATTRIBUTE_TEXTSCALEX "textScaleX" | |
57 #define SKDEBUGCANVAS_ATTRIBUTE_TEXTSKEWX "textSkewX" | |
58 #define SKDEBUGCANVAS_ATTRIBUTE_DASHING "dashing" | |
59 #define SKDEBUGCANVAS_ATTRIBUTE_INTERVALS "intervals" | |
60 #define SKDEBUGCANVAS_ATTRIBUTE_PHASE "phase" | |
61 #define SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE "fillType" | |
62 #define SKDEBUGCANVAS_ATTRIBUTE_VERBS "verbs" | |
63 #define SKDEBUGCANVAS_ATTRIBUTE_NAME "name" | |
64 #define SKDEBUGCANVAS_ATTRIBUTE_BYTES "bytes" | |
65 #define SKDEBUGCANVAS_ATTRIBUTE_SHADER "shader" | |
66 #define SKDEBUGCANVAS_ATTRIBUTE_PATHEFFECT "pathEffect" | |
67 #define SKDEBUGCANVAS_ATTRIBUTE_MASKFILTER "maskFilter" | |
68 #define SKDEBUGCANVAS_ATTRIBUTE_XFERMODE "xfermode" | |
69 #define SKDEBUGCANVAS_ATTRIBUTE_BACKDROP "backdrop" | |
70 #define SKDEBUGCANVAS_ATTRIBUTE_COLORFILTER "colorfilter" | |
71 #define SKDEBUGCANVAS_ATTRIBUTE_IMAGEFILTER "imagefilter" | |
72 #define SKDEBUGCANVAS_ATTRIBUTE_IMAGE "image" | |
73 #define SKDEBUGCANVAS_ATTRIBUTE_BITMAP "bitmap" | |
74 #define SKDEBUGCANVAS_ATTRIBUTE_SRC "src" | |
75 #define SKDEBUGCANVAS_ATTRIBUTE_DST "dst" | |
76 #define SKDEBUGCANVAS_ATTRIBUTE_CENTER "center" | |
77 #define SKDEBUGCANVAS_ATTRIBUTE_STRICT "strict" | |
78 #define SKDEBUGCANVAS_ATTRIBUTE_DESCRIPTION "description" | |
79 #define SKDEBUGCANVAS_ATTRIBUTE_X "x" | |
80 #define SKDEBUGCANVAS_ATTRIBUTE_Y "y" | |
81 #define SKDEBUGCANVAS_ATTRIBUTE_RUNS "runs" | |
82 #define SKDEBUGCANVAS_ATTRIBUTE_POSITIONS "positions" | |
83 #define SKDEBUGCANVAS_ATTRIBUTE_GLYPHS "glyphs" | |
84 #define SKDEBUGCANVAS_ATTRIBUTE_FONT "font" | |
85 #define SKDEBUGCANVAS_ATTRIBUTE_TYPEFACE "typeface" | |
86 | |
87 #define SKDEBUGCANVAS_VERB_MOVE "move" | |
88 #define SKDEBUGCANVAS_VERB_LINE "line" | |
89 #define SKDEBUGCANVAS_VERB_QUAD "quad" | |
90 #define SKDEBUGCANVAS_VERB_CUBIC "cubic" | |
91 #define SKDEBUGCANVAS_VERB_CONIC "conic" | |
92 #define SKDEBUGCANVAS_VERB_CLOSE "close" | |
93 | |
94 #define SKDEBUGCANVAS_STYLE_FILL "fill" | |
95 #define SKDEBUGCANVAS_STYLE_STROKE "stroke" | |
96 #define SKDEBUGCANVAS_STYLE_STROKEANDFILL "strokeAndFill" | |
97 | |
98 #define SKDEBUGCANVAS_POINTMODE_POINTS "points" | |
99 #define SKDEBUGCANVAS_POINTMODE_LINES "lines" | |
100 #define SKDEBUGCANVAS_POINTMODE_POLYGON "polygon" | |
101 | |
102 #define SKDEBUGCANVAS_REGIONOP_DIFFERENCE "difference" | |
103 #define SKDEBUGCANVAS_REGIONOP_INTERSECT "intersect" | |
104 #define SKDEBUGCANVAS_REGIONOP_UNION "union" | |
105 #define SKDEBUGCANVAS_REGIONOP_XOR "xor" | |
106 #define SKDEBUGCANVAS_REGIONOP_REVERSE_DIFFERENCE "reverseDifference" | |
107 #define SKDEBUGCANVAS_REGIONOP_REPLACE "replace" | |
108 | |
109 #define SKDEBUGCANVAS_BLURSTYLE_NORMAL "normal" | |
110 #define SKDEBUGCANVAS_BLURSTYLE_SOLID "solid" | |
111 #define SKDEBUGCANVAS_BLURSTYLE_OUTER "outer" | |
112 #define SKDEBUGCANVAS_BLURSTYLE_INNER "inner" | |
113 | |
114 #define SKDEBUGCANVAS_BLURQUALITY_LOW "low" | |
115 #define SKDEBUGCANVAS_BLURQUALITY_HIGH "high" | |
116 | |
117 #define SKDEBUGCANVAS_ALIGN_LEFT "left" | |
118 #define SKDEBUGCANVAS_ALIGN_CENTER "center" | |
119 #define SKDEBUGCANVAS_ALIGN_RIGHT "right" | |
120 | |
121 #define SKDEBUGCANVAS_FILLTYPE_WINDING "winding" | |
122 #define SKDEBUGCANVAS_FILLTYPE_EVENODD "evenOdd" | |
123 #define SKDEBUGCANVAS_FILLTYPE_INVERSEWINDING "inverseWinding" | |
124 #define SKDEBUGCANVAS_FILLTYPE_INVERSEEVENODD "inverseEvenOdd" | |
125 | |
126 #define SKDEBUGCANVAS_CAP_BUTT "butt" | |
127 #define SKDEBUGCANVAS_CAP_ROUND "round" | |
128 #define SKDEBUGCANVAS_CAP_SQUARE "square" | |
129 | |
130 #define SKDEBUGCANVAS_COLORTYPE_ARGB4444 "ARGB4444" | |
131 #define SKDEBUGCANVAS_COLORTYPE_RGBA8888 "RGBA8888" | |
132 #define SKDEBUGCANVAS_COLORTYPE_BGRA8888 "BGRA8888" | |
133 #define SKDEBUGCANVAS_COLORTYPE_565 "565" | |
134 #define SKDEBUGCANVAS_COLORTYPE_GRAY8 "Gray8" | |
135 #define SKDEBUGCANVAS_COLORTYPE_INDEX8 "Index8" | |
136 #define SKDEBUGCANVAS_COLORTYPE_ALPHA8 "Alpha8" | |
137 | |
138 #define SKDEBUGCANVAS_ALPHATYPE_OPAQUE "opaque" | |
139 #define SKDEBUGCANVAS_ALPHATYPE_PREMUL "premul" | |
140 #define SKDEBUGCANVAS_ALPHATYPE_UNPREMUL "unpremul" | |
141 | |
142 typedef SkDrawCommand* (*FROM_JSON)(Json::Value); | |
143 | 15 |
144 // TODO(chudy): Refactor into non subclass model. | 16 // TODO(chudy): Refactor into non subclass model. |
145 | 17 |
146 SkDrawCommand::SkDrawCommand(OpType type) | 18 SkDrawCommand::SkDrawCommand(OpType type) |
147 : fOpType(type) | 19 : fOpType(type) |
148 , fVisible(true) { | 20 , fVisible(true) { |
149 } | 21 } |
150 | 22 |
151 SkDrawCommand::~SkDrawCommand() { | 23 SkDrawCommand::~SkDrawCommand() { |
152 fInfo.deleteAll(); | 24 fInfo.deleteAll(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 break; | 63 break; |
192 } | 64 } |
193 SkDEBUGFAIL("DrawType UNUSED\n"); | 65 SkDEBUGFAIL("DrawType UNUSED\n"); |
194 return nullptr; | 66 return nullptr; |
195 } | 67 } |
196 | 68 |
197 SkString SkDrawCommand::toString() const { | 69 SkString SkDrawCommand::toString() const { |
198 return SkString(GetCommandString(fOpType)); | 70 return SkString(GetCommandString(fOpType)); |
199 } | 71 } |
200 | 72 |
201 Json::Value SkDrawCommand::toJSON() const { | |
202 Json::Value result; | |
203 result[SKDEBUGCANVAS_ATTRIBUTE_COMMAND] = this->GetCommandString(fOpType); | |
204 return result; | |
205 } | |
206 | |
207 #define INSTALL_FACTORY(name) factories.set(SkString(GetCommandString(k ## name
##_OpType)), \ | |
208 (FROM_JSON) Sk ## name ## Command::f
romJSON) | |
209 SkDrawCommand* SkDrawCommand::fromJSON(Json::Value& command) { | |
210 static SkTHashMap<SkString, FROM_JSON> factories; | |
211 static bool initialized = false; | |
212 if (!initialized) { | |
213 initialized = true; | |
214 INSTALL_FACTORY(Restore); | |
215 INSTALL_FACTORY(ClipPath); | |
216 INSTALL_FACTORY(ClipRegion); | |
217 INSTALL_FACTORY(ClipRect); | |
218 INSTALL_FACTORY(ClipRRect); | |
219 INSTALL_FACTORY(Concat); | |
220 INSTALL_FACTORY(DrawBitmap); | |
221 INSTALL_FACTORY(DrawBitmapRect); | |
222 INSTALL_FACTORY(DrawBitmapNine); | |
223 INSTALL_FACTORY(DrawImage); | |
224 INSTALL_FACTORY(DrawImageRect); | |
225 INSTALL_FACTORY(DrawOval); | |
226 INSTALL_FACTORY(DrawPaint); | |
227 INSTALL_FACTORY(DrawPath); | |
228 INSTALL_FACTORY(DrawPoints); | |
229 INSTALL_FACTORY(DrawText); | |
230 INSTALL_FACTORY(DrawPosText); | |
231 INSTALL_FACTORY(DrawTextOnPath); | |
232 INSTALL_FACTORY(DrawTextBlob); | |
233 | |
234 INSTALL_FACTORY(DrawRect); | |
235 INSTALL_FACTORY(DrawRRect); | |
236 INSTALL_FACTORY(DrawDRRect); | |
237 INSTALL_FACTORY(Save); | |
238 INSTALL_FACTORY(SaveLayer); | |
239 INSTALL_FACTORY(SetMatrix); | |
240 } | |
241 SkString name = SkString(command[SKDEBUGCANVAS_ATTRIBUTE_COMMAND].asCString(
)); | |
242 FROM_JSON* factory = factories.find(name); | |
243 if (factory == nullptr) { | |
244 SkDebugf("no JSON factory for '%s'\n", name.c_str()); | |
245 return nullptr; | |
246 } | |
247 return (*factory)(command); | |
248 } | |
249 | |
250 SkClearCommand::SkClearCommand(SkColor color) : INHERITED(kDrawClear_OpType) { | 73 SkClearCommand::SkClearCommand(SkColor color) : INHERITED(kDrawClear_OpType) { |
251 fColor = color; | 74 fColor = color; |
252 fInfo.push(SkObjectParser::CustomTextToString("No Parameters")); | 75 fInfo.push(SkObjectParser::CustomTextToString("No Parameters")); |
253 } | 76 } |
254 | 77 |
255 void SkClearCommand::execute(SkCanvas* canvas) const { | 78 void SkClearCommand::execute(SkCanvas* canvas) const { |
256 canvas->clear(fColor); | 79 canvas->clear(fColor); |
257 } | 80 } |
258 | 81 |
259 Json::Value SkClearCommand::toJSON() const { | |
260 Json::Value result = INHERITED::toJSON(); | |
261 Json::Value colorValue(Json::arrayValue); | |
262 colorValue.append(Json::Value(SkColorGetA(fColor))); | |
263 colorValue.append(Json::Value(SkColorGetR(fColor))); | |
264 colorValue.append(Json::Value(SkColorGetG(fColor))); | |
265 colorValue.append(Json::Value(SkColorGetB(fColor))); | |
266 result[SKDEBUGCANVAS_ATTRIBUTE_COLOR] = colorValue;; | |
267 return result; | |
268 } | |
269 | |
270 SkClearCommand* SkClearCommand::fromJSON(Json::Value& command) { | |
271 Json::Value color = command[SKDEBUGCANVAS_ATTRIBUTE_COLOR]; | |
272 return new SkClearCommand(SkColorSetARGB(color[0].asInt(), color[1].asInt(),
color[2].asInt(), | |
273 color[3].asInt())); | |
274 } | |
275 | |
276 namespace { | 82 namespace { |
277 | 83 |
278 void xlate_and_scale_to_bounds(SkCanvas* canvas, const SkRect& bounds) { | 84 void xlate_and_scale_to_bounds(SkCanvas* canvas, const SkRect& bounds) { |
279 const SkISize& size = canvas->getDeviceSize(); | 85 const SkISize& size = canvas->getDeviceSize(); |
280 | 86 |
281 static const SkScalar kInsetFrac = 0.9f; // Leave a border around object | 87 static const SkScalar kInsetFrac = 0.9f; // Leave a border around object |
282 | 88 |
283 canvas->translate(size.fWidth/2.0f, size.fHeight/2.0f); | 89 canvas->translate(size.fWidth/2.0f, size.fHeight/2.0f); |
284 if (bounds.width() > bounds.height()) { | 90 if (bounds.width() > bounds.height()) { |
285 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.width()), | 91 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.width()), |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 SkPaint p; | 193 SkPaint p; |
388 p.setColor(SK_ColorBLACK); | 194 p.setColor(SK_ColorBLACK); |
389 p.setStyle(SkPaint::kStroke_Style); | 195 p.setStyle(SkPaint::kStroke_Style); |
390 | 196 |
391 canvas->drawDRRect(outer, inner, p); | 197 canvas->drawDRRect(outer, inner, p); |
392 canvas->restore(); | 198 canvas->restore(); |
393 } | 199 } |
394 | 200 |
395 }; | 201 }; |
396 | 202 |
397 static Json::Value make_json_point(const SkPoint& point) { | |
398 Json::Value result(Json::arrayValue); | |
399 result.append(Json::Value(point.x())); | |
400 result.append(Json::Value(point.y())); | |
401 return result; | |
402 } | |
403 | |
404 static Json::Value make_json_point(SkScalar x, SkScalar y) { | |
405 Json::Value result(Json::arrayValue); | |
406 result.append(Json::Value(x)); | |
407 result.append(Json::Value(y)); | |
408 return result; | |
409 } | |
410 | |
411 static Json::Value make_json_rect(const SkRect& rect) { | |
412 Json::Value result(Json::arrayValue); | |
413 result.append(Json::Value(rect.left())); | |
414 result.append(Json::Value(rect.top())); | |
415 result.append(Json::Value(rect.right())); | |
416 result.append(Json::Value(rect.bottom())); | |
417 return result; | |
418 } | |
419 | |
420 static Json::Value make_json_irect(const SkIRect& rect) { | |
421 Json::Value result(Json::arrayValue); | |
422 result.append(Json::Value(rect.left())); | |
423 result.append(Json::Value(rect.top())); | |
424 result.append(Json::Value(rect.right())); | |
425 result.append(Json::Value(rect.bottom())); | |
426 return result; | |
427 } | |
428 | |
429 static Json::Value make_json_rrect(const SkRRect& rrect) { | |
430 Json::Value result(Json::arrayValue); | |
431 result.append(make_json_rect(rrect.rect())); | |
432 result.append(make_json_point(rrect.radii(SkRRect::kUpperLeft_Corner))); | |
433 result.append(make_json_point(rrect.radii(SkRRect::kUpperRight_Corner))); | |
434 result.append(make_json_point(rrect.radii(SkRRect::kLowerRight_Corner))); | |
435 result.append(make_json_point(rrect.radii(SkRRect::kLowerLeft_Corner))); | |
436 return result; | |
437 } | |
438 | |
439 static Json::Value make_json_matrix(const SkMatrix& matrix) { | |
440 Json::Value result(Json::arrayValue); | |
441 Json::Value row1(Json::arrayValue); | |
442 row1.append(Json::Value(matrix[0])); | |
443 row1.append(Json::Value(matrix[1])); | |
444 row1.append(Json::Value(matrix[2])); | |
445 result.append(row1); | |
446 Json::Value row2(Json::arrayValue); | |
447 row2.append(Json::Value(matrix[3])); | |
448 row2.append(Json::Value(matrix[4])); | |
449 row2.append(Json::Value(matrix[5])); | |
450 result.append(row2); | |
451 Json::Value row3(Json::arrayValue); | |
452 row3.append(Json::Value(matrix[6])); | |
453 row3.append(Json::Value(matrix[7])); | |
454 row3.append(Json::Value(matrix[8])); | |
455 result.append(row3); | |
456 return result; | |
457 } | |
458 static Json::Value make_json_path(const SkPath& path) { | |
459 Json::Value result(Json::objectValue); | |
460 switch (path.getFillType()) { | |
461 case SkPath::kWinding_FillType: | |
462 result[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE] = SKDEBUGCANVAS_FILLTYPE_WI
NDING; | |
463 break; | |
464 case SkPath::kEvenOdd_FillType: | |
465 result[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE] = SKDEBUGCANVAS_FILLTYPE_EV
ENODD; | |
466 break; | |
467 case SkPath::kInverseWinding_FillType: | |
468 result[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE] = SKDEBUGCANVAS_FILLTYPE_IN
VERSEWINDING; | |
469 break; | |
470 case SkPath::kInverseEvenOdd_FillType: | |
471 result[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE] = SKDEBUGCANVAS_FILLTYPE_IN
VERSEEVENODD; | |
472 break; | |
473 } | |
474 Json::Value verbs(Json::arrayValue); | |
475 SkPath::Iter iter(path, false); | |
476 SkPoint pts[4]; | |
477 SkPath::Verb verb; | |
478 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { | |
479 switch (verb) { | |
480 case SkPath::kLine_Verb: { | |
481 Json::Value line(Json::objectValue); | |
482 line[SKDEBUGCANVAS_VERB_LINE] = make_json_point(pts[1]); | |
483 verbs.append(line); | |
484 break; | |
485 } | |
486 case SkPath::kQuad_Verb: { | |
487 Json::Value quad(Json::objectValue); | |
488 Json::Value coords(Json::arrayValue); | |
489 coords.append(make_json_point(pts[1])); | |
490 coords.append(make_json_point(pts[2])); | |
491 quad[SKDEBUGCANVAS_VERB_QUAD] = coords; | |
492 verbs.append(quad); | |
493 break; | |
494 } | |
495 case SkPath::kCubic_Verb: { | |
496 Json::Value cubic(Json::objectValue); | |
497 Json::Value coords(Json::arrayValue); | |
498 coords.append(make_json_point(pts[1])); | |
499 coords.append(make_json_point(pts[2])); | |
500 coords.append(make_json_point(pts[3])); | |
501 cubic[SKDEBUGCANVAS_VERB_CUBIC] = coords; | |
502 verbs.append(cubic); | |
503 break; | |
504 } | |
505 case SkPath::kConic_Verb: { | |
506 Json::Value conic(Json::objectValue); | |
507 Json::Value coords(Json::arrayValue); | |
508 coords.append(make_json_point(pts[1])); | |
509 coords.append(make_json_point(pts[2])); | |
510 coords.append(Json::Value(iter.conicWeight())); | |
511 conic[SKDEBUGCANVAS_VERB_CONIC] = coords; | |
512 verbs.append(conic); | |
513 break; | |
514 } | |
515 case SkPath::kMove_Verb: { | |
516 Json::Value move(Json::objectValue); | |
517 move[SKDEBUGCANVAS_VERB_MOVE] = make_json_point(pts[0]); | |
518 verbs.append(move); | |
519 break; | |
520 } | |
521 case SkPath::kClose_Verb: | |
522 verbs.append(Json::Value(SKDEBUGCANVAS_VERB_CLOSE)); | |
523 break; | |
524 case SkPath::kDone_Verb: | |
525 break; | |
526 } | |
527 } | |
528 result[SKDEBUGCANVAS_ATTRIBUTE_VERBS] = verbs; | |
529 return result; | |
530 } | |
531 | |
532 static Json::Value make_json_region(const SkRegion& region) { | |
533 return Json::Value("<unimplemented>"); | |
534 } | |
535 | |
536 static Json::Value make_json_regionop(SkRegion::Op op) { | |
537 switch (op) { | |
538 case SkRegion::kDifference_Op: | |
539 return Json::Value(SKDEBUGCANVAS_REGIONOP_DIFFERENCE); | |
540 case SkRegion::kIntersect_Op: | |
541 return Json::Value(SKDEBUGCANVAS_REGIONOP_INTERSECT); | |
542 case SkRegion::kUnion_Op: | |
543 return Json::Value(SKDEBUGCANVAS_REGIONOP_UNION); | |
544 case SkRegion::kXOR_Op: | |
545 return Json::Value(SKDEBUGCANVAS_REGIONOP_XOR); | |
546 case SkRegion::kReverseDifference_Op: | |
547 return Json::Value(SKDEBUGCANVAS_REGIONOP_REVERSE_DIFFERENCE); | |
548 case SkRegion::kReplace_Op: | |
549 return Json::Value(SKDEBUGCANVAS_REGIONOP_REPLACE); | |
550 default: | |
551 SkASSERT(false); | |
552 return Json::Value("<invalid region op>"); | |
553 }; | |
554 } | |
555 | |
556 static Json::Value make_json_pointmode(SkCanvas::PointMode mode) { | |
557 switch (mode) { | |
558 case SkCanvas::kPoints_PointMode: | |
559 return Json::Value(SKDEBUGCANVAS_POINTMODE_POINTS); | |
560 case SkCanvas::kLines_PointMode: | |
561 return Json::Value(SKDEBUGCANVAS_POINTMODE_LINES); | |
562 case SkCanvas::kPolygon_PointMode: | |
563 return Json::Value(SKDEBUGCANVAS_POINTMODE_POLYGON); | |
564 default: | |
565 SkASSERT(false); | |
566 return Json::Value("<invalid point mode>"); | |
567 }; | |
568 } | |
569 | |
570 void store_scalar(Json::Value* target, const char* key, SkScalar value, SkScalar
defaultValue) { | |
571 if (value != defaultValue) { | |
572 (*target)[key] = Json::Value(value); | |
573 } | |
574 } | |
575 | |
576 void store_bool(Json::Value* target, const char* key, bool value, bool defaultVa
lue) { | |
577 if (value != defaultValue) { | |
578 (*target)[key] = Json::Value(value); | |
579 } | |
580 } | |
581 | |
582 static void encode_data(const void* data, size_t count, Json::Value* target) { | |
583 // just use a brain-dead JSON array for now, switch to base64 or something e
lse smarter down the | |
584 // road | |
585 for (size_t i = 0; i < count; i++) { | |
586 target->append(((const uint8_t*)data)[i]); | |
587 } | |
588 } | |
589 | |
590 static void flatten(const SkFlattenable* flattenable, Json::Value* target, bool
sendBinaries) { | |
591 if (sendBinaries) { | |
592 SkWriteBuffer buffer; | |
593 flattenable->flatten(buffer); | |
594 void* data = sk_malloc_throw(buffer.bytesWritten()); | |
595 buffer.writeToMemory(data); | |
596 Json::Value bytes; | |
597 encode_data(data, buffer.bytesWritten(), &bytes); | |
598 Json::Value jsonFlattenable; | |
599 jsonFlattenable[SKDEBUGCANVAS_ATTRIBUTE_NAME] = Json::Value(flattenable-
>getTypeName()); | |
600 jsonFlattenable[SKDEBUGCANVAS_ATTRIBUTE_BYTES] = bytes; | |
601 (*target) = jsonFlattenable; | |
602 free(data); | |
603 } else { | |
604 (*target)[SKDEBUGCANVAS_ATTRIBUTE_DESCRIPTION] = Json::Value(flattenable
->getTypeName()); | |
605 } | |
606 } | |
607 | |
608 static bool SK_WARN_UNUSED_RESULT flatten(const SkImage& image, Json::Value* tar
get, | |
609 bool sendBinaries) { | |
610 if (sendBinaries) { | |
611 SkData* encoded = image.encode(SkImageEncoder::kPNG_Type, 100); | |
612 if (encoded == nullptr) { | |
613 // PNG encode doesn't necessarily support all color formats, convert
to a different | |
614 // format | |
615 size_t rowBytes = 4 * image.width(); | |
616 void* buffer = sk_malloc_throw(rowBytes * image.height()); | |
617 SkImageInfo dstInfo = SkImageInfo::Make(image.width(), image.height(
), | |
618 kN32_SkColorType, kPremul_Sk
AlphaType); | |
619 if (!image.readPixels(dstInfo, buffer, rowBytes, 0, 0)) { | |
620 SkDebugf("readPixels failed\n"); | |
621 return false; | |
622 } | |
623 SkImage* converted = SkImage::NewRasterCopy(dstInfo, buffer, rowByte
s); | |
624 encoded = converted->encode(SkImageEncoder::kPNG_Type, 100); | |
625 if (encoded == nullptr) { | |
626 SkDebugf("image encode failed\n"); | |
627 return false; | |
628 } | |
629 free(converted); | |
630 free(buffer); | |
631 } | |
632 Json::Value bytes; | |
633 encode_data(encoded->data(), encoded->size(), &bytes); | |
634 (*target)[SKDEBUGCANVAS_ATTRIBUTE_BYTES] = bytes; | |
635 encoded->unref(); | |
636 } else { | |
637 SkString description = SkStringPrintf("%dx%d pixel image", image.width()
, image.height()); | |
638 (*target)[SKDEBUGCANVAS_ATTRIBUTE_DESCRIPTION] = Json::Value(description
.c_str()); | |
639 } | |
640 return true; | |
641 } | |
642 | |
643 static const char* color_type_name(SkColorType colorType) { | |
644 switch (colorType) { | |
645 case kARGB_4444_SkColorType: | |
646 return SKDEBUGCANVAS_COLORTYPE_ARGB4444; | |
647 case kRGBA_8888_SkColorType: | |
648 return SKDEBUGCANVAS_COLORTYPE_RGBA8888; | |
649 case kBGRA_8888_SkColorType: | |
650 return SKDEBUGCANVAS_COLORTYPE_BGRA8888; | |
651 case kRGB_565_SkColorType: | |
652 return SKDEBUGCANVAS_COLORTYPE_565; | |
653 case kGray_8_SkColorType: | |
654 return SKDEBUGCANVAS_COLORTYPE_GRAY8; | |
655 case kIndex_8_SkColorType: | |
656 return SKDEBUGCANVAS_COLORTYPE_INDEX8; | |
657 case kAlpha_8_SkColorType: | |
658 return SKDEBUGCANVAS_COLORTYPE_ALPHA8; | |
659 default: | |
660 SkASSERT(false); | |
661 return SKDEBUGCANVAS_COLORTYPE_RGBA8888; | |
662 } | |
663 } | |
664 | |
665 static const char* alpha_type_name(SkAlphaType alphaType) { | |
666 switch (alphaType) { | |
667 case kOpaque_SkAlphaType: | |
668 return SKDEBUGCANVAS_ALPHATYPE_OPAQUE; | |
669 case kPremul_SkAlphaType: | |
670 return SKDEBUGCANVAS_ALPHATYPE_PREMUL; | |
671 case kUnpremul_SkAlphaType: | |
672 return SKDEBUGCANVAS_ALPHATYPE_UNPREMUL; | |
673 default: | |
674 SkASSERT(false); | |
675 return SKDEBUGCANVAS_ALPHATYPE_OPAQUE; | |
676 } | |
677 } | |
678 | |
679 // note that the caller is responsible for freeing the pointer | |
680 static Json::ArrayIndex decode_data(Json::Value bytes, void** target) { | |
681 Json::ArrayIndex size = bytes.size(); | |
682 *target = sk_malloc_throw(size); | |
683 for (Json::ArrayIndex i = 0; i < size; i++) { | |
684 ((uint8_t*) *target)[i] = bytes[i].asInt(); | |
685 } | |
686 return size; | |
687 } | |
688 | |
689 static SkFlattenable* load_flattenable(Json::Value jsonFlattenable) { | |
690 if (!jsonFlattenable.isMember(SKDEBUGCANVAS_ATTRIBUTE_NAME)) { | |
691 return nullptr; | |
692 } | |
693 const char* name = jsonFlattenable[SKDEBUGCANVAS_ATTRIBUTE_NAME].asCString()
; | |
694 SkFlattenable::Factory factory = SkFlattenable::NameToFactory(name); | |
695 if (factory == nullptr) { | |
696 SkDebugf("no factory for loading '%s'\n", name); | |
697 return nullptr; | |
698 } | |
699 void* data; | |
700 int size = decode_data(jsonFlattenable[SKDEBUGCANVAS_ATTRIBUTE_BYTES], &data
); | |
701 SkValidatingReadBuffer buffer(data, size); | |
702 SkFlattenable* result = factory(buffer); | |
703 free(data); | |
704 if (!buffer.isValid()) { | |
705 SkDebugf("invalid buffer loading flattenable\n"); | |
706 return nullptr; | |
707 } | |
708 return result; | |
709 } | |
710 | |
711 static SkColorType colortype_from_name(const char* name) { | |
712 if (!strcmp(name, SKDEBUGCANVAS_COLORTYPE_ARGB4444)) { | |
713 return kARGB_4444_SkColorType; | |
714 } | |
715 else if (!strcmp(name, SKDEBUGCANVAS_COLORTYPE_RGBA8888)) { | |
716 return kRGBA_8888_SkColorType; | |
717 } | |
718 else if (!strcmp(name, SKDEBUGCANVAS_COLORTYPE_BGRA8888)) { | |
719 return kBGRA_8888_SkColorType; | |
720 } | |
721 else if (!strcmp(name, SKDEBUGCANVAS_COLORTYPE_565)) { | |
722 return kRGB_565_SkColorType; | |
723 } | |
724 else if (!strcmp(name, SKDEBUGCANVAS_COLORTYPE_GRAY8)) { | |
725 return kGray_8_SkColorType; | |
726 } | |
727 else if (!strcmp(name, SKDEBUGCANVAS_COLORTYPE_INDEX8)) { | |
728 return kIndex_8_SkColorType; | |
729 } | |
730 else if (!strcmp(name, SKDEBUGCANVAS_COLORTYPE_ALPHA8)) { | |
731 return kAlpha_8_SkColorType; | |
732 } | |
733 SkASSERT(false); | |
734 return kN32_SkColorType; | |
735 } | |
736 | |
737 static SkBitmap* convert_colortype(SkBitmap* bitmap, SkColorType colorType) { | |
738 if (bitmap->colorType() == colorType ) { | |
739 return bitmap; | |
740 } | |
741 SkBitmap* dst = new SkBitmap(); | |
742 if (bitmap->copyTo(dst, colorType)) { | |
743 delete bitmap; | |
744 return dst; | |
745 } | |
746 SkASSERT(false); | |
747 delete dst; | |
748 return bitmap; | |
749 } | |
750 | |
751 // caller is responsible for freeing return value | |
752 static SkBitmap* load_bitmap(const Json::Value& jsonBitmap) { | |
753 if (!jsonBitmap.isMember(SKDEBUGCANVAS_ATTRIBUTE_BYTES)) { | |
754 SkDebugf("invalid bitmap\n"); | |
755 return nullptr; | |
756 } | |
757 void* data; | |
758 int size = decode_data(jsonBitmap[SKDEBUGCANVAS_ATTRIBUTE_BYTES], &data); | |
759 SkMemoryStream stream(data, size); | |
760 SkImageDecoder* decoder = SkImageDecoder::Factory(&stream); | |
761 SkBitmap* bitmap = new SkBitmap(); | |
762 SkImageDecoder::Result result = decoder->decode(&stream, bitmap, | |
763 SkImageDecoder::kDecodePixel
s_Mode); | |
764 free(decoder); | |
765 if (result != SkImageDecoder::kFailure) { | |
766 free(data); | |
767 if (jsonBitmap.isMember(SKDEBUGCANVAS_ATTRIBUTE_COLOR)) { | |
768 const char* ctName = jsonBitmap[SKDEBUGCANVAS_ATTRIBUTE_COLOR].asCSt
ring(); | |
769 SkColorType ct = colortype_from_name(ctName); | |
770 if (ct != kIndex_8_SkColorType) { | |
771 bitmap = convert_colortype(bitmap, ct); | |
772 } | |
773 } | |
774 return bitmap; | |
775 } | |
776 SkDebugf("image decode failed\n"); | |
777 free(data); | |
778 return nullptr; | |
779 } | |
780 | |
781 static SkImage* load_image(const Json::Value& jsonImage) { | |
782 SkBitmap* bitmap = load_bitmap(jsonImage); | |
783 if (bitmap == nullptr) { | |
784 return nullptr; | |
785 } | |
786 SkImage* result = SkImage::NewFromBitmap(*bitmap); | |
787 delete bitmap; | |
788 return result; | |
789 } | |
790 | |
791 static bool SK_WARN_UNUSED_RESULT flatten(const SkBitmap& bitmap, Json::Value* t
arget, | |
792 bool sendBinaries) { | |
793 bitmap.lockPixels(); | |
794 SkAutoTUnref<SkImage> image(SkImage::NewFromBitmap(bitmap)); | |
795 bitmap.unlockPixels(); | |
796 (*target)[SKDEBUGCANVAS_ATTRIBUTE_COLOR] = Json::Value(color_type_name(bitma
p.colorType())); | |
797 (*target)[SKDEBUGCANVAS_ATTRIBUTE_ALPHA] = Json::Value(alpha_type_name(bitma
p.alphaType())); | |
798 bool success = flatten(*image, target, sendBinaries); | |
799 return success; | |
800 } | |
801 | |
802 static void apply_paint_color(const SkPaint& paint, Json::Value* target) { | |
803 SkColor color = paint.getColor(); | |
804 if (color != SK_ColorBLACK) { | |
805 Json::Value colorValue(Json::arrayValue); | |
806 colorValue.append(Json::Value(SkColorGetA(color))); | |
807 colorValue.append(Json::Value(SkColorGetR(color))); | |
808 colorValue.append(Json::Value(SkColorGetG(color))); | |
809 colorValue.append(Json::Value(SkColorGetB(color))); | |
810 (*target)[SKDEBUGCANVAS_ATTRIBUTE_COLOR] = colorValue;; | |
811 } | |
812 } | |
813 | |
814 static void apply_paint_style(const SkPaint& paint, Json::Value* target) { | |
815 SkPaint::Style style = paint.getStyle(); | |
816 if (style != SkPaint::kFill_Style) { | |
817 switch (style) { | |
818 case SkPaint::kStroke_Style: { | |
819 Json::Value stroke(SKDEBUGCANVAS_STYLE_STROKE); | |
820 (*target)[SKDEBUGCANVAS_ATTRIBUTE_STYLE] = stroke; | |
821 break; | |
822 } | |
823 case SkPaint::kStrokeAndFill_Style: { | |
824 Json::Value strokeAndFill(SKDEBUGCANVAS_STYLE_STROKEANDFILL); | |
825 (*target)[SKDEBUGCANVAS_ATTRIBUTE_STYLE] = strokeAndFill; | |
826 break; | |
827 } | |
828 default: SkASSERT(false); | |
829 } | |
830 } | |
831 } | |
832 | |
833 static void apply_paint_cap(const SkPaint& paint, Json::Value* target) { | |
834 SkPaint::Cap cap = paint.getStrokeCap(); | |
835 if (cap != SkPaint::kDefault_Cap) { | |
836 switch (cap) { | |
837 case SkPaint::kButt_Cap: { | |
838 (*target)[SKDEBUGCANVAS_ATTRIBUTE_CAP] = Json::Value(SKDEBUGCANV
AS_CAP_BUTT); | |
839 break; | |
840 } | |
841 case SkPaint::kRound_Cap: { | |
842 (*target)[SKDEBUGCANVAS_ATTRIBUTE_CAP] = Json::Value(SKDEBUGCANV
AS_CAP_ROUND); | |
843 break; | |
844 } | |
845 case SkPaint::kSquare_Cap: { | |
846 (*target)[SKDEBUGCANVAS_ATTRIBUTE_CAP] = Json::Value(SKDEBUGCANV
AS_CAP_SQUARE); | |
847 break; | |
848 } | |
849 default: SkASSERT(false); | |
850 } | |
851 } | |
852 } | |
853 static void apply_paint_maskfilter(const SkPaint& paint, Json::Value* target, bo
ol sendBinaries) { | |
854 SkMaskFilter* maskFilter = paint.getMaskFilter(); | |
855 if (maskFilter != nullptr) { | |
856 SkMaskFilter::BlurRec blurRec; | |
857 if (maskFilter->asABlur(&blurRec)) { | |
858 Json::Value blur(Json::objectValue); | |
859 blur[SKDEBUGCANVAS_ATTRIBUTE_SIGMA] = Json::Value(blurRec.fSigma); | |
860 switch (blurRec.fStyle) { | |
861 case SkBlurStyle::kNormal_SkBlurStyle: | |
862 blur[SKDEBUGCANVAS_ATTRIBUTE_STYLE] = Json::Value(SKDEBUGCAN
VAS_BLURSTYLE_NORMAL); | |
863 break; | |
864 case SkBlurStyle::kSolid_SkBlurStyle: | |
865 blur[SKDEBUGCANVAS_ATTRIBUTE_STYLE] = Json::Value(SKDEBUGCAN
VAS_BLURSTYLE_SOLID); | |
866 break; | |
867 case SkBlurStyle::kOuter_SkBlurStyle: | |
868 blur[SKDEBUGCANVAS_ATTRIBUTE_STYLE] = Json::Value(SKDEBUGCAN
VAS_BLURSTYLE_OUTER); | |
869 break; | |
870 case SkBlurStyle::kInner_SkBlurStyle: | |
871 blur[SKDEBUGCANVAS_ATTRIBUTE_STYLE] = Json::Value(SKDEBUGCAN
VAS_BLURSTYLE_INNER); | |
872 break; | |
873 default: | |
874 SkASSERT(false); | |
875 } | |
876 switch (blurRec.fQuality) { | |
877 case SkBlurQuality::kLow_SkBlurQuality: | |
878 blur[SKDEBUGCANVAS_ATTRIBUTE_QUALITY] = Json::Value(SKDEBUGC
ANVAS_BLURQUALITY_LOW); | |
879 break; | |
880 case SkBlurQuality::kHigh_SkBlurQuality: | |
881 blur[SKDEBUGCANVAS_ATTRIBUTE_QUALITY] = Json::Value(SKDEBUGC
ANVAS_BLURQUALITY_HIGH); | |
882 break; | |
883 default: | |
884 SkASSERT(false); | |
885 } | |
886 (*target)[SKDEBUGCANVAS_ATTRIBUTE_BLUR] = blur; | |
887 } else { | |
888 Json::Value jsonMaskFilter; | |
889 flatten(maskFilter, &jsonMaskFilter, sendBinaries); | |
890 (*target)[SKDEBUGCANVAS_ATTRIBUTE_MASKFILTER] = jsonMaskFilter; | |
891 } | |
892 } | |
893 } | |
894 | |
895 static void apply_paint_patheffect(const SkPaint& paint, Json::Value* target, bo
ol sendBinaries) { | |
896 SkPathEffect* pathEffect = paint.getPathEffect(); | |
897 if (pathEffect != nullptr) { | |
898 SkPathEffect::DashInfo dashInfo; | |
899 SkPathEffect::DashType dashType = pathEffect->asADash(&dashInfo); | |
900 if (dashType == SkPathEffect::kDash_DashType) { | |
901 dashInfo.fIntervals = (SkScalar*) sk_malloc_throw(dashInfo.fCount *
sizeof(SkScalar)); | |
902 pathEffect->asADash(&dashInfo); | |
903 Json::Value dashing(Json::objectValue); | |
904 Json::Value intervals(Json::arrayValue); | |
905 for (int32_t i = 0; i < dashInfo.fCount; i++) { | |
906 intervals.append(Json::Value(dashInfo.fIntervals[i])); | |
907 } | |
908 free(dashInfo.fIntervals); | |
909 dashing[SKDEBUGCANVAS_ATTRIBUTE_INTERVALS] = intervals; | |
910 dashing[SKDEBUGCANVAS_ATTRIBUTE_PHASE] = dashInfo.fPhase; | |
911 (*target)[SKDEBUGCANVAS_ATTRIBUTE_DASHING] = dashing; | |
912 } else { | |
913 Json::Value jsonPathEffect; | |
914 flatten(pathEffect, &jsonPathEffect, sendBinaries); | |
915 (*target)[SKDEBUGCANVAS_ATTRIBUTE_PATHEFFECT] = jsonPathEffect; | |
916 } | |
917 } | |
918 } | |
919 | |
920 static void apply_paint_textalign(const SkPaint& paint, Json::Value* target) { | |
921 SkPaint::Align textAlign = paint.getTextAlign(); | |
922 if (textAlign != SkPaint::kLeft_Align) { | |
923 switch (textAlign) { | |
924 case SkPaint::kCenter_Align: { | |
925 (*target)[SKDEBUGCANVAS_ATTRIBUTE_TEXTALIGN] = SKDEBUGCANVAS_ALI
GN_CENTER; | |
926 break; | |
927 } | |
928 case SkPaint::kRight_Align: { | |
929 (*target)[SKDEBUGCANVAS_ATTRIBUTE_TEXTALIGN] = SKDEBUGCANVAS_ALI
GN_RIGHT; | |
930 break; | |
931 } | |
932 default: SkASSERT(false); | |
933 } | |
934 } | |
935 } | |
936 | |
937 static void apply_paint_typeface(const SkPaint& paint, Json::Value* target, | |
938 bool sendBinaries) { | |
939 SkTypeface* typeface = paint.getTypeface(); | |
940 if (typeface != nullptr) { | |
941 if (sendBinaries) { | |
942 Json::Value jsonTypeface; | |
943 SkDynamicMemoryWStream buffer; | |
944 typeface->serialize(&buffer); | |
945 void* data = sk_malloc_throw(buffer.bytesWritten()); | |
946 buffer.copyTo(data); | |
947 Json::Value bytes; | |
948 encode_data(data, buffer.bytesWritten(), &bytes); | |
949 jsonTypeface[SKDEBUGCANVAS_ATTRIBUTE_BYTES] = bytes; | |
950 free(data); | |
951 (*target)[SKDEBUGCANVAS_ATTRIBUTE_TYPEFACE] = jsonTypeface; | |
952 } | |
953 } | |
954 } | |
955 | |
956 static void apply_paint_shader(const SkPaint& paint, Json::Value* target, bool s
endBinaries) { | |
957 SkFlattenable* shader = paint.getShader(); | |
958 if (shader != nullptr) { | |
959 Json::Value jsonShader; | |
960 flatten(shader, &jsonShader, sendBinaries); | |
961 (*target)[SKDEBUGCANVAS_ATTRIBUTE_SHADER] = jsonShader; | |
962 } | |
963 } | |
964 | |
965 static void apply_paint_xfermode(const SkPaint& paint, Json::Value* target, bool
sendBinaries) { | |
966 SkFlattenable* xfermode = paint.getXfermode(); | |
967 if (xfermode != nullptr) { | |
968 Json::Value jsonXfermode; | |
969 flatten(xfermode, &jsonXfermode, sendBinaries); | |
970 (*target)[SKDEBUGCANVAS_ATTRIBUTE_XFERMODE] = jsonXfermode; | |
971 } | |
972 } | |
973 | |
974 static void apply_paint_imagefilter(const SkPaint& paint, Json::Value* target, b
ool sendBinaries) { | |
975 SkFlattenable* imageFilter = paint.getImageFilter(); | |
976 if (imageFilter != nullptr) { | |
977 Json::Value jsonImageFilter; | |
978 flatten(imageFilter, &jsonImageFilter, sendBinaries); | |
979 (*target)[SKDEBUGCANVAS_ATTRIBUTE_IMAGEFILTER] = jsonImageFilter; | |
980 } | |
981 } | |
982 | |
983 static void apply_paint_colorfilter(const SkPaint& paint, Json::Value* target, b
ool sendBinaries) { | |
984 SkFlattenable* colorFilter = paint.getColorFilter(); | |
985 if (colorFilter != nullptr) { | |
986 Json::Value jsonColorFilter; | |
987 flatten(colorFilter, &jsonColorFilter, sendBinaries); | |
988 (*target)[SKDEBUGCANVAS_ATTRIBUTE_COLORFILTER] = jsonColorFilter; | |
989 } | |
990 } | |
991 | |
992 Json::Value make_json_paint(const SkPaint& paint, bool sendBinaries) { | |
993 Json::Value result(Json::objectValue); | |
994 store_scalar(&result, SKDEBUGCANVAS_ATTRIBUTE_STROKEWIDTH, paint.getStrokeWi
dth(), 0.0f); | |
995 store_scalar(&result, SKDEBUGCANVAS_ATTRIBUTE_STROKEMITER, paint.getStrokeMi
ter(), | |
996 SkPaintDefaults_MiterLimit); | |
997 store_bool(&result, SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS, paint.isAntiAlias(),
false); | |
998 store_scalar(&result, SKDEBUGCANVAS_ATTRIBUTE_TEXTSIZE, paint.getTextSize(),
| |
999 SkPaintDefaults_TextSize); | |
1000 store_scalar(&result, SKDEBUGCANVAS_ATTRIBUTE_TEXTSCALEX, paint.getTextScale
X(), SK_Scalar1); | |
1001 store_scalar(&result, SKDEBUGCANVAS_ATTRIBUTE_TEXTSCALEX, paint.getTextSkewX
(), 0.0f); | |
1002 apply_paint_color(paint, &result); | |
1003 apply_paint_style(paint, &result); | |
1004 apply_paint_cap(paint, &result); | |
1005 apply_paint_textalign(paint, &result); | |
1006 apply_paint_patheffect(paint, &result, sendBinaries); | |
1007 apply_paint_maskfilter(paint, &result, sendBinaries); | |
1008 apply_paint_shader(paint, &result, sendBinaries); | |
1009 apply_paint_xfermode(paint, &result, sendBinaries); | |
1010 apply_paint_imagefilter(paint, &result, sendBinaries); | |
1011 apply_paint_colorfilter(paint, &result, sendBinaries); | |
1012 apply_paint_typeface(paint, &result, sendBinaries); | |
1013 return result; | |
1014 } | |
1015 | |
1016 static void extract_json_paint_color(Json::Value& jsonPaint, SkPaint* target) { | |
1017 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_COLOR)) { | |
1018 Json::Value color = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_COLOR]; | |
1019 target->setColor(SkColorSetARGB(color[0].asInt(), color[1].asInt(), colo
r[2].asInt(), | |
1020 color[3].asInt())); | |
1021 } | |
1022 } | |
1023 | |
1024 static void extract_json_paint_shader(Json::Value& jsonPaint, SkPaint* target) { | |
1025 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_SHADER)) { | |
1026 Json::Value jsonShader = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_SHADER]; | |
1027 SkShader* shader = (SkShader*) load_flattenable(jsonShader); | |
1028 if (shader != nullptr) { | |
1029 target->setShader(shader); | |
1030 shader->unref(); | |
1031 } | |
1032 } | |
1033 } | |
1034 | |
1035 static void extract_json_paint_patheffect(Json::Value& jsonPaint, SkPaint* targe
t) { | |
1036 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_PATHEFFECT)) { | |
1037 Json::Value jsonPathEffect = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_PATHEFFEC
T]; | |
1038 SkPathEffect* pathEffect = (SkPathEffect*) load_flattenable(jsonPathEffe
ct); | |
1039 if (pathEffect != nullptr) { | |
1040 target->setPathEffect(pathEffect); | |
1041 pathEffect->unref(); | |
1042 } | |
1043 } | |
1044 } | |
1045 | |
1046 static void extract_json_paint_maskfilter(Json::Value& jsonPaint, SkPaint* targe
t) { | |
1047 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_MASKFILTER)) { | |
1048 Json::Value jsonMaskFilter = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_MASKFILTE
R]; | |
1049 SkMaskFilter* maskFilter = (SkMaskFilter*) load_flattenable(jsonMaskFilt
er); | |
1050 if (maskFilter != nullptr) { | |
1051 target->setMaskFilter(maskFilter); | |
1052 maskFilter->unref(); | |
1053 } | |
1054 } | |
1055 } | |
1056 | |
1057 static void extract_json_paint_colorfilter(Json::Value& jsonPaint, SkPaint* targ
et) { | |
1058 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_COLORFILTER)) { | |
1059 Json::Value jsonColorFilter = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_COLORFIL
TER]; | |
1060 SkColorFilter* colorFilter = (SkColorFilter*) load_flattenable(jsonColor
Filter); | |
1061 if (colorFilter != nullptr) { | |
1062 target->setColorFilter(colorFilter); | |
1063 colorFilter->unref(); | |
1064 } | |
1065 } | |
1066 } | |
1067 | |
1068 static void extract_json_paint_xfermode(Json::Value& jsonPaint, SkPaint* target)
{ | |
1069 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_XFERMODE)) { | |
1070 Json::Value jsonXfermode = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_XFERMODE]; | |
1071 SkXfermode* xfermode = (SkXfermode*) load_flattenable(jsonXfermode); | |
1072 if (xfermode != nullptr) { | |
1073 target->setXfermode(xfermode); | |
1074 xfermode->unref(); | |
1075 } | |
1076 } | |
1077 } | |
1078 | |
1079 static void extract_json_paint_imagefilter(Json::Value& jsonPaint, SkPaint* targ
et) { | |
1080 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_IMAGEFILTER)) { | |
1081 Json::Value jsonImageFilter = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_IMAGEFIL
TER]; | |
1082 SkImageFilter* imageFilter = (SkImageFilter*) load_flattenable(jsonImage
Filter); | |
1083 if (imageFilter != nullptr) { | |
1084 target->setImageFilter(imageFilter); | |
1085 imageFilter->unref(); | |
1086 } | |
1087 } | |
1088 } | |
1089 | |
1090 static void extract_json_paint_style(Json::Value& jsonPaint, SkPaint* target) { | |
1091 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_STYLE)) { | |
1092 const char* style = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_STYLE].asCString()
; | |
1093 if (!strcmp(style, SKDEBUGCANVAS_STYLE_FILL)) { | |
1094 target->setStyle(SkPaint::kFill_Style); | |
1095 } | |
1096 else if (!strcmp(style, SKDEBUGCANVAS_STYLE_STROKE)) { | |
1097 target->setStyle(SkPaint::kStroke_Style); | |
1098 } | |
1099 else if (!strcmp(style, SKDEBUGCANVAS_STYLE_STROKEANDFILL)) { | |
1100 target->setStyle(SkPaint::kStrokeAndFill_Style); | |
1101 } | |
1102 } | |
1103 } | |
1104 | |
1105 static void extract_json_paint_strokewidth(Json::Value& jsonPaint, SkPaint* targ
et) { | |
1106 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_STROKEWIDTH)) { | |
1107 float strokeWidth = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_STROKEWIDTH].asFlo
at(); | |
1108 target->setStrokeWidth(strokeWidth); | |
1109 } | |
1110 } | |
1111 | |
1112 static void extract_json_paint_strokemiter(Json::Value& jsonPaint, SkPaint* targ
et) { | |
1113 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_STROKEMITER)) { | |
1114 float strokeMiter = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_STROKEMITER].asFlo
at(); | |
1115 target->setStrokeMiter(strokeMiter); | |
1116 } | |
1117 } | |
1118 | |
1119 static void extract_json_paint_cap(Json::Value& jsonPaint, SkPaint* target) { | |
1120 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_CAP)) { | |
1121 const char* cap = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_CAP].asCString(); | |
1122 if (!strcmp(cap, SKDEBUGCANVAS_CAP_BUTT)) { | |
1123 target->setStrokeCap(SkPaint::kButt_Cap); | |
1124 } | |
1125 else if (!strcmp(cap, SKDEBUGCANVAS_CAP_ROUND)) { | |
1126 target->setStrokeCap(SkPaint::kRound_Cap); | |
1127 } | |
1128 else if (!strcmp(cap, SKDEBUGCANVAS_CAP_SQUARE)) { | |
1129 target->setStrokeCap(SkPaint::kSquare_Cap); | |
1130 } | |
1131 } | |
1132 } | |
1133 | |
1134 static void extract_json_paint_antialias(Json::Value& jsonPaint, SkPaint* target
) { | |
1135 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS)) { | |
1136 target->setAntiAlias(jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS].asBool
()); | |
1137 } | |
1138 } | |
1139 | |
1140 static void extract_json_paint_blur(Json::Value& jsonPaint, SkPaint* target) { | |
1141 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_BLUR)) { | |
1142 Json::Value blur = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_BLUR]; | |
1143 SkScalar sigma = blur[SKDEBUGCANVAS_ATTRIBUTE_SIGMA].asFloat(); | |
1144 SkBlurStyle style; | |
1145 const char* jsonStyle = blur[SKDEBUGCANVAS_ATTRIBUTE_STYLE].asCString(); | |
1146 if (!strcmp(jsonStyle, SKDEBUGCANVAS_BLURSTYLE_NORMAL)) { | |
1147 style = SkBlurStyle::kNormal_SkBlurStyle; | |
1148 } | |
1149 else if (!strcmp(jsonStyle, SKDEBUGCANVAS_BLURSTYLE_SOLID)) { | |
1150 style = SkBlurStyle::kSolid_SkBlurStyle; | |
1151 } | |
1152 else if (!strcmp(jsonStyle, SKDEBUGCANVAS_BLURSTYLE_OUTER)) { | |
1153 style = SkBlurStyle::kOuter_SkBlurStyle; | |
1154 } | |
1155 else if (!strcmp(jsonStyle, SKDEBUGCANVAS_BLURSTYLE_INNER)) { | |
1156 style = SkBlurStyle::kInner_SkBlurStyle; | |
1157 } | |
1158 else { | |
1159 SkASSERT(false); | |
1160 style = SkBlurStyle::kNormal_SkBlurStyle; | |
1161 } | |
1162 SkBlurMaskFilter::BlurFlags flags; | |
1163 const char* jsonQuality = blur[SKDEBUGCANVAS_ATTRIBUTE_QUALITY].asCStrin
g(); | |
1164 if (!strcmp(jsonQuality, SKDEBUGCANVAS_BLURQUALITY_LOW)) { | |
1165 flags = SkBlurMaskFilter::BlurFlags::kNone_BlurFlag; | |
1166 } | |
1167 else if (!strcmp(jsonQuality, SKDEBUGCANVAS_BLURQUALITY_HIGH)) { | |
1168 flags = SkBlurMaskFilter::BlurFlags::kHighQuality_BlurFlag; | |
1169 } | |
1170 else { | |
1171 SkASSERT(false); | |
1172 flags = SkBlurMaskFilter::BlurFlags::kNone_BlurFlag; | |
1173 } | |
1174 target->setMaskFilter(SkBlurMaskFilter::Create(style, sigma, flags)); | |
1175 } | |
1176 } | |
1177 | |
1178 static void extract_json_paint_dashing(Json::Value& jsonPaint, SkPaint* target)
{ | |
1179 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_DASHING)) { | |
1180 Json::Value dash = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_DASHING]; | |
1181 Json::Value jsonIntervals = dash[SKDEBUGCANVAS_ATTRIBUTE_INTERVALS]; | |
1182 Json::ArrayIndex count = jsonIntervals.size(); | |
1183 SkScalar* intervals = (SkScalar*) sk_malloc_throw(count * sizeof(SkScala
r)); | |
1184 for (Json::ArrayIndex i = 0; i < count; i++) { | |
1185 intervals[i] = jsonIntervals[i].asFloat(); | |
1186 } | |
1187 SkScalar phase = dash[SKDEBUGCANVAS_ATTRIBUTE_PHASE].asFloat(); | |
1188 target->setPathEffect(SkDashPathEffect::Create(intervals, count, phase))
; | |
1189 free(intervals); | |
1190 } | |
1191 } | |
1192 | |
1193 static void extract_json_paint_textalign(Json::Value& jsonPaint, SkPaint* target
) { | |
1194 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_TEXTALIGN)) { | |
1195 SkPaint::Align textAlign; | |
1196 const char* jsonAlign = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_TEXTALIGN].asC
String(); | |
1197 if (!strcmp(jsonAlign, SKDEBUGCANVAS_ALIGN_LEFT)) { | |
1198 textAlign = SkPaint::kLeft_Align; | |
1199 } | |
1200 else if (!strcmp(jsonAlign, SKDEBUGCANVAS_ALIGN_CENTER)) { | |
1201 textAlign = SkPaint::kCenter_Align; | |
1202 } | |
1203 else if (!strcmp(jsonAlign, SKDEBUGCANVAS_ALIGN_RIGHT)) { | |
1204 textAlign = SkPaint::kRight_Align; | |
1205 } | |
1206 else { | |
1207 SkASSERT(false); | |
1208 textAlign = SkPaint::kLeft_Align; | |
1209 } | |
1210 target->setTextAlign(textAlign); | |
1211 } | |
1212 } | |
1213 | |
1214 static void extract_json_paint_textsize(Json::Value& jsonPaint, SkPaint* target)
{ | |
1215 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_TEXTSIZE)) { | |
1216 float textSize = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_TEXTSIZE].asFloat(); | |
1217 target->setTextSize(textSize); | |
1218 } | |
1219 } | |
1220 | |
1221 static void extract_json_paint_textscalex(Json::Value& jsonPaint, SkPaint* targe
t) { | |
1222 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_TEXTSCALEX)) { | |
1223 float textScaleX = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_TEXTSCALEX].asFloat
(); | |
1224 target->setTextScaleX(textScaleX); | |
1225 } | |
1226 } | |
1227 | |
1228 static void extract_json_paint_textskewx(Json::Value& jsonPaint, SkPaint* target
) { | |
1229 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_TEXTSKEWX)) { | |
1230 float textSkewX = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_TEXTSKEWX].asFloat()
; | |
1231 target->setTextSkewX(textSkewX); | |
1232 } | |
1233 } | |
1234 | |
1235 static void extract_json_paint_typeface(Json::Value& jsonPaint, SkPaint* target)
{ | |
1236 if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_TYPEFACE)) { | |
1237 Json::Value jsonTypeface = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_TYPEFACE]; | |
1238 Json::Value bytes = jsonTypeface[SKDEBUGCANVAS_ATTRIBUTE_BYTES]; | |
1239 void* data; | |
1240 Json::ArrayIndex length = decode_data(bytes, &data); | |
1241 SkMemoryStream buffer(data, length); | |
1242 SkTypeface* typeface = SkTypeface::Deserialize(&buffer); | |
1243 free(data); | |
1244 target->setTypeface(typeface); | |
1245 } | |
1246 } | |
1247 | |
1248 static void extract_json_paint(Json::Value& paint, SkPaint* result) { | |
1249 extract_json_paint_color(paint, result); | |
1250 extract_json_paint_shader(paint, result); | |
1251 extract_json_paint_patheffect(paint, result); | |
1252 extract_json_paint_maskfilter(paint, result); | |
1253 extract_json_paint_colorfilter(paint, result); | |
1254 extract_json_paint_xfermode(paint, result); | |
1255 extract_json_paint_imagefilter(paint, result); | |
1256 extract_json_paint_style(paint, result); | |
1257 extract_json_paint_strokewidth(paint, result); | |
1258 extract_json_paint_strokemiter(paint, result); | |
1259 extract_json_paint_cap(paint, result); | |
1260 extract_json_paint_antialias(paint, result); | |
1261 extract_json_paint_blur(paint, result); | |
1262 extract_json_paint_dashing(paint, result); | |
1263 extract_json_paint_textalign(paint, result); | |
1264 extract_json_paint_textsize(paint, result); | |
1265 extract_json_paint_textscalex(paint, result); | |
1266 extract_json_paint_textskewx(paint, result); | |
1267 extract_json_paint_typeface(paint, result); | |
1268 } | |
1269 | |
1270 static void extract_json_rect(Json::Value& rect, SkRect* result) { | |
1271 result->set(rect[0].asFloat(), rect[1].asFloat(), rect[2].asFloat(), rect[3]
.asFloat()); | |
1272 } | |
1273 | |
1274 static void extract_json_irect(Json::Value& rect, SkIRect* result) { | |
1275 result->set(rect[0].asInt(), rect[1].asInt(), rect[2].asInt(), rect[3].asInt
()); | |
1276 } | |
1277 | |
1278 static void extract_json_rrect(Json::Value& rrect, SkRRect* result) { | |
1279 SkVector radii[4] = { | |
1280 { rrect[1][0].asFloat(), rrect[1][1].asFloat() }, | |
1281 { rrect[2][0].asFloat(), rrect[2][1].asFloat() }, | |
1282 { rrect[3][0].asFloat(), rrect[3][1].asFloat() }, | |
1283 { rrect[4][0].asFloat(), rrect[4][1].asFloat() } | |
1284 }; | |
1285 result->setRectRadii(SkRect::MakeLTRB(rrect[0][0].asFloat(), rrect[0][1].asF
loat(), | |
1286 rrect[0][2].asFloat(), rrect[0][3].asF
loat()), | |
1287 radii); | |
1288 } | |
1289 | |
1290 static void extract_json_matrix(Json::Value& matrix, SkMatrix* result) { | |
1291 SkScalar values[] = { | |
1292 matrix[0][0].asFloat(), matrix[0][1].asFloat(), matrix[0][2].asFloat(), | |
1293 matrix[1][0].asFloat(), matrix[1][1].asFloat(), matrix[1][2].asFloat(), | |
1294 matrix[2][0].asFloat(), matrix[2][1].asFloat(), matrix[2][2].asFloat() | |
1295 }; | |
1296 result->set9(values); | |
1297 } | |
1298 | |
1299 static void extract_json_path(Json::Value& path, SkPath* result) { | |
1300 const char* fillType = path[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE].asCString(); | |
1301 if (!strcmp(fillType, SKDEBUGCANVAS_FILLTYPE_WINDING)) { | |
1302 result->setFillType(SkPath::kWinding_FillType); | |
1303 } | |
1304 else if (!strcmp(fillType, SKDEBUGCANVAS_FILLTYPE_EVENODD)) { | |
1305 result->setFillType(SkPath::kEvenOdd_FillType); | |
1306 } | |
1307 else if (!strcmp(fillType, SKDEBUGCANVAS_FILLTYPE_INVERSEWINDING)) { | |
1308 result->setFillType(SkPath::kInverseWinding_FillType); | |
1309 } | |
1310 else if (!strcmp(fillType, SKDEBUGCANVAS_FILLTYPE_INVERSEEVENODD)) { | |
1311 result->setFillType(SkPath::kInverseEvenOdd_FillType); | |
1312 } | |
1313 Json::Value verbs = path[SKDEBUGCANVAS_ATTRIBUTE_VERBS]; | |
1314 for (Json::ArrayIndex i = 0; i < verbs.size(); i++) { | |
1315 Json::Value verb = verbs[i]; | |
1316 if (verb.isString()) { | |
1317 SkASSERT(!strcmp(verb.asCString(), SKDEBUGCANVAS_VERB_CLOSE)); | |
1318 result->close(); | |
1319 } | |
1320 else { | |
1321 if (verb.isMember(SKDEBUGCANVAS_VERB_MOVE)) { | |
1322 Json::Value move = verb[SKDEBUGCANVAS_VERB_MOVE]; | |
1323 result->moveTo(move[0].asFloat(), move[1].asFloat()); | |
1324 } | |
1325 else if (verb.isMember(SKDEBUGCANVAS_VERB_LINE)) { | |
1326 Json::Value line = verb[SKDEBUGCANVAS_VERB_LINE]; | |
1327 result->lineTo(line[0].asFloat(), line[1].asFloat()); | |
1328 } | |
1329 else if (verb.isMember(SKDEBUGCANVAS_VERB_QUAD)) { | |
1330 Json::Value quad = verb[SKDEBUGCANVAS_VERB_QUAD]; | |
1331 result->quadTo(quad[0][0].asFloat(), quad[0][1].asFloat(), | |
1332 quad[1][0].asFloat(), quad[1][1].asFloat()); | |
1333 } | |
1334 else if (verb.isMember(SKDEBUGCANVAS_VERB_CUBIC)) { | |
1335 Json::Value cubic = verb[SKDEBUGCANVAS_VERB_CUBIC]; | |
1336 result->cubicTo(cubic[0][0].asFloat(), cubic[0][1].asFloat(), | |
1337 cubic[1][0].asFloat(), cubic[1][1].asFloat(), | |
1338 cubic[2][0].asFloat(), cubic[2][1].asFloat()); | |
1339 } | |
1340 else if (verb.isMember(SKDEBUGCANVAS_VERB_CONIC)) { | |
1341 Json::Value conic = verb[SKDEBUGCANVAS_VERB_CONIC]; | |
1342 result->conicTo(conic[0][0].asFloat(), conic[0][1].asFloat(), | |
1343 conic[1][0].asFloat(), conic[1][1].asFloat(), | |
1344 conic[2].asFloat()); | |
1345 } | |
1346 else { | |
1347 SkASSERT(false); | |
1348 } | |
1349 } | |
1350 } | |
1351 } | |
1352 | |
1353 SkRegion::Op get_json_regionop(Json::Value& jsonOp) { | |
1354 const char* op = jsonOp.asCString(); | |
1355 if (!strcmp(op, SKDEBUGCANVAS_REGIONOP_DIFFERENCE)) { | |
1356 return SkRegion::kDifference_Op; | |
1357 } | |
1358 else if (!strcmp(op, SKDEBUGCANVAS_REGIONOP_INTERSECT)) { | |
1359 return SkRegion::kIntersect_Op; | |
1360 } | |
1361 else if (!strcmp(op, SKDEBUGCANVAS_REGIONOP_UNION)) { | |
1362 return SkRegion::kUnion_Op; | |
1363 } | |
1364 else if (!strcmp(op, SKDEBUGCANVAS_REGIONOP_XOR)) { | |
1365 return SkRegion::kXOR_Op; | |
1366 } | |
1367 else if (!strcmp(op, SKDEBUGCANVAS_REGIONOP_REVERSE_DIFFERENCE)) { | |
1368 return SkRegion::kReverseDifference_Op; | |
1369 } | |
1370 else if (!strcmp(op, SKDEBUGCANVAS_REGIONOP_REPLACE)) { | |
1371 return SkRegion::kReplace_Op; | |
1372 } | |
1373 SkASSERT(false); | |
1374 return SkRegion::kIntersect_Op; | |
1375 } | |
1376 | |
1377 | 203 |
1378 SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool d
oAA) | 204 SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool d
oAA) |
1379 : INHERITED(kClipPath_OpType) { | 205 : INHERITED(kClipPath_OpType) { |
1380 fPath = path; | 206 fPath = path; |
1381 fOp = op; | 207 fOp = op; |
1382 fDoAA = doAA; | 208 fDoAA = doAA; |
1383 | 209 |
1384 fInfo.push(SkObjectParser::PathToString(path)); | 210 fInfo.push(SkObjectParser::PathToString(path)); |
1385 fInfo.push(SkObjectParser::RegionOpToString(op)); | 211 fInfo.push(SkObjectParser::RegionOpToString(op)); |
1386 fInfo.push(SkObjectParser::BoolToString(doAA)); | 212 fInfo.push(SkObjectParser::BoolToString(doAA)); |
1387 } | 213 } |
1388 | 214 |
1389 void SkClipPathCommand::execute(SkCanvas* canvas) const { | 215 void SkClipPathCommand::execute(SkCanvas* canvas) const { |
1390 canvas->clipPath(fPath, fOp, fDoAA); | 216 canvas->clipPath(fPath, fOp, fDoAA); |
1391 } | 217 } |
1392 | 218 |
1393 bool SkClipPathCommand::render(SkCanvas* canvas) const { | 219 bool SkClipPathCommand::render(SkCanvas* canvas) const { |
1394 render_path(canvas, fPath); | 220 render_path(canvas, fPath); |
1395 return true; | 221 return true; |
1396 } | 222 } |
1397 | 223 |
1398 Json::Value SkClipPathCommand::toJSON() const { | |
1399 Json::Value result = INHERITED::toJSON(); | |
1400 result[SKDEBUGCANVAS_ATTRIBUTE_PATH] = make_json_path(fPath); | |
1401 result[SKDEBUGCANVAS_ATTRIBUTE_REGIONOP] = make_json_regionop(fOp); | |
1402 result[SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS] = fDoAA; | |
1403 return result; | |
1404 } | |
1405 | |
1406 SkClipPathCommand* SkClipPathCommand::fromJSON(Json::Value& command) { | |
1407 SkPath path; | |
1408 extract_json_path(command[SKDEBUGCANVAS_ATTRIBUTE_PATH], &path); | |
1409 return new SkClipPathCommand(path, get_json_regionop(command[SKDEBUGCANVAS_A
TTRIBUTE_REGIONOP]), | |
1410 command[SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS].asBo
ol()); | |
1411 } | |
1412 | |
1413 SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkRegion::Op op
) | 224 SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkRegion::Op op
) |
1414 : INHERITED(kClipRegion_OpType) { | 225 : INHERITED(kClipRegion_OpType) { |
1415 fRegion = region; | 226 fRegion = region; |
1416 fOp = op; | 227 fOp = op; |
1417 | 228 |
1418 fInfo.push(SkObjectParser::RegionToString(region)); | 229 fInfo.push(SkObjectParser::RegionToString(region)); |
1419 fInfo.push(SkObjectParser::RegionOpToString(op)); | 230 fInfo.push(SkObjectParser::RegionOpToString(op)); |
1420 } | 231 } |
1421 | 232 |
1422 void SkClipRegionCommand::execute(SkCanvas* canvas) const { | 233 void SkClipRegionCommand::execute(SkCanvas* canvas) const { |
1423 canvas->clipRegion(fRegion, fOp); | 234 canvas->clipRegion(fRegion, fOp); |
1424 } | 235 } |
1425 | 236 |
1426 Json::Value SkClipRegionCommand::toJSON() const { | |
1427 Json::Value result = INHERITED::toJSON(); | |
1428 result[SKDEBUGCANVAS_ATTRIBUTE_REGION] = make_json_region(fRegion); | |
1429 result[SKDEBUGCANVAS_ATTRIBUTE_REGIONOP] = make_json_regionop(fOp); | |
1430 return result; | |
1431 } | |
1432 | |
1433 SkClipRegionCommand* SkClipRegionCommand::fromJSON(Json::Value& command) { | |
1434 SkASSERT(false); | |
1435 return nullptr; | |
1436 } | |
1437 | |
1438 SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool d
oAA) | 237 SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool d
oAA) |
1439 : INHERITED(kClipRect_OpType) { | 238 : INHERITED(kClipRect_OpType) { |
1440 fRect = rect; | 239 fRect = rect; |
1441 fOp = op; | 240 fOp = op; |
1442 fDoAA = doAA; | 241 fDoAA = doAA; |
1443 | 242 |
1444 fInfo.push(SkObjectParser::RectToString(rect)); | 243 fInfo.push(SkObjectParser::RectToString(rect)); |
1445 fInfo.push(SkObjectParser::RegionOpToString(op)); | 244 fInfo.push(SkObjectParser::RegionOpToString(op)); |
1446 fInfo.push(SkObjectParser::BoolToString(doAA)); | 245 fInfo.push(SkObjectParser::BoolToString(doAA)); |
1447 } | 246 } |
1448 | 247 |
1449 void SkClipRectCommand::execute(SkCanvas* canvas) const { | 248 void SkClipRectCommand::execute(SkCanvas* canvas) const { |
1450 canvas->clipRect(fRect, fOp, fDoAA); | 249 canvas->clipRect(fRect, fOp, fDoAA); |
1451 } | 250 } |
1452 | 251 |
1453 Json::Value SkClipRectCommand::toJSON() const { | |
1454 Json::Value result = INHERITED::toJSON(); | |
1455 result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = make_json_rect(fRect); | |
1456 result[SKDEBUGCANVAS_ATTRIBUTE_REGIONOP] = make_json_regionop(fOp); | |
1457 result[SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS] = Json::Value(fDoAA); | |
1458 return result; | |
1459 } | |
1460 | |
1461 SkClipRectCommand* SkClipRectCommand::fromJSON(Json::Value& command) { | |
1462 SkRect rect; | |
1463 extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_COORDS], &rect); | |
1464 return new SkClipRectCommand(rect, get_json_regionop(command[SKDEBUGCANVAS_A
TTRIBUTE_REGIONOP]), | |
1465 command[SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS].asBo
ol()); | |
1466 } | |
1467 | |
1468 SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bo
ol doAA) | 252 SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bo
ol doAA) |
1469 : INHERITED(kClipRRect_OpType) { | 253 : INHERITED(kClipRRect_OpType) { |
1470 fRRect = rrect; | 254 fRRect = rrect; |
1471 fOp = op; | 255 fOp = op; |
1472 fDoAA = doAA; | 256 fDoAA = doAA; |
1473 | 257 |
1474 fInfo.push(SkObjectParser::RRectToString(rrect)); | 258 fInfo.push(SkObjectParser::RRectToString(rrect)); |
1475 fInfo.push(SkObjectParser::RegionOpToString(op)); | 259 fInfo.push(SkObjectParser::RegionOpToString(op)); |
1476 fInfo.push(SkObjectParser::BoolToString(doAA)); | 260 fInfo.push(SkObjectParser::BoolToString(doAA)); |
1477 } | 261 } |
1478 | 262 |
1479 void SkClipRRectCommand::execute(SkCanvas* canvas) const { | 263 void SkClipRRectCommand::execute(SkCanvas* canvas) const { |
1480 canvas->clipRRect(fRRect, fOp, fDoAA); | 264 canvas->clipRRect(fRRect, fOp, fDoAA); |
1481 } | 265 } |
1482 | 266 |
1483 bool SkClipRRectCommand::render(SkCanvas* canvas) const { | 267 bool SkClipRRectCommand::render(SkCanvas* canvas) const { |
1484 render_rrect(canvas, fRRect); | 268 render_rrect(canvas, fRRect); |
1485 return true; | 269 return true; |
1486 } | 270 } |
1487 | 271 |
1488 Json::Value SkClipRRectCommand::toJSON() const { | |
1489 Json::Value result = INHERITED::toJSON(); | |
1490 result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = make_json_rrect(fRRect); | |
1491 result[SKDEBUGCANVAS_ATTRIBUTE_REGIONOP] = make_json_regionop(fOp); | |
1492 result[SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS] = Json::Value(fDoAA); | |
1493 return result; | |
1494 } | |
1495 | |
1496 SkClipRRectCommand* SkClipRRectCommand::fromJSON(Json::Value& command) { | |
1497 SkRRect rrect; | |
1498 extract_json_rrect(command[SKDEBUGCANVAS_ATTRIBUTE_COORDS], &rrect); | |
1499 return new SkClipRRectCommand(rrect, | |
1500 get_json_regionop(command[SKDEBUGCANVAS_ATTRIB
UTE_REGIONOP]), | |
1501 command[SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS].asB
ool()); | |
1502 } | |
1503 | |
1504 SkConcatCommand::SkConcatCommand(const SkMatrix& matrix) | 272 SkConcatCommand::SkConcatCommand(const SkMatrix& matrix) |
1505 : INHERITED(kConcat_OpType) { | 273 : INHERITED(kConcat_OpType) { |
1506 fMatrix = matrix; | 274 fMatrix = matrix; |
1507 | 275 |
1508 fInfo.push(SkObjectParser::MatrixToString(matrix)); | 276 fInfo.push(SkObjectParser::MatrixToString(matrix)); |
1509 } | 277 } |
1510 | 278 |
1511 void SkConcatCommand::execute(SkCanvas* canvas) const { | 279 void SkConcatCommand::execute(SkCanvas* canvas) const { |
1512 canvas->concat(fMatrix); | 280 canvas->concat(fMatrix); |
1513 } | 281 } |
1514 | 282 |
1515 Json::Value SkConcatCommand::toJSON() const { | |
1516 Json::Value result = INHERITED::toJSON(); | |
1517 result[SKDEBUGCANVAS_ATTRIBUTE_MATRIX] = make_json_matrix(fMatrix); | |
1518 return result; | |
1519 } | |
1520 | |
1521 SkConcatCommand* SkConcatCommand::fromJSON(Json::Value& command) { | |
1522 SkMatrix matrix; | |
1523 extract_json_matrix(command[SKDEBUGCANVAS_ATTRIBUTE_MATRIX], &matrix); | |
1524 return new SkConcatCommand(matrix); | |
1525 } | |
1526 | |
1527 SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left,
SkScalar top, | 283 SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left,
SkScalar top, |
1528 const SkPaint* paint) | 284 const SkPaint* paint) |
1529 : INHERITED(kDrawBitmap_OpType) { | 285 : INHERITED(kDrawBitmap_OpType) { |
1530 fBitmap = bitmap; | 286 fBitmap = bitmap; |
1531 fLeft = left; | 287 fLeft = left; |
1532 fTop = top; | 288 fTop = top; |
1533 if (paint) { | 289 if (paint) { |
1534 fPaint = *paint; | 290 fPaint = *paint; |
1535 fPaintPtr = &fPaint; | 291 fPaintPtr = &fPaint; |
1536 } else { | 292 } else { |
(...skipping 10 matching lines...) Expand all Loading... |
1547 | 303 |
1548 void SkDrawBitmapCommand::execute(SkCanvas* canvas) const { | 304 void SkDrawBitmapCommand::execute(SkCanvas* canvas) const { |
1549 canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr); | 305 canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr); |
1550 } | 306 } |
1551 | 307 |
1552 bool SkDrawBitmapCommand::render(SkCanvas* canvas) const { | 308 bool SkDrawBitmapCommand::render(SkCanvas* canvas) const { |
1553 render_bitmap(canvas, fBitmap); | 309 render_bitmap(canvas, fBitmap); |
1554 return true; | 310 return true; |
1555 } | 311 } |
1556 | 312 |
1557 Json::Value SkDrawBitmapCommand::toJSON() const { | |
1558 Json::Value result = INHERITED::toJSON(); | |
1559 Json::Value encoded; | |
1560 if (flatten(fBitmap, &encoded, SKDEBUGCANVAS_SEND_BINARIES)) { | |
1561 Json::Value command(Json::objectValue); | |
1562 result[SKDEBUGCANVAS_ATTRIBUTE_BITMAP] = encoded; | |
1563 result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = make_json_point(fLeft, fTop); | |
1564 if (fPaintPtr != nullptr) { | |
1565 result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(*fPaintPtr,
SKDEBUGCANVAS_SEND_BINARIES); | |
1566 } | |
1567 } | |
1568 return result; | |
1569 } | |
1570 | |
1571 SkDrawBitmapCommand* SkDrawBitmapCommand::fromJSON(Json::Value& command) { | |
1572 SkBitmap* bitmap = load_bitmap(command[SKDEBUGCANVAS_ATTRIBUTE_BITMAP]); | |
1573 if (bitmap == nullptr) { | |
1574 return nullptr; | |
1575 } | |
1576 Json::Value point = command[SKDEBUGCANVAS_ATTRIBUTE_COORDS]; | |
1577 SkPaint* paintPtr; | |
1578 SkPaint paint; | |
1579 if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_PAINT)) { | |
1580 extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], &paint); | |
1581 paintPtr = &paint; | |
1582 } | |
1583 else { | |
1584 paintPtr = nullptr; | |
1585 } | |
1586 SkDrawBitmapCommand* result = new SkDrawBitmapCommand(*bitmap, point[0].asFl
oat(), | |
1587 point[1].asFloat(), pa
intPtr); | |
1588 delete bitmap; | |
1589 return result; | |
1590 } | |
1591 | |
1592 SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const S
kIRect& center, | 313 SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const S
kIRect& center, |
1593 const SkRect& dst, const SkPain
t* paint) | 314 const SkRect& dst, const SkPain
t* paint) |
1594 : INHERITED(kDrawBitmapNine_OpType) { | 315 : INHERITED(kDrawBitmapNine_OpType) { |
1595 fBitmap = bitmap; | 316 fBitmap = bitmap; |
1596 fCenter = center; | 317 fCenter = center; |
1597 fDst = dst; | 318 fDst = dst; |
1598 if (paint) { | 319 if (paint) { |
1599 fPaint = *paint; | 320 fPaint = *paint; |
1600 fPaintPtr = &fPaint; | 321 fPaintPtr = &fPaint; |
1601 } else { | 322 } else { |
(...skipping 11 matching lines...) Expand all Loading... |
1613 void SkDrawBitmapNineCommand::execute(SkCanvas* canvas) const { | 334 void SkDrawBitmapNineCommand::execute(SkCanvas* canvas) const { |
1614 canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr); | 335 canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr); |
1615 } | 336 } |
1616 | 337 |
1617 bool SkDrawBitmapNineCommand::render(SkCanvas* canvas) const { | 338 bool SkDrawBitmapNineCommand::render(SkCanvas* canvas) const { |
1618 SkRect tmp = SkRect::Make(fCenter); | 339 SkRect tmp = SkRect::Make(fCenter); |
1619 render_bitmap(canvas, fBitmap, &tmp); | 340 render_bitmap(canvas, fBitmap, &tmp); |
1620 return true; | 341 return true; |
1621 } | 342 } |
1622 | 343 |
1623 Json::Value SkDrawBitmapNineCommand::toJSON() const { | |
1624 Json::Value result = INHERITED::toJSON(); | |
1625 Json::Value encoded; | |
1626 if (flatten(fBitmap, &encoded, SKDEBUGCANVAS_SEND_BINARIES)) { | |
1627 result[SKDEBUGCANVAS_ATTRIBUTE_BITMAP] = encoded; | |
1628 result[SKDEBUGCANVAS_ATTRIBUTE_CENTER] = make_json_irect(fCenter); | |
1629 result[SKDEBUGCANVAS_ATTRIBUTE_DST] = make_json_rect(fDst); | |
1630 if (fPaintPtr != nullptr) { | |
1631 result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(*fPaintPtr, | |
1632 SKDEBUGCANVA
S_SEND_BINARIES); | |
1633 } | |
1634 } | |
1635 return result; | |
1636 } | |
1637 | |
1638 SkDrawBitmapNineCommand* SkDrawBitmapNineCommand::fromJSON(Json::Value& command)
{ | |
1639 SkBitmap* bitmap = load_bitmap(command[SKDEBUGCANVAS_ATTRIBUTE_BITMAP]); | |
1640 if (bitmap == nullptr) { | |
1641 return nullptr; | |
1642 } | |
1643 SkIRect center; | |
1644 extract_json_irect(command[SKDEBUGCANVAS_ATTRIBUTE_CENTER], ¢er); | |
1645 SkRect dst; | |
1646 extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_DST], &dst); | |
1647 SkPaint* paintPtr; | |
1648 SkPaint paint; | |
1649 if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_PAINT)) { | |
1650 extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], &paint); | |
1651 paintPtr = &paint; | |
1652 } | |
1653 else { | |
1654 paintPtr = nullptr; | |
1655 } | |
1656 SkDrawBitmapNineCommand* result = new SkDrawBitmapNineCommand(*bitmap, cente
r, dst, paintPtr); | |
1657 delete bitmap; | |
1658 return result; | |
1659 } | |
1660 | |
1661 SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const S
kRect* src, | 344 SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const S
kRect* src, |
1662 const SkRect& dst, const SkPain
t* paint, | 345 const SkRect& dst, const SkPain
t* paint, |
1663 SkCanvas::SrcRectConstraint con
straint) | 346 SkCanvas::SrcRectConstraint con
straint) |
1664 : INHERITED(kDrawBitmapRect_OpType) { | 347 : INHERITED(kDrawBitmapRect_OpType) { |
1665 fBitmap = bitmap; | 348 fBitmap = bitmap; |
1666 if (src) { | 349 if (src) { |
1667 fSrc = *src; | 350 fSrc = *src; |
1668 } else { | 351 } else { |
1669 fSrc.setEmpty(); | 352 fSrc.setEmpty(); |
1670 } | 353 } |
(...skipping 20 matching lines...) Expand all Loading... |
1691 | 374 |
1692 void SkDrawBitmapRectCommand::execute(SkCanvas* canvas) const { | 375 void SkDrawBitmapRectCommand::execute(SkCanvas* canvas) const { |
1693 canvas->legacy_drawBitmapRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fCo
nstraint); | 376 canvas->legacy_drawBitmapRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fCo
nstraint); |
1694 } | 377 } |
1695 | 378 |
1696 bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const { | 379 bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const { |
1697 render_bitmap(canvas, fBitmap, this->srcRect()); | 380 render_bitmap(canvas, fBitmap, this->srcRect()); |
1698 return true; | 381 return true; |
1699 } | 382 } |
1700 | 383 |
1701 Json::Value SkDrawBitmapRectCommand::toJSON() const { | |
1702 Json::Value result = INHERITED::toJSON(); | |
1703 Json::Value encoded; | |
1704 if (flatten(fBitmap, &encoded, SKDEBUGCANVAS_SEND_BINARIES)) { | |
1705 result[SKDEBUGCANVAS_ATTRIBUTE_BITMAP] = encoded; | |
1706 if (!fSrc.isEmpty()) { | |
1707 result[SKDEBUGCANVAS_ATTRIBUTE_SRC] = make_json_rect(fSrc); | |
1708 } | |
1709 result[SKDEBUGCANVAS_ATTRIBUTE_DST] = make_json_rect(fDst); | |
1710 if (fPaintPtr != nullptr) { | |
1711 result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(*fPaintPtr, | |
1712 SKDEBUGCANVA
S_SEND_BINARIES); | |
1713 } | |
1714 if (fConstraint == SkCanvas::kStrict_SrcRectConstraint) { | |
1715 result[SKDEBUGCANVAS_ATTRIBUTE_STRICT] = Json::Value(true); | |
1716 } | |
1717 } | |
1718 return result; | |
1719 } | |
1720 | |
1721 SkDrawBitmapRectCommand* SkDrawBitmapRectCommand::fromJSON(Json::Value& command)
{ | |
1722 SkBitmap* bitmap = load_bitmap(command[SKDEBUGCANVAS_ATTRIBUTE_BITMAP]); | |
1723 if (bitmap == nullptr) { | |
1724 return nullptr; | |
1725 } | |
1726 SkRect dst; | |
1727 extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_DST], &dst); | |
1728 SkPaint* paintPtr; | |
1729 SkPaint paint; | |
1730 if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_PAINT)) { | |
1731 extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], &paint); | |
1732 paintPtr = &paint; | |
1733 } | |
1734 else { | |
1735 paintPtr = nullptr; | |
1736 } | |
1737 SkCanvas::SrcRectConstraint constraint; | |
1738 if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_STRICT) && | |
1739 command[SKDEBUGCANVAS_ATTRIBUTE_STRICT].asBool()) { | |
1740 constraint = SkCanvas::kStrict_SrcRectConstraint; | |
1741 } | |
1742 else { | |
1743 constraint = SkCanvas::kFast_SrcRectConstraint; | |
1744 } | |
1745 SkRect* srcPtr; | |
1746 SkRect src; | |
1747 if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_SRC)) { | |
1748 extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_SRC], &src); | |
1749 srcPtr = &src; | |
1750 } | |
1751 else { | |
1752 srcPtr = nullptr; | |
1753 } | |
1754 SkDrawBitmapRectCommand* result = new SkDrawBitmapRectCommand(*bitmap, srcPt
r, dst, paintPtr, | |
1755 constraint); | |
1756 delete bitmap; | |
1757 return result; | |
1758 } | |
1759 | |
1760 SkDrawImageCommand::SkDrawImageCommand(const SkImage* image, SkScalar left, SkSc
alar top, | 384 SkDrawImageCommand::SkDrawImageCommand(const SkImage* image, SkScalar left, SkSc
alar top, |
1761 const SkPaint* paint) | 385 const SkPaint* paint) |
1762 : INHERITED(kDrawImage_OpType) | 386 : INHERITED(kDrawImage_OpType) |
1763 , fImage(SkRef(image)) | 387 , fImage(SkRef(image)) |
1764 , fLeft(left) | 388 , fLeft(left) |
1765 , fTop(top) { | 389 , fTop(top) { |
1766 | 390 |
1767 fInfo.push(SkObjectParser::ImageToString(image)); | 391 fInfo.push(SkObjectParser::ImageToString(image)); |
1768 fInfo.push(SkObjectParser::ScalarToString(left, "Left: ")); | 392 fInfo.push(SkObjectParser::ScalarToString(left, "Left: ")); |
1769 fInfo.push(SkObjectParser::ScalarToString(top, "Top: ")); | 393 fInfo.push(SkObjectParser::ScalarToString(top, "Top: ")); |
(...skipping 12 matching lines...) Expand all Loading... |
1782 SkAutoCanvasRestore acr(canvas, true); | 406 SkAutoCanvasRestore acr(canvas, true); |
1783 canvas->clear(0xFFFFFFFF); | 407 canvas->clear(0xFFFFFFFF); |
1784 | 408 |
1785 xlate_and_scale_to_bounds(canvas, SkRect::MakeXYWH(fLeft, fTop, | 409 xlate_and_scale_to_bounds(canvas, SkRect::MakeXYWH(fLeft, fTop, |
1786 SkIntToScalar(fImage->wid
th()), | 410 SkIntToScalar(fImage->wid
th()), |
1787 SkIntToScalar(fImage->hei
ght()))); | 411 SkIntToScalar(fImage->hei
ght()))); |
1788 this->execute(canvas); | 412 this->execute(canvas); |
1789 return true; | 413 return true; |
1790 } | 414 } |
1791 | 415 |
1792 Json::Value SkDrawImageCommand::toJSON() const { | |
1793 Json::Value result = INHERITED::toJSON(); | |
1794 Json::Value encoded; | |
1795 if (flatten(*fImage, &encoded, SKDEBUGCANVAS_SEND_BINARIES)) { | |
1796 result[SKDEBUGCANVAS_ATTRIBUTE_IMAGE] = encoded; | |
1797 result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = make_json_point(fLeft, fTop); | |
1798 if (fPaint.isValid()) { | |
1799 result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(*fPaint.get(
), | |
1800 SKDEBUGCANVA
S_SEND_BINARIES); | |
1801 } | |
1802 } | |
1803 return result; | |
1804 } | |
1805 | |
1806 SkDrawImageCommand* SkDrawImageCommand::fromJSON(Json::Value& command) { | |
1807 SkImage* image = load_image(command[SKDEBUGCANVAS_ATTRIBUTE_IMAGE]); | |
1808 if (image == nullptr) { | |
1809 return nullptr; | |
1810 } | |
1811 Json::Value point = command[SKDEBUGCANVAS_ATTRIBUTE_COORDS]; | |
1812 SkPaint* paintPtr; | |
1813 SkPaint paint; | |
1814 if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_PAINT)) { | |
1815 extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], &paint); | |
1816 paintPtr = &paint; | |
1817 } | |
1818 else { | |
1819 paintPtr = nullptr; | |
1820 } | |
1821 SkDrawImageCommand* result = new SkDrawImageCommand(image, point[0].asFloat(
), | |
1822 point[1].asFloat(), pain
tPtr); | |
1823 image->unref(); | |
1824 return result; | |
1825 } | |
1826 | |
1827 SkDrawImageRectCommand::SkDrawImageRectCommand(const SkImage* image, const SkRec
t* src, | 416 SkDrawImageRectCommand::SkDrawImageRectCommand(const SkImage* image, const SkRec
t* src, |
1828 const SkRect& dst, const SkPaint*
paint, | 417 const SkRect& dst, const SkPaint*
paint, |
1829 SkCanvas::SrcRectConstraint const
raint) | 418 SkCanvas::SrcRectConstraint const
raint) |
1830 : INHERITED(kDrawImageRect_OpType) | 419 : INHERITED(kDrawImageRect_OpType) |
1831 , fImage(SkRef(image)) | 420 , fImage(SkRef(image)) |
1832 , fDst(dst) | 421 , fDst(dst) |
1833 , fConstraint(constraint) { | 422 , fConstraint(constraint) { |
1834 | 423 |
1835 if (src) { | 424 if (src) { |
1836 fSrc.set(*src); | 425 fSrc.set(*src); |
(...skipping 21 matching lines...) Expand all Loading... |
1858 bool SkDrawImageRectCommand::render(SkCanvas* canvas) const { | 447 bool SkDrawImageRectCommand::render(SkCanvas* canvas) const { |
1859 SkAutoCanvasRestore acr(canvas, true); | 448 SkAutoCanvasRestore acr(canvas, true); |
1860 canvas->clear(0xFFFFFFFF); | 449 canvas->clear(0xFFFFFFFF); |
1861 | 450 |
1862 xlate_and_scale_to_bounds(canvas, fDst); | 451 xlate_and_scale_to_bounds(canvas, fDst); |
1863 | 452 |
1864 this->execute(canvas); | 453 this->execute(canvas); |
1865 return true; | 454 return true; |
1866 } | 455 } |
1867 | 456 |
1868 Json::Value SkDrawImageRectCommand::toJSON() const { | |
1869 Json::Value result = INHERITED::toJSON(); | |
1870 Json::Value encoded; | |
1871 if (flatten(*fImage.get(), &encoded, SKDEBUGCANVAS_SEND_BINARIES)) { | |
1872 result[SKDEBUGCANVAS_ATTRIBUTE_BITMAP] = encoded; | |
1873 if (fSrc.isValid()) { | |
1874 result[SKDEBUGCANVAS_ATTRIBUTE_SRC] = make_json_rect(*fSrc.get()); | |
1875 } | |
1876 result[SKDEBUGCANVAS_ATTRIBUTE_DST] = make_json_rect(fDst); | |
1877 if (fPaint.isValid()) { | |
1878 result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(*fPaint.get(
), | |
1879 SKDEBUGCANVA
S_SEND_BINARIES); | |
1880 } | |
1881 if (fConstraint == SkCanvas::kStrict_SrcRectConstraint) { | |
1882 result[SKDEBUGCANVAS_ATTRIBUTE_STRICT] = Json::Value(true); | |
1883 } | |
1884 } | |
1885 return result; | |
1886 } | |
1887 | |
1888 SkDrawImageRectCommand* SkDrawImageRectCommand::fromJSON(Json::Value& command) { | |
1889 SkImage* image = load_image(command[SKDEBUGCANVAS_ATTRIBUTE_IMAGE]); | |
1890 if (image == nullptr) { | |
1891 return nullptr; | |
1892 } | |
1893 SkRect dst; | |
1894 extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_DST], &dst); | |
1895 SkPaint* paintPtr; | |
1896 SkPaint paint; | |
1897 if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_PAINT)) { | |
1898 extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], &paint); | |
1899 paintPtr = &paint; | |
1900 } | |
1901 else { | |
1902 paintPtr = nullptr; | |
1903 } | |
1904 SkCanvas::SrcRectConstraint constraint; | |
1905 if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_STRICT) && | |
1906 command[SKDEBUGCANVAS_ATTRIBUTE_STRICT].asBool()) { | |
1907 constraint = SkCanvas::kStrict_SrcRectConstraint; | |
1908 } | |
1909 else { | |
1910 constraint = SkCanvas::kFast_SrcRectConstraint; | |
1911 } | |
1912 SkRect* srcPtr; | |
1913 SkRect src; | |
1914 if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_SRC)) { | |
1915 extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_SRC], &src); | |
1916 srcPtr = &src; | |
1917 } | |
1918 else { | |
1919 srcPtr = nullptr; | |
1920 } | |
1921 SkDrawImageRectCommand* result = new SkDrawImageRectCommand(image, srcPtr, d
st, paintPtr, | |
1922 constraint); | |
1923 image->unref(); | |
1924 return result; | |
1925 } | |
1926 | |
1927 SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint) | 457 SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint) |
1928 : INHERITED(kDrawOval_OpType) { | 458 : INHERITED(kDrawOval_OpType) { |
1929 fOval = oval; | 459 fOval = oval; |
1930 fPaint = paint; | 460 fPaint = paint; |
1931 | 461 |
1932 fInfo.push(SkObjectParser::RectToString(oval)); | 462 fInfo.push(SkObjectParser::RectToString(oval)); |
1933 fInfo.push(SkObjectParser::PaintToString(paint)); | 463 fInfo.push(SkObjectParser::PaintToString(paint)); |
1934 } | 464 } |
1935 | 465 |
1936 void SkDrawOvalCommand::execute(SkCanvas* canvas) const { | 466 void SkDrawOvalCommand::execute(SkCanvas* canvas) const { |
1937 canvas->drawOval(fOval, fPaint); | 467 canvas->drawOval(fOval, fPaint); |
1938 } | 468 } |
1939 | 469 |
1940 bool SkDrawOvalCommand::render(SkCanvas* canvas) const { | 470 bool SkDrawOvalCommand::render(SkCanvas* canvas) const { |
1941 canvas->clear(0xFFFFFFFF); | 471 canvas->clear(0xFFFFFFFF); |
1942 canvas->save(); | 472 canvas->save(); |
1943 | 473 |
1944 xlate_and_scale_to_bounds(canvas, fOval); | 474 xlate_and_scale_to_bounds(canvas, fOval); |
1945 | 475 |
1946 SkPaint p; | 476 SkPaint p; |
1947 p.setColor(SK_ColorBLACK); | 477 p.setColor(SK_ColorBLACK); |
1948 p.setStyle(SkPaint::kStroke_Style); | 478 p.setStyle(SkPaint::kStroke_Style); |
1949 | 479 |
1950 canvas->drawOval(fOval, p); | 480 canvas->drawOval(fOval, p); |
1951 canvas->restore(); | 481 canvas->restore(); |
1952 | 482 |
1953 return true; | 483 return true; |
1954 } | 484 } |
1955 | 485 |
1956 Json::Value SkDrawOvalCommand::toJSON() const { | |
1957 Json::Value result = INHERITED::toJSON(); | |
1958 result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = make_json_rect(fOval); | |
1959 result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(fPaint, SKDEBUGCANVA
S_SEND_BINARIES); | |
1960 return result; | |
1961 } | |
1962 | |
1963 SkDrawOvalCommand* SkDrawOvalCommand::fromJSON(Json::Value& command) { | |
1964 SkRect coords; | |
1965 extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_COORDS], &coords); | |
1966 SkPaint paint; | |
1967 extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], &paint); | |
1968 return new SkDrawOvalCommand(coords, paint); | |
1969 } | |
1970 | |
1971 SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint) | 486 SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint) |
1972 : INHERITED(kDrawPaint_OpType) { | 487 : INHERITED(kDrawPaint_OpType) { |
1973 fPaint = paint; | 488 fPaint = paint; |
1974 | 489 |
1975 fInfo.push(SkObjectParser::PaintToString(paint)); | 490 fInfo.push(SkObjectParser::PaintToString(paint)); |
1976 } | 491 } |
1977 | 492 |
1978 void SkDrawPaintCommand::execute(SkCanvas* canvas) const { | 493 void SkDrawPaintCommand::execute(SkCanvas* canvas) const { |
1979 canvas->drawPaint(fPaint); | 494 canvas->drawPaint(fPaint); |
1980 } | 495 } |
1981 | 496 |
1982 bool SkDrawPaintCommand::render(SkCanvas* canvas) const { | 497 bool SkDrawPaintCommand::render(SkCanvas* canvas) const { |
1983 canvas->clear(0xFFFFFFFF); | 498 canvas->clear(0xFFFFFFFF); |
1984 canvas->drawPaint(fPaint); | 499 canvas->drawPaint(fPaint); |
1985 return true; | 500 return true; |
1986 } | 501 } |
1987 | 502 |
1988 Json::Value SkDrawPaintCommand::toJSON() const { | |
1989 Json::Value result = INHERITED::toJSON(); | |
1990 result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(fPaint, SKDEBUGCANVA
S_SEND_BINARIES); | |
1991 return result; | |
1992 } | |
1993 | |
1994 SkDrawPaintCommand* SkDrawPaintCommand::fromJSON(Json::Value& command) { | |
1995 SkPaint paint; | |
1996 extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], &paint); | |
1997 return new SkDrawPaintCommand(paint); | |
1998 } | |
1999 | |
2000 SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint) | 503 SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint) |
2001 : INHERITED(kDrawPath_OpType) { | 504 : INHERITED(kDrawPath_OpType) { |
2002 fPath = path; | 505 fPath = path; |
2003 fPaint = paint; | 506 fPaint = paint; |
2004 | 507 |
2005 fInfo.push(SkObjectParser::PathToString(path)); | 508 fInfo.push(SkObjectParser::PathToString(path)); |
2006 fInfo.push(SkObjectParser::PaintToString(paint)); | 509 fInfo.push(SkObjectParser::PaintToString(paint)); |
2007 } | 510 } |
2008 | 511 |
2009 void SkDrawPathCommand::execute(SkCanvas* canvas) const { | 512 void SkDrawPathCommand::execute(SkCanvas* canvas) const { |
2010 canvas->drawPath(fPath, fPaint); | 513 canvas->drawPath(fPath, fPaint); |
2011 } | 514 } |
2012 | 515 |
2013 bool SkDrawPathCommand::render(SkCanvas* canvas) const { | 516 bool SkDrawPathCommand::render(SkCanvas* canvas) const { |
2014 render_path(canvas, fPath); | 517 render_path(canvas, fPath); |
2015 return true; | 518 return true; |
2016 } | 519 } |
2017 | 520 |
2018 Json::Value SkDrawPathCommand::toJSON() const { | |
2019 Json::Value result = INHERITED::toJSON(); | |
2020 result[SKDEBUGCANVAS_ATTRIBUTE_PATH] = make_json_path(fPath); | |
2021 result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(fPaint, SKDEBUGCANVA
S_SEND_BINARIES); | |
2022 return result; | |
2023 } | |
2024 | |
2025 SkDrawPathCommand* SkDrawPathCommand::fromJSON(Json::Value& command) { | |
2026 SkPath path; | |
2027 extract_json_path(command[SKDEBUGCANVAS_ATTRIBUTE_PATH], &path); | |
2028 SkPaint paint; | |
2029 extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], &paint); | |
2030 return new SkDrawPathCommand(path, paint); | |
2031 } | |
2032 | |
2033 SkBeginDrawPictureCommand::SkBeginDrawPictureCommand(const SkPicture* picture, | 521 SkBeginDrawPictureCommand::SkBeginDrawPictureCommand(const SkPicture* picture, |
2034 const SkMatrix* matrix, | 522 const SkMatrix* matrix, |
2035 const SkPaint* paint) | 523 const SkPaint* paint) |
2036 : INHERITED(kBeginDrawPicture_OpType) | 524 : INHERITED(kBeginDrawPicture_OpType) |
2037 , fPicture(SkRef(picture)) { | 525 , fPicture(SkRef(picture)) { |
2038 | 526 |
2039 SkString* str = new SkString; | 527 SkString* str = new SkString; |
2040 str->appendf("SkPicture: L: %f T: %f R: %f B: %f", | 528 str->appendf("SkPicture: L: %f T: %f R: %f B: %f", |
2041 picture->cullRect().fLeft, picture->cullRect().fTop, | 529 picture->cullRect().fLeft, picture->cullRect().fTop, |
2042 picture->cullRect().fRight, picture->cullRect().fBottom); | 530 picture->cullRect().fRight, picture->cullRect().fBottom); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2129 SkPaint p; | 617 SkPaint p; |
2130 p.setColor(SK_ColorBLACK); | 618 p.setColor(SK_ColorBLACK); |
2131 p.setStyle(SkPaint::kStroke_Style); | 619 p.setStyle(SkPaint::kStroke_Style); |
2132 | 620 |
2133 canvas->drawPoints(fMode, fCount, fPts, p); | 621 canvas->drawPoints(fMode, fCount, fPts, p); |
2134 canvas->restore(); | 622 canvas->restore(); |
2135 | 623 |
2136 return true; | 624 return true; |
2137 } | 625 } |
2138 | 626 |
2139 Json::Value SkDrawPointsCommand::toJSON() const { | |
2140 Json::Value result = INHERITED::toJSON(); | |
2141 result[SKDEBUGCANVAS_ATTRIBUTE_MODE] = make_json_pointmode(fMode); | |
2142 Json::Value points(Json::arrayValue); | |
2143 for (size_t i = 0; i < fCount; i++) { | |
2144 points.append(make_json_point(fPts[i])); | |
2145 } | |
2146 result[SKDEBUGCANVAS_ATTRIBUTE_POINTS] = points; | |
2147 result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(fPaint, SKDEBUGCANVA
S_SEND_BINARIES); | |
2148 return result; | |
2149 } | |
2150 | |
2151 SkDrawPointsCommand* SkDrawPointsCommand::fromJSON(Json::Value& command) { | |
2152 SkCanvas::PointMode mode; | |
2153 const char* jsonMode = command[SKDEBUGCANVAS_ATTRIBUTE_MODE].asCString(); | |
2154 if (!strcmp(jsonMode, SKDEBUGCANVAS_POINTMODE_POINTS)) { | |
2155 mode = SkCanvas::kPoints_PointMode; | |
2156 } | |
2157 else if (!strcmp(jsonMode, SKDEBUGCANVAS_POINTMODE_LINES)) { | |
2158 mode = SkCanvas::kLines_PointMode; | |
2159 } | |
2160 else if (!strcmp(jsonMode, SKDEBUGCANVAS_POINTMODE_POLYGON)) { | |
2161 mode = SkCanvas::kPolygon_PointMode; | |
2162 } | |
2163 else { | |
2164 SkASSERT(false); | |
2165 return nullptr; | |
2166 } | |
2167 Json::Value jsonPoints = command[SKDEBUGCANVAS_ATTRIBUTE_POINTS]; | |
2168 int count = (int) jsonPoints.size(); | |
2169 SkPoint* points = (SkPoint*) sk_malloc_throw(count * sizeof(SkPoint)); | |
2170 for (int i = 0; i < count; i++) { | |
2171 points[i] = SkPoint::Make(jsonPoints[i][0].asFloat(), jsonPoints[i][1].a
sFloat()); | |
2172 } | |
2173 SkPaint paint; | |
2174 extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], &paint); | |
2175 SkDrawPointsCommand* result = new SkDrawPointsCommand(mode, count, points, p
aint); | |
2176 free(points); | |
2177 return result; | |
2178 } | |
2179 | |
2180 SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength, | 627 SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength, |
2181 const SkPoint pos[], const SkPaint& p
aint) | 628 const SkPoint pos[], const SkPaint& p
aint) |
2182 : INHERITED(kDrawPosText_OpType) { | 629 : INHERITED(kDrawPosText_OpType) { |
2183 size_t numPts = paint.countText(text, byteLength); | 630 size_t numPts = paint.countText(text, byteLength); |
2184 | 631 |
2185 fText = new char[byteLength]; | 632 fText = new char[byteLength]; |
2186 memcpy(fText, text, byteLength); | 633 memcpy(fText, text, byteLength); |
2187 fByteLength = byteLength; | 634 fByteLength = byteLength; |
2188 | 635 |
2189 fPos = new SkPoint[numPts]; | 636 fPos = new SkPoint[numPts]; |
2190 memcpy(fPos, pos, numPts * sizeof(SkPoint)); | 637 memcpy(fPos, pos, numPts * sizeof(SkPoint)); |
2191 | 638 |
2192 fPaint = paint; | 639 fPaint = paint; |
2193 | 640 |
2194 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncod
ing())); | 641 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncod
ing())); |
2195 // TODO(chudy): Test that this works. | 642 // TODO(chudy): Test that this works. |
2196 fInfo.push(SkObjectParser::PointsToString(pos, 1)); | 643 fInfo.push(SkObjectParser::PointsToString(pos, 1)); |
2197 fInfo.push(SkObjectParser::PaintToString(paint)); | 644 fInfo.push(SkObjectParser::PaintToString(paint)); |
2198 } | 645 } |
2199 | 646 |
2200 void SkDrawPosTextCommand::execute(SkCanvas* canvas) const { | 647 void SkDrawPosTextCommand::execute(SkCanvas* canvas) const { |
2201 canvas->drawPosText(fText, fByteLength, fPos, fPaint); | 648 canvas->drawPosText(fText, fByteLength, fPos, fPaint); |
2202 } | 649 } |
2203 | 650 |
2204 Json::Value SkDrawPosTextCommand::toJSON() const { | |
2205 Json::Value result = INHERITED::toJSON(); | |
2206 result[SKDEBUGCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) fText, | |
2207 ((const char*) fText) + f
ByteLength); | |
2208 Json::Value coords(Json::arrayValue); | |
2209 for (size_t i = 0; i < fByteLength; i++) { | |
2210 coords.append(make_json_point(fPos[i])); | |
2211 } | |
2212 result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = coords; | |
2213 result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(fPaint, SKDEBUGCANVA
S_SEND_BINARIES); | |
2214 return result; | |
2215 } | |
2216 | |
2217 SkDrawPosTextCommand* SkDrawPosTextCommand::fromJSON(Json::Value& command) { | |
2218 const char* text = command[SKDEBUGCANVAS_ATTRIBUTE_TEXT].asCString(); | |
2219 SkPaint paint; | |
2220 extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], &paint); | |
2221 Json::Value coords = command[SKDEBUGCANVAS_ATTRIBUTE_COORDS]; | |
2222 int count = (int) coords.size(); | |
2223 SkPoint* points = (SkPoint*) sk_malloc_throw(count * sizeof(SkPoint)); | |
2224 for (int i = 0; i < count; i++) { | |
2225 points[i] = SkPoint::Make(coords[i][0].asFloat(), coords[i][1].asFloat()
); | |
2226 } | |
2227 return new SkDrawPosTextCommand(text, strlen(text), points, paint); | |
2228 } | |
2229 | 651 |
2230 SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength
, | 652 SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength
, |
2231 const SkScalar xpos[], SkScalar con
stY, | 653 const SkScalar xpos[], SkScalar con
stY, |
2232 const SkPaint& paint) | 654 const SkPaint& paint) |
2233 : INHERITED(kDrawPosTextH_OpType) { | 655 : INHERITED(kDrawPosTextH_OpType) { |
2234 size_t numPts = paint.countText(text, byteLength); | 656 size_t numPts = paint.countText(text, byteLength); |
2235 | 657 |
2236 fText = new char[byteLength]; | 658 fText = new char[byteLength]; |
2237 memcpy(fText, text, byteLength); | 659 memcpy(fText, text, byteLength); |
2238 fByteLength = byteLength; | 660 fByteLength = byteLength; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2309 SkRect bounds = fBlob->bounds().makeOffset(fXPos, fYPos); | 731 SkRect bounds = fBlob->bounds().makeOffset(fXPos, fYPos); |
2310 xlate_and_scale_to_bounds(canvas, bounds); | 732 xlate_and_scale_to_bounds(canvas, bounds); |
2311 | 733 |
2312 canvas->drawTextBlob(fBlob.get(), fXPos, fYPos, fPaint); | 734 canvas->drawTextBlob(fBlob.get(), fXPos, fYPos, fPaint); |
2313 | 735 |
2314 canvas->restore(); | 736 canvas->restore(); |
2315 | 737 |
2316 return true; | 738 return true; |
2317 } | 739 } |
2318 | 740 |
2319 Json::Value SkDrawTextBlobCommand::toJSON() const { | |
2320 Json::Value result = INHERITED::toJSON(); | |
2321 Json::Value runs(Json::arrayValue); | |
2322 SkTextBlobRunIterator iter(fBlob.get()); | |
2323 while (!iter.done()) { | |
2324 Json::Value run(Json::objectValue); | |
2325 Json::Value jsonPositions(Json::arrayValue); | |
2326 Json::Value jsonGlyphs(Json::arrayValue); | |
2327 const SkScalar* iterPositions = iter.pos(); | |
2328 const uint16_t* iterGlyphs = iter.glyphs(); | |
2329 for (uint32_t i = 0; i < iter.glyphCount(); i++) { | |
2330 switch (iter.positioning()) { | |
2331 case SkTextBlob::kFull_Positioning: | |
2332 jsonPositions.append(make_json_point(iterPositions[i * 2], | |
2333 iterPositions[i * 2 + 1
])); | |
2334 break; | |
2335 case SkTextBlob::kHorizontal_Positioning: | |
2336 jsonPositions.append(Json::Value(iterPositions[i])); | |
2337 break; | |
2338 case SkTextBlob::kDefault_Positioning: | |
2339 break; | |
2340 } | |
2341 jsonGlyphs.append(Json::Value(iterGlyphs[i])); | |
2342 } | |
2343 if (iter.positioning() != SkTextBlob::kDefault_Positioning) { | |
2344 run[SKDEBUGCANVAS_ATTRIBUTE_POSITIONS] = jsonPositions; | |
2345 } | |
2346 run[SKDEBUGCANVAS_ATTRIBUTE_GLYPHS] = jsonGlyphs; | |
2347 SkPaint fontPaint; | |
2348 iter.applyFontToPaint(&fontPaint); | |
2349 run[SKDEBUGCANVAS_ATTRIBUTE_FONT] = make_json_paint(fontPaint, SKDEBUGCA
NVAS_SEND_BINARIES); | |
2350 run[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = make_json_point(iter.offset()); | |
2351 runs.append(run); | |
2352 iter.next(); | |
2353 } | |
2354 result[SKDEBUGCANVAS_ATTRIBUTE_RUNS] = runs; | |
2355 result[SKDEBUGCANVAS_ATTRIBUTE_X] = Json::Value(fXPos); | |
2356 result[SKDEBUGCANVAS_ATTRIBUTE_Y] = Json::Value(fYPos); | |
2357 result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(fPaint, SKDEBUGCANVA
S_SEND_BINARIES); | |
2358 return result; | |
2359 } | |
2360 | |
2361 SkDrawTextBlobCommand* SkDrawTextBlobCommand::fromJSON(Json::Value& command) { | |
2362 SkTextBlobBuilder builder; | |
2363 Json::Value runs = command[SKDEBUGCANVAS_ATTRIBUTE_RUNS]; | |
2364 for (Json::ArrayIndex i = 0 ; i < runs.size(); i++) { | |
2365 Json::Value run = runs[i]; | |
2366 SkPaint font; | |
2367 font.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | |
2368 extract_json_paint(run[SKDEBUGCANVAS_ATTRIBUTE_FONT], &font); | |
2369 Json::Value glyphs = run[SKDEBUGCANVAS_ATTRIBUTE_GLYPHS]; | |
2370 int count = glyphs.size(); | |
2371 Json::Value coords = run[SKDEBUGCANVAS_ATTRIBUTE_COORDS]; | |
2372 SkScalar x = coords[0].asFloat(); | |
2373 SkScalar y = coords[1].asFloat(); | |
2374 if (run.isMember(SKDEBUGCANVAS_ATTRIBUTE_POSITIONS)) { | |
2375 Json::Value positions = run[SKDEBUGCANVAS_ATTRIBUTE_POSITIONS]; | |
2376 if (positions.size() > 0 && positions[0].isNumeric()) { | |
2377 SkTextBlobBuilder::RunBuffer buffer = builder.allocRunPosH(font,
count, y); | |
2378 for (int j = 0; j < count; j++) { | |
2379 buffer.glyphs[j] = glyphs[j].asUInt(); | |
2380 buffer.pos[j] = positions[j].asFloat(); | |
2381 } | |
2382 } | |
2383 else { | |
2384 SkTextBlobBuilder::RunBuffer buffer = builder.allocRunPos(font,
count); | |
2385 for (int j = 0; j < count; j++) { | |
2386 buffer.glyphs[j] = glyphs[j].asUInt(); | |
2387 buffer.pos[j * 2] = positions[j][0].asFloat(); | |
2388 buffer.pos[j * 2 + 1] = positions[j][1].asFloat(); | |
2389 } | |
2390 } | |
2391 } | |
2392 else { | |
2393 SkTextBlobBuilder::RunBuffer buffer = builder.allocRun(font, count,
x, y); | |
2394 for (int j = 0; j < count; j++) { | |
2395 buffer.glyphs[j] = glyphs[j].asUInt(); | |
2396 } | |
2397 } | |
2398 } | |
2399 SkScalar x = command[SKDEBUGCANVAS_ATTRIBUTE_X].asFloat(); | |
2400 SkScalar y = command[SKDEBUGCANVAS_ATTRIBUTE_Y].asFloat(); | |
2401 SkPaint paint; | |
2402 extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], &paint); | |
2403 return new SkDrawTextBlobCommand(builder.build(), x, y, paint); | |
2404 } | |
2405 | |
2406 SkDrawPatchCommand::SkDrawPatchCommand(const SkPoint cubics[12], const SkColor c
olors[4], | 741 SkDrawPatchCommand::SkDrawPatchCommand(const SkPoint cubics[12], const SkColor c
olors[4], |
2407 const SkPoint texCoords[4], SkXfermode* x
fermode, | 742 const SkPoint texCoords[4], SkXfermode* x
fermode, |
2408 const SkPaint& paint) | 743 const SkPaint& paint) |
2409 : INHERITED(kDrawPatch_OpType) { | 744 : INHERITED(kDrawPatch_OpType) { |
2410 memcpy(fCubics, cubics, sizeof(fCubics)); | 745 memcpy(fCubics, cubics, sizeof(fCubics)); |
2411 memcpy(fColors, colors, sizeof(fColors)); | 746 memcpy(fColors, colors, sizeof(fColors)); |
2412 memcpy(fTexCoords, texCoords, sizeof(fTexCoords)); | 747 memcpy(fTexCoords, texCoords, sizeof(fTexCoords)); |
2413 fXfermode.reset(xfermode); | 748 fXfermode.reset(xfermode); |
2414 fPaint = paint; | 749 fPaint = paint; |
2415 | 750 |
(...skipping 10 matching lines...) Expand all Loading... |
2426 fPaint = paint; | 761 fPaint = paint; |
2427 | 762 |
2428 fInfo.push(SkObjectParser::RectToString(rect)); | 763 fInfo.push(SkObjectParser::RectToString(rect)); |
2429 fInfo.push(SkObjectParser::PaintToString(paint)); | 764 fInfo.push(SkObjectParser::PaintToString(paint)); |
2430 } | 765 } |
2431 | 766 |
2432 void SkDrawRectCommand::execute(SkCanvas* canvas) const { | 767 void SkDrawRectCommand::execute(SkCanvas* canvas) const { |
2433 canvas->drawRect(fRect, fPaint); | 768 canvas->drawRect(fRect, fPaint); |
2434 } | 769 } |
2435 | 770 |
2436 Json::Value SkDrawRectCommand::toJSON() const { | |
2437 Json::Value result = INHERITED::toJSON(); | |
2438 result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = make_json_rect(fRect); | |
2439 result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(fPaint, SKDEBUGCANVA
S_SEND_BINARIES); | |
2440 return result; | |
2441 } | |
2442 | |
2443 SkDrawRectCommand* SkDrawRectCommand::fromJSON(Json::Value& command) { | |
2444 SkRect coords; | |
2445 extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_COORDS], &coords); | |
2446 SkPaint paint; | |
2447 extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], &paint); | |
2448 return new SkDrawRectCommand(coords, paint); | |
2449 } | |
2450 | |
2451 SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& pain
t) | 771 SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& pain
t) |
2452 : INHERITED(kDrawRRect_OpType) { | 772 : INHERITED(kDrawRRect_OpType) { |
2453 fRRect = rrect; | 773 fRRect = rrect; |
2454 fPaint = paint; | 774 fPaint = paint; |
2455 | 775 |
2456 fInfo.push(SkObjectParser::RRectToString(rrect)); | 776 fInfo.push(SkObjectParser::RRectToString(rrect)); |
2457 fInfo.push(SkObjectParser::PaintToString(paint)); | 777 fInfo.push(SkObjectParser::PaintToString(paint)); |
2458 } | 778 } |
2459 | 779 |
2460 void SkDrawRRectCommand::execute(SkCanvas* canvas) const { | 780 void SkDrawRRectCommand::execute(SkCanvas* canvas) const { |
2461 canvas->drawRRect(fRRect, fPaint); | 781 canvas->drawRRect(fRRect, fPaint); |
2462 } | 782 } |
2463 | 783 |
2464 bool SkDrawRRectCommand::render(SkCanvas* canvas) const { | 784 bool SkDrawRRectCommand::render(SkCanvas* canvas) const { |
2465 render_rrect(canvas, fRRect); | 785 render_rrect(canvas, fRRect); |
2466 return true; | 786 return true; |
2467 } | 787 } |
2468 | 788 |
2469 Json::Value SkDrawRRectCommand::toJSON() const { | |
2470 Json::Value result = INHERITED::toJSON(); | |
2471 result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = make_json_rrect(fRRect); | |
2472 result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(fPaint, SKDEBUGCANVA
S_SEND_BINARIES); | |
2473 return result; | |
2474 } | |
2475 | |
2476 SkDrawRRectCommand* SkDrawRRectCommand::fromJSON(Json::Value& command) { | |
2477 SkRRect coords; | |
2478 extract_json_rrect(command[SKDEBUGCANVAS_ATTRIBUTE_COORDS], &coords); | |
2479 SkPaint paint; | |
2480 extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], &paint); | |
2481 return new SkDrawRRectCommand(coords, paint); | |
2482 } | |
2483 | |
2484 SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer, | 789 SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer, |
2485 const SkRRect& inner, | 790 const SkRRect& inner, |
2486 const SkPaint& paint) | 791 const SkPaint& paint) |
2487 : INHERITED(kDrawDRRect_OpType) { | 792 : INHERITED(kDrawDRRect_OpType) { |
2488 fOuter = outer; | 793 fOuter = outer; |
2489 fInner = inner; | 794 fInner = inner; |
2490 fPaint = paint; | 795 fPaint = paint; |
2491 | 796 |
2492 fInfo.push(SkObjectParser::RRectToString(outer)); | 797 fInfo.push(SkObjectParser::RRectToString(outer)); |
2493 fInfo.push(SkObjectParser::RRectToString(inner)); | 798 fInfo.push(SkObjectParser::RRectToString(inner)); |
2494 fInfo.push(SkObjectParser::PaintToString(paint)); | 799 fInfo.push(SkObjectParser::PaintToString(paint)); |
2495 } | 800 } |
2496 | 801 |
2497 void SkDrawDRRectCommand::execute(SkCanvas* canvas) const { | 802 void SkDrawDRRectCommand::execute(SkCanvas* canvas) const { |
2498 canvas->drawDRRect(fOuter, fInner, fPaint); | 803 canvas->drawDRRect(fOuter, fInner, fPaint); |
2499 } | 804 } |
2500 | 805 |
2501 bool SkDrawDRRectCommand::render(SkCanvas* canvas) const { | 806 bool SkDrawDRRectCommand::render(SkCanvas* canvas) const { |
2502 render_drrect(canvas, fOuter, fInner); | 807 render_drrect(canvas, fOuter, fInner); |
2503 return true; | 808 return true; |
2504 } | 809 } |
2505 | 810 |
2506 Json::Value SkDrawDRRectCommand::toJSON() const { | |
2507 Json::Value result = INHERITED::toJSON(); | |
2508 result[SKDEBUGCANVAS_ATTRIBUTE_OUTER] = make_json_rrect(fOuter); | |
2509 result[SKDEBUGCANVAS_ATTRIBUTE_INNER] = make_json_rrect(fInner); | |
2510 result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(fPaint, SKDEBUGCANVA
S_SEND_BINARIES); | |
2511 return result; | |
2512 } | |
2513 | |
2514 SkDrawDRRectCommand* SkDrawDRRectCommand::fromJSON(Json::Value& command) { | |
2515 SkRRect outer; | |
2516 extract_json_rrect(command[SKDEBUGCANVAS_ATTRIBUTE_INNER], &outer); | |
2517 SkRRect inner; | |
2518 extract_json_rrect(command[SKDEBUGCANVAS_ATTRIBUTE_INNER], &inner); | |
2519 SkPaint paint; | |
2520 extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], &paint); | |
2521 return new SkDrawDRRectCommand(outer, inner, paint); | |
2522 } | |
2523 | |
2524 SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScal
ar x, SkScalar y, | 811 SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScal
ar x, SkScalar y, |
2525 const SkPaint& paint) | 812 const SkPaint& paint) |
2526 : INHERITED(kDrawText_OpType) { | 813 : INHERITED(kDrawText_OpType) { |
2527 fText = new char[byteLength]; | 814 fText = new char[byteLength]; |
2528 memcpy(fText, text, byteLength); | 815 memcpy(fText, text, byteLength); |
2529 fByteLength = byteLength; | 816 fByteLength = byteLength; |
2530 fX = x; | 817 fX = x; |
2531 fY = y; | 818 fY = y; |
2532 fPaint = paint; | 819 fPaint = paint; |
2533 | 820 |
2534 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncod
ing())); | 821 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncod
ing())); |
2535 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: ")); | 822 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: ")); |
2536 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: ")); | 823 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: ")); |
2537 fInfo.push(SkObjectParser::PaintToString(paint)); | 824 fInfo.push(SkObjectParser::PaintToString(paint)); |
2538 } | 825 } |
2539 | 826 |
2540 void SkDrawTextCommand::execute(SkCanvas* canvas) const { | 827 void SkDrawTextCommand::execute(SkCanvas* canvas) const { |
2541 canvas->drawText(fText, fByteLength, fX, fY, fPaint); | 828 canvas->drawText(fText, fByteLength, fX, fY, fPaint); |
2542 } | 829 } |
2543 | 830 |
2544 Json::Value SkDrawTextCommand::toJSON() const { | |
2545 Json::Value result = INHERITED::toJSON(); | |
2546 result[SKDEBUGCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) fText, | |
2547 ((const char*) fText) + f
ByteLength); | |
2548 Json::Value coords(Json::arrayValue); | |
2549 result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = make_json_point(fX, fY); | |
2550 result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(fPaint, SKDEBUGCANVA
S_SEND_BINARIES); | |
2551 return result; | |
2552 } | |
2553 | |
2554 SkDrawTextCommand* SkDrawTextCommand::fromJSON(Json::Value& command) { | |
2555 const char* text = command[SKDEBUGCANVAS_ATTRIBUTE_TEXT].asCString(); | |
2556 SkPaint paint; | |
2557 extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], &paint); | |
2558 Json::Value coords = command[SKDEBUGCANVAS_ATTRIBUTE_COORDS]; | |
2559 return new SkDrawTextCommand(text, strlen(text), coords[0].asFloat(), coords
[1].asFloat(), | |
2560 paint); | |
2561 } | |
2562 | |
2563 SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLe
ngth, | 831 SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLe
ngth, |
2564 const SkPath& path, const SkMat
rix* matrix, | 832 const SkPath& path, const SkMat
rix* matrix, |
2565 const SkPaint& paint) | 833 const SkPaint& paint) |
2566 : INHERITED(kDrawTextOnPath_OpType) { | 834 : INHERITED(kDrawTextOnPath_OpType) { |
2567 fText = new char[byteLength]; | 835 fText = new char[byteLength]; |
2568 memcpy(fText, text, byteLength); | 836 memcpy(fText, text, byteLength); |
2569 fByteLength = byteLength; | 837 fByteLength = byteLength; |
2570 fPath = path; | 838 fPath = path; |
2571 if (matrix) { | 839 if (matrix) { |
2572 fMatrix = *matrix; | 840 fMatrix = *matrix; |
2573 } else { | 841 } else { |
2574 fMatrix.setIdentity(); | 842 fMatrix.setIdentity(); |
2575 } | 843 } |
2576 fPaint = paint; | 844 fPaint = paint; |
2577 | 845 |
2578 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncod
ing())); | 846 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncod
ing())); |
2579 fInfo.push(SkObjectParser::PathToString(path)); | 847 fInfo.push(SkObjectParser::PathToString(path)); |
2580 if (matrix) { | 848 if (matrix) { |
2581 fInfo.push(SkObjectParser::MatrixToString(*matrix)); | 849 fInfo.push(SkObjectParser::MatrixToString(*matrix)); |
2582 } | 850 } |
2583 fInfo.push(SkObjectParser::PaintToString(paint)); | 851 fInfo.push(SkObjectParser::PaintToString(paint)); |
2584 } | 852 } |
2585 | 853 |
2586 void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) const { | 854 void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) const { |
2587 canvas->drawTextOnPath(fText, fByteLength, fPath, | 855 canvas->drawTextOnPath(fText, fByteLength, fPath, |
2588 fMatrix.isIdentity() ? nullptr : &fMatrix, | 856 fMatrix.isIdentity() ? nullptr : &fMatrix, |
2589 fPaint); | 857 fPaint); |
2590 } | 858 } |
2591 | 859 |
2592 Json::Value SkDrawTextOnPathCommand::toJSON() const { | |
2593 Json::Value result = INHERITED::toJSON(); | |
2594 result[SKDEBUGCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) fText, | |
2595 ((const char*) fText) + f
ByteLength); | |
2596 Json::Value coords(Json::arrayValue); | |
2597 result[SKDEBUGCANVAS_ATTRIBUTE_PATH] = make_json_path(fPath); | |
2598 if (!fMatrix.isIdentity()) { | |
2599 result[SKDEBUGCANVAS_ATTRIBUTE_MATRIX] = make_json_matrix(fMatrix); | |
2600 } | |
2601 result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(fPaint, SKDEBUGCANVA
S_SEND_BINARIES); | |
2602 return result; | |
2603 } | |
2604 | |
2605 SkDrawTextOnPathCommand* SkDrawTextOnPathCommand::fromJSON(Json::Value& command)
{ | |
2606 const char* text = command[SKDEBUGCANVAS_ATTRIBUTE_TEXT].asCString(); | |
2607 SkPaint paint; | |
2608 extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], &paint); | |
2609 SkPath path; | |
2610 extract_json_path(command[SKDEBUGCANVAS_ATTRIBUTE_PATH], &path); | |
2611 SkMatrix* matrixPtr; | |
2612 SkMatrix matrix; | |
2613 if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_MATRIX)) { | |
2614 extract_json_matrix(command[SKDEBUGCANVAS_ATTRIBUTE_MATRIX], &matrix); | |
2615 matrixPtr = &matrix; | |
2616 } | |
2617 else { | |
2618 matrixPtr = nullptr; | |
2619 } | |
2620 return new SkDrawTextOnPathCommand(text, strlen(text), path, matrixPtr, pain
t); | |
2621 } | |
2622 | |
2623 SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int ver
texCount, | 860 SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int ver
texCount, |
2624 const SkPoint vertices[], const SkP
oint texs[], | 861 const SkPoint vertices[], const SkP
oint texs[], |
2625 const SkColor colors[], SkXfermode*
xfermode, | 862 const SkColor colors[], SkXfermode*
xfermode, |
2626 const uint16_t indices[], int index
Count, | 863 const uint16_t indices[], int index
Count, |
2627 const SkPaint& paint) | 864 const SkPaint& paint) |
2628 : INHERITED(kDrawVertices_OpType) { | 865 : INHERITED(kDrawVertices_OpType) { |
2629 fVmode = vmode; | 866 fVmode = vmode; |
2630 | 867 |
2631 fVertexCount = vertexCount; | 868 fVertexCount = vertexCount; |
2632 | 869 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2683 | 920 |
2684 SkRestoreCommand::SkRestoreCommand() | 921 SkRestoreCommand::SkRestoreCommand() |
2685 : INHERITED(kRestore_OpType) { | 922 : INHERITED(kRestore_OpType) { |
2686 fInfo.push(SkObjectParser::CustomTextToString("No Parameters")); | 923 fInfo.push(SkObjectParser::CustomTextToString("No Parameters")); |
2687 } | 924 } |
2688 | 925 |
2689 void SkRestoreCommand::execute(SkCanvas* canvas) const { | 926 void SkRestoreCommand::execute(SkCanvas* canvas) const { |
2690 canvas->restore(); | 927 canvas->restore(); |
2691 } | 928 } |
2692 | 929 |
2693 SkRestoreCommand* SkRestoreCommand::fromJSON(Json::Value& command) { | |
2694 return new SkRestoreCommand(); | |
2695 } | |
2696 | |
2697 SkSaveCommand::SkSaveCommand() | 930 SkSaveCommand::SkSaveCommand() |
2698 : INHERITED(kSave_OpType) { | 931 : INHERITED(kSave_OpType) { |
2699 } | 932 } |
2700 | 933 |
2701 void SkSaveCommand::execute(SkCanvas* canvas) const { | 934 void SkSaveCommand::execute(SkCanvas* canvas) const { |
2702 canvas->save(); | 935 canvas->save(); |
2703 } | 936 } |
2704 | 937 |
2705 SkSaveCommand* SkSaveCommand::fromJSON(Json::Value& command) { | |
2706 return new SkSaveCommand(); | |
2707 } | |
2708 | |
2709 SkSaveLayerCommand::SkSaveLayerCommand(const SkCanvas::SaveLayerRec& rec) | 938 SkSaveLayerCommand::SkSaveLayerCommand(const SkCanvas::SaveLayerRec& rec) |
2710 : INHERITED(kSaveLayer_OpType) { | 939 : INHERITED(kSaveLayer_OpType) { |
2711 if (rec.fBounds) { | 940 if (rec.fBounds) { |
2712 fBounds = *rec.fBounds; | 941 fBounds = *rec.fBounds; |
2713 } else { | 942 } else { |
2714 fBounds.setEmpty(); | 943 fBounds.setEmpty(); |
2715 } | 944 } |
2716 | 945 |
2717 if (rec.fPaint) { | 946 if (rec.fPaint) { |
2718 fPaint = *rec.fPaint; | 947 fPaint = *rec.fPaint; |
2719 fPaintPtr = &fPaint; | 948 fPaintPtr = &fPaint; |
2720 } else { | 949 } else { |
2721 fPaintPtr = nullptr; | 950 fPaintPtr = nullptr; |
2722 } | 951 } |
2723 fSaveLayerFlags = rec.fSaveLayerFlags; | 952 fSaveLayerFlags = rec.fSaveLayerFlags; |
2724 | 953 |
2725 if (rec.fBackdrop) { | |
2726 fBackdrop = rec.fBackdrop; | |
2727 fBackdrop->ref(); | |
2728 } else { | |
2729 fBackdrop = nullptr; | |
2730 } | |
2731 | |
2732 if (rec.fBounds) { | 954 if (rec.fBounds) { |
2733 fInfo.push(SkObjectParser::RectToString(*rec.fBounds, "Bounds: ")); | 955 fInfo.push(SkObjectParser::RectToString(*rec.fBounds, "Bounds: ")); |
2734 } | 956 } |
2735 if (rec.fPaint) { | 957 if (rec.fPaint) { |
2736 fInfo.push(SkObjectParser::PaintToString(*rec.fPaint)); | 958 fInfo.push(SkObjectParser::PaintToString(*rec.fPaint)); |
2737 } | 959 } |
2738 fInfo.push(SkObjectParser::SaveLayerFlagsToString(fSaveLayerFlags)); | 960 fInfo.push(SkObjectParser::SaveLayerFlagsToString(fSaveLayerFlags)); |
2739 } | 961 } |
2740 | 962 |
2741 SkSaveLayerCommand::~SkSaveLayerCommand() { | |
2742 if (fBackdrop != nullptr) { | |
2743 fBackdrop->unref(); | |
2744 } | |
2745 } | |
2746 | |
2747 void SkSaveLayerCommand::execute(SkCanvas* canvas) const { | 963 void SkSaveLayerCommand::execute(SkCanvas* canvas) const { |
2748 canvas->saveLayer(SkCanvas::SaveLayerRec(fBounds.isEmpty() ? nullptr : &fBou
nds, | 964 canvas->saveLayer(SkCanvas::SaveLayerRec(fBounds.isEmpty() ? nullptr : &fBou
nds, |
2749 fPaintPtr, | 965 fPaintPtr, |
2750 fSaveLayerFlags)); | 966 fSaveLayerFlags)); |
2751 } | 967 } |
2752 | 968 |
2753 void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) const { | 969 void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) const { |
2754 canvas->save(); | 970 canvas->save(); |
2755 } | 971 } |
2756 | 972 |
2757 Json::Value SkSaveLayerCommand::toJSON() const { | |
2758 Json::Value result = INHERITED::toJSON(); | |
2759 if (!fBounds.isEmpty()) { | |
2760 result[SKDEBUGCANVAS_ATTRIBUTE_BOUNDS] = make_json_rect(fBounds); | |
2761 } | |
2762 if (fPaintPtr != nullptr) { | |
2763 result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(*fPaintPtr, | |
2764 SKDEBUGCANVAS_SE
ND_BINARIES); | |
2765 } | |
2766 if (fBackdrop != nullptr) { | |
2767 Json::Value jsonBackdrop; | |
2768 flatten(fBackdrop, &jsonBackdrop, SKDEBUGCANVAS_SEND_BINARIES); | |
2769 result[SKDEBUGCANVAS_ATTRIBUTE_BACKDROP] = jsonBackdrop; | |
2770 } | |
2771 if (fSaveLayerFlags != 0) { | |
2772 SkDebugf("unsupported: saveLayer flags\n"); | |
2773 SkASSERT(false); | |
2774 } | |
2775 return result; | |
2776 } | |
2777 | |
2778 SkSaveLayerCommand* SkSaveLayerCommand::fromJSON(Json::Value& command) { | |
2779 SkCanvas::SaveLayerRec rec; | |
2780 SkRect bounds; | |
2781 if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_BOUNDS)) { | |
2782 extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_BOUNDS], &bounds); | |
2783 rec.fBounds = &bounds; | |
2784 } | |
2785 SkPaint paint; | |
2786 if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_PAINT)) { | |
2787 extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], &paint); | |
2788 rec.fPaint = &paint; | |
2789 } | |
2790 if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_BACKDROP)) { | |
2791 Json::Value backdrop = command[SKDEBUGCANVAS_ATTRIBUTE_BACKDROP]; | |
2792 rec.fBackdrop = (SkImageFilter*) load_flattenable(backdrop); | |
2793 } | |
2794 SkSaveLayerCommand* result = new SkSaveLayerCommand(rec); | |
2795 if (rec.fBackdrop != nullptr) { | |
2796 rec.fBackdrop->unref(); | |
2797 } | |
2798 return result; | |
2799 } | |
2800 | |
2801 SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix) | 973 SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix) |
2802 : INHERITED(kSetMatrix_OpType) { | 974 : INHERITED(kSetMatrix_OpType) { |
2803 fUserMatrix.reset(); | 975 fUserMatrix.reset(); |
2804 fMatrix = matrix; | 976 fMatrix = matrix; |
2805 | 977 |
2806 fInfo.push(SkObjectParser::MatrixToString(matrix)); | 978 fInfo.push(SkObjectParser::MatrixToString(matrix)); |
2807 } | 979 } |
2808 | 980 |
2809 void SkSetMatrixCommand::setUserMatrix(const SkMatrix& userMatrix) { | 981 void SkSetMatrixCommand::setUserMatrix(const SkMatrix& userMatrix) { |
2810 fUserMatrix = userMatrix; | 982 fUserMatrix = userMatrix; |
2811 } | 983 } |
2812 | 984 |
2813 void SkSetMatrixCommand::execute(SkCanvas* canvas) const { | 985 void SkSetMatrixCommand::execute(SkCanvas* canvas) const { |
2814 SkMatrix temp = SkMatrix::Concat(fUserMatrix, fMatrix); | 986 SkMatrix temp = SkMatrix::Concat(fUserMatrix, fMatrix); |
2815 canvas->setMatrix(temp); | 987 canvas->setMatrix(temp); |
2816 } | 988 } |
2817 | 989 |
2818 Json::Value SkSetMatrixCommand::toJSON() const { | |
2819 Json::Value result = INHERITED::toJSON(); | |
2820 result[SKDEBUGCANVAS_ATTRIBUTE_MATRIX] = make_json_matrix(fMatrix); | |
2821 return result; | |
2822 } | |
2823 | |
2824 SkSetMatrixCommand* SkSetMatrixCommand::fromJSON(Json::Value& command) { | |
2825 SkMatrix matrix; | |
2826 extract_json_matrix(command[SKDEBUGCANVAS_ATTRIBUTE_MATRIX], &matrix); | |
2827 return new SkSetMatrixCommand(matrix); | |
2828 } | |
OLD | NEW |