| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
| 10 #include "cc/layers/layer.h" | 10 #include "cc/layers/layer.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 template <typename LayerType> | 130 template <typename LayerType> |
| 131 static bool IsRootLayerOfNewRenderingContext(LayerType* layer) { | 131 static bool IsRootLayerOfNewRenderingContext(LayerType* layer) { |
| 132 if (layer->parent()) | 132 if (layer->parent()) |
| 133 return !layer->parent()->Is3dSorted() && layer->Is3dSorted(); | 133 return !layer->parent()->Is3dSorted() && layer->Is3dSorted(); |
| 134 return layer->Is3dSorted(); | 134 return layer->Is3dSorted(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 template <typename LayerType> | 137 template <typename LayerType> |
| 138 static inline bool LayerIsInExisting3DRenderingContext(LayerType* layer) { | 138 static inline bool LayerIsInExisting3DRenderingContext(LayerType* layer) { |
| 139 return layer->Is3dSorted() && layer->parent() && | 139 return layer->Is3dSorted() && layer->parent() && |
| 140 layer->parent()->Is3dSorted(); | 140 layer->parent()->Is3dSorted() && |
| 141 layer->parent()->sorting_context_id() == layer->sorting_context_id(); |
| 141 } | 142 } |
| 142 | 143 |
| 143 template <typename LayerType> | 144 template <typename LayerType> |
| 144 static bool TransformToScreenIsKnown(LayerType* layer, | 145 static bool TransformToScreenIsKnown(LayerType* layer, |
| 145 const TransformTree& tree) { | 146 const TransformTree& tree) { |
| 146 const TransformNode* node = tree.Node(layer->transform_tree_index()); | 147 const TransformNode* node = tree.Node(layer->transform_tree_index()); |
| 147 return !node->data.to_screen_is_animated; | 148 return !node->data.to_screen_is_animated; |
| 148 } | 149 } |
| 149 | 150 |
| 150 template <typename LayerType> | 151 template <typename LayerType> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 163 | 164 |
| 164 if (LayerIsInExisting3DRenderingContext(layer)) | 165 if (LayerIsInExisting3DRenderingContext(layer)) |
| 165 return DrawTransformFromPropertyTrees(layer, tree).IsBackFaceVisible(); | 166 return DrawTransformFromPropertyTrees(layer, tree).IsBackFaceVisible(); |
| 166 | 167 |
| 167 // In this case, either the layer establishes a new 3d rendering context, or | 168 // In this case, either the layer establishes a new 3d rendering context, or |
| 168 // is not in a 3d rendering context at all. | 169 // is not in a 3d rendering context at all. |
| 169 return layer->transform().IsBackFaceVisible(); | 170 return layer->transform().IsBackFaceVisible(); |
| 170 } | 171 } |
| 171 | 172 |
| 172 template <typename LayerType> | 173 template <typename LayerType> |
| 174 static bool IsSurfaceBackFaceVisible(LayerType* layer, |
| 175 const TransformTree& tree) { |
| 176 if (LayerIsInExisting3DRenderingContext(layer)) { |
| 177 const TransformNode* node = tree.Node(layer->transform_tree_index()); |
| 178 // Draw transform as a contributing render surface. |
| 179 // TODO(enne): we shouldn't walk the tree during a tree walk. |
| 180 gfx::Transform surface_draw_transform; |
| 181 tree.ComputeTransform(node->id, node->data.target_id, |
| 182 &surface_draw_transform); |
| 183 return surface_draw_transform.IsBackFaceVisible(); |
| 184 } |
| 185 |
| 186 if (IsRootLayerOfNewRenderingContext(layer)) |
| 187 return layer->transform().IsBackFaceVisible(); |
| 188 |
| 189 // If the render_surface is not part of a new or existing rendering context, |
| 190 // then the layers that contribute to this surface will decide back-face |
| 191 // visibility for themselves. |
| 192 return false; |
| 193 } |
| 194 |
| 195 template <typename LayerType> |
| 173 static bool IsAnimatingTransformToScreen(LayerType* layer, | 196 static bool IsAnimatingTransformToScreen(LayerType* layer, |
| 174 const TransformTree& tree) { | 197 const TransformTree& tree) { |
| 175 const TransformNode* node = tree.Node(layer->transform_tree_index()); | 198 const TransformNode* node = tree.Node(layer->transform_tree_index()); |
| 176 return node->data.to_screen_is_animated; | 199 return node->data.to_screen_is_animated; |
| 177 } | 200 } |
| 178 | 201 |
| 179 static inline bool TransformToScreenIsKnown(Layer* layer, | 202 static inline bool TransformToScreenIsKnown(Layer* layer, |
| 180 const TransformTree& tree) { | 203 const TransformTree& tree) { |
| 181 return !IsAnimatingTransformToScreen(layer, tree); | 204 return !IsAnimatingTransformToScreen(layer, tree); |
| 182 } | 205 } |
| 183 | 206 |
| 184 static inline bool TransformToScreenIsKnown(LayerImpl* layer, | 207 static inline bool TransformToScreenIsKnown(LayerImpl* layer, |
| 185 const TransformTree& tree) { | 208 const TransformTree& tree) { |
| 186 return true; | 209 return true; |
| 187 } | 210 } |
| 188 | 211 |
| 189 template <typename LayerType> | 212 template <typename LayerType> |
| 190 static bool HasInvertibleOrAnimatedTransform(LayerType* layer) { | 213 static bool HasInvertibleOrAnimatedTransform(LayerType* layer) { |
| 191 return layer->transform_is_invertible() || layer->TransformIsAnimating(); | 214 return layer->transform_is_invertible() || layer->TransformIsAnimating(); |
| 192 } | 215 } |
| 193 | 216 |
| 194 static inline bool SubtreeShouldBeSkipped(LayerImpl* layer, | 217 static inline bool SubtreeShouldBeSkipped(LayerImpl* layer, |
| 195 bool layer_is_drawn) { | 218 bool layer_is_drawn, |
| 219 const TransformTree& tree) { |
| 196 // If the layer transform is not invertible, it should not be drawn. | 220 // If the layer transform is not invertible, it should not be drawn. |
| 197 // TODO(ajuma): Correctly process subtrees with singular transform for the | 221 // TODO(ajuma): Correctly process subtrees with singular transform for the |
| 198 // case where we may animate to a non-singular transform and wish to | 222 // case where we may animate to a non-singular transform and wish to |
| 199 // pre-raster. | 223 // pre-raster. |
| 200 if (!HasInvertibleOrAnimatedTransform(layer)) | 224 if (!HasInvertibleOrAnimatedTransform(layer)) |
| 201 return true; | 225 return true; |
| 202 | 226 |
| 203 // When we need to do a readback/copy of a layer's output, we can not skip | 227 // When we need to do a readback/copy of a layer's output, we can not skip |
| 204 // it or any of its ancestors. | 228 // it or any of its ancestors. |
| 205 if (layer->draw_properties().layer_or_descendant_has_copy_request) | 229 if (layer->draw_properties().layer_or_descendant_has_copy_request) |
| 206 return false; | 230 return false; |
| 207 | 231 |
| 208 // We cannot skip the the subtree if a descendant has a wheel or touch handler | 232 // We cannot skip the the subtree if a descendant has a wheel or touch handler |
| 209 // or the hit testing code will break (it requires fresh transforms, etc). | 233 // or the hit testing code will break (it requires fresh transforms, etc). |
| 210 if (layer->draw_properties().layer_or_descendant_has_input_handler) | 234 if (layer->draw_properties().layer_or_descendant_has_input_handler) |
| 211 return false; | 235 return false; |
| 212 | 236 |
| 213 // If the layer is not drawn, then skip it and its subtree. | 237 // If the layer is not drawn, then skip it and its subtree. |
| 214 if (!layer_is_drawn) | 238 if (!layer_is_drawn) |
| 215 return true; | 239 return true; |
| 216 | 240 |
| 241 if (layer->render_surface() && !layer->double_sided() && |
| 242 IsSurfaceBackFaceVisible(layer, tree)) |
| 243 return true; |
| 244 |
| 217 // If layer is on the pending tree and opacity is being animated then | 245 // If layer is on the pending tree and opacity is being animated then |
| 218 // this subtree can't be skipped as we need to create, prioritize and | 246 // this subtree can't be skipped as we need to create, prioritize and |
| 219 // include tiles for this layer when deciding if tree can be activated. | 247 // include tiles for this layer when deciding if tree can be activated. |
| 220 if (layer->layer_tree_impl()->IsPendingTree() && layer->OpacityIsAnimating()) | 248 if (layer->layer_tree_impl()->IsPendingTree() && layer->OpacityIsAnimating()) |
| 221 return false; | 249 return false; |
| 222 | 250 |
| 223 // The opacity of a layer always applies to its children (either implicitly | 251 // The opacity of a layer always applies to its children (either implicitly |
| 224 // via a render surface or explicitly if the parent preserves 3D), so the | 252 // via a render surface or explicitly if the parent preserves 3D), so the |
| 225 // entire subtree can be skipped if this layer is fully transparent. | 253 // entire subtree can be skipped if this layer is fully transparent. |
| 226 return !layer->opacity(); | 254 return !layer->opacity(); |
| 227 } | 255 } |
| 228 | 256 |
| 229 static inline bool SubtreeShouldBeSkipped(Layer* layer, bool layer_is_drawn) { | 257 static inline bool SubtreeShouldBeSkipped(Layer* layer, |
| 258 bool layer_is_drawn, |
| 259 const TransformTree& tree) { |
| 230 // If the layer transform is not invertible, it should not be drawn. | 260 // If the layer transform is not invertible, it should not be drawn. |
| 231 if (!layer->transform_is_invertible() && !layer->TransformIsAnimating()) | 261 if (!layer->transform_is_invertible() && !layer->TransformIsAnimating()) |
| 232 return true; | 262 return true; |
| 233 | 263 |
| 234 // When we need to do a readback/copy of a layer's output, we can not skip | 264 // When we need to do a readback/copy of a layer's output, we can not skip |
| 235 // it or any of its ancestors. | 265 // it or any of its ancestors. |
| 236 if (layer->draw_properties().layer_or_descendant_has_copy_request) | 266 if (layer->draw_properties().layer_or_descendant_has_copy_request) |
| 237 return false; | 267 return false; |
| 238 | 268 |
| 239 // We cannot skip the the subtree if a descendant has a wheel or touch handler | 269 // We cannot skip the the subtree if a descendant has a wheel or touch handler |
| 240 // or the hit testing code will break (it requires fresh transforms, etc). | 270 // or the hit testing code will break (it requires fresh transforms, etc). |
| 241 if (layer->draw_properties().layer_or_descendant_has_input_handler) | 271 if (layer->draw_properties().layer_or_descendant_has_input_handler) |
| 242 return false; | 272 return false; |
| 243 | 273 |
| 244 // If the layer is not drawn, then skip it and its subtree. | 274 // If the layer is not drawn, then skip it and its subtree. |
| 245 if (!layer_is_drawn) | 275 if (!layer_is_drawn) |
| 246 return true; | 276 return true; |
| 247 | 277 |
| 278 if (layer->render_surface() && !layer->double_sided() && |
| 279 !layer->TransformIsAnimating() && IsSurfaceBackFaceVisible(layer, tree)) |
| 280 return true; |
| 281 |
| 248 // If the opacity is being animated then the opacity on the main thread is | 282 // If the opacity is being animated then the opacity on the main thread is |
| 249 // unreliable (since the impl thread may be using a different opacity), so it | 283 // unreliable (since the impl thread may be using a different opacity), so it |
| 250 // should not be trusted. | 284 // should not be trusted. |
| 251 // In particular, it should not cause the subtree to be skipped. | 285 // In particular, it should not cause the subtree to be skipped. |
| 252 // Similarly, for layers that might animate opacity using an impl-only | 286 // Similarly, for layers that might animate opacity using an impl-only |
| 253 // animation, their subtree should also not be skipped. | 287 // animation, their subtree should also not be skipped. |
| 254 return !layer->opacity() && !layer->OpacityIsAnimating() && | 288 return !layer->opacity() && !layer->OpacityIsAnimating() && |
| 255 !layer->OpacityCanAnimateOnImplThread(); | 289 !layer->OpacityCanAnimateOnImplThread(); |
| 256 } | 290 } |
| 257 | 291 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 void FindLayersThatNeedUpdates( | 336 void FindLayersThatNeedUpdates( |
| 303 LayerType* layer, | 337 LayerType* layer, |
| 304 const TransformTree& tree, | 338 const TransformTree& tree, |
| 305 bool subtree_is_visible_from_ancestor, | 339 bool subtree_is_visible_from_ancestor, |
| 306 typename LayerType::LayerListType* update_layer_list, | 340 typename LayerType::LayerListType* update_layer_list, |
| 307 std::vector<LayerType*>* visible_layer_list) { | 341 std::vector<LayerType*>* visible_layer_list) { |
| 308 bool layer_is_drawn = | 342 bool layer_is_drawn = |
| 309 layer->HasCopyRequest() || | 343 layer->HasCopyRequest() || |
| 310 (subtree_is_visible_from_ancestor && !layer->hide_layer_and_subtree()); | 344 (subtree_is_visible_from_ancestor && !layer->hide_layer_and_subtree()); |
| 311 | 345 |
| 312 if (layer->parent() && SubtreeShouldBeSkipped(layer, layer_is_drawn)) | 346 if (layer->parent() && SubtreeShouldBeSkipped(layer, layer_is_drawn, tree)) |
| 313 return; | 347 return; |
| 314 | 348 |
| 315 if (!LayerShouldBeSkipped(layer, layer_is_drawn, tree)) { | 349 if (!LayerShouldBeSkipped(layer, layer_is_drawn, tree)) { |
| 316 visible_layer_list->push_back(layer); | 350 visible_layer_list->push_back(layer); |
| 317 update_layer_list->push_back(layer); | 351 update_layer_list->push_back(layer); |
| 318 } | 352 } |
| 319 | 353 |
| 320 // Append mask layers to the update layer list. They don't have valid visible | 354 // Append mask layers to the update layer list. They don't have valid visible |
| 321 // rects, so need to get added after the above calculation. Replica layers | 355 // rects, so need to get added after the above calculation. Replica layers |
| 322 // don't need to be updated. | 356 // don't need to be updated. |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 if (static_cast<int>(layer->offset_to_transform_parent().x()) != | 660 if (static_cast<int>(layer->offset_to_transform_parent().x()) != |
| 627 layer->offset_to_transform_parent().x()) | 661 layer->offset_to_transform_parent().x()) |
| 628 return false; | 662 return false; |
| 629 if (static_cast<int>(layer->offset_to_transform_parent().y()) != | 663 if (static_cast<int>(layer->offset_to_transform_parent().y()) != |
| 630 layer->offset_to_transform_parent().y()) | 664 layer->offset_to_transform_parent().y()) |
| 631 return false; | 665 return false; |
| 632 return true; | 666 return true; |
| 633 } | 667 } |
| 634 | 668 |
| 635 } // namespace cc | 669 } // namespace cc |
| OLD | NEW |