Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: tools/debugger/SkDrawCommand.cpp

Issue 1681643002: Moved Canvas->JSON and JSON->Canvas functionality into SkDebugCanvas. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: switched from free to sk_free Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/debugger/SkDrawCommand.h ('k') | tools/debugger/SkObjectParser.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "SkObjectParser.h" 16 #include "SkObjectParser.h"
17 #include "SkPaintDefaults.h"
18 #include "SkPathEffect.h"
12 #include "SkPicture.h" 19 #include "SkPicture.h"
13 #include "SkTextBlob.h" 20 #include "SkTextBlob.h"
14 #include "SkTextBlobRunIterator.h" 21 #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 false
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);
15 143
16 // TODO(chudy): Refactor into non subclass model. 144 // TODO(chudy): Refactor into non subclass model.
17 145
18 SkDrawCommand::SkDrawCommand(OpType type) 146 SkDrawCommand::SkDrawCommand(OpType type)
19 : fOpType(type) 147 : fOpType(type)
20 , fVisible(true) { 148 , fVisible(true) {
21 } 149 }
22 150
23 SkDrawCommand::~SkDrawCommand() { 151 SkDrawCommand::~SkDrawCommand() {
24 fInfo.deleteAll(); 152 fInfo.deleteAll();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 break; 191 break;
64 } 192 }
65 SkDEBUGFAIL("DrawType UNUSED\n"); 193 SkDEBUGFAIL("DrawType UNUSED\n");
66 return nullptr; 194 return nullptr;
67 } 195 }
68 196
69 SkString SkDrawCommand::toString() const { 197 SkString SkDrawCommand::toString() const {
70 return SkString(GetCommandString(fOpType)); 198 return SkString(GetCommandString(fOpType));
71 } 199 }
72 200
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
73 SkClearCommand::SkClearCommand(SkColor color) : INHERITED(kDrawClear_OpType) { 250 SkClearCommand::SkClearCommand(SkColor color) : INHERITED(kDrawClear_OpType) {
74 fColor = color; 251 fColor = color;
75 fInfo.push(SkObjectParser::CustomTextToString("No Parameters")); 252 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
76 } 253 }
77 254
78 void SkClearCommand::execute(SkCanvas* canvas) const { 255 void SkClearCommand::execute(SkCanvas* canvas) const {
79 canvas->clear(fColor); 256 canvas->clear(fColor);
80 } 257 }
81 258
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
82 namespace { 276 namespace {
83 277
84 void xlate_and_scale_to_bounds(SkCanvas* canvas, const SkRect& bounds) { 278 void xlate_and_scale_to_bounds(SkCanvas* canvas, const SkRect& bounds) {
85 const SkISize& size = canvas->getDeviceSize(); 279 const SkISize& size = canvas->getDeviceSize();
86 280
87 static const SkScalar kInsetFrac = 0.9f; // Leave a border around object 281 static const SkScalar kInsetFrac = 0.9f; // Leave a border around object
88 282
89 canvas->translate(size.fWidth/2.0f, size.fHeight/2.0f); 283 canvas->translate(size.fWidth/2.0f, size.fHeight/2.0f);
90 if (bounds.width() > bounds.height()) { 284 if (bounds.width() > bounds.height()) {
91 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.width()), 285 canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.width()),
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 SkPaint p; 387 SkPaint p;
194 p.setColor(SK_ColorBLACK); 388 p.setColor(SK_ColorBLACK);
195 p.setStyle(SkPaint::kStroke_Style); 389 p.setStyle(SkPaint::kStroke_Style);
196 390
197 canvas->drawDRRect(outer, inner, p); 391 canvas->drawDRRect(outer, inner, p);
198 canvas->restore(); 392 canvas->restore();
199 } 393 }
200 394
201 }; 395 };
202 396
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 sk_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 sk_free(converted);
630 sk_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 sk_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 sk_free(decoder);
765 if (result != SkImageDecoder::kFailure) {
766 sk_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 sk_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 sk_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 sk_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 sk_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 sk_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
203 1377
204 SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool d oAA) 1378 SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool d oAA)
205 : INHERITED(kClipPath_OpType) { 1379 : INHERITED(kClipPath_OpType) {
206 fPath = path; 1380 fPath = path;
207 fOp = op; 1381 fOp = op;
208 fDoAA = doAA; 1382 fDoAA = doAA;
209 1383
210 fInfo.push(SkObjectParser::PathToString(path)); 1384 fInfo.push(SkObjectParser::PathToString(path));
211 fInfo.push(SkObjectParser::RegionOpToString(op)); 1385 fInfo.push(SkObjectParser::RegionOpToString(op));
212 fInfo.push(SkObjectParser::BoolToString(doAA)); 1386 fInfo.push(SkObjectParser::BoolToString(doAA));
213 } 1387 }
214 1388
215 void SkClipPathCommand::execute(SkCanvas* canvas) const { 1389 void SkClipPathCommand::execute(SkCanvas* canvas) const {
216 canvas->clipPath(fPath, fOp, fDoAA); 1390 canvas->clipPath(fPath, fOp, fDoAA);
217 } 1391 }
218 1392
219 bool SkClipPathCommand::render(SkCanvas* canvas) const { 1393 bool SkClipPathCommand::render(SkCanvas* canvas) const {
220 render_path(canvas, fPath); 1394 render_path(canvas, fPath);
221 return true; 1395 return true;
222 } 1396 }
223 1397
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
224 SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkRegion::Op op ) 1413 SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkRegion::Op op )
225 : INHERITED(kClipRegion_OpType) { 1414 : INHERITED(kClipRegion_OpType) {
226 fRegion = region; 1415 fRegion = region;
227 fOp = op; 1416 fOp = op;
228 1417
229 fInfo.push(SkObjectParser::RegionToString(region)); 1418 fInfo.push(SkObjectParser::RegionToString(region));
230 fInfo.push(SkObjectParser::RegionOpToString(op)); 1419 fInfo.push(SkObjectParser::RegionOpToString(op));
231 } 1420 }
232 1421
233 void SkClipRegionCommand::execute(SkCanvas* canvas) const { 1422 void SkClipRegionCommand::execute(SkCanvas* canvas) const {
234 canvas->clipRegion(fRegion, fOp); 1423 canvas->clipRegion(fRegion, fOp);
235 } 1424 }
236 1425
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
237 SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool d oAA) 1438 SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool d oAA)
238 : INHERITED(kClipRect_OpType) { 1439 : INHERITED(kClipRect_OpType) {
239 fRect = rect; 1440 fRect = rect;
240 fOp = op; 1441 fOp = op;
241 fDoAA = doAA; 1442 fDoAA = doAA;
242 1443
243 fInfo.push(SkObjectParser::RectToString(rect)); 1444 fInfo.push(SkObjectParser::RectToString(rect));
244 fInfo.push(SkObjectParser::RegionOpToString(op)); 1445 fInfo.push(SkObjectParser::RegionOpToString(op));
245 fInfo.push(SkObjectParser::BoolToString(doAA)); 1446 fInfo.push(SkObjectParser::BoolToString(doAA));
246 } 1447 }
247 1448
248 void SkClipRectCommand::execute(SkCanvas* canvas) const { 1449 void SkClipRectCommand::execute(SkCanvas* canvas) const {
249 canvas->clipRect(fRect, fOp, fDoAA); 1450 canvas->clipRect(fRect, fOp, fDoAA);
250 } 1451 }
251 1452
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
252 SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bo ol doAA) 1468 SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bo ol doAA)
253 : INHERITED(kClipRRect_OpType) { 1469 : INHERITED(kClipRRect_OpType) {
254 fRRect = rrect; 1470 fRRect = rrect;
255 fOp = op; 1471 fOp = op;
256 fDoAA = doAA; 1472 fDoAA = doAA;
257 1473
258 fInfo.push(SkObjectParser::RRectToString(rrect)); 1474 fInfo.push(SkObjectParser::RRectToString(rrect));
259 fInfo.push(SkObjectParser::RegionOpToString(op)); 1475 fInfo.push(SkObjectParser::RegionOpToString(op));
260 fInfo.push(SkObjectParser::BoolToString(doAA)); 1476 fInfo.push(SkObjectParser::BoolToString(doAA));
261 } 1477 }
262 1478
263 void SkClipRRectCommand::execute(SkCanvas* canvas) const { 1479 void SkClipRRectCommand::execute(SkCanvas* canvas) const {
264 canvas->clipRRect(fRRect, fOp, fDoAA); 1480 canvas->clipRRect(fRRect, fOp, fDoAA);
265 } 1481 }
266 1482
267 bool SkClipRRectCommand::render(SkCanvas* canvas) const { 1483 bool SkClipRRectCommand::render(SkCanvas* canvas) const {
268 render_rrect(canvas, fRRect); 1484 render_rrect(canvas, fRRect);
269 return true; 1485 return true;
270 } 1486 }
271 1487
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
272 SkConcatCommand::SkConcatCommand(const SkMatrix& matrix) 1504 SkConcatCommand::SkConcatCommand(const SkMatrix& matrix)
273 : INHERITED(kConcat_OpType) { 1505 : INHERITED(kConcat_OpType) {
274 fMatrix = matrix; 1506 fMatrix = matrix;
275 1507
276 fInfo.push(SkObjectParser::MatrixToString(matrix)); 1508 fInfo.push(SkObjectParser::MatrixToString(matrix));
277 } 1509 }
278 1510
279 void SkConcatCommand::execute(SkCanvas* canvas) const { 1511 void SkConcatCommand::execute(SkCanvas* canvas) const {
280 canvas->concat(fMatrix); 1512 canvas->concat(fMatrix);
281 } 1513 }
282 1514
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
283 SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top, 1527 SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top,
284 const SkPaint* paint) 1528 const SkPaint* paint)
285 : INHERITED(kDrawBitmap_OpType) { 1529 : INHERITED(kDrawBitmap_OpType) {
286 fBitmap = bitmap; 1530 fBitmap = bitmap;
287 fLeft = left; 1531 fLeft = left;
288 fTop = top; 1532 fTop = top;
289 if (paint) { 1533 if (paint) {
290 fPaint = *paint; 1534 fPaint = *paint;
291 fPaintPtr = &fPaint; 1535 fPaintPtr = &fPaint;
292 } else { 1536 } else {
(...skipping 10 matching lines...) Expand all
303 1547
304 void SkDrawBitmapCommand::execute(SkCanvas* canvas) const { 1548 void SkDrawBitmapCommand::execute(SkCanvas* canvas) const {
305 canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr); 1549 canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr);
306 } 1550 }
307 1551
308 bool SkDrawBitmapCommand::render(SkCanvas* canvas) const { 1552 bool SkDrawBitmapCommand::render(SkCanvas* canvas) const {
309 render_bitmap(canvas, fBitmap); 1553 render_bitmap(canvas, fBitmap);
310 return true; 1554 return true;
311 } 1555 }
312 1556
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
313 SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const S kIRect& center, 1592 SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const S kIRect& center,
314 const SkRect& dst, const SkPain t* paint) 1593 const SkRect& dst, const SkPain t* paint)
315 : INHERITED(kDrawBitmapNine_OpType) { 1594 : INHERITED(kDrawBitmapNine_OpType) {
316 fBitmap = bitmap; 1595 fBitmap = bitmap;
317 fCenter = center; 1596 fCenter = center;
318 fDst = dst; 1597 fDst = dst;
319 if (paint) { 1598 if (paint) {
320 fPaint = *paint; 1599 fPaint = *paint;
321 fPaintPtr = &fPaint; 1600 fPaintPtr = &fPaint;
322 } else { 1601 } else {
(...skipping 11 matching lines...) Expand all
334 void SkDrawBitmapNineCommand::execute(SkCanvas* canvas) const { 1613 void SkDrawBitmapNineCommand::execute(SkCanvas* canvas) const {
335 canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr); 1614 canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr);
336 } 1615 }
337 1616
338 bool SkDrawBitmapNineCommand::render(SkCanvas* canvas) const { 1617 bool SkDrawBitmapNineCommand::render(SkCanvas* canvas) const {
339 SkRect tmp = SkRect::Make(fCenter); 1618 SkRect tmp = SkRect::Make(fCenter);
340 render_bitmap(canvas, fBitmap, &tmp); 1619 render_bitmap(canvas, fBitmap, &tmp);
341 return true; 1620 return true;
342 } 1621 }
343 1622
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], &center);
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
344 SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const S kRect* src, 1661 SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const S kRect* src,
345 const SkRect& dst, const SkPain t* paint, 1662 const SkRect& dst, const SkPain t* paint,
346 SkCanvas::SrcRectConstraint con straint) 1663 SkCanvas::SrcRectConstraint con straint)
347 : INHERITED(kDrawBitmapRect_OpType) { 1664 : INHERITED(kDrawBitmapRect_OpType) {
348 fBitmap = bitmap; 1665 fBitmap = bitmap;
349 if (src) { 1666 if (src) {
350 fSrc = *src; 1667 fSrc = *src;
351 } else { 1668 } else {
352 fSrc.setEmpty(); 1669 fSrc.setEmpty();
353 } 1670 }
(...skipping 20 matching lines...) Expand all
374 1691
375 void SkDrawBitmapRectCommand::execute(SkCanvas* canvas) const { 1692 void SkDrawBitmapRectCommand::execute(SkCanvas* canvas) const {
376 canvas->legacy_drawBitmapRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fCo nstraint); 1693 canvas->legacy_drawBitmapRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fCo nstraint);
377 } 1694 }
378 1695
379 bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const { 1696 bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const {
380 render_bitmap(canvas, fBitmap, this->srcRect()); 1697 render_bitmap(canvas, fBitmap, this->srcRect());
381 return true; 1698 return true;
382 } 1699 }
383 1700
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
384 SkDrawImageCommand::SkDrawImageCommand(const SkImage* image, SkScalar left, SkSc alar top, 1760 SkDrawImageCommand::SkDrawImageCommand(const SkImage* image, SkScalar left, SkSc alar top,
385 const SkPaint* paint) 1761 const SkPaint* paint)
386 : INHERITED(kDrawImage_OpType) 1762 : INHERITED(kDrawImage_OpType)
387 , fImage(SkRef(image)) 1763 , fImage(SkRef(image))
388 , fLeft(left) 1764 , fLeft(left)
389 , fTop(top) { 1765 , fTop(top) {
390 1766
391 fInfo.push(SkObjectParser::ImageToString(image)); 1767 fInfo.push(SkObjectParser::ImageToString(image));
392 fInfo.push(SkObjectParser::ScalarToString(left, "Left: ")); 1768 fInfo.push(SkObjectParser::ScalarToString(left, "Left: "));
393 fInfo.push(SkObjectParser::ScalarToString(top, "Top: ")); 1769 fInfo.push(SkObjectParser::ScalarToString(top, "Top: "));
(...skipping 12 matching lines...) Expand all
406 SkAutoCanvasRestore acr(canvas, true); 1782 SkAutoCanvasRestore acr(canvas, true);
407 canvas->clear(0xFFFFFFFF); 1783 canvas->clear(0xFFFFFFFF);
408 1784
409 xlate_and_scale_to_bounds(canvas, SkRect::MakeXYWH(fLeft, fTop, 1785 xlate_and_scale_to_bounds(canvas, SkRect::MakeXYWH(fLeft, fTop,
410 SkIntToScalar(fImage->wid th()), 1786 SkIntToScalar(fImage->wid th()),
411 SkIntToScalar(fImage->hei ght()))); 1787 SkIntToScalar(fImage->hei ght())));
412 this->execute(canvas); 1788 this->execute(canvas);
413 return true; 1789 return true;
414 } 1790 }
415 1791
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
416 SkDrawImageRectCommand::SkDrawImageRectCommand(const SkImage* image, const SkRec t* src, 1827 SkDrawImageRectCommand::SkDrawImageRectCommand(const SkImage* image, const SkRec t* src,
417 const SkRect& dst, const SkPaint* paint, 1828 const SkRect& dst, const SkPaint* paint,
418 SkCanvas::SrcRectConstraint const raint) 1829 SkCanvas::SrcRectConstraint const raint)
419 : INHERITED(kDrawImageRect_OpType) 1830 : INHERITED(kDrawImageRect_OpType)
420 , fImage(SkRef(image)) 1831 , fImage(SkRef(image))
421 , fDst(dst) 1832 , fDst(dst)
422 , fConstraint(constraint) { 1833 , fConstraint(constraint) {
423 1834
424 if (src) { 1835 if (src) {
425 fSrc.set(*src); 1836 fSrc.set(*src);
(...skipping 21 matching lines...) Expand all
447 bool SkDrawImageRectCommand::render(SkCanvas* canvas) const { 1858 bool SkDrawImageRectCommand::render(SkCanvas* canvas) const {
448 SkAutoCanvasRestore acr(canvas, true); 1859 SkAutoCanvasRestore acr(canvas, true);
449 canvas->clear(0xFFFFFFFF); 1860 canvas->clear(0xFFFFFFFF);
450 1861
451 xlate_and_scale_to_bounds(canvas, fDst); 1862 xlate_and_scale_to_bounds(canvas, fDst);
452 1863
453 this->execute(canvas); 1864 this->execute(canvas);
454 return true; 1865 return true;
455 } 1866 }
456 1867
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
457 SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint) 1927 SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint)
458 : INHERITED(kDrawOval_OpType) { 1928 : INHERITED(kDrawOval_OpType) {
459 fOval = oval; 1929 fOval = oval;
460 fPaint = paint; 1930 fPaint = paint;
461 1931
462 fInfo.push(SkObjectParser::RectToString(oval)); 1932 fInfo.push(SkObjectParser::RectToString(oval));
463 fInfo.push(SkObjectParser::PaintToString(paint)); 1933 fInfo.push(SkObjectParser::PaintToString(paint));
464 } 1934 }
465 1935
466 void SkDrawOvalCommand::execute(SkCanvas* canvas) const { 1936 void SkDrawOvalCommand::execute(SkCanvas* canvas) const {
467 canvas->drawOval(fOval, fPaint); 1937 canvas->drawOval(fOval, fPaint);
468 } 1938 }
469 1939
470 bool SkDrawOvalCommand::render(SkCanvas* canvas) const { 1940 bool SkDrawOvalCommand::render(SkCanvas* canvas) const {
471 canvas->clear(0xFFFFFFFF); 1941 canvas->clear(0xFFFFFFFF);
472 canvas->save(); 1942 canvas->save();
473 1943
474 xlate_and_scale_to_bounds(canvas, fOval); 1944 xlate_and_scale_to_bounds(canvas, fOval);
475 1945
476 SkPaint p; 1946 SkPaint p;
477 p.setColor(SK_ColorBLACK); 1947 p.setColor(SK_ColorBLACK);
478 p.setStyle(SkPaint::kStroke_Style); 1948 p.setStyle(SkPaint::kStroke_Style);
479 1949
480 canvas->drawOval(fOval, p); 1950 canvas->drawOval(fOval, p);
481 canvas->restore(); 1951 canvas->restore();
482 1952
483 return true; 1953 return true;
484 } 1954 }
485 1955
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
486 SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint) 1971 SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint)
487 : INHERITED(kDrawPaint_OpType) { 1972 : INHERITED(kDrawPaint_OpType) {
488 fPaint = paint; 1973 fPaint = paint;
489 1974
490 fInfo.push(SkObjectParser::PaintToString(paint)); 1975 fInfo.push(SkObjectParser::PaintToString(paint));
491 } 1976 }
492 1977
493 void SkDrawPaintCommand::execute(SkCanvas* canvas) const { 1978 void SkDrawPaintCommand::execute(SkCanvas* canvas) const {
494 canvas->drawPaint(fPaint); 1979 canvas->drawPaint(fPaint);
495 } 1980 }
496 1981
497 bool SkDrawPaintCommand::render(SkCanvas* canvas) const { 1982 bool SkDrawPaintCommand::render(SkCanvas* canvas) const {
498 canvas->clear(0xFFFFFFFF); 1983 canvas->clear(0xFFFFFFFF);
499 canvas->drawPaint(fPaint); 1984 canvas->drawPaint(fPaint);
500 return true; 1985 return true;
501 } 1986 }
502 1987
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
503 SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint) 2000 SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint)
504 : INHERITED(kDrawPath_OpType) { 2001 : INHERITED(kDrawPath_OpType) {
505 fPath = path; 2002 fPath = path;
506 fPaint = paint; 2003 fPaint = paint;
507 2004
508 fInfo.push(SkObjectParser::PathToString(path)); 2005 fInfo.push(SkObjectParser::PathToString(path));
509 fInfo.push(SkObjectParser::PaintToString(paint)); 2006 fInfo.push(SkObjectParser::PaintToString(paint));
510 } 2007 }
511 2008
512 void SkDrawPathCommand::execute(SkCanvas* canvas) const { 2009 void SkDrawPathCommand::execute(SkCanvas* canvas) const {
513 canvas->drawPath(fPath, fPaint); 2010 canvas->drawPath(fPath, fPaint);
514 } 2011 }
515 2012
516 bool SkDrawPathCommand::render(SkCanvas* canvas) const { 2013 bool SkDrawPathCommand::render(SkCanvas* canvas) const {
517 render_path(canvas, fPath); 2014 render_path(canvas, fPath);
518 return true; 2015 return true;
519 } 2016 }
520 2017
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
521 SkBeginDrawPictureCommand::SkBeginDrawPictureCommand(const SkPicture* picture, 2033 SkBeginDrawPictureCommand::SkBeginDrawPictureCommand(const SkPicture* picture,
522 const SkMatrix* matrix, 2034 const SkMatrix* matrix,
523 const SkPaint* paint) 2035 const SkPaint* paint)
524 : INHERITED(kBeginDrawPicture_OpType) 2036 : INHERITED(kBeginDrawPicture_OpType)
525 , fPicture(SkRef(picture)) { 2037 , fPicture(SkRef(picture)) {
526 2038
527 SkString* str = new SkString; 2039 SkString* str = new SkString;
528 str->appendf("SkPicture: L: %f T: %f R: %f B: %f", 2040 str->appendf("SkPicture: L: %f T: %f R: %f B: %f",
529 picture->cullRect().fLeft, picture->cullRect().fTop, 2041 picture->cullRect().fLeft, picture->cullRect().fTop,
530 picture->cullRect().fRight, picture->cullRect().fBottom); 2042 picture->cullRect().fRight, picture->cullRect().fBottom);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 SkPaint p; 2129 SkPaint p;
618 p.setColor(SK_ColorBLACK); 2130 p.setColor(SK_ColorBLACK);
619 p.setStyle(SkPaint::kStroke_Style); 2131 p.setStyle(SkPaint::kStroke_Style);
620 2132
621 canvas->drawPoints(fMode, fCount, fPts, p); 2133 canvas->drawPoints(fMode, fCount, fPts, p);
622 canvas->restore(); 2134 canvas->restore();
623 2135
624 return true; 2136 return true;
625 } 2137 }
626 2138
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 sk_free(points);
2177 return result;
2178 }
2179
627 SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength, 2180 SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength,
628 const SkPoint pos[], const SkPaint& p aint) 2181 const SkPoint pos[], const SkPaint& p aint)
629 : INHERITED(kDrawPosText_OpType) { 2182 : INHERITED(kDrawPosText_OpType) {
630 size_t numPts = paint.countText(text, byteLength); 2183 size_t numPts = paint.countText(text, byteLength);
631 2184
632 fText = new char[byteLength]; 2185 fText = new char[byteLength];
633 memcpy(fText, text, byteLength); 2186 memcpy(fText, text, byteLength);
634 fByteLength = byteLength; 2187 fByteLength = byteLength;
635 2188
636 fPos = new SkPoint[numPts]; 2189 fPos = new SkPoint[numPts];
637 memcpy(fPos, pos, numPts * sizeof(SkPoint)); 2190 memcpy(fPos, pos, numPts * sizeof(SkPoint));
638 2191
639 fPaint = paint; 2192 fPaint = paint;
640 2193
641 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncod ing())); 2194 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncod ing()));
642 // TODO(chudy): Test that this works. 2195 // TODO(chudy): Test that this works.
643 fInfo.push(SkObjectParser::PointsToString(pos, 1)); 2196 fInfo.push(SkObjectParser::PointsToString(pos, 1));
644 fInfo.push(SkObjectParser::PaintToString(paint)); 2197 fInfo.push(SkObjectParser::PaintToString(paint));
645 } 2198 }
646 2199
647 void SkDrawPosTextCommand::execute(SkCanvas* canvas) const { 2200 void SkDrawPosTextCommand::execute(SkCanvas* canvas) const {
648 canvas->drawPosText(fText, fByteLength, fPos, fPaint); 2201 canvas->drawPosText(fText, fByteLength, fPos, fPaint);
649 } 2202 }
650 2203
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 }
651 2229
652 SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength , 2230 SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength ,
653 const SkScalar xpos[], SkScalar con stY, 2231 const SkScalar xpos[], SkScalar con stY,
654 const SkPaint& paint) 2232 const SkPaint& paint)
655 : INHERITED(kDrawPosTextH_OpType) { 2233 : INHERITED(kDrawPosTextH_OpType) {
656 size_t numPts = paint.countText(text, byteLength); 2234 size_t numPts = paint.countText(text, byteLength);
657 2235
658 fText = new char[byteLength]; 2236 fText = new char[byteLength];
659 memcpy(fText, text, byteLength); 2237 memcpy(fText, text, byteLength);
660 fByteLength = byteLength; 2238 fByteLength = byteLength;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 SkRect bounds = fBlob->bounds().makeOffset(fXPos, fYPos); 2309 SkRect bounds = fBlob->bounds().makeOffset(fXPos, fYPos);
732 xlate_and_scale_to_bounds(canvas, bounds); 2310 xlate_and_scale_to_bounds(canvas, bounds);
733 2311
734 canvas->drawTextBlob(fBlob.get(), fXPos, fYPos, fPaint); 2312 canvas->drawTextBlob(fBlob.get(), fXPos, fYPos, fPaint);
735 2313
736 canvas->restore(); 2314 canvas->restore();
737 2315
738 return true; 2316 return true;
739 } 2317 }
740 2318
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
741 SkDrawPatchCommand::SkDrawPatchCommand(const SkPoint cubics[12], const SkColor c olors[4], 2406 SkDrawPatchCommand::SkDrawPatchCommand(const SkPoint cubics[12], const SkColor c olors[4],
742 const SkPoint texCoords[4], SkXfermode* x fermode, 2407 const SkPoint texCoords[4], SkXfermode* x fermode,
743 const SkPaint& paint) 2408 const SkPaint& paint)
744 : INHERITED(kDrawPatch_OpType) { 2409 : INHERITED(kDrawPatch_OpType) {
745 memcpy(fCubics, cubics, sizeof(fCubics)); 2410 memcpy(fCubics, cubics, sizeof(fCubics));
746 memcpy(fColors, colors, sizeof(fColors)); 2411 memcpy(fColors, colors, sizeof(fColors));
747 memcpy(fTexCoords, texCoords, sizeof(fTexCoords)); 2412 memcpy(fTexCoords, texCoords, sizeof(fTexCoords));
748 fXfermode.reset(xfermode); 2413 fXfermode.reset(xfermode);
749 fPaint = paint; 2414 fPaint = paint;
750 2415
(...skipping 10 matching lines...) Expand all
761 fPaint = paint; 2426 fPaint = paint;
762 2427
763 fInfo.push(SkObjectParser::RectToString(rect)); 2428 fInfo.push(SkObjectParser::RectToString(rect));
764 fInfo.push(SkObjectParser::PaintToString(paint)); 2429 fInfo.push(SkObjectParser::PaintToString(paint));
765 } 2430 }
766 2431
767 void SkDrawRectCommand::execute(SkCanvas* canvas) const { 2432 void SkDrawRectCommand::execute(SkCanvas* canvas) const {
768 canvas->drawRect(fRect, fPaint); 2433 canvas->drawRect(fRect, fPaint);
769 } 2434 }
770 2435
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
771 SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& pain t) 2451 SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& pain t)
772 : INHERITED(kDrawRRect_OpType) { 2452 : INHERITED(kDrawRRect_OpType) {
773 fRRect = rrect; 2453 fRRect = rrect;
774 fPaint = paint; 2454 fPaint = paint;
775 2455
776 fInfo.push(SkObjectParser::RRectToString(rrect)); 2456 fInfo.push(SkObjectParser::RRectToString(rrect));
777 fInfo.push(SkObjectParser::PaintToString(paint)); 2457 fInfo.push(SkObjectParser::PaintToString(paint));
778 } 2458 }
779 2459
780 void SkDrawRRectCommand::execute(SkCanvas* canvas) const { 2460 void SkDrawRRectCommand::execute(SkCanvas* canvas) const {
781 canvas->drawRRect(fRRect, fPaint); 2461 canvas->drawRRect(fRRect, fPaint);
782 } 2462 }
783 2463
784 bool SkDrawRRectCommand::render(SkCanvas* canvas) const { 2464 bool SkDrawRRectCommand::render(SkCanvas* canvas) const {
785 render_rrect(canvas, fRRect); 2465 render_rrect(canvas, fRRect);
786 return true; 2466 return true;
787 } 2467 }
788 2468
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
789 SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer, 2484 SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer,
790 const SkRRect& inner, 2485 const SkRRect& inner,
791 const SkPaint& paint) 2486 const SkPaint& paint)
792 : INHERITED(kDrawDRRect_OpType) { 2487 : INHERITED(kDrawDRRect_OpType) {
793 fOuter = outer; 2488 fOuter = outer;
794 fInner = inner; 2489 fInner = inner;
795 fPaint = paint; 2490 fPaint = paint;
796 2491
797 fInfo.push(SkObjectParser::RRectToString(outer)); 2492 fInfo.push(SkObjectParser::RRectToString(outer));
798 fInfo.push(SkObjectParser::RRectToString(inner)); 2493 fInfo.push(SkObjectParser::RRectToString(inner));
799 fInfo.push(SkObjectParser::PaintToString(paint)); 2494 fInfo.push(SkObjectParser::PaintToString(paint));
800 } 2495 }
801 2496
802 void SkDrawDRRectCommand::execute(SkCanvas* canvas) const { 2497 void SkDrawDRRectCommand::execute(SkCanvas* canvas) const {
803 canvas->drawDRRect(fOuter, fInner, fPaint); 2498 canvas->drawDRRect(fOuter, fInner, fPaint);
804 } 2499 }
805 2500
806 bool SkDrawDRRectCommand::render(SkCanvas* canvas) const { 2501 bool SkDrawDRRectCommand::render(SkCanvas* canvas) const {
807 render_drrect(canvas, fOuter, fInner); 2502 render_drrect(canvas, fOuter, fInner);
808 return true; 2503 return true;
809 } 2504 }
810 2505
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
811 SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScal ar x, SkScalar y, 2524 SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScal ar x, SkScalar y,
812 const SkPaint& paint) 2525 const SkPaint& paint)
813 : INHERITED(kDrawText_OpType) { 2526 : INHERITED(kDrawText_OpType) {
814 fText = new char[byteLength]; 2527 fText = new char[byteLength];
815 memcpy(fText, text, byteLength); 2528 memcpy(fText, text, byteLength);
816 fByteLength = byteLength; 2529 fByteLength = byteLength;
817 fX = x; 2530 fX = x;
818 fY = y; 2531 fY = y;
819 fPaint = paint; 2532 fPaint = paint;
820 2533
821 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncod ing())); 2534 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncod ing()));
822 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: ")); 2535 fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
823 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: ")); 2536 fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
824 fInfo.push(SkObjectParser::PaintToString(paint)); 2537 fInfo.push(SkObjectParser::PaintToString(paint));
825 } 2538 }
826 2539
827 void SkDrawTextCommand::execute(SkCanvas* canvas) const { 2540 void SkDrawTextCommand::execute(SkCanvas* canvas) const {
828 canvas->drawText(fText, fByteLength, fX, fY, fPaint); 2541 canvas->drawText(fText, fByteLength, fX, fY, fPaint);
829 } 2542 }
830 2543
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
831 SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLe ngth, 2563 SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLe ngth,
832 const SkPath& path, const SkMat rix* matrix, 2564 const SkPath& path, const SkMat rix* matrix,
833 const SkPaint& paint) 2565 const SkPaint& paint)
834 : INHERITED(kDrawTextOnPath_OpType) { 2566 : INHERITED(kDrawTextOnPath_OpType) {
835 fText = new char[byteLength]; 2567 fText = new char[byteLength];
836 memcpy(fText, text, byteLength); 2568 memcpy(fText, text, byteLength);
837 fByteLength = byteLength; 2569 fByteLength = byteLength;
838 fPath = path; 2570 fPath = path;
839 if (matrix) { 2571 if (matrix) {
840 fMatrix = *matrix; 2572 fMatrix = *matrix;
841 } else { 2573 } else {
842 fMatrix.setIdentity(); 2574 fMatrix.setIdentity();
843 } 2575 }
844 fPaint = paint; 2576 fPaint = paint;
845 2577
846 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncod ing())); 2578 fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncod ing()));
847 fInfo.push(SkObjectParser::PathToString(path)); 2579 fInfo.push(SkObjectParser::PathToString(path));
848 if (matrix) { 2580 if (matrix) {
849 fInfo.push(SkObjectParser::MatrixToString(*matrix)); 2581 fInfo.push(SkObjectParser::MatrixToString(*matrix));
850 } 2582 }
851 fInfo.push(SkObjectParser::PaintToString(paint)); 2583 fInfo.push(SkObjectParser::PaintToString(paint));
852 } 2584 }
853 2585
854 void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) const { 2586 void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) const {
855 canvas->drawTextOnPath(fText, fByteLength, fPath, 2587 canvas->drawTextOnPath(fText, fByteLength, fPath,
856 fMatrix.isIdentity() ? nullptr : &fMatrix, 2588 fMatrix.isIdentity() ? nullptr : &fMatrix,
857 fPaint); 2589 fPaint);
858 } 2590 }
859 2591
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
860 SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int ver texCount, 2623 SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int ver texCount,
861 const SkPoint vertices[], const SkP oint texs[], 2624 const SkPoint vertices[], const SkP oint texs[],
862 const SkColor colors[], SkXfermode* xfermode, 2625 const SkColor colors[], SkXfermode* xfermode,
863 const uint16_t indices[], int index Count, 2626 const uint16_t indices[], int index Count,
864 const SkPaint& paint) 2627 const SkPaint& paint)
865 : INHERITED(kDrawVertices_OpType) { 2628 : INHERITED(kDrawVertices_OpType) {
866 fVmode = vmode; 2629 fVmode = vmode;
867 2630
868 fVertexCount = vertexCount; 2631 fVertexCount = vertexCount;
869 2632
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 2683
921 SkRestoreCommand::SkRestoreCommand() 2684 SkRestoreCommand::SkRestoreCommand()
922 : INHERITED(kRestore_OpType) { 2685 : INHERITED(kRestore_OpType) {
923 fInfo.push(SkObjectParser::CustomTextToString("No Parameters")); 2686 fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
924 } 2687 }
925 2688
926 void SkRestoreCommand::execute(SkCanvas* canvas) const { 2689 void SkRestoreCommand::execute(SkCanvas* canvas) const {
927 canvas->restore(); 2690 canvas->restore();
928 } 2691 }
929 2692
2693 SkRestoreCommand* SkRestoreCommand::fromJSON(Json::Value& command) {
2694 return new SkRestoreCommand();
2695 }
2696
930 SkSaveCommand::SkSaveCommand() 2697 SkSaveCommand::SkSaveCommand()
931 : INHERITED(kSave_OpType) { 2698 : INHERITED(kSave_OpType) {
932 } 2699 }
933 2700
934 void SkSaveCommand::execute(SkCanvas* canvas) const { 2701 void SkSaveCommand::execute(SkCanvas* canvas) const {
935 canvas->save(); 2702 canvas->save();
936 } 2703 }
937 2704
2705 SkSaveCommand* SkSaveCommand::fromJSON(Json::Value& command) {
2706 return new SkSaveCommand();
2707 }
2708
938 SkSaveLayerCommand::SkSaveLayerCommand(const SkCanvas::SaveLayerRec& rec) 2709 SkSaveLayerCommand::SkSaveLayerCommand(const SkCanvas::SaveLayerRec& rec)
939 : INHERITED(kSaveLayer_OpType) { 2710 : INHERITED(kSaveLayer_OpType) {
940 if (rec.fBounds) { 2711 if (rec.fBounds) {
941 fBounds = *rec.fBounds; 2712 fBounds = *rec.fBounds;
942 } else { 2713 } else {
943 fBounds.setEmpty(); 2714 fBounds.setEmpty();
944 } 2715 }
945 2716
946 if (rec.fPaint) { 2717 if (rec.fPaint) {
947 fPaint = *rec.fPaint; 2718 fPaint = *rec.fPaint;
948 fPaintPtr = &fPaint; 2719 fPaintPtr = &fPaint;
949 } else { 2720 } else {
950 fPaintPtr = nullptr; 2721 fPaintPtr = nullptr;
951 } 2722 }
952 fSaveLayerFlags = rec.fSaveLayerFlags; 2723 fSaveLayerFlags = rec.fSaveLayerFlags;
953 2724
2725 if (rec.fBackdrop) {
2726 fBackdrop = rec.fBackdrop;
2727 fBackdrop->ref();
2728 } else {
2729 fBackdrop = nullptr;
2730 }
2731
954 if (rec.fBounds) { 2732 if (rec.fBounds) {
955 fInfo.push(SkObjectParser::RectToString(*rec.fBounds, "Bounds: ")); 2733 fInfo.push(SkObjectParser::RectToString(*rec.fBounds, "Bounds: "));
956 } 2734 }
957 if (rec.fPaint) { 2735 if (rec.fPaint) {
958 fInfo.push(SkObjectParser::PaintToString(*rec.fPaint)); 2736 fInfo.push(SkObjectParser::PaintToString(*rec.fPaint));
959 } 2737 }
960 fInfo.push(SkObjectParser::SaveLayerFlagsToString(fSaveLayerFlags)); 2738 fInfo.push(SkObjectParser::SaveLayerFlagsToString(fSaveLayerFlags));
961 } 2739 }
962 2740
2741 SkSaveLayerCommand::~SkSaveLayerCommand() {
2742 if (fBackdrop != nullptr) {
2743 fBackdrop->unref();
2744 }
2745 }
2746
963 void SkSaveLayerCommand::execute(SkCanvas* canvas) const { 2747 void SkSaveLayerCommand::execute(SkCanvas* canvas) const {
964 canvas->saveLayer(SkCanvas::SaveLayerRec(fBounds.isEmpty() ? nullptr : &fBou nds, 2748 canvas->saveLayer(SkCanvas::SaveLayerRec(fBounds.isEmpty() ? nullptr : &fBou nds,
965 fPaintPtr, 2749 fPaintPtr,
966 fSaveLayerFlags)); 2750 fSaveLayerFlags));
967 } 2751 }
968 2752
969 void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) const { 2753 void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) const {
970 canvas->save(); 2754 canvas->save();
971 } 2755 }
972 2756
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
973 SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix) 2801 SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix)
974 : INHERITED(kSetMatrix_OpType) { 2802 : INHERITED(kSetMatrix_OpType) {
975 fUserMatrix.reset(); 2803 fUserMatrix.reset();
976 fMatrix = matrix; 2804 fMatrix = matrix;
977 2805
978 fInfo.push(SkObjectParser::MatrixToString(matrix)); 2806 fInfo.push(SkObjectParser::MatrixToString(matrix));
979 } 2807 }
980 2808
981 void SkSetMatrixCommand::setUserMatrix(const SkMatrix& userMatrix) { 2809 void SkSetMatrixCommand::setUserMatrix(const SkMatrix& userMatrix) {
982 fUserMatrix = userMatrix; 2810 fUserMatrix = userMatrix;
983 } 2811 }
984 2812
985 void SkSetMatrixCommand::execute(SkCanvas* canvas) const { 2813 void SkSetMatrixCommand::execute(SkCanvas* canvas) const {
986 SkMatrix temp = SkMatrix::Concat(fUserMatrix, fMatrix); 2814 SkMatrix temp = SkMatrix::Concat(fUserMatrix, fMatrix);
987 canvas->setMatrix(temp); 2815 canvas->setMatrix(temp);
988 } 2816 }
989 2817
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 }
OLDNEW
« no previous file with comments | « tools/debugger/SkDrawCommand.h ('k') | tools/debugger/SkObjectParser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698