| 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 12 matching lines...) Expand all Loading... |
| 23 ClipTree* clip_tree; | 23 ClipTree* clip_tree; |
| 24 Layer* transform_tree_parent; | 24 Layer* transform_tree_parent; |
| 25 Layer* transform_fixed_parent; | 25 Layer* transform_fixed_parent; |
| 26 Layer* render_target; | 26 Layer* render_target; |
| 27 int clip_tree_parent; | 27 int clip_tree_parent; |
| 28 gfx::Vector2dF offset_to_transform_tree_parent; | 28 gfx::Vector2dF offset_to_transform_tree_parent; |
| 29 gfx::Vector2dF offset_to_transform_fixed_parent; | 29 gfx::Vector2dF offset_to_transform_fixed_parent; |
| 30 const Layer* page_scale_layer; | 30 const Layer* page_scale_layer; |
| 31 float page_scale_factor; | 31 float page_scale_factor; |
| 32 float device_scale_factor; | 32 float device_scale_factor; |
| 33 bool in_subtree_of_page_scale_application_layer; |
| 34 const gfx::Transform* device_transform; |
| 33 }; | 35 }; |
| 34 | 36 |
| 35 static Layer* GetTransformParent(const DataForRecursion& data, Layer* layer) { | 37 static Layer* GetTransformParent(const DataForRecursion& data, Layer* layer) { |
| 36 return layer->position_constraint().is_fixed_position() | 38 return layer->position_constraint().is_fixed_position() |
| 37 ? data.transform_fixed_parent | 39 ? data.transform_fixed_parent |
| 38 : data.transform_tree_parent; | 40 : data.transform_tree_parent; |
| 39 } | 41 } |
| 40 | 42 |
| 41 static ClipNode* GetClipParent(const DataForRecursion& data, Layer* layer) { | 43 static ClipNode* GetClipParent(const DataForRecursion& data, Layer* layer) { |
| 42 const bool inherits_clip = !layer->parent() || !layer->clip_parent(); | 44 const bool inherits_clip = !layer->parent() || !layer->clip_parent(); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 data_for_children->transform_tree_parent = layer; | 160 data_for_children->transform_tree_parent = layer; |
| 159 | 161 |
| 160 if (!requires_node) { | 162 if (!requires_node) { |
| 161 gfx::Vector2dF local_offset = layer->position().OffsetFromOrigin() + | 163 gfx::Vector2dF local_offset = layer->position().OffsetFromOrigin() + |
| 162 layer->transform().To2dTranslation(); | 164 layer->transform().To2dTranslation(); |
| 163 layer->set_offset_to_transform_parent(parent_offset + local_offset); | 165 layer->set_offset_to_transform_parent(parent_offset + local_offset); |
| 164 layer->set_transform_tree_index(transform_parent->transform_tree_index()); | 166 layer->set_transform_tree_index(transform_parent->transform_tree_index()); |
| 165 return; | 167 return; |
| 166 } | 168 } |
| 167 | 169 |
| 168 if (!is_root) { | 170 int parent_index = 0; |
| 169 data_for_children->transform_tree->Insert( | 171 if (transform_parent) |
| 170 TransformNode(), transform_parent->transform_tree_index()); | 172 parent_index = transform_parent->transform_tree_index(); |
| 171 } | 173 |
| 174 data_for_children->transform_tree->Insert(TransformNode(), parent_index); |
| 172 | 175 |
| 173 TransformNode* node = data_for_children->transform_tree->back(); | 176 TransformNode* node = data_for_children->transform_tree->back(); |
| 174 layer->set_transform_tree_index(node->id); | 177 layer->set_transform_tree_index(node->id); |
| 175 | 178 |
| 179 node->data.scrolls = is_scrollable; |
| 176 node->data.flattens = layer->should_flatten_transform(); | 180 node->data.flattens = layer->should_flatten_transform(); |
| 177 node->data.target_id = | 181 node->data.target_id = |
| 178 data_from_ancestor.render_target->transform_tree_index(); | 182 data_from_ancestor.render_target->transform_tree_index(); |
| 183 node->data.content_target_id = |
| 184 data_for_children->render_target->transform_tree_index(); |
| 179 DCHECK_NE(node->data.target_id, -1); | 185 DCHECK_NE(node->data.target_id, -1); |
| 180 node->data.is_animated = layer->TransformIsAnimating(); | 186 node->data.is_animated = layer->TransformIsAnimating(); |
| 181 | 187 |
| 182 gfx::Transform transform; | 188 float scale_factors = 1.0f; |
| 183 float device_and_page_scale_factors = 1.0f; | 189 if (is_root) { |
| 184 if (is_root) | 190 node->data.post_local = *data_from_ancestor.device_transform; |
| 185 device_and_page_scale_factors = data_from_ancestor.device_scale_factor; | 191 scale_factors = data_from_ancestor.device_scale_factor; |
| 186 if (is_page_scale_application_layer) | |
| 187 device_and_page_scale_factors *= data_from_ancestor.page_scale_factor; | |
| 188 | |
| 189 transform.Scale(device_and_page_scale_factors, device_and_page_scale_factors); | |
| 190 | |
| 191 // TODO(vollick): We've accounted for the scroll offset here but we haven't | |
| 192 // taken into account snapping to screen space pixels. For the purposes of | |
| 193 // computing rects we need to record, this should be fine (the visible rects | |
| 194 // we compute may be slightly different than what we'd compute with snapping, | |
| 195 // but since we significantly expand the visible rect when determining what to | |
| 196 // record, the slight difference should be inconsequential). | |
| 197 gfx::Vector2dF position = layer->position().OffsetFromOrigin(); | |
| 198 if (!layer->scroll_parent()) { | |
| 199 position -= gfx::Vector2dF(layer->CurrentScrollOffset().x(), | |
| 200 layer->CurrentScrollOffset().y()); | |
| 201 } | 192 } |
| 202 | 193 |
| 203 position += parent_offset; | 194 if (is_page_scale_application_layer) |
| 195 scale_factors *= data_from_ancestor.page_scale_factor; |
| 204 | 196 |
| 205 transform.Translate3d(position.x() + layer->transform_origin().x(), | 197 if (has_surface && !is_root) { |
| 206 position.y() + layer->transform_origin().y(), | 198 node->data.needs_sublayer_scale = true; |
| 207 layer->transform_origin().z()); | 199 node->data.layer_scale_factor = data_from_ancestor.device_scale_factor; |
| 208 transform.PreconcatTransform(layer->transform()); | 200 if (data_from_ancestor.in_subtree_of_page_scale_application_layer) |
| 209 transform.Translate3d(-layer->transform_origin().x(), | 201 node->data.layer_scale_factor *= data_from_ancestor.page_scale_factor; |
| 210 -layer->transform_origin().y(), | 202 } |
| 211 -layer->transform_origin().z()); | |
| 212 | 203 |
| 213 node->data.to_parent = transform; | 204 node->data.post_local.Scale(scale_factors, scale_factors); |
| 214 node->data.is_invertible = transform.GetInverse(&node->data.from_parent); | 205 node->data.post_local.Translate3d( |
| 206 layer->position().x() + parent_offset.x() + layer->transform_origin().x(), |
| 207 layer->position().y() + parent_offset.y() + layer->transform_origin().y(), |
| 208 layer->transform_origin().z()); |
| 215 | 209 |
| 216 data_from_ancestor.transform_tree->UpdateScreenSpaceTransform(node->id); | 210 if (!layer->scroll_parent()) { |
| 211 node->data.scroll_offset = |
| 212 gfx::ScrollOffsetToVector2dF(layer->CurrentScrollOffset()); |
| 213 } |
| 214 |
| 215 node->data.local = layer->transform(); |
| 216 node->data.pre_local.Translate3d(-layer->transform_origin().x(), |
| 217 -layer->transform_origin().y(), |
| 218 -layer->transform_origin().z()); |
| 219 |
| 220 node->data.needs_local_transform_update = true; |
| 221 data_from_ancestor.transform_tree->UpdateTransforms(node->id); |
| 217 | 222 |
| 218 layer->set_offset_to_transform_parent(gfx::Vector2dF()); | 223 layer->set_offset_to_transform_parent(gfx::Vector2dF()); |
| 219 } | 224 } |
| 220 | 225 |
| 221 void BuildPropertyTreesInternal(Layer* layer, | 226 void BuildPropertyTreesInternal(Layer* layer, |
| 222 const DataForRecursion& data_from_parent) { | 227 const DataForRecursion& data_from_parent) { |
| 223 DataForRecursion data_for_children(data_from_parent); | 228 DataForRecursion data_for_children(data_from_parent); |
| 224 if (layer->render_surface()) | 229 if (layer->render_surface()) |
| 225 data_for_children.render_target = layer; | 230 data_for_children.render_target = layer; |
| 226 | 231 |
| 227 AddTransformNodeIfNeeded(data_from_parent, layer, &data_for_children); | 232 AddTransformNodeIfNeeded(data_from_parent, layer, &data_for_children); |
| 228 AddClipNodeIfNeeded(data_from_parent, layer, &data_for_children); | 233 AddClipNodeIfNeeded(data_from_parent, layer, &data_for_children); |
| 229 | 234 |
| 235 if (layer == data_from_parent.page_scale_layer) |
| 236 data_for_children.in_subtree_of_page_scale_application_layer = true; |
| 237 |
| 230 for (size_t i = 0; i < layer->children().size(); ++i) { | 238 for (size_t i = 0; i < layer->children().size(); ++i) { |
| 231 if (!layer->children()[i]->scroll_parent()) | 239 if (!layer->children()[i]->scroll_parent()) |
| 232 BuildPropertyTreesInternal(layer->children()[i].get(), data_for_children); | 240 BuildPropertyTreesInternal(layer->children()[i].get(), data_for_children); |
| 233 } | 241 } |
| 234 | 242 |
| 235 if (layer->scroll_children()) { | 243 if (layer->scroll_children()) { |
| 236 for (Layer* scroll_child : *layer->scroll_children()) { | 244 for (Layer* scroll_child : *layer->scroll_children()) { |
| 237 BuildPropertyTreesInternal(scroll_child, data_for_children); | 245 BuildPropertyTreesInternal(scroll_child, data_for_children); |
| 238 } | 246 } |
| 239 } | 247 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 256 DataForRecursion data_for_recursion; | 264 DataForRecursion data_for_recursion; |
| 257 data_for_recursion.transform_tree = transform_tree; | 265 data_for_recursion.transform_tree = transform_tree; |
| 258 data_for_recursion.clip_tree = clip_tree; | 266 data_for_recursion.clip_tree = clip_tree; |
| 259 data_for_recursion.transform_tree_parent = nullptr; | 267 data_for_recursion.transform_tree_parent = nullptr; |
| 260 data_for_recursion.transform_fixed_parent = nullptr; | 268 data_for_recursion.transform_fixed_parent = nullptr; |
| 261 data_for_recursion.render_target = root_layer; | 269 data_for_recursion.render_target = root_layer; |
| 262 data_for_recursion.clip_tree_parent = 0; | 270 data_for_recursion.clip_tree_parent = 0; |
| 263 data_for_recursion.page_scale_layer = page_scale_layer; | 271 data_for_recursion.page_scale_layer = page_scale_layer; |
| 264 data_for_recursion.page_scale_factor = page_scale_factor; | 272 data_for_recursion.page_scale_factor = page_scale_factor; |
| 265 data_for_recursion.device_scale_factor = device_scale_factor; | 273 data_for_recursion.device_scale_factor = device_scale_factor; |
| 266 | 274 data_for_recursion.in_subtree_of_page_scale_application_layer = false; |
| 267 int transform_root_id = transform_tree->Insert(TransformNode(), 0); | 275 data_for_recursion.device_transform = &device_transform; |
| 268 | 276 |
| 269 ClipNode root_clip; | 277 ClipNode root_clip; |
| 270 root_clip.data.clip = viewport; | 278 root_clip.data.clip = viewport; |
| 271 root_clip.data.transform_id = 0; | 279 root_clip.data.transform_id = 0; |
| 272 data_for_recursion.clip_tree_parent = clip_tree->Insert(root_clip, 0); | 280 data_for_recursion.clip_tree_parent = clip_tree->Insert(root_clip, 0); |
| 273 | |
| 274 BuildPropertyTreesInternal(root_layer, data_for_recursion); | 281 BuildPropertyTreesInternal(root_layer, data_for_recursion); |
| 275 | |
| 276 TransformNode* transform_root = transform_tree->Node(transform_root_id); | |
| 277 transform_root->data.set_to_parent(device_transform * | |
| 278 transform_root->data.to_parent); | |
| 279 } | 282 } |
| 280 | 283 |
| 281 } // namespace cc | 284 } // namespace cc |
| OLD | NEW |