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