| 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" |
| 11 #include "cc/layers/layer.h" | 11 #include "cc/layers/layer.h" |
| 12 #include "cc/trees/layer_tree_host.h" | 12 #include "cc/trees/layer_tree_host.h" |
| 13 #include "ui/gfx/geometry/point_f.h" | 13 #include "ui/gfx/geometry/point_f.h" |
| 14 #include "ui/gfx/geometry/vector2d_conversions.h" |
| 14 | 15 |
| 15 namespace cc { | 16 namespace cc { |
| 16 | 17 |
| 17 class LayerTreeHost; | 18 class LayerTreeHost; |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 struct DataForRecursion { | 22 struct DataForRecursion { |
| 22 TransformTree* transform_tree; | 23 TransformTree* transform_tree; |
| 23 ClipTree* clip_tree; | 24 ClipTree* clip_tree; |
| 24 OpacityTree* opacity_tree; | 25 OpacityTree* opacity_tree; |
| 25 Layer* transform_tree_parent; | 26 Layer* transform_tree_parent; |
| 26 Layer* transform_fixed_parent; | 27 Layer* transform_fixed_parent; |
| 27 Layer* render_target; | 28 Layer* render_target; |
| 28 int clip_tree_parent; | 29 int clip_tree_parent; |
| 29 int opacity_tree_parent; | 30 int opacity_tree_parent; |
| 30 const Layer* page_scale_layer; | 31 const Layer* page_scale_layer; |
| 31 float page_scale_factor; | 32 float page_scale_factor; |
| 32 float device_scale_factor; | 33 float device_scale_factor; |
| 33 bool in_subtree_of_page_scale_application_layer; | 34 bool in_subtree_of_page_scale_application_layer; |
| 34 bool should_flatten; | 35 bool should_flatten; |
| 35 const gfx::Transform* device_transform; | 36 const gfx::Transform* device_transform; |
| 37 gfx::Vector2dF scroll_compensation_adjustment; |
| 36 }; | 38 }; |
| 37 | 39 |
| 38 static Layer* GetTransformParent(const DataForRecursion& data, Layer* layer) { | 40 static Layer* GetTransformParent(const DataForRecursion& data, Layer* layer) { |
| 39 return layer->position_constraint().is_fixed_position() | 41 return layer->position_constraint().is_fixed_position() |
| 40 ? data.transform_fixed_parent | 42 ? data.transform_fixed_parent |
| 41 : data.transform_tree_parent; | 43 : data.transform_tree_parent; |
| 42 } | 44 } |
| 43 | 45 |
| 44 static ClipNode* GetClipParent(const DataForRecursion& data, Layer* layer) { | 46 static ClipNode* GetClipParent(const DataForRecursion& data, Layer* layer) { |
| 45 const bool inherits_clip = !layer->parent() || !layer->clip_parent(); | 47 const bool inherits_clip = !layer->parent() || !layer->clip_parent(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 if (layer->scroll_parent()) { | 136 if (layer->scroll_parent()) { |
| 135 gfx::Transform to_parent; | 137 gfx::Transform to_parent; |
| 136 Layer* source = layer->parent(); | 138 Layer* source = layer->parent(); |
| 137 parent_offset += source->offset_to_transform_parent(); | 139 parent_offset += source->offset_to_transform_parent(); |
| 138 data_from_ancestor.transform_tree->ComputeTransform( | 140 data_from_ancestor.transform_tree->ComputeTransform( |
| 139 source->transform_tree_index(), | 141 source->transform_tree_index(), |
| 140 transform_parent->transform_tree_index(), &to_parent); | 142 transform_parent->transform_tree_index(), &to_parent); |
| 141 parent_offset += to_parent.To2dTranslation(); | 143 parent_offset += to_parent.To2dTranslation(); |
| 142 } else if (!is_fixed) { | 144 } else if (!is_fixed) { |
| 143 parent_offset = transform_parent->offset_to_transform_parent(); | 145 parent_offset = transform_parent->offset_to_transform_parent(); |
| 144 } else if (data_from_ancestor.transform_tree_parent != | 146 } else { |
| 145 data_from_ancestor.transform_fixed_parent) { | 147 if (data_from_ancestor.transform_tree_parent != |
| 146 gfx::Vector2dF fixed_offset = data_from_ancestor.transform_tree_parent | 148 data_from_ancestor.transform_fixed_parent) { |
| 147 ->offset_to_transform_parent(); | 149 gfx::Vector2dF fixed_offset = data_from_ancestor.transform_tree_parent |
| 148 gfx::Transform parent_to_parent; | 150 ->offset_to_transform_parent(); |
| 149 data_from_ancestor.transform_tree->ComputeTransform( | 151 gfx::Transform parent_to_parent; |
| 150 data_from_ancestor.transform_tree_parent->transform_tree_index(), | 152 data_from_ancestor.transform_tree->ComputeTransform( |
| 151 data_from_ancestor.transform_fixed_parent->transform_tree_index(), | 153 data_from_ancestor.transform_tree_parent->transform_tree_index(), |
| 152 &parent_to_parent); | 154 data_from_ancestor.transform_fixed_parent->transform_tree_index(), |
| 155 &parent_to_parent); |
| 153 | 156 |
| 154 fixed_offset += parent_to_parent.To2dTranslation(); | 157 fixed_offset += parent_to_parent.To2dTranslation(); |
| 155 parent_offset += fixed_offset; | 158 parent_offset += fixed_offset; |
| 159 } |
| 160 parent_offset += data_from_ancestor.scroll_compensation_adjustment; |
| 156 } | 161 } |
| 157 } | 162 } |
| 158 | 163 |
| 159 if (layer->IsContainerForFixedPositionLayers() || is_root) | 164 if (layer->IsContainerForFixedPositionLayers() || is_root) |
| 160 data_for_children->transform_fixed_parent = layer; | 165 data_for_children->transform_fixed_parent = layer; |
| 161 data_for_children->transform_tree_parent = layer; | 166 data_for_children->transform_tree_parent = layer; |
| 162 | 167 |
| 168 if (layer->IsContainerForFixedPositionLayers() || is_fixed) |
| 169 data_for_children->scroll_compensation_adjustment = gfx::Vector2dF(); |
| 170 |
| 163 if (!requires_node) { | 171 if (!requires_node) { |
| 164 data_for_children->should_flatten |= layer->should_flatten_transform(); | 172 data_for_children->should_flatten |= layer->should_flatten_transform(); |
| 165 gfx::Vector2dF local_offset = layer->position().OffsetFromOrigin() + | 173 gfx::Vector2dF local_offset = layer->position().OffsetFromOrigin() + |
| 166 layer->transform().To2dTranslation(); | 174 layer->transform().To2dTranslation(); |
| 167 layer->set_offset_to_transform_parent(parent_offset + local_offset); | 175 layer->set_offset_to_transform_parent(parent_offset + local_offset); |
| 168 layer->set_should_flatten_transform_from_property_tree( | 176 layer->set_should_flatten_transform_from_property_tree( |
| 169 data_from_ancestor.should_flatten); | 177 data_from_ancestor.should_flatten); |
| 170 layer->set_transform_tree_index(transform_parent->transform_tree_index()); | 178 layer->set_transform_tree_index(transform_parent->transform_tree_index()); |
| 171 return; | 179 return; |
| 172 } | 180 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 -layer->transform_origin().y(), | 233 -layer->transform_origin().y(), |
| 226 -layer->transform_origin().z()); | 234 -layer->transform_origin().z()); |
| 227 | 235 |
| 228 node->data.needs_local_transform_update = true; | 236 node->data.needs_local_transform_update = true; |
| 229 data_from_ancestor.transform_tree->UpdateTransforms(node->id); | 237 data_from_ancestor.transform_tree->UpdateTransforms(node->id); |
| 230 | 238 |
| 231 layer->set_offset_to_transform_parent(gfx::Vector2dF()); | 239 layer->set_offset_to_transform_parent(gfx::Vector2dF()); |
| 232 | 240 |
| 233 // Flattening (if needed) will be handled by |node|. | 241 // Flattening (if needed) will be handled by |node|. |
| 234 layer->set_should_flatten_transform_from_property_tree(false); | 242 layer->set_should_flatten_transform_from_property_tree(false); |
| 243 |
| 244 data_for_children->scroll_compensation_adjustment += |
| 245 layer->ScrollCompensationAdjustment() - node->data.scroll_snap; |
| 235 } | 246 } |
| 236 | 247 |
| 237 void AddOpacityNodeIfNeeded(const DataForRecursion& data_from_ancestor, | 248 void AddOpacityNodeIfNeeded(const DataForRecursion& data_from_ancestor, |
| 238 Layer* layer, | 249 Layer* layer, |
| 239 DataForRecursion* data_for_children) { | 250 DataForRecursion* data_for_children) { |
| 240 const bool is_root = !layer->parent(); | 251 const bool is_root = !layer->parent(); |
| 241 const bool has_transparency = layer->opacity() != 1.f; | 252 const bool has_transparency = layer->opacity() != 1.f; |
| 242 const bool has_animated_opacity = | 253 const bool has_animated_opacity = |
| 243 layer->layer_animation_controller()->IsAnimatingProperty( | 254 layer->layer_animation_controller()->IsAnimatingProperty( |
| 244 Animation::OPACITY) || | 255 Animation::OPACITY) || |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 data_for_recursion.device_transform = &device_transform; | 330 data_for_recursion.device_transform = &device_transform; |
| 320 | 331 |
| 321 ClipNode root_clip; | 332 ClipNode root_clip; |
| 322 root_clip.data.clip = viewport; | 333 root_clip.data.clip = viewport; |
| 323 root_clip.data.transform_id = 0; | 334 root_clip.data.transform_id = 0; |
| 324 data_for_recursion.clip_tree_parent = clip_tree->Insert(root_clip, 0); | 335 data_for_recursion.clip_tree_parent = clip_tree->Insert(root_clip, 0); |
| 325 BuildPropertyTreesInternal(root_layer, data_for_recursion); | 336 BuildPropertyTreesInternal(root_layer, data_for_recursion); |
| 326 } | 337 } |
| 327 | 338 |
| 328 } // namespace cc | 339 } // namespace cc |
| OLD | NEW |