Changeset 190844 in webkit


Ignore:
Timestamp:
Oct 10, 2015 11:16:18 PM (9 years ago)
Author:
Simon Fraser
Message:

Use references and more const in SVGPathUtilities
https://bugs.webkit.org/show_bug.cgi?id=150007

Reviewed by Zalan Bujtas.

SVGPathUtilities had lots of pointers whose non-nullness was asserted,
little const, and was very trigger-happy with stack allocations. Clean
that all up.

  • svg/SVGAnimatedPath.cpp:

(WebCore::SVGAnimatedPathAnimator::constructFromString):
(WebCore::SVGAnimatedPathAnimator::resetAnimValToBaseVal):
(WebCore::SVGAnimatedPathAnimator::addAnimatedTypes):
(WebCore::SVGAnimatedPathAnimator::calculateAnimatedValue):

  • svg/SVGPathByteStream.h:

(WebCore::SVGPathByteStream::begin):
(WebCore::SVGPathByteStream::end):
(WebCore::SVGPathByteStream::append):

  • svg/SVGPathByteStreamSource.cpp:

(WebCore::SVGPathByteStreamSource::SVGPathByteStreamSource):

  • svg/SVGPathByteStreamSource.h:
  • svg/SVGPathElement.cpp:

(WebCore::SVGPathElement::getTotalLength):
(WebCore::SVGPathElement::getPointAtLength):
(WebCore::SVGPathElement::getPathSegAtLength):
(WebCore::SVGPathElement::parseAttribute):
(WebCore::SVGPathElement::svgAttributeChanged):
(WebCore::SVGPathElement::pathByteStream):
(WebCore::SVGPathElement::lookupOrCreateDWrapper):
(WebCore::SVGPathElement::pathSegListChanged):
(WebCore::SVGPathElement::SVGPathElement): Deleted.

  • svg/SVGPathElement.h:
  • svg/SVGPathUtilities.cpp:

(WebCore::globalSVGPathBuilder):
(WebCore::globalSVGPathSegListBuilder):
(WebCore::globalSVGPathByteStreamBuilder):
(WebCore::globalSVGPathStringBuilder):
(WebCore::globalSVGPathTraversalStateBuilder):
(WebCore::globalSVGPathParser):
(WebCore::globalSVGPathBlender):
(WebCore::buildPathFromString):
(WebCore::buildSVGPathByteStreamFromSVGPathSegList):
(WebCore::appendSVGPathByteStreamFromSVGPathSeg):
(WebCore::buildPathFromByteStream):
(WebCore::buildSVGPathSegListFromByteStream):
(WebCore::buildStringFromByteStream):
(WebCore::buildStringFromSVGPathSegList):
(WebCore::buildSVGPathByteStreamFromString):
(WebCore::buildAnimatedSVGPathByteStream):
(WebCore::addToSVGPathByteStream):
(WebCore::getSVGPathSegAtLengthFromSVGPathByteStream):
(WebCore::getTotalLengthOfSVGPathByteStream):
(WebCore::getPointAtLengthOfSVGPathByteStream):
(WebCore::buildStringFromPath):

  • svg/SVGPathUtilities.h:
  • svg/properties/SVGAnimatedPathSegListPropertyTearOff.h:

(WebCore::SVGAnimatedPathSegListPropertyTearOff::animValDidChange):

Location:
trunk/Source/WebCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r190842 r190844  
     12015-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
    1612015-10-10  Andreas Kling  <akling@apple.com>
    262
  • trunk/Source/WebCore/svg/SVGAnimatedPath.cpp

    r186541 r190844  
    3535{
    3636    auto byteStream = std::make_unique<SVGPathByteStream>();
    37     buildSVGPathByteStreamFromString(string, byteStream.get(), UnalteredParsing);
     37    buildSVGPathByteStreamFromString(string, *byteStream, UnalteredParsing);
    3838    return SVGAnimatedType::createPath(WTF::move(byteStream));
    3939}
     
    5959    const SVGPathSegList& baseValue = property->currentBaseValue();
    6060
    61     buildSVGPathByteStreamFromSVGPathSegList(baseValue, byteStream, UnalteredParsing);
     61    buildSVGPathByteStreamFromSVGPathSegList(baseValue, *byteStream, UnalteredParsing);
    6262
    6363    Vector<RefPtr<SVGAnimatedPathSegListPropertyTearOff>> result;
     
    105105    if (!fromPathSize || fromPathSize != toPath->size())
    106106        return;
    107     addToSVGPathByteStream(toPath, fromPath);
     107    addToSVGPathByteStream(*toPath, *fromPath);
    108108}
    109109
     
    134134        return;
    135135
    136     buildAnimatedSVGPathByteStream(fromPath, toPath, animatedPath, percentage);
     136    buildAnimatedSVGPathByteStream(*fromPath, *toPath, *animatedPath, percentage);
    137137
    138138    // Handle additive='sum'.
    139139    if (lastAnimatedPath)
    140         addToSVGPathByteStream(animatedPath, lastAnimatedPath.get());
     140        addToSVGPathByteStream(*animatedPath, *lastAnimatedPath);
    141141
    142142    // Handle accumulate='sum'.
    143143    if (m_animationElement->isAccumulated() && repeatCount)
    144         addToSVGPathByteStream(animatedPath, toAtEndOfDurationPath, repeatCount);
     144        addToSVGPathByteStream(*animatedPath, *toAtEndOfDurationPath, repeatCount);
    145145}
    146146
  • trunk/Source/WebCore/svg/SVGPathByteStream.h

    r184844 r190844  
    5656    }
    5757
    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
    6061    void append(unsigned char byte) { m_data.append(byte); }
    61     void append(SVGPathByteStream& other)
     62    void append(const SVGPathByteStream& other)
    6263    {
    6364        for (auto stream : other)
  • trunk/Source/WebCore/svg/SVGPathByteStreamSource.cpp

    r163440 r190844  
    2323namespace WebCore {
    2424
    25 SVGPathByteStreamSource::SVGPathByteStreamSource(SVGPathByteStream* stream)
     25SVGPathByteStreamSource::SVGPathByteStreamSource(const SVGPathByteStream& stream)
    2626{
    27     ASSERT(stream);
    28     m_streamCurrent = stream->begin();
    29     m_streamEnd = stream->end();
     27    m_streamCurrent = stream.begin();
     28    m_streamEnd = stream.end();
    3029}
    3130
  • trunk/Source/WebCore/svg/SVGPathByteStreamSource.h

    r163440 r190844  
    2929class SVGPathByteStreamSource : public SVGPathSource {
    3030public:
    31     explicit SVGPathByteStreamSource(SVGPathByteStream*);
     31    explicit SVGPathByteStreamSource(const SVGPathByteStream&);
    3232
    3333private:
  • trunk/Source/WebCore/svg/SVGPathElement.cpp

    r189565 r190844  
    8181inline SVGPathElement::SVGPathElement(const QualifiedName& tagName, Document& document)
    8282    : SVGGraphicsElement(tagName, document)
    83     , m_pathByteStream(std::make_unique<SVGPathByteStream>())
    8483    , m_pathSegList(PathSegUnalteredRole)
    8584    , m_isAnimValObserved(false)
     
    9493}
    9594
    96 float SVGPathElement::getTotalLength()
     95float SVGPathElement::getTotalLength() const
    9796{
    9897    float totalLength = 0;
     
    101100}
    102101
    103 SVGPoint SVGPathElement::getPointAtLength(float length)
     102SVGPoint SVGPathElement::getPointAtLength(float length) const
    104103{
    105104    SVGPoint point;
     
    108107}
    109108
    110 unsigned SVGPathElement::getPathSegAtLength(float length)
     109unsigned SVGPathElement::getPathSegAtLength(float length) const
    111110{
    112111    unsigned pathSeg = 0;
     
    225224{
    226225    if (name == SVGNames::dAttr) {
    227         if (!buildSVGPathByteStreamFromString(value, m_pathByteStream.get(), UnalteredParsing))
     226        if (!buildSVGPathByteStreamFromString(value, m_pathByteStream, UnalteredParsing))
    228227            document().accessSVGExtensions().reportError("Problem parsing d=\"" + value + "\"");
    229228        return;
     
    255254        if (m_pathSegList.shouldSynchronize && !SVGAnimatedProperty::lookupWrapper<SVGPathElement, SVGAnimatedPathSegListPropertyTearOff>(this, dPropertyInfo())->isAnimating()) {
    256255            SVGPathSegList newList(PathSegUnalteredRole);
    257             buildSVGPathSegListFromByteStream(m_pathByteStream.get(), this, newList, UnalteredParsing);
     256            buildSVGPathSegListFromByteStream(m_pathByteStream, *this, newList, UnalteredParsing);
    258257            m_pathSegList.value = newList;
    259258        }
     
    294293}
    295294
    296 SVGPathByteStream* SVGPathElement::pathByteStream() const
     295const SVGPathByteStream& SVGPathElement::pathByteStream() const
    297296{
    298297    SVGAnimatedProperty* property = SVGAnimatedProperty::lookupWrapper<SVGPathElement, SVGAnimatedPathSegListPropertyTearOff>(this, dPropertyInfo());
    299298    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;
    302306}
    303307
     
    311315
    312316    // 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);
    314318
    315319    return SVGAnimatedProperty::lookupOrCreateWrapper<SVGPathElement, SVGAnimatedPathSegListPropertyTearOff, SVGPathSegList>
     
    360364        if (listModification == ListModificationAppend) {
    361365            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);
    363367        } else
    364             buildSVGPathByteStreamFromSVGPathSegList(m_pathSegList.value, m_pathByteStream.get(), UnalteredParsing);
     368            buildSVGPathByteStreamFromSVGPathSegList(m_pathSegList.value, m_pathByteStream, UnalteredParsing);
    365369        break;
    366370    case PathSegUndefinedRole:
  • trunk/Source/WebCore/svg/SVGPathElement.h

    r185503 r190844  
    5858    static Ref<SVGPathElement> create(const QualifiedName&, Document&);
    5959   
    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;
    6363
    6464    Ref<SVGPathSegClosePath> createSVGPathSegClosePath(SVGPathSegRole = PathSegUndefinedRole);
     
    8888    SVGPathSegListPropertyTearOff* animatedNormalizedPathSegList();
    8989
    90     SVGPathByteStream* pathByteStream() const;
     90    const SVGPathByteStream& pathByteStream() const;
    9191
    9292    void pathSegListChanged(SVGPathSegRole, ListModification = ListModificationUnknown);
     
    125125
    126126private:
    127     std::unique_ptr<SVGPathByteStream> m_pathByteStream;
     127    SVGPathByteStream m_pathByteStream;
    128128    mutable SVGSynchronizableAnimatedProperty<SVGPathSegList> m_pathSegList;
    129129    bool m_isAnimValObserved;
  • trunk/Source/WebCore/svg/SVGPathUtilities.cpp

    r189565 r190844  
    3838namespace WebCore {
    3939
    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?
     41static SVGPathBuilder& globalSVGPathBuilder(Path& result)
     42{
     43    static NeverDestroyed<SVGPathBuilder> s_builder;
     44    s_builder.get().setCurrentPath(&result);
     45    return s_builder.get();
     46}
     47
     48static 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
     58static SVGPathByteStreamBuilder& globalSVGPathByteStreamBuilder(SVGPathByteStream& result)
     59{
     60    static NeverDestroyed<SVGPathByteStreamBuilder> s_builder;
     61    s_builder.get().setCurrentByteStream(&result);
     62    return s_builder.get();
     63}
     64
     65static SVGPathStringBuilder& globalSVGPathStringBuilder()
     66{
     67    static NeverDestroyed<SVGPathStringBuilder> s_builder;
     68    return s_builder.get();
     69}
     70
     71static 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?
     81static 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
     90static SVGPathBlender& globalSVGPathBlender()
     91{
     92    static NeverDestroyed<SVGPathBlender> s_blender;
     93    return s_blender.get();
    11094}
    11195
     
    11599        return true;
    116100
    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
     110bool buildSVGPathByteStreamFromSVGPathSegList(const SVGPathSegList& list, SVGPathByteStream& result, PathParsingMode parsingMode)
     111{
     112    result.clear();
    130113    if (list.isEmpty())
    131114        return true;
    132115
    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
     125bool appendSVGPathByteStreamFromSVGPathSeg(RefPtr<SVGPathSeg>&& pathSeg, SVGPathByteStream& result, PathParsingMode parsingMode)
     126{
    145127    // FIXME: https://bugs.webkit.org/show_bug.cgi?id=15412 - Implement normalized path segment lists!
    146128    ASSERT(parsingMode == UnalteredParsing);
     
    148130    SVGPathSegList appendedItemList(PathSegUnalteredRole);
    149131    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();
    157139
    158140    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
     146bool 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
     160bool 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
     174bool 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();
    207186    return ok;
    208187}
     
    214193        return true;
    215194
    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
     205bool buildSVGPathByteStreamFromString(const String& d, SVGPathByteStream& result, PathParsingMode parsingMode)
     206{
     207    result.clear();
    230208    if (d.isEmpty())
    231209        return true;
    232210
    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
     220bool 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
     237bool 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
     257bool getSVGPathSegAtLengthFromSVGPathByteStream(const SVGPathByteStream& stream, float length, unsigned& pathSeg)
     258{
     259    if (stream.isEmpty())
    287260        return false;
    288261
    289262    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
     273bool getTotalLengthOfSVGPathByteStream(const SVGPathByteStream& stream, float& totalLength)
     274{
     275    if (stream.isEmpty())
    304276        return false;
    305277
    306278    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
     289bool getPointAtLengthOfSVGPathByteStream(const SVGPathByteStream& stream, float length, SVGPoint& point)
     290{
     291    if (stream.isEmpty())
    321292        return false;
    322293
    323294    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();
    331302    return ok;
    332303}
     
    362333    // a path, only apply a function to all path elements at once.
    363334
    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);
    367338    });
    368     string = builder->result();
    369     static_cast<SVGPathConsumer*>(builder)->cleanup();
     339    string = builder.result();
     340    static_cast<SVGPathConsumer&>(builder).cleanup(); // Wat?
    370341
    371342    return true;
  • trunk/Source/WebCore/svg/SVGPathUtilities.h

    r189565 r190844  
    3535// String/SVGPathByteStream -> Path
    3636bool buildPathFromString(const String&, Path&);
    37 bool buildPathFromByteStream(SVGPathByteStream*, Path&);
     37bool buildPathFromByteStream(const SVGPathByteStream&, Path&);
    3838
    3939// SVGPathSegList/String -> SVGPathByteStream
    40 bool buildSVGPathByteStreamFromSVGPathSegList(const SVGPathSegList&, SVGPathByteStream*, PathParsingMode);
    41 bool appendSVGPathByteStreamFromSVGPathSeg(RefPtr<SVGPathSeg>&&, SVGPathByteStream*, PathParsingMode);
    42 bool buildSVGPathByteStreamFromString(const String&, SVGPathByteStream*, PathParsingMode);
     40bool buildSVGPathByteStreamFromSVGPathSegList(const SVGPathSegList&, SVGPathByteStream& result, PathParsingMode);
     41bool appendSVGPathByteStreamFromSVGPathSeg(RefPtr<SVGPathSeg>&&, SVGPathByteStream&, PathParsingMode);
     42bool buildSVGPathByteStreamFromString(const String&, SVGPathByteStream&, PathParsingMode);
    4343
    4444// SVGPathByteStream/SVGPathSegList -> String
    45 bool buildStringFromByteStream(SVGPathByteStream*, String&, PathParsingMode);
     45bool buildStringFromByteStream(const SVGPathByteStream&, String&, PathParsingMode);
    4646bool buildStringFromSVGPathSegList(const SVGPathSegList&, String&, PathParsingMode);
    4747
    4848// SVGPathByteStream -> SVGPathSegList
    49 bool buildSVGPathSegListFromByteStream(SVGPathByteStream*, SVGPathElement*, SVGPathSegList&, PathParsingMode);
     49bool buildSVGPathSegListFromByteStream(const SVGPathByteStream&, SVGPathElement&, SVGPathSegList&, PathParsingMode);
    5050
    51 bool buildAnimatedSVGPathByteStream(SVGPathByteStream*, SVGPathByteStream*, SVGPathByteStream*, float);
    52 bool addToSVGPathByteStream(SVGPathByteStream*, SVGPathByteStream*, unsigned repeatCount = 1);
     51bool buildAnimatedSVGPathByteStream(const SVGPathByteStream& from, const SVGPathByteStream& to, SVGPathByteStream& result, float progress);
     52bool addToSVGPathByteStream(SVGPathByteStream& streamToAppendTo, const SVGPathByteStream& from, unsigned repeatCount = 1);
    5353
    54 bool getSVGPathSegAtLengthFromSVGPathByteStream(SVGPathByteStream*, float length, unsigned& pathSeg);
    55 bool getTotalLengthOfSVGPathByteStream(SVGPathByteStream*, float& totalLength);
    56 bool getPointAtLengthOfSVGPathByteStream(SVGPathByteStream*, float length, SVGPoint&);
     54bool getSVGPathSegAtLengthFromSVGPathByteStream(const SVGPathByteStream&, float length, unsigned& pathSeg);
     55bool getTotalLengthOfSVGPathByteStream(const SVGPathByteStream&, float& totalLength);
     56bool getPointAtLengthOfSVGPathByteStream(const SVGPathByteStream&, float length, SVGPoint&);
    5757
    5858// Path -> String
  • trunk/Source/WebCore/svg/properties/SVGAnimatedPathSegListPropertyTearOff.h

    r184852 r190844  
    9696            SVGPathSegList& animatedList = currentAnimatedValue();
    9797            animatedList.clear();
    98             buildSVGPathSegListFromByteStream(m_animatedPathByteStream, pathElement, animatedList, UnalteredParsing);
     98            buildSVGPathSegListFromByteStream(*m_animatedPathByteStream, *pathElement, animatedList, UnalteredParsing);
    9999        }
    100100
Note: See TracChangeset for help on using the changeset viewer.