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

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);
159 }
160
161 bool TransformTree::ComputeTransformFromSourceToParent(
ajuma 2016/07/27 15:57:11 Since this currently has essentially the same impl
jaydasika 2016/07/27 18:42:23 Done.
162 int source_id,
163 int dest_id,
164 gfx::Transform* transform) const {
165 transform->MakeIdentity();
166
167 if (source_id == dest_id)
168 return true;
169
170 if (source_id > dest_id) {
171 CombineTransformsBetween(source_id, dest_id, transform);
172 return true;
173 }
174
175 return CombineInversesBetween(source_id, dest_id, transform);
158 } 176 }
159 177
160 bool TransformTree::NeedsSourceToParentUpdate(TransformNode* node) { 178 bool TransformTree::NeedsSourceToParentUpdate(TransformNode* node) {
161 return (source_to_parent_updates_allowed() && 179 return (source_to_parent_updates_allowed() &&
162 node->parent_id != node->source_node_id); 180 node->parent_id != node->source_node_id);
163 } 181 }
164 182
165 void TransformTree::ResetChangeTracking() { 183 void TransformTree::ResetChangeTracking() {
166 for (int id = 1; id < static_cast<int>(size()); ++id) { 184 for (int id = 1; id < static_cast<int>(size()); ++id) {
167 TransformNode* node = Node(id); 185 TransformNode* node = Node(id);
(...skipping 23 matching lines...) Expand all
191 209
192 bool TransformTree::IsDescendant(int desc_id, int source_id) const { 210 bool TransformTree::IsDescendant(int desc_id, int source_id) const {
193 while (desc_id != source_id) { 211 while (desc_id != source_id) {
194 if (desc_id == kInvalidNodeId) 212 if (desc_id == kInvalidNodeId)
195 return false; 213 return false;
196 desc_id = Node(desc_id)->parent_id; 214 desc_id = Node(desc_id)->parent_id;
197 } 215 }
198 return true; 216 return true;
199 } 217 }
200 218
201 bool TransformTree::CombineTransformsBetween(int source_id, 219 void TransformTree::CombineTransformsBetween(int source_id,
202 int dest_id, 220 int dest_id,
203 gfx::Transform* transform) const { 221 gfx::Transform* transform) const {
204 DCHECK(source_id > dest_id); 222 DCHECK(source_id > dest_id);
205 const TransformNode* current = Node(source_id); 223 const TransformNode* current = Node(source_id);
206 const TransformNode* dest = Node(dest_id); 224 const TransformNode* dest = Node(dest_id);
207 // Combine transforms to and from the screen when possible. Since flattening 225 // 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 226 // is a non-linear operation, we cannot use this approach when there is
209 // non-trivial flattening between the source and destination nodes. For 227 // non-trivial flattening between the source and destination nodes. For
210 // example, consider the tree R->A->B->C, where B flattens its inherited 228 // 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 229 // 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 230 // 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 231 // 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 232 // 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 233 // 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. 234 // A's from_screen will not produce the correct result.
217 if (!dest || 235 if (!dest ||
218 (dest->ancestors_are_invertible && dest->node_and_ancestors_are_flat)) { 236 (dest->ancestors_are_invertible && dest->node_and_ancestors_are_flat)) {
219 transform->ConcatTransform(ToScreen(current->id)); 237 transform->ConcatTransform(ToScreen(current->id));
220 if (dest) 238 if (dest)
221 transform->ConcatTransform(FromScreen(dest->id)); 239 transform->ConcatTransform(FromScreen(dest->id));
222 return true; 240 return;
223 } 241 }
224 242
225 // Flattening is defined in a way that requires it to be applied while 243 // 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 244 // 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 245 // 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 246 // 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 247 // 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, 248 // 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 249 // 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 250 // 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(); 301 size_t source_to_destination_size = source_to_destination.size();
284 for (size_t i = 0; i < source_to_destination_size; ++i) { 302 for (size_t i = 0; i < source_to_destination_size; ++i) {
285 size_t index = source_to_destination_size - 1 - i; 303 size_t index = source_to_destination_size - 1 - i;
286 const TransformNode* node = Node(source_to_destination[index]); 304 const TransformNode* node = Node(source_to_destination[index]);
287 if (node->flattens_inherited_transform) 305 if (node->flattens_inherited_transform)
288 combined_transform.FlattenTo2d(); 306 combined_transform.FlattenTo2d();
289 combined_transform.PreconcatTransform(node->to_parent); 307 combined_transform.PreconcatTransform(node->to_parent);
290 } 308 }
291 309
292 transform->ConcatTransform(combined_transform); 310 transform->ConcatTransform(combined_transform);
293 return true;
294 } 311 }
295 312
296 bool TransformTree::CombineInversesBetween(int source_id, 313 bool TransformTree::CombineInversesBetween(int source_id,
297 int dest_id, 314 int dest_id,
298 gfx::Transform* transform) const { 315 gfx::Transform* transform) const {
299 DCHECK(source_id < dest_id); 316 DCHECK(source_id < dest_id);
300 const TransformNode* current = Node(dest_id); 317 const TransformNode* current = Node(dest_id);
301 const TransformNode* dest = Node(source_id); 318 const TransformNode* dest = Node(source_id);
302 // Just as in CombineTransformsBetween, we can use screen space transforms in 319 // Just as in CombineTransformsBetween, we can use screen space transforms in
303 // this computation only when there isn't any non-trivial flattening 320 // this computation only when there isn't any non-trivial flattening
(...skipping 16 matching lines...) Expand all
320 gfx::Transform source_to_dest; 337 gfx::Transform source_to_dest;
321 bool all_are_invertible = dest_to_source.GetInverse(&source_to_dest); 338 bool all_are_invertible = dest_to_source.GetInverse(&source_to_dest);
322 transform->PreconcatTransform(source_to_dest); 339 transform->PreconcatTransform(source_to_dest);
323 return all_are_invertible; 340 return all_are_invertible;
324 } 341 }
325 342
326 void TransformTree::UpdateLocalTransform(TransformNode* node) { 343 void TransformTree::UpdateLocalTransform(TransformNode* node) {
327 gfx::Transform transform = node->post_local; 344 gfx::Transform transform = node->post_local;
328 if (NeedsSourceToParentUpdate(node)) { 345 if (NeedsSourceToParentUpdate(node)) {
329 gfx::Transform to_parent; 346 gfx::Transform to_parent;
330 ComputeTransform(node->source_node_id, node->parent_id, &to_parent); 347 ComputeTransformFromSourceToParent(node->source_node_id, node->parent_id,
348 &to_parent);
331 node->source_to_parent = to_parent.To2dTranslation(); 349 node->source_to_parent = to_parent.To2dTranslation();
332 } 350 }
333 351
334 gfx::Vector2dF fixed_position_adjustment; 352 gfx::Vector2dF fixed_position_adjustment;
335 gfx::Vector2dF inner_viewport_bounds_delta = 353 gfx::Vector2dF inner_viewport_bounds_delta =
336 property_trees()->inner_viewport_container_bounds_delta(); 354 property_trees()->inner_viewport_container_bounds_delta();
337 gfx::Vector2dF outer_viewport_bounds_delta = 355 gfx::Vector2dF outer_viewport_bounds_delta =
338 property_trees()->outer_viewport_container_bounds_delta(); 356 property_trees()->outer_viewport_container_bounds_delta();
339 if (node->affected_by_inner_viewport_bounds_delta_x) 357 if (node->affected_by_inner_viewport_bounds_delta_x)
340 fixed_position_adjustment.set_x(inner_viewport_bounds_delta.x()); 358 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(), 1972 screen_space_transform.Scale(1.0 / effect_node->surface_contents_scale.x(),
1955 1.0 / effect_node->surface_contents_scale.y()); 1973 1.0 / effect_node->surface_contents_scale.y());
1956 return screen_space_transform; 1974 return screen_space_transform;
1957 } 1975 }
1958 1976
1959 bool PropertyTrees::ComputeTransformToTarget(int transform_id, 1977 bool PropertyTrees::ComputeTransformToTarget(int transform_id,
1960 int effect_id, 1978 int effect_id,
1961 gfx::Transform* transform) const { 1979 gfx::Transform* transform) const {
1962 transform->MakeIdentity(); 1980 transform->MakeIdentity();
1963 1981
1964 int destination_transform_id; 1982 int target_transform_id;
1965 if (effect_id == EffectTree::kInvalidNodeId) { 1983 if (effect_id == EffectTree::kInvalidNodeId) {
1966 // This can happen when PaintArtifactCompositor builds property trees as 1984 // This can happen when PaintArtifactCompositor builds property trees as
1967 // it doesn't set effect ids on clip nodes. We want to compute transform 1985 // it doesn't set effect ids on clip nodes. We want to compute transform
1968 // to the root in this case. 1986 // to the root in this case.
1969 destination_transform_id = TransformTree::kRootNodeId; 1987 target_transform_id = TransformTree::kRootNodeId;
1970 } else { 1988 } else {
1971 const EffectNode* effect_node = effect_tree.Node(effect_id); 1989 const EffectNode* effect_node = effect_tree.Node(effect_id);
1972 DCHECK(effect_node->has_render_surface || 1990 DCHECK(effect_node->has_render_surface ||
1973 effect_node->id == EffectTree::kRootNodeId); 1991 effect_node->id == EffectTree::kRootNodeId);
1974 destination_transform_id = effect_node->transform_id; 1992 target_transform_id = effect_node->transform_id;
1975 } 1993 }
1976 1994
1977 if (transform_id == destination_transform_id) 1995 if (transform_id == target_transform_id)
1978 return true; 1996 return true;
1979 1997
1980 if (transform_id > destination_transform_id) { 1998 if (transform_id > target_transform_id) {
1981 return transform_tree.CombineTransformsBetween( 1999 transform_tree.CombineTransformsBetween(transform_id, target_transform_id,
1982 transform_id, destination_transform_id, transform); 2000 transform);
2001 return true;
1983 } 2002 }
1984 2003
1985 return transform_tree.CombineInversesBetween( 2004 return transform_tree.CombineInversesBetween(transform_id,
1986 transform_id, destination_transform_id, transform); 2005 target_transform_id, transform);
2006 }
2007
2008 bool PropertyTrees::ComputeTransformFromTarget(
2009 int transform_id,
2010 int effect_id,
2011 gfx::Transform* transform) const {
2012 transform->MakeIdentity();
2013
2014 int target_transform_id;
2015 if (effect_id == EffectTree::kInvalidNodeId) {
2016 // This can happen when PaintArtifactCompositor builds property trees as
2017 // it doesn't set effect ids on clip nodes. We want to compute transform
2018 // to the root in this case.
2019 target_transform_id = TransformTree::kRootNodeId;
2020 } else {
2021 const EffectNode* effect_node = effect_tree.Node(effect_id);
2022 DCHECK(effect_node->has_render_surface ||
2023 effect_node->id == EffectTree::kRootNodeId);
2024 target_transform_id = effect_node->transform_id;
2025 }
2026
2027 if (transform_id == target_transform_id)
2028 return true;
2029
2030 if (transform_id > target_transform_id) {
2031 return transform_tree.CombineInversesBetween(target_transform_id,
2032 transform_id, transform);
2033 }
2034
2035 transform_tree.CombineTransformsBetween(target_transform_id, transform_id,
2036 transform);
2037 return true;
1987 } 2038 }
1988 2039
1989 } // namespace cc 2040 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698