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

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

Issue 244273002: fix size_t/int warnings in pictures (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 8 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 | « src/core/SkPictureRecord.h ('k') | 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 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 "SkPictureRecord.h" 8 #include "SkPictureRecord.h"
9 #include "SkTSearch.h" 9 #include "SkTSearch.h"
10 #include "SkPixelRef.h" 10 #include "SkPixelRef.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 SkSafeUnref(fStateTree); 62 SkSafeUnref(fStateTree);
63 fFlattenableHeap.setBitmapStorage(NULL); 63 fFlattenableHeap.setBitmapStorage(NULL);
64 fPictureRefs.unrefAll(); 64 fPictureRefs.unrefAll();
65 } 65 }
66 66
67 /////////////////////////////////////////////////////////////////////////////// 67 ///////////////////////////////////////////////////////////////////////////////
68 68
69 // Return the offset of the paint inside a given op's byte stream. A zero 69 // Return the offset of the paint inside a given op's byte stream. A zero
70 // return value means there is no paint (and you really shouldn't be calling 70 // return value means there is no paint (and you really shouldn't be calling
71 // this method) 71 // this method)
72 static inline uint32_t getPaintOffset(DrawType op, uint32_t opSize) { 72 static inline size_t getPaintOffset(DrawType op, size_t opSize) {
73 // These offsets are where the paint would be if the op size doesn't overflo w 73 // These offsets are where the paint would be if the op size doesn't overflo w
74 static const uint8_t gPaintOffsets[LAST_DRAWTYPE_ENUM + 1] = { 74 static const uint8_t gPaintOffsets[LAST_DRAWTYPE_ENUM + 1] = {
75 0, // UNUSED - no paint 75 0, // UNUSED - no paint
76 0, // CLIP_PATH - no paint 76 0, // CLIP_PATH - no paint
77 0, // CLIP_REGION - no paint 77 0, // CLIP_REGION - no paint
78 0, // CLIP_RECT - no paint 78 0, // CLIP_RECT - no paint
79 0, // CLIP_RRECT - no paint 79 0, // CLIP_RRECT - no paint
80 0, // CONCAT - no paint 80 0, // CONCAT - no paint
81 1, // DRAW_BITMAP - right after op code 81 1, // DRAW_BITMAP - right after op code
82 1, // DRAW_BITMAP_MATRIX - right after op code 82 1, // DRAW_BITMAP_MATRIX - right after op code
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 // from a clip entry. 153 // from a clip entry.
154 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); 154 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten());
155 this->recordSave(flags); 155 this->recordSave(flags);
156 #endif 156 #endif
157 157
158 this->INHERITED::willSave(flags); 158 this->INHERITED::willSave(flags);
159 } 159 }
160 160
161 void SkPictureRecord::recordSave(SaveFlags flags) { 161 void SkPictureRecord::recordSave(SaveFlags flags) {
162 // op + flags 162 // op + flags
163 uint32_t size = kSaveSize; 163 size_t size = kSaveSize;
164 size_t initialOffset = this->addDraw(SAVE, &size); 164 size_t initialOffset = this->addDraw(SAVE, &size);
165 this->addInt(flags); 165 this->addInt(flags);
166 166
167 this->validate(initialOffset, size); 167 this->validate(initialOffset, size);
168 } 168 }
169 169
170 SkCanvas::SaveLayerStrategy SkPictureRecord::willSaveLayer(const SkRect* bounds, 170 SkCanvas::SaveLayerStrategy SkPictureRecord::willSaveLayer(const SkRect* bounds,
171 const SkPaint* paint, SaveFlags flags) { 171 const SkPaint* paint, SaveFlags flags) {
172 172
173 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 173 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
(...skipping 13 matching lines...) Expand all
187 at this time (and may not be able to afford since during record our 187 at this time (and may not be able to afford since during record our
188 clip starts out the size of the picture, which is often much larger 188 clip starts out the size of the picture, which is often much larger
189 than the size of the actual device we'll use during playback). 189 than the size of the actual device we'll use during playback).
190 */ 190 */
191 return kNoLayer_SaveLayerStrategy; 191 return kNoLayer_SaveLayerStrategy;
192 } 192 }
193 193
194 void SkPictureRecord::recordSaveLayer(const SkRect* bounds, const SkPaint* paint , 194 void SkPictureRecord::recordSaveLayer(const SkRect* bounds, const SkPaint* paint ,
195 SaveFlags flags) { 195 SaveFlags flags) {
196 // op + bool for 'bounds' 196 // op + bool for 'bounds'
197 uint32_t size = 2 * kUInt32Size; 197 size_t size = 2 * kUInt32Size;
198 if (NULL != bounds) { 198 if (NULL != bounds) {
199 size += sizeof(*bounds); // + rect 199 size += sizeof(*bounds); // + rect
200 } 200 }
201 // + paint index + flags 201 // + paint index + flags
202 size += 2 * kUInt32Size; 202 size += 2 * kUInt32Size;
203 203
204 SkASSERT(kSaveLayerNoBoundsSize == size || kSaveLayerWithBoundsSize == size) ; 204 SkASSERT(kSaveLayerNoBoundsSize == size || kSaveLayerWithBoundsSize == size) ;
205 205
206 size_t initialOffset = this->addDraw(SAVE_LAYER, &size); 206 size_t initialOffset = this->addDraw(SAVE_LAYER, &size);
207 this->addRectPtr(bounds); 207 this->addRectPtr(bounds);
208 SkASSERT(initialOffset+getPaintOffset(SAVE_LAYER, size) == fWriter.bytesWrit ten()); 208 SkASSERT(initialOffset+getPaintOffset(SAVE_LAYER, size) == fWriter.bytesWrit ten());
209 this->addPaintPtr(paint); 209 this->addPaintPtr(paint);
210 this->addInt(flags); 210 this->addInt(flags);
211 211
212 this->validate(initialOffset, size); 212 this->validate(initialOffset, size);
213 } 213 }
214 214
215 bool SkPictureRecord::isDrawingToLayer() const { 215 bool SkPictureRecord::isDrawingToLayer() const {
216 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 216 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
217 return fMCMgr.isDrawingToLayer(); 217 return fMCMgr.isDrawingToLayer();
218 #else 218 #else
219 return fFirstSavedLayerIndex != kNoSavedLayerIndex; 219 return fFirstSavedLayerIndex != kNoSavedLayerIndex;
220 #endif 220 #endif
221 } 221 }
222 222
223 /* 223 /*
224 * Read the op code from 'offset' in 'writer'. 224 * Read the op code from 'offset' in 'writer'.
225 */ 225 */
226 #ifdef SK_DEBUG 226 #ifdef SK_DEBUG
227 static DrawType peek_op(SkWriter32* writer, int32_t offset) { 227 static DrawType peek_op(SkWriter32* writer, size_t offset) {
228 return (DrawType)(writer->readTAt<uint32_t>(offset) >> 24); 228 return (DrawType)(writer->readTAt<uint32_t>(offset) >> 24);
229 } 229 }
230 #endif 230 #endif
231 231
232 /* 232 /*
233 * Read the op code from 'offset' in 'writer' and extract the size too. 233 * Read the op code from 'offset' in 'writer' and extract the size too.
234 */ 234 */
235 static DrawType peek_op_and_size(SkWriter32* writer, int32_t offset, uint32_t* s ize) { 235 static DrawType peek_op_and_size(SkWriter32* writer, size_t offset, uint32_t* si ze) {
236 uint32_t peek = writer->readTAt<uint32_t>(offset); 236 uint32_t peek = writer->readTAt<uint32_t>(offset);
237 237
238 uint32_t op; 238 uint32_t op;
239 UNPACK_8_24(peek, op, *size); 239 UNPACK_8_24(peek, op, *size);
240 if (MASK_24 == *size) { 240 if (MASK_24 == *size) {
241 // size required its own slot right after the op code 241 // size required its own slot right after the op code
242 *size = writer->readTAt<uint32_t>(offset + kUInt32Size); 242 *size = writer->readTAt<uint32_t>(offset + kUInt32Size);
243 } 243 }
244 return (DrawType) op; 244 return (DrawType) op;
245 } 245 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 static bool merge_savelayer_paint_into_drawbitmp(SkWriter32* writer, 377 static bool merge_savelayer_paint_into_drawbitmp(SkWriter32* writer,
378 SkPaintDictionary* paintDict, 378 SkPaintDictionary* paintDict,
379 const CommandInfo& saveLayerInf o, 379 const CommandInfo& saveLayerInf o,
380 const CommandInfo& dbmInfo) { 380 const CommandInfo& dbmInfo) {
381 SkASSERT(SAVE_LAYER == saveLayerInfo.fActualOp); 381 SkASSERT(SAVE_LAYER == saveLayerInfo.fActualOp);
382 SkASSERT(DRAW_BITMAP == dbmInfo.fActualOp || 382 SkASSERT(DRAW_BITMAP == dbmInfo.fActualOp ||
383 DRAW_BITMAP_MATRIX == dbmInfo.fActualOp || 383 DRAW_BITMAP_MATRIX == dbmInfo.fActualOp ||
384 DRAW_BITMAP_NINE == dbmInfo.fActualOp || 384 DRAW_BITMAP_NINE == dbmInfo.fActualOp ||
385 DRAW_BITMAP_RECT_TO_RECT == dbmInfo.fActualOp); 385 DRAW_BITMAP_RECT_TO_RECT == dbmInfo.fActualOp);
386 386
387 uint32_t dbmPaintOffset = getPaintOffset(dbmInfo.fActualOp, dbmInfo.fSize); 387 size_t dbmPaintOffset = getPaintOffset(dbmInfo.fActualOp, dbmInfo.fSize);
388 uint32_t slPaintOffset = getPaintOffset(SAVE_LAYER, saveLayerInfo.fSize); 388 size_t slPaintOffset = getPaintOffset(SAVE_LAYER, saveLayerInfo.fSize);
389 389
390 // we have a match, now we need to get the paints involved 390 // we have a match, now we need to get the paints involved
391 uint32_t dbmPaintId = writer->readTAt<uint32_t>(dbmInfo.fOffset + dbmPaintOf fset); 391 uint32_t dbmPaintId = writer->readTAt<uint32_t>(dbmInfo.fOffset + dbmPaintOf fset);
392 uint32_t saveLayerPaintId = writer->readTAt<uint32_t>(saveLayerInfo.fOffset + slPaintOffset); 392 uint32_t saveLayerPaintId = writer->readTAt<uint32_t>(saveLayerInfo.fOffset + slPaintOffset);
393 393
394 if (0 == saveLayerPaintId) { 394 if (0 == saveLayerPaintId) {
395 // In this case the saveLayer/restore isn't needed at all - just kill th e saveLayer 395 // In this case the saveLayer/restore isn't needed at all - just kill th e saveLayer
396 // and signal the caller (by returning true) to not add the RESTORE op 396 // and signal the caller (by returning true) to not add the RESTORE op
397 convert_command_to_noop(writer, saveLayerInfo.fOffset); 397 convert_command_to_noop(writer, saveLayerInfo.fOffset);
398 return true; 398 return true;
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 this->recordRestore(); 646 this->recordRestore();
647 } 647 }
648 648
649 fRestoreOffsetStack.pop(); 649 fRestoreOffsetStack.pop();
650 #endif 650 #endif
651 651
652 this->INHERITED::willRestore(); 652 this->INHERITED::willRestore();
653 } 653 }
654 654
655 void SkPictureRecord::recordRestore(bool fillInSkips) { 655 void SkPictureRecord::recordRestore(bool fillInSkips) {
656 uint32_t initialOffset, size;
657 if (fillInSkips) { 656 if (fillInSkips) {
658 this->fillRestoreOffsetPlaceholdersForCurrentStackLevel((uint32_t)fWrite r.bytesWritten()); 657 this->fillRestoreOffsetPlaceholdersForCurrentStackLevel((uint32_t)fWrite r.bytesWritten());
659 } 658 }
660 size = 1 * kUInt32Size; // RESTORE consists solely of 1 op code 659 size_t size = 1 * kUInt32Size; // RESTORE consists solely of 1 op code
661 initialOffset = this->addDraw(RESTORE, &size); 660 size_t initialOffset = this->addDraw(RESTORE, &size);
662 this->validate(initialOffset, size); 661 this->validate(initialOffset, size);
663 } 662 }
664 663
665 void SkPictureRecord::recordTranslate(const SkMatrix& m) { 664 void SkPictureRecord::recordTranslate(const SkMatrix& m) {
666 SkASSERT(SkMatrix::kTranslate_Mask == m.getType()); 665 SkASSERT(SkMatrix::kTranslate_Mask == m.getType());
667 666
668 // op + dx + dy 667 // op + dx + dy
669 uint32_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar); 668 size_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar);
670 size_t initialOffset = this->addDraw(TRANSLATE, &size); 669 size_t initialOffset = this->addDraw(TRANSLATE, &size);
671 this->addScalar(m.getTranslateX()); 670 this->addScalar(m.getTranslateX());
672 this->addScalar(m.getTranslateY()); 671 this->addScalar(m.getTranslateY());
673 this->validate(initialOffset, size); 672 this->validate(initialOffset, size);
674 } 673 }
675 674
676 void SkPictureRecord::recordScale(const SkMatrix& m) { 675 void SkPictureRecord::recordScale(const SkMatrix& m) {
677 SkASSERT(SkMatrix::kScale_Mask == m.getType()); 676 SkASSERT(SkMatrix::kScale_Mask == m.getType());
678 677
679 // op + sx + sy 678 // op + sx + sy
680 uint32_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar); 679 size_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar);
681 size_t initialOffset = this->addDraw(SCALE, &size); 680 size_t initialOffset = this->addDraw(SCALE, &size);
682 this->addScalar(m.getScaleX()); 681 this->addScalar(m.getScaleX());
683 this->addScalar(m.getScaleY()); 682 this->addScalar(m.getScaleY());
684 this->validate(initialOffset, size); 683 this->validate(initialOffset, size);
685 } 684 }
686 685
687 void SkPictureRecord::didConcat(const SkMatrix& matrix) { 686 void SkPictureRecord::didConcat(const SkMatrix& matrix) {
688 687
689 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 688 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
690 fMCMgr.concat(matrix); 689 fMCMgr.concat(matrix);
691 #else 690 #else
692 switch (matrix.getType()) { 691 switch (matrix.getType()) {
693 case SkMatrix::kTranslate_Mask: 692 case SkMatrix::kTranslate_Mask:
694 this->recordTranslate(matrix); 693 this->recordTranslate(matrix);
695 break; 694 break;
696 case SkMatrix::kScale_Mask: 695 case SkMatrix::kScale_Mask:
697 this->recordScale(matrix); 696 this->recordScale(matrix);
698 break; 697 break;
699 default: 698 default:
700 this->recordConcat(matrix); 699 this->recordConcat(matrix);
701 break; 700 break;
702 } 701 }
703 #endif 702 #endif
704 this->INHERITED::didConcat(matrix); 703 this->INHERITED::didConcat(matrix);
705 } 704 }
706 705
707 void SkPictureRecord::recordConcat(const SkMatrix& matrix) { 706 void SkPictureRecord::recordConcat(const SkMatrix& matrix) {
708 this->validate(fWriter.bytesWritten(), 0); 707 this->validate(fWriter.bytesWritten(), 0);
709 // op + matrix 708 // op + matrix
710 uint32_t size = kUInt32Size + matrix.writeToMemory(NULL); 709 size_t size = kUInt32Size + matrix.writeToMemory(NULL);
711 size_t initialOffset = this->addDraw(CONCAT, &size); 710 size_t initialOffset = this->addDraw(CONCAT, &size);
712 this->addMatrix(matrix); 711 this->addMatrix(matrix);
713 this->validate(initialOffset, size); 712 this->validate(initialOffset, size);
714 } 713 }
715 714
716 void SkPictureRecord::didSetMatrix(const SkMatrix& matrix) { 715 void SkPictureRecord::didSetMatrix(const SkMatrix& matrix) {
717 716
718 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 717 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
719 fMCMgr.setMatrix(matrix); 718 fMCMgr.setMatrix(matrix);
720 #else 719 #else
721 this->validate(fWriter.bytesWritten(), 0); 720 this->validate(fWriter.bytesWritten(), 0);
722 // op + matrix 721 // op + matrix
723 uint32_t size = kUInt32Size + matrix.writeToMemory(NULL); 722 size_t size = kUInt32Size + matrix.writeToMemory(NULL);
724 size_t initialOffset = this->addDraw(SET_MATRIX, &size); 723 size_t initialOffset = this->addDraw(SET_MATRIX, &size);
725 this->addMatrix(matrix); 724 this->addMatrix(matrix);
726 this->validate(initialOffset, size); 725 this->validate(initialOffset, size);
727 #endif 726 #endif
728 this->INHERITED::didSetMatrix(matrix); 727 this->INHERITED::didSetMatrix(matrix);
729 } 728 }
730 729
731 static bool regionOpExpands(SkRegion::Op op) { 730 static bool regionOpExpands(SkRegion::Op op) {
732 switch (op) { 731 switch (op) {
733 case SkRegion::kUnion_Op: 732 case SkRegion::kUnion_Op:
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 #endif 780 #endif
782 } 781 }
783 782
784 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 783 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
785 int SkPictureRecord::recordRestoreOffsetPlaceholder(SkRegion::Op op) { 784 int SkPictureRecord::recordRestoreOffsetPlaceholder(SkRegion::Op op) {
786 size_t offset = fWriter.bytesWritten(); 785 size_t offset = fWriter.bytesWritten();
787 this->addInt(-1); 786 this->addInt(-1);
788 return offset; 787 return offset;
789 } 788 }
790 #else 789 #else
791 int SkPictureRecord::recordRestoreOffsetPlaceholder(SkRegion::Op op) { 790 size_t SkPictureRecord::recordRestoreOffsetPlaceholder(SkRegion::Op op) {
792 if (fRestoreOffsetStack.isEmpty()) { 791 if (fRestoreOffsetStack.isEmpty()) {
793 return -1; 792 return -1;
794 } 793 }
795 794
796 // The RestoreOffset field is initially filled with a placeholder 795 // The RestoreOffset field is initially filled with a placeholder
797 // value that points to the offset of the previous RestoreOffset 796 // value that points to the offset of the previous RestoreOffset
798 // in the current stack level, thus forming a linked list so that 797 // in the current stack level, thus forming a linked list so that
799 // the restore offsets can be filled in when the corresponding 798 // the restore offsets can be filled in when the corresponding
800 // restore command is recorded. 799 // restore command is recorded.
801 int32_t prevOffset = fRestoreOffsetStack.top(); 800 int32_t prevOffset = fRestoreOffsetStack.top();
802 801
803 if (regionOpExpands(op)) { 802 if (regionOpExpands(op)) {
804 // Run back through any previous clip ops, and mark their offset to 803 // Run back through any previous clip ops, and mark their offset to
805 // be 0, disabling their ability to trigger a jump-to-restore, otherwise 804 // be 0, disabling their ability to trigger a jump-to-restore, otherwise
806 // they could hide this clips ability to expand the clip (i.e. go from 805 // they could hide this clips ability to expand the clip (i.e. go from
807 // empty to non-empty). 806 // empty to non-empty).
808 this->fillRestoreOffsetPlaceholdersForCurrentStackLevel(0); 807 this->fillRestoreOffsetPlaceholdersForCurrentStackLevel(0);
809 808
810 // Reset the pointer back to the previous clip so that subsequent 809 // Reset the pointer back to the previous clip so that subsequent
811 // restores don't overwrite the offsets we just cleared. 810 // restores don't overwrite the offsets we just cleared.
812 prevOffset = 0; 811 prevOffset = 0;
813 } 812 }
814 813
815 size_t offset = fWriter.bytesWritten(); 814 size_t offset = fWriter.bytesWritten();
816 this->addInt(prevOffset); 815 this->addInt(prevOffset);
817 fRestoreOffsetStack.top() = offset; 816 fRestoreOffsetStack.top() = SkToU32(offset);
818 return offset; 817 return offset;
819 } 818 }
820 #endif 819 #endif
821 820
822 void SkPictureRecord::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeSt yle edgeStyle) { 821 void SkPictureRecord::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeSt yle edgeStyle) {
823 822
824 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 823 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
825 fMCMgr.clipRect(rect, op, doAA); 824 fMCMgr.clipRect(rect, op, doAA);
826 #else 825 #else
827 this->recordClipRect(rect, op, kSoft_ClipEdgeStyle == edgeStyle); 826 this->recordClipRect(rect, op, kSoft_ClipEdgeStyle == edgeStyle);
828 #endif 827 #endif
829 this->INHERITED::onClipRect(rect, op, edgeStyle); 828 this->INHERITED::onClipRect(rect, op, edgeStyle);
830 } 829 }
831 830
832 int SkPictureRecord::recordClipRect(const SkRect& rect, SkRegion::Op op, bool do AA) { 831 size_t SkPictureRecord::recordClipRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
833 // id + rect + clip params 832 // id + rect + clip params
834 uint32_t size = 1 * kUInt32Size + sizeof(rect) + 1 * kUInt32Size; 833 size_t size = 1 * kUInt32Size + sizeof(rect) + 1 * kUInt32Size;
835 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 834 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
836 size += kUInt32Size; // + restore offset 835 size += kUInt32Size; // + restore offset
837 #else 836 #else
838 // recordRestoreOffsetPlaceholder doesn't always write an offset 837 // recordRestoreOffsetPlaceholder doesn't always write an offset
839 if (!fRestoreOffsetStack.isEmpty()) { 838 if (!fRestoreOffsetStack.isEmpty()) {
840 // + restore offset 839 // + restore offset
841 size += kUInt32Size; 840 size += kUInt32Size;
842 } 841 }
843 #endif 842 #endif
844 size_t initialOffset = this->addDraw(CLIP_RECT, &size); 843 size_t initialOffset = this->addDraw(CLIP_RECT, &size);
845 this->addRect(rect); 844 this->addRect(rect);
846 this->addInt(ClipParams_pack(op, doAA)); 845 this->addInt(ClipParams_pack(op, doAA));
847 int offset = this->recordRestoreOffsetPlaceholder(op); 846 size_t offset = this->recordRestoreOffsetPlaceholder(op);
848 847
849 this->validate(initialOffset, size); 848 this->validate(initialOffset, size);
850 return offset; 849 return offset;
851 } 850 }
852 851
853 void SkPictureRecord::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdg eStyle edgeStyle) { 852 void SkPictureRecord::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdg eStyle edgeStyle) {
854 853
855 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 854 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
856 fMCMgr.clipRRect(rrect, op, doAA); 855 fMCMgr.clipRRect(rrect, op, doAA);
857 #else 856 #else
858 this->recordClipRRect(rrect, op, kSoft_ClipEdgeStyle == edgeStyle); 857 this->recordClipRRect(rrect, op, kSoft_ClipEdgeStyle == edgeStyle);
859 #endif 858 #endif
860 if (fRecordFlags & SkPicture::kUsePathBoundsForClip_RecordingFlag) { 859 if (fRecordFlags & SkPicture::kUsePathBoundsForClip_RecordingFlag) {
861 this->updateClipConservativelyUsingBounds(rrect.getBounds(), op, false); 860 this->updateClipConservativelyUsingBounds(rrect.getBounds(), op, false);
862 } else { 861 } else {
863 this->INHERITED::onClipRRect(rrect, op, edgeStyle); 862 this->INHERITED::onClipRRect(rrect, op, edgeStyle);
864 } 863 }
865 } 864 }
866 865
867 int SkPictureRecord::recordClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) { 866 size_t SkPictureRecord::recordClipRRect(const SkRRect& rrect, SkRegion::Op op, b ool doAA) {
868 // op + rrect + clip params 867 // op + rrect + clip params
869 uint32_t size = 1 * kUInt32Size + SkRRect::kSizeInMemory + 1 * kUInt32Size; 868 size_t size = 1 * kUInt32Size + SkRRect::kSizeInMemory + 1 * kUInt32Size;
870 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 869 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
871 size += kUInt32Size; // + restore offset 870 size += kUInt32Size; // + restore offset
872 #else 871 #else
873 // recordRestoreOffsetPlaceholder doesn't always write an offset 872 // recordRestoreOffsetPlaceholder doesn't always write an offset
874 if (!fRestoreOffsetStack.isEmpty()) { 873 if (!fRestoreOffsetStack.isEmpty()) {
875 // + restore offset 874 // + restore offset
876 size += kUInt32Size; 875 size += kUInt32Size;
877 } 876 }
878 #endif 877 #endif
879 size_t initialOffset = this->addDraw(CLIP_RRECT, &size); 878 size_t initialOffset = this->addDraw(CLIP_RRECT, &size);
880 this->addRRect(rrect); 879 this->addRRect(rrect);
881 this->addInt(ClipParams_pack(op, doAA)); 880 this->addInt(ClipParams_pack(op, doAA));
882 int offset = recordRestoreOffsetPlaceholder(op); 881 size_t offset = recordRestoreOffsetPlaceholder(op);
883 this->validate(initialOffset, size); 882 this->validate(initialOffset, size);
884 return offset; 883 return offset;
885 } 884 }
886 885
887 void SkPictureRecord::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeSt yle edgeStyle) { 886 void SkPictureRecord::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeSt yle edgeStyle) {
888 887
889 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 888 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
890 fMCMgr.clipPath(path, op, doAA); 889 fMCMgr.clipPath(path, op, doAA);
891 #else 890 #else
892 int pathID = this->addPathToHeap(path); 891 int pathID = this->addPathToHeap(path);
893 this->recordClipPath(pathID, op, kSoft_ClipEdgeStyle == edgeStyle); 892 this->recordClipPath(pathID, op, kSoft_ClipEdgeStyle == edgeStyle);
894 #endif 893 #endif
895 894
896 if (fRecordFlags & SkPicture::kUsePathBoundsForClip_RecordingFlag) { 895 if (fRecordFlags & SkPicture::kUsePathBoundsForClip_RecordingFlag) {
897 this->updateClipConservativelyUsingBounds(path.getBounds(), op, 896 this->updateClipConservativelyUsingBounds(path.getBounds(), op,
898 path.isInverseFillType()); 897 path.isInverseFillType());
899 } else { 898 } else {
900 this->INHERITED::onClipPath(path, op, edgeStyle); 899 this->INHERITED::onClipPath(path, op, edgeStyle);
901 } 900 }
902 } 901 }
903 902
904 int SkPictureRecord::recordClipPath(int pathID, SkRegion::Op op, bool doAA) { 903 size_t SkPictureRecord::recordClipPath(int pathID, SkRegion::Op op, bool doAA) {
905 // op + path index + clip params 904 // op + path index + clip params
906 uint32_t size = 3 * kUInt32Size; 905 size_t size = 3 * kUInt32Size;
907 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 906 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
908 size += kUInt32Size; // + restore offset 907 size += kUInt32Size; // + restore offset
909 #else 908 #else
910 // recordRestoreOffsetPlaceholder doesn't always write an offset 909 // recordRestoreOffsetPlaceholder doesn't always write an offset
911 if (!fRestoreOffsetStack.isEmpty()) { 910 if (!fRestoreOffsetStack.isEmpty()) {
912 // + restore offset 911 // + restore offset
913 size += kUInt32Size; 912 size += kUInt32Size;
914 } 913 }
915 #endif 914 #endif
916 size_t initialOffset = this->addDraw(CLIP_PATH, &size); 915 size_t initialOffset = this->addDraw(CLIP_PATH, &size);
917 this->addInt(pathID); 916 this->addInt(pathID);
918 this->addInt(ClipParams_pack(op, doAA)); 917 this->addInt(ClipParams_pack(op, doAA));
919 int offset = recordRestoreOffsetPlaceholder(op); 918 size_t offset = recordRestoreOffsetPlaceholder(op);
920 this->validate(initialOffset, size); 919 this->validate(initialOffset, size);
921 return offset; 920 return offset;
922 } 921 }
923 922
924 void SkPictureRecord::onClipRegion(const SkRegion& region, SkRegion::Op op) { 923 void SkPictureRecord::onClipRegion(const SkRegion& region, SkRegion::Op op) {
925 924
926 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 925 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
927 fMCMgr.clipRegion(region, op); 926 fMCMgr.clipRegion(region, op);
928 #else 927 #else
929 this->recordClipRegion(region, op); 928 this->recordClipRegion(region, op);
930 #endif 929 #endif
931 this->INHERITED::onClipRegion(region, op); 930 this->INHERITED::onClipRegion(region, op);
932 } 931 }
933 932
934 int SkPictureRecord::recordClipRegion(const SkRegion& region, SkRegion::Op op) { 933 size_t SkPictureRecord::recordClipRegion(const SkRegion& region, SkRegion::Op op ) {
935 // op + clip params + region 934 // op + clip params + region
936 uint32_t size = 2 * kUInt32Size + region.writeToMemory(NULL); 935 size_t size = 2 * kUInt32Size + region.writeToMemory(NULL);
937 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 936 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
938 size += kUInt32Size; // + restore offset 937 size += kUInt32Size; // + restore offset
939 #else 938 #else
940 // recordRestoreOffsetPlaceholder doesn't always write an offset 939 // recordRestoreOffsetPlaceholder doesn't always write an offset
941 if (!fRestoreOffsetStack.isEmpty()) { 940 if (!fRestoreOffsetStack.isEmpty()) {
942 // + restore offset 941 // + restore offset
943 size += kUInt32Size; 942 size += kUInt32Size;
944 } 943 }
945 #endif 944 #endif
946 size_t initialOffset = this->addDraw(CLIP_REGION, &size); 945 size_t initialOffset = this->addDraw(CLIP_REGION, &size);
947 this->addRegion(region); 946 this->addRegion(region);
948 this->addInt(ClipParams_pack(op, false)); 947 this->addInt(ClipParams_pack(op, false));
949 int offset = this->recordRestoreOffsetPlaceholder(op); 948 size_t offset = this->recordRestoreOffsetPlaceholder(op);
950 949
951 this->validate(initialOffset, size); 950 this->validate(initialOffset, size);
952 return offset; 951 return offset;
953 } 952 }
954 953
955 void SkPictureRecord::clear(SkColor color) { 954 void SkPictureRecord::clear(SkColor color) {
956 955
957 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 956 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
958 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); 957 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType);
959 #endif 958 #endif
960 959
961 // op + color 960 // op + color
962 uint32_t size = 2 * kUInt32Size; 961 size_t size = 2 * kUInt32Size;
963 size_t initialOffset = this->addDraw(DRAW_CLEAR, &size); 962 size_t initialOffset = this->addDraw(DRAW_CLEAR, &size);
964 this->addInt(color); 963 this->addInt(color);
965 this->validate(initialOffset, size); 964 this->validate(initialOffset, size);
966 } 965 }
967 966
968 void SkPictureRecord::drawPaint(const SkPaint& paint) { 967 void SkPictureRecord::drawPaint(const SkPaint& paint) {
969 968
970 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 969 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
971 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); 970 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType);
972 #endif 971 #endif
973 972
974 // op + paint index 973 // op + paint index
975 uint32_t size = 2 * kUInt32Size; 974 size_t size = 2 * kUInt32Size;
976 size_t initialOffset = this->addDraw(DRAW_PAINT, &size); 975 size_t initialOffset = this->addDraw(DRAW_PAINT, &size);
977 SkASSERT(initialOffset+getPaintOffset(DRAW_PAINT, size) == fWriter.bytesWrit ten()); 976 SkASSERT(initialOffset+getPaintOffset(DRAW_PAINT, size) == fWriter.bytesWrit ten());
978 this->addPaint(paint); 977 this->addPaint(paint);
979 this->validate(initialOffset, size); 978 this->validate(initialOffset, size);
980 } 979 }
981 980
982 void SkPictureRecord::drawPoints(PointMode mode, size_t count, const SkPoint pts [], 981 void SkPictureRecord::drawPoints(PointMode mode, size_t count, const SkPoint pts [],
983 const SkPaint& paint) { 982 const SkPaint& paint) {
984 983
985 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 984 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
986 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); 985 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType);
987 #endif 986 #endif
988 987
989 // op + paint index + mode + count + point data 988 // op + paint index + mode + count + point data
990 uint32_t size = 4 * kUInt32Size + count * sizeof(SkPoint); 989 size_t size = 4 * kUInt32Size + count * sizeof(SkPoint);
991 size_t initialOffset = this->addDraw(DRAW_POINTS, &size); 990 size_t initialOffset = this->addDraw(DRAW_POINTS, &size);
992 SkASSERT(initialOffset+getPaintOffset(DRAW_POINTS, size) == fWriter.bytesWri tten()); 991 SkASSERT(initialOffset+getPaintOffset(DRAW_POINTS, size) == fWriter.bytesWri tten());
993 this->addPaint(paint); 992 this->addPaint(paint);
994 this->addInt(mode); 993 this->addInt(mode);
995 this->addInt(count); 994 this->addInt(SkToInt(count));
996 fWriter.writeMul4(pts, count * sizeof(SkPoint)); 995 fWriter.writeMul4(pts, count * sizeof(SkPoint));
997 this->validate(initialOffset, size); 996 this->validate(initialOffset, size);
998 } 997 }
999 998
1000 void SkPictureRecord::drawOval(const SkRect& oval, const SkPaint& paint) { 999 void SkPictureRecord::drawOval(const SkRect& oval, const SkPaint& paint) {
1001 1000
1002 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 1001 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
1003 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); 1002 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType);
1004 #endif 1003 #endif
1005 1004
1006 // op + paint index + rect 1005 // op + paint index + rect
1007 uint32_t size = 2 * kUInt32Size + sizeof(oval); 1006 size_t size = 2 * kUInt32Size + sizeof(oval);
1008 size_t initialOffset = this->addDraw(DRAW_OVAL, &size); 1007 size_t initialOffset = this->addDraw(DRAW_OVAL, &size);
1009 SkASSERT(initialOffset+getPaintOffset(DRAW_OVAL, size) == fWriter.bytesWritt en()); 1008 SkASSERT(initialOffset+getPaintOffset(DRAW_OVAL, size) == fWriter.bytesWritt en());
1010 this->addPaint(paint); 1009 this->addPaint(paint);
1011 this->addRect(oval); 1010 this->addRect(oval);
1012 this->validate(initialOffset, size); 1011 this->validate(initialOffset, size);
1013 } 1012 }
1014 1013
1015 void SkPictureRecord::drawRect(const SkRect& rect, const SkPaint& paint) { 1014 void SkPictureRecord::drawRect(const SkRect& rect, const SkPaint& paint) {
1016 1015
1017 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 1016 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
1018 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); 1017 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType);
1019 #endif 1018 #endif
1020 1019
1021 // op + paint index + rect 1020 // op + paint index + rect
1022 uint32_t size = 2 * kUInt32Size + sizeof(rect); 1021 size_t size = 2 * kUInt32Size + sizeof(rect);
1023 size_t initialOffset = this->addDraw(DRAW_RECT, &size); 1022 size_t initialOffset = this->addDraw(DRAW_RECT, &size);
1024 SkASSERT(initialOffset+getPaintOffset(DRAW_RECT, size) == fWriter.bytesWritt en()); 1023 SkASSERT(initialOffset+getPaintOffset(DRAW_RECT, size) == fWriter.bytesWritt en());
1025 this->addPaint(paint); 1024 this->addPaint(paint);
1026 this->addRect(rect); 1025 this->addRect(rect);
1027 this->validate(initialOffset, size); 1026 this->validate(initialOffset, size);
1028 } 1027 }
1029 1028
1030 void SkPictureRecord::drawRRect(const SkRRect& rrect, const SkPaint& paint) { 1029 void SkPictureRecord::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
1031 1030
1032 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 1031 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
1033 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); 1032 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType);
1034 #endif 1033 #endif
1035 1034
1036 if (rrect.isRect()) { 1035 if (rrect.isRect()) {
1037 this->SkPictureRecord::drawRect(rrect.getBounds(), paint); 1036 this->SkPictureRecord::drawRect(rrect.getBounds(), paint);
1038 } else if (rrect.isOval()) { 1037 } else if (rrect.isOval()) {
1039 this->SkPictureRecord::drawOval(rrect.getBounds(), paint); 1038 this->SkPictureRecord::drawOval(rrect.getBounds(), paint);
1040 } else { 1039 } else {
1041 // op + paint index + rrect 1040 // op + paint index + rrect
1042 uint32_t initialOffset, size; 1041 size_t size = 2 * kUInt32Size + SkRRect::kSizeInMemory;
1043 size = 2 * kUInt32Size + SkRRect::kSizeInMemory; 1042 size_t initialOffset = this->addDraw(DRAW_RRECT, &size);
1044 initialOffset = this->addDraw(DRAW_RRECT, &size);
1045 SkASSERT(initialOffset+getPaintOffset(DRAW_RRECT, size) == fWriter.bytes Written()); 1043 SkASSERT(initialOffset+getPaintOffset(DRAW_RRECT, size) == fWriter.bytes Written());
1046 this->addPaint(paint); 1044 this->addPaint(paint);
1047 this->addRRect(rrect); 1045 this->addRRect(rrect);
1048 this->validate(initialOffset, size); 1046 this->validate(initialOffset, size);
1049 } 1047 }
1050 } 1048 }
1051 1049
1052 void SkPictureRecord::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, 1050 void SkPictureRecord::onDrawDRRect(const SkRRect& outer, const SkRRect& inner,
1053 const SkPaint& paint) { 1051 const SkPaint& paint) {
1054 1052
1055 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 1053 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
1056 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); 1054 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType);
1057 #endif 1055 #endif
1058 1056
1059 // op + paint index + rrects 1057 // op + paint index + rrects
1060 uint32_t initialOffset, size; 1058 size_t size = 2 * kUInt32Size + SkRRect::kSizeInMemory * 2;
1061 size = 2 * kUInt32Size + SkRRect::kSizeInMemory * 2; 1059 size_t initialOffset = this->addDraw(DRAW_DRRECT, &size);
1062 initialOffset = this->addDraw(DRAW_DRRECT, &size);
1063 SkASSERT(initialOffset+getPaintOffset(DRAW_DRRECT, size) == fWriter.bytesWri tten()); 1060 SkASSERT(initialOffset+getPaintOffset(DRAW_DRRECT, size) == fWriter.bytesWri tten());
1064 this->addPaint(paint); 1061 this->addPaint(paint);
1065 this->addRRect(outer); 1062 this->addRRect(outer);
1066 this->addRRect(inner); 1063 this->addRRect(inner);
1067 this->validate(initialOffset, size); 1064 this->validate(initialOffset, size);
1068 } 1065 }
1069 1066
1070 void SkPictureRecord::drawPath(const SkPath& path, const SkPaint& paint) { 1067 void SkPictureRecord::drawPath(const SkPath& path, const SkPaint& paint) {
1071 1068
1072 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 1069 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
1073 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); 1070 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType);
1074 #endif 1071 #endif
1075 1072
1076 // op + paint index + path index 1073 // op + paint index + path index
1077 uint32_t size = 3 * kUInt32Size; 1074 size_t size = 3 * kUInt32Size;
1078 size_t initialOffset = this->addDraw(DRAW_PATH, &size); 1075 size_t initialOffset = this->addDraw(DRAW_PATH, &size);
1079 SkASSERT(initialOffset+getPaintOffset(DRAW_PATH, size) == fWriter.bytesWritt en()); 1076 SkASSERT(initialOffset+getPaintOffset(DRAW_PATH, size) == fWriter.bytesWritt en());
1080 this->addPaint(paint); 1077 this->addPaint(paint);
1081 this->addPath(path); 1078 this->addPath(path);
1082 this->validate(initialOffset, size); 1079 this->validate(initialOffset, size);
1083 } 1080 }
1084 1081
1085 void SkPictureRecord::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, 1082 void SkPictureRecord::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
1086 const SkPaint* paint = NULL) { 1083 const SkPaint* paint = NULL) {
1087 if (bitmap.drawsNothing()) { 1084 if (bitmap.drawsNothing()) {
1088 return; 1085 return;
1089 } 1086 }
1090 1087
1091 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 1088 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
1092 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); 1089 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType);
1093 #endif 1090 #endif
1094 1091
1095 // op + paint index + bitmap index + left + top 1092 // op + paint index + bitmap index + left + top
1096 uint32_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar); 1093 size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar);
1097 size_t initialOffset = this->addDraw(DRAW_BITMAP, &size); 1094 size_t initialOffset = this->addDraw(DRAW_BITMAP, &size);
1098 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP, size) == fWriter.bytesWri tten()); 1095 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP, size) == fWriter.bytesWri tten());
1099 this->addPaintPtr(paint); 1096 this->addPaintPtr(paint);
1100 this->addBitmap(bitmap); 1097 this->addBitmap(bitmap);
1101 this->addScalar(left); 1098 this->addScalar(left);
1102 this->addScalar(top); 1099 this->addScalar(top);
1103 this->validate(initialOffset, size); 1100 this->validate(initialOffset, size);
1104 } 1101 }
1105 1102
1106 void SkPictureRecord::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, 1103 void SkPictureRecord::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src,
1107 const SkRect& dst, const SkPaint* pai nt, 1104 const SkRect& dst, const SkPaint* pai nt,
1108 DrawBitmapRectFlags flags) { 1105 DrawBitmapRectFlags flags) {
1109 if (bitmap.drawsNothing()) { 1106 if (bitmap.drawsNothing()) {
1110 return; 1107 return;
1111 } 1108 }
1112 1109
1113 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 1110 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
1114 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); 1111 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType);
1115 #endif 1112 #endif
1116 // id + paint index + bitmap index + bool for 'src' + flags 1113 // id + paint index + bitmap index + bool for 'src' + flags
1117 uint32_t size = 5 * kUInt32Size; 1114 size_t size = 5 * kUInt32Size;
1118 if (NULL != src) { 1115 if (NULL != src) {
1119 size += sizeof(*src); // + rect 1116 size += sizeof(*src); // + rect
1120 } 1117 }
1121 size += sizeof(dst); // + rect 1118 size += sizeof(dst); // + rect
1122 1119
1123 size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT_TO_RECT, &size); 1120 size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT_TO_RECT, &size);
1124 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_RECT_TO_RECT, size) 1121 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_RECT_TO_RECT, size)
1125 == fWriter.bytesWritten()); 1122 == fWriter.bytesWritten());
1126 this->addPaintPtr(paint); 1123 this->addPaintPtr(paint);
1127 this->addBitmap(bitmap); 1124 this->addBitmap(bitmap);
1128 this->addRectPtr(src); // may be null 1125 this->addRectPtr(src); // may be null
1129 this->addRect(dst); 1126 this->addRect(dst);
1130 this->addInt(flags); 1127 this->addInt(flags);
1131 this->validate(initialOffset, size); 1128 this->validate(initialOffset, size);
1132 } 1129 }
1133 1130
1134 void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m atrix, 1131 void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m atrix,
1135 const SkPaint* paint) { 1132 const SkPaint* paint) {
1136 if (bitmap.drawsNothing()) { 1133 if (bitmap.drawsNothing()) {
1137 return; 1134 return;
1138 } 1135 }
1139 1136
1140 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 1137 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
1141 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); 1138 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType);
1142 #endif 1139 #endif
1143 1140
1144 // id + paint index + bitmap index + matrix 1141 // id + paint index + bitmap index + matrix
1145 uint32_t size = 3 * kUInt32Size + matrix.writeToMemory(NULL); 1142 size_t size = 3 * kUInt32Size + matrix.writeToMemory(NULL);
1146 size_t initialOffset = this->addDraw(DRAW_BITMAP_MATRIX, &size); 1143 size_t initialOffset = this->addDraw(DRAW_BITMAP_MATRIX, &size);
1147 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_MATRIX, size) == fWriter.b ytesWritten()); 1144 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_MATRIX, size) == fWriter.b ytesWritten());
1148 this->addPaintPtr(paint); 1145 this->addPaintPtr(paint);
1149 this->addBitmap(bitmap); 1146 this->addBitmap(bitmap);
1150 this->addMatrix(matrix); 1147 this->addMatrix(matrix);
1151 this->validate(initialOffset, size); 1148 this->validate(initialOffset, size);
1152 } 1149 }
1153 1150
1154 void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& cent er, 1151 void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& cent er,
1155 const SkRect& dst, const SkPaint* paint) { 1152 const SkRect& dst, const SkPaint* paint) {
1156 if (bitmap.drawsNothing()) { 1153 if (bitmap.drawsNothing()) {
1157 return; 1154 return;
1158 } 1155 }
1159 1156
1160 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 1157 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
1161 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); 1158 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType);
1162 #endif 1159 #endif
1163 1160
1164 // op + paint index + bitmap id + center + dst rect 1161 // op + paint index + bitmap id + center + dst rect
1165 uint32_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst); 1162 size_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst);
1166 size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size); 1163 size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size);
1167 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_NINE, size) == fWriter.byt esWritten()); 1164 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_NINE, size) == fWriter.byt esWritten());
1168 this->addPaintPtr(paint); 1165 this->addPaintPtr(paint);
1169 this->addBitmap(bitmap); 1166 this->addBitmap(bitmap);
1170 this->addIRect(center); 1167 this->addIRect(center);
1171 this->addRect(dst); 1168 this->addRect(dst);
1172 this->validate(initialOffset, size); 1169 this->validate(initialOffset, size);
1173 } 1170 }
1174 1171
1175 void SkPictureRecord::drawSprite(const SkBitmap& bitmap, int left, int top, 1172 void SkPictureRecord::drawSprite(const SkBitmap& bitmap, int left, int top,
1176 const SkPaint* paint = NULL) { 1173 const SkPaint* paint = NULL) {
1177 if (bitmap.drawsNothing()) { 1174 if (bitmap.drawsNothing()) {
1178 return; 1175 return;
1179 } 1176 }
1180 1177
1181 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 1178 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
1182 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); 1179 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType);
1183 #endif 1180 #endif
1184 1181
1185 // op + paint index + bitmap index + left + top 1182 // op + paint index + bitmap index + left + top
1186 uint32_t size = 5 * kUInt32Size; 1183 size_t size = 5 * kUInt32Size;
1187 size_t initialOffset = this->addDraw(DRAW_SPRITE, &size); 1184 size_t initialOffset = this->addDraw(DRAW_SPRITE, &size);
1188 SkASSERT(initialOffset+getPaintOffset(DRAW_SPRITE, size) == fWriter.bytesWri tten()); 1185 SkASSERT(initialOffset+getPaintOffset(DRAW_SPRITE, size) == fWriter.bytesWri tten());
1189 this->addPaintPtr(paint); 1186 this->addPaintPtr(paint);
1190 this->addBitmap(bitmap); 1187 this->addBitmap(bitmap);
1191 this->addInt(left); 1188 this->addInt(left);
1192 this->addInt(top); 1189 this->addInt(top);
1193 this->validate(initialOffset, size); 1190 this->validate(initialOffset, size);
1194 } 1191 }
1195 1192
1196 void SkPictureRecord::ComputeFontMetricsTopBottom(const SkPaint& paint, SkScalar topbot[2]) { 1193 void SkPictureRecord::ComputeFontMetricsTopBottom(const SkPaint& paint, SkScalar topbot[2]) {
(...skipping 18 matching lines...) Expand all
1215 void SkPictureRecord::drawText(const void* text, size_t byteLength, SkScalar x, 1212 void SkPictureRecord::drawText(const void* text, size_t byteLength, SkScalar x,
1216 SkScalar y, const SkPaint& paint) { 1213 SkScalar y, const SkPaint& paint) {
1217 1214
1218 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 1215 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
1219 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); 1216 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType);
1220 #endif 1217 #endif
1221 1218
1222 bool fast = !paint.isVerticalText() && paint.canComputeFastBounds(); 1219 bool fast = !paint.isVerticalText() && paint.canComputeFastBounds();
1223 1220
1224 // op + paint index + length + 'length' worth of chars + x + y 1221 // op + paint index + length + 'length' worth of chars + x + y
1225 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 2 * sizeof(SkScalar ); 1222 size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 2 * sizeof(SkScalar);
1226 if (fast) { 1223 if (fast) {
1227 size += 2 * sizeof(SkScalar); // + top & bottom 1224 size += 2 * sizeof(SkScalar); // + top & bottom
1228 } 1225 }
1229 1226
1230 DrawType op = fast ? DRAW_TEXT_TOP_BOTTOM : DRAW_TEXT; 1227 DrawType op = fast ? DRAW_TEXT_TOP_BOTTOM : DRAW_TEXT;
1231 size_t initialOffset = this->addDraw(op, &size); 1228 size_t initialOffset = this->addDraw(op, &size);
1232 SkASSERT(initialOffset+getPaintOffset(op, size) == fWriter.bytesWritten()); 1229 SkASSERT(initialOffset+getPaintOffset(op, size) == fWriter.bytesWritten());
1233 const SkFlatData* flatPaintData = addPaint(paint); 1230 const SkFlatData* flatPaintData = addPaint(paint);
1234 SkASSERT(flatPaintData); 1231 SkASSERT(flatPaintData);
1235 this->addText(text, byteLength); 1232 this->addText(text, byteLength);
1236 this->addScalar(x); 1233 this->addScalar(x);
1237 this->addScalar(y); 1234 this->addScalar(y);
1238 if (fast) { 1235 if (fast) {
1239 this->addFontMetricsTopBottom(paint, *flatPaintData, y, y); 1236 this->addFontMetricsTopBottom(paint, *flatPaintData, y, y);
1240 } 1237 }
1241 this->validate(initialOffset, size); 1238 this->validate(initialOffset, size);
1242 } 1239 }
1243 1240
1244 void SkPictureRecord::drawPosText(const void* text, size_t byteLength, 1241 void SkPictureRecord::drawPosText(const void* text, size_t byteLength,
1245 const SkPoint pos[], const SkPaint& paint) { 1242 const SkPoint pos[], const SkPaint& paint) {
1246 1243
1247 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 1244 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
1248 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); 1245 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType);
1249 #endif 1246 #endif
1250 1247
1251 size_t points = paint.countText(text, byteLength); 1248 int points = paint.countText(text, byteLength);
1252 if (0 == points) 1249 if (0 == points)
1253 return; 1250 return;
1254 1251
1255 bool canUseDrawH = true; 1252 bool canUseDrawH = true;
1256 SkScalar minY = pos[0].fY; 1253 SkScalar minY = pos[0].fY;
1257 SkScalar maxY = pos[0].fY; 1254 SkScalar maxY = pos[0].fY;
1258 // check if the caller really should have used drawPosTextH() 1255 // check if the caller really should have used drawPosTextH()
1259 { 1256 {
1260 const SkScalar firstY = pos[0].fY; 1257 const SkScalar firstY = pos[0].fY;
1261 for (size_t index = 1; index < points; index++) { 1258 for (int index = 1; index < points; index++) {
1262 if (pos[index].fY != firstY) { 1259 if (pos[index].fY != firstY) {
1263 canUseDrawH = false; 1260 canUseDrawH = false;
1264 if (pos[index].fY < minY) { 1261 if (pos[index].fY < minY) {
1265 minY = pos[index].fY; 1262 minY = pos[index].fY;
1266 } else if (pos[index].fY > maxY) { 1263 } else if (pos[index].fY > maxY) {
1267 maxY = pos[index].fY; 1264 maxY = pos[index].fY;
1268 } 1265 }
1269 } 1266 }
1270 } 1267 }
1271 } 1268 }
1272 1269
1273 bool fastBounds = !paint.isVerticalText() && paint.canComputeFastBounds(); 1270 bool fastBounds = !paint.isVerticalText() && paint.canComputeFastBounds();
1274 bool fast = canUseDrawH && fastBounds; 1271 bool fast = canUseDrawH && fastBounds;
1275 1272
1276 // op + paint index + length + 'length' worth of data + num points 1273 // op + paint index + length + 'length' worth of data + num points
1277 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 1 * kUInt32Size; 1274 size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 1 * kUInt32Size;
1278 if (canUseDrawH) { 1275 if (canUseDrawH) {
1279 if (fast) { 1276 if (fast) {
1280 size += 2 * sizeof(SkScalar); // + top & bottom 1277 size += 2 * sizeof(SkScalar); // + top & bottom
1281 } 1278 }
1282 // + y-pos + actual x-point data 1279 // + y-pos + actual x-point data
1283 size += sizeof(SkScalar) + points * sizeof(SkScalar); 1280 size += sizeof(SkScalar) + points * sizeof(SkScalar);
1284 } else { 1281 } else {
1285 // + x&y point data 1282 // + x&y point data
1286 size += points * sizeof(SkPoint); 1283 size += points * sizeof(SkPoint);
1287 if (fastBounds) { 1284 if (fastBounds) {
(...skipping 20 matching lines...) Expand all
1308 1305
1309 #ifdef SK_DEBUG_SIZE 1306 #ifdef SK_DEBUG_SIZE
1310 size_t start = fWriter.bytesWritten(); 1307 size_t start = fWriter.bytesWritten();
1311 #endif 1308 #endif
1312 if (canUseDrawH) { 1309 if (canUseDrawH) {
1313 if (fast) { 1310 if (fast) {
1314 this->addFontMetricsTopBottom(paint, *flatPaintData, pos[0].fY, pos[ 0].fY); 1311 this->addFontMetricsTopBottom(paint, *flatPaintData, pos[0].fY, pos[ 0].fY);
1315 } 1312 }
1316 this->addScalar(pos[0].fY); 1313 this->addScalar(pos[0].fY);
1317 SkScalar* xptr = (SkScalar*)fWriter.reserve(points * sizeof(SkScalar)); 1314 SkScalar* xptr = (SkScalar*)fWriter.reserve(points * sizeof(SkScalar));
1318 for (size_t index = 0; index < points; index++) 1315 for (int index = 0; index < points; index++)
1319 *xptr++ = pos[index].fX; 1316 *xptr++ = pos[index].fX;
1320 } else { 1317 } else {
1321 fWriter.writeMul4(pos, points * sizeof(SkPoint)); 1318 fWriter.writeMul4(pos, points * sizeof(SkPoint));
1322 if (fastBounds) { 1319 if (fastBounds) {
1323 this->addFontMetricsTopBottom(paint, *flatPaintData, minY, maxY); 1320 this->addFontMetricsTopBottom(paint, *flatPaintData, minY, maxY);
1324 } 1321 }
1325 } 1322 }
1326 #ifdef SK_DEBUG_SIZE 1323 #ifdef SK_DEBUG_SIZE
1327 fPointBytes += fWriter.bytesWritten() - start; 1324 fPointBytes += fWriter.bytesWritten() - start;
1328 fPointWrites += points; 1325 fPointWrites += points;
1329 #endif 1326 #endif
1330 this->validate(initialOffset, size); 1327 this->validate(initialOffset, size);
1331 } 1328 }
1332 1329
1333 void SkPictureRecord::drawPosTextH(const void* text, size_t byteLength, 1330 void SkPictureRecord::drawPosTextH(const void* text, size_t byteLength,
1334 const SkScalar xpos[], SkScalar constY, 1331 const SkScalar xpos[], SkScalar constY,
1335 const SkPaint& paint) { 1332 const SkPaint& paint) {
1336 1333
1337 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 1334 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
1338 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); 1335 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType);
1339 #endif 1336 #endif
1340 1337
1341 const SkFlatData* flatPaintData = this->getFlatPaintData(paint); 1338 const SkFlatData* flatPaintData = this->getFlatPaintData(paint);
1342 this->drawPosTextHImpl(text, byteLength, xpos, constY, paint, flatPaintData) ; 1339 this->drawPosTextHImpl(text, byteLength, xpos, constY, paint, flatPaintData) ;
1343 } 1340 }
1344 1341
1345 void SkPictureRecord::drawPosTextHImpl(const void* text, size_t byteLength, 1342 void SkPictureRecord::drawPosTextHImpl(const void* text, size_t byteLength,
1346 const SkScalar xpos[], SkScalar constY, 1343 const SkScalar xpos[], SkScalar constY,
1347 const SkPaint& paint, const SkFlatData* flatPaintData) { 1344 const SkPaint& paint, const SkFlatData* flatPaintData) {
1348 size_t points = paint.countText(text, byteLength); 1345 int points = paint.countText(text, byteLength);
1349 if (0 == points) 1346 if (0 == points)
1350 return; 1347 return;
1351 1348
1352 bool fast = !paint.isVerticalText() && paint.canComputeFastBounds(); 1349 bool fast = !paint.isVerticalText() && paint.canComputeFastBounds();
1353 1350
1354 // op + paint index + length + 'length' worth of data + num points 1351 // op + paint index + length + 'length' worth of data + num points
1355 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 1 * kUInt32Size; 1352 size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 1 * kUInt32Size;
1356 if (fast) { 1353 if (fast) {
1357 size += 2 * sizeof(SkScalar); // + top & bottom 1354 size += 2 * sizeof(SkScalar); // + top & bottom
1358 } 1355 }
1359 // + y + the actual points 1356 // + y + the actual points
1360 size += 1 * kUInt32Size + points * sizeof(SkScalar); 1357 size += 1 * kUInt32Size + points * sizeof(SkScalar);
1361 size_t initialOffset = this->addDraw(fast ? DRAW_POS_TEXT_H_TOP_BOTTOM : DRA W_POS_TEXT_H, 1358 size_t initialOffset = this->addDraw(fast ? DRAW_POS_TEXT_H_TOP_BOTTOM : DRA W_POS_TEXT_H,
1362 &size); 1359 &size);
1363 SkASSERT(flatPaintData); 1360 SkASSERT(flatPaintData);
1364 this->addFlatPaint(flatPaintData); 1361 this->addFlatPaint(flatPaintData);
1365 1362
(...skipping 18 matching lines...) Expand all
1384 void SkPictureRecord::drawTextOnPath(const void* text, size_t byteLength, 1381 void SkPictureRecord::drawTextOnPath(const void* text, size_t byteLength,
1385 const SkPath& path, const SkMatrix* matrix, 1382 const SkPath& path, const SkMatrix* matrix,
1386 const SkPaint& paint) { 1383 const SkPaint& paint) {
1387 1384
1388 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 1385 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
1389 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); 1386 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType);
1390 #endif 1387 #endif
1391 1388
1392 // op + paint index + length + 'length' worth of data + path index + matrix 1389 // op + paint index + length + 'length' worth of data + path index + matrix
1393 const SkMatrix& m = matrix ? *matrix : SkMatrix::I(); 1390 const SkMatrix& m = matrix ? *matrix : SkMatrix::I();
1394 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + m.wri teToMemory(NULL); 1391 size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + m.write ToMemory(NULL);
1395 size_t initialOffset = this->addDraw(DRAW_TEXT_ON_PATH, &size); 1392 size_t initialOffset = this->addDraw(DRAW_TEXT_ON_PATH, &size);
1396 SkASSERT(initialOffset+getPaintOffset(DRAW_TEXT_ON_PATH, size) == fWriter.by tesWritten()); 1393 SkASSERT(initialOffset+getPaintOffset(DRAW_TEXT_ON_PATH, size) == fWriter.by tesWritten());
1397 this->addPaint(paint); 1394 this->addPaint(paint);
1398 this->addText(text, byteLength); 1395 this->addText(text, byteLength);
1399 this->addPath(path); 1396 this->addPath(path);
1400 this->addMatrix(m); 1397 this->addMatrix(m);
1401 this->validate(initialOffset, size); 1398 this->validate(initialOffset, size);
1402 } 1399 }
1403 1400
1404 void SkPictureRecord::drawPicture(SkPicture& picture) { 1401 void SkPictureRecord::drawPicture(SkPicture& picture) {
1405 1402
1406 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 1403 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
1407 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); 1404 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType);
1408 #endif 1405 #endif
1409 1406
1410 // op + picture index 1407 // op + picture index
1411 uint32_t size = 2 * kUInt32Size; 1408 size_t size = 2 * kUInt32Size;
1412 size_t initialOffset = this->addDraw(DRAW_PICTURE, &size); 1409 size_t initialOffset = this->addDraw(DRAW_PICTURE, &size);
1413 this->addPicture(picture); 1410 this->addPicture(picture);
1414 this->validate(initialOffset, size); 1411 this->validate(initialOffset, size);
1415 } 1412 }
1416 1413
1417 void SkPictureRecord::drawVertices(VertexMode vmode, int vertexCount, 1414 void SkPictureRecord::drawVertices(VertexMode vmode, int vertexCount,
1418 const SkPoint vertices[], const SkPoint texs[], 1415 const SkPoint vertices[], const SkPoint texs[],
1419 const SkColor colors[], SkXfermode* xfer, 1416 const SkColor colors[], SkXfermode* xfer,
1420 const uint16_t indices[], int indexCount, 1417 const uint16_t indices[], int indexCount,
1421 const SkPaint& paint) { 1418 const SkPaint& paint) {
(...skipping 13 matching lines...) Expand all
1435 flags |= DRAW_VERTICES_HAS_INDICES; 1432 flags |= DRAW_VERTICES_HAS_INDICES;
1436 } 1433 }
1437 if (NULL != xfer) { 1434 if (NULL != xfer) {
1438 SkXfermode::Mode mode; 1435 SkXfermode::Mode mode;
1439 if (xfer->asMode(&mode) && SkXfermode::kModulate_Mode != mode) { 1436 if (xfer->asMode(&mode) && SkXfermode::kModulate_Mode != mode) {
1440 flags |= DRAW_VERTICES_HAS_XFER; 1437 flags |= DRAW_VERTICES_HAS_XFER;
1441 } 1438 }
1442 } 1439 }
1443 1440
1444 // op + paint index + flags + vmode + vCount + vertices 1441 // op + paint index + flags + vmode + vCount + vertices
1445 uint32_t size = 5 * kUInt32Size + vertexCount * sizeof(SkPoint); 1442 size_t size = 5 * kUInt32Size + vertexCount * sizeof(SkPoint);
1446 if (flags & DRAW_VERTICES_HAS_TEXS) { 1443 if (flags & DRAW_VERTICES_HAS_TEXS) {
1447 size += vertexCount * sizeof(SkPoint); // + uvs 1444 size += vertexCount * sizeof(SkPoint); // + uvs
1448 } 1445 }
1449 if (flags & DRAW_VERTICES_HAS_COLORS) { 1446 if (flags & DRAW_VERTICES_HAS_COLORS) {
1450 size += vertexCount * sizeof(SkColor); // + vert colors 1447 size += vertexCount * sizeof(SkColor); // + vert colors
1451 } 1448 }
1452 if (flags & DRAW_VERTICES_HAS_INDICES) { 1449 if (flags & DRAW_VERTICES_HAS_INDICES) {
1453 // + num indices + indices 1450 // + num indices + indices
1454 size += 1 * kUInt32Size + SkAlign4(indexCount * sizeof(uint16_t)); 1451 size += 1 * kUInt32Size + SkAlign4(indexCount * sizeof(uint16_t));
1455 } 1452 }
(...skipping 26 matching lines...) Expand all
1482 this->validate(initialOffset, size); 1479 this->validate(initialOffset, size);
1483 } 1480 }
1484 1481
1485 void SkPictureRecord::drawData(const void* data, size_t length) { 1482 void SkPictureRecord::drawData(const void* data, size_t length) {
1486 1483
1487 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 1484 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
1488 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); 1485 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType);
1489 #endif 1486 #endif
1490 1487
1491 // op + length + 'length' worth of data 1488 // op + length + 'length' worth of data
1492 uint32_t size = 2 * kUInt32Size + SkAlign4(length); 1489 size_t size = 2 * kUInt32Size + SkAlign4(length);
1493 size_t initialOffset = this->addDraw(DRAW_DATA, &size); 1490 size_t initialOffset = this->addDraw(DRAW_DATA, &size);
1494 this->addInt(length); 1491 this->addInt(SkToInt(length));
1495 fWriter.writePad(data, length); 1492 fWriter.writePad(data, length);
1496 this->validate(initialOffset, size); 1493 this->validate(initialOffset, size);
1497 } 1494 }
1498 1495
1499 void SkPictureRecord::beginCommentGroup(const char* description) { 1496 void SkPictureRecord::beginCommentGroup(const char* description) {
1500 // op/size + length of string + \0 terminated chars 1497 // op/size + length of string + \0 terminated chars
1501 int length = strlen(description); 1498 size_t length = strlen(description);
1502 uint32_t size = 2 * kUInt32Size + SkAlign4(length + 1); 1499 size_t size = 2 * kUInt32Size + SkAlign4(length + 1);
1503 size_t initialOffset = this->addDraw(BEGIN_COMMENT_GROUP, &size); 1500 size_t initialOffset = this->addDraw(BEGIN_COMMENT_GROUP, &size);
1504 fWriter.writeString(description, length); 1501 fWriter.writeString(description, length);
1505 this->validate(initialOffset, size); 1502 this->validate(initialOffset, size);
1506 } 1503 }
1507 1504
1508 void SkPictureRecord::addComment(const char* kywd, const char* value) { 1505 void SkPictureRecord::addComment(const char* kywd, const char* value) {
1509 // op/size + 2x length of string + 2x \0 terminated chars 1506 // op/size + 2x length of string + 2x \0 terminated chars
1510 int kywdLen = strlen(kywd); 1507 size_t kywdLen = strlen(kywd);
1511 int valueLen = strlen(value); 1508 size_t valueLen = strlen(value);
1512 uint32_t size = 3 * kUInt32Size + SkAlign4(kywdLen + 1) + SkAlign4(valueLen + 1); 1509 size_t size = 3 * kUInt32Size + SkAlign4(kywdLen + 1) + SkAlign4(valueLen + 1);
1513 size_t initialOffset = this->addDraw(COMMENT, &size); 1510 size_t initialOffset = this->addDraw(COMMENT, &size);
1514 fWriter.writeString(kywd, kywdLen); 1511 fWriter.writeString(kywd, kywdLen);
1515 fWriter.writeString(value, valueLen); 1512 fWriter.writeString(value, valueLen);
1516 this->validate(initialOffset, size); 1513 this->validate(initialOffset, size);
1517 } 1514 }
1518 1515
1519 void SkPictureRecord::endCommentGroup() { 1516 void SkPictureRecord::endCommentGroup() {
1520 // op/size 1517 // op/size
1521 uint32_t size = 1 * kUInt32Size; 1518 size_t size = 1 * kUInt32Size;
1522 size_t initialOffset = this->addDraw(END_COMMENT_GROUP, &size); 1519 size_t initialOffset = this->addDraw(END_COMMENT_GROUP, &size);
1523 this->validate(initialOffset, size); 1520 this->validate(initialOffset, size);
1524 } 1521 }
1525 1522
1526 // [op/size] [rect] [skip offset] 1523 // [op/size] [rect] [skip offset]
1527 static const uint32_t kPushCullOpSize = 2 * kUInt32Size + sizeof(SkRect); 1524 static const uint32_t kPushCullOpSize = 2 * kUInt32Size + sizeof(SkRect);
1528 void SkPictureRecord::onPushCull(const SkRect& cullRect) { 1525 void SkPictureRecord::onPushCull(const SkRect& cullRect) {
1529 uint32_t size = kPushCullOpSize; 1526 size_t size = kPushCullOpSize;
1530 size_t initialOffset = this->addDraw(PUSH_CULL, &size); 1527 size_t initialOffset = this->addDraw(PUSH_CULL, &size);
1531 // PUSH_CULL's size should stay constant (used to rewind). 1528 // PUSH_CULL's size should stay constant (used to rewind).
1532 SkASSERT(size == kPushCullOpSize); 1529 SkASSERT(size == kPushCullOpSize);
1533 1530
1534 this->addRect(cullRect); 1531 this->addRect(cullRect);
1535 fCullOffsetStack.push(fWriter.bytesWritten()); 1532 fCullOffsetStack.push(SkToU32(fWriter.bytesWritten()));
1536 this->addInt(0); 1533 this->addInt(0);
1537 this->validate(initialOffset, size); 1534 this->validate(initialOffset, size);
1538 } 1535 }
1539 1536
1540 void SkPictureRecord::onPopCull() { 1537 void SkPictureRecord::onPopCull() {
1541 SkASSERT(!fCullOffsetStack.isEmpty()); 1538 SkASSERT(!fCullOffsetStack.isEmpty());
1542 1539
1543 uint32_t cullSkipOffset = fCullOffsetStack.top(); 1540 uint32_t cullSkipOffset = fCullOffsetStack.top();
1544 fCullOffsetStack.pop(); 1541 fCullOffsetStack.pop();
1545 1542
1546 // Collapse empty push/pop pairs. 1543 // Collapse empty push/pop pairs.
1547 if ((size_t)(cullSkipOffset + kUInt32Size) == fWriter.bytesWritten()) { 1544 if ((size_t)(cullSkipOffset + kUInt32Size) == fWriter.bytesWritten()) {
1548 SkASSERT(fWriter.bytesWritten() >= kPushCullOpSize); 1545 SkASSERT(fWriter.bytesWritten() >= kPushCullOpSize);
1549 SkASSERT(PUSH_CULL == peek_op(&fWriter, fWriter.bytesWritten() - kPushCu llOpSize)); 1546 SkASSERT(PUSH_CULL == peek_op(&fWriter, fWriter.bytesWritten() - kPushCu llOpSize));
1550 fWriter.rewindToOffset(fWriter.bytesWritten() - kPushCullOpSize); 1547 fWriter.rewindToOffset(fWriter.bytesWritten() - kPushCullOpSize);
1551 return; 1548 return;
1552 } 1549 }
1553 1550
1554 // op only 1551 // op only
1555 uint32_t size = kUInt32Size; 1552 size_t size = kUInt32Size;
1556 size_t initialOffset = this->addDraw(POP_CULL, &size); 1553 size_t initialOffset = this->addDraw(POP_CULL, &size);
1557 1554
1558 // update the cull skip offset to point past this op. 1555 // update the cull skip offset to point past this op.
1559 fWriter.overwriteTAt<uint32_t>(cullSkipOffset, fWriter.bytesWritten()); 1556 fWriter.overwriteTAt<uint32_t>(cullSkipOffset, SkToU32(fWriter.bytesWritten( )));
1560 1557
1561 this->validate(initialOffset, size); 1558 this->validate(initialOffset, size);
1562 } 1559 }
1563 1560
1564 /////////////////////////////////////////////////////////////////////////////// 1561 ///////////////////////////////////////////////////////////////////////////////
1565 1562
1566 SkSurface* SkPictureRecord::onNewSurface(const SkImageInfo& info) { 1563 SkSurface* SkPictureRecord::onNewSurface(const SkImageInfo& info) {
1567 return NULL; 1564 return NULL;
1568 } 1565 }
1569 1566
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 } 1670 }
1674 1671
1675 void SkPictureRecord::addRegion(const SkRegion& region) { 1672 void SkPictureRecord::addRegion(const SkRegion& region) {
1676 fWriter.writeRegion(region); 1673 fWriter.writeRegion(region);
1677 } 1674 }
1678 1675
1679 void SkPictureRecord::addText(const void* text, size_t byteLength) { 1676 void SkPictureRecord::addText(const void* text, size_t byteLength) {
1680 #ifdef SK_DEBUG_SIZE 1677 #ifdef SK_DEBUG_SIZE
1681 size_t start = fWriter.bytesWritten(); 1678 size_t start = fWriter.bytesWritten();
1682 #endif 1679 #endif
1683 addInt(byteLength); 1680 addInt(SkToInt(byteLength));
1684 fWriter.writePad(text, byteLength); 1681 fWriter.writePad(text, byteLength);
1685 #ifdef SK_DEBUG_SIZE 1682 #ifdef SK_DEBUG_SIZE
1686 fTextBytes += fWriter.bytesWritten() - start; 1683 fTextBytes += fWriter.bytesWritten() - start;
1687 fTextWrites++; 1684 fTextWrites++;
1688 #endif 1685 #endif
1689 } 1686 }
1690 1687
1691 /////////////////////////////////////////////////////////////////////////////// 1688 ///////////////////////////////////////////////////////////////////////////////
1692 1689
1693 #ifdef SK_DEBUG_SIZE 1690 #ifdef SK_DEBUG_SIZE
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1814 void SkPictureRecord::validateRegions() const { 1811 void SkPictureRecord::validateRegions() const {
1815 int count = fRegions.count(); 1812 int count = fRegions.count();
1816 SkASSERT((unsigned) count < 0x1000); 1813 SkASSERT((unsigned) count < 0x1000);
1817 for (int index = 0; index < count; index++) { 1814 for (int index = 0; index < count; index++) {
1818 const SkFlatData* region = fRegions[index]; 1815 const SkFlatData* region = fRegions[index];
1819 SkASSERT(region); 1816 SkASSERT(region);
1820 // region->validate(); 1817 // region->validate();
1821 } 1818 }
1822 } 1819 }
1823 #endif 1820 #endif
OLDNEW
« no previous file with comments | « src/core/SkPictureRecord.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698