Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/paint/GeometryMapper.cpp

Issue 1973343003: Initial implementation of GeometryMapper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: none Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "platform/graphics/paint/GeometryMapper.h"
6
7 #include "platform/geometry/LayoutRect.h"
8 #include "platform/graphics/paint/ClipPaintPropertyNode.h"
9 #include "platform/graphics/paint/EffectPaintPropertyNode.h"
10 #include "platform/graphics/paint/TransformPaintPropertyNode.h"
11
12 namespace blink {
13
14 FloatRect GeometryMapper::LocalToVisualRectInAncestorSpace(
15 const FloatRect& rect,
16 const PropertyTreeState& localState,
17 const PropertyTreeState& ancestorState)
18 {
19 const auto transformMatrix = LocalToAncestorMatrix(localState.transform, anc estorState);
20 FloatRect mappedRect = transformMatrix.mapRect(rect);
21
22 const auto clipRect = LocalToAncestorClipRect(localState, ancestorState);
23
24 mappedRect.intersect(clipRect);
25 return mappedRect;
26 }
27
28 FloatRect GeometryMapper::LocalToAncestorRect(
29 const FloatRect& rect,
30 const PropertyTreeState& localState,
31 const PropertyTreeState& ancestorState)
32 {
33 const auto transformMatrix = LocalToAncestorMatrix(localState.transform, anc estorState);
34 return transformMatrix.mapRect(rect);
35 }
36
37 FloatRect GeometryMapper::AncestorToLocalRect(
38 const FloatRect& rect,
39 const PropertyTreeState& localState,
40 const PropertyTreeState& ancestorState, bool* success)
41 {
42 const auto& transformMatrix = LocalToAncestorMatrix(localState.transform, an cestorState);
43 if (!transformMatrix.isInvertible()) {
44 *success = false;
45 return FloatRect();
46 }
47 *success = true;
48
49 // TODO(chrishtr): Cache the inverse?
50 return transformMatrix.inverse().mapRect(rect);
51 }
52
53 PrecomputedDataForAncestor& GeometryMapper::GetPrecomputedDataForAncestor(const PropertyTreeState& ancestorState)
54 {
55 auto addResult = m_data.add(ancestorState.transform, nullptr);
56 if (addResult.isNewEntry)
57 addResult.storedValue->value = PrecomputedDataForAncestor::create();
58 return *addResult.storedValue->value;
59 }
60
61 const FloatRect& GeometryMapper::LocalToAncestorClipRect(
62 const PropertyTreeState& localState,
63 const PropertyTreeState& ancestorState)
64 {
65 PrecomputedDataForAncestor& precomputedData = GetPrecomputedDataForAncestor( ancestorState);
66 const ClipPaintPropertyNode* clipNode = localState.clip;
67 Vector<const ClipPaintPropertyNode*> intermediateNodes;
68 FloatRect clip(LayoutRect::infiniteIntRect());
69
70 bool found = false;
71 // Iterate over the path from localState.clip to ancestorState.clip. Stop if we've found a memoized (precomputed) clip
72 // for any particular node.
73 while (clipNode) {
74 auto it = precomputedData.toAncestorClipRects.find(clipNode);
75 if (it != precomputedData.toAncestorClipRects.end()) {
76 clip = it->value;
77 found = true;
78 break;
79 }
80 intermediateNodes.append(clipNode);
81
82 if (clipNode == ancestorState.clip)
83 break;
84
85 clipNode = clipNode->parent();
86 }
87 // It's illegal to ask for a local-to-ancestor clip when the ancestor is not an ancestor.
88 DCHECK(clipNode == ancestorState.clip || found);
89
90 // Iterate down from the top intermediate node found in the previous loop, c omputing and memoizing clip rects as we go.
91 for (auto it = intermediateNodes.rbegin(); it != intermediateNodes.rend(); + +it) {
92 if ((*it) != ancestorState.clip) {
93 const TransformationMatrix transformMatrix = LocalToAncestorMatrix(( *it)->localTransformSpace(), ancestorState);
94 FloatRect mappedRect = transformMatrix.mapRect((*it)->clipRect().rec t());
95 clip.intersect(mappedRect);
96 }
97
98 precomputedData.toAncestorClipRects.set(*it, clip);
99 }
100
101 return precomputedData.toAncestorClipRects.find(localState.clip)->value;
102 }
103
104 const TransformationMatrix& GeometryMapper::LocalToAncestorMatrix(
105 const TransformPaintPropertyNode* localTransformNode,
106 const PropertyTreeState& ancestorState) {
107 PrecomputedDataForAncestor& precomputedData = GetPrecomputedDataForAncestor( ancestorState);
108
109 const TransformPaintPropertyNode* transformNode = localTransformNode;
110 Vector<const TransformPaintPropertyNode*> intermediateNodes;
111 TransformationMatrix transformMatrix;
112
113 bool found = false;
114 // Iterate over the path from localTransformNode to ancestorState.transform. Stop if we've found a memoized (precomputed) transform
115 // for any particular node.
116 while (transformNode) {
117 auto it = precomputedData.toAncestorTransforms.find(transformNode);
118 if (it != precomputedData.toAncestorTransforms.end()) {
119 transformMatrix = it->value;
120 found = true;
121 break;
122 }
123
124 intermediateNodes.append(transformNode);
125
126 if (transformNode == ancestorState.transform)
127 break;
128
129 transformNode = transformNode->parent();
130 }
131 // It's illegal to ask for a local-to-ancestor matrix when the ancestor is n ot an ancestor.
132 DCHECK(transformNode == ancestorState.transform || found);
133
134 // Iterate down from the top intermediate node found in the previous loop, c omputing and memoizing transforms as we go.
135 for (auto it = intermediateNodes.rbegin(); it != intermediateNodes.rend(); i t++) {
136 if ((*it) != ancestorState.transform) {
137 TransformationMatrix localTransformMatrix = (*it)->matrix();
138 localTransformMatrix.applyTransformOrigin((*it)->origin());
139 transformMatrix = localTransformMatrix * transformMatrix;
140 }
141
142 precomputedData.toAncestorTransforms.set(*it, transformMatrix);
143 }
144 return precomputedData.toAncestorTransforms.find(localTransformNode)->value;
145 }
146
147 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698