| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 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 | 8 |
| 9 | 9 |
| 10 #include "SkBuffer.h" | 10 #include "SkBuffer.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 // flag to require a moveTo if we begin with something else, like lineTo etc. | 125 // flag to require a moveTo if we begin with something else, like lineTo etc. |
| 126 #define INITIAL_LASTMOVETOINDEX_VALUE ~0 | 126 #define INITIAL_LASTMOVETOINDEX_VALUE ~0 |
| 127 | 127 |
| 128 SkPath::SkPath() | 128 SkPath::SkPath() |
| 129 : fPathRef(SkPathRef::CreateEmpty()) | 129 : fPathRef(SkPathRef::CreateEmpty()) |
| 130 #ifdef SK_BUILD_FOR_ANDROID | 130 #ifdef SK_BUILD_FOR_ANDROID |
| 131 , fSourcePath(NULL) | 131 , fSourcePath(NULL) |
| 132 #endif | 132 #endif |
| 133 { | 133 { |
| 134 this->resetFields(); | 134 this->resetFields(); |
| 135 fIsVolatile = false; |
| 135 } | 136 } |
| 136 | 137 |
| 137 void SkPath::resetFields() { | 138 void SkPath::resetFields() { |
| 138 //fPathRef is assumed to have been emptied by the caller. | 139 //fPathRef is assumed to have been emptied by the caller. |
| 139 fLastMoveToIndex = INITIAL_LASTMOVETOINDEX_VALUE; | 140 fLastMoveToIndex = INITIAL_LASTMOVETOINDEX_VALUE; |
| 140 fFillType = kWinding_FillType; | 141 fFillType = kWinding_FillType; |
| 141 fConvexity = kUnknown_Convexity; | 142 fConvexity = kUnknown_Convexity; |
| 142 fDirection = kUnknown_Direction; | 143 fDirection = kUnknown_Direction; |
| 143 | 144 |
| 144 // We don't touch Android's fSourcePath. It's used to track texture garbage
collection, so we | 145 // We don't touch Android's fSourcePath. It's used to track texture garbage
collection, so we |
| (...skipping 26 matching lines...) Expand all Loading... |
| 171 SkDEBUGCODE(this->validate();) | 172 SkDEBUGCODE(this->validate();) |
| 172 return *this; | 173 return *this; |
| 173 } | 174 } |
| 174 | 175 |
| 175 void SkPath::copyFields(const SkPath& that) { | 176 void SkPath::copyFields(const SkPath& that) { |
| 176 //fPathRef is assumed to have been set by the caller. | 177 //fPathRef is assumed to have been set by the caller. |
| 177 fLastMoveToIndex = that.fLastMoveToIndex; | 178 fLastMoveToIndex = that.fLastMoveToIndex; |
| 178 fFillType = that.fFillType; | 179 fFillType = that.fFillType; |
| 179 fConvexity = that.fConvexity; | 180 fConvexity = that.fConvexity; |
| 180 fDirection = that.fDirection; | 181 fDirection = that.fDirection; |
| 182 fIsVolatile = that.fIsVolatile; |
| 181 } | 183 } |
| 182 | 184 |
| 183 bool operator==(const SkPath& a, const SkPath& b) { | 185 bool operator==(const SkPath& a, const SkPath& b) { |
| 184 // note: don't need to look at isConvex or bounds, since just comparing the | 186 // note: don't need to look at isConvex or bounds, since just comparing the |
| 185 // raw data is sufficient. | 187 // raw data is sufficient. |
| 186 return &a == &b || | 188 return &a == &b || |
| 187 (a.fFillType == b.fFillType && *a.fPathRef.get() == *b.fPathRef.get()); | 189 (a.fFillType == b.fFillType && *a.fPathRef.get() == *b.fPathRef.get()); |
| 188 } | 190 } |
| 189 | 191 |
| 190 void SkPath::swap(SkPath& that) { | 192 void SkPath::swap(SkPath& that) { |
| 191 SkASSERT(&that != NULL); | 193 SkASSERT(&that != NULL); |
| 192 | 194 |
| 193 if (this != &that) { | 195 if (this != &that) { |
| 194 fPathRef.swap(&that.fPathRef); | 196 fPathRef.swap(&that.fPathRef); |
| 195 SkTSwap<int>(fLastMoveToIndex, that.fLastMoveToIndex); | 197 SkTSwap<int>(fLastMoveToIndex, that.fLastMoveToIndex); |
| 196 SkTSwap<uint8_t>(fFillType, that.fFillType); | 198 SkTSwap<uint8_t>(fFillType, that.fFillType); |
| 197 SkTSwap<uint8_t>(fConvexity, that.fConvexity); | 199 SkTSwap<uint8_t>(fConvexity, that.fConvexity); |
| 198 SkTSwap<uint8_t>(fDirection, that.fDirection); | 200 SkTSwap<uint8_t>(fDirection, that.fDirection); |
| 201 SkTSwap<SkBool8>(fIsVolatile, that.fIsVolatile); |
| 199 #ifdef SK_BUILD_FOR_ANDROID | 202 #ifdef SK_BUILD_FOR_ANDROID |
| 200 SkTSwap<const SkPath*>(fSourcePath, that.fSourcePath); | 203 SkTSwap<const SkPath*>(fSourcePath, that.fSourcePath); |
| 201 #endif | 204 #endif |
| 202 } | 205 } |
| 203 } | 206 } |
| 204 | 207 |
| 205 static inline bool check_edge_against_rect(const SkPoint& p0, | 208 static inline bool check_edge_against_rect(const SkPoint& p0, |
| 206 const SkPoint& p1, | 209 const SkPoint& p1, |
| 207 const SkRect& rect, | 210 const SkRect& rect, |
| 208 SkPath::Direction dir) { | 211 SkPath::Direction dir) { |
| (...skipping 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1599 dst->swap(tmp); | 1602 dst->swap(tmp); |
| 1600 SkPathRef::Editor ed(&dst->fPathRef); | 1603 SkPathRef::Editor ed(&dst->fPathRef); |
| 1601 matrix.mapPoints(ed.points(), ed.pathRef()->countPoints()); | 1604 matrix.mapPoints(ed.points(), ed.pathRef()->countPoints()); |
| 1602 dst->fDirection = kUnknown_Direction; | 1605 dst->fDirection = kUnknown_Direction; |
| 1603 } else { | 1606 } else { |
| 1604 SkPathRef::CreateTransformedCopy(&dst->fPathRef, *fPathRef.get(), matrix
); | 1607 SkPathRef::CreateTransformedCopy(&dst->fPathRef, *fPathRef.get(), matrix
); |
| 1605 | 1608 |
| 1606 if (this != dst) { | 1609 if (this != dst) { |
| 1607 dst->fFillType = fFillType; | 1610 dst->fFillType = fFillType; |
| 1608 dst->fConvexity = fConvexity; | 1611 dst->fConvexity = fConvexity; |
| 1612 dst->fIsVolatile = fIsVolatile; |
| 1609 } | 1613 } |
| 1610 | 1614 |
| 1611 if (kUnknown_Direction == fDirection) { | 1615 if (kUnknown_Direction == fDirection) { |
| 1612 dst->fDirection = kUnknown_Direction; | 1616 dst->fDirection = kUnknown_Direction; |
| 1613 } else { | 1617 } else { |
| 1614 SkScalar det2x2 = | 1618 SkScalar det2x2 = |
| 1615 SkScalarMul(matrix.get(SkMatrix::kMScaleX), matrix.get(SkMatrix:
:kMScaleY)) - | 1619 SkScalarMul(matrix.get(SkMatrix::kMScaleX), matrix.get(SkMatrix:
:kMScaleY)) - |
| 1616 SkScalarMul(matrix.get(SkMatrix::kMSkewX), matrix.get(SkMatrix::
kMSkewY)); | 1620 SkScalarMul(matrix.get(SkMatrix::kMSkewX), matrix.get(SkMatrix::
kMSkewY)); |
| 1617 if (det2x2 < 0) { | 1621 if (det2x2 < 0) { |
| 1618 dst->fDirection = SkPath::OppositeDirection(static_cast<Directio
n>(fDirection)); | 1622 dst->fDirection = SkPath::OppositeDirection(static_cast<Directio
n>(fDirection)); |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1971 | 1975 |
| 1972 if (NULL == storage) { | 1976 if (NULL == storage) { |
| 1973 const int byteCount = sizeof(int32_t) + fPathRef->writeSize(); | 1977 const int byteCount = sizeof(int32_t) + fPathRef->writeSize(); |
| 1974 return SkAlign4(byteCount); | 1978 return SkAlign4(byteCount); |
| 1975 } | 1979 } |
| 1976 | 1980 |
| 1977 SkWBuffer buffer(storage); | 1981 SkWBuffer buffer(storage); |
| 1978 | 1982 |
| 1979 int32_t packed = (fConvexity << kConvexity_SerializationShift) | | 1983 int32_t packed = (fConvexity << kConvexity_SerializationShift) | |
| 1980 (fFillType << kFillType_SerializationShift) | | 1984 (fFillType << kFillType_SerializationShift) | |
| 1981 (fDirection << kDirection_SerializationShift); | 1985 (fDirection << kDirection_SerializationShift) | |
| 1986 (fIsVolatile << kIsVolatile_SerializationShift); |
| 1982 | 1987 |
| 1983 buffer.write32(packed); | 1988 buffer.write32(packed); |
| 1984 | 1989 |
| 1985 fPathRef->writeToBuffer(&buffer); | 1990 fPathRef->writeToBuffer(&buffer); |
| 1986 | 1991 |
| 1987 buffer.padToAlign4(); | 1992 buffer.padToAlign4(); |
| 1988 return buffer.pos(); | 1993 return buffer.pos(); |
| 1989 } | 1994 } |
| 1990 | 1995 |
| 1991 size_t SkPath::readFromMemory(const void* storage, size_t length) { | 1996 size_t SkPath::readFromMemory(const void* storage, size_t length) { |
| 1992 SkRBufferWithSizeCheck buffer(storage, length); | 1997 SkRBufferWithSizeCheck buffer(storage, length); |
| 1993 | 1998 |
| 1994 int32_t packed; | 1999 int32_t packed; |
| 1995 if (!buffer.readS32(&packed)) { | 2000 if (!buffer.readS32(&packed)) { |
| 1996 return 0; | 2001 return 0; |
| 1997 } | 2002 } |
| 1998 | 2003 |
| 1999 fConvexity = (packed >> kConvexity_SerializationShift) & 0xFF; | 2004 fConvexity = (packed >> kConvexity_SerializationShift) & 0xFF; |
| 2000 fFillType = (packed >> kFillType_SerializationShift) & 0xFF; | 2005 fFillType = (packed >> kFillType_SerializationShift) & 0xFF; |
| 2001 fDirection = (packed >> kDirection_SerializationShift) & 0x3; | 2006 fDirection = (packed >> kDirection_SerializationShift) & 0x3; |
| 2007 fIsVolatile = (packed >> kIsVolatile_SerializationShift) & 0x1; |
| 2002 SkPathRef* pathRef = SkPathRef::CreateFromBuffer(&buffer); | 2008 SkPathRef* pathRef = SkPathRef::CreateFromBuffer(&buffer); |
| 2003 | 2009 |
| 2004 size_t sizeRead = 0; | 2010 size_t sizeRead = 0; |
| 2005 if (buffer.isValid()) { | 2011 if (buffer.isValid()) { |
| 2006 fPathRef.reset(pathRef); | 2012 fPathRef.reset(pathRef); |
| 2007 SkDEBUGCODE(this->validate();) | 2013 SkDEBUGCODE(this->validate();) |
| 2008 buffer.skipToAlign4(); | 2014 buffer.skipToAlign4(); |
| 2009 sizeRead = buffer.pos(); | 2015 sizeRead = buffer.pos(); |
| 2010 } else if (pathRef) { | 2016 } else if (pathRef) { |
| 2011 // If the buffer is not valid, pathRef should be NULL | 2017 // If the buffer is not valid, pathRef should be NULL |
| (...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2858 switch (this->getFillType()) { | 2864 switch (this->getFillType()) { |
| 2859 case SkPath::kEvenOdd_FillType: | 2865 case SkPath::kEvenOdd_FillType: |
| 2860 case SkPath::kInverseEvenOdd_FillType: | 2866 case SkPath::kInverseEvenOdd_FillType: |
| 2861 w &= 1; | 2867 w &= 1; |
| 2862 break; | 2868 break; |
| 2863 default: | 2869 default: |
| 2864 break; | 2870 break; |
| 2865 } | 2871 } |
| 2866 return SkToBool(w); | 2872 return SkToBool(w); |
| 2867 } | 2873 } |
| OLD | NEW |