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

Side by Side Diff: src/core/SkPictureRecord.cpp

Issue 153983007: Clean up SkPictureRecord.cpp (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 2011 Google Inc. 3 * Copyright 2011 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 #include "SkPictureRecord.h" 8 #include "SkPictureRecord.h"
9 #include "SkTSearch.h" 9 #include "SkTSearch.h"
10 #include "SkPixelRef.h" 10 #include "SkPixelRef.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 // from a clip entry. 142 // from a clip entry.
143 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); 143 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten());
144 this->recordSave(flags); 144 this->recordSave(flags);
145 return this->INHERITED::save(flags); 145 return this->INHERITED::save(flags);
146 } 146 }
147 147
148 void SkPictureRecord::recordSave(SaveFlags flags) { 148 void SkPictureRecord::recordSave(SaveFlags flags) {
149 // op + flags 149 // op + flags
150 uint32_t size = kSaveSize; 150 uint32_t size = kSaveSize;
151 size_t initialOffset = this->addDraw(SAVE, &size); 151 size_t initialOffset = this->addDraw(SAVE, &size);
152 addInt(flags); 152 this->addInt(flags);
153 153
154 this->validate(initialOffset, size); 154 this->validate(initialOffset, size);
155 } 155 }
156 156
157 int SkPictureRecord::saveLayer(const SkRect* bounds, const SkPaint* paint, 157 int SkPictureRecord::saveLayer(const SkRect* bounds, const SkPaint* paint,
158 SaveFlags flags) { 158 SaveFlags flags) {
159 // record the offset to us, making it non-positive to distinguish a save 159 // record the offset to us, making it non-positive to distinguish a save
160 // from a clip entry. 160 // from a clip entry.
161 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); 161 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten());
162 this->recordSaveLayer(bounds, paint, flags); 162 this->recordSaveLayer(bounds, paint, flags);
(...skipping 18 matching lines...) Expand all
181 uint32_t size = 2 * kUInt32Size; 181 uint32_t size = 2 * kUInt32Size;
182 if (NULL != bounds) { 182 if (NULL != bounds) {
183 size += sizeof(*bounds); // + rect 183 size += sizeof(*bounds); // + rect
184 } 184 }
185 // + paint index + flags 185 // + paint index + flags
186 size += 2 * kUInt32Size; 186 size += 2 * kUInt32Size;
187 187
188 SkASSERT(kSaveLayerNoBoundsSize == size || kSaveLayerWithBoundsSize == size) ; 188 SkASSERT(kSaveLayerNoBoundsSize == size || kSaveLayerWithBoundsSize == size) ;
189 189
190 size_t initialOffset = this->addDraw(SAVE_LAYER, &size); 190 size_t initialOffset = this->addDraw(SAVE_LAYER, &size);
191 addRectPtr(bounds); 191 this->addRectPtr(bounds);
192 SkASSERT(initialOffset+getPaintOffset(SAVE_LAYER, size) == fWriter.bytesWrit ten()); 192 SkASSERT(initialOffset+getPaintOffset(SAVE_LAYER, size) == fWriter.bytesWrit ten());
193 addPaintPtr(paint); 193 this->addPaintPtr(paint);
194 addInt(flags); 194 this->addInt(flags);
195 195
196 this->validate(initialOffset, size); 196 this->validate(initialOffset, size);
197 } 197 }
198 198
199 bool SkPictureRecord::isDrawingToLayer() const { 199 bool SkPictureRecord::isDrawingToLayer() const {
200 return fFirstSavedLayerIndex != kNoSavedLayerIndex; 200 return fFirstSavedLayerIndex != kNoSavedLayerIndex;
201 } 201 }
202 202
203 /* 203 /*
204 * Read the op code from 'offset' in 'writer' and extract the size too. 204 * Read the op code from 'offset' in 'writer' and extract the size too.
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 this->recordRestore(); 607 this->recordRestore();
608 } 608 }
609 609
610 fRestoreOffsetStack.pop(); 610 fRestoreOffsetStack.pop();
611 611
612 return this->INHERITED::restore(); 612 return this->INHERITED::restore();
613 } 613 }
614 614
615 void SkPictureRecord::recordRestore() { 615 void SkPictureRecord::recordRestore() {
616 uint32_t initialOffset, size; 616 uint32_t initialOffset, size;
617 fillRestoreOffsetPlaceholdersForCurrentStackLevel((uint32_t)fWriter.bytesWri tten()); 617 this->fillRestoreOffsetPlaceholdersForCurrentStackLevel((uint32_t)fWriter.by tesWritten());
618 size = 1 * kUInt32Size; // RESTORE consists solely of 1 op code 618 size = 1 * kUInt32Size; // RESTORE consists solely of 1 op code
619 initialOffset = this->addDraw(RESTORE, &size); 619 initialOffset = this->addDraw(RESTORE, &size);
620 this->validate(initialOffset, size); 620 this->validate(initialOffset, size);
621 } 621 }
622 622
623 bool SkPictureRecord::translate(SkScalar dx, SkScalar dy) { 623 bool SkPictureRecord::translate(SkScalar dx, SkScalar dy) {
624 // op + dx + dy 624 // op + dx + dy
625 uint32_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar); 625 uint32_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar);
626 size_t initialOffset = this->addDraw(TRANSLATE, &size); 626 size_t initialOffset = this->addDraw(TRANSLATE, &size);
627 addScalar(dx); 627 this->addScalar(dx);
628 addScalar(dy); 628 this->addScalar(dy);
629 this->validate(initialOffset, size); 629 this->validate(initialOffset, size);
630 return this->INHERITED::translate(dx, dy); 630 return this->INHERITED::translate(dx, dy);
631 } 631 }
632 632
633 bool SkPictureRecord::scale(SkScalar sx, SkScalar sy) { 633 bool SkPictureRecord::scale(SkScalar sx, SkScalar sy) {
634 // op + sx + sy 634 // op + sx + sy
635 uint32_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar); 635 uint32_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar);
636 size_t initialOffset = this->addDraw(SCALE, &size); 636 size_t initialOffset = this->addDraw(SCALE, &size);
637 addScalar(sx); 637 this->addScalar(sx);
638 addScalar(sy); 638 this->addScalar(sy);
639 this->validate(initialOffset, size); 639 this->validate(initialOffset, size);
640 return this->INHERITED::scale(sx, sy); 640 return this->INHERITED::scale(sx, sy);
641 } 641 }
642 642
643 bool SkPictureRecord::rotate(SkScalar degrees) { 643 bool SkPictureRecord::rotate(SkScalar degrees) {
644 // op + degrees 644 // op + degrees
645 uint32_t size = 1 * kUInt32Size + sizeof(SkScalar); 645 uint32_t size = 1 * kUInt32Size + sizeof(SkScalar);
646 size_t initialOffset = this->addDraw(ROTATE, &size); 646 size_t initialOffset = this->addDraw(ROTATE, &size);
647 addScalar(degrees); 647 this->addScalar(degrees);
648 this->validate(initialOffset, size); 648 this->validate(initialOffset, size);
649 return this->INHERITED::rotate(degrees); 649 return this->INHERITED::rotate(degrees);
650 } 650 }
651 651
652 bool SkPictureRecord::skew(SkScalar sx, SkScalar sy) { 652 bool SkPictureRecord::skew(SkScalar sx, SkScalar sy) {
653 // op + sx + sy 653 // op + sx + sy
654 uint32_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar); 654 uint32_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar);
655 size_t initialOffset = this->addDraw(SKEW, &size); 655 size_t initialOffset = this->addDraw(SKEW, &size);
656 addScalar(sx); 656 this->addScalar(sx);
657 addScalar(sy); 657 this->addScalar(sy);
658 this->validate(initialOffset, size); 658 this->validate(initialOffset, size);
659 return this->INHERITED::skew(sx, sy); 659 return this->INHERITED::skew(sx, sy);
660 } 660 }
661 661
662 bool SkPictureRecord::concat(const SkMatrix& matrix) { 662 bool SkPictureRecord::concat(const SkMatrix& matrix) {
663 this->recordConcat(matrix); 663 this->recordConcat(matrix);
664 return this->INHERITED::concat(matrix); 664 return this->INHERITED::concat(matrix);
665 } 665 }
666 666
667 void SkPictureRecord::recordConcat(const SkMatrix& matrix) { 667 void SkPictureRecord::recordConcat(const SkMatrix& matrix) {
668 this->validate(fWriter.bytesWritten(), 0); 668 this->validate(fWriter.bytesWritten(), 0);
669 // op + matrix 669 // op + matrix
670 uint32_t size = kUInt32Size + matrix.writeToMemory(NULL); 670 uint32_t size = kUInt32Size + matrix.writeToMemory(NULL);
671 size_t initialOffset = this->addDraw(CONCAT, &size); 671 size_t initialOffset = this->addDraw(CONCAT, &size);
672 addMatrix(matrix); 672 this->addMatrix(matrix);
673 this->validate(initialOffset, size); 673 this->validate(initialOffset, size);
674 } 674 }
675 675
676 void SkPictureRecord::setMatrix(const SkMatrix& matrix) { 676 void SkPictureRecord::setMatrix(const SkMatrix& matrix) {
677 this->validate(fWriter.bytesWritten(), 0); 677 this->validate(fWriter.bytesWritten(), 0);
678 // op + matrix 678 // op + matrix
679 uint32_t size = kUInt32Size + matrix.writeToMemory(NULL); 679 uint32_t size = kUInt32Size + matrix.writeToMemory(NULL);
680 size_t initialOffset = this->addDraw(SET_MATRIX, &size); 680 size_t initialOffset = this->addDraw(SET_MATRIX, &size);
681 addMatrix(matrix); 681 this->addMatrix(matrix);
682 this->validate(initialOffset, size); 682 this->validate(initialOffset, size);
683 this->INHERITED::setMatrix(matrix); 683 this->INHERITED::setMatrix(matrix);
684 } 684 }
685 685
686 static bool regionOpExpands(SkRegion::Op op) { 686 static bool regionOpExpands(SkRegion::Op op) {
687 switch (op) { 687 switch (op) {
688 case SkRegion::kUnion_Op: 688 case SkRegion::kUnion_Op:
689 case SkRegion::kXOR_Op: 689 case SkRegion::kXOR_Op:
690 case SkRegion::kReverseDifference_Op: 690 case SkRegion::kReverseDifference_Op:
691 case SkRegion::kReplace_Op: 691 case SkRegion::kReplace_Op:
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 // in the current stack level, thus forming a linked list so that 737 // in the current stack level, thus forming a linked list so that
738 // the restore offsets can be filled in when the corresponding 738 // the restore offsets can be filled in when the corresponding
739 // restore command is recorded. 739 // restore command is recorded.
740 int32_t prevOffset = fRestoreOffsetStack.top(); 740 int32_t prevOffset = fRestoreOffsetStack.top();
741 741
742 if (regionOpExpands(op)) { 742 if (regionOpExpands(op)) {
743 // Run back through any previous clip ops, and mark their offset to 743 // Run back through any previous clip ops, and mark their offset to
744 // be 0, disabling their ability to trigger a jump-to-restore, otherwise 744 // be 0, disabling their ability to trigger a jump-to-restore, otherwise
745 // they could hide this clips ability to expand the clip (i.e. go from 745 // they could hide this clips ability to expand the clip (i.e. go from
746 // empty to non-empty). 746 // empty to non-empty).
747 fillRestoreOffsetPlaceholdersForCurrentStackLevel(0); 747 this->fillRestoreOffsetPlaceholdersForCurrentStackLevel(0);
748 748
749 // Reset the pointer back to the previous clip so that subsequent 749 // Reset the pointer back to the previous clip so that subsequent
750 // restores don't overwrite the offsets we just cleared. 750 // restores don't overwrite the offsets we just cleared.
751 prevOffset = 0; 751 prevOffset = 0;
752 } 752 }
753 753
754 size_t offset = fWriter.bytesWritten(); 754 size_t offset = fWriter.bytesWritten();
755 addInt(prevOffset); 755 this->addInt(prevOffset);
756 fRestoreOffsetStack.top() = offset; 756 fRestoreOffsetStack.top() = offset;
757 return offset; 757 return offset;
758 } 758 }
759 759
760 bool SkPictureRecord::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { 760 bool SkPictureRecord::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
761 this->recordClipRect(rect, op, doAA); 761 this->recordClipRect(rect, op, doAA);
762 return this->INHERITED::clipRect(rect, op, doAA); 762 return this->INHERITED::clipRect(rect, op, doAA);
763 } 763 }
764 764
765 int SkPictureRecord::recordClipRect(const SkRect& rect, SkRegion::Op op, bool do AA) { 765 int SkPictureRecord::recordClipRect(const SkRect& rect, SkRegion::Op op, bool do AA) {
766 766
767 // id + rect + clip params 767 // id + rect + clip params
768 uint32_t size = 1 * kUInt32Size + sizeof(rect) + 1 * kUInt32Size; 768 uint32_t size = 1 * kUInt32Size + sizeof(rect) + 1 * kUInt32Size;
769 // recordRestoreOffsetPlaceholder doesn't always write an offset 769 // recordRestoreOffsetPlaceholder doesn't always write an offset
770 if (!fRestoreOffsetStack.isEmpty()) { 770 if (!fRestoreOffsetStack.isEmpty()) {
771 // + restore offset 771 // + restore offset
772 size += kUInt32Size; 772 size += kUInt32Size;
773 } 773 }
774 774
775 size_t initialOffset = this->addDraw(CLIP_RECT, &size); 775 size_t initialOffset = this->addDraw(CLIP_RECT, &size);
776 addRect(rect); 776 this->addRect(rect);
777 addInt(ClipParams_pack(op, doAA)); 777 this->addInt(ClipParams_pack(op, doAA));
778 int offset = this->recordRestoreOffsetPlaceholder(op); 778 int offset = this->recordRestoreOffsetPlaceholder(op);
779 779
780 this->validate(initialOffset, size); 780 this->validate(initialOffset, size);
781 return offset; 781 return offset;
782 } 782 }
783 783
784 bool SkPictureRecord::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA ) { 784 bool SkPictureRecord::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA ) {
785 if (rrect.isRect()) { 785 if (rrect.isRect()) {
786 return this->SkPictureRecord::clipRect(rrect.getBounds(), op, doAA); 786 return this->SkPictureRecord::clipRect(rrect.getBounds(), op, doAA);
787 } 787 }
788 788
789 this->recordClipRRect(rrect, op, doAA); 789 this->recordClipRRect(rrect, op, doAA);
790 if (fRecordFlags & SkPicture::kUsePathBoundsForClip_RecordingFlag) { 790 if (fRecordFlags & SkPicture::kUsePathBoundsForClip_RecordingFlag) {
791 return this->updateClipConservativelyUsingBounds(rrect.getBounds(), op, false); 791 return this->updateClipConservativelyUsingBounds(rrect.getBounds(), op, false);
792 } else { 792 } else {
793 return this->INHERITED::clipRRect(rrect, op, doAA); 793 return this->INHERITED::clipRRect(rrect, op, doAA);
794 } 794 }
795 } 795 }
796 796
797 int SkPictureRecord::recordClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) { 797 int SkPictureRecord::recordClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
798 798
799 // op + rrect + clip params 799 // op + rrect + clip params
800 uint32_t size = 1 * kUInt32Size + SkRRect::kSizeInMemory + 1 * kUInt32Size; 800 uint32_t size = 1 * kUInt32Size + SkRRect::kSizeInMemory + 1 * kUInt32Size;
801 // recordRestoreOffsetPlaceholder doesn't always write an offset 801 // recordRestoreOffsetPlaceholder doesn't always write an offset
802 if (!fRestoreOffsetStack.isEmpty()) { 802 if (!fRestoreOffsetStack.isEmpty()) {
803 // + restore offset 803 // + restore offset
804 size += kUInt32Size; 804 size += kUInt32Size;
805 } 805 }
806 size_t initialOffset = this->addDraw(CLIP_RRECT, &size); 806 size_t initialOffset = this->addDraw(CLIP_RRECT, &size);
807 addRRect(rrect); 807 this->addRRect(rrect);
808 addInt(ClipParams_pack(op, doAA)); 808 this->addInt(ClipParams_pack(op, doAA));
809 int offset = recordRestoreOffsetPlaceholder(op); 809 int offset = recordRestoreOffsetPlaceholder(op);
810 810
811 this->validate(initialOffset, size); 811 this->validate(initialOffset, size);
812 return offset; 812 return offset;
813 } 813 }
814 814
815 bool SkPictureRecord::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { 815 bool SkPictureRecord::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) {
816 816
817 SkRect r; 817 SkRect r;
818 if (!path.isInverseFillType() && path.isRect(&r)) { 818 if (!path.isInverseFillType() && path.isRect(&r)) {
(...skipping 14 matching lines...) Expand all
833 int SkPictureRecord::recordClipPath(int pathID, SkRegion::Op op, bool doAA) { 833 int SkPictureRecord::recordClipPath(int pathID, SkRegion::Op op, bool doAA) {
834 834
835 // op + path index + clip params 835 // op + path index + clip params
836 uint32_t size = 3 * kUInt32Size; 836 uint32_t size = 3 * kUInt32Size;
837 // recordRestoreOffsetPlaceholder doesn't always write an offset 837 // recordRestoreOffsetPlaceholder doesn't always write an offset
838 if (!fRestoreOffsetStack.isEmpty()) { 838 if (!fRestoreOffsetStack.isEmpty()) {
839 // + restore offset 839 // + restore offset
840 size += kUInt32Size; 840 size += kUInt32Size;
841 } 841 }
842 size_t initialOffset = this->addDraw(CLIP_PATH, &size); 842 size_t initialOffset = this->addDraw(CLIP_PATH, &size);
843 addInt(pathID); 843 this->addInt(pathID);
844 addInt(ClipParams_pack(op, doAA)); 844 this->addInt(ClipParams_pack(op, doAA));
845 int offset = recordRestoreOffsetPlaceholder(op); 845 int offset = recordRestoreOffsetPlaceholder(op);
846 846
847 this->validate(initialOffset, size); 847 this->validate(initialOffset, size);
848 return offset; 848 return offset;
849 } 849 }
850 850
851 bool SkPictureRecord::clipRegion(const SkRegion& region, SkRegion::Op op) { 851 bool SkPictureRecord::clipRegion(const SkRegion& region, SkRegion::Op op) {
852 this->recordClipRegion(region, op); 852 this->recordClipRegion(region, op);
853 return this->INHERITED::clipRegion(region, op); 853 return this->INHERITED::clipRegion(region, op);
854 } 854 }
855 855
856 int SkPictureRecord::recordClipRegion(const SkRegion& region, SkRegion::Op op) { 856 int SkPictureRecord::recordClipRegion(const SkRegion& region, SkRegion::Op op) {
857 // op + clip params + region 857 // op + clip params + region
858 uint32_t size = 2 * kUInt32Size + region.writeToMemory(NULL); 858 uint32_t size = 2 * kUInt32Size + region.writeToMemory(NULL);
859 // recordRestoreOffsetPlaceholder doesn't always write an offset 859 // recordRestoreOffsetPlaceholder doesn't always write an offset
860 if (!fRestoreOffsetStack.isEmpty()) { 860 if (!fRestoreOffsetStack.isEmpty()) {
861 // + restore offset 861 // + restore offset
862 size += kUInt32Size; 862 size += kUInt32Size;
863 } 863 }
864 size_t initialOffset = this->addDraw(CLIP_REGION, &size); 864 size_t initialOffset = this->addDraw(CLIP_REGION, &size);
865 addRegion(region); 865 this->addRegion(region);
866 addInt(ClipParams_pack(op, false)); 866 this->addInt(ClipParams_pack(op, false));
867 int offset = recordRestoreOffsetPlaceholder(op); 867 int offset = this->recordRestoreOffsetPlaceholder(op);
868 868
869 this->validate(initialOffset, size); 869 this->validate(initialOffset, size);
870 return offset; 870 return offset;
871 } 871 }
872 872
873 void SkPictureRecord::clear(SkColor color) { 873 void SkPictureRecord::clear(SkColor color) {
874 // op + color 874 // op + color
875 uint32_t size = 2 * kUInt32Size; 875 uint32_t size = 2 * kUInt32Size;
876 size_t initialOffset = this->addDraw(DRAW_CLEAR, &size); 876 size_t initialOffset = this->addDraw(DRAW_CLEAR, &size);
877 addInt(color); 877 this->addInt(color);
878 this->validate(initialOffset, size); 878 this->validate(initialOffset, size);
879 } 879 }
880 880
881 void SkPictureRecord::drawPaint(const SkPaint& paint) { 881 void SkPictureRecord::drawPaint(const SkPaint& paint) {
882 // op + paint index 882 // op + paint index
883 uint32_t size = 2 * kUInt32Size; 883 uint32_t size = 2 * kUInt32Size;
884 size_t initialOffset = this->addDraw(DRAW_PAINT, &size); 884 size_t initialOffset = this->addDraw(DRAW_PAINT, &size);
885 SkASSERT(initialOffset+getPaintOffset(DRAW_PAINT, size) == fWriter.bytesWrit ten()); 885 SkASSERT(initialOffset+getPaintOffset(DRAW_PAINT, size) == fWriter.bytesWrit ten());
886 addPaint(paint); 886 this->addPaint(paint);
887 this->validate(initialOffset, size); 887 this->validate(initialOffset, size);
888 } 888 }
889 889
890 void SkPictureRecord::drawPoints(PointMode mode, size_t count, const SkPoint pts [], 890 void SkPictureRecord::drawPoints(PointMode mode, size_t count, const SkPoint pts [],
891 const SkPaint& paint) { 891 const SkPaint& paint) {
892 // op + paint index + mode + count + point data 892 // op + paint index + mode + count + point data
893 uint32_t size = 4 * kUInt32Size + count * sizeof(SkPoint); 893 uint32_t size = 4 * kUInt32Size + count * sizeof(SkPoint);
894 size_t initialOffset = this->addDraw(DRAW_POINTS, &size); 894 size_t initialOffset = this->addDraw(DRAW_POINTS, &size);
895 SkASSERT(initialOffset+getPaintOffset(DRAW_POINTS, size) == fWriter.bytesWri tten()); 895 SkASSERT(initialOffset+getPaintOffset(DRAW_POINTS, size) == fWriter.bytesWri tten());
896 addPaint(paint); 896 this->addPaint(paint);
897 addInt(mode); 897 this->addInt(mode);
898 addInt(count); 898 this->addInt(count);
899 fWriter.writeMul4(pts, count * sizeof(SkPoint)); 899 fWriter.writeMul4(pts, count * sizeof(SkPoint));
900 this->validate(initialOffset, size); 900 this->validate(initialOffset, size);
901 } 901 }
902 902
903 void SkPictureRecord::drawOval(const SkRect& oval, const SkPaint& paint) { 903 void SkPictureRecord::drawOval(const SkRect& oval, const SkPaint& paint) {
904 // op + paint index + rect 904 // op + paint index + rect
905 uint32_t size = 2 * kUInt32Size + sizeof(oval); 905 uint32_t size = 2 * kUInt32Size + sizeof(oval);
906 size_t initialOffset = this->addDraw(DRAW_OVAL, &size); 906 size_t initialOffset = this->addDraw(DRAW_OVAL, &size);
907 SkASSERT(initialOffset+getPaintOffset(DRAW_OVAL, size) == fWriter.bytesWritt en()); 907 SkASSERT(initialOffset+getPaintOffset(DRAW_OVAL, size) == fWriter.bytesWritt en());
908 addPaint(paint); 908 this->addPaint(paint);
909 addRect(oval); 909 this->addRect(oval);
910 this->validate(initialOffset, size); 910 this->validate(initialOffset, size);
911 } 911 }
912 912
913 void SkPictureRecord::drawRect(const SkRect& rect, const SkPaint& paint) { 913 void SkPictureRecord::drawRect(const SkRect& rect, const SkPaint& paint) {
914 // op + paint index + rect 914 // op + paint index + rect
915 uint32_t size = 2 * kUInt32Size + sizeof(rect); 915 uint32_t size = 2 * kUInt32Size + sizeof(rect);
916 size_t initialOffset = this->addDraw(DRAW_RECT, &size); 916 size_t initialOffset = this->addDraw(DRAW_RECT, &size);
917 SkASSERT(initialOffset+getPaintOffset(DRAW_RECT, size) == fWriter.bytesWritt en()); 917 SkASSERT(initialOffset+getPaintOffset(DRAW_RECT, size) == fWriter.bytesWritt en());
918 addPaint(paint); 918 this->addPaint(paint);
919 addRect(rect); 919 this->addRect(rect);
920 this->validate(initialOffset, size); 920 this->validate(initialOffset, size);
921 } 921 }
922 922
923 void SkPictureRecord::drawRRect(const SkRRect& rrect, const SkPaint& paint) { 923 void SkPictureRecord::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
924 if (rrect.isRect()) { 924 if (rrect.isRect()) {
925 this->SkPictureRecord::drawRect(rrect.getBounds(), paint); 925 this->SkPictureRecord::drawRect(rrect.getBounds(), paint);
926 } else if (rrect.isOval()) { 926 } else if (rrect.isOval()) {
927 this->SkPictureRecord::drawOval(rrect.getBounds(), paint); 927 this->SkPictureRecord::drawOval(rrect.getBounds(), paint);
928 } else { 928 } else {
929 // op + paint index + rrect 929 // op + paint index + rrect
930 uint32_t initialOffset, size; 930 uint32_t initialOffset, size;
931 size = 2 * kUInt32Size + SkRRect::kSizeInMemory; 931 size = 2 * kUInt32Size + SkRRect::kSizeInMemory;
932 initialOffset = this->addDraw(DRAW_RRECT, &size); 932 initialOffset = this->addDraw(DRAW_RRECT, &size);
933 SkASSERT(initialOffset+getPaintOffset(DRAW_RRECT, size) == fWriter.bytes Written()); 933 SkASSERT(initialOffset+getPaintOffset(DRAW_RRECT, size) == fWriter.bytes Written());
934 addPaint(paint); 934 this->addPaint(paint);
935 addRRect(rrect); 935 this->addRRect(rrect);
936 this->validate(initialOffset, size); 936 this->validate(initialOffset, size);
937 } 937 }
938 } 938 }
939 939
940 void SkPictureRecord::drawPath(const SkPath& path, const SkPaint& paint) { 940 void SkPictureRecord::drawPath(const SkPath& path, const SkPaint& paint) {
941 // op + paint index + path index 941 // op + paint index + path index
942 uint32_t size = 3 * kUInt32Size; 942 uint32_t size = 3 * kUInt32Size;
943 size_t initialOffset = this->addDraw(DRAW_PATH, &size); 943 size_t initialOffset = this->addDraw(DRAW_PATH, &size);
944 SkASSERT(initialOffset+getPaintOffset(DRAW_PATH, size) == fWriter.bytesWritt en()); 944 SkASSERT(initialOffset+getPaintOffset(DRAW_PATH, size) == fWriter.bytesWritt en());
945 addPaint(paint); 945 this->addPaint(paint);
946 addPath(path); 946 this->addPath(path);
947 this->validate(initialOffset, size); 947 this->validate(initialOffset, size);
948 } 948 }
949 949
950 void SkPictureRecord::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, 950 void SkPictureRecord::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
951 const SkPaint* paint = NULL) { 951 const SkPaint* paint = NULL) {
952 // op + paint index + bitmap index + left + top 952 // op + paint index + bitmap index + left + top
953 uint32_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar); 953 uint32_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar);
954 size_t initialOffset = this->addDraw(DRAW_BITMAP, &size); 954 size_t initialOffset = this->addDraw(DRAW_BITMAP, &size);
955 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP, size) == fWriter.bytesWri tten()); 955 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP, size) == fWriter.bytesWri tten());
956 addPaintPtr(paint); 956 this->addPaintPtr(paint);
957 addBitmap(bitmap); 957 this->addBitmap(bitmap);
958 addScalar(left); 958 this->addScalar(left);
959 addScalar(top); 959 this->addScalar(top);
960 this->validate(initialOffset, size); 960 this->validate(initialOffset, size);
961 } 961 }
962 962
963 void SkPictureRecord::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, 963 void SkPictureRecord::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src,
964 const SkRect& dst, const SkPaint* pai nt, 964 const SkRect& dst, const SkPaint* pai nt,
965 DrawBitmapRectFlags flags) { 965 DrawBitmapRectFlags flags) {
966 // id + paint index + bitmap index + bool for 'src' + flags 966 // id + paint index + bitmap index + bool for 'src' + flags
967 uint32_t size = 5 * kUInt32Size; 967 uint32_t size = 5 * kUInt32Size;
968 if (NULL != src) { 968 if (NULL != src) {
969 size += sizeof(*src); // + rect 969 size += sizeof(*src); // + rect
970 } 970 }
971 size += sizeof(dst); // + rect 971 size += sizeof(dst); // + rect
972 972
973 size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT_TO_RECT, &size); 973 size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT_TO_RECT, &size);
974 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_RECT_TO_RECT, size) == fWr iter.bytesWritten()); 974 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_RECT_TO_RECT, size) == fWr iter.bytesWritten());
975 addPaintPtr(paint); 975 this->addPaintPtr(paint);
976 addBitmap(bitmap); 976 this->addBitmap(bitmap);
977 addRectPtr(src); // may be null 977 this->addRectPtr(src); // may be null
978 addRect(dst); 978 this->addRect(dst);
979 addInt(flags); 979 this->addInt(flags);
980 this->validate(initialOffset, size); 980 this->validate(initialOffset, size);
981 } 981 }
982 982
983 void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m atrix, 983 void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m atrix,
984 const SkPaint* paint) { 984 const SkPaint* paint) {
985 // id + paint index + bitmap index + matrix 985 // id + paint index + bitmap index + matrix
986 uint32_t size = 3 * kUInt32Size + matrix.writeToMemory(NULL); 986 uint32_t size = 3 * kUInt32Size + matrix.writeToMemory(NULL);
987 size_t initialOffset = this->addDraw(DRAW_BITMAP_MATRIX, &size); 987 size_t initialOffset = this->addDraw(DRAW_BITMAP_MATRIX, &size);
988 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_MATRIX, size) == fWriter.b ytesWritten()); 988 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_MATRIX, size) == fWriter.b ytesWritten());
989 addPaintPtr(paint); 989 this->addPaintPtr(paint);
990 addBitmap(bitmap); 990 this->addBitmap(bitmap);
991 addMatrix(matrix); 991 this->addMatrix(matrix);
992 this->validate(initialOffset, size); 992 this->validate(initialOffset, size);
993 } 993 }
994 994
995 void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& cent er, 995 void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& cent er,
996 const SkRect& dst, const SkPaint* paint) { 996 const SkRect& dst, const SkPaint* paint) {
997 // op + paint index + bitmap id + center + dst rect 997 // op + paint index + bitmap id + center + dst rect
998 uint32_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst); 998 uint32_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst);
999 size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size); 999 size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size);
1000 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_NINE, size) == fWriter.byt esWritten()); 1000 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_NINE, size) == fWriter.byt esWritten());
1001 addPaintPtr(paint); 1001 this->addPaintPtr(paint);
1002 addBitmap(bitmap); 1002 this->addBitmap(bitmap);
1003 addIRect(center); 1003 this->addIRect(center);
1004 addRect(dst); 1004 this->addRect(dst);
1005 this->validate(initialOffset, size); 1005 this->validate(initialOffset, size);
1006 } 1006 }
1007 1007
1008 void SkPictureRecord::drawSprite(const SkBitmap& bitmap, int left, int top, 1008 void SkPictureRecord::drawSprite(const SkBitmap& bitmap, int left, int top,
1009 const SkPaint* paint = NULL) { 1009 const SkPaint* paint = NULL) {
1010 // op + paint index + bitmap index + left + top 1010 // op + paint index + bitmap index + left + top
1011 uint32_t size = 5 * kUInt32Size; 1011 uint32_t size = 5 * kUInt32Size;
1012 size_t initialOffset = this->addDraw(DRAW_SPRITE, &size); 1012 size_t initialOffset = this->addDraw(DRAW_SPRITE, &size);
1013 SkASSERT(initialOffset+getPaintOffset(DRAW_SPRITE, size) == fWriter.bytesWri tten()); 1013 SkASSERT(initialOffset+getPaintOffset(DRAW_SPRITE, size) == fWriter.bytesWri tten());
1014 addPaintPtr(paint); 1014 this->addPaintPtr(paint);
1015 addBitmap(bitmap); 1015 this->addBitmap(bitmap);
1016 addInt(left); 1016 this->addInt(left);
1017 addInt(top); 1017 this->addInt(top);
1018 this->validate(initialOffset, size); 1018 this->validate(initialOffset, size);
1019 } 1019 }
1020 1020
1021 void SkPictureRecord::ComputeFontMetricsTopBottom(const SkPaint& paint, SkScalar topbot[2]) { 1021 void SkPictureRecord::ComputeFontMetricsTopBottom(const SkPaint& paint, SkScalar topbot[2]) {
1022 SkPaint::FontMetrics metrics; 1022 SkPaint::FontMetrics metrics;
1023 paint.getFontMetrics(&metrics); 1023 paint.getFontMetrics(&metrics);
1024 SkRect bounds; 1024 SkRect bounds;
1025 // construct a rect so we can see any adjustments from the paint. 1025 // construct a rect so we can see any adjustments from the paint.
1026 // we use 0,1 for left,right, just so the rect isn't empty 1026 // we use 0,1 for left,right, just so the rect isn't empty
1027 bounds.set(0, metrics.fTop, SK_Scalar1, metrics.fBottom); 1027 bounds.set(0, metrics.fTop, SK_Scalar1, metrics.fBottom);
1028 (void)paint.computeFastBounds(bounds, &bounds); 1028 (void)paint.computeFastBounds(bounds, &bounds);
1029 topbot[0] = bounds.fTop; 1029 topbot[0] = bounds.fTop;
1030 topbot[1] = bounds.fBottom; 1030 topbot[1] = bounds.fBottom;
1031 } 1031 }
1032 1032
1033 void SkPictureRecord::addFontMetricsTopBottom(const SkPaint& paint, const SkFlat Data& flat, 1033 void SkPictureRecord::addFontMetricsTopBottom(const SkPaint& paint, const SkFlat Data& flat,
1034 SkScalar minY, SkScalar maxY) { 1034 SkScalar minY, SkScalar maxY) {
1035 WriteTopBot(paint, flat); 1035 WriteTopBot(paint, flat);
1036 addScalar(flat.topBot()[0] + minY); 1036 this->addScalar(flat.topBot()[0] + minY);
1037 addScalar(flat.topBot()[1] + maxY); 1037 this->addScalar(flat.topBot()[1] + maxY);
1038 } 1038 }
1039 1039
1040 void SkPictureRecord::drawText(const void* text, size_t byteLength, SkScalar x, 1040 void SkPictureRecord::drawText(const void* text, size_t byteLength, SkScalar x,
1041 SkScalar y, const SkPaint& paint) { 1041 SkScalar y, const SkPaint& paint) {
1042 bool fast = !paint.isVerticalText() && paint.canComputeFastBounds(); 1042 bool fast = !paint.isVerticalText() && paint.canComputeFastBounds();
1043 1043
1044 // op + paint index + length + 'length' worth of chars + x + y 1044 // op + paint index + length + 'length' worth of chars + x + y
1045 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 2 * sizeof(SkScalar ); 1045 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 2 * sizeof(SkScalar );
1046 if (fast) { 1046 if (fast) {
1047 size += 2 * sizeof(SkScalar); // + top & bottom 1047 size += 2 * sizeof(SkScalar); // + top & bottom
1048 } 1048 }
1049 1049
1050 DrawType op = fast ? DRAW_TEXT_TOP_BOTTOM : DRAW_TEXT; 1050 DrawType op = fast ? DRAW_TEXT_TOP_BOTTOM : DRAW_TEXT;
1051 size_t initialOffset = this->addDraw(op, &size); 1051 size_t initialOffset = this->addDraw(op, &size);
1052 SkASSERT(initialOffset+getPaintOffset(op, size) == fWriter.bytesWritten()); 1052 SkASSERT(initialOffset+getPaintOffset(op, size) == fWriter.bytesWritten());
1053 const SkFlatData* flatPaintData = addPaint(paint); 1053 const SkFlatData* flatPaintData = addPaint(paint);
1054 SkASSERT(flatPaintData); 1054 SkASSERT(flatPaintData);
1055 addText(text, byteLength); 1055 this->addText(text, byteLength);
1056 addScalar(x); 1056 this->addScalar(x);
1057 addScalar(y); 1057 this->addScalar(y);
1058 if (fast) { 1058 if (fast) {
1059 addFontMetricsTopBottom(paint, *flatPaintData, y, y); 1059 this->addFontMetricsTopBottom(paint, *flatPaintData, y, y);
1060 } 1060 }
1061 this->validate(initialOffset, size); 1061 this->validate(initialOffset, size);
1062 } 1062 }
1063 1063
1064 void SkPictureRecord::drawPosText(const void* text, size_t byteLength, 1064 void SkPictureRecord::drawPosText(const void* text, size_t byteLength,
1065 const SkPoint pos[], const SkPaint& paint) { 1065 const SkPoint pos[], const SkPaint& paint) {
1066 size_t points = paint.countText(text, byteLength); 1066 size_t points = paint.countText(text, byteLength);
1067 if (0 == points) 1067 if (0 == points)
1068 return; 1068 return;
1069 1069
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 op = DRAW_POS_TEXT_H_TOP_BOTTOM; 1109 op = DRAW_POS_TEXT_H_TOP_BOTTOM;
1110 } else if (canUseDrawH) { 1110 } else if (canUseDrawH) {
1111 op = DRAW_POS_TEXT_H; 1111 op = DRAW_POS_TEXT_H;
1112 } else if (fastBounds) { 1112 } else if (fastBounds) {
1113 op = DRAW_POS_TEXT_TOP_BOTTOM; 1113 op = DRAW_POS_TEXT_TOP_BOTTOM;
1114 } else { 1114 } else {
1115 op = DRAW_POS_TEXT; 1115 op = DRAW_POS_TEXT;
1116 } 1116 }
1117 size_t initialOffset = this->addDraw(op, &size); 1117 size_t initialOffset = this->addDraw(op, &size);
1118 SkASSERT(initialOffset+getPaintOffset(op, size) == fWriter.bytesWritten()); 1118 SkASSERT(initialOffset+getPaintOffset(op, size) == fWriter.bytesWritten());
1119 const SkFlatData* flatPaintData = addPaint(paint); 1119 const SkFlatData* flatPaintData = this->addPaint(paint);
1120 SkASSERT(flatPaintData); 1120 SkASSERT(flatPaintData);
1121 addText(text, byteLength); 1121 this->addText(text, byteLength);
1122 addInt(points); 1122 this->addInt(points);
1123 1123
1124 #ifdef SK_DEBUG_SIZE 1124 #ifdef SK_DEBUG_SIZE
1125 size_t start = fWriter.bytesWritten(); 1125 size_t start = fWriter.bytesWritten();
1126 #endif 1126 #endif
1127 if (canUseDrawH) { 1127 if (canUseDrawH) {
1128 if (fast) { 1128 if (fast) {
1129 addFontMetricsTopBottom(paint, *flatPaintData, pos[0].fY, pos[0].fY) ; 1129 this->addFontMetricsTopBottom(paint, *flatPaintData, pos[0].fY, pos[ 0].fY);
1130 } 1130 }
1131 addScalar(pos[0].fY); 1131 this->addScalar(pos[0].fY);
1132 SkScalar* xptr = (SkScalar*)fWriter.reserve(points * sizeof(SkScalar)); 1132 SkScalar* xptr = (SkScalar*)fWriter.reserve(points * sizeof(SkScalar));
1133 for (size_t index = 0; index < points; index++) 1133 for (size_t index = 0; index < points; index++)
1134 *xptr++ = pos[index].fX; 1134 *xptr++ = pos[index].fX;
1135 } else { 1135 } else {
1136 fWriter.writeMul4(pos, points * sizeof(SkPoint)); 1136 fWriter.writeMul4(pos, points * sizeof(SkPoint));
1137 if (fastBounds) { 1137 if (fastBounds) {
1138 addFontMetricsTopBottom(paint, *flatPaintData, minY, maxY); 1138 this->addFontMetricsTopBottom(paint, *flatPaintData, minY, maxY);
1139 } 1139 }
1140 } 1140 }
1141 #ifdef SK_DEBUG_SIZE 1141 #ifdef SK_DEBUG_SIZE
1142 fPointBytes += fWriter.bytesWritten() - start; 1142 fPointBytes += fWriter.bytesWritten() - start;
1143 fPointWrites += points; 1143 fPointWrites += points;
1144 #endif 1144 #endif
1145 this->validate(initialOffset, size); 1145 this->validate(initialOffset, size);
1146 } 1146 }
1147 1147
1148 void SkPictureRecord::drawPosTextH(const void* text, size_t byteLength, 1148 void SkPictureRecord::drawPosTextH(const void* text, size_t byteLength,
1149 const SkScalar xpos[], SkScalar constY, 1149 const SkScalar xpos[], SkScalar constY,
1150 const SkPaint& paint) { 1150 const SkPaint& paint) {
1151 1151
1152 const SkFlatData* flatPaintData = this->getFlatPaintData(paint); 1152 const SkFlatData* flatPaintData = this->getFlatPaintData(paint);
1153 drawPosTextHImpl(text, byteLength, xpos, constY, paint, flatPaintData); 1153 this->drawPosTextHImpl(text, byteLength, xpos, constY, paint, flatPaintData) ;
1154 } 1154 }
1155 1155
1156 void SkPictureRecord::drawPosTextHImpl(const void* text, size_t byteLength, 1156 void SkPictureRecord::drawPosTextHImpl(const void* text, size_t byteLength,
1157 const SkScalar xpos[], SkScalar constY, 1157 const SkScalar xpos[], SkScalar constY,
1158 const SkPaint& paint, const SkFlatData* flatPaintData) { 1158 const SkPaint& paint, const SkFlatData* flatPaintData) {
1159 size_t points = paint.countText(text, byteLength); 1159 size_t points = paint.countText(text, byteLength);
1160 if (0 == points) 1160 if (0 == points)
1161 return; 1161 return;
1162 1162
1163 bool fast = !paint.isVerticalText() && paint.canComputeFastBounds(); 1163 bool fast = !paint.isVerticalText() && paint.canComputeFastBounds();
1164 1164
1165 // op + paint index + length + 'length' worth of data + num points 1165 // op + paint index + length + 'length' worth of data + num points
1166 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 1 * kUInt32Size; 1166 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 1 * kUInt32Size;
1167 if (fast) { 1167 if (fast) {
1168 size += 2 * sizeof(SkScalar); // + top & bottom 1168 size += 2 * sizeof(SkScalar); // + top & bottom
1169 } 1169 }
1170 // + y + the actual points 1170 // + y + the actual points
1171 size += 1 * kUInt32Size + points * sizeof(SkScalar); 1171 size += 1 * kUInt32Size + points * sizeof(SkScalar);
1172 size_t initialOffset = this->addDraw(fast ? DRAW_POS_TEXT_H_TOP_BOTTOM : DRA W_POS_TEXT_H, 1172 size_t initialOffset = this->addDraw(fast ? DRAW_POS_TEXT_H_TOP_BOTTOM : DRA W_POS_TEXT_H,
1173 &size); 1173 &size);
1174 SkASSERT(flatPaintData); 1174 SkASSERT(flatPaintData);
1175 addFlatPaint(flatPaintData); 1175 this->addFlatPaint(flatPaintData);
1176 1176
1177 addText(text, byteLength); 1177 this->addText(text, byteLength);
1178 addInt(points); 1178 this->addInt(points);
1179 1179
1180 #ifdef SK_DEBUG_SIZE 1180 #ifdef SK_DEBUG_SIZE
1181 size_t start = fWriter.bytesWritten(); 1181 size_t start = fWriter.bytesWritten();
1182 #endif 1182 #endif
1183 if (fast) { 1183 if (fast) {
1184 addFontMetricsTopBottom(paint, *flatPaintData, constY, constY); 1184 this->addFontMetricsTopBottom(paint, *flatPaintData, constY, constY);
1185 } 1185 }
1186 addScalar(constY); 1186 this->addScalar(constY);
1187 fWriter.writeMul4(xpos, points * sizeof(SkScalar)); 1187 fWriter.writeMul4(xpos, points * sizeof(SkScalar));
1188 #ifdef SK_DEBUG_SIZE 1188 #ifdef SK_DEBUG_SIZE
1189 fPointBytes += fWriter.bytesWritten() - start; 1189 fPointBytes += fWriter.bytesWritten() - start;
1190 fPointWrites += points; 1190 fPointWrites += points;
1191 #endif 1191 #endif
1192 this->validate(initialOffset, size); 1192 this->validate(initialOffset, size);
1193 } 1193 }
1194 1194
1195 void SkPictureRecord::drawTextOnPath(const void* text, size_t byteLength, 1195 void SkPictureRecord::drawTextOnPath(const void* text, size_t byteLength,
1196 const SkPath& path, const SkMatrix* matrix, 1196 const SkPath& path, const SkMatrix* matrix,
1197 const SkPaint& paint) { 1197 const SkPaint& paint) {
1198 // op + paint index + length + 'length' worth of data + path index + matrix 1198 // op + paint index + length + 'length' worth of data + path index + matrix
1199 const SkMatrix& m = matrix ? *matrix : SkMatrix::I(); 1199 const SkMatrix& m = matrix ? *matrix : SkMatrix::I();
1200 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + m.wri teToMemory(NULL); 1200 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + m.wri teToMemory(NULL);
1201 size_t initialOffset = this->addDraw(DRAW_TEXT_ON_PATH, &size); 1201 size_t initialOffset = this->addDraw(DRAW_TEXT_ON_PATH, &size);
1202 SkASSERT(initialOffset+getPaintOffset(DRAW_TEXT_ON_PATH, size) == fWriter.by tesWritten()); 1202 SkASSERT(initialOffset+getPaintOffset(DRAW_TEXT_ON_PATH, size) == fWriter.by tesWritten());
1203 addPaint(paint); 1203 this->addPaint(paint);
1204 addText(text, byteLength); 1204 this->addText(text, byteLength);
1205 addPath(path); 1205 this->addPath(path);
1206 addMatrix(m); 1206 this->addMatrix(m);
1207 this->validate(initialOffset, size); 1207 this->validate(initialOffset, size);
1208 } 1208 }
1209 1209
1210 void SkPictureRecord::drawPicture(SkPicture& picture) { 1210 void SkPictureRecord::drawPicture(SkPicture& picture) {
1211 // op + picture index 1211 // op + picture index
1212 uint32_t size = 2 * kUInt32Size; 1212 uint32_t size = 2 * kUInt32Size;
1213 size_t initialOffset = this->addDraw(DRAW_PICTURE, &size); 1213 size_t initialOffset = this->addDraw(DRAW_PICTURE, &size);
1214 addPicture(picture); 1214 this->addPicture(picture);
1215 this->validate(initialOffset, size); 1215 this->validate(initialOffset, size);
1216 } 1216 }
1217 1217
1218 void SkPictureRecord::drawVertices(VertexMode vmode, int vertexCount, 1218 void SkPictureRecord::drawVertices(VertexMode vmode, int vertexCount,
1219 const SkPoint vertices[], const SkPoint texs[], 1219 const SkPoint vertices[], const SkPoint texs[],
1220 const SkColor colors[], SkXfermode* xfer, 1220 const SkColor colors[], SkXfermode* xfer,
1221 const uint16_t indices[], int indexCount, 1221 const uint16_t indices[], int indexCount,
1222 const SkPaint& paint) { 1222 const SkPaint& paint) {
1223 uint32_t flags = 0; 1223 uint32_t flags = 0;
1224 if (texs) { 1224 if (texs) {
(...skipping 23 matching lines...) Expand all
1248 if (flags & DRAW_VERTICES_HAS_INDICES) { 1248 if (flags & DRAW_VERTICES_HAS_INDICES) {
1249 // + num indices + indices 1249 // + num indices + indices
1250 size += 1 * kUInt32Size + SkAlign4(indexCount * sizeof(uint16_t)); 1250 size += 1 * kUInt32Size + SkAlign4(indexCount * sizeof(uint16_t));
1251 } 1251 }
1252 if (flags & DRAW_VERTICES_HAS_XFER) { 1252 if (flags & DRAW_VERTICES_HAS_XFER) {
1253 size += kUInt32Size; // mode enum 1253 size += kUInt32Size; // mode enum
1254 } 1254 }
1255 1255
1256 size_t initialOffset = this->addDraw(DRAW_VERTICES, &size); 1256 size_t initialOffset = this->addDraw(DRAW_VERTICES, &size);
1257 SkASSERT(initialOffset+getPaintOffset(DRAW_VERTICES, size) == fWriter.bytesW ritten()); 1257 SkASSERT(initialOffset+getPaintOffset(DRAW_VERTICES, size) == fWriter.bytesW ritten());
1258 addPaint(paint); 1258 this->addPaint(paint);
1259 addInt(flags); 1259 this->addInt(flags);
1260 addInt(vmode); 1260 this->addInt(vmode);
1261 addInt(vertexCount); 1261 this->addInt(vertexCount);
1262 addPoints(vertices, vertexCount); 1262 this->addPoints(vertices, vertexCount);
1263 if (flags & DRAW_VERTICES_HAS_TEXS) { 1263 if (flags & DRAW_VERTICES_HAS_TEXS) {
1264 addPoints(texs, vertexCount); 1264 this->addPoints(texs, vertexCount);
1265 } 1265 }
1266 if (flags & DRAW_VERTICES_HAS_COLORS) { 1266 if (flags & DRAW_VERTICES_HAS_COLORS) {
1267 fWriter.writeMul4(colors, vertexCount * sizeof(SkColor)); 1267 fWriter.writeMul4(colors, vertexCount * sizeof(SkColor));
1268 } 1268 }
1269 if (flags & DRAW_VERTICES_HAS_INDICES) { 1269 if (flags & DRAW_VERTICES_HAS_INDICES) {
1270 addInt(indexCount); 1270 this->addInt(indexCount);
1271 fWriter.writePad(indices, indexCount * sizeof(uint16_t)); 1271 fWriter.writePad(indices, indexCount * sizeof(uint16_t));
1272 } 1272 }
1273 if (flags & DRAW_VERTICES_HAS_XFER) { 1273 if (flags & DRAW_VERTICES_HAS_XFER) {
1274 SkXfermode::Mode mode = SkXfermode::kModulate_Mode; 1274 SkXfermode::Mode mode = SkXfermode::kModulate_Mode;
1275 (void)xfer->asMode(&mode); 1275 (void)xfer->asMode(&mode);
1276 addInt(mode); 1276 this->addInt(mode);
1277 } 1277 }
1278 this->validate(initialOffset, size); 1278 this->validate(initialOffset, size);
1279 } 1279 }
1280 1280
1281 void SkPictureRecord::drawData(const void* data, size_t length) { 1281 void SkPictureRecord::drawData(const void* data, size_t length) {
1282 // op + length + 'length' worth of data 1282 // op + length + 'length' worth of data
1283 uint32_t size = 2 * kUInt32Size + SkAlign4(length); 1283 uint32_t size = 2 * kUInt32Size + SkAlign4(length);
1284 size_t initialOffset = this->addDraw(DRAW_DATA, &size); 1284 size_t initialOffset = this->addDraw(DRAW_DATA, &size);
1285 addInt(length); 1285 this->addInt(length);
1286 fWriter.writePad(data, length); 1286 fWriter.writePad(data, length);
1287 this->validate(initialOffset, size); 1287 this->validate(initialOffset, size);
1288 } 1288 }
1289 1289
1290 void SkPictureRecord::beginCommentGroup(const char* description) { 1290 void SkPictureRecord::beginCommentGroup(const char* description) {
1291 // op/size + length of string + \0 terminated chars 1291 // op/size + length of string + \0 terminated chars
1292 int length = strlen(description); 1292 int length = strlen(description);
1293 uint32_t size = 2 * kUInt32Size + SkAlign4(length + 1); 1293 uint32_t size = 2 * kUInt32Size + SkAlign4(length + 1);
1294 size_t initialOffset = this->addDraw(BEGIN_COMMENT_GROUP, &size); 1294 size_t initialOffset = this->addDraw(BEGIN_COMMENT_GROUP, &size);
1295 fWriter.writeString(description, length); 1295 fWriter.writeString(description, length);
(...skipping 19 matching lines...) Expand all
1315 } 1315 }
1316 1316
1317 /////////////////////////////////////////////////////////////////////////////// 1317 ///////////////////////////////////////////////////////////////////////////////
1318 1318
1319 void SkPictureRecord::addBitmap(const SkBitmap& bitmap) { 1319 void SkPictureRecord::addBitmap(const SkBitmap& bitmap) {
1320 const int index = fBitmapHeap->insert(bitmap); 1320 const int index = fBitmapHeap->insert(bitmap);
1321 // In debug builds, a bad return value from insert() will crash, allowing fo r debugging. In 1321 // In debug builds, a bad return value from insert() will crash, allowing fo r debugging. In
1322 // release builds, the invalid value will be recorded so that the reader wil l know that there 1322 // release builds, the invalid value will be recorded so that the reader wil l know that there
1323 // was a problem. 1323 // was a problem.
1324 SkASSERT(index != SkBitmapHeap::INVALID_SLOT); 1324 SkASSERT(index != SkBitmapHeap::INVALID_SLOT);
1325 addInt(index); 1325 this->addInt(index);
1326 } 1326 }
1327 1327
1328 void SkPictureRecord::addMatrix(const SkMatrix& matrix) { 1328 void SkPictureRecord::addMatrix(const SkMatrix& matrix) {
1329 fWriter.writeMatrix(matrix); 1329 fWriter.writeMatrix(matrix);
1330 } 1330 }
1331 1331
1332 const SkFlatData* SkPictureRecord::getFlatPaintData(const SkPaint& paint) { 1332 const SkFlatData* SkPictureRecord::getFlatPaintData(const SkPaint& paint) {
1333 return fPaints.findAndReturnFlat(paint); 1333 return fPaints.findAndReturnFlat(paint);
1334 } 1334 }
1335 1335
1336 const SkFlatData* SkPictureRecord::addPaintPtr(const SkPaint* paint) { 1336 const SkFlatData* SkPictureRecord::addPaintPtr(const SkPaint* paint) {
1337 const SkFlatData* data = paint ? getFlatPaintData(*paint) : NULL; 1337 const SkFlatData* data = paint ? getFlatPaintData(*paint) : NULL;
1338 this->addFlatPaint(data); 1338 this->addFlatPaint(data);
1339 return data; 1339 return data;
1340 } 1340 }
1341 1341
1342 void SkPictureRecord::addFlatPaint(const SkFlatData* flatPaint) { 1342 void SkPictureRecord::addFlatPaint(const SkFlatData* flatPaint) {
1343 int index = flatPaint ? flatPaint->index() : 0; 1343 int index = flatPaint ? flatPaint->index() : 0;
1344 this->addInt(index); 1344 this->addInt(index);
1345 } 1345 }
1346 1346
1347 int SkPictureRecord::addPathToHeap(const SkPath& path) { 1347 int SkPictureRecord::addPathToHeap(const SkPath& path) {
1348 if (NULL == fPathHeap) { 1348 if (NULL == fPathHeap) {
1349 fPathHeap = SkNEW(SkPathHeap); 1349 fPathHeap = SkNEW(SkPathHeap);
1350 } 1350 }
1351 return fPathHeap->append(path); 1351 return fPathHeap->append(path);
1352 } 1352 }
1353 1353
1354 void SkPictureRecord::addPath(const SkPath& path) { 1354 void SkPictureRecord::addPath(const SkPath& path) {
1355 addInt(this->addPathToHeap(path)); 1355 this->addInt(this->addPathToHeap(path));
1356 } 1356 }
1357 1357
1358 void SkPictureRecord::addPicture(SkPicture& picture) { 1358 void SkPictureRecord::addPicture(SkPicture& picture) {
1359 int index = fPictureRefs.find(&picture); 1359 int index = fPictureRefs.find(&picture);
1360 if (index < 0) { // not found 1360 if (index < 0) { // not found
1361 index = fPictureRefs.count(); 1361 index = fPictureRefs.count();
1362 *fPictureRefs.append() = &picture; 1362 *fPictureRefs.append() = &picture;
1363 picture.ref(); 1363 picture.ref();
1364 } 1364 }
1365 // follow the convention of recording a 1-based index 1365 // follow the convention of recording a 1-based index
1366 addInt(index + 1); 1366 this->addInt(index + 1);
1367 } 1367 }
1368 1368
1369 void SkPictureRecord::addPoint(const SkPoint& point) { 1369 void SkPictureRecord::addPoint(const SkPoint& point) {
1370 #ifdef SK_DEBUG_SIZE 1370 #ifdef SK_DEBUG_SIZE
1371 size_t start = fWriter.bytesWritten(); 1371 size_t start = fWriter.bytesWritten();
1372 #endif 1372 #endif
1373 fWriter.writePoint(point); 1373 fWriter.writePoint(point);
1374 #ifdef SK_DEBUG_SIZE 1374 #ifdef SK_DEBUG_SIZE
1375 fPointBytes += fWriter.bytesWritten() - start; 1375 fPointBytes += fWriter.bytesWritten() - start;
1376 fPointWrites++; 1376 fPointWrites++;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1558 void SkPictureRecord::validateRegions() const { 1558 void SkPictureRecord::validateRegions() const {
1559 int count = fRegions.count(); 1559 int count = fRegions.count();
1560 SkASSERT((unsigned) count < 0x1000); 1560 SkASSERT((unsigned) count < 0x1000);
1561 for (int index = 0; index < count; index++) { 1561 for (int index = 0; index < count; index++) {
1562 const SkFlatData* region = fRegions[index]; 1562 const SkFlatData* region = fRegions[index];
1563 SkASSERT(region); 1563 SkASSERT(region);
1564 // region->validate(); 1564 // region->validate();
1565 } 1565 }
1566 } 1566 }
1567 #endif 1567 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698