| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/animation/PathInterpolationFunctions.h" | 5 #include "core/animation/PathInterpolationFunctions.h" |
| 6 | 6 |
| 7 #include "core/animation/InterpolatedSVGPathSource.h" | 7 #include "core/animation/InterpolatedSVGPathSource.h" |
| 8 #include "core/animation/InterpolationEnvironment.h" | 8 #include "core/animation/InterpolationEnvironment.h" |
| 9 #include "core/animation/SVGPathSegInterpolationFunctions.h" | 9 #include "core/animation/SVGPathSegInterpolationFunctions.h" |
| 10 #include "core/css/CSSPathValue.h" | 10 #include "core/css/CSSPathValue.h" |
| 11 #include "core/svg/SVGPath.h" | 11 #include "core/svg/SVGPath.h" |
| 12 #include "core/svg/SVGPathByteStreamBuilder.h" | 12 #include "core/svg/SVGPathByteStreamBuilder.h" |
| 13 #include "core/svg/SVGPathByteStreamSource.h" | 13 #include "core/svg/SVGPathByteStreamSource.h" |
| 14 #include "core/svg/SVGPathParser.h" | 14 #include "core/svg/SVGPathParser.h" |
| 15 #include "wtf/PtrUtil.h" |
| 16 #include <memory> |
| 15 | 17 |
| 16 namespace blink { | 18 namespace blink { |
| 17 | 19 |
| 18 class SVGPathNonInterpolableValue : public NonInterpolableValue { | 20 class SVGPathNonInterpolableValue : public NonInterpolableValue { |
| 19 public: | 21 public: |
| 20 virtual ~SVGPathNonInterpolableValue() {} | 22 virtual ~SVGPathNonInterpolableValue() {} |
| 21 | 23 |
| 22 static PassRefPtr<SVGPathNonInterpolableValue> create(Vector<SVGPathSegType>
& pathSegTypes) | 24 static PassRefPtr<SVGPathNonInterpolableValue> create(Vector<SVGPathSegType>
& pathSegTypes) |
| 23 { | 25 { |
| 24 return adoptRef(new SVGPathNonInterpolableValue(pathSegTypes)); | 26 return adoptRef(new SVGPathNonInterpolableValue(pathSegTypes)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 44 PathArgsIndex, | 46 PathArgsIndex, |
| 45 PathNeutralIndex, | 47 PathNeutralIndex, |
| 46 PathComponentIndexCount, | 48 PathComponentIndexCount, |
| 47 }; | 49 }; |
| 48 | 50 |
| 49 InterpolationValue PathInterpolationFunctions::convertValue(const SVGPathByteStr
eam& byteStream) | 51 InterpolationValue PathInterpolationFunctions::convertValue(const SVGPathByteStr
eam& byteStream) |
| 50 { | 52 { |
| 51 SVGPathByteStreamSource pathSource(byteStream); | 53 SVGPathByteStreamSource pathSource(byteStream); |
| 52 size_t length = 0; | 54 size_t length = 0; |
| 53 PathCoordinates currentCoordinates; | 55 PathCoordinates currentCoordinates; |
| 54 Vector<OwnPtr<InterpolableValue>> interpolablePathSegs; | 56 Vector<std::unique_ptr<InterpolableValue>> interpolablePathSegs; |
| 55 Vector<SVGPathSegType> pathSegTypes; | 57 Vector<SVGPathSegType> pathSegTypes; |
| 56 | 58 |
| 57 while (pathSource.hasMoreData()) { | 59 while (pathSource.hasMoreData()) { |
| 58 const PathSegmentData segment = pathSource.parseSegment(); | 60 const PathSegmentData segment = pathSource.parseSegment(); |
| 59 interpolablePathSegs.append(SVGPathSegInterpolationFunctions::consumePat
hSeg(segment, currentCoordinates)); | 61 interpolablePathSegs.append(SVGPathSegInterpolationFunctions::consumePat
hSeg(segment, currentCoordinates)); |
| 60 pathSegTypes.append(segment.command); | 62 pathSegTypes.append(segment.command); |
| 61 length++; | 63 length++; |
| 62 } | 64 } |
| 63 | 65 |
| 64 OwnPtr<InterpolableList> pathArgs = InterpolableList::create(length); | 66 std::unique_ptr<InterpolableList> pathArgs = InterpolableList::create(length
); |
| 65 for (size_t i = 0; i < interpolablePathSegs.size(); i++) | 67 for (size_t i = 0; i < interpolablePathSegs.size(); i++) |
| 66 pathArgs->set(i, std::move(interpolablePathSegs[i])); | 68 pathArgs->set(i, std::move(interpolablePathSegs[i])); |
| 67 | 69 |
| 68 OwnPtr<InterpolableList> result = InterpolableList::create(PathComponentInde
xCount); | 70 std::unique_ptr<InterpolableList> result = InterpolableList::create(PathComp
onentIndexCount); |
| 69 result->set(PathArgsIndex, std::move(pathArgs)); | 71 result->set(PathArgsIndex, std::move(pathArgs)); |
| 70 result->set(PathNeutralIndex, InterpolableNumber::create(0)); | 72 result->set(PathNeutralIndex, InterpolableNumber::create(0)); |
| 71 | 73 |
| 72 return InterpolationValue(std::move(result), SVGPathNonInterpolableValue::cr
eate(pathSegTypes)); | 74 return InterpolationValue(std::move(result), SVGPathNonInterpolableValue::cr
eate(pathSegTypes)); |
| 73 } | 75 } |
| 74 | 76 |
| 75 InterpolationValue PathInterpolationFunctions::convertValue(const StylePath* sty
lePath) | 77 InterpolationValue PathInterpolationFunctions::convertValue(const StylePath* sty
lePath) |
| 76 { | 78 { |
| 77 if (stylePath) | 79 if (stylePath) |
| 78 return convertValue(stylePath->byteStream()); | 80 return convertValue(stylePath->byteStream()); |
| 79 | 81 |
| 80 OwnPtr<SVGPathByteStream> emptyPath = SVGPathByteStream::create(); | 82 std::unique_ptr<SVGPathByteStream> emptyPath = SVGPathByteStream::create(); |
| 81 return convertValue(*emptyPath); | 83 return convertValue(*emptyPath); |
| 82 } | 84 } |
| 83 | 85 |
| 84 class UnderlyingPathSegTypesChecker : public InterpolationType::ConversionChecke
r { | 86 class UnderlyingPathSegTypesChecker : public InterpolationType::ConversionChecke
r { |
| 85 public: | 87 public: |
| 86 ~UnderlyingPathSegTypesChecker() final {} | 88 ~UnderlyingPathSegTypesChecker() final {} |
| 87 | 89 |
| 88 static PassOwnPtr<UnderlyingPathSegTypesChecker> create(const InterpolationV
alue& underlying) | 90 static std::unique_ptr<UnderlyingPathSegTypesChecker> create(const Interpola
tionValue& underlying) |
| 89 { | 91 { |
| 90 return adoptPtr(new UnderlyingPathSegTypesChecker(getPathSegTypes(underl
ying))); | 92 return wrapUnique(new UnderlyingPathSegTypesChecker(getPathSegTypes(unde
rlying))); |
| 91 } | 93 } |
| 92 | 94 |
| 93 private: | 95 private: |
| 94 UnderlyingPathSegTypesChecker(const Vector<SVGPathSegType>& pathSegTypes) | 96 UnderlyingPathSegTypesChecker(const Vector<SVGPathSegType>& pathSegTypes) |
| 95 : m_pathSegTypes(pathSegTypes) | 97 : m_pathSegTypes(pathSegTypes) |
| 96 { } | 98 { } |
| 97 | 99 |
| 98 static const Vector<SVGPathSegType>& getPathSegTypes(const InterpolationValu
e& underlying) | 100 static const Vector<SVGPathSegType>& getPathSegTypes(const InterpolationValu
e& underlying) |
| 99 { | 101 { |
| 100 return toSVGPathNonInterpolableValue(*underlying.nonInterpolableValue).p
athSegTypes(); | 102 return toSVGPathNonInterpolableValue(*underlying.nonInterpolableValue).p
athSegTypes(); |
| 101 } | 103 } |
| 102 | 104 |
| 103 bool isValid(const InterpolationEnvironment&, const InterpolationValue& unde
rlying) const final | 105 bool isValid(const InterpolationEnvironment&, const InterpolationValue& unde
rlying) const final |
| 104 { | 106 { |
| 105 return m_pathSegTypes == getPathSegTypes(underlying); | 107 return m_pathSegTypes == getPathSegTypes(underlying); |
| 106 } | 108 } |
| 107 | 109 |
| 108 Vector<SVGPathSegType> m_pathSegTypes; | 110 Vector<SVGPathSegType> m_pathSegTypes; |
| 109 }; | 111 }; |
| 110 | 112 |
| 111 InterpolationValue PathInterpolationFunctions::maybeConvertNeutral(const Interpo
lationValue& underlying, InterpolationType::ConversionCheckers& conversionChecke
rs) | 113 InterpolationValue PathInterpolationFunctions::maybeConvertNeutral(const Interpo
lationValue& underlying, InterpolationType::ConversionCheckers& conversionChecke
rs) |
| 112 { | 114 { |
| 113 conversionCheckers.append(UnderlyingPathSegTypesChecker::create(underlying))
; | 115 conversionCheckers.append(UnderlyingPathSegTypesChecker::create(underlying))
; |
| 114 OwnPtr<InterpolableList> result = InterpolableList::create(PathComponentInde
xCount); | 116 std::unique_ptr<InterpolableList> result = InterpolableList::create(PathComp
onentIndexCount); |
| 115 result->set(PathArgsIndex, toInterpolableList(*underlying.interpolableValue)
.get(PathArgsIndex)->cloneAndZero()); | 117 result->set(PathArgsIndex, toInterpolableList(*underlying.interpolableValue)
.get(PathArgsIndex)->cloneAndZero()); |
| 116 result->set(PathNeutralIndex, InterpolableNumber::create(1)); | 118 result->set(PathNeutralIndex, InterpolableNumber::create(1)); |
| 117 return InterpolationValue(std::move(result), underlying.nonInterpolableValue
.get()); | 119 return InterpolationValue(std::move(result), underlying.nonInterpolableValue
.get()); |
| 118 } | 120 } |
| 119 | 121 |
| 120 static bool pathSegTypesMatch(const Vector<SVGPathSegType>& a, const Vector<SVGP
athSegType>& b) | 122 static bool pathSegTypesMatch(const Vector<SVGPathSegType>& a, const Vector<SVGP
athSegType>& b) |
| 121 { | 123 { |
| 122 if (a.size() != b.size()) | 124 if (a.size() != b.size()) |
| 123 return false; | 125 return false; |
| 124 | 126 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 150 return; | 152 return; |
| 151 } | 153 } |
| 152 | 154 |
| 153 ASSERT(pathSegTypesMatch( | 155 ASSERT(pathSegTypesMatch( |
| 154 toSVGPathNonInterpolableValue(*underlyingValueOwner.value().nonInterpola
bleValue).pathSegTypes(), | 156 toSVGPathNonInterpolableValue(*underlyingValueOwner.value().nonInterpola
bleValue).pathSegTypes(), |
| 155 toSVGPathNonInterpolableValue(*value.nonInterpolableValue).pathSegTypes(
))); | 157 toSVGPathNonInterpolableValue(*value.nonInterpolableValue).pathSegTypes(
))); |
| 156 underlyingValueOwner.mutableValue().interpolableValue->scaleAndAdd(neutralCo
mponent, *value.interpolableValue); | 158 underlyingValueOwner.mutableValue().interpolableValue->scaleAndAdd(neutralCo
mponent, *value.interpolableValue); |
| 157 underlyingValueOwner.mutableValue().nonInterpolableValue = value.nonInterpol
ableValue.get(); | 159 underlyingValueOwner.mutableValue().nonInterpolableValue = value.nonInterpol
ableValue.get(); |
| 158 } | 160 } |
| 159 | 161 |
| 160 PassOwnPtr<SVGPathByteStream> PathInterpolationFunctions::appliedValue(const Int
erpolableValue& interpolableValue, const NonInterpolableValue* nonInterpolableVa
lue) | 162 std::unique_ptr<SVGPathByteStream> PathInterpolationFunctions::appliedValue(cons
t InterpolableValue& interpolableValue, const NonInterpolableValue* nonInterpola
bleValue) |
| 161 { | 163 { |
| 162 OwnPtr<SVGPathByteStream> pathByteStream = SVGPathByteStream::create(); | 164 std::unique_ptr<SVGPathByteStream> pathByteStream = SVGPathByteStream::creat
e(); |
| 163 InterpolatedSVGPathSource source( | 165 InterpolatedSVGPathSource source( |
| 164 toInterpolableList(*toInterpolableList(interpolableValue).get(PathArgsIn
dex)), | 166 toInterpolableList(*toInterpolableList(interpolableValue).get(PathArgsIn
dex)), |
| 165 toSVGPathNonInterpolableValue(nonInterpolableValue)->pathSegTypes()); | 167 toSVGPathNonInterpolableValue(nonInterpolableValue)->pathSegTypes()); |
| 166 SVGPathByteStreamBuilder builder(*pathByteStream); | 168 SVGPathByteStreamBuilder builder(*pathByteStream); |
| 167 SVGPathParser::parsePath(source, builder); | 169 SVGPathParser::parsePath(source, builder); |
| 168 return pathByteStream; | 170 return pathByteStream; |
| 169 } | 171 } |
| 170 | 172 |
| 171 } // namespace blink | 173 } // namespace blink |
| OLD | NEW |