OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkJSONCanvas.h" | 8 #include "SkJSONCanvas.h" |
9 #include "SkImageFilter.h" | 9 #include "SkImageFilter.h" |
10 #include "SkMaskFilter.h" | 10 #include "SkMaskFilter.h" |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 case SkCanvas::kLines_PointMode: | 503 case SkCanvas::kLines_PointMode: |
504 return Json::Value(SKJSONCANVAS_POINTMODE_LINES); | 504 return Json::Value(SKJSONCANVAS_POINTMODE_LINES); |
505 case SkCanvas::kPolygon_PointMode: | 505 case SkCanvas::kPolygon_PointMode: |
506 return Json::Value(SKJSONCANVAS_POINTMODE_POLYGON); | 506 return Json::Value(SKJSONCANVAS_POINTMODE_POLYGON); |
507 default: | 507 default: |
508 SkASSERT(false); | 508 SkASSERT(false); |
509 return Json::Value("<invalid point mode>"); | 509 return Json::Value("<invalid point mode>"); |
510 }; | 510 }; |
511 } | 511 } |
512 | 512 |
513 void SkJSONCanvas::updateMatrix() { | 513 void SkJSONCanvas::didConcat(const SkMatrix& matrix) { |
514 const SkMatrix& matrix = this->getTotalMatrix(); | 514 Json::Value command(Json::objectValue); |
515 if (matrix != fLastMatrix) { | 515 switch (matrix.getType()) { |
516 Json::Value command(Json::objectValue); | 516 case SkMatrix::kTranslate_Mask: |
517 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_MATRIX)
; | 517 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_TRA
NSLATE); |
518 command[SKJSONCANVAS_ATTRIBUTE_MATRIX] = MakeMatrix(matrix); | 518 command[SKJSONCANVAS_ATTRIBUTE_X] = Json::Value(matrix.get(SkMatrix:
:kMTransX)); |
519 fCommands.append(command); | 519 command[SKJSONCANVAS_ATTRIBUTE_Y] = Json::Value(matrix.get(SkMatrix:
:kMTransY)); |
520 fLastMatrix = matrix; | 520 break; |
| 521 case SkMatrix::kScale_Mask: |
| 522 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_SCA
LE); |
| 523 command[SKJSONCANVAS_ATTRIBUTE_X] = Json::Value(matrix.get(SkMatrix:
:kMScaleX)); |
| 524 command[SKJSONCANVAS_ATTRIBUTE_Y] = Json::Value(matrix.get(SkMatrix:
:kMScaleY)); |
| 525 break; |
| 526 default: |
| 527 this->didSetMatrix(this->getTotalMatrix()); |
| 528 return; |
521 } | 529 } |
| 530 fCommands.append(command); |
| 531 } |
| 532 |
| 533 void SkJSONCanvas::didSetMatrix(const SkMatrix& matrix) { |
| 534 Json::Value command(Json::objectValue); |
| 535 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_MATRIX); |
| 536 command[SKJSONCANVAS_ATTRIBUTE_MATRIX] = this->makeMatrix(matrix); |
| 537 fCommands.append(command); |
522 } | 538 } |
523 | 539 |
524 void SkJSONCanvas::onDrawPaint(const SkPaint& paint) { | 540 void SkJSONCanvas::onDrawPaint(const SkPaint& paint) { |
525 Json::Value command(Json::objectValue); | 541 Json::Value command(Json::objectValue); |
526 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_PAINT); | 542 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_PAINT); |
527 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); | 543 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); |
528 fCommands.append(command); | 544 fCommands.append(command); |
529 } | 545 } |
530 | 546 |
531 void SkJSONCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) { | 547 void SkJSONCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) { |
532 this->updateMatrix(); | |
533 Json::Value command(Json::objectValue); | 548 Json::Value command(Json::objectValue); |
534 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_RECT); | 549 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_RECT); |
535 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRect(rect); | 550 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRect(rect); |
536 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); | 551 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); |
537 fCommands.append(command); | 552 fCommands.append(command); |
538 } | 553 } |
539 | 554 |
540 void SkJSONCanvas::onDrawOval(const SkRect& rect, const SkPaint& paint) { | 555 void SkJSONCanvas::onDrawOval(const SkRect& rect, const SkPaint& paint) { |
541 this->updateMatrix(); | |
542 Json::Value command(Json::objectValue); | 556 Json::Value command(Json::objectValue); |
543 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_OVAL); | 557 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_OVAL); |
544 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRect(rect); | 558 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRect(rect); |
545 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); | 559 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); |
546 fCommands.append(command); | 560 fCommands.append(command); |
547 } | 561 } |
548 | 562 |
549 void SkJSONCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { | 563 void SkJSONCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { |
550 this->updateMatrix(); | |
551 Json::Value command(Json::objectValue); | 564 Json::Value command(Json::objectValue); |
552 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_RRECT); | 565 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_RRECT); |
553 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRRect(rrect); | 566 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRRect(rrect); |
554 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); | 567 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); |
555 fCommands.append(command); | 568 fCommands.append(command); |
556 } | 569 } |
557 | 570 |
558 void SkJSONCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, cons
t SkPaint& paint) { | 571 void SkJSONCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, cons
t SkPaint& paint) { |
559 this->updateMatrix(); | |
560 Json::Value command(Json::objectValue); | 572 Json::Value command(Json::objectValue); |
561 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_RRECT); | 573 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_RRECT); |
562 command[SKJSONCANVAS_ATTRIBUTE_INNER] = this->makeRRect(inner); | 574 command[SKJSONCANVAS_ATTRIBUTE_INNER] = this->makeRRect(inner); |
563 command[SKJSONCANVAS_ATTRIBUTE_OUTER] = this->makeRRect(outer); | 575 command[SKJSONCANVAS_ATTRIBUTE_OUTER] = this->makeRRect(outer); |
564 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); | 576 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); |
565 fCommands.append(command); | 577 fCommands.append(command); |
566 } | 578 } |
567 | 579 |
568 void SkJSONCanvas::onDrawPoints(SkCanvas::PointMode mode, size_t count, const Sk
Point pts[], | 580 void SkJSONCanvas::onDrawPoints(SkCanvas::PointMode mode, size_t count, const Sk
Point pts[], |
569 const SkPaint& paint) { | 581 const SkPaint& paint) { |
570 this->updateMatrix(); | |
571 Json::Value command(Json::objectValue); | 582 Json::Value command(Json::objectValue); |
572 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_POINTS); | 583 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_POINTS); |
573 command[SKJSONCANVAS_ATTRIBUTE_MODE] = this->makePointMode(mode); | 584 command[SKJSONCANVAS_ATTRIBUTE_MODE] = this->makePointMode(mode); |
574 Json::Value points(Json::arrayValue); | 585 Json::Value points(Json::arrayValue); |
575 for (size_t i = 0; i < count; i++) { | 586 for (size_t i = 0; i < count; i++) { |
576 points.append(this->makePoint(pts[i])); | 587 points.append(this->makePoint(pts[i])); |
577 } | 588 } |
578 command[SKJSONCANVAS_ATTRIBUTE_POINTS] = points; | 589 command[SKJSONCANVAS_ATTRIBUTE_POINTS] = points; |
579 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); | 590 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); |
580 fCommands.append(command); | 591 fCommands.append(command); |
581 } | 592 } |
582 | 593 |
583 void SkJSONCanvas::onDrawVertices(SkCanvas::VertexMode, int vertexCount, const S
kPoint vertices[], | 594 void SkJSONCanvas::onDrawVertices(SkCanvas::VertexMode, int vertexCount, const S
kPoint vertices[], |
584 const SkPoint texs[], const SkColor colors[],
SkXfermode*, | 595 const SkPoint texs[], const SkColor colors[],
SkXfermode*, |
585 const uint16_t indices[], int indexCount, cons
t SkPaint&) { | 596 const uint16_t indices[], int indexCount, cons
t SkPaint&) { |
586 SkDebugf("unsupported: drawVertices\n"); | 597 SkDebugf("unsupported: drawVertices\n"); |
| 598 Json::Value command(Json::objectValue); |
| 599 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_VERTICES); |
| 600 fCommands.append(command); |
587 } | 601 } |
588 | 602 |
589 void SkJSONCanvas::onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[]
, const SkColor[], | 603 void SkJSONCanvas::onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[]
, const SkColor[], |
590 int count, SkXfermode::Mode, const SkRect* cull,
const SkPaint*) { | 604 int count, SkXfermode::Mode, const SkRect* cull,
const SkPaint*) { |
591 SkDebugf("unsupported: drawAtlas\n"); | 605 SkDebugf("unsupported: drawAtlas\n"); |
| 606 Json::Value command(Json::objectValue); |
| 607 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_ATLAS); |
| 608 fCommands.append(command); |
592 } | 609 } |
593 | 610 |
594 void SkJSONCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { | 611 void SkJSONCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { |
595 this->updateMatrix(); | |
596 Json::Value command(Json::objectValue); | 612 Json::Value command(Json::objectValue); |
597 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_PATH); | 613 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_PATH); |
598 command[SKJSONCANVAS_ATTRIBUTE_PATH] = this->makePath(path); | 614 command[SKJSONCANVAS_ATTRIBUTE_PATH] = this->makePath(path); |
599 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); | 615 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); |
600 fCommands.append(command); | 616 fCommands.append(command); |
601 } | 617 } |
602 | 618 |
603 void SkJSONCanvas::onDrawImage(const SkImage* image, SkScalar dx, SkScalar dy, | 619 void SkJSONCanvas::onDrawImage(const SkImage* image, SkScalar dx, SkScalar dy, |
604 const SkPaint* paint) { | 620 const SkPaint* paint) { |
605 Json::Value encoded; | 621 Json::Value encoded; |
606 if (flatten(*image, &encoded, fSendBinaries)) { | 622 if (flatten(*image, &encoded, fSendBinaries)) { |
607 this->updateMatrix(); | |
608 Json::Value command(Json::objectValue); | 623 Json::Value command(Json::objectValue); |
609 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_IMAGE); | 624 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_IMAGE); |
610 command[SKJSONCANVAS_ATTRIBUTE_IMAGE] = encoded; | 625 command[SKJSONCANVAS_ATTRIBUTE_IMAGE] = encoded; |
611 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makePoint(dx, dy); | 626 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makePoint(dx, dy); |
612 if (paint != nullptr) { | 627 if (paint != nullptr) { |
613 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(*paint); | 628 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(*paint); |
614 } | 629 } |
615 fCommands.append(command); | 630 fCommands.append(command); |
616 } | 631 } |
617 } | 632 } |
618 | 633 |
619 void SkJSONCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, cons
t SkRect& dst, | 634 void SkJSONCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, cons
t SkRect& dst, |
620 const SkPaint* paint, SkCanvas::SrcRectConstr
aint constraint) { | 635 const SkPaint* paint, SkCanvas::SrcRectConstr
aint constraint) { |
621 Json::Value encoded; | 636 Json::Value encoded; |
622 if (flatten(*image, &encoded, fSendBinaries)) { | 637 if (flatten(*image, &encoded, fSendBinaries)) { |
623 this->updateMatrix(); | |
624 Json::Value command(Json::objectValue); | 638 Json::Value command(Json::objectValue); |
625 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_IMAGERE
CT); | 639 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_IMAGERE
CT); |
626 command[SKJSONCANVAS_ATTRIBUTE_IMAGE] = encoded; | 640 command[SKJSONCANVAS_ATTRIBUTE_IMAGE] = encoded; |
627 if (src != nullptr) { | 641 if (src != nullptr) { |
628 command[SKJSONCANVAS_ATTRIBUTE_SRC] = this->makeRect(*src); | 642 command[SKJSONCANVAS_ATTRIBUTE_SRC] = this->makeRect(*src); |
629 } | 643 } |
630 command[SKJSONCANVAS_ATTRIBUTE_DST] = this->makeRect(dst); | 644 command[SKJSONCANVAS_ATTRIBUTE_DST] = this->makeRect(dst); |
631 if (paint != nullptr) { | 645 if (paint != nullptr) { |
632 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(*paint); | 646 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(*paint); |
633 } | 647 } |
634 if (constraint == SkCanvas::kStrict_SrcRectConstraint) { | 648 if (constraint == SkCanvas::kStrict_SrcRectConstraint) { |
635 command[SKJSONCANVAS_ATTRIBUTE_STRICT] = Json::Value(true); | 649 command[SKJSONCANVAS_ATTRIBUTE_STRICT] = Json::Value(true); |
636 } | 650 } |
637 fCommands.append(command); | 651 fCommands.append(command); |
638 } | 652 } |
639 } | 653 } |
640 | 654 |
641 void SkJSONCanvas::onDrawImageNine(const SkImage*, const SkIRect& center, const
SkRect& dst, | 655 void SkJSONCanvas::onDrawImageNine(const SkImage*, const SkIRect& center, const
SkRect& dst, |
642 const SkPaint*) { | 656 const SkPaint*) { |
643 SkDebugf("unsupported: drawImageNine\n"); | 657 SkDebugf("unsupported: drawImageNine\n"); |
| 658 Json::Value command(Json::objectValue); |
| 659 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_IMAGENINE); |
| 660 fCommands.append(command); |
644 } | 661 } |
645 | 662 |
646 void SkJSONCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar dx, SkScalar dy
, | 663 void SkJSONCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar dx, SkScalar dy
, |
647 const SkPaint* paint) { | 664 const SkPaint* paint) { |
648 Json::Value encoded; | 665 Json::Value encoded; |
649 if (flatten(bitmap, &encoded, fSendBinaries)) { | 666 if (flatten(bitmap, &encoded, fSendBinaries)) { |
650 this->updateMatrix(); | |
651 Json::Value command(Json::objectValue); | 667 Json::Value command(Json::objectValue); |
652 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_BITMAP)
; | 668 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_BITMAP)
; |
653 command[SKJSONCANVAS_ATTRIBUTE_BITMAP] = encoded; | 669 command[SKJSONCANVAS_ATTRIBUTE_BITMAP] = encoded; |
654 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makePoint(dx, dy); | 670 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makePoint(dx, dy); |
655 if (paint != nullptr) { | 671 if (paint != nullptr) { |
656 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(*paint); | 672 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(*paint); |
657 } | 673 } |
658 fCommands.append(command); | 674 fCommands.append(command); |
659 } | 675 } |
660 } | 676 } |
661 | 677 |
662 void SkJSONCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, c
onst SkRect& dst, | 678 void SkJSONCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, c
onst SkRect& dst, |
663 const SkPaint* paint, SkCanvas::SrcRectConstr
aint constraint) { | 679 const SkPaint* paint, SkCanvas::SrcRectConstr
aint constraint) { |
664 Json::Value encoded; | 680 Json::Value encoded; |
665 if (flatten(bitmap, &encoded, fSendBinaries)) { | 681 if (flatten(bitmap, &encoded, fSendBinaries)) { |
666 this->updateMatrix(); | |
667 Json::Value command(Json::objectValue); | 682 Json::Value command(Json::objectValue); |
668 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_BITMAPR
ECT); | 683 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_BITMAPR
ECT); |
669 command[SKJSONCANVAS_ATTRIBUTE_BITMAP] = encoded; | 684 command[SKJSONCANVAS_ATTRIBUTE_BITMAP] = encoded; |
670 if (src != nullptr) { | 685 if (src != nullptr) { |
671 command[SKJSONCANVAS_ATTRIBUTE_SRC] = this->makeRect(*src); | 686 command[SKJSONCANVAS_ATTRIBUTE_SRC] = this->makeRect(*src); |
672 } | 687 } |
673 command[SKJSONCANVAS_ATTRIBUTE_DST] = this->makeRect(dst); | 688 command[SKJSONCANVAS_ATTRIBUTE_DST] = this->makeRect(dst); |
674 if (paint != nullptr) { | 689 if (paint != nullptr) { |
675 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(*paint); | 690 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(*paint); |
676 } | 691 } |
677 if (constraint == SkCanvas::kStrict_SrcRectConstraint) { | 692 if (constraint == SkCanvas::kStrict_SrcRectConstraint) { |
678 command[SKJSONCANVAS_ATTRIBUTE_STRICT] = Json::Value(true); | 693 command[SKJSONCANVAS_ATTRIBUTE_STRICT] = Json::Value(true); |
679 } | 694 } |
680 fCommands.append(command); | 695 fCommands.append(command); |
681 } | 696 } |
682 } | 697 } |
683 | 698 |
684 void SkJSONCanvas::onDrawBitmapNine(const SkBitmap&, const SkIRect& center, cons
t SkRect& dst, | 699 void SkJSONCanvas::onDrawBitmapNine(const SkBitmap&, const SkIRect& center, cons
t SkRect& dst, |
685 const SkPaint*) { | 700 const SkPaint*) { |
686 SkDebugf("unsupported: drawBitmapNine\n"); | 701 SkDebugf("unsupported: drawBitmapNine\n"); |
| 702 Json::Value command(Json::objectValue); |
| 703 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_BITMAPNINE)
; |
| 704 fCommands.append(command); |
687 } | 705 } |
688 | 706 |
689 void SkJSONCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, | 707 void SkJSONCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, |
690 SkScalar y, const SkPaint& paint) { | 708 SkScalar y, const SkPaint& paint) { |
691 this->updateMatrix(); | |
692 Json::Value command(Json::objectValue); | 709 Json::Value command(Json::objectValue); |
693 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_TEXT); | 710 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_TEXT); |
694 command[SKJSONCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) text, | 711 command[SKJSONCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) text, |
695 ((const char*) text) + by
teLength); | 712 ((const char*) text) + by
teLength); |
696 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makePoint(x, y); | 713 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makePoint(x, y); |
697 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); | 714 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); |
698 fCommands.append(command); | 715 fCommands.append(command); |
699 } | 716 } |
700 | 717 |
701 void SkJSONCanvas::onDrawPosText(const void* text, size_t byteLength, | 718 void SkJSONCanvas::onDrawPosText(const void* text, size_t byteLength, |
702 const SkPoint pos[], const SkPaint& paint) { | 719 const SkPoint pos[], const SkPaint& paint) { |
703 this->updateMatrix(); | |
704 Json::Value command(Json::objectValue); | 720 Json::Value command(Json::objectValue); |
705 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_POSTEXT); | 721 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_POSTEXT); |
706 command[SKJSONCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) text, | 722 command[SKJSONCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) text, |
707 ((const char*) text) + by
teLength); | 723 ((const char*) text) + by
teLength); |
708 Json::Value coords(Json::arrayValue); | 724 Json::Value coords(Json::arrayValue); |
709 for (size_t i = 0; i < byteLength; i++) { | 725 for (size_t i = 0; i < byteLength; i++) { |
710 coords.append(this->makePoint(pos[i])); | 726 coords.append(this->makePoint(pos[i])); |
711 } | 727 } |
712 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = coords; | 728 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = coords; |
713 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); | 729 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); |
714 fCommands.append(command); | 730 fCommands.append(command); |
715 } | 731 } |
716 | 732 |
717 void SkJSONCanvas::onDrawPosTextH(const void* text, size_t byteLength, | 733 void SkJSONCanvas::onDrawPosTextH(const void* text, size_t byteLength, |
718 const SkScalar xpos[], SkScalar constY, | 734 const SkScalar xpos[], SkScalar constY, |
719 const SkPaint& paint) { | 735 const SkPaint& paint) { |
720 SkDebugf("unsupported: drawPosTextH\n"); | 736 SkDebugf("unsupported: drawPosTextH\n"); |
| 737 Json::Value command(Json::objectValue); |
| 738 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_POSTEXTH); |
| 739 fCommands.append(command); |
721 } | 740 } |
722 | 741 |
723 void SkJSONCanvas::onDrawTextOnPath(const void* text, size_t byteLength, | 742 void SkJSONCanvas::onDrawTextOnPath(const void* text, size_t byteLength, |
724 const SkPath& path, const SkMatrix* matrix, | 743 const SkPath& path, const SkMatrix* matrix, |
725 const SkPaint& paint) { | 744 const SkPaint& paint) { |
726 SkDebugf("unsupported: drawTextOnPath\n"); | 745 Json::Value command(Json::objectValue); |
| 746 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_TEXTONPATH)
; |
| 747 command[SKJSONCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) text, |
| 748 ((const char*) text) + by
teLength); |
| 749 command[SKJSONCANVAS_ATTRIBUTE_PATH] = this->makePath(path); |
| 750 if (matrix != nullptr) { |
| 751 command[SKJSONCANVAS_ATTRIBUTE_MATRIX] = this->makeMatrix(*matrix); |
| 752 } |
| 753 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint); |
| 754 fCommands.append(command); |
727 } | 755 } |
728 | 756 |
729 void SkJSONCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y
, | 757 void SkJSONCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y
, |
730 const SkPaint& paint) { | 758 const SkPaint& paint) { |
731 SkDebugf("unsupported: drawTextBlob\n"); | 759 SkDebugf("unsupported: drawTextBlob\n"); |
| 760 Json::Value command(Json::objectValue); |
| 761 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_TEXTBLOB); |
| 762 fCommands.append(command); |
732 } | 763 } |
733 | 764 |
734 void SkJSONCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4]
, | 765 void SkJSONCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4]
, |
735 const SkPoint texCoords[4], SkXfermode* xmode, | 766 const SkPoint texCoords[4], SkXfermode* xmode, |
736 const SkPaint& paint) { | 767 const SkPaint& paint) { |
737 SkDebugf("unsupported: drawPatch\n"); | 768 SkDebugf("unsupported: drawPatch\n"); |
| 769 Json::Value command(Json::objectValue); |
| 770 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_PATCH); |
| 771 fCommands.append(command); |
738 } | 772 } |
739 | 773 |
740 void SkJSONCanvas::onDrawDrawable(SkDrawable*, const SkMatrix*) { | 774 void SkJSONCanvas::onDrawDrawable(SkDrawable*, const SkMatrix*) { |
741 SkDebugf("unsupported: drawDrawable\n"); | 775 SkDebugf("unsupported: drawDrawable\n"); |
| 776 Json::Value command(Json::objectValue); |
| 777 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_DRAWABLE); |
| 778 fCommands.append(command); |
742 } | 779 } |
743 | 780 |
744 void SkJSONCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle
edgeStyle) { | 781 void SkJSONCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle
edgeStyle) { |
745 this->updateMatrix(); | |
746 Json::Value command(Json::objectValue); | 782 Json::Value command(Json::objectValue); |
747 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPRECT); | 783 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPRECT); |
748 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRect(rect); | 784 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRect(rect); |
749 command[SKJSONCANVAS_ATTRIBUTE_REGIONOP] = this->makeRegionOp(op); | 785 command[SKJSONCANVAS_ATTRIBUTE_REGIONOP] = this->makeRegionOp(op); |
750 command[SKJSONCANVAS_ATTRIBUTE_ANTIALIAS] = (edgeStyle == SkCanvas::kSoft_Cl
ipEdgeStyle); | 786 command[SKJSONCANVAS_ATTRIBUTE_ANTIALIAS] = (edgeStyle == SkCanvas::kSoft_Cl
ipEdgeStyle); |
751 fCommands.append(command); | 787 fCommands.append(command); |
752 } | 788 } |
753 | 789 |
754 void SkJSONCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeSt
yle edgeStyle) { | 790 void SkJSONCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeSt
yle edgeStyle) { |
755 this->updateMatrix(); | |
756 Json::Value command(Json::objectValue); | 791 Json::Value command(Json::objectValue); |
757 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPRRECT); | 792 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPRRECT); |
758 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRRect(rrect); | 793 command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRRect(rrect); |
759 command[SKJSONCANVAS_ATTRIBUTE_REGIONOP] = this->makeRegionOp(op); | 794 command[SKJSONCANVAS_ATTRIBUTE_REGIONOP] = this->makeRegionOp(op); |
760 command[SKJSONCANVAS_ATTRIBUTE_ANTIALIAS] = (edgeStyle == SkCanvas::kSoft_Cl
ipEdgeStyle); | 795 command[SKJSONCANVAS_ATTRIBUTE_ANTIALIAS] = (edgeStyle == SkCanvas::kSoft_Cl
ipEdgeStyle); |
761 fCommands.append(command); | 796 fCommands.append(command); |
762 } | 797 } |
763 | 798 |
764 void SkJSONCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle
edgeStyle) { | 799 void SkJSONCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle
edgeStyle) { |
765 this->updateMatrix(); | |
766 Json::Value command(Json::objectValue); | 800 Json::Value command(Json::objectValue); |
767 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPPATH); | 801 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPPATH); |
768 command[SKJSONCANVAS_ATTRIBUTE_PATH] = this->makePath(path); | 802 command[SKJSONCANVAS_ATTRIBUTE_PATH] = this->makePath(path); |
769 command[SKJSONCANVAS_ATTRIBUTE_REGIONOP] = this->makeRegionOp(op); | 803 command[SKJSONCANVAS_ATTRIBUTE_REGIONOP] = this->makeRegionOp(op); |
770 command[SKJSONCANVAS_ATTRIBUTE_ANTIALIAS] = (edgeStyle == SkCanvas::kSoft_Cl
ipEdgeStyle); | 804 command[SKJSONCANVAS_ATTRIBUTE_ANTIALIAS] = (edgeStyle == SkCanvas::kSoft_Cl
ipEdgeStyle); |
771 fCommands.append(command); | 805 fCommands.append(command); |
772 } | 806 } |
773 | 807 |
774 void SkJSONCanvas::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { | 808 void SkJSONCanvas::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { |
775 this->updateMatrix(); | |
776 Json::Value command(Json::objectValue); | 809 Json::Value command(Json::objectValue); |
777 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPREGION)
; | 810 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPREGION)
; |
778 command[SKJSONCANVAS_ATTRIBUTE_REGION] = this->makeRegion(deviceRgn); | 811 command[SKJSONCANVAS_ATTRIBUTE_REGION] = this->makeRegion(deviceRgn); |
779 command[SKJSONCANVAS_ATTRIBUTE_REGIONOP] = this->makeRegionOp(op); | 812 command[SKJSONCANVAS_ATTRIBUTE_REGIONOP] = this->makeRegionOp(op); |
780 fCommands.append(command); | 813 fCommands.append(command); |
781 } | 814 } |
782 | 815 |
783 void SkJSONCanvas::willSave() { | 816 void SkJSONCanvas::willSave() { |
784 this->updateMatrix(); | |
785 Json::Value command(Json::objectValue); | 817 Json::Value command(Json::objectValue); |
786 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_SAVE); | 818 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_SAVE); |
787 fCommands.append(command); | 819 fCommands.append(command); |
788 } | 820 } |
789 | 821 |
790 void SkJSONCanvas::willRestore() { | 822 void SkJSONCanvas::willRestore() { |
791 Json::Value command(Json::objectValue); | 823 Json::Value command(Json::objectValue); |
792 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_RESTORE); | 824 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_RESTORE); |
793 fCommands.append(command); | 825 fCommands.append(command); |
794 } | 826 } |
795 | 827 |
796 SkCanvas::SaveLayerStrategy SkJSONCanvas::getSaveLayerStrategy(const SaveLayerRe
c& rec) { | 828 SkCanvas::SaveLayerStrategy SkJSONCanvas::getSaveLayerStrategy(const SaveLayerRe
c& rec) { |
797 this->updateMatrix(); | |
798 Json::Value command(Json::objectValue); | 829 Json::Value command(Json::objectValue); |
799 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_SAVELAYER); | 830 command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_SAVELAYER); |
800 if (rec.fBounds != nullptr) { | 831 if (rec.fBounds != nullptr) { |
801 command[SKJSONCANVAS_ATTRIBUTE_BOUNDS] = this->makeRect(*rec.fBounds); | 832 command[SKJSONCANVAS_ATTRIBUTE_BOUNDS] = this->makeRect(*rec.fBounds); |
802 } | 833 } |
803 if (rec.fPaint != nullptr) { | 834 if (rec.fPaint != nullptr) { |
804 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(*rec.fPaint); | 835 command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(*rec.fPaint); |
805 } | 836 } |
806 if (rec.fBackdrop != nullptr) { | 837 if (rec.fBackdrop != nullptr) { |
807 Json::Value backdrop; | 838 Json::Value backdrop; |
808 flatten(rec.fBackdrop, &backdrop, fSendBinaries); | 839 flatten(rec.fBackdrop, &backdrop, fSendBinaries); |
809 command[SKJSONCANVAS_ATTRIBUTE_BACKDROP] = backdrop; | 840 command[SKJSONCANVAS_ATTRIBUTE_BACKDROP] = backdrop; |
810 } | 841 } |
811 if (rec.fSaveLayerFlags != 0) { | 842 if (rec.fSaveLayerFlags != 0) { |
812 SkDebugf("unsupported: saveLayer flags\n"); | 843 SkDebugf("unsupported: saveLayer flags\n"); |
813 } | 844 } |
814 fCommands.append(command); | 845 fCommands.append(command); |
815 return this->INHERITED::getSaveLayerStrategy(rec); | 846 return this->INHERITED::getSaveLayerStrategy(rec); |
816 } | 847 } |
OLD | NEW |