| OLD | NEW |
| 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 "cc/trees/property_tree_builder.h" | 5 #include "cc/trees/property_tree_builder.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 : data.transform_tree_parent; | 43 : data.transform_tree_parent; |
| 44 } | 44 } |
| 45 | 45 |
| 46 static ClipNode* GetClipParent(const DataForRecursion& data, Layer* layer) { | 46 static ClipNode* GetClipParent(const DataForRecursion& data, Layer* layer) { |
| 47 const bool inherits_clip = !layer->parent() || !layer->clip_parent(); | 47 const bool inherits_clip = !layer->parent() || !layer->clip_parent(); |
| 48 const int id = inherits_clip ? data.clip_tree_parent | 48 const int id = inherits_clip ? data.clip_tree_parent |
| 49 : layer->clip_parent()->clip_tree_index(); | 49 : layer->clip_parent()->clip_tree_index(); |
| 50 return data.clip_tree->Node(id); | 50 return data.clip_tree->Node(id); |
| 51 } | 51 } |
| 52 | 52 |
| 53 static bool HasPotentiallyRunningAnimation(Layer* layer, |
| 54 Animation::TargetProperty property) { |
| 55 if (Animation* animation = |
| 56 layer->layer_animation_controller()->GetAnimation(property)) { |
| 57 return !animation->is_finished(); |
| 58 } |
| 59 return false; |
| 60 } |
| 61 |
| 53 static bool RequiresClipNode(Layer* layer, | 62 static bool RequiresClipNode(Layer* layer, |
| 54 const DataForRecursion& data, | 63 const DataForRecursion& data, |
| 55 int parent_transform_id) { | 64 int parent_transform_id) { |
| 56 const bool render_surface_applies_clip = | 65 const bool render_surface_applies_clip = |
| 57 layer->render_surface() && layer->is_clipped(); | 66 layer->render_surface() && layer->is_clipped(); |
| 58 const bool render_surface_may_grow_due_to_clip_children = | 67 const bool render_surface_may_grow_due_to_clip_children = |
| 59 layer->render_surface() && layer->num_unclipped_descendants() > 0; | 68 layer->render_surface() && layer->num_unclipped_descendants() > 0; |
| 60 | 69 |
| 61 if (!layer->parent() || layer->masks_to_bounds() || layer->mask_layer() || | 70 if (!layer->parent() || layer->masks_to_bounds() || layer->mask_layer() || |
| 62 render_surface_may_grow_due_to_clip_children) | 71 render_surface_may_grow_due_to_clip_children) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 if (layer->position_constraint().is_fixed_position() && | 107 if (layer->position_constraint().is_fixed_position() && |
| 99 !created_transform_node) { | 108 !created_transform_node) { |
| 100 transform_parent = data_for_children->transform_fixed_parent; | 109 transform_parent = data_for_children->transform_fixed_parent; |
| 101 } | 110 } |
| 102 ClipNode node; | 111 ClipNode node; |
| 103 node.data.clip = gfx::RectF( | 112 node.data.clip = gfx::RectF( |
| 104 gfx::PointF() + layer->offset_to_transform_parent(), layer->bounds()); | 113 gfx::PointF() + layer->offset_to_transform_parent(), layer->bounds()); |
| 105 node.data.transform_id = transform_parent->transform_tree_index(); | 114 node.data.transform_id = transform_parent->transform_tree_index(); |
| 106 node.data.target_id = | 115 node.data.target_id = |
| 107 data_for_children->render_target->transform_tree_index(); | 116 data_for_children->render_target->transform_tree_index(); |
| 117 node.owner_id = layer->id(); |
| 108 | 118 |
| 109 data_for_children->clip_tree_parent = | 119 data_for_children->clip_tree_parent = |
| 110 data_for_children->clip_tree->Insert(node, parent_id); | 120 data_for_children->clip_tree->Insert(node, parent_id); |
| 111 } | 121 } |
| 112 | 122 |
| 113 layer->set_clip_tree_index( | 123 layer->set_clip_tree_index( |
| 114 has_unclipped_surface ? 0 : data_for_children->clip_tree_parent); | 124 has_unclipped_surface ? 0 : data_for_children->clip_tree_parent); |
| 115 | 125 |
| 116 // TODO(awoloszyn): Right now when we hit a node with a replica, we reset the | 126 // TODO(awoloszyn): Right now when we hit a node with a replica, we reset the |
| 117 // clip for all children since we may need to draw. We need to figure out a | 127 // clip for all children since we may need to draw. We need to figure out a |
| 118 // better way, since we will need both the clipped and unclipped versions. | 128 // better way, since we will need both the clipped and unclipped versions. |
| 119 } | 129 } |
| 120 | 130 |
| 121 bool AddTransformNodeIfNeeded(const DataForRecursion& data_from_ancestor, | 131 bool AddTransformNodeIfNeeded(const DataForRecursion& data_from_ancestor, |
| 122 Layer* layer, | 132 Layer* layer, |
| 123 DataForRecursion* data_for_children) { | 133 DataForRecursion* data_for_children) { |
| 124 const bool is_root = !layer->parent(); | 134 const bool is_root = !layer->parent(); |
| 125 const bool is_page_scale_application_layer = | 135 const bool is_page_scale_application_layer = |
| 126 layer->parent() && layer->parent() == data_from_ancestor.page_scale_layer; | 136 layer->parent() && layer->parent() == data_from_ancestor.page_scale_layer; |
| 127 const bool is_scrollable = layer->scrollable(); | 137 const bool is_scrollable = layer->scrollable(); |
| 128 const bool is_fixed = layer->position_constraint().is_fixed_position(); | 138 const bool is_fixed = layer->position_constraint().is_fixed_position(); |
| 129 | 139 |
| 130 const bool has_significant_transform = | 140 const bool has_significant_transform = |
| 131 !layer->transform().IsIdentityOr2DTranslation(); | 141 !layer->transform().IsIdentityOr2DTranslation(); |
| 132 | 142 |
| 143 const bool has_potentially_animated_transform = |
| 144 HasPotentiallyRunningAnimation(layer, Animation::TRANSFORM); |
| 145 |
| 133 const bool has_animated_transform = | 146 const bool has_animated_transform = |
| 134 layer->layer_animation_controller()->IsAnimatingProperty( | 147 layer->layer_animation_controller()->IsAnimatingProperty( |
| 135 Animation::TRANSFORM); | 148 Animation::TRANSFORM); |
| 136 | 149 |
| 137 const bool has_surface = !!layer->render_surface(); | 150 const bool has_surface = !!layer->render_surface(); |
| 138 | 151 |
| 139 bool requires_node = is_root || is_scrollable || has_significant_transform || | 152 bool requires_node = is_root || is_scrollable || has_significant_transform || |
| 140 has_animated_transform || has_surface || | 153 has_potentially_animated_transform || has_surface || |
| 141 is_page_scale_application_layer; | 154 is_page_scale_application_layer; |
| 142 | 155 |
| 143 Layer* transform_parent = GetTransformParent(data_from_ancestor, layer); | 156 Layer* transform_parent = GetTransformParent(data_from_ancestor, layer); |
| 144 | 157 |
| 145 gfx::Vector2dF parent_offset; | 158 gfx::Vector2dF parent_offset; |
| 146 if (transform_parent) { | 159 if (transform_parent) { |
| 147 if (layer->scroll_parent()) { | 160 if (layer->scroll_parent()) { |
| 148 gfx::Transform to_parent; | 161 gfx::Transform to_parent; |
| 149 Layer* source = layer->parent(); | 162 Layer* source = layer->parent(); |
| 150 parent_offset += source->offset_to_transform_parent(); | 163 parent_offset += source->offset_to_transform_parent(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 // Surfaces inherently flatten transforms. | 218 // Surfaces inherently flatten transforms. |
| 206 data_for_children->should_flatten = | 219 data_for_children->should_flatten = |
| 207 layer->should_flatten_transform() || has_surface; | 220 layer->should_flatten_transform() || has_surface; |
| 208 node->data.target_id = | 221 node->data.target_id = |
| 209 data_from_ancestor.render_target->transform_tree_index(); | 222 data_from_ancestor.render_target->transform_tree_index(); |
| 210 node->data.content_target_id = | 223 node->data.content_target_id = |
| 211 data_for_children->render_target->transform_tree_index(); | 224 data_for_children->render_target->transform_tree_index(); |
| 212 DCHECK_NE(node->data.target_id, -1); | 225 DCHECK_NE(node->data.target_id, -1); |
| 213 node->data.is_animated = has_animated_transform; | 226 node->data.is_animated = has_animated_transform; |
| 214 | 227 |
| 215 float scale_factors = 1.0f; | 228 float post_local_scale_factor = 1.0f; |
| 216 if (is_root) { | 229 if (is_root) { |
| 217 node->data.post_local = *data_from_ancestor.device_transform; | 230 node->data.post_local = *data_from_ancestor.device_transform; |
| 218 scale_factors = data_from_ancestor.device_scale_factor; | 231 post_local_scale_factor = data_from_ancestor.device_scale_factor; |
| 219 } | 232 } |
| 220 | 233 |
| 221 if (is_page_scale_application_layer) | 234 if (is_page_scale_application_layer) |
| 222 scale_factors *= data_from_ancestor.page_scale_factor; | 235 post_local_scale_factor *= data_from_ancestor.page_scale_factor; |
| 223 | 236 |
| 224 if (has_surface && !is_root) { | 237 if (has_surface && !is_root) { |
| 225 node->data.needs_sublayer_scale = true; | 238 node->data.needs_sublayer_scale = true; |
| 226 node->data.layer_scale_factor = data_from_ancestor.device_scale_factor; | 239 node->data.layer_scale_factor = data_from_ancestor.device_scale_factor; |
| 227 if (data_from_ancestor.in_subtree_of_page_scale_application_layer) | 240 if (data_from_ancestor.in_subtree_of_page_scale_application_layer) |
| 228 node->data.layer_scale_factor *= data_from_ancestor.page_scale_factor; | 241 node->data.layer_scale_factor *= data_from_ancestor.page_scale_factor; |
| 229 } | 242 } |
| 230 | 243 |
| 231 node->data.post_local.Scale(scale_factors, scale_factors); | 244 if (is_root) { |
| 232 node->data.post_local.Translate3d( | 245 node->data.post_local.Scale(post_local_scale_factor, |
| 233 layer->position().x() + parent_offset.x() + layer->transform_origin().x(), | 246 post_local_scale_factor); |
| 234 layer->position().y() + parent_offset.y() + layer->transform_origin().y(), | 247 } else { |
| 235 layer->transform_origin().z()); | 248 node->data.post_local_scale_factor = post_local_scale_factor; |
| 249 node->data.parent_offset = parent_offset; |
| 250 node->data.update_post_local_transform(layer->position(), |
| 251 layer->transform_origin()); |
| 252 } |
| 236 | 253 |
| 237 if (!layer->scroll_parent()) { | 254 if (!layer->scroll_parent()) { |
| 238 node->data.scroll_offset = | 255 node->data.scroll_offset = |
| 239 gfx::ScrollOffsetToVector2dF(layer->CurrentScrollOffset()); | 256 gfx::ScrollOffsetToVector2dF(layer->CurrentScrollOffset()); |
| 240 } | 257 } |
| 241 | 258 |
| 242 node->data.local = layer->transform(); | 259 node->data.local = layer->transform(); |
| 243 node->data.pre_local.Translate3d(-layer->transform_origin().x(), | 260 node->data.pre_local.Translate3d(-layer->transform_origin().x(), |
| 244 -layer->transform_origin().y(), | 261 -layer->transform_origin().y(), |
| 245 -layer->transform_origin().z()); | 262 -layer->transform_origin().z()); |
| 246 | 263 |
| 247 node->data.needs_local_transform_update = true; | 264 node->data.needs_local_transform_update = true; |
| 248 data_from_ancestor.transform_tree->UpdateTransforms(node->id); | 265 data_from_ancestor.transform_tree->UpdateTransforms(node->id); |
| 249 | 266 |
| 250 layer->set_offset_to_transform_parent(gfx::Vector2dF()); | 267 layer->set_offset_to_transform_parent(gfx::Vector2dF()); |
| 251 | 268 |
| 252 // Flattening (if needed) will be handled by |node|. | 269 // Flattening (if needed) will be handled by |node|. |
| 253 layer->set_should_flatten_transform_from_property_tree(false); | 270 layer->set_should_flatten_transform_from_property_tree(false); |
| 254 | 271 |
| 255 data_for_children->scroll_compensation_adjustment += | 272 data_for_children->scroll_compensation_adjustment += |
| 256 layer->ScrollCompensationAdjustment() - node->data.scroll_snap; | 273 layer->ScrollCompensationAdjustment() - node->data.scroll_snap; |
| 274 |
| 275 node->owner_id = layer->id(); |
| 276 |
| 257 return true; | 277 return true; |
| 258 } | 278 } |
| 259 | 279 |
| 260 void AddOpacityNodeIfNeeded(const DataForRecursion& data_from_ancestor, | 280 void AddOpacityNodeIfNeeded(const DataForRecursion& data_from_ancestor, |
| 261 Layer* layer, | 281 Layer* layer, |
| 262 DataForRecursion* data_for_children) { | 282 DataForRecursion* data_for_children) { |
| 263 const bool is_root = !layer->parent(); | 283 const bool is_root = !layer->parent(); |
| 264 const bool has_transparency = layer->opacity() != 1.f; | 284 const bool has_transparency = layer->opacity() != 1.f; |
| 265 const bool has_animated_opacity = | 285 const bool has_animated_opacity = |
| 266 layer->layer_animation_controller()->IsAnimatingProperty( | 286 HasPotentiallyRunningAnimation(layer, Animation::OPACITY) || |
| 267 Animation::OPACITY) || | |
| 268 layer->OpacityCanAnimateOnImplThread(); | 287 layer->OpacityCanAnimateOnImplThread(); |
| 269 bool requires_node = is_root || has_transparency || has_animated_opacity; | 288 bool requires_node = is_root || has_transparency || has_animated_opacity; |
| 270 | 289 |
| 271 int parent_id = data_from_ancestor.opacity_tree_parent; | 290 int parent_id = data_from_ancestor.opacity_tree_parent; |
| 272 | 291 |
| 273 if (!requires_node) { | 292 if (!requires_node) { |
| 274 layer->set_opacity_tree_index(parent_id); | 293 layer->set_opacity_tree_index(parent_id); |
| 275 data_for_children->opacity_tree_parent = parent_id; | 294 data_for_children->opacity_tree_parent = parent_id; |
| 276 return; | 295 return; |
| 277 } | 296 } |
| 278 | 297 |
| 279 OpacityNode node; | 298 OpacityNode node; |
| 299 node.owner_id = layer->id(); |
| 280 node.data = layer->opacity(); | 300 node.data = layer->opacity(); |
| 281 data_for_children->opacity_tree_parent = | 301 data_for_children->opacity_tree_parent = |
| 282 data_for_children->opacity_tree->Insert(node, parent_id); | 302 data_for_children->opacity_tree->Insert(node, parent_id); |
| 283 layer->set_opacity_tree_index(data_for_children->opacity_tree_parent); | 303 layer->set_opacity_tree_index(data_for_children->opacity_tree_parent); |
| 284 } | 304 } |
| 285 | 305 |
| 286 void BuildPropertyTreesInternal(Layer* layer, | 306 void BuildPropertyTreesInternal(Layer* layer, |
| 287 const DataForRecursion& data_from_parent) { | 307 const DataForRecursion& data_from_parent) { |
| 288 DataForRecursion data_for_children(data_from_parent); | 308 DataForRecursion data_for_children(data_from_parent); |
| 289 if (layer->render_surface()) | 309 if (layer->render_surface()) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 318 } // namespace | 338 } // namespace |
| 319 | 339 |
| 320 void PropertyTreeBuilder::BuildPropertyTrees( | 340 void PropertyTreeBuilder::BuildPropertyTrees( |
| 321 Layer* root_layer, | 341 Layer* root_layer, |
| 322 const Layer* page_scale_layer, | 342 const Layer* page_scale_layer, |
| 323 float page_scale_factor, | 343 float page_scale_factor, |
| 324 float device_scale_factor, | 344 float device_scale_factor, |
| 325 const gfx::Rect& viewport, | 345 const gfx::Rect& viewport, |
| 326 const gfx::Transform& device_transform, | 346 const gfx::Transform& device_transform, |
| 327 PropertyTrees* property_trees) { | 347 PropertyTrees* property_trees) { |
| 348 if (!property_trees->needs_rebuild) |
| 349 return; |
| 350 |
| 328 DataForRecursion data_for_recursion; | 351 DataForRecursion data_for_recursion; |
| 329 data_for_recursion.transform_tree = &property_trees->transform_tree; | 352 data_for_recursion.transform_tree = &property_trees->transform_tree; |
| 330 data_for_recursion.clip_tree = &property_trees->clip_tree; | 353 data_for_recursion.clip_tree = &property_trees->clip_tree; |
| 331 data_for_recursion.opacity_tree = &property_trees->opacity_tree; | 354 data_for_recursion.opacity_tree = &property_trees->opacity_tree; |
| 332 data_for_recursion.transform_tree_parent = nullptr; | 355 data_for_recursion.transform_tree_parent = nullptr; |
| 333 data_for_recursion.transform_fixed_parent = nullptr; | 356 data_for_recursion.transform_fixed_parent = nullptr; |
| 334 data_for_recursion.render_target = root_layer; | 357 data_for_recursion.render_target = root_layer; |
| 335 data_for_recursion.clip_tree_parent = 0; | 358 data_for_recursion.clip_tree_parent = 0; |
| 336 data_for_recursion.opacity_tree_parent = -1; | 359 data_for_recursion.opacity_tree_parent = -1; |
| 337 data_for_recursion.page_scale_layer = page_scale_layer; | 360 data_for_recursion.page_scale_layer = page_scale_layer; |
| 338 data_for_recursion.page_scale_factor = page_scale_factor; | 361 data_for_recursion.page_scale_factor = page_scale_factor; |
| 339 data_for_recursion.device_scale_factor = device_scale_factor; | 362 data_for_recursion.device_scale_factor = device_scale_factor; |
| 340 data_for_recursion.in_subtree_of_page_scale_application_layer = false; | 363 data_for_recursion.in_subtree_of_page_scale_application_layer = false; |
| 341 data_for_recursion.should_flatten = false; | 364 data_for_recursion.should_flatten = false; |
| 342 data_for_recursion.device_transform = &device_transform; | 365 data_for_recursion.device_transform = &device_transform; |
| 343 | 366 |
| 367 data_for_recursion.transform_tree->clear(); |
| 368 data_for_recursion.clip_tree->clear(); |
| 369 data_for_recursion.opacity_tree->clear(); |
| 370 |
| 344 ClipNode root_clip; | 371 ClipNode root_clip; |
| 345 root_clip.data.clip = viewport; | 372 root_clip.data.clip = viewport; |
| 346 root_clip.data.transform_id = 0; | 373 root_clip.data.transform_id = 0; |
| 347 data_for_recursion.clip_tree_parent = | 374 data_for_recursion.clip_tree_parent = |
| 348 data_for_recursion.clip_tree->Insert(root_clip, 0); | 375 data_for_recursion.clip_tree->Insert(root_clip, 0); |
| 349 BuildPropertyTreesInternal(root_layer, data_for_recursion); | 376 BuildPropertyTreesInternal(root_layer, data_for_recursion); |
| 377 property_trees->needs_rebuild = false; |
| 350 } | 378 } |
| 351 | 379 |
| 352 } // namespace cc | 380 } // namespace cc |
| OLD | NEW |