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

Side by Side Diff: cc/trees/property_tree.cc

Issue 2180223005: cc : Split TransformTree::ComputeTransform (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 4 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 144
145 bool TransformTree::ComputeTransform(int source_id, 145 bool TransformTree::ComputeTransform(int source_id,
146 int dest_id, 146 int dest_id,
147 gfx::Transform* transform) const { 147 gfx::Transform* transform) const {
148 transform->MakeIdentity(); 148 transform->MakeIdentity();
149 149
150 if (source_id == dest_id) 150 if (source_id == dest_id)
151 return true; 151 return true;
152 152
153 if (source_id > dest_id) { 153 if (source_id > dest_id) {
154 return CombineTransformsBetween(source_id, dest_id, transform); 154 CombineTransformsBetween(source_id, dest_id, transform);
155 return true;
155 } 156 }
156 157
157 return CombineInversesBetween(source_id, dest_id, transform); 158 return CombineInversesBetween(source_id, dest_id, transform);
158 } 159 }
159 160
161 bool TransformTree::ComputeTranslation(int source_id,
162 int dest_id,
163 gfx::Transform* transform) const {
164 bool success = ComputeTransform(source_id, dest_id, transform);
165 DCHECK(transform->IsIdentityOr2DTranslation());
166 return success;
167 }
168
160 bool TransformTree::NeedsSourceToParentUpdate(TransformNode* node) { 169 bool TransformTree::NeedsSourceToParentUpdate(TransformNode* node) {
161 return (source_to_parent_updates_allowed() && 170 return (source_to_parent_updates_allowed() &&
162 node->parent_id != node->source_node_id); 171 node->parent_id != node->source_node_id);
163 } 172 }
164 173
165 void TransformTree::ResetChangeTracking() { 174 void TransformTree::ResetChangeTracking() {
166 for (int id = 1; id < static_cast<int>(size()); ++id) { 175 for (int id = 1; id < static_cast<int>(size()); ++id) {
167 TransformNode* node = Node(id); 176 TransformNode* node = Node(id);
168 node->transform_changed = false; 177 node->transform_changed = false;
169 } 178 }
(...skipping 21 matching lines...) Expand all
191 200
192 bool TransformTree::IsDescendant(int desc_id, int source_id) const { 201 bool TransformTree::IsDescendant(int desc_id, int source_id) const {
193 while (desc_id != source_id) { 202 while (desc_id != source_id) {
194 if (desc_id == kInvalidNodeId) 203 if (desc_id == kInvalidNodeId)
195 return false; 204 return false;
196 desc_id = Node(desc_id)->parent_id; 205 desc_id = Node(desc_id)->parent_id;
197 } 206 }
198 return true; 207 return true;
199 } 208 }
200 209
201 bool TransformTree::CombineTransformsBetween(int source_id, 210 void TransformTree::CombineTransformsBetween(int source_id,
202 int dest_id, 211 int dest_id,
203 gfx::Transform* transform) const { 212 gfx::Transform* transform) const {
204 DCHECK(source_id > dest_id); 213 DCHECK(source_id > dest_id);
205 const TransformNode* current = Node(source_id); 214 const TransformNode* current = Node(source_id);
206 const TransformNode* dest = Node(dest_id); 215 const TransformNode* dest = Node(dest_id);
207 // Combine transforms to and from the screen when possible. Since flattening 216 // Combine transforms to and from the screen when possible. Since flattening
208 // is a non-linear operation, we cannot use this approach when there is 217 // is a non-linear operation, we cannot use this approach when there is
209 // non-trivial flattening between the source and destination nodes. For 218 // non-trivial flattening between the source and destination nodes. For
210 // example, consider the tree R->A->B->C, where B flattens its inherited 219 // example, consider the tree R->A->B->C, where B flattens its inherited
211 // transform, and A has a non-flat transform. Suppose C is the source and A is 220 // transform, and A has a non-flat transform. Suppose C is the source and A is
212 // the destination. The expected result is C * B. But C's to_screen 221 // the destination. The expected result is C * B. But C's to_screen
213 // transform is C * B * flattened(A * R), and A's from_screen transform is 222 // transform is C * B * flattened(A * R), and A's from_screen transform is
214 // R^{-1} * A^{-1}. If at least one of A and R isn't flat, the inverse of 223 // R^{-1} * A^{-1}. If at least one of A and R isn't flat, the inverse of
215 // flattened(A * R) won't be R^{-1} * A{-1}, so multiplying C's to_screen and 224 // flattened(A * R) won't be R^{-1} * A{-1}, so multiplying C's to_screen and
216 // A's from_screen will not produce the correct result. 225 // A's from_screen will not produce the correct result.
217 if (!dest || 226 if (!dest ||
218 (dest->ancestors_are_invertible && dest->node_and_ancestors_are_flat)) { 227 (dest->ancestors_are_invertible && dest->node_and_ancestors_are_flat)) {
219 transform->ConcatTransform(ToScreen(current->id)); 228 transform->ConcatTransform(ToScreen(current->id));
220 if (dest) 229 if (dest)
221 transform->ConcatTransform(FromScreen(dest->id)); 230 transform->ConcatTransform(FromScreen(dest->id));
222 return true; 231 return;
223 } 232 }
224 233
225 // Flattening is defined in a way that requires it to be applied while 234 // Flattening is defined in a way that requires it to be applied while
226 // traversing downward in the tree. We first identify nodes that are on the 235 // traversing downward in the tree. We first identify nodes that are on the
227 // path from the source to the destination (this is traversing upward), and 236 // path from the source to the destination (this is traversing upward), and
228 // then we visit these nodes in reverse order, flattening as needed. We 237 // then we visit these nodes in reverse order, flattening as needed. We
229 // early-out if we get to a node whose target node is the destination, since 238 // early-out if we get to a node whose target node is the destination, since
230 // we can then re-use the target space transform stored at that node. However, 239 // we can then re-use the target space transform stored at that node. However,
231 // we cannot re-use a stored target space transform if the destination has a 240 // we cannot re-use a stored target space transform if the destination has a
232 // zero surface contents scale, since stored target space transforms have 241 // zero surface contents scale, since stored target space transforms have
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 size_t source_to_destination_size = source_to_destination.size(); 292 size_t source_to_destination_size = source_to_destination.size();
284 for (size_t i = 0; i < source_to_destination_size; ++i) { 293 for (size_t i = 0; i < source_to_destination_size; ++i) {
285 size_t index = source_to_destination_size - 1 - i; 294 size_t index = source_to_destination_size - 1 - i;
286 const TransformNode* node = Node(source_to_destination[index]); 295 const TransformNode* node = Node(source_to_destination[index]);
287 if (node->flattens_inherited_transform) 296 if (node->flattens_inherited_transform)
288 combined_transform.FlattenTo2d(); 297 combined_transform.FlattenTo2d();
289 combined_transform.PreconcatTransform(node->to_parent); 298 combined_transform.PreconcatTransform(node->to_parent);
290 } 299 }
291 300
292 transform->ConcatTransform(combined_transform); 301 transform->ConcatTransform(combined_transform);
293 return true;
294 } 302 }
295 303
296 bool TransformTree::CombineInversesBetween(int source_id, 304 bool TransformTree::CombineInversesBetween(int source_id,
297 int dest_id, 305 int dest_id,
298 gfx::Transform* transform) const { 306 gfx::Transform* transform) const {
299 DCHECK(source_id < dest_id); 307 DCHECK(source_id < dest_id);
300 const TransformNode* current = Node(dest_id); 308 const TransformNode* current = Node(dest_id);
301 const TransformNode* dest = Node(source_id); 309 const TransformNode* dest = Node(source_id);
302 // Just as in CombineTransformsBetween, we can use screen space transforms in 310 // Just as in CombineTransformsBetween, we can use screen space transforms in
303 // this computation only when there isn't any non-trivial flattening 311 // this computation only when there isn't any non-trivial flattening
(...skipping 16 matching lines...) Expand all
320 gfx::Transform source_to_dest; 328 gfx::Transform source_to_dest;
321 bool all_are_invertible = dest_to_source.GetInverse(&source_to_dest); 329 bool all_are_invertible = dest_to_source.GetInverse(&source_to_dest);
322 transform->PreconcatTransform(source_to_dest); 330 transform->PreconcatTransform(source_to_dest);
323 return all_are_invertible; 331 return all_are_invertible;
324 } 332 }
325 333
326 void TransformTree::UpdateLocalTransform(TransformNode* node) { 334 void TransformTree::UpdateLocalTransform(TransformNode* node) {
327 gfx::Transform transform = node->post_local; 335 gfx::Transform transform = node->post_local;
328 if (NeedsSourceToParentUpdate(node)) { 336 if (NeedsSourceToParentUpdate(node)) {
329 gfx::Transform to_parent; 337 gfx::Transform to_parent;
330 ComputeTransform(node->source_node_id, node->parent_id, &to_parent); 338 ComputeTranslation(node->source_node_id, node->parent_id, &to_parent);
331 node->source_to_parent = to_parent.To2dTranslation(); 339 node->source_to_parent = to_parent.To2dTranslation();
332 } 340 }
333 341
334 gfx::Vector2dF fixed_position_adjustment; 342 gfx::Vector2dF fixed_position_adjustment;
335 gfx::Vector2dF inner_viewport_bounds_delta = 343 gfx::Vector2dF inner_viewport_bounds_delta =
336 property_trees()->inner_viewport_container_bounds_delta(); 344 property_trees()->inner_viewport_container_bounds_delta();
337 gfx::Vector2dF outer_viewport_bounds_delta = 345 gfx::Vector2dF outer_viewport_bounds_delta =
338 property_trees()->outer_viewport_container_bounds_delta(); 346 property_trees()->outer_viewport_container_bounds_delta();
339 if (node->affected_by_inner_viewport_bounds_delta_x) 347 if (node->affected_by_inner_viewport_bounds_delta_x)
340 fixed_position_adjustment.set_x(inner_viewport_bounds_delta.x()); 348 fixed_position_adjustment.set_x(inner_viewport_bounds_delta.x());
(...skipping 1613 matching lines...) Expand 10 before | Expand all | Expand 10 after
1954 screen_space_transform.Scale(1.0 / effect_node->surface_contents_scale.x(), 1962 screen_space_transform.Scale(1.0 / effect_node->surface_contents_scale.x(),
1955 1.0 / effect_node->surface_contents_scale.y()); 1963 1.0 / effect_node->surface_contents_scale.y());
1956 return screen_space_transform; 1964 return screen_space_transform;
1957 } 1965 }
1958 1966
1959 bool PropertyTrees::ComputeTransformToTarget(int transform_id, 1967 bool PropertyTrees::ComputeTransformToTarget(int transform_id,
1960 int effect_id, 1968 int effect_id,
1961 gfx::Transform* transform) const { 1969 gfx::Transform* transform) const {
1962 transform->MakeIdentity(); 1970 transform->MakeIdentity();
1963 1971
1964 int destination_transform_id; 1972 int target_transform_id;
1965 if (effect_id == EffectTree::kInvalidNodeId) { 1973 if (effect_id == EffectTree::kInvalidNodeId) {
1966 // This can happen when PaintArtifactCompositor builds property trees as 1974 // This can happen when PaintArtifactCompositor builds property trees as
1967 // it doesn't set effect ids on clip nodes. We want to compute transform 1975 // it doesn't set effect ids on clip nodes. We want to compute transform
1968 // to the root in this case. 1976 // to the root in this case.
1969 destination_transform_id = TransformTree::kRootNodeId; 1977 target_transform_id = TransformTree::kRootNodeId;
1970 } else { 1978 } else {
1971 const EffectNode* effect_node = effect_tree.Node(effect_id); 1979 const EffectNode* effect_node = effect_tree.Node(effect_id);
1972 DCHECK(effect_node->has_render_surface || 1980 DCHECK(effect_node->has_render_surface ||
1973 effect_node->id == EffectTree::kRootNodeId); 1981 effect_node->id == EffectTree::kRootNodeId);
1974 destination_transform_id = effect_node->transform_id; 1982 target_transform_id = effect_node->transform_id;
1975 } 1983 }
1976 1984
1977 if (transform_id == destination_transform_id) 1985 return transform_tree.ComputeTransform(transform_id, target_transform_id,
1978 return true; 1986 transform);
1987 }
1979 1988
1980 if (transform_id > destination_transform_id) { 1989 bool PropertyTrees::ComputeTransformFromTarget(
1981 return transform_tree.CombineTransformsBetween( 1990 int transform_id,
1982 transform_id, destination_transform_id, transform); 1991 int effect_id,
1992 gfx::Transform* transform) const {
1993 transform->MakeIdentity();
1994
1995 int target_transform_id;
1996 if (effect_id == EffectTree::kInvalidNodeId) {
1997 // This can happen when PaintArtifactCompositor builds property trees as
1998 // it doesn't set effect ids on clip nodes. We want to compute transform
1999 // to the root in this case.
2000 target_transform_id = TransformTree::kRootNodeId;
2001 } else {
2002 const EffectNode* effect_node = effect_tree.Node(effect_id);
2003 DCHECK(effect_node->has_render_surface ||
2004 effect_node->id == EffectTree::kRootNodeId);
2005 target_transform_id = effect_node->transform_id;
1983 } 2006 }
1984 2007
1985 return transform_tree.CombineInversesBetween( 2008 return transform_tree.ComputeTransform(target_transform_id, transform_id,
1986 transform_id, destination_transform_id, transform); 2009 transform);
1987 } 2010 }
1988 2011
1989 } // namespace cc 2012 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698