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 2048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2059 fPts = srcPts; | 2059 fPts = srcPts; |
2060 return (Verb)verb; | 2060 return (Verb)verb; |
2061 } | 2061 } |
2062 | 2062 |
2063 /////////////////////////////////////////////////////////////////////////////// | 2063 /////////////////////////////////////////////////////////////////////////////// |
2064 | 2064 |
2065 /* | 2065 /* |
2066 Format in compressed buffer: [ptCount, verbCount, pts[], verbs[]] | 2066 Format in compressed buffer: [ptCount, verbCount, pts[], verbs[]] |
2067 */ | 2067 */ |
2068 | 2068 |
2069 uint32_t SkPath::writeToMemory(void* storage) const { | 2069 size_t SkPath::writeToMemory(void* storage) const { |
2070 SkDEBUGCODE(this->validate();) | 2070 SkDEBUGCODE(this->validate();) |
2071 | 2071 |
2072 if (NULL == storage) { | 2072 if (NULL == storage) { |
2073 const int byteCount = sizeof(int32_t) + fPathRef->writeSize(); | 2073 const int byteCount = sizeof(int32_t) + fPathRef->writeSize(); |
2074 return SkAlign4(byteCount); | 2074 return SkAlign4(byteCount); |
2075 } | 2075 } |
2076 | 2076 |
2077 SkWBuffer buffer(storage); | 2077 SkWBuffer buffer(storage); |
2078 | 2078 |
2079 int32_t packed = ((fIsOval & 1) << kIsOval_SerializationShift) | | 2079 int32_t packed = ((fIsOval & 1) << kIsOval_SerializationShift) | |
2080 (fConvexity << kConvexity_SerializationShift) | | 2080 (fConvexity << kConvexity_SerializationShift) | |
2081 (fFillType << kFillType_SerializationShift) | | 2081 (fFillType << kFillType_SerializationShift) | |
2082 (fSegmentMask << kSegmentMask_SerializationShift) | | 2082 (fSegmentMask << kSegmentMask_SerializationShift) | |
2083 (fDirection << kDirection_SerializationShift) | 2083 (fDirection << kDirection_SerializationShift) |
2084 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TO
O | 2084 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TO
O |
2085 | (0x1 << kNewFormat_SerializationShift); | 2085 | (0x1 << kNewFormat_SerializationShift); |
2086 #endif | 2086 #endif |
2087 | 2087 |
2088 buffer.write32(packed); | 2088 buffer.write32(packed); |
2089 | 2089 |
2090 fPathRef->writeToBuffer(&buffer); | 2090 fPathRef->writeToBuffer(&buffer); |
2091 | 2091 |
2092 buffer.padToAlign4(); | 2092 buffer.padToAlign4(); |
2093 return SkToU32(buffer.pos()); | 2093 return buffer.pos(); |
2094 } | 2094 } |
2095 | 2095 |
2096 uint32_t SkPath::readFromMemory(const void* storage) { | 2096 size_t SkPath::readFromMemory(const void* storage, size_t length) { |
2097 SkRBuffer buffer(storage); | 2097 SkRBufferWithSizeCheck buffer(storage, length); |
2098 | 2098 |
2099 uint32_t packed = buffer.readS32(); | 2099 uint32_t packed = buffer.readS32(); |
2100 fIsOval = (packed >> kIsOval_SerializationShift) & 1; | 2100 fIsOval = (packed >> kIsOval_SerializationShift) & 1; |
2101 fConvexity = (packed >> kConvexity_SerializationShift) & 0xFF; | 2101 fConvexity = (packed >> kConvexity_SerializationShift) & 0xFF; |
2102 fFillType = (packed >> kFillType_SerializationShift) & 0xFF; | 2102 fFillType = (packed >> kFillType_SerializationShift) & 0xFF; |
2103 fSegmentMask = (packed >> kSegmentMask_SerializationShift) & 0xF; | 2103 fSegmentMask = (packed >> kSegmentMask_SerializationShift) & 0xF; |
2104 fDirection = (packed >> kDirection_SerializationShift) & 0x3; | 2104 fDirection = (packed >> kDirection_SerializationShift) & 0x3; |
2105 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TO
O | 2105 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TO
O |
2106 bool newFormat = (packed >> kNewFormat_SerializationShift) & 1; | 2106 bool newFormat = (packed >> kNewFormat_SerializationShift) & 1; |
2107 #endif | 2107 #endif |
2108 | 2108 |
2109 fPathRef.reset(SkPathRef::CreateFromBuffer(&buffer | 2109 fPathRef.reset(SkPathRef::CreateFromBuffer(&buffer |
2110 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TO
O | 2110 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TO
O |
2111 , newFormat, packed) | 2111 , newFormat, packed |
2112 #endif | 2112 #endif |
2113 ); | 2113 )); |
2114 | 2114 |
2115 buffer.skipToAlign4(); | 2115 buffer.skipToAlign4(); |
2116 | 2116 |
2117 SkDEBUGCODE(this->validate();) | 2117 SkDEBUGCODE(this->validate();) |
2118 return SkToU32(buffer.pos()); | 2118 return buffer.isValid() ? buffer.pos() : 0; |
2119 } | 2119 } |
2120 | 2120 |
2121 /////////////////////////////////////////////////////////////////////////////// | 2121 /////////////////////////////////////////////////////////////////////////////// |
2122 | 2122 |
2123 #include "SkString.h" | 2123 #include "SkString.h" |
2124 | 2124 |
2125 static void append_scalar(SkString* str, SkScalar value) { | 2125 static void append_scalar(SkString* str, SkScalar value) { |
2126 SkString tmp; | 2126 SkString tmp; |
2127 tmp.printf("%g", value); | 2127 tmp.printf("%g", value); |
2128 if (tmp.contains('.')) { | 2128 if (tmp.contains('.')) { |
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3002 switch (this->getFillType()) { | 3002 switch (this->getFillType()) { |
3003 case SkPath::kEvenOdd_FillType: | 3003 case SkPath::kEvenOdd_FillType: |
3004 case SkPath::kInverseEvenOdd_FillType: | 3004 case SkPath::kInverseEvenOdd_FillType: |
3005 w &= 1; | 3005 w &= 1; |
3006 break; | 3006 break; |
3007 default: | 3007 default: |
3008 break; | 3008 break; |
3009 } | 3009 } |
3010 return SkToBool(w); | 3010 return SkToBool(w); |
3011 } | 3011 } |
OLD | NEW |