Chromium Code Reviews| 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 | 124 |
| 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(); |
|
bsalomon
2014/10/23 20:36:28
Don't you need to set volatile=false here now?
| |
| 135 } | 135 } |
| 136 | 136 |
| 137 void SkPath::resetFields() { | 137 void SkPath::resetFields() { |
| 138 //fPathRef is assumed to have been emptied by the caller. | 138 //fPathRef is assumed to have been emptied by the caller. |
| 139 fLastMoveToIndex = INITIAL_LASTMOVETOINDEX_VALUE; | 139 fLastMoveToIndex = INITIAL_LASTMOVETOINDEX_VALUE; |
| 140 fFillType = kWinding_FillType; | 140 fFillType = kWinding_FillType; |
| 141 fConvexity = kUnknown_Convexity; | 141 fConvexity = kUnknown_Convexity; |
| 142 fDirection = kUnknown_Direction; | 142 fDirection = kUnknown_Direction; |
| 143 | 143 |
| 144 // We don't touch Android's fSourcePath. It's used to track texture garbage collection, so we | 144 // 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();) | 171 SkDEBUGCODE(this->validate();) |
| 172 return *this; | 172 return *this; |
| 173 } | 173 } |
| 174 | 174 |
| 175 void SkPath::copyFields(const SkPath& that) { | 175 void SkPath::copyFields(const SkPath& that) { |
| 176 //fPathRef is assumed to have been set by the caller. | 176 //fPathRef is assumed to have been set by the caller. |
| 177 fLastMoveToIndex = that.fLastMoveToIndex; | 177 fLastMoveToIndex = that.fLastMoveToIndex; |
| 178 fFillType = that.fFillType; | 178 fFillType = that.fFillType; |
| 179 fConvexity = that.fConvexity; | 179 fConvexity = that.fConvexity; |
| 180 fDirection = that.fDirection; | 180 fDirection = that.fDirection; |
| 181 fIsVolatile = that.fIsVolatile; | |
| 181 } | 182 } |
| 182 | 183 |
| 183 bool operator==(const SkPath& a, const SkPath& b) { | 184 bool operator==(const SkPath& a, const SkPath& b) { |
| 184 // note: don't need to look at isConvex or bounds, since just comparing the | 185 // note: don't need to look at isConvex or bounds, since just comparing the |
| 185 // raw data is sufficient. | 186 // raw data is sufficient. |
| 186 return &a == &b || | 187 return &a == &b || |
| 187 (a.fFillType == b.fFillType && *a.fPathRef.get() == *b.fPathRef.get()); | 188 (a.fFillType == b.fFillType && *a.fPathRef.get() == *b.fPathRef.get()); |
| 188 } | 189 } |
| 189 | 190 |
| 190 void SkPath::swap(SkPath& that) { | 191 void SkPath::swap(SkPath& that) { |
| 191 SkASSERT(&that != NULL); | 192 SkASSERT(&that != NULL); |
| 192 | 193 |
| 193 if (this != &that) { | 194 if (this != &that) { |
| 194 fPathRef.swap(&that.fPathRef); | 195 fPathRef.swap(&that.fPathRef); |
| 195 SkTSwap<int>(fLastMoveToIndex, that.fLastMoveToIndex); | 196 SkTSwap<int>(fLastMoveToIndex, that.fLastMoveToIndex); |
| 196 SkTSwap<uint8_t>(fFillType, that.fFillType); | 197 SkTSwap<uint8_t>(fFillType, that.fFillType); |
| 197 SkTSwap<uint8_t>(fConvexity, that.fConvexity); | 198 SkTSwap<uint8_t>(fConvexity, that.fConvexity); |
| 198 SkTSwap<uint8_t>(fDirection, that.fDirection); | 199 SkTSwap<uint8_t>(fDirection, that.fDirection); |
| 200 SkTSwap<SkBool8>(fIsVolatile, that.fIsVolatile); | |
| 199 #ifdef SK_BUILD_FOR_ANDROID | 201 #ifdef SK_BUILD_FOR_ANDROID |
| 200 SkTSwap<const SkPath*>(fSourcePath, that.fSourcePath); | 202 SkTSwap<const SkPath*>(fSourcePath, that.fSourcePath); |
| 201 #endif | 203 #endif |
| 202 } | 204 } |
| 203 } | 205 } |
| 204 | 206 |
| 205 static inline bool check_edge_against_rect(const SkPoint& p0, | 207 static inline bool check_edge_against_rect(const SkPoint& p0, |
| 206 const SkPoint& p1, | 208 const SkPoint& p1, |
| 207 const SkRect& rect, | 209 const SkRect& rect, |
| 208 SkPath::Direction dir) { | 210 SkPath::Direction dir) { |
| (...skipping 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1599 dst->swap(tmp); | 1601 dst->swap(tmp); |
| 1600 SkPathRef::Editor ed(&dst->fPathRef); | 1602 SkPathRef::Editor ed(&dst->fPathRef); |
| 1601 matrix.mapPoints(ed.points(), ed.pathRef()->countPoints()); | 1603 matrix.mapPoints(ed.points(), ed.pathRef()->countPoints()); |
| 1602 dst->fDirection = kUnknown_Direction; | 1604 dst->fDirection = kUnknown_Direction; |
| 1603 } else { | 1605 } else { |
| 1604 SkPathRef::CreateTransformedCopy(&dst->fPathRef, *fPathRef.get(), matrix ); | 1606 SkPathRef::CreateTransformedCopy(&dst->fPathRef, *fPathRef.get(), matrix ); |
| 1605 | 1607 |
| 1606 if (this != dst) { | 1608 if (this != dst) { |
| 1607 dst->fFillType = fFillType; | 1609 dst->fFillType = fFillType; |
| 1608 dst->fConvexity = fConvexity; | 1610 dst->fConvexity = fConvexity; |
| 1611 dst->fIsVolatile = fIsVolatile; | |
| 1609 } | 1612 } |
| 1610 | 1613 |
| 1611 if (kUnknown_Direction == fDirection) { | 1614 if (kUnknown_Direction == fDirection) { |
| 1612 dst->fDirection = kUnknown_Direction; | 1615 dst->fDirection = kUnknown_Direction; |
| 1613 } else { | 1616 } else { |
| 1614 SkScalar det2x2 = | 1617 SkScalar det2x2 = |
| 1615 SkScalarMul(matrix.get(SkMatrix::kMScaleX), matrix.get(SkMatrix: :kMScaleY)) - | 1618 SkScalarMul(matrix.get(SkMatrix::kMScaleX), matrix.get(SkMatrix: :kMScaleY)) - |
| 1616 SkScalarMul(matrix.get(SkMatrix::kMSkewX), matrix.get(SkMatrix:: kMSkewY)); | 1619 SkScalarMul(matrix.get(SkMatrix::kMSkewX), matrix.get(SkMatrix:: kMSkewY)); |
| 1617 if (det2x2 < 0) { | 1620 if (det2x2 < 0) { |
| 1618 dst->fDirection = SkPath::OppositeDirection(static_cast<Directio n>(fDirection)); | 1621 dst->fDirection = SkPath::OppositeDirection(static_cast<Directio n>(fDirection)); |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1971 | 1974 |
| 1972 if (NULL == storage) { | 1975 if (NULL == storage) { |
| 1973 const int byteCount = sizeof(int32_t) + fPathRef->writeSize(); | 1976 const int byteCount = sizeof(int32_t) + fPathRef->writeSize(); |
| 1974 return SkAlign4(byteCount); | 1977 return SkAlign4(byteCount); |
| 1975 } | 1978 } |
| 1976 | 1979 |
| 1977 SkWBuffer buffer(storage); | 1980 SkWBuffer buffer(storage); |
| 1978 | 1981 |
| 1979 int32_t packed = (fConvexity << kConvexity_SerializationShift) | | 1982 int32_t packed = (fConvexity << kConvexity_SerializationShift) | |
| 1980 (fFillType << kFillType_SerializationShift) | | 1983 (fFillType << kFillType_SerializationShift) | |
| 1981 (fDirection << kDirection_SerializationShift); | 1984 (fDirection << kDirection_SerializationShift) | |
| 1985 (fIsVolatile << kIsVolatile_SerializationShift); | |
| 1982 | 1986 |
| 1983 buffer.write32(packed); | 1987 buffer.write32(packed); |
| 1984 | 1988 |
| 1985 fPathRef->writeToBuffer(&buffer); | 1989 fPathRef->writeToBuffer(&buffer); |
| 1986 | 1990 |
| 1987 buffer.padToAlign4(); | 1991 buffer.padToAlign4(); |
| 1988 return buffer.pos(); | 1992 return buffer.pos(); |
| 1989 } | 1993 } |
| 1990 | 1994 |
| 1991 size_t SkPath::readFromMemory(const void* storage, size_t length) { | 1995 size_t SkPath::readFromMemory(const void* storage, size_t length) { |
| 1992 SkRBufferWithSizeCheck buffer(storage, length); | 1996 SkRBufferWithSizeCheck buffer(storage, length); |
| 1993 | 1997 |
| 1994 int32_t packed; | 1998 int32_t packed; |
| 1995 if (!buffer.readS32(&packed)) { | 1999 if (!buffer.readS32(&packed)) { |
| 1996 return 0; | 2000 return 0; |
| 1997 } | 2001 } |
| 1998 | 2002 |
| 1999 fConvexity = (packed >> kConvexity_SerializationShift) & 0xFF; | 2003 fConvexity = (packed >> kConvexity_SerializationShift) & 0xFF; |
| 2000 fFillType = (packed >> kFillType_SerializationShift) & 0xFF; | 2004 fFillType = (packed >> kFillType_SerializationShift) & 0xFF; |
| 2001 fDirection = (packed >> kDirection_SerializationShift) & 0x3; | 2005 fDirection = (packed >> kDirection_SerializationShift) & 0x3; |
| 2006 fIsVolatile = (packed >> kIsVolatile_SerializationShift) & 0x1; | |
| 2002 SkPathRef* pathRef = SkPathRef::CreateFromBuffer(&buffer); | 2007 SkPathRef* pathRef = SkPathRef::CreateFromBuffer(&buffer); |
| 2003 | 2008 |
| 2004 size_t sizeRead = 0; | 2009 size_t sizeRead = 0; |
| 2005 if (buffer.isValid()) { | 2010 if (buffer.isValid()) { |
| 2006 fPathRef.reset(pathRef); | 2011 fPathRef.reset(pathRef); |
| 2007 SkDEBUGCODE(this->validate();) | 2012 SkDEBUGCODE(this->validate();) |
| 2008 buffer.skipToAlign4(); | 2013 buffer.skipToAlign4(); |
| 2009 sizeRead = buffer.pos(); | 2014 sizeRead = buffer.pos(); |
| 2010 } else if (pathRef) { | 2015 } else if (pathRef) { |
| 2011 // If the buffer is not valid, pathRef should be NULL | 2016 // If the buffer is not valid, pathRef should be NULL |
| (...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2844 switch (this->getFillType()) { | 2849 switch (this->getFillType()) { |
| 2845 case SkPath::kEvenOdd_FillType: | 2850 case SkPath::kEvenOdd_FillType: |
| 2846 case SkPath::kInverseEvenOdd_FillType: | 2851 case SkPath::kInverseEvenOdd_FillType: |
| 2847 w &= 1; | 2852 w &= 1; |
| 2848 break; | 2853 break; |
| 2849 default: | 2854 default: |
| 2850 break; | 2855 break; |
| 2851 } | 2856 } |
| 2852 return SkToBool(w); | 2857 return SkToBool(w); |
| 2853 } | 2858 } |
| OLD | NEW |