| 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 "platform/graphics/paint/GeometryMapper.h" | 5 #include "platform/graphics/paint/GeometryMapper.h" |
| 6 | 6 |
| 7 #include "platform/geometry/LayoutRect.h" | 7 #include "platform/geometry/LayoutRect.h" |
| 8 | 8 |
| 9 namespace blink { | 9 namespace blink { |
| 10 | 10 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 FloatRect GeometryMapper::slowMapToVisualRectInDestinationSpace( | 37 FloatRect GeometryMapper::slowMapToVisualRectInDestinationSpace( |
| 38 const FloatRect& rect, | 38 const FloatRect& rect, |
| 39 const PropertyTreeState& sourceState, | 39 const PropertyTreeState& sourceState, |
| 40 const PropertyTreeState& destinationState, | 40 const PropertyTreeState& destinationState, |
| 41 bool& success) { | 41 bool& success) { |
| 42 const TransformPaintPropertyNode* lcaTransform = leastCommonAncestor( | 42 const TransformPaintPropertyNode* lcaTransform = leastCommonAncestor( |
| 43 sourceState.transform(), destinationState.transform()); | 43 sourceState.transform(), destinationState.transform()); |
| 44 DCHECK(lcaTransform); | 44 DCHECK(lcaTransform); |
| 45 | 45 |
| 46 // Assume that the clip of destinationState is an ancestor of the clip of sour
ceState | 46 // Assume that the clip of destinationState is an ancestor of the clip of |
| 47 // and is under the space of lcaTransform. Otherwise localToAncestorClipRect()
will fail. | 47 // sourceState and is under the space of lcaTransform. Otherwise |
| 48 // localToAncestorClipRect() will fail. |
| 48 PropertyTreeState lcaState = destinationState; | 49 PropertyTreeState lcaState = destinationState; |
| 49 lcaState.setTransform(lcaTransform); | 50 lcaState.setTransform(lcaTransform); |
| 50 | 51 |
| 51 const auto clipRect = localToAncestorClipRect(sourceState, lcaState, success); | 52 const auto clipRect = localToAncestorClipRect(sourceState, lcaState, success); |
| 52 if (!success) | 53 if (!success) |
| 53 return rect; | 54 return rect; |
| 54 | 55 |
| 55 FloatRect result = localToAncestorRect(rect, sourceState, lcaState, success); | 56 FloatRect result = localToAncestorRect(rect, sourceState, lcaState, success); |
| 56 DCHECK(success); | 57 DCHECK(success); |
| 57 result.intersect(clipRect); | 58 result.intersect(clipRect); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 const PropertyTreeState& localState, | 157 const PropertyTreeState& localState, |
| 157 const PropertyTreeState& ancestorState, | 158 const PropertyTreeState& ancestorState, |
| 158 bool& success) { | 159 bool& success) { |
| 159 PrecomputedDataForAncestor& precomputedData = | 160 PrecomputedDataForAncestor& precomputedData = |
| 160 getPrecomputedDataForAncestor(ancestorState); | 161 getPrecomputedDataForAncestor(ancestorState); |
| 161 const ClipPaintPropertyNode* clipNode = localState.clip(); | 162 const ClipPaintPropertyNode* clipNode = localState.clip(); |
| 162 Vector<const ClipPaintPropertyNode*> intermediateNodes; | 163 Vector<const ClipPaintPropertyNode*> intermediateNodes; |
| 163 FloatRect clip(LayoutRect::infiniteIntRect()); | 164 FloatRect clip(LayoutRect::infiniteIntRect()); |
| 164 | 165 |
| 165 bool found = false; | 166 bool found = false; |
| 166 // Iterate over the path from localState.clip to ancestorState.clip. Stop if w
e've found a memoized (precomputed) clip | 167 // Iterate over the path from localState.clip to ancestorState.clip. Stop if |
| 167 // for any particular node. | 168 // we've found a memoized (precomputed) clip for any particular node. |
| 168 while (clipNode) { | 169 while (clipNode) { |
| 169 auto it = precomputedData.toAncestorClipRects.find(clipNode); | 170 auto it = precomputedData.toAncestorClipRects.find(clipNode); |
| 170 if (it != precomputedData.toAncestorClipRects.end()) { | 171 if (it != precomputedData.toAncestorClipRects.end()) { |
| 171 clip = it->value; | 172 clip = it->value; |
| 172 found = true; | 173 found = true; |
| 173 break; | 174 break; |
| 174 } | 175 } |
| 175 intermediateNodes.append(clipNode); | 176 intermediateNodes.append(clipNode); |
| 176 | 177 |
| 177 if (clipNode == ancestorState.clip()) | 178 if (clipNode == ancestorState.clip()) |
| 178 break; | 179 break; |
| 179 | 180 |
| 180 clipNode = clipNode->parent(); | 181 clipNode = clipNode->parent(); |
| 181 } | 182 } |
| 182 if (clipNode != ancestorState.clip() && !found) { | 183 if (clipNode != ancestorState.clip() && !found) { |
| 183 success = false; | 184 success = false; |
| 184 return clip; | 185 return clip; |
| 185 } | 186 } |
| 186 | 187 |
| 187 // Iterate down from the top intermediate node found in the previous loop, com
puting and memoizing clip rects as we go. | 188 // Iterate down from the top intermediate node found in the previous loop, |
| 189 // computing and memoizing clip rects as we go. |
| 188 for (auto it = intermediateNodes.rbegin(); it != intermediateNodes.rend(); | 190 for (auto it = intermediateNodes.rbegin(); it != intermediateNodes.rend(); |
| 189 ++it) { | 191 ++it) { |
| 190 if ((*it) != ancestorState.clip()) { | 192 if ((*it) != ancestorState.clip()) { |
| 191 success = false; | 193 success = false; |
| 192 const TransformationMatrix& transformMatrix = localToAncestorMatrix( | 194 const TransformationMatrix& transformMatrix = localToAncestorMatrix( |
| 193 (*it)->localTransformSpace(), ancestorState, success); | 195 (*it)->localTransformSpace(), ancestorState, success); |
| 194 if (!success) | 196 if (!success) |
| 195 return clip; | 197 return clip; |
| 196 FloatRect mappedRect = transformMatrix.mapRect((*it)->clipRect().rect()); | 198 FloatRect mappedRect = transformMatrix.mapRect((*it)->clipRect().rect()); |
| 197 clip.intersect(mappedRect); | 199 clip.intersect(mappedRect); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 209 const PropertyTreeState& ancestorState, | 211 const PropertyTreeState& ancestorState, |
| 210 bool& success) { | 212 bool& success) { |
| 211 PrecomputedDataForAncestor& precomputedData = | 213 PrecomputedDataForAncestor& precomputedData = |
| 212 getPrecomputedDataForAncestor(ancestorState); | 214 getPrecomputedDataForAncestor(ancestorState); |
| 213 | 215 |
| 214 const TransformPaintPropertyNode* transformNode = localTransformNode; | 216 const TransformPaintPropertyNode* transformNode = localTransformNode; |
| 215 Vector<const TransformPaintPropertyNode*> intermediateNodes; | 217 Vector<const TransformPaintPropertyNode*> intermediateNodes; |
| 216 TransformationMatrix transformMatrix; | 218 TransformationMatrix transformMatrix; |
| 217 | 219 |
| 218 bool found = false; | 220 bool found = false; |
| 219 // Iterate over the path from localTransformNode to ancestorState.transform. S
top if we've found a memoized (precomputed) transform | 221 // Iterate over the path from localTransformNode to ancestorState.transform. |
| 220 // for any particular node. | 222 // Stop if we've found a memoized (precomputed) transform for any particular |
| 223 // node. |
| 221 while (transformNode) { | 224 while (transformNode) { |
| 222 auto it = precomputedData.toAncestorTransforms.find(transformNode); | 225 auto it = precomputedData.toAncestorTransforms.find(transformNode); |
| 223 if (it != precomputedData.toAncestorTransforms.end()) { | 226 if (it != precomputedData.toAncestorTransforms.end()) { |
| 224 transformMatrix = it->value; | 227 transformMatrix = it->value; |
| 225 found = true; | 228 found = true; |
| 226 break; | 229 break; |
| 227 } | 230 } |
| 228 | 231 |
| 229 intermediateNodes.append(transformNode); | 232 intermediateNodes.append(transformNode); |
| 230 | 233 |
| 231 if (transformNode == ancestorState.transform()) | 234 if (transformNode == ancestorState.transform()) |
| 232 break; | 235 break; |
| 233 | 236 |
| 234 transformNode = transformNode->parent(); | 237 transformNode = transformNode->parent(); |
| 235 } | 238 } |
| 236 if (!found && transformNode != ancestorState.transform()) { | 239 if (!found && transformNode != ancestorState.transform()) { |
| 237 success = false; | 240 success = false; |
| 238 return m_identity; | 241 return m_identity; |
| 239 } | 242 } |
| 240 | 243 |
| 241 // Iterate down from the top intermediate node found in the previous loop, com
puting and memoizing transforms as we go. | 244 // Iterate down from the top intermediate node found in the previous loop, |
| 245 // computing and memoizing transforms as we go. |
| 242 for (auto it = intermediateNodes.rbegin(); it != intermediateNodes.rend(); | 246 for (auto it = intermediateNodes.rbegin(); it != intermediateNodes.rend(); |
| 243 it++) { | 247 it++) { |
| 244 if ((*it) != ancestorState.transform()) { | 248 if ((*it) != ancestorState.transform()) { |
| 245 TransformationMatrix localTransformMatrix = (*it)->matrix(); | 249 TransformationMatrix localTransformMatrix = (*it)->matrix(); |
| 246 localTransformMatrix.applyTransformOrigin((*it)->origin()); | 250 localTransformMatrix.applyTransformOrigin((*it)->origin()); |
| 247 transformMatrix = transformMatrix * localTransformMatrix; | 251 transformMatrix = transformMatrix * localTransformMatrix; |
| 248 } | 252 } |
| 249 | 253 |
| 250 precomputedData.toAncestorTransforms.set(*it, transformMatrix); | 254 precomputedData.toAncestorTransforms.set(*it, transformMatrix); |
| 251 } | 255 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 | 291 |
| 288 // Walk up until we find the ancestor. | 292 // Walk up until we find the ancestor. |
| 289 while (a != b) { | 293 while (a != b) { |
| 290 a = a->parent(); | 294 a = a->parent(); |
| 291 b = b->parent(); | 295 b = b->parent(); |
| 292 } | 296 } |
| 293 return a; | 297 return a; |
| 294 } | 298 } |
| 295 | 299 |
| 296 } // namespace blink | 300 } // namespace blink |
| OLD | NEW |