OLD | NEW |
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 "SkImage_Base.h" | 9 #include "SkImage_Base.h" |
10 #include "SkPatchUtils.h" | 10 #include "SkPatchUtils.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags) | 27 SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags) |
28 : INHERITED(dimensions.width(), dimensions.height()) | 28 : INHERITED(dimensions.width(), dimensions.height()) |
29 , fRecordFlags(flags) | 29 , fRecordFlags(flags) |
30 , fInitialSaveCount(kNoInitialSave) { | 30 , fInitialSaveCount(kNoInitialSave) { |
31 } | 31 } |
32 | 32 |
33 SkPictureRecord::~SkPictureRecord() { | 33 SkPictureRecord::~SkPictureRecord() { |
34 fImageRefs.unrefAll(); | 34 fImageRefs.unrefAll(); |
35 fPictureRefs.unrefAll(); | 35 fPictureRefs.unrefAll(); |
36 fDrawableRefs.unrefAll(); | |
37 fTextBlobRefs.unrefAll(); | 36 fTextBlobRefs.unrefAll(); |
38 } | 37 } |
39 | 38 |
40 /////////////////////////////////////////////////////////////////////////////// | 39 /////////////////////////////////////////////////////////////////////////////// |
41 | 40 |
42 void SkPictureRecord::willSave() { | 41 void SkPictureRecord::willSave() { |
43 // record the offset to us, making it non-positive to distinguish a save | 42 // record the offset to us, making it non-positive to distinguish a save |
44 // from a clip entry. | 43 // from a clip entry. |
45 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); | 44 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); |
46 this->recordSave(); | 45 this->recordSave(); |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 } else { | 629 } else { |
631 const SkMatrix& m = matrix ? *matrix : SkMatrix::I(); | 630 const SkMatrix& m = matrix ? *matrix : SkMatrix::I(); |
632 size += m.writeToMemory(nullptr) + kUInt32Size; // matrix + paint | 631 size += m.writeToMemory(nullptr) + kUInt32Size; // matrix + paint |
633 initialOffset = this->addDraw(DRAW_PICTURE_MATRIX_PAINT, &size); | 632 initialOffset = this->addDraw(DRAW_PICTURE_MATRIX_PAINT, &size); |
634 this->addPaintPtr(paint); | 633 this->addPaintPtr(paint); |
635 this->addMatrix(m); | 634 this->addMatrix(m); |
636 this->addPicture(picture); | 635 this->addPicture(picture); |
637 } | 636 } |
638 this->validate(initialOffset, size); | 637 this->validate(initialOffset, size); |
639 } | 638 } |
640 | |
641 void SkPictureRecord::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matri
x) { | |
642 // op + drawable index | |
643 size_t size = 2 * kUInt32Size; | |
644 size_t initialOffset; | |
645 | |
646 if (nullptr == matrix) { | |
647 initialOffset = this->addDraw(DRAW_DRAWABLE, &size); | |
648 this->addDrawable(drawable); | |
649 } else { | |
650 size += matrix->writeToMemory(nullptr); // matrix | |
651 initialOffset = this->addDraw(DRAW_DRAWABLE_MATRIX, &size); | |
652 this->addMatrix(*matrix); | |
653 this->addDrawable(drawable); | |
654 } | |
655 this->validate(initialOffset, size); | |
656 } | |
657 | 639 |
658 void SkPictureRecord::onDrawVertices(VertexMode vmode, int vertexCount, | 640 void SkPictureRecord::onDrawVertices(VertexMode vmode, int vertexCount, |
659 const SkPoint vertices[], const SkPoint tex
s[], | 641 const SkPoint vertices[], const SkPoint tex
s[], |
660 const SkColor colors[], SkXfermode* xfer, | 642 const SkColor colors[], SkXfermode* xfer, |
661 const uint16_t indices[], int indexCount, | 643 const uint16_t indices[], int indexCount, |
662 const SkPaint& paint) { | 644 const SkPaint& paint) { |
663 uint32_t flags = 0; | 645 uint32_t flags = 0; |
664 if (texs) { | 646 if (texs) { |
665 flags |= DRAW_VERTICES_HAS_TEXS; | 647 flags |= DRAW_VERTICES_HAS_TEXS; |
666 } | 648 } |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 int index = fPictureRefs.find(picture); | 911 int index = fPictureRefs.find(picture); |
930 if (index < 0) { // not found | 912 if (index < 0) { // not found |
931 index = fPictureRefs.count(); | 913 index = fPictureRefs.count(); |
932 *fPictureRefs.append() = picture; | 914 *fPictureRefs.append() = picture; |
933 picture->ref(); | 915 picture->ref(); |
934 } | 916 } |
935 // follow the convention of recording a 1-based index | 917 // follow the convention of recording a 1-based index |
936 this->addInt(index + 1); | 918 this->addInt(index + 1); |
937 } | 919 } |
938 | 920 |
939 void SkPictureRecord::addDrawable(SkDrawable* drawable) { | |
940 int index = fDrawableRefs.find(drawable); | |
941 if (index < 0) { // not found | |
942 index = fDrawableRefs.count(); | |
943 *fDrawableRefs.append() = drawable; | |
944 drawable->ref(); | |
945 } | |
946 // follow the convention of recording a 1-based index | |
947 this->addInt(index + 1); | |
948 } | |
949 | |
950 void SkPictureRecord::addPoint(const SkPoint& point) { | 921 void SkPictureRecord::addPoint(const SkPoint& point) { |
951 fWriter.writePoint(point); | 922 fWriter.writePoint(point); |
952 } | 923 } |
953 | 924 |
954 void SkPictureRecord::addPoints(const SkPoint pts[], int count) { | 925 void SkPictureRecord::addPoints(const SkPoint pts[], int count) { |
955 fWriter.writeMul4(pts, count * sizeof(SkPoint)); | 926 fWriter.writeMul4(pts, count * sizeof(SkPoint)); |
956 } | 927 } |
957 | 928 |
958 void SkPictureRecord::addNoOp() { | 929 void SkPictureRecord::addNoOp() { |
959 size_t size = kUInt32Size; // op | 930 size_t size = kUInt32Size; // op |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
996 | 967 |
997 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { | 968 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { |
998 int index = fTextBlobRefs.count(); | 969 int index = fTextBlobRefs.count(); |
999 *fTextBlobRefs.append() = blob; | 970 *fTextBlobRefs.append() = blob; |
1000 blob->ref(); | 971 blob->ref(); |
1001 // follow the convention of recording a 1-based index | 972 // follow the convention of recording a 1-based index |
1002 this->addInt(index + 1); | 973 this->addInt(index + 1); |
1003 } | 974 } |
1004 | 975 |
1005 /////////////////////////////////////////////////////////////////////////////// | 976 /////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |