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/draw_property_utils.h" | 5 #include "cc/trees/draw_property_utils.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 } else { | 197 } else { |
198 layer->set_visible_rect_from_property_trees(gfx::Rect(layer_bounds)); | 198 layer->set_visible_rect_from_property_trees(gfx::Rect(layer_bounds)); |
199 // As the layer is unclipped, the clip rect in target space of this layer | 199 // As the layer is unclipped, the clip rect in target space of this layer |
200 // is not used. So, we set it to an empty rect. | 200 // is not used. So, we set it to an empty rect. |
201 layer->set_clip_rect_in_target_space_from_property_trees(gfx::Rect()); | 201 layer->set_clip_rect_in_target_space_from_property_trees(gfx::Rect()); |
202 } | 202 } |
203 } | 203 } |
204 } | 204 } |
205 | 205 |
206 template <typename LayerType> | 206 template <typename LayerType> |
207 static bool IsRootLayerOfNewRenderingContext(LayerType* layer) { | |
208 if (layer->parent()) | |
209 return !layer->parent()->Is3dSorted() && layer->Is3dSorted(); | |
210 return layer->Is3dSorted(); | |
211 } | |
212 | |
213 template <typename LayerType> | |
214 static inline bool LayerIsInExisting3DRenderingContext(LayerType* layer) { | |
215 return layer->Is3dSorted() && layer->parent() && | |
216 layer->parent()->Is3dSorted() && | |
217 layer->parent()->sorting_context_id() == layer->sorting_context_id(); | |
218 } | |
219 | |
220 template <typename LayerType> | |
221 static bool TransformToScreenIsKnown(LayerType* layer, | 207 static bool TransformToScreenIsKnown(LayerType* layer, |
222 const TransformTree& tree) { | 208 const TransformTree& tree) { |
223 const TransformNode* node = tree.Node(layer->transform_tree_index()); | 209 const TransformNode* node = tree.Node(layer->transform_tree_index()); |
224 return !node->data.to_screen_is_animated; | 210 return !node->data.to_screen_is_animated; |
225 } | 211 } |
226 | 212 |
227 template <typename LayerType> | 213 template <typename LayerType> |
228 static bool HasSingularTransform(LayerType* layer, const TransformTree& tree) { | 214 static bool HasSingularTransform(LayerType* layer, const TransformTree& tree) { |
229 const TransformNode* node = tree.Node(layer->transform_tree_index()); | 215 const TransformNode* node = tree.Node(layer->transform_tree_index()); |
230 return !node->data.is_invertible || !node->data.ancestors_are_invertible; | 216 return !node->data.is_invertible || !node->data.ancestors_are_invertible; |
231 } | 217 } |
232 | 218 |
233 template <typename LayerType> | 219 template <typename LayerType> |
234 static bool IsLayerBackFaceVisible(LayerType* layer, | 220 static bool IsLayerBackFaceVisible(LayerType* layer, |
235 const TransformTree& tree) { | 221 const TransformTree& tree) { |
236 // A layer with singular transform is not drawn. So, we can assume that its | 222 // A layer with singular transform is not drawn. So, we can assume that its |
237 // backface is not visible. | 223 // backface is not visible. |
238 if (HasSingularTransform(layer, tree)) | 224 if (HasSingularTransform(layer, tree)) |
239 return false; | 225 return false; |
240 // The current W3C spec on CSS transforms says that backface visibility should | 226 // The current W3C spec on CSS transforms says that backface visibility should |
241 // be determined differently depending on whether the layer is in a "3d | 227 // be determined differently depending on whether the layer is in a "3d |
242 // rendering context" or not. For Chromium code, we can determine whether we | 228 // rendering context" or not. For Chromium code, we can determine whether we |
243 // are in a 3d rendering context by checking if the parent preserves 3d. | 229 // are in a 3d rendering context by checking if the parent preserves 3d. |
244 | 230 |
245 if (LayerIsInExisting3DRenderingContext(layer)) | 231 const TransformNode* node = tree.Node(layer->transform_tree_index()); |
| 232 const TransformNode* parent_node = tree.parent(node); |
| 233 const bool is_3d_sorted = (node->data.sorting_context_id != 0); |
| 234 const bool no_transfrom_node_created = (layer->id() != node->owner_id); |
| 235 const bool parent_also_in_same_rendering_context = |
| 236 parent_node && |
| 237 parent_node->data.sorting_context_id == node->data.sorting_context_id; |
| 238 if (is_3d_sorted && |
| 239 (no_transfrom_node_created || parent_also_in_same_rendering_context)) { |
246 return DrawTransformFromPropertyTrees(layer, tree).IsBackFaceVisible(); | 240 return DrawTransformFromPropertyTrees(layer, tree).IsBackFaceVisible(); |
| 241 } |
247 | 242 |
248 // In this case, either the layer establishes a new 3d rendering context, or | 243 // In this case, either the layer establishes a new 3d rendering context, or |
249 // is not in a 3d rendering context at all. | 244 // is not in a 3d rendering context at all. |
250 return layer->transform().IsBackFaceVisible(); | 245 return layer->transform().IsBackFaceVisible(); |
251 } | 246 } |
252 | 247 |
253 template <typename LayerType> | 248 template <typename LayerType> |
254 static bool IsSurfaceBackFaceVisible(LayerType* layer, | 249 static bool IsSurfaceBackFaceVisible(LayerType* layer, |
255 const TransformTree& tree) { | 250 const TransformTree& tree) { |
256 if (HasSingularTransform(layer, tree)) | 251 if (HasSingularTransform(layer, tree)) |
257 return false; | 252 return false; |
258 if (LayerIsInExisting3DRenderingContext(layer)) { | 253 const TransformNode* node = tree.Node(layer->transform_tree_index()); |
259 const TransformNode* node = tree.Node(layer->transform_tree_index()); | 254 // If the render_surface is not part of a new or existing rendering context, |
| 255 // then the layers that contribute to this surface will decide back-face |
| 256 // visibility for themselves. |
| 257 if (!node->data.sorting_context_id) |
| 258 return false; |
| 259 |
| 260 const TransformNode* parent_node = tree.parent(node); |
| 261 if (parent_node && |
| 262 parent_node->data.sorting_context_id == node->data.sorting_context_id) { |
260 // Draw transform as a contributing render surface. | 263 // Draw transform as a contributing render surface. |
261 // TODO(enne): we shouldn't walk the tree during a tree walk. | 264 // TODO(enne): we shouldn't walk the tree during a tree walk. |
262 gfx::Transform surface_draw_transform; | 265 gfx::Transform surface_draw_transform; |
263 tree.ComputeTransform(node->id, node->data.target_id, | 266 tree.ComputeTransform(node->id, node->data.target_id, |
264 &surface_draw_transform); | 267 &surface_draw_transform); |
265 return surface_draw_transform.IsBackFaceVisible(); | 268 return surface_draw_transform.IsBackFaceVisible(); |
266 } | 269 } |
267 | 270 |
268 if (IsRootLayerOfNewRenderingContext(layer)) | 271 // We use layer's transform to determine back face visibility when its the |
269 return layer->transform().IsBackFaceVisible(); | 272 // root of a new rendering context. |
270 | 273 return layer->transform().IsBackFaceVisible(); |
271 // If the render_surface is not part of a new or existing rendering context, | |
272 // then the layers that contribute to this surface will decide back-face | |
273 // visibility for themselves. | |
274 return false; | |
275 } | 274 } |
276 | 275 |
277 template <typename LayerType> | 276 template <typename LayerType> |
278 static bool IsAnimatingTransformToScreen(LayerType* layer, | 277 static bool IsAnimatingTransformToScreen(LayerType* layer, |
279 const TransformTree& tree) { | 278 const TransformTree& tree) { |
280 const TransformNode* node = tree.Node(layer->transform_tree_index()); | 279 const TransformNode* node = tree.Node(layer->transform_tree_index()); |
281 return node->data.to_screen_is_animated; | 280 return node->data.to_screen_is_animated; |
282 } | 281 } |
283 | 282 |
284 static inline bool TransformToScreenIsKnown(Layer* layer, | 283 static inline bool TransformToScreenIsKnown(Layer* layer, |
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 | 1176 |
1178 void UpdateElasticOverscrollInPropertyTrees( | 1177 void UpdateElasticOverscrollInPropertyTrees( |
1179 PropertyTrees* property_trees, | 1178 PropertyTrees* property_trees, |
1180 const Layer* overscroll_elasticity_layer, | 1179 const Layer* overscroll_elasticity_layer, |
1181 const gfx::Vector2dF& elastic_overscroll) { | 1180 const gfx::Vector2dF& elastic_overscroll) { |
1182 UpdateElasticOverscrollInPropertyTreesInternal( | 1181 UpdateElasticOverscrollInPropertyTreesInternal( |
1183 property_trees, overscroll_elasticity_layer, elastic_overscroll); | 1182 property_trees, overscroll_elasticity_layer, elastic_overscroll); |
1184 } | 1183 } |
1185 | 1184 |
1186 } // namespace cc | 1185 } // namespace cc |
OLD | NEW |