Changeset 190844 in webkit
- Timestamp:
- Oct 10, 2015 11:16:18 PM (9 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r190842 r190844 1 2015-10-10 Simon Fraser <simon.fraser@apple.com> 2 3 Use references and more const in SVGPathUtilities 4 https://bugs.webkit.org/show_bug.cgi?id=150007 5 6 Reviewed by Zalan Bujtas. 7 8 SVGPathUtilities had lots of pointers whose non-nullness was asserted, 9 little const, and was very trigger-happy with stack allocations. Clean 10 that all up. 11 12 * svg/SVGAnimatedPath.cpp: 13 (WebCore::SVGAnimatedPathAnimator::constructFromString): 14 (WebCore::SVGAnimatedPathAnimator::resetAnimValToBaseVal): 15 (WebCore::SVGAnimatedPathAnimator::addAnimatedTypes): 16 (WebCore::SVGAnimatedPathAnimator::calculateAnimatedValue): 17 * svg/SVGPathByteStream.h: 18 (WebCore::SVGPathByteStream::begin): 19 (WebCore::SVGPathByteStream::end): 20 (WebCore::SVGPathByteStream::append): 21 * svg/SVGPathByteStreamSource.cpp: 22 (WebCore::SVGPathByteStreamSource::SVGPathByteStreamSource): 23 * svg/SVGPathByteStreamSource.h: 24 * svg/SVGPathElement.cpp: 25 (WebCore::SVGPathElement::getTotalLength): 26 (WebCore::SVGPathElement::getPointAtLength): 27 (WebCore::SVGPathElement::getPathSegAtLength): 28 (WebCore::SVGPathElement::parseAttribute): 29 (WebCore::SVGPathElement::svgAttributeChanged): 30 (WebCore::SVGPathElement::pathByteStream): 31 (WebCore::SVGPathElement::lookupOrCreateDWrapper): 32 (WebCore::SVGPathElement::pathSegListChanged): 33 (WebCore::SVGPathElement::SVGPathElement): Deleted. 34 * svg/SVGPathElement.h: 35 * svg/SVGPathUtilities.cpp: 36 (WebCore::globalSVGPathBuilder): 37 (WebCore::globalSVGPathSegListBuilder): 38 (WebCore::globalSVGPathByteStreamBuilder): 39 (WebCore::globalSVGPathStringBuilder): 40 (WebCore::globalSVGPathTraversalStateBuilder): 41 (WebCore::globalSVGPathParser): 42 (WebCore::globalSVGPathBlender): 43 (WebCore::buildPathFromString): 44 (WebCore::buildSVGPathByteStreamFromSVGPathSegList): 45 (WebCore::appendSVGPathByteStreamFromSVGPathSeg): 46 (WebCore::buildPathFromByteStream): 47 (WebCore::buildSVGPathSegListFromByteStream): 48 (WebCore::buildStringFromByteStream): 49 (WebCore::buildStringFromSVGPathSegList): 50 (WebCore::buildSVGPathByteStreamFromString): 51 (WebCore::buildAnimatedSVGPathByteStream): 52 (WebCore::addToSVGPathByteStream): 53 (WebCore::getSVGPathSegAtLengthFromSVGPathByteStream): 54 (WebCore::getTotalLengthOfSVGPathByteStream): 55 (WebCore::getPointAtLengthOfSVGPathByteStream): 56 (WebCore::buildStringFromPath): 57 * svg/SVGPathUtilities.h: 58 * svg/properties/SVGAnimatedPathSegListPropertyTearOff.h: 59 (WebCore::SVGAnimatedPathSegListPropertyTearOff::animValDidChange): 60 1 61 2015-10-10 Andreas Kling <akling@apple.com> 2 62 -
trunk/Source/WebCore/svg/SVGAnimatedPath.cpp
r186541 r190844 35 35 { 36 36 auto byteStream = std::make_unique<SVGPathByteStream>(); 37 buildSVGPathByteStreamFromString(string, byteStream.get(), UnalteredParsing);37 buildSVGPathByteStreamFromString(string, *byteStream, UnalteredParsing); 38 38 return SVGAnimatedType::createPath(WTF::move(byteStream)); 39 39 } … … 59 59 const SVGPathSegList& baseValue = property->currentBaseValue(); 60 60 61 buildSVGPathByteStreamFromSVGPathSegList(baseValue, byteStream, UnalteredParsing);61 buildSVGPathByteStreamFromSVGPathSegList(baseValue, *byteStream, UnalteredParsing); 62 62 63 63 Vector<RefPtr<SVGAnimatedPathSegListPropertyTearOff>> result; … … 105 105 if (!fromPathSize || fromPathSize != toPath->size()) 106 106 return; 107 addToSVGPathByteStream( toPath,fromPath);107 addToSVGPathByteStream(*toPath, *fromPath); 108 108 } 109 109 … … 134 134 return; 135 135 136 buildAnimatedSVGPathByteStream( fromPath, toPath,animatedPath, percentage);136 buildAnimatedSVGPathByteStream(*fromPath, *toPath, *animatedPath, percentage); 137 137 138 138 // Handle additive='sum'. 139 139 if (lastAnimatedPath) 140 addToSVGPathByteStream( animatedPath, lastAnimatedPath.get());140 addToSVGPathByteStream(*animatedPath, *lastAnimatedPath); 141 141 142 142 // Handle accumulate='sum'. 143 143 if (m_animationElement->isAccumulated() && repeatCount) 144 addToSVGPathByteStream( animatedPath,toAtEndOfDurationPath, repeatCount);144 addToSVGPathByteStream(*animatedPath, *toAtEndOfDurationPath, repeatCount); 145 145 } 146 146 -
trunk/Source/WebCore/svg/SVGPathByteStream.h
r184844 r190844 56 56 } 57 57 58 DataIterator begin() { return m_data.begin(); } 59 DataIterator end() { return m_data.end(); } 58 DataIterator begin() const { return m_data.begin(); } 59 DataIterator end() const { return m_data.end(); } 60 60 61 void append(unsigned char byte) { m_data.append(byte); } 61 void append( SVGPathByteStream& other)62 void append(const SVGPathByteStream& other) 62 63 { 63 64 for (auto stream : other) -
trunk/Source/WebCore/svg/SVGPathByteStreamSource.cpp
r163440 r190844 23 23 namespace WebCore { 24 24 25 SVGPathByteStreamSource::SVGPathByteStreamSource( SVGPathByteStream*stream)25 SVGPathByteStreamSource::SVGPathByteStreamSource(const SVGPathByteStream& stream) 26 26 { 27 ASSERT(stream); 28 m_streamCurrent = stream->begin(); 29 m_streamEnd = stream->end(); 27 m_streamCurrent = stream.begin(); 28 m_streamEnd = stream.end(); 30 29 } 31 30 -
trunk/Source/WebCore/svg/SVGPathByteStreamSource.h
r163440 r190844 29 29 class SVGPathByteStreamSource : public SVGPathSource { 30 30 public: 31 explicit SVGPathByteStreamSource( SVGPathByteStream*);31 explicit SVGPathByteStreamSource(const SVGPathByteStream&); 32 32 33 33 private: -
trunk/Source/WebCore/svg/SVGPathElement.cpp
r189565 r190844 81 81 inline SVGPathElement::SVGPathElement(const QualifiedName& tagName, Document& document) 82 82 : SVGGraphicsElement(tagName, document) 83 , m_pathByteStream(std::make_unique<SVGPathByteStream>())84 83 , m_pathSegList(PathSegUnalteredRole) 85 84 , m_isAnimValObserved(false) … … 94 93 } 95 94 96 float SVGPathElement::getTotalLength() 95 float SVGPathElement::getTotalLength() const 97 96 { 98 97 float totalLength = 0; … … 101 100 } 102 101 103 SVGPoint SVGPathElement::getPointAtLength(float length) 102 SVGPoint SVGPathElement::getPointAtLength(float length) const 104 103 { 105 104 SVGPoint point; … … 108 107 } 109 108 110 unsigned SVGPathElement::getPathSegAtLength(float length) 109 unsigned SVGPathElement::getPathSegAtLength(float length) const 111 110 { 112 111 unsigned pathSeg = 0; … … 225 224 { 226 225 if (name == SVGNames::dAttr) { 227 if (!buildSVGPathByteStreamFromString(value, m_pathByteStream .get(), UnalteredParsing))226 if (!buildSVGPathByteStreamFromString(value, m_pathByteStream, UnalteredParsing)) 228 227 document().accessSVGExtensions().reportError("Problem parsing d=\"" + value + "\""); 229 228 return; … … 255 254 if (m_pathSegList.shouldSynchronize && !SVGAnimatedProperty::lookupWrapper<SVGPathElement, SVGAnimatedPathSegListPropertyTearOff>(this, dPropertyInfo())->isAnimating()) { 256 255 SVGPathSegList newList(PathSegUnalteredRole); 257 buildSVGPathSegListFromByteStream(m_pathByteStream .get(),this, newList, UnalteredParsing);256 buildSVGPathSegListFromByteStream(m_pathByteStream, *this, newList, UnalteredParsing); 258 257 m_pathSegList.value = newList; 259 258 } … … 294 293 } 295 294 296 SVGPathByteStream*SVGPathElement::pathByteStream() const295 const SVGPathByteStream& SVGPathElement::pathByteStream() const 297 296 { 298 297 SVGAnimatedProperty* property = SVGAnimatedProperty::lookupWrapper<SVGPathElement, SVGAnimatedPathSegListPropertyTearOff>(this, dPropertyInfo()); 299 298 if (!property || !property->isAnimating()) 300 return m_pathByteStream.get(); 301 return static_cast<SVGAnimatedPathSegListPropertyTearOff*>(property)->animatedPathByteStream(); 299 return m_pathByteStream; 300 301 SVGPathByteStream* animatedPathByteStream = static_cast<SVGAnimatedPathSegListPropertyTearOff*>(property)->animatedPathByteStream(); 302 if (!animatedPathByteStream) 303 return m_pathByteStream; 304 305 return *animatedPathByteStream; 302 306 } 303 307 … … 311 315 312 316 // Build initial SVGPathSegList. 313 buildSVGPathSegListFromByteStream(ownerType.m_pathByteStream .get(), &ownerType, ownerType.m_pathSegList.value, UnalteredParsing);317 buildSVGPathSegListFromByteStream(ownerType.m_pathByteStream, ownerType, ownerType.m_pathSegList.value, UnalteredParsing); 314 318 315 319 return SVGAnimatedProperty::lookupOrCreateWrapper<SVGPathElement, SVGAnimatedPathSegListPropertyTearOff, SVGPathSegList> … … 360 364 if (listModification == ListModificationAppend) { 361 365 ASSERT(!m_pathSegList.value.isEmpty()); 362 appendSVGPathByteStreamFromSVGPathSeg(m_pathSegList.value.last().copyRef(), m_pathByteStream .get(), UnalteredParsing);366 appendSVGPathByteStreamFromSVGPathSeg(m_pathSegList.value.last().copyRef(), m_pathByteStream, UnalteredParsing); 363 367 } else 364 buildSVGPathByteStreamFromSVGPathSegList(m_pathSegList.value, m_pathByteStream .get(), UnalteredParsing);368 buildSVGPathByteStreamFromSVGPathSegList(m_pathSegList.value, m_pathByteStream, UnalteredParsing); 365 369 break; 366 370 case PathSegUndefinedRole: -
trunk/Source/WebCore/svg/SVGPathElement.h
r185503 r190844 58 58 static Ref<SVGPathElement> create(const QualifiedName&, Document&); 59 59 60 float getTotalLength() ;61 SVGPoint getPointAtLength(float distance) ;62 unsigned getPathSegAtLength(float distance) ;60 float getTotalLength() const; 61 SVGPoint getPointAtLength(float distance) const; 62 unsigned getPathSegAtLength(float distance) const; 63 63 64 64 Ref<SVGPathSegClosePath> createSVGPathSegClosePath(SVGPathSegRole = PathSegUndefinedRole); … … 88 88 SVGPathSegListPropertyTearOff* animatedNormalizedPathSegList(); 89 89 90 SVGPathByteStream*pathByteStream() const;90 const SVGPathByteStream& pathByteStream() const; 91 91 92 92 void pathSegListChanged(SVGPathSegRole, ListModification = ListModificationUnknown); … … 125 125 126 126 private: 127 std::unique_ptr<SVGPathByteStream>m_pathByteStream;127 SVGPathByteStream m_pathByteStream; 128 128 mutable SVGSynchronizableAnimatedProperty<SVGPathSegList> m_pathSegList; 129 129 bool m_isAnimValObserved; -
trunk/Source/WebCore/svg/SVGPathUtilities.cpp
r189565 r190844 38 38 namespace WebCore { 39 39 40 static SVGPathBuilder* globalSVGPathBuilder(Path& result) 41 { 42 static SVGPathBuilder* s_builder = nullptr; 43 if (!s_builder) 44 s_builder = new SVGPathBuilder; 45 46 s_builder->setCurrentPath(&result); 47 return s_builder; 48 } 49 50 static SVGPathSegListBuilder* globalSVGPathSegListBuilder(SVGPathElement* element, SVGPathSegRole role, SVGPathSegList& result) 51 { 52 static SVGPathSegListBuilder* s_builder = nullptr; 53 if (!s_builder) 54 s_builder = new SVGPathSegListBuilder; 55 56 s_builder->setCurrentSVGPathElement(element); 57 s_builder->setCurrentSVGPathSegList(result); 58 s_builder->setCurrentSVGPathSegRole(role); 59 return s_builder; 60 } 61 62 static SVGPathByteStreamBuilder* globalSVGPathByteStreamBuilder(SVGPathByteStream* result) 63 { 64 static SVGPathByteStreamBuilder* s_builder = nullptr; 65 if (!s_builder) 66 s_builder = new SVGPathByteStreamBuilder; 67 68 s_builder->setCurrentByteStream(result); 69 return s_builder; 70 } 71 72 static SVGPathStringBuilder* globalSVGPathStringBuilder() 73 { 74 static SVGPathStringBuilder* s_builder = nullptr; 75 if (!s_builder) 76 s_builder = new SVGPathStringBuilder; 77 78 return s_builder; 79 } 80 81 static SVGPathTraversalStateBuilder* globalSVGPathTraversalStateBuilder(PathTraversalState& traversalState, float length) 82 { 83 static SVGPathTraversalStateBuilder* s_builder = nullptr; 84 if (!s_builder) 85 s_builder = new SVGPathTraversalStateBuilder; 86 87 s_builder->setCurrentTraversalState(&traversalState); 88 s_builder->setDesiredLength(length); 89 return s_builder; 90 } 91 92 static SVGPathParser* globalSVGPathParser(SVGPathSource* source, SVGPathConsumer* consumer) 93 { 94 static SVGPathParser* s_parser = nullptr; 95 if (!s_parser) 96 s_parser = new SVGPathParser; 97 98 s_parser->setCurrentSource(source); 99 s_parser->setCurrentConsumer(consumer); 100 return s_parser; 101 } 102 103 static SVGPathBlender* globalSVGPathBlender() 104 { 105 static SVGPathBlender* s_blender = nullptr; 106 if (!s_blender) 107 s_blender = new SVGPathBlender; 108 109 return s_blender; 40 // FIXME: are all these globals warranted? Why not just make them on the stack? 41 static SVGPathBuilder& globalSVGPathBuilder(Path& result) 42 { 43 static NeverDestroyed<SVGPathBuilder> s_builder; 44 s_builder.get().setCurrentPath(&result); 45 return s_builder.get(); 46 } 47 48 static SVGPathSegListBuilder& globalSVGPathSegListBuilder(SVGPathElement& element, SVGPathSegRole role, SVGPathSegList& result) 49 { 50 static NeverDestroyed<SVGPathSegListBuilder> s_builder; 51 52 s_builder.get().setCurrentSVGPathElement(&element); 53 s_builder.get().setCurrentSVGPathSegList(result); 54 s_builder.get().setCurrentSVGPathSegRole(role); 55 return s_builder.get(); 56 } 57 58 static SVGPathByteStreamBuilder& globalSVGPathByteStreamBuilder(SVGPathByteStream& result) 59 { 60 static NeverDestroyed<SVGPathByteStreamBuilder> s_builder; 61 s_builder.get().setCurrentByteStream(&result); 62 return s_builder.get(); 63 } 64 65 static SVGPathStringBuilder& globalSVGPathStringBuilder() 66 { 67 static NeverDestroyed<SVGPathStringBuilder> s_builder; 68 return s_builder.get(); 69 } 70 71 static SVGPathTraversalStateBuilder& globalSVGPathTraversalStateBuilder(PathTraversalState& traversalState, float length) 72 { 73 static NeverDestroyed<SVGPathTraversalStateBuilder> s_parser; 74 75 s_parser.get().setCurrentTraversalState(&traversalState); 76 s_parser.get().setDesiredLength(length); 77 return s_parser.get(); 78 } 79 80 // FIXME: why bother keeping a singleton around? Is it slow to allocate? 81 static SVGPathParser& globalSVGPathParser(SVGPathSource& source, SVGPathConsumer& consumer) 82 { 83 static NeverDestroyed<SVGPathParser> s_parser; 84 85 s_parser.get().setCurrentSource(&source); 86 s_parser.get().setCurrentConsumer(&consumer); 87 return s_parser.get(); 88 } 89 90 static SVGPathBlender& globalSVGPathBlender() 91 { 92 static NeverDestroyed<SVGPathBlender> s_blender; 93 return s_blender.get(); 110 94 } 111 95 … … 115 99 return true; 116 100 117 SVGPathBuilder* builder = globalSVGPathBuilder(result); 118 119 auto source = std::make_unique<SVGPathStringSource>(d); 120 SVGPathParser* parser = globalSVGPathParser(source.get(), builder); 121 bool ok = parser->parsePathDataFromSource(NormalizedParsing); 122 parser->cleanup(); 123 return ok; 124 } 125 126 bool buildSVGPathByteStreamFromSVGPathSegList(const SVGPathSegList& list, SVGPathByteStream* result, PathParsingMode parsingMode) 127 { 128 ASSERT(result); 129 result->clear(); 101 SVGPathBuilder& builder = globalSVGPathBuilder(result); 102 103 SVGPathStringSource source(d); 104 SVGPathParser& parser = globalSVGPathParser(source, builder); 105 bool ok = parser.parsePathDataFromSource(NormalizedParsing); 106 parser.cleanup(); 107 return ok; 108 } 109 110 bool buildSVGPathByteStreamFromSVGPathSegList(const SVGPathSegList& list, SVGPathByteStream& result, PathParsingMode parsingMode) 111 { 112 result.clear(); 130 113 if (list.isEmpty()) 131 114 return true; 132 115 133 SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder(result); 134 135 auto source = std::make_unique<SVGPathSegListSource>(list); 136 SVGPathParser* parser = globalSVGPathParser(source.get(), builder); 137 bool ok = parser->parsePathDataFromSource(parsingMode); 138 parser->cleanup(); 139 return ok; 140 } 141 142 bool appendSVGPathByteStreamFromSVGPathSeg(RefPtr<SVGPathSeg>&& pathSeg, SVGPathByteStream* result, PathParsingMode parsingMode) 143 { 144 ASSERT(result); 116 SVGPathByteStreamBuilder& builder = globalSVGPathByteStreamBuilder(result); 117 118 SVGPathSegListSource source(list); 119 SVGPathParser& parser = globalSVGPathParser(source, builder); 120 bool ok = parser.parsePathDataFromSource(parsingMode); 121 parser.cleanup(); 122 return ok; 123 } 124 125 bool appendSVGPathByteStreamFromSVGPathSeg(RefPtr<SVGPathSeg>&& pathSeg, SVGPathByteStream& result, PathParsingMode parsingMode) 126 { 145 127 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=15412 - Implement normalized path segment lists! 146 128 ASSERT(parsingMode == UnalteredParsing); … … 148 130 SVGPathSegList appendedItemList(PathSegUnalteredRole); 149 131 appendedItemList.append(WTF::move(pathSeg)); 150 auto appendedByteStream = std::make_unique<SVGPathByteStream>(); 151 152 SVGPathByteStreamBuilder * builder = globalSVGPathByteStreamBuilder(appendedByteStream.get());153 auto source = std::make_unique<SVGPathSegListSource>(appendedItemList);154 SVGPathParser * parser = globalSVGPathParser(source.get(), builder);155 bool ok = parser ->parsePathDataFromSource(parsingMode, false);156 parser ->cleanup();132 133 SVGPathByteStream appendedByteStream; 134 SVGPathByteStreamBuilder& builder = globalSVGPathByteStreamBuilder(appendedByteStream); 135 SVGPathSegListSource source(appendedItemList); 136 SVGPathParser& parser = globalSVGPathParser(source, builder); 137 bool ok = parser.parsePathDataFromSource(parsingMode, false); 138 parser.cleanup(); 157 139 158 140 if (ok) 159 result->append(*appendedByteStream); 160 161 return ok; 162 } 163 164 bool buildPathFromByteStream(SVGPathByteStream* stream, Path& result) 165 { 166 ASSERT(stream); 167 if (stream->isEmpty()) 168 return true; 169 170 SVGPathBuilder* builder = globalSVGPathBuilder(result); 171 172 auto source = std::make_unique<SVGPathByteStreamSource>(stream); 173 SVGPathParser* parser = globalSVGPathParser(source.get(), builder); 174 bool ok = parser->parsePathDataFromSource(NormalizedParsing); 175 parser->cleanup(); 176 return ok; 177 } 178 179 bool buildSVGPathSegListFromByteStream(SVGPathByteStream* stream, SVGPathElement* element, SVGPathSegList& result, PathParsingMode parsingMode) 180 { 181 ASSERT(stream); 182 if (stream->isEmpty()) 183 return true; 184 185 SVGPathSegListBuilder* builder = globalSVGPathSegListBuilder(element, parsingMode == NormalizedParsing ? PathSegNormalizedRole : PathSegUnalteredRole, result); 186 187 auto source = std::make_unique<SVGPathByteStreamSource>(stream); 188 SVGPathParser* parser = globalSVGPathParser(source.get(), builder); 189 bool ok = parser->parsePathDataFromSource(parsingMode); 190 parser->cleanup(); 191 return ok; 192 } 193 194 bool buildStringFromByteStream(SVGPathByteStream* stream, String& result, PathParsingMode parsingMode) 195 { 196 ASSERT(stream); 197 if (stream->isEmpty()) 198 return true; 199 200 SVGPathStringBuilder* builder = globalSVGPathStringBuilder(); 201 202 auto source = std::make_unique<SVGPathByteStreamSource>(stream); 203 SVGPathParser* parser = globalSVGPathParser(source.get(), builder); 204 bool ok = parser->parsePathDataFromSource(parsingMode); 205 result = builder->result(); 206 parser->cleanup(); 141 result.append(appendedByteStream); 142 143 return ok; 144 } 145 146 bool buildPathFromByteStream(const SVGPathByteStream& stream, Path& result) 147 { 148 if (stream.isEmpty()) 149 return true; 150 151 SVGPathBuilder& builder = globalSVGPathBuilder(result); 152 153 SVGPathByteStreamSource source(stream); 154 SVGPathParser& parser = globalSVGPathParser(source, builder); 155 bool ok = parser.parsePathDataFromSource(NormalizedParsing); 156 parser.cleanup(); 157 return ok; 158 } 159 160 bool buildSVGPathSegListFromByteStream(const SVGPathByteStream& stream, SVGPathElement& element, SVGPathSegList& result, PathParsingMode parsingMode) 161 { 162 if (stream.isEmpty()) 163 return true; 164 165 SVGPathSegListBuilder& builder = globalSVGPathSegListBuilder(element, parsingMode == NormalizedParsing ? PathSegNormalizedRole : PathSegUnalteredRole, result); 166 167 SVGPathByteStreamSource source(stream); 168 SVGPathParser& parser = globalSVGPathParser(source, builder); 169 bool ok = parser.parsePathDataFromSource(parsingMode); 170 parser.cleanup(); 171 return ok; 172 } 173 174 bool buildStringFromByteStream(const SVGPathByteStream& stream, String& result, PathParsingMode parsingMode) 175 { 176 if (stream.isEmpty()) 177 return true; 178 179 SVGPathStringBuilder& builder = globalSVGPathStringBuilder(); 180 181 SVGPathByteStreamSource source(stream); 182 SVGPathParser& parser = globalSVGPathParser(source, builder); 183 bool ok = parser.parsePathDataFromSource(parsingMode); 184 result = builder.result(); 185 parser.cleanup(); 207 186 return ok; 208 187 } … … 214 193 return true; 215 194 216 SVGPathStringBuilder* builder = globalSVGPathStringBuilder(); 217 218 auto source = std::make_unique<SVGPathSegListSource>(list); 219 SVGPathParser* parser = globalSVGPathParser(source.get(), builder); 220 bool ok = parser->parsePathDataFromSource(parsingMode); 221 result = builder->result(); 222 parser->cleanup(); 223 return ok; 224 } 225 226 bool buildSVGPathByteStreamFromString(const String& d, SVGPathByteStream* result, PathParsingMode parsingMode) 227 { 228 ASSERT(result); 229 result->clear(); 195 SVGPathStringBuilder& builder = globalSVGPathStringBuilder(); 196 197 SVGPathSegListSource source(list); 198 SVGPathParser& parser = globalSVGPathParser(source, builder); 199 bool ok = parser.parsePathDataFromSource(parsingMode); 200 result = builder.result(); 201 parser.cleanup(); 202 return ok; 203 } 204 205 bool buildSVGPathByteStreamFromString(const String& d, SVGPathByteStream& result, PathParsingMode parsingMode) 206 { 207 result.clear(); 230 208 if (d.isEmpty()) 231 209 return true; 232 210 233 SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder(result); 234 235 auto source = std::make_unique<SVGPathStringSource>(d); 236 SVGPathParser* parser = globalSVGPathParser(source.get(), builder); 237 bool ok = parser->parsePathDataFromSource(parsingMode); 238 parser->cleanup(); 239 return ok; 240 } 241 242 bool buildAnimatedSVGPathByteStream(SVGPathByteStream* fromStream, SVGPathByteStream* toStream, SVGPathByteStream* result, float progress) 243 { 244 ASSERT(fromStream); 245 ASSERT(toStream); 246 ASSERT(result); 247 ASSERT(toStream != result); 248 249 result->clear(); 250 if (toStream->isEmpty()) 251 return true; 252 253 SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder(result); 254 255 auto fromSource = std::make_unique<SVGPathByteStreamSource>(fromStream); 256 auto toSource = std::make_unique<SVGPathByteStreamSource>(toStream); 257 SVGPathBlender* blender = globalSVGPathBlender(); 258 bool ok = blender->blendAnimatedPath(progress, fromSource.get(), toSource.get(), builder); 259 blender->cleanup(); 260 return ok; 261 } 262 263 bool addToSVGPathByteStream(SVGPathByteStream* fromStream, SVGPathByteStream* byStream, unsigned repeatCount) 264 { 265 ASSERT(fromStream); 266 ASSERT(byStream); 267 if (fromStream->isEmpty() || byStream->isEmpty()) 268 return true; 269 270 SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder(fromStream); 271 272 auto fromStreamCopy = fromStream->copy(); 273 fromStream->clear(); 274 275 auto fromSource = std::make_unique<SVGPathByteStreamSource>(fromStreamCopy.get()); 276 auto bySource = std::make_unique<SVGPathByteStreamSource>(byStream); 277 SVGPathBlender* blender = globalSVGPathBlender(); 278 bool ok = blender->addAnimatedPath(fromSource.get(), bySource.get(), builder, repeatCount); 279 blender->cleanup(); 280 return ok; 281 } 282 283 bool getSVGPathSegAtLengthFromSVGPathByteStream(SVGPathByteStream* stream, float length, unsigned& pathSeg) 284 { 285 ASSERT(stream); 286 if (stream->isEmpty()) 211 SVGPathByteStreamBuilder& builder = globalSVGPathByteStreamBuilder(result); 212 213 SVGPathStringSource source(d); 214 SVGPathParser& parser = globalSVGPathParser(source, builder); 215 bool ok = parser.parsePathDataFromSource(parsingMode); 216 parser.cleanup(); 217 return ok; 218 } 219 220 bool buildAnimatedSVGPathByteStream(const SVGPathByteStream& fromStream, const SVGPathByteStream& toStream, SVGPathByteStream& result, float progress) 221 { 222 ASSERT(&toStream != &result); 223 result.clear(); 224 if (toStream.isEmpty()) 225 return true; 226 227 SVGPathByteStreamBuilder& builder = globalSVGPathByteStreamBuilder(result); 228 229 SVGPathByteStreamSource fromSource(fromStream); 230 SVGPathByteStreamSource toSource(toStream); 231 SVGPathBlender& blender = globalSVGPathBlender(); 232 bool ok = blender.blendAnimatedPath(progress, &fromSource, &toSource, &builder); 233 blender.cleanup(); 234 return ok; 235 } 236 237 bool addToSVGPathByteStream(SVGPathByteStream& streamToAppendTo, const SVGPathByteStream& byStream, unsigned repeatCount) 238 { 239 // Why return when streamToAppendTo is empty? Don't we still need to append? 240 if (streamToAppendTo.isEmpty() || byStream.isEmpty()) 241 return true; 242 243 // Is it OK to make the SVGPathByteStreamBuilder from a stream, and then clear that stream? 244 SVGPathByteStreamBuilder& builder = globalSVGPathByteStreamBuilder(streamToAppendTo); 245 246 SVGPathByteStream fromStreamCopy = streamToAppendTo; 247 streamToAppendTo.clear(); 248 249 SVGPathByteStreamSource fromSource(fromStreamCopy); 250 SVGPathByteStreamSource bySource(byStream); 251 SVGPathBlender& blender = globalSVGPathBlender(); 252 bool ok = blender.addAnimatedPath(&fromSource, &bySource, &builder, repeatCount); 253 blender.cleanup(); 254 return ok; 255 } 256 257 bool getSVGPathSegAtLengthFromSVGPathByteStream(const SVGPathByteStream& stream, float length, unsigned& pathSeg) 258 { 259 if (stream.isEmpty()) 287 260 return false; 288 261 289 262 PathTraversalState traversalState(PathTraversalState::Action::SegmentAtLength); 290 SVGPathTraversalStateBuilder* builder = globalSVGPathTraversalStateBuilder(traversalState, length); 291 292 auto source = std::make_unique<SVGPathByteStreamSource>(stream); 293 SVGPathParser* parser = globalSVGPathParser(source.get(), builder); 294 bool ok = parser->parsePathDataFromSource(NormalizedParsing); 295 pathSeg = builder->pathSegmentIndex(); 296 parser->cleanup(); 297 return ok; 298 } 299 300 bool getTotalLengthOfSVGPathByteStream(SVGPathByteStream* stream, float& totalLength) 301 { 302 ASSERT(stream); 303 if (stream->isEmpty()) 263 SVGPathTraversalStateBuilder& builder = globalSVGPathTraversalStateBuilder(traversalState, length); 264 265 SVGPathByteStreamSource source(stream); 266 SVGPathParser& parser = globalSVGPathParser(source, builder); 267 bool ok = parser.parsePathDataFromSource(NormalizedParsing); 268 pathSeg = builder.pathSegmentIndex(); 269 parser.cleanup(); 270 return ok; 271 } 272 273 bool getTotalLengthOfSVGPathByteStream(const SVGPathByteStream& stream, float& totalLength) 274 { 275 if (stream.isEmpty()) 304 276 return false; 305 277 306 278 PathTraversalState traversalState(PathTraversalState::Action::TotalLength); 307 SVGPathTraversalStateBuilder* builder = globalSVGPathTraversalStateBuilder(traversalState, 0); 308 309 auto source = std::make_unique<SVGPathByteStreamSource>(stream); 310 SVGPathParser* parser = globalSVGPathParser(source.get(), builder); 311 bool ok = parser->parsePathDataFromSource(NormalizedParsing); 312 totalLength = builder->totalLength(); 313 parser->cleanup(); 314 return ok; 315 } 316 317 bool getPointAtLengthOfSVGPathByteStream(SVGPathByteStream* stream, float length, SVGPoint& point) 318 { 319 ASSERT(stream); 320 if (stream->isEmpty()) 279 SVGPathTraversalStateBuilder& builder = globalSVGPathTraversalStateBuilder(traversalState, 0); 280 281 SVGPathByteStreamSource source(stream); 282 SVGPathParser& parser = globalSVGPathParser(source, builder); 283 bool ok = parser.parsePathDataFromSource(NormalizedParsing); 284 totalLength = builder.totalLength(); 285 parser.cleanup(); 286 return ok; 287 } 288 289 bool getPointAtLengthOfSVGPathByteStream(const SVGPathByteStream& stream, float length, SVGPoint& point) 290 { 291 if (stream.isEmpty()) 321 292 return false; 322 293 323 294 PathTraversalState traversalState(PathTraversalState::Action::VectorAtLength); 324 SVGPathTraversalStateBuilder *builder = globalSVGPathTraversalStateBuilder(traversalState, length);325 326 auto source = std::make_unique<SVGPathByteStreamSource>(stream);327 SVGPathParser * parser = globalSVGPathParser(source.get(), builder);328 bool ok = parser ->parsePathDataFromSource(NormalizedParsing);329 point = builder ->currentPoint();330 parser ->cleanup();295 SVGPathTraversalStateBuilder& builder = globalSVGPathTraversalStateBuilder(traversalState, length); 296 297 SVGPathByteStreamSource source(stream); 298 SVGPathParser& parser = globalSVGPathParser(source, builder); 299 bool ok = parser.parsePathDataFromSource(NormalizedParsing); 300 point = builder.currentPoint(); 301 parser.cleanup(); 331 302 return ok; 332 303 } … … 362 333 // a path, only apply a function to all path elements at once. 363 334 364 SVGPathStringBuilder *builder = globalSVGPathStringBuilder();365 path.apply([ builder](const PathElement& pathElement) {366 pathIteratorForBuildingString( *builder, pathElement);335 SVGPathStringBuilder& builder = globalSVGPathStringBuilder(); 336 path.apply([&builder](const PathElement& pathElement) { 337 pathIteratorForBuildingString(builder, pathElement); 367 338 }); 368 string = builder ->result();369 static_cast<SVGPathConsumer *>(builder)->cleanup();339 string = builder.result(); 340 static_cast<SVGPathConsumer&>(builder).cleanup(); // Wat? 370 341 371 342 return true; -
trunk/Source/WebCore/svg/SVGPathUtilities.h
r189565 r190844 35 35 // String/SVGPathByteStream -> Path 36 36 bool buildPathFromString(const String&, Path&); 37 bool buildPathFromByteStream( SVGPathByteStream*, Path&);37 bool buildPathFromByteStream(const SVGPathByteStream&, Path&); 38 38 39 39 // SVGPathSegList/String -> SVGPathByteStream 40 bool buildSVGPathByteStreamFromSVGPathSegList(const SVGPathSegList&, SVGPathByteStream *, PathParsingMode);41 bool appendSVGPathByteStreamFromSVGPathSeg(RefPtr<SVGPathSeg>&&, SVGPathByteStream *, PathParsingMode);42 bool buildSVGPathByteStreamFromString(const String&, SVGPathByteStream *, PathParsingMode);40 bool buildSVGPathByteStreamFromSVGPathSegList(const SVGPathSegList&, SVGPathByteStream& result, PathParsingMode); 41 bool appendSVGPathByteStreamFromSVGPathSeg(RefPtr<SVGPathSeg>&&, SVGPathByteStream&, PathParsingMode); 42 bool buildSVGPathByteStreamFromString(const String&, SVGPathByteStream&, PathParsingMode); 43 43 44 44 // SVGPathByteStream/SVGPathSegList -> String 45 bool buildStringFromByteStream( SVGPathByteStream*, String&, PathParsingMode);45 bool buildStringFromByteStream(const SVGPathByteStream&, String&, PathParsingMode); 46 46 bool buildStringFromSVGPathSegList(const SVGPathSegList&, String&, PathParsingMode); 47 47 48 48 // SVGPathByteStream -> SVGPathSegList 49 bool buildSVGPathSegListFromByteStream( SVGPathByteStream*, SVGPathElement*, SVGPathSegList&, PathParsingMode);49 bool buildSVGPathSegListFromByteStream(const SVGPathByteStream&, SVGPathElement&, SVGPathSegList&, PathParsingMode); 50 50 51 bool buildAnimatedSVGPathByteStream( SVGPathByteStream*, SVGPathByteStream*, SVGPathByteStream*, float);52 bool addToSVGPathByteStream(SVGPathByteStream *, SVGPathByteStream*, unsigned repeatCount = 1);51 bool buildAnimatedSVGPathByteStream(const SVGPathByteStream& from, const SVGPathByteStream& to, SVGPathByteStream& result, float progress); 52 bool addToSVGPathByteStream(SVGPathByteStream& streamToAppendTo, const SVGPathByteStream& from, unsigned repeatCount = 1); 53 53 54 bool getSVGPathSegAtLengthFromSVGPathByteStream( SVGPathByteStream*, float length, unsigned& pathSeg);55 bool getTotalLengthOfSVGPathByteStream( SVGPathByteStream*, float& totalLength);56 bool getPointAtLengthOfSVGPathByteStream( SVGPathByteStream*, float length, SVGPoint&);54 bool getSVGPathSegAtLengthFromSVGPathByteStream(const SVGPathByteStream&, float length, unsigned& pathSeg); 55 bool getTotalLengthOfSVGPathByteStream(const SVGPathByteStream&, float& totalLength); 56 bool getPointAtLengthOfSVGPathByteStream(const SVGPathByteStream&, float length, SVGPoint&); 57 57 58 58 // Path -> String -
trunk/Source/WebCore/svg/properties/SVGAnimatedPathSegListPropertyTearOff.h
r184852 r190844 96 96 SVGPathSegList& animatedList = currentAnimatedValue(); 97 97 animatedList.clear(); 98 buildSVGPathSegListFromByteStream( m_animatedPathByteStream,pathElement, animatedList, UnalteredParsing);98 buildSVGPathSegListFromByteStream(*m_animatedPathByteStream, *pathElement, animatedList, UnalteredParsing); 99 99 } 100 100
Note: See TracChangeset
for help on using the changeset viewer.