OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 21 matching lines...) Expand all Loading... | |
32 TransformState& TransformState::operator=(const TransformState& other) | 32 TransformState& TransformState::operator=(const TransformState& other) |
33 { | 33 { |
34 m_accumulatedOffset = other.m_accumulatedOffset; | 34 m_accumulatedOffset = other.m_accumulatedOffset; |
35 m_mapPoint = other.m_mapPoint; | 35 m_mapPoint = other.m_mapPoint; |
36 m_mapQuad = other.m_mapQuad; | 36 m_mapQuad = other.m_mapQuad; |
37 if (m_mapPoint) | 37 if (m_mapPoint) |
38 m_lastPlanarPoint = other.m_lastPlanarPoint; | 38 m_lastPlanarPoint = other.m_lastPlanarPoint; |
39 if (m_mapQuad) | 39 if (m_mapQuad) |
40 m_lastPlanarQuad = other.m_lastPlanarQuad; | 40 m_lastPlanarQuad = other.m_lastPlanarQuad; |
41 m_accumulatingTransform = other.m_accumulatingTransform; | 41 m_accumulatingTransform = other.m_accumulatingTransform; |
42 m_forceAccumulatingTransform = other.m_forceAccumulatingTransform; | |
42 m_direction = other.m_direction; | 43 m_direction = other.m_direction; |
43 | 44 |
44 m_accumulatedTransform.clear(); | 45 m_accumulatedTransform.clear(); |
45 | 46 |
46 if (other.m_accumulatedTransform) | 47 if (other.m_accumulatedTransform) |
47 m_accumulatedTransform = TransformationMatrix::create(*other.m_accumulat edTransform); | 48 m_accumulatedTransform = TransformationMatrix::create(*other.m_accumulat edTransform); |
48 | 49 |
49 return *this; | 50 return *this; |
50 } | 51 } |
51 | 52 |
52 void TransformState::translateTransform(const LayoutSize& offset) | 53 void TransformState::translateTransform(const LayoutSize& offset) |
53 { | 54 { |
54 if (m_direction == ApplyTransformDirection) | 55 if (m_direction == ApplyTransformDirection) |
55 m_accumulatedTransform->translateRight(offset.width().toDouble(), offset .height().toDouble()); | 56 m_accumulatedTransform->translateRight(offset.width().toDouble(), offset .height().toDouble()); |
56 else | 57 else |
57 m_accumulatedTransform->translate(offset.width().toDouble(), offset.heig ht().toDouble()); | 58 m_accumulatedTransform->translate(offset.width().toDouble(), offset.heig ht().toDouble()); |
58 } | 59 } |
59 | 60 |
60 void TransformState::translateMappedCoordinates(const LayoutSize& offset) | 61 void TransformState::translateMappedCoordinates(const LayoutSize& offset) |
61 { | 62 { |
62 FloatSize adjustedOffset((m_direction == ApplyTransformDirection) ? offset : -offset); | 63 FloatSize adjustedOffset((m_direction == ApplyTransformDirection) ? offset : -offset); |
63 if (m_mapPoint) | 64 if (m_mapPoint) |
64 m_lastPlanarPoint.move(adjustedOffset); | 65 m_lastPlanarPoint.move(adjustedOffset); |
65 if (m_mapQuad) | 66 if (m_mapQuad) |
66 m_lastPlanarQuad.move(adjustedOffset); | 67 m_lastPlanarQuad.move(adjustedOffset); |
67 } | 68 } |
68 | 69 |
69 void TransformState::move(const LayoutSize& offset, TransformAccumulation accumu late) | 70 void TransformState::move(const LayoutSize& offset, TransformAccumulation accumu late) |
70 { | 71 { |
72 if (m_forceAccumulatingTransform) | |
73 accumulate = AccumulateTransform; | |
74 | |
71 if (accumulate == FlattenTransform || !m_accumulatedTransform) { | 75 if (accumulate == FlattenTransform || !m_accumulatedTransform) { |
72 m_accumulatedOffset += offset; | 76 m_accumulatedOffset += offset; |
73 } else { | 77 } else { |
74 applyAccumulatedOffset(); | 78 applyAccumulatedOffset(); |
75 if (m_accumulatingTransform && m_accumulatedTransform) { | 79 if (m_accumulatingTransform && m_accumulatedTransform) { |
76 // If we're accumulating into an existing transform, apply the trans lation. | 80 // If we're accumulating into an existing transform, apply the trans lation. |
77 translateTransform(offset); | 81 translateTransform(offset); |
78 } else { | 82 } else { |
79 // Just move the point and/or quad. | 83 // Just move the point and/or quad. |
80 translateMappedCoordinates(offset); | 84 translateMappedCoordinates(offset); |
(...skipping 20 matching lines...) Expand all Loading... | |
101 void TransformState::applyTransform(const AffineTransform& transformFromContaine r, TransformAccumulation accumulate, bool* wasClamped) | 105 void TransformState::applyTransform(const AffineTransform& transformFromContaine r, TransformAccumulation accumulate, bool* wasClamped) |
102 { | 106 { |
103 applyTransform(transformFromContainer.toTransformationMatrix(), accumulate, wasClamped); | 107 applyTransform(transformFromContainer.toTransformationMatrix(), accumulate, wasClamped); |
104 } | 108 } |
105 | 109 |
106 void TransformState::applyTransform(const TransformationMatrix& transformFromCon tainer, TransformAccumulation accumulate, bool* wasClamped) | 110 void TransformState::applyTransform(const TransformationMatrix& transformFromCon tainer, TransformAccumulation accumulate, bool* wasClamped) |
107 { | 111 { |
108 if (wasClamped) | 112 if (wasClamped) |
109 *wasClamped = false; | 113 *wasClamped = false; |
110 | 114 |
115 if (m_forceAccumulatingTransform) | |
chrishtr
2016/03/10 16:53:39
I don't think this works in the case of a flatteni
dmazzoni
2016/03/14 20:10:37
Good catch. Fixed this and added a new test.
| |
116 accumulate = AccumulateTransform; | |
117 | |
111 if (transformFromContainer.isIntegerTranslation()) { | 118 if (transformFromContainer.isIntegerTranslation()) { |
112 move(LayoutSize(LayoutUnit(transformFromContainer.e()), LayoutUnit(trans formFromContainer.f())), accumulate); | 119 move(LayoutSize(LayoutUnit(transformFromContainer.e()), LayoutUnit(trans formFromContainer.f())), accumulate); |
113 return; | 120 return; |
114 } | 121 } |
115 | 122 |
116 applyAccumulatedOffset(); | 123 applyAccumulatedOffset(); |
117 | 124 |
118 // If we have an accumulated transform from last time, multiply in this tran sform | 125 // If we have an accumulated transform from last time, multiply in this tran sform |
119 if (m_accumulatedTransform) { | 126 if (m_accumulatedTransform) { |
120 if (m_direction == ApplyTransformDirection) | 127 if (m_direction == ApplyTransformDirection) |
121 m_accumulatedTransform = TransformationMatrix::create(transformFromC ontainer * *m_accumulatedTransform); | 128 m_accumulatedTransform = TransformationMatrix::create(transformFromC ontainer * *m_accumulatedTransform); |
122 else | 129 else |
123 m_accumulatedTransform->multiply(transformFromContainer); | 130 m_accumulatedTransform->multiply(transformFromContainer); |
124 } else if (accumulate == AccumulateTransform) { | 131 } else if (accumulate == AccumulateTransform) { |
125 // Make one if we started to accumulate | 132 // Make one if we started to accumulate |
126 m_accumulatedTransform = TransformationMatrix::create(transformFromConta iner); | 133 m_accumulatedTransform = TransformationMatrix::create(transformFromConta iner); |
127 } | 134 } |
128 | 135 |
129 if (accumulate == FlattenTransform) { | 136 if (accumulate == FlattenTransform) { |
130 const TransformationMatrix* finalTransform = m_accumulatedTransform ? m_ accumulatedTransform.get() : &transformFromContainer; | 137 const TransformationMatrix* finalTransform = m_accumulatedTransform ? m_ accumulatedTransform.get() : &transformFromContainer; |
131 flattenWithTransform(*finalTransform, wasClamped); | 138 flattenWithTransform(*finalTransform, wasClamped); |
132 } | 139 } |
133 m_accumulatingTransform = accumulate == AccumulateTransform; | 140 m_accumulatingTransform = accumulate == AccumulateTransform; |
134 } | 141 } |
135 | 142 |
136 void TransformState::flatten(bool* wasClamped) | 143 void TransformState::flatten(bool* wasClamped) |
137 { | 144 { |
145 ASSERT(!m_forceAccumulatingTransform); | |
138 if (wasClamped) | 146 if (wasClamped) |
139 *wasClamped = false; | 147 *wasClamped = false; |
140 | 148 |
141 applyAccumulatedOffset(); | 149 applyAccumulatedOffset(); |
142 | 150 |
143 if (!m_accumulatedTransform) { | 151 if (!m_accumulatedTransform) { |
144 m_accumulatingTransform = false; | 152 m_accumulatingTransform = false; |
145 return; | 153 return; |
146 } | 154 } |
147 | 155 |
(...skipping 25 matching lines...) Expand all Loading... | |
173 quad.move(FloatSize((m_direction == ApplyTransformDirection) ? m_accumulated Offset : -m_accumulatedOffset)); | 181 quad.move(FloatSize((m_direction == ApplyTransformDirection) ? m_accumulated Offset : -m_accumulatedOffset)); |
174 if (!m_accumulatedTransform) | 182 if (!m_accumulatedTransform) |
175 return quad; | 183 return quad; |
176 | 184 |
177 if (m_direction == ApplyTransformDirection) | 185 if (m_direction == ApplyTransformDirection) |
178 return m_accumulatedTransform->mapQuad(quad); | 186 return m_accumulatedTransform->mapQuad(quad); |
179 | 187 |
180 return m_accumulatedTransform->inverse().projectQuad(quad, wasClamped); | 188 return m_accumulatedTransform->inverse().projectQuad(quad, wasClamped); |
181 } | 189 } |
182 | 190 |
191 const TransformationMatrix& TransformState::accumulatedTransform() const | |
192 { | |
193 ASSERT(m_forceAccumulatingTransform && m_accumulatingTransform); | |
194 return *m_accumulatedTransform; | |
195 } | |
196 | |
183 void TransformState::flattenWithTransform(const TransformationMatrix& t, bool* w asClamped) | 197 void TransformState::flattenWithTransform(const TransformationMatrix& t, bool* w asClamped) |
184 { | 198 { |
185 if (m_direction == ApplyTransformDirection) { | 199 if (m_direction == ApplyTransformDirection) { |
186 if (m_mapPoint) | 200 if (m_mapPoint) |
187 m_lastPlanarPoint = t.mapPoint(m_lastPlanarPoint); | 201 m_lastPlanarPoint = t.mapPoint(m_lastPlanarPoint); |
188 if (m_mapQuad) | 202 if (m_mapQuad) |
189 m_lastPlanarQuad = t.mapQuad(m_lastPlanarQuad); | 203 m_lastPlanarQuad = t.mapQuad(m_lastPlanarQuad); |
190 } else { | 204 } else { |
191 TransformationMatrix inverseTransform = t.inverse(); | 205 TransformationMatrix inverseTransform = t.inverse(); |
192 if (m_mapPoint) | 206 if (m_mapPoint) |
193 m_lastPlanarPoint = inverseTransform.projectPoint(m_lastPlanarPoint) ; | 207 m_lastPlanarPoint = inverseTransform.projectPoint(m_lastPlanarPoint) ; |
194 if (m_mapQuad) | 208 if (m_mapQuad) |
195 m_lastPlanarQuad = inverseTransform.projectQuad(m_lastPlanarQuad, wa sClamped); | 209 m_lastPlanarQuad = inverseTransform.projectQuad(m_lastPlanarQuad, wa sClamped); |
196 } | 210 } |
197 | 211 |
198 // We could throw away m_accumulatedTransform if we wanted to here, but that | 212 // We could throw away m_accumulatedTransform if we wanted to here, but that |
199 // would cause thrash when traversing hierarchies with alternating | 213 // would cause thrash when traversing hierarchies with alternating |
200 // preserve-3d and flat elements. | 214 // preserve-3d and flat elements. |
201 if (m_accumulatedTransform) | 215 if (m_accumulatedTransform) |
202 m_accumulatedTransform->makeIdentity(); | 216 m_accumulatedTransform->makeIdentity(); |
203 m_accumulatingTransform = false; | 217 m_accumulatingTransform = false; |
204 } | 218 } |
205 | 219 |
206 } // namespace blink | 220 } // namespace blink |
OLD | NEW |