| OLD | NEW |
| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 return this->INHERITED::setDevice(device); | 143 return this->INHERITED::setDevice(device); |
| 144 } | 144 } |
| 145 | 145 |
| 146 int SkPictureRecord::save(SaveFlags flags) { | 146 int SkPictureRecord::save(SaveFlags flags) { |
| 147 // record the offset to us, making it non-positive to distinguish a save | 147 // record the offset to us, making it non-positive to distinguish a save |
| 148 // from a clip entry. | 148 // from a clip entry. |
| 149 fRestoreOffsetStack.push(-(int32_t)fWriter.size()); | 149 fRestoreOffsetStack.push(-(int32_t)fWriter.size()); |
| 150 | 150 |
| 151 // op + flags | 151 // op + flags |
| 152 uint32_t size = kSaveSize; | 152 uint32_t size = kSaveSize; |
| 153 uint32_t initialOffset = this->addDraw(SAVE, &size); | 153 size_t initialOffset = this->addDraw(SAVE, &size); |
| 154 addInt(flags); | 154 addInt(flags); |
| 155 | 155 |
| 156 validate(initialOffset, size); | 156 this->validate(initialOffset, size); |
| 157 return this->INHERITED::save(flags); | 157 return this->INHERITED::save(flags); |
| 158 } | 158 } |
| 159 | 159 |
| 160 int SkPictureRecord::saveLayer(const SkRect* bounds, const SkPaint* paint, | 160 int SkPictureRecord::saveLayer(const SkRect* bounds, const SkPaint* paint, |
| 161 SaveFlags flags) { | 161 SaveFlags flags) { |
| 162 // record the offset to us, making it non-positive to distinguish a save | 162 // record the offset to us, making it non-positive to distinguish a save |
| 163 // from a clip entry. | 163 // from a clip entry. |
| 164 fRestoreOffsetStack.push(-(int32_t)fWriter.size()); | 164 fRestoreOffsetStack.push(-(int32_t)fWriter.size()); |
| 165 | 165 |
| 166 // op + bool for 'bounds' | 166 // op + bool for 'bounds' |
| 167 uint32_t size = 2 * kUInt32Size; | 167 uint32_t size = 2 * kUInt32Size; |
| 168 if (NULL != bounds) { | 168 if (NULL != bounds) { |
| 169 size += sizeof(*bounds); // + rect | 169 size += sizeof(*bounds); // + rect |
| 170 } | 170 } |
| 171 // + paint index + flags | 171 // + paint index + flags |
| 172 size += 2 * kUInt32Size; | 172 size += 2 * kUInt32Size; |
| 173 | 173 |
| 174 SkASSERT(kSaveLayerNoBoundsSize == size || kSaveLayerWithBoundsSize == size)
; | 174 SkASSERT(kSaveLayerNoBoundsSize == size || kSaveLayerWithBoundsSize == size)
; |
| 175 | 175 |
| 176 uint32_t initialOffset = this->addDraw(SAVE_LAYER, &size); | 176 size_t initialOffset = this->addDraw(SAVE_LAYER, &size); |
| 177 addRectPtr(bounds); | 177 addRectPtr(bounds); |
| 178 SkASSERT(initialOffset+getPaintOffset(SAVE_LAYER, size) == fWriter.size()); | 178 SkASSERT(initialOffset+getPaintOffset(SAVE_LAYER, size) == fWriter.size()); |
| 179 addPaintPtr(paint); | 179 addPaintPtr(paint); |
| 180 addInt(flags); | 180 addInt(flags); |
| 181 | 181 |
| 182 if (kNoSavedLayerIndex == fFirstSavedLayerIndex) { | 182 if (kNoSavedLayerIndex == fFirstSavedLayerIndex) { |
| 183 fFirstSavedLayerIndex = fRestoreOffsetStack.count(); | 183 fFirstSavedLayerIndex = fRestoreOffsetStack.count(); |
| 184 } | 184 } |
| 185 | 185 |
| 186 validate(initialOffset, size); | 186 this->validate(initialOffset, size); |
| 187 /* Don't actually call saveLayer, because that will try to allocate an | 187 /* Don't actually call saveLayer, because that will try to allocate an |
| 188 offscreen device (potentially very big) which we don't actually need | 188 offscreen device (potentially very big) which we don't actually need |
| 189 at this time (and may not be able to afford since during record our | 189 at this time (and may not be able to afford since during record our |
| 190 clip starts out the size of the picture, which is often much larger | 190 clip starts out the size of the picture, which is often much larger |
| 191 than the size of the actual device we'll use during playback). | 191 than the size of the actual device we'll use during playback). |
| 192 */ | 192 */ |
| 193 int count = this->INHERITED::save(flags); | 193 int count = this->INHERITED::save(flags); |
| 194 this->clipRectBounds(bounds, flags, NULL); | 194 this->clipRectBounds(bounds, flags, NULL); |
| 195 return count; | 195 return count; |
| 196 } | 196 } |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 if ((fRecordFlags & SkPicture::kDisableRecordOptimizations_RecordingFlag) || | 596 if ((fRecordFlags & SkPicture::kDisableRecordOptimizations_RecordingFlag) || |
| 597 SK_ARRAY_COUNT(gPictureRecordOpts) == opt) { | 597 SK_ARRAY_COUNT(gPictureRecordOpts) == opt) { |
| 598 // No optimization fired so add the RESTORE | 598 // No optimization fired so add the RESTORE |
| 599 fillRestoreOffsetPlaceholdersForCurrentStackLevel((uint32_t)fWriter.size
()); | 599 fillRestoreOffsetPlaceholdersForCurrentStackLevel((uint32_t)fWriter.size
()); |
| 600 size = 1 * kUInt32Size; // RESTORE consists solely of 1 op code | 600 size = 1 * kUInt32Size; // RESTORE consists solely of 1 op code |
| 601 initialOffset = this->addDraw(RESTORE, &size); | 601 initialOffset = this->addDraw(RESTORE, &size); |
| 602 } | 602 } |
| 603 | 603 |
| 604 fRestoreOffsetStack.pop(); | 604 fRestoreOffsetStack.pop(); |
| 605 | 605 |
| 606 validate(initialOffset, size); | 606 this->validate(initialOffset, size); |
| 607 return this->INHERITED::restore(); | 607 return this->INHERITED::restore(); |
| 608 } | 608 } |
| 609 | 609 |
| 610 bool SkPictureRecord::translate(SkScalar dx, SkScalar dy) { | 610 bool SkPictureRecord::translate(SkScalar dx, SkScalar dy) { |
| 611 // op + dx + dy | 611 // op + dx + dy |
| 612 uint32_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar); | 612 uint32_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar); |
| 613 uint32_t initialOffset = this->addDraw(TRANSLATE, &size); | 613 size_t initialOffset = this->addDraw(TRANSLATE, &size); |
| 614 addScalar(dx); | 614 addScalar(dx); |
| 615 addScalar(dy); | 615 addScalar(dy); |
| 616 validate(initialOffset, size); | 616 this->validate(initialOffset, size); |
| 617 return this->INHERITED::translate(dx, dy); | 617 return this->INHERITED::translate(dx, dy); |
| 618 } | 618 } |
| 619 | 619 |
| 620 bool SkPictureRecord::scale(SkScalar sx, SkScalar sy) { | 620 bool SkPictureRecord::scale(SkScalar sx, SkScalar sy) { |
| 621 // op + sx + sy | 621 // op + sx + sy |
| 622 uint32_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar); | 622 uint32_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar); |
| 623 uint32_t initialOffset = this->addDraw(SCALE, &size); | 623 size_t initialOffset = this->addDraw(SCALE, &size); |
| 624 addScalar(sx); | 624 addScalar(sx); |
| 625 addScalar(sy); | 625 addScalar(sy); |
| 626 validate(initialOffset, size); | 626 this->validate(initialOffset, size); |
| 627 return this->INHERITED::scale(sx, sy); | 627 return this->INHERITED::scale(sx, sy); |
| 628 } | 628 } |
| 629 | 629 |
| 630 bool SkPictureRecord::rotate(SkScalar degrees) { | 630 bool SkPictureRecord::rotate(SkScalar degrees) { |
| 631 // op + degrees | 631 // op + degrees |
| 632 uint32_t size = 1 * kUInt32Size + sizeof(SkScalar); | 632 uint32_t size = 1 * kUInt32Size + sizeof(SkScalar); |
| 633 uint32_t initialOffset = this->addDraw(ROTATE, &size); | 633 size_t initialOffset = this->addDraw(ROTATE, &size); |
| 634 addScalar(degrees); | 634 addScalar(degrees); |
| 635 validate(initialOffset, size); | 635 this->validate(initialOffset, size); |
| 636 return this->INHERITED::rotate(degrees); | 636 return this->INHERITED::rotate(degrees); |
| 637 } | 637 } |
| 638 | 638 |
| 639 bool SkPictureRecord::skew(SkScalar sx, SkScalar sy) { | 639 bool SkPictureRecord::skew(SkScalar sx, SkScalar sy) { |
| 640 // op + sx + sy | 640 // op + sx + sy |
| 641 uint32_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar); | 641 uint32_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar); |
| 642 uint32_t initialOffset = this->addDraw(SKEW, &size); | 642 size_t initialOffset = this->addDraw(SKEW, &size); |
| 643 addScalar(sx); | 643 addScalar(sx); |
| 644 addScalar(sy); | 644 addScalar(sy); |
| 645 validate(initialOffset, size); | 645 this->validate(initialOffset, size); |
| 646 return this->INHERITED::skew(sx, sy); | 646 return this->INHERITED::skew(sx, sy); |
| 647 } | 647 } |
| 648 | 648 |
| 649 bool SkPictureRecord::concat(const SkMatrix& matrix) { | 649 bool SkPictureRecord::concat(const SkMatrix& matrix) { |
| 650 validate(fWriter.size(), 0); | 650 this->validate(fWriter.size(), 0); |
| 651 // op + matrix index | 651 // op + matrix index |
| 652 uint32_t size = 2 * kUInt32Size; | 652 uint32_t size = 2 * kUInt32Size; |
| 653 uint32_t initialOffset = this->addDraw(CONCAT, &size); | 653 size_t initialOffset = this->addDraw(CONCAT, &size); |
| 654 addMatrix(matrix); | 654 addMatrix(matrix); |
| 655 validate(initialOffset, size); | 655 this->validate(initialOffset, size); |
| 656 return this->INHERITED::concat(matrix); | 656 return this->INHERITED::concat(matrix); |
| 657 } | 657 } |
| 658 | 658 |
| 659 void SkPictureRecord::setMatrix(const SkMatrix& matrix) { | 659 void SkPictureRecord::setMatrix(const SkMatrix& matrix) { |
| 660 validate(fWriter.size(), 0); | 660 this->validate(fWriter.size(), 0); |
| 661 // op + matrix index | 661 // op + matrix index |
| 662 uint32_t size = 2 * kUInt32Size; | 662 uint32_t size = 2 * kUInt32Size; |
| 663 uint32_t initialOffset = this->addDraw(SET_MATRIX, &size); | 663 size_t initialOffset = this->addDraw(SET_MATRIX, &size); |
| 664 addMatrix(matrix); | 664 addMatrix(matrix); |
| 665 validate(initialOffset, size); | 665 this->validate(initialOffset, size); |
| 666 this->INHERITED::setMatrix(matrix); | 666 this->INHERITED::setMatrix(matrix); |
| 667 } | 667 } |
| 668 | 668 |
| 669 static bool regionOpExpands(SkRegion::Op op) { | 669 static bool regionOpExpands(SkRegion::Op op) { |
| 670 switch (op) { | 670 switch (op) { |
| 671 case SkRegion::kUnion_Op: | 671 case SkRegion::kUnion_Op: |
| 672 case SkRegion::kXOR_Op: | 672 case SkRegion::kXOR_Op: |
| 673 case SkRegion::kReverseDifference_Op: | 673 case SkRegion::kReverseDifference_Op: |
| 674 case SkRegion::kReplace_Op: | 674 case SkRegion::kReplace_Op: |
| 675 return true; | 675 return true; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 } | 740 } |
| 741 | 741 |
| 742 bool SkPictureRecord::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { | 742 bool SkPictureRecord::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { |
| 743 // id + rect + clip params | 743 // id + rect + clip params |
| 744 uint32_t size = 1 * kUInt32Size + sizeof(rect) + 1 * kUInt32Size; | 744 uint32_t size = 1 * kUInt32Size + sizeof(rect) + 1 * kUInt32Size; |
| 745 // recordRestoreOffsetPlaceholder doesn't always write an offset | 745 // recordRestoreOffsetPlaceholder doesn't always write an offset |
| 746 if (!fRestoreOffsetStack.isEmpty()) { | 746 if (!fRestoreOffsetStack.isEmpty()) { |
| 747 // + restore offset | 747 // + restore offset |
| 748 size += kUInt32Size; | 748 size += kUInt32Size; |
| 749 } | 749 } |
| 750 uint32_t initialOffset = this->addDraw(CLIP_RECT, &size); | 750 size_t initialOffset = this->addDraw(CLIP_RECT, &size); |
| 751 addRect(rect); | 751 addRect(rect); |
| 752 addInt(ClipParams_pack(op, doAA)); | 752 addInt(ClipParams_pack(op, doAA)); |
| 753 recordRestoreOffsetPlaceholder(op); | 753 recordRestoreOffsetPlaceholder(op); |
| 754 | 754 |
| 755 validate(initialOffset, size); | 755 this->validate(initialOffset, size); |
| 756 return this->INHERITED::clipRect(rect, op, doAA); | 756 return this->INHERITED::clipRect(rect, op, doAA); |
| 757 } | 757 } |
| 758 | 758 |
| 759 bool SkPictureRecord::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA
) { | 759 bool SkPictureRecord::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA
) { |
| 760 if (rrect.isRect()) { | 760 if (rrect.isRect()) { |
| 761 return this->SkPictureRecord::clipRect(rrect.getBounds(), op, doAA); | 761 return this->SkPictureRecord::clipRect(rrect.getBounds(), op, doAA); |
| 762 } | 762 } |
| 763 | 763 |
| 764 // op + rrect + clip params | 764 // op + rrect + clip params |
| 765 uint32_t size = 1 * kUInt32Size + SkRRect::kSizeInMemory + 1 * kUInt32Size; | 765 uint32_t size = 1 * kUInt32Size + SkRRect::kSizeInMemory + 1 * kUInt32Size; |
| 766 // recordRestoreOffsetPlaceholder doesn't always write an offset | 766 // recordRestoreOffsetPlaceholder doesn't always write an offset |
| 767 if (!fRestoreOffsetStack.isEmpty()) { | 767 if (!fRestoreOffsetStack.isEmpty()) { |
| 768 // + restore offset | 768 // + restore offset |
| 769 size += kUInt32Size; | 769 size += kUInt32Size; |
| 770 } | 770 } |
| 771 uint32_t initialOffset = this->addDraw(CLIP_RRECT, &size); | 771 size_t initialOffset = this->addDraw(CLIP_RRECT, &size); |
| 772 addRRect(rrect); | 772 addRRect(rrect); |
| 773 addInt(ClipParams_pack(op, doAA)); | 773 addInt(ClipParams_pack(op, doAA)); |
| 774 recordRestoreOffsetPlaceholder(op); | 774 recordRestoreOffsetPlaceholder(op); |
| 775 | 775 |
| 776 validate(initialOffset, size); | 776 this->validate(initialOffset, size); |
| 777 | 777 |
| 778 if (fRecordFlags & SkPicture::kUsePathBoundsForClip_RecordingFlag) { | 778 if (fRecordFlags & SkPicture::kUsePathBoundsForClip_RecordingFlag) { |
| 779 return this->updateClipConservativelyUsingBounds(rrect.getBounds(), op,
false); | 779 return this->updateClipConservativelyUsingBounds(rrect.getBounds(), op,
false); |
| 780 } else { | 780 } else { |
| 781 return this->INHERITED::clipRRect(rrect, op, doAA); | 781 return this->INHERITED::clipRRect(rrect, op, doAA); |
| 782 } | 782 } |
| 783 } | 783 } |
| 784 | 784 |
| 785 bool SkPictureRecord::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { | 785 bool SkPictureRecord::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { |
| 786 | 786 |
| 787 SkRect r; | 787 SkRect r; |
| 788 if (!path.isInverseFillType() && path.isRect(&r)) { | 788 if (!path.isInverseFillType() && path.isRect(&r)) { |
| 789 return this->clipRect(r, op, doAA); | 789 return this->clipRect(r, op, doAA); |
| 790 } | 790 } |
| 791 | 791 |
| 792 // op + path index + clip params | 792 // op + path index + clip params |
| 793 uint32_t size = 3 * kUInt32Size; | 793 uint32_t size = 3 * kUInt32Size; |
| 794 // recordRestoreOffsetPlaceholder doesn't always write an offset | 794 // recordRestoreOffsetPlaceholder doesn't always write an offset |
| 795 if (!fRestoreOffsetStack.isEmpty()) { | 795 if (!fRestoreOffsetStack.isEmpty()) { |
| 796 // + restore offset | 796 // + restore offset |
| 797 size += kUInt32Size; | 797 size += kUInt32Size; |
| 798 } | 798 } |
| 799 uint32_t initialOffset = this->addDraw(CLIP_PATH, &size); | 799 size_t initialOffset = this->addDraw(CLIP_PATH, &size); |
| 800 addPath(path); | 800 addPath(path); |
| 801 addInt(ClipParams_pack(op, doAA)); | 801 addInt(ClipParams_pack(op, doAA)); |
| 802 recordRestoreOffsetPlaceholder(op); | 802 recordRestoreOffsetPlaceholder(op); |
| 803 | 803 |
| 804 validate(initialOffset, size); | 804 this->validate(initialOffset, size); |
| 805 | 805 |
| 806 if (fRecordFlags & SkPicture::kUsePathBoundsForClip_RecordingFlag) { | 806 if (fRecordFlags & SkPicture::kUsePathBoundsForClip_RecordingFlag) { |
| 807 return this->updateClipConservativelyUsingBounds(path.getBounds(), op, | 807 return this->updateClipConservativelyUsingBounds(path.getBounds(), op, |
| 808 path.isInverseFillType(
)); | 808 path.isInverseFillType(
)); |
| 809 } else { | 809 } else { |
| 810 return this->INHERITED::clipPath(path, op, doAA); | 810 return this->INHERITED::clipPath(path, op, doAA); |
| 811 } | 811 } |
| 812 } | 812 } |
| 813 | 813 |
| 814 bool SkPictureRecord::clipRegion(const SkRegion& region, SkRegion::Op op) { | 814 bool SkPictureRecord::clipRegion(const SkRegion& region, SkRegion::Op op) { |
| 815 // op + region index + clip params | 815 // op + region index + clip params |
| 816 uint32_t size = 3 * kUInt32Size; | 816 uint32_t size = 3 * kUInt32Size; |
| 817 // recordRestoreOffsetPlaceholder doesn't always write an offset | 817 // recordRestoreOffsetPlaceholder doesn't always write an offset |
| 818 if (!fRestoreOffsetStack.isEmpty()) { | 818 if (!fRestoreOffsetStack.isEmpty()) { |
| 819 // + restore offset | 819 // + restore offset |
| 820 size += kUInt32Size; | 820 size += kUInt32Size; |
| 821 } | 821 } |
| 822 uint32_t initialOffset = this->addDraw(CLIP_REGION, &size); | 822 size_t initialOffset = this->addDraw(CLIP_REGION, &size); |
| 823 addRegion(region); | 823 addRegion(region); |
| 824 addInt(ClipParams_pack(op, false)); | 824 addInt(ClipParams_pack(op, false)); |
| 825 recordRestoreOffsetPlaceholder(op); | 825 recordRestoreOffsetPlaceholder(op); |
| 826 | 826 |
| 827 validate(initialOffset, size); | 827 this->validate(initialOffset, size); |
| 828 return this->INHERITED::clipRegion(region, op); | 828 return this->INHERITED::clipRegion(region, op); |
| 829 } | 829 } |
| 830 | 830 |
| 831 void SkPictureRecord::clear(SkColor color) { | 831 void SkPictureRecord::clear(SkColor color) { |
| 832 // op + color | 832 // op + color |
| 833 uint32_t size = 2 * kUInt32Size; | 833 uint32_t size = 2 * kUInt32Size; |
| 834 uint32_t initialOffset = this->addDraw(DRAW_CLEAR, &size); | 834 size_t initialOffset = this->addDraw(DRAW_CLEAR, &size); |
| 835 addInt(color); | 835 addInt(color); |
| 836 validate(initialOffset, size); | 836 this->validate(initialOffset, size); |
| 837 } | 837 } |
| 838 | 838 |
| 839 void SkPictureRecord::drawPaint(const SkPaint& paint) { | 839 void SkPictureRecord::drawPaint(const SkPaint& paint) { |
| 840 // op + paint index | 840 // op + paint index |
| 841 uint32_t size = 2 * kUInt32Size; | 841 uint32_t size = 2 * kUInt32Size; |
| 842 uint32_t initialOffset = this->addDraw(DRAW_PAINT, &size); | 842 size_t initialOffset = this->addDraw(DRAW_PAINT, &size); |
| 843 SkASSERT(initialOffset+getPaintOffset(DRAW_PAINT, size) == fWriter.size()); | 843 SkASSERT(initialOffset+getPaintOffset(DRAW_PAINT, size) == fWriter.size()); |
| 844 addPaint(paint); | 844 addPaint(paint); |
| 845 validate(initialOffset, size); | 845 this->validate(initialOffset, size); |
| 846 } | 846 } |
| 847 | 847 |
| 848 void SkPictureRecord::drawPoints(PointMode mode, size_t count, const SkPoint pts
[], | 848 void SkPictureRecord::drawPoints(PointMode mode, size_t count, const SkPoint pts
[], |
| 849 const SkPaint& paint) { | 849 const SkPaint& paint) { |
| 850 // op + paint index + mode + count + point data | 850 // op + paint index + mode + count + point data |
| 851 uint32_t size = 4 * kUInt32Size + count * sizeof(SkPoint); | 851 uint32_t size = 4 * kUInt32Size + count * sizeof(SkPoint); |
| 852 uint32_t initialOffset = this->addDraw(DRAW_POINTS, &size); | 852 size_t initialOffset = this->addDraw(DRAW_POINTS, &size); |
| 853 SkASSERT(initialOffset+getPaintOffset(DRAW_POINTS, size) == fWriter.size()); | 853 SkASSERT(initialOffset+getPaintOffset(DRAW_POINTS, size) == fWriter.size()); |
| 854 addPaint(paint); | 854 addPaint(paint); |
| 855 addInt(mode); | 855 addInt(mode); |
| 856 addInt(count); | 856 addInt(count); |
| 857 fWriter.writeMul4(pts, count * sizeof(SkPoint)); | 857 fWriter.writeMul4(pts, count * sizeof(SkPoint)); |
| 858 validate(initialOffset, size); | 858 this->validate(initialOffset, size); |
| 859 } | 859 } |
| 860 | 860 |
| 861 void SkPictureRecord::drawOval(const SkRect& oval, const SkPaint& paint) { | 861 void SkPictureRecord::drawOval(const SkRect& oval, const SkPaint& paint) { |
| 862 // op + paint index + rect | 862 // op + paint index + rect |
| 863 uint32_t size = 2 * kUInt32Size + sizeof(oval); | 863 uint32_t size = 2 * kUInt32Size + sizeof(oval); |
| 864 uint32_t initialOffset = this->addDraw(DRAW_OVAL, &size); | 864 size_t initialOffset = this->addDraw(DRAW_OVAL, &size); |
| 865 SkASSERT(initialOffset+getPaintOffset(DRAW_OVAL, size) == fWriter.size()); | 865 SkASSERT(initialOffset+getPaintOffset(DRAW_OVAL, size) == fWriter.size()); |
| 866 addPaint(paint); | 866 addPaint(paint); |
| 867 addRect(oval); | 867 addRect(oval); |
| 868 validate(initialOffset, size); | 868 this->validate(initialOffset, size); |
| 869 } | 869 } |
| 870 | 870 |
| 871 void SkPictureRecord::drawRect(const SkRect& rect, const SkPaint& paint) { | 871 void SkPictureRecord::drawRect(const SkRect& rect, const SkPaint& paint) { |
| 872 // op + paint index + rect | 872 // op + paint index + rect |
| 873 uint32_t size = 2 * kUInt32Size + sizeof(rect); | 873 uint32_t size = 2 * kUInt32Size + sizeof(rect); |
| 874 uint32_t initialOffset = this->addDraw(DRAW_RECT, &size); | 874 size_t initialOffset = this->addDraw(DRAW_RECT, &size); |
| 875 SkASSERT(initialOffset+getPaintOffset(DRAW_RECT, size) == fWriter.size()); | 875 SkASSERT(initialOffset+getPaintOffset(DRAW_RECT, size) == fWriter.size()); |
| 876 addPaint(paint); | 876 addPaint(paint); |
| 877 addRect(rect); | 877 addRect(rect); |
| 878 validate(initialOffset, size); | 878 this->validate(initialOffset, size); |
| 879 } | 879 } |
| 880 | 880 |
| 881 void SkPictureRecord::drawRRect(const SkRRect& rrect, const SkPaint& paint) { | 881 void SkPictureRecord::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
| 882 if (rrect.isRect()) { | 882 if (rrect.isRect()) { |
| 883 this->SkPictureRecord::drawRect(rrect.getBounds(), paint); | 883 this->SkPictureRecord::drawRect(rrect.getBounds(), paint); |
| 884 } else if (rrect.isOval()) { | 884 } else if (rrect.isOval()) { |
| 885 this->SkPictureRecord::drawOval(rrect.getBounds(), paint); | 885 this->SkPictureRecord::drawOval(rrect.getBounds(), paint); |
| 886 } else { | 886 } else { |
| 887 // op + paint index + rrect | 887 // op + paint index + rrect |
| 888 uint32_t initialOffset, size; | 888 uint32_t initialOffset, size; |
| 889 size = 2 * kUInt32Size + SkRRect::kSizeInMemory; | 889 size = 2 * kUInt32Size + SkRRect::kSizeInMemory; |
| 890 initialOffset = this->addDraw(DRAW_RRECT, &size); | 890 initialOffset = this->addDraw(DRAW_RRECT, &size); |
| 891 SkASSERT(initialOffset+getPaintOffset(DRAW_RRECT, size) == fWriter.size(
)); | 891 SkASSERT(initialOffset+getPaintOffset(DRAW_RRECT, size) == fWriter.size(
)); |
| 892 addPaint(paint); | 892 addPaint(paint); |
| 893 addRRect(rrect); | 893 addRRect(rrect); |
| 894 validate(initialOffset, size); | 894 this->validate(initialOffset, size); |
| 895 } | 895 } |
| 896 } | 896 } |
| 897 | 897 |
| 898 void SkPictureRecord::drawPath(const SkPath& path, const SkPaint& paint) { | 898 void SkPictureRecord::drawPath(const SkPath& path, const SkPaint& paint) { |
| 899 // op + paint index + path index | 899 // op + paint index + path index |
| 900 uint32_t size = 3 * kUInt32Size; | 900 uint32_t size = 3 * kUInt32Size; |
| 901 uint32_t initialOffset = this->addDraw(DRAW_PATH, &size); | 901 size_t initialOffset = this->addDraw(DRAW_PATH, &size); |
| 902 SkASSERT(initialOffset+getPaintOffset(DRAW_PATH, size) == fWriter.size()); | 902 SkASSERT(initialOffset+getPaintOffset(DRAW_PATH, size) == fWriter.size()); |
| 903 addPaint(paint); | 903 addPaint(paint); |
| 904 addPath(path); | 904 addPath(path); |
| 905 validate(initialOffset, size); | 905 this->validate(initialOffset, size); |
| 906 } | 906 } |
| 907 | 907 |
| 908 void SkPictureRecord::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar
top, | 908 void SkPictureRecord::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar
top, |
| 909 const SkPaint* paint = NULL) { | 909 const SkPaint* paint = NULL) { |
| 910 // op + paint index + bitmap index + left + top | 910 // op + paint index + bitmap index + left + top |
| 911 uint32_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar); | 911 uint32_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar); |
| 912 uint32_t initialOffset = this->addDraw(DRAW_BITMAP, &size); | 912 size_t initialOffset = this->addDraw(DRAW_BITMAP, &size); |
| 913 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP, size) == fWriter.size()); | 913 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP, size) == fWriter.size()); |
| 914 addPaintPtr(paint); | 914 addPaintPtr(paint); |
| 915 addBitmap(bitmap); | 915 addBitmap(bitmap); |
| 916 addScalar(left); | 916 addScalar(left); |
| 917 addScalar(top); | 917 addScalar(top); |
| 918 validate(initialOffset, size); | 918 this->validate(initialOffset, size); |
| 919 } | 919 } |
| 920 | 920 |
| 921 void SkPictureRecord::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect*
src, | 921 void SkPictureRecord::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect*
src, |
| 922 const SkRect& dst, const SkPaint* pai
nt, | 922 const SkRect& dst, const SkPaint* pai
nt, |
| 923 DrawBitmapRectFlags flags) { | 923 DrawBitmapRectFlags flags) { |
| 924 // id + paint index + bitmap index + bool for 'src' + flags | 924 // id + paint index + bitmap index + bool for 'src' + flags |
| 925 uint32_t size = 5 * kUInt32Size; | 925 uint32_t size = 5 * kUInt32Size; |
| 926 if (NULL != src) { | 926 if (NULL != src) { |
| 927 size += sizeof(*src); // + rect | 927 size += sizeof(*src); // + rect |
| 928 } | 928 } |
| 929 size += sizeof(dst); // + rect | 929 size += sizeof(dst); // + rect |
| 930 | 930 |
| 931 uint32_t initialOffset = this->addDraw(DRAW_BITMAP_RECT_TO_RECT, &size); | 931 size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT_TO_RECT, &size); |
| 932 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_RECT_TO_RECT, size) == fWr
iter.size()); | 932 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_RECT_TO_RECT, size) == fWr
iter.size()); |
| 933 addPaintPtr(paint); | 933 addPaintPtr(paint); |
| 934 addBitmap(bitmap); | 934 addBitmap(bitmap); |
| 935 addRectPtr(src); // may be null | 935 addRectPtr(src); // may be null |
| 936 addRect(dst); | 936 addRect(dst); |
| 937 addInt(flags); | 937 addInt(flags); |
| 938 validate(initialOffset, size); | 938 this->validate(initialOffset, size); |
| 939 } | 939 } |
| 940 | 940 |
| 941 void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m
atrix, | 941 void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m
atrix, |
| 942 const SkPaint* paint) { | 942 const SkPaint* paint) { |
| 943 // id + paint index + bitmap index + matrix index | 943 // id + paint index + bitmap index + matrix index |
| 944 uint32_t size = 4 * kUInt32Size; | 944 uint32_t size = 4 * kUInt32Size; |
| 945 uint32_t initialOffset = this->addDraw(DRAW_BITMAP_MATRIX, &size); | 945 size_t initialOffset = this->addDraw(DRAW_BITMAP_MATRIX, &size); |
| 946 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_MATRIX, size) == fWriter.s
ize()); | 946 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_MATRIX, size) == fWriter.s
ize()); |
| 947 addPaintPtr(paint); | 947 addPaintPtr(paint); |
| 948 addBitmap(bitmap); | 948 addBitmap(bitmap); |
| 949 addMatrix(matrix); | 949 addMatrix(matrix); |
| 950 validate(initialOffset, size); | 950 this->validate(initialOffset, size); |
| 951 } | 951 } |
| 952 | 952 |
| 953 void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& cent
er, | 953 void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& cent
er, |
| 954 const SkRect& dst, const SkPaint* paint) { | 954 const SkRect& dst, const SkPaint* paint) { |
| 955 // op + paint index + bitmap id + center + dst rect | 955 // op + paint index + bitmap id + center + dst rect |
| 956 uint32_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst); | 956 uint32_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst); |
| 957 uint32_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size); | 957 size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size); |
| 958 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_NINE, size) == fWriter.siz
e()); | 958 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_NINE, size) == fWriter.siz
e()); |
| 959 addPaintPtr(paint); | 959 addPaintPtr(paint); |
| 960 addBitmap(bitmap); | 960 addBitmap(bitmap); |
| 961 addIRect(center); | 961 addIRect(center); |
| 962 addRect(dst); | 962 addRect(dst); |
| 963 validate(initialOffset, size); | 963 this->validate(initialOffset, size); |
| 964 } | 964 } |
| 965 | 965 |
| 966 void SkPictureRecord::drawSprite(const SkBitmap& bitmap, int left, int top, | 966 void SkPictureRecord::drawSprite(const SkBitmap& bitmap, int left, int top, |
| 967 const SkPaint* paint = NULL) { | 967 const SkPaint* paint = NULL) { |
| 968 // op + paint index + bitmap index + left + top | 968 // op + paint index + bitmap index + left + top |
| 969 uint32_t size = 5 * kUInt32Size; | 969 uint32_t size = 5 * kUInt32Size; |
| 970 uint32_t initialOffset = this->addDraw(DRAW_SPRITE, &size); | 970 size_t initialOffset = this->addDraw(DRAW_SPRITE, &size); |
| 971 SkASSERT(initialOffset+getPaintOffset(DRAW_SPRITE, size) == fWriter.size()); | 971 SkASSERT(initialOffset+getPaintOffset(DRAW_SPRITE, size) == fWriter.size()); |
| 972 addPaintPtr(paint); | 972 addPaintPtr(paint); |
| 973 addBitmap(bitmap); | 973 addBitmap(bitmap); |
| 974 addInt(left); | 974 addInt(left); |
| 975 addInt(top); | 975 addInt(top); |
| 976 validate(initialOffset, size); | 976 this->validate(initialOffset, size); |
| 977 } | 977 } |
| 978 | 978 |
| 979 void SkPictureRecord::ComputeFontMetricsTopBottom(const SkPaint& paint, SkScalar
topbot[2]) { | 979 void SkPictureRecord::ComputeFontMetricsTopBottom(const SkPaint& paint, SkScalar
topbot[2]) { |
| 980 SkPaint::FontMetrics metrics; | 980 SkPaint::FontMetrics metrics; |
| 981 paint.getFontMetrics(&metrics); | 981 paint.getFontMetrics(&metrics); |
| 982 SkRect bounds; | 982 SkRect bounds; |
| 983 // construct a rect so we can see any adjustments from the paint. | 983 // construct a rect so we can see any adjustments from the paint. |
| 984 // we use 0,1 for left,right, just so the rect isn't empty | 984 // we use 0,1 for left,right, just so the rect isn't empty |
| 985 bounds.set(0, metrics.fTop, SK_Scalar1, metrics.fBottom); | 985 bounds.set(0, metrics.fTop, SK_Scalar1, metrics.fBottom); |
| 986 (void)paint.computeFastBounds(bounds, &bounds); | 986 (void)paint.computeFastBounds(bounds, &bounds); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 999 SkScalar y, const SkPaint& paint) { | 999 SkScalar y, const SkPaint& paint) { |
| 1000 bool fast = !paint.isVerticalText() && paint.canComputeFastBounds(); | 1000 bool fast = !paint.isVerticalText() && paint.canComputeFastBounds(); |
| 1001 | 1001 |
| 1002 // op + paint index + length + 'length' worth of chars + x + y | 1002 // op + paint index + length + 'length' worth of chars + x + y |
| 1003 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 2 * sizeof(SkScalar
); | 1003 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 2 * sizeof(SkScalar
); |
| 1004 if (fast) { | 1004 if (fast) { |
| 1005 size += 2 * sizeof(SkScalar); // + top & bottom | 1005 size += 2 * sizeof(SkScalar); // + top & bottom |
| 1006 } | 1006 } |
| 1007 | 1007 |
| 1008 DrawType op = fast ? DRAW_TEXT_TOP_BOTTOM : DRAW_TEXT; | 1008 DrawType op = fast ? DRAW_TEXT_TOP_BOTTOM : DRAW_TEXT; |
| 1009 uint32_t initialOffset = this->addDraw(op, &size); | 1009 size_t initialOffset = this->addDraw(op, &size); |
| 1010 SkASSERT(initialOffset+getPaintOffset(op, size) == fWriter.size()); | 1010 SkASSERT(initialOffset+getPaintOffset(op, size) == fWriter.size()); |
| 1011 const SkFlatData* flatPaintData = addPaint(paint); | 1011 const SkFlatData* flatPaintData = addPaint(paint); |
| 1012 SkASSERT(flatPaintData); | 1012 SkASSERT(flatPaintData); |
| 1013 addText(text, byteLength); | 1013 addText(text, byteLength); |
| 1014 addScalar(x); | 1014 addScalar(x); |
| 1015 addScalar(y); | 1015 addScalar(y); |
| 1016 if (fast) { | 1016 if (fast) { |
| 1017 addFontMetricsTopBottom(paint, *flatPaintData, y, y); | 1017 addFontMetricsTopBottom(paint, *flatPaintData, y, y); |
| 1018 } | 1018 } |
| 1019 validate(initialOffset, size); | 1019 this->validate(initialOffset, size); |
| 1020 } | 1020 } |
| 1021 | 1021 |
| 1022 void SkPictureRecord::drawPosText(const void* text, size_t byteLength, | 1022 void SkPictureRecord::drawPosText(const void* text, size_t byteLength, |
| 1023 const SkPoint pos[], const SkPaint& paint) { | 1023 const SkPoint pos[], const SkPaint& paint) { |
| 1024 size_t points = paint.countText(text, byteLength); | 1024 size_t points = paint.countText(text, byteLength); |
| 1025 if (0 == points) | 1025 if (0 == points) |
| 1026 return; | 1026 return; |
| 1027 | 1027 |
| 1028 bool canUseDrawH = true; | 1028 bool canUseDrawH = true; |
| 1029 SkScalar minY = pos[0].fY; | 1029 SkScalar minY = pos[0].fY; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1065 DrawType op; | 1065 DrawType op; |
| 1066 if (fast) { | 1066 if (fast) { |
| 1067 op = DRAW_POS_TEXT_H_TOP_BOTTOM; | 1067 op = DRAW_POS_TEXT_H_TOP_BOTTOM; |
| 1068 } else if (canUseDrawH) { | 1068 } else if (canUseDrawH) { |
| 1069 op = DRAW_POS_TEXT_H; | 1069 op = DRAW_POS_TEXT_H; |
| 1070 } else if (fastBounds) { | 1070 } else if (fastBounds) { |
| 1071 op = DRAW_POS_TEXT_TOP_BOTTOM; | 1071 op = DRAW_POS_TEXT_TOP_BOTTOM; |
| 1072 } else { | 1072 } else { |
| 1073 op = DRAW_POS_TEXT; | 1073 op = DRAW_POS_TEXT; |
| 1074 } | 1074 } |
| 1075 uint32_t initialOffset = this->addDraw(op, &size); | 1075 size_t initialOffset = this->addDraw(op, &size); |
| 1076 SkASSERT(initialOffset+getPaintOffset(op, size) == fWriter.size()); | 1076 SkASSERT(initialOffset+getPaintOffset(op, size) == fWriter.size()); |
| 1077 const SkFlatData* flatPaintData = addPaint(paint); | 1077 const SkFlatData* flatPaintData = addPaint(paint); |
| 1078 SkASSERT(flatPaintData); | 1078 SkASSERT(flatPaintData); |
| 1079 addText(text, byteLength); | 1079 addText(text, byteLength); |
| 1080 addInt(points); | 1080 addInt(points); |
| 1081 | 1081 |
| 1082 #ifdef SK_DEBUG_SIZE | 1082 #ifdef SK_DEBUG_SIZE |
| 1083 size_t start = fWriter.size(); | 1083 size_t start = fWriter.size(); |
| 1084 #endif | 1084 #endif |
| 1085 if (canUseDrawH) { | 1085 if (canUseDrawH) { |
| 1086 if (fast) { | 1086 if (fast) { |
| 1087 addFontMetricsTopBottom(paint, *flatPaintData, pos[0].fY, pos[0].fY)
; | 1087 addFontMetricsTopBottom(paint, *flatPaintData, pos[0].fY, pos[0].fY)
; |
| 1088 } | 1088 } |
| 1089 addScalar(pos[0].fY); | 1089 addScalar(pos[0].fY); |
| 1090 SkScalar* xptr = (SkScalar*)fWriter.reserve(points * sizeof(SkScalar)); | 1090 SkScalar* xptr = (SkScalar*)fWriter.reserve(points * sizeof(SkScalar)); |
| 1091 for (size_t index = 0; index < points; index++) | 1091 for (size_t index = 0; index < points; index++) |
| 1092 *xptr++ = pos[index].fX; | 1092 *xptr++ = pos[index].fX; |
| 1093 } else { | 1093 } else { |
| 1094 fWriter.writeMul4(pos, points * sizeof(SkPoint)); | 1094 fWriter.writeMul4(pos, points * sizeof(SkPoint)); |
| 1095 if (fastBounds) { | 1095 if (fastBounds) { |
| 1096 addFontMetricsTopBottom(paint, *flatPaintData, minY, maxY); | 1096 addFontMetricsTopBottom(paint, *flatPaintData, minY, maxY); |
| 1097 } | 1097 } |
| 1098 } | 1098 } |
| 1099 #ifdef SK_DEBUG_SIZE | 1099 #ifdef SK_DEBUG_SIZE |
| 1100 fPointBytes += fWriter.size() - start; | 1100 fPointBytes += fWriter.size() - start; |
| 1101 fPointWrites += points; | 1101 fPointWrites += points; |
| 1102 #endif | 1102 #endif |
| 1103 validate(initialOffset, size); | 1103 this->validate(initialOffset, size); |
| 1104 } | 1104 } |
| 1105 | 1105 |
| 1106 void SkPictureRecord::drawPosTextH(const void* text, size_t byteLength, | 1106 void SkPictureRecord::drawPosTextH(const void* text, size_t byteLength, |
| 1107 const SkScalar xpos[], SkScalar constY, | 1107 const SkScalar xpos[], SkScalar constY, |
| 1108 const SkPaint& paint) { | 1108 const SkPaint& paint) { |
| 1109 | 1109 |
| 1110 const SkFlatData* flatPaintData = this->getFlatPaintData(paint); | 1110 const SkFlatData* flatPaintData = this->getFlatPaintData(paint); |
| 1111 drawPosTextHImpl(text, byteLength, xpos, constY, paint, flatPaintData); | 1111 drawPosTextHImpl(text, byteLength, xpos, constY, paint, flatPaintData); |
| 1112 } | 1112 } |
| 1113 | 1113 |
| 1114 void SkPictureRecord::drawPosTextHImpl(const void* text, size_t byteLength, | 1114 void SkPictureRecord::drawPosTextHImpl(const void* text, size_t byteLength, |
| 1115 const SkScalar xpos[], SkScalar constY, | 1115 const SkScalar xpos[], SkScalar constY, |
| 1116 const SkPaint& paint, const SkFlatData* flatPaintData)
{ | 1116 const SkPaint& paint, const SkFlatData* flatPaintData)
{ |
| 1117 size_t points = paint.countText(text, byteLength); | 1117 size_t points = paint.countText(text, byteLength); |
| 1118 if (0 == points) | 1118 if (0 == points) |
| 1119 return; | 1119 return; |
| 1120 | 1120 |
| 1121 bool fast = !paint.isVerticalText() && paint.canComputeFastBounds(); | 1121 bool fast = !paint.isVerticalText() && paint.canComputeFastBounds(); |
| 1122 | 1122 |
| 1123 // op + paint index + length + 'length' worth of data + num points | 1123 // op + paint index + length + 'length' worth of data + num points |
| 1124 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 1 * kUInt32Size; | 1124 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 1 * kUInt32Size; |
| 1125 if (fast) { | 1125 if (fast) { |
| 1126 size += 2 * sizeof(SkScalar); // + top & bottom | 1126 size += 2 * sizeof(SkScalar); // + top & bottom |
| 1127 } | 1127 } |
| 1128 // + y + the actual points | 1128 // + y + the actual points |
| 1129 size += 1 * kUInt32Size + points * sizeof(SkScalar); | 1129 size += 1 * kUInt32Size + points * sizeof(SkScalar); |
| 1130 uint32_t initialOffset = this->addDraw(fast ? DRAW_POS_TEXT_H_TOP_BOTTOM : D
RAW_POS_TEXT_H, | 1130 size_t initialOffset = this->addDraw(fast ? DRAW_POS_TEXT_H_TOP_BOTTOM : DRA
W_POS_TEXT_H, |
| 1131 &size); | 1131 &size); |
| 1132 SkASSERT(flatPaintData); | 1132 SkASSERT(flatPaintData); |
| 1133 addFlatPaint(flatPaintData); | 1133 addFlatPaint(flatPaintData); |
| 1134 | 1134 |
| 1135 addText(text, byteLength); | 1135 addText(text, byteLength); |
| 1136 addInt(points); | 1136 addInt(points); |
| 1137 | 1137 |
| 1138 #ifdef SK_DEBUG_SIZE | 1138 #ifdef SK_DEBUG_SIZE |
| 1139 size_t start = fWriter.size(); | 1139 size_t start = fWriter.size(); |
| 1140 #endif | 1140 #endif |
| 1141 if (fast) { | 1141 if (fast) { |
| 1142 addFontMetricsTopBottom(paint, *flatPaintData, constY, constY); | 1142 addFontMetricsTopBottom(paint, *flatPaintData, constY, constY); |
| 1143 } | 1143 } |
| 1144 addScalar(constY); | 1144 addScalar(constY); |
| 1145 fWriter.writeMul4(xpos, points * sizeof(SkScalar)); | 1145 fWriter.writeMul4(xpos, points * sizeof(SkScalar)); |
| 1146 #ifdef SK_DEBUG_SIZE | 1146 #ifdef SK_DEBUG_SIZE |
| 1147 fPointBytes += fWriter.size() - start; | 1147 fPointBytes += fWriter.size() - start; |
| 1148 fPointWrites += points; | 1148 fPointWrites += points; |
| 1149 #endif | 1149 #endif |
| 1150 validate(initialOffset, size); | 1150 this->validate(initialOffset, size); |
| 1151 } | 1151 } |
| 1152 | 1152 |
| 1153 void SkPictureRecord::drawTextOnPath(const void* text, size_t byteLength, | 1153 void SkPictureRecord::drawTextOnPath(const void* text, size_t byteLength, |
| 1154 const SkPath& path, const SkMatrix* matrix, | 1154 const SkPath& path, const SkMatrix* matrix, |
| 1155 const SkPaint& paint) { | 1155 const SkPaint& paint) { |
| 1156 // op + paint index + length + 'length' worth of data + path index + matrix
index | 1156 // op + paint index + length + 'length' worth of data + path index + matrix
index |
| 1157 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 2 * kUInt32Size; | 1157 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 2 * kUInt32Size; |
| 1158 uint32_t initialOffset = this->addDraw(DRAW_TEXT_ON_PATH, &size); | 1158 size_t initialOffset = this->addDraw(DRAW_TEXT_ON_PATH, &size); |
| 1159 SkASSERT(initialOffset+getPaintOffset(DRAW_TEXT_ON_PATH, size) == fWriter.si
ze()); | 1159 SkASSERT(initialOffset+getPaintOffset(DRAW_TEXT_ON_PATH, size) == fWriter.si
ze()); |
| 1160 addPaint(paint); | 1160 addPaint(paint); |
| 1161 addText(text, byteLength); | 1161 addText(text, byteLength); |
| 1162 addPath(path); | 1162 addPath(path); |
| 1163 addMatrixPtr(matrix); | 1163 addMatrixPtr(matrix); |
| 1164 validate(initialOffset, size); | 1164 this->validate(initialOffset, size); |
| 1165 } | 1165 } |
| 1166 | 1166 |
| 1167 void SkPictureRecord::drawPicture(SkPicture& picture) { | 1167 void SkPictureRecord::drawPicture(SkPicture& picture) { |
| 1168 // op + picture index | 1168 // op + picture index |
| 1169 uint32_t size = 2 * kUInt32Size; | 1169 uint32_t size = 2 * kUInt32Size; |
| 1170 uint32_t initialOffset = this->addDraw(DRAW_PICTURE, &size); | 1170 size_t initialOffset = this->addDraw(DRAW_PICTURE, &size); |
| 1171 addPicture(picture); | 1171 addPicture(picture); |
| 1172 validate(initialOffset, size); | 1172 this->validate(initialOffset, size); |
| 1173 } | 1173 } |
| 1174 | 1174 |
| 1175 void SkPictureRecord::drawVertices(VertexMode vmode, int vertexCount, | 1175 void SkPictureRecord::drawVertices(VertexMode vmode, int vertexCount, |
| 1176 const SkPoint vertices[], const SkPoint texs[], | 1176 const SkPoint vertices[], const SkPoint texs[], |
| 1177 const SkColor colors[], SkXfermode*, | 1177 const SkColor colors[], SkXfermode*, |
| 1178 const uint16_t indices[], int indexCount, | 1178 const uint16_t indices[], int indexCount, |
| 1179 const SkPaint& paint) { | 1179 const SkPaint& paint) { |
| 1180 uint32_t flags = 0; | 1180 uint32_t flags = 0; |
| 1181 if (texs) { | 1181 if (texs) { |
| 1182 flags |= DRAW_VERTICES_HAS_TEXS; | 1182 flags |= DRAW_VERTICES_HAS_TEXS; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1194 size += vertexCount * sizeof(SkPoint); // + uvs | 1194 size += vertexCount * sizeof(SkPoint); // + uvs |
| 1195 } | 1195 } |
| 1196 if (flags & DRAW_VERTICES_HAS_COLORS) { | 1196 if (flags & DRAW_VERTICES_HAS_COLORS) { |
| 1197 size += vertexCount * sizeof(SkColor); // + vert colors | 1197 size += vertexCount * sizeof(SkColor); // + vert colors |
| 1198 } | 1198 } |
| 1199 if (flags & DRAW_VERTICES_HAS_INDICES) { | 1199 if (flags & DRAW_VERTICES_HAS_INDICES) { |
| 1200 // + num indices + indices | 1200 // + num indices + indices |
| 1201 size += 1 * kUInt32Size + SkAlign4(indexCount * sizeof(uint16_t)); | 1201 size += 1 * kUInt32Size + SkAlign4(indexCount * sizeof(uint16_t)); |
| 1202 } | 1202 } |
| 1203 | 1203 |
| 1204 uint32_t initialOffset = this->addDraw(DRAW_VERTICES, &size); | 1204 size_t initialOffset = this->addDraw(DRAW_VERTICES, &size); |
| 1205 SkASSERT(initialOffset+getPaintOffset(DRAW_VERTICES, size) == fWriter.size()
); | 1205 SkASSERT(initialOffset+getPaintOffset(DRAW_VERTICES, size) == fWriter.size()
); |
| 1206 addPaint(paint); | 1206 addPaint(paint); |
| 1207 addInt(flags); | 1207 addInt(flags); |
| 1208 addInt(vmode); | 1208 addInt(vmode); |
| 1209 addInt(vertexCount); | 1209 addInt(vertexCount); |
| 1210 addPoints(vertices, vertexCount); | 1210 addPoints(vertices, vertexCount); |
| 1211 if (flags & DRAW_VERTICES_HAS_TEXS) { | 1211 if (flags & DRAW_VERTICES_HAS_TEXS) { |
| 1212 addPoints(texs, vertexCount); | 1212 addPoints(texs, vertexCount); |
| 1213 } | 1213 } |
| 1214 if (flags & DRAW_VERTICES_HAS_COLORS) { | 1214 if (flags & DRAW_VERTICES_HAS_COLORS) { |
| 1215 fWriter.writeMul4(colors, vertexCount * sizeof(SkColor)); | 1215 fWriter.writeMul4(colors, vertexCount * sizeof(SkColor)); |
| 1216 } | 1216 } |
| 1217 if (flags & DRAW_VERTICES_HAS_INDICES) { | 1217 if (flags & DRAW_VERTICES_HAS_INDICES) { |
| 1218 addInt(indexCount); | 1218 addInt(indexCount); |
| 1219 fWriter.writePad(indices, indexCount * sizeof(uint16_t)); | 1219 fWriter.writePad(indices, indexCount * sizeof(uint16_t)); |
| 1220 } | 1220 } |
| 1221 validate(initialOffset, size); | 1221 this->validate(initialOffset, size); |
| 1222 } | 1222 } |
| 1223 | 1223 |
| 1224 void SkPictureRecord::drawData(const void* data, size_t length) { | 1224 void SkPictureRecord::drawData(const void* data, size_t length) { |
| 1225 // op + length + 'length' worth of data | 1225 // op + length + 'length' worth of data |
| 1226 uint32_t size = 2 * kUInt32Size + SkAlign4(length); | 1226 uint32_t size = 2 * kUInt32Size + SkAlign4(length); |
| 1227 uint32_t initialOffset = this->addDraw(DRAW_DATA, &size); | 1227 size_t initialOffset = this->addDraw(DRAW_DATA, &size); |
| 1228 addInt(length); | 1228 addInt(length); |
| 1229 fWriter.writePad(data, length); | 1229 fWriter.writePad(data, length); |
| 1230 validate(initialOffset, size); | 1230 this->validate(initialOffset, size); |
| 1231 } | 1231 } |
| 1232 | 1232 |
| 1233 void SkPictureRecord::beginCommentGroup(const char* description) { | 1233 void SkPictureRecord::beginCommentGroup(const char* description) { |
| 1234 // op/size + length of string + \0 terminated chars | 1234 // op/size + length of string + \0 terminated chars |
| 1235 int length = strlen(description); | 1235 int length = strlen(description); |
| 1236 uint32_t size = 2 * kUInt32Size + SkAlign4(length + 1); | 1236 uint32_t size = 2 * kUInt32Size + SkAlign4(length + 1); |
| 1237 uint32_t initialOffset = this->addDraw(BEGIN_COMMENT_GROUP, &size); | 1237 size_t initialOffset = this->addDraw(BEGIN_COMMENT_GROUP, &size); |
| 1238 fWriter.writeString(description, length); | 1238 fWriter.writeString(description, length); |
| 1239 validate(initialOffset, size); | 1239 this->validate(initialOffset, size); |
| 1240 } | 1240 } |
| 1241 | 1241 |
| 1242 void SkPictureRecord::addComment(const char* kywd, const char* value) { | 1242 void SkPictureRecord::addComment(const char* kywd, const char* value) { |
| 1243 // op/size + 2x length of string + 2x \0 terminated chars | 1243 // op/size + 2x length of string + 2x \0 terminated chars |
| 1244 int kywdLen = strlen(kywd); | 1244 int kywdLen = strlen(kywd); |
| 1245 int valueLen = strlen(value); | 1245 int valueLen = strlen(value); |
| 1246 uint32_t size = 3 * kUInt32Size + SkAlign4(kywdLen + 1) + SkAlign4(valueLen
+ 1); | 1246 uint32_t size = 3 * kUInt32Size + SkAlign4(kywdLen + 1) + SkAlign4(valueLen
+ 1); |
| 1247 uint32_t initialOffset = this->addDraw(COMMENT, &size); | 1247 size_t initialOffset = this->addDraw(COMMENT, &size); |
| 1248 fWriter.writeString(kywd, kywdLen); | 1248 fWriter.writeString(kywd, kywdLen); |
| 1249 fWriter.writeString(value, valueLen); | 1249 fWriter.writeString(value, valueLen); |
| 1250 validate(initialOffset, size); | 1250 this->validate(initialOffset, size); |
| 1251 } | 1251 } |
| 1252 | 1252 |
| 1253 void SkPictureRecord::endCommentGroup() { | 1253 void SkPictureRecord::endCommentGroup() { |
| 1254 // op/size | 1254 // op/size |
| 1255 uint32_t size = 1 * kUInt32Size; | 1255 uint32_t size = 1 * kUInt32Size; |
| 1256 uint32_t initialOffset = this->addDraw(END_COMMENT_GROUP, &size); | 1256 size_t initialOffset = this->addDraw(END_COMMENT_GROUP, &size); |
| 1257 validate(initialOffset, size); | 1257 this->validate(initialOffset, size); |
| 1258 } | 1258 } |
| 1259 | 1259 |
| 1260 /////////////////////////////////////////////////////////////////////////////// | 1260 /////////////////////////////////////////////////////////////////////////////// |
| 1261 | 1261 |
| 1262 void SkPictureRecord::addBitmap(const SkBitmap& bitmap) { | 1262 void SkPictureRecord::addBitmap(const SkBitmap& bitmap) { |
| 1263 const int index = fBitmapHeap->insert(bitmap); | 1263 const int index = fBitmapHeap->insert(bitmap); |
| 1264 // In debug builds, a bad return value from insert() will crash, allowing fo
r debugging. In | 1264 // In debug builds, a bad return value from insert() will crash, allowing fo
r debugging. In |
| 1265 // release builds, the invalid value will be recorded so that the reader wil
l know that there | 1265 // release builds, the invalid value will be recorded so that the reader wil
l know that there |
| 1266 // was a problem. | 1266 // was a problem. |
| 1267 SkASSERT(index != SkBitmapHeap::INVALID_SLOT); | 1267 SkASSERT(index != SkBitmapHeap::INVALID_SLOT); |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1501 void SkPictureRecord::validateRegions() const { | 1501 void SkPictureRecord::validateRegions() const { |
| 1502 int count = fRegions.count(); | 1502 int count = fRegions.count(); |
| 1503 SkASSERT((unsigned) count < 0x1000); | 1503 SkASSERT((unsigned) count < 0x1000); |
| 1504 for (int index = 0; index < count; index++) { | 1504 for (int index = 0; index < count; index++) { |
| 1505 const SkFlatData* region = fRegions[index]; | 1505 const SkFlatData* region = fRegions[index]; |
| 1506 SkASSERT(region); | 1506 SkASSERT(region); |
| 1507 // region->validate(); | 1507 // region->validate(); |
| 1508 } | 1508 } |
| 1509 } | 1509 } |
| 1510 #endif | 1510 #endif |
| OLD | NEW |