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 "SkTSearch.h" | 9 #include "SkTSearch.h" |
10 #include "SkPixelRef.h" | 10 #include "SkPixelRef.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 kNoInitialSave = -1, | 29 kNoInitialSave = -1, |
30 }; | 30 }; |
31 | 31 |
32 // A lot of basic types get stored as a uint32_t: bools, ints, paint indices, et
c. | 32 // A lot of basic types get stored as a uint32_t: bools, ints, paint indices, et
c. |
33 static int const kUInt32Size = 4; | 33 static int const kUInt32Size = 4; |
34 | 34 |
35 static const uint32_t kSaveSize = 2 * kUInt32Size; | 35 static const uint32_t kSaveSize = 2 * kUInt32Size; |
36 static const uint32_t kSaveLayerNoBoundsSize = 4 * kUInt32Size; | 36 static const uint32_t kSaveLayerNoBoundsSize = 4 * kUInt32Size; |
37 static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect
); | 37 static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect
); |
38 | 38 |
39 SkPictureRecord::SkPictureRecord(SkPicture* picture, const SkISize& dimensions,
uint32_t flags) | 39 SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags) |
40 : INHERITED(dimensions.width(), dimensions.height()) | 40 : INHERITED(dimensions.width(), dimensions.height()) |
41 , fBoundingHierarchy(NULL) | 41 , fBoundingHierarchy(NULL) |
42 , fStateTree(NULL) | 42 , fStateTree(NULL) |
43 , fFlattenableHeap(HEAP_BLOCK_SIZE) | 43 , fFlattenableHeap(HEAP_BLOCK_SIZE) |
44 , fPaints(&fFlattenableHeap) | 44 , fPaints(&fFlattenableHeap) |
45 , fRecordFlags(flags) | 45 , fRecordFlags(flags) |
46 , fOptsEnabled(kBeClever) { | 46 , fOptsEnabled(kBeClever) { |
47 #ifdef SK_DEBUG_SIZE | 47 #ifdef SK_DEBUG_SIZE |
48 fPointBytes = fRectBytes = fTextBytes = 0; | 48 fPointBytes = fRectBytes = fTextBytes = 0; |
49 fPointWrites = fRectWrites = fTextWrites = 0; | 49 fPointWrites = fRectWrites = fTextWrites = 0; |
50 #endif | 50 #endif |
51 | 51 |
52 fPicture = picture; | |
53 fBitmapHeap = SkNEW(SkBitmapHeap); | 52 fBitmapHeap = SkNEW(SkBitmapHeap); |
54 fFlattenableHeap.setBitmapStorage(fBitmapHeap); | 53 fFlattenableHeap.setBitmapStorage(fBitmapHeap); |
55 | 54 |
56 #ifndef SK_COLLAPSE_MATRIX_CLIP_STATE | 55 #ifndef SK_COLLAPSE_MATRIX_CLIP_STATE |
57 fFirstSavedLayerIndex = kNoSavedLayerIndex; | 56 fFirstSavedLayerIndex = kNoSavedLayerIndex; |
58 #endif | 57 #endif |
59 | 58 |
60 fInitialSaveCount = kNoInitialSave; | 59 fInitialSaveCount = kNoInitialSave; |
61 | 60 |
62 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE | 61 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 SkASSERT(initialOffset+getPaintOffset(DRAW_DRRECT, size) == fWriter.bytesWri
tten()); | 1058 SkASSERT(initialOffset+getPaintOffset(DRAW_DRRECT, size) == fWriter.bytesWri
tten()); |
1060 this->addPaint(paint); | 1059 this->addPaint(paint); |
1061 this->addRRect(outer); | 1060 this->addRRect(outer); |
1062 this->addRRect(inner); | 1061 this->addRRect(inner); |
1063 this->validate(initialOffset, size); | 1062 this->validate(initialOffset, size); |
1064 } | 1063 } |
1065 | 1064 |
1066 void SkPictureRecord::drawPath(const SkPath& path, const SkPaint& paint) { | 1065 void SkPictureRecord::drawPath(const SkPath& path, const SkPaint& paint) { |
1067 | 1066 |
1068 if (paint.isAntiAlias() && !path.isConvex()) { | 1067 if (paint.isAntiAlias() && !path.isConvex()) { |
1069 fPicture->incAAConcavePaths(); | 1068 fContentInfo.incAAConcavePaths(); |
1070 | 1069 |
1071 if (SkPaint::kStroke_Style == paint.getStyle() && | 1070 if (SkPaint::kStroke_Style == paint.getStyle() && |
1072 0 == paint.getStrokeWidth()) { | 1071 0 == paint.getStrokeWidth()) { |
1073 fPicture->incAAHairlineConcavePaths(); | 1072 fContentInfo.incAAHairlineConcavePaths(); |
1074 } | 1073 } |
1075 } | 1074 } |
1076 | 1075 |
1077 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE | 1076 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
1078 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); | 1077 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
1079 #endif | 1078 #endif |
1080 | 1079 |
1081 // op + paint index + path index | 1080 // op + paint index + path index |
1082 size_t size = 3 * kUInt32Size; | 1081 size_t size = 3 * kUInt32Size; |
1083 size_t initialOffset = this->addDraw(DRAW_PATH, &size); | 1082 size_t initialOffset = this->addDraw(DRAW_PATH, &size); |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1582 void SkPictureRecord::addMatrix(const SkMatrix& matrix) { | 1581 void SkPictureRecord::addMatrix(const SkMatrix& matrix) { |
1583 fWriter.writeMatrix(matrix); | 1582 fWriter.writeMatrix(matrix); |
1584 } | 1583 } |
1585 | 1584 |
1586 const SkFlatData* SkPictureRecord::getFlatPaintData(const SkPaint& paint) { | 1585 const SkFlatData* SkPictureRecord::getFlatPaintData(const SkPaint& paint) { |
1587 return fPaints.findAndReturnFlat(paint); | 1586 return fPaints.findAndReturnFlat(paint); |
1588 } | 1587 } |
1589 | 1588 |
1590 const SkFlatData* SkPictureRecord::addPaintPtr(const SkPaint* paint) { | 1589 const SkFlatData* SkPictureRecord::addPaintPtr(const SkPaint* paint) { |
1591 if (NULL != paint && NULL != paint->getPathEffect()) { | 1590 if (NULL != paint && NULL != paint->getPathEffect()) { |
1592 fPicture->incPaintWithPathEffectUses(); | 1591 fContentInfo.incPaintWithPathEffectUses(); |
1593 } | 1592 } |
1594 | 1593 |
1595 const SkFlatData* data = paint ? getFlatPaintData(*paint) : NULL; | 1594 const SkFlatData* data = paint ? getFlatPaintData(*paint) : NULL; |
1596 this->addFlatPaint(data); | 1595 this->addFlatPaint(data); |
1597 return data; | 1596 return data; |
1598 } | 1597 } |
1599 | 1598 |
1600 void SkPictureRecord::addFlatPaint(const SkFlatData* flatPaint) { | 1599 void SkPictureRecord::addFlatPaint(const SkFlatData* flatPaint) { |
1601 int index = flatPaint ? flatPaint->index() : 0; | 1600 int index = flatPaint ? flatPaint->index() : 0; |
1602 this->addInt(index); | 1601 this->addInt(index); |
1603 } | 1602 } |
1604 | 1603 |
1605 int SkPictureRecord::addPathToHeap(const SkPath& path) { | 1604 int SkPictureRecord::addPathToHeap(const SkPath& path) { |
1606 return fPicture->addPathToHeap(path); | 1605 if (NULL == fPathHeap) { |
| 1606 fPathHeap.reset(SkNEW(SkPathHeap)); |
| 1607 } |
| 1608 #ifdef SK_DEDUP_PICTURE_PATHS |
| 1609 return fPathHeap->insert(path); |
| 1610 #else |
| 1611 return fPathHeap->append(path); |
| 1612 #endif |
1607 } | 1613 } |
1608 | 1614 |
1609 void SkPictureRecord::addPath(const SkPath& path) { | 1615 void SkPictureRecord::addPath(const SkPath& path) { |
1610 this->addInt(this->addPathToHeap(path)); | 1616 this->addInt(this->addPathToHeap(path)); |
1611 } | 1617 } |
1612 | 1618 |
1613 void SkPictureRecord::addPicture(const SkPicture* picture) { | 1619 void SkPictureRecord::addPicture(const SkPicture* picture) { |
1614 int index = fPictureRefs.find(picture); | 1620 int index = fPictureRefs.find(picture); |
1615 if (index < 0) { // not found | 1621 if (index < 0) { // not found |
1616 index = fPictureRefs.count(); | 1622 index = fPictureRefs.count(); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1818 void SkPictureRecord::validateRegions() const { | 1824 void SkPictureRecord::validateRegions() const { |
1819 int count = fRegions.count(); | 1825 int count = fRegions.count(); |
1820 SkASSERT((unsigned) count < 0x1000); | 1826 SkASSERT((unsigned) count < 0x1000); |
1821 for (int index = 0; index < count; index++) { | 1827 for (int index = 0; index < count; index++) { |
1822 const SkFlatData* region = fRegions[index]; | 1828 const SkFlatData* region = fRegions[index]; |
1823 SkASSERT(region); | 1829 SkASSERT(region); |
1824 // region->validate(); | 1830 // region->validate(); |
1825 } | 1831 } |
1826 } | 1832 } |
1827 #endif | 1833 #endif |
OLD | NEW |