OLD | NEW |
---|---|
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/layer_tree_host_common.h" | 5 #include "cc/trees/layer_tree_host_common.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 static gfx::Vector2dF GetEffectiveTotalScrollOffset(LayerType* layer) { | 56 static gfx::Vector2dF GetEffectiveTotalScrollOffset(LayerType* layer) { |
57 gfx::Vector2dF offset = layer->TotalScrollOffset(); | 57 gfx::Vector2dF offset = layer->TotalScrollOffset(); |
58 // The scroll parent's total scroll offset (scroll offset + scroll delta) | 58 // The scroll parent's total scroll offset (scroll offset + scroll delta) |
59 // can't be used because its scroll offset has already been applied to the | 59 // can't be used because its scroll offset has already been applied to the |
60 // scroll children's positions by the main thread layer positioning code. | 60 // scroll children's positions by the main thread layer positioning code. |
61 if (layer->scroll_parent()) | 61 if (layer->scroll_parent()) |
62 offset += layer->scroll_parent()->ScrollDelta(); | 62 offset += layer->scroll_parent()->ScrollDelta(); |
63 return offset; | 63 return offset; |
64 } | 64 } |
65 | 65 |
66 template <typename LayerType> | |
67 static inline bool LayerCanAcceptInput(LayerType* layer) { | |
68 return !layer->touch_event_handler_region().IsEmpty() || | |
69 layer->have_wheel_event_handlers(); | |
70 } | |
71 | |
66 inline gfx::Rect CalculateVisibleRectWithCachedLayerRect( | 72 inline gfx::Rect CalculateVisibleRectWithCachedLayerRect( |
67 gfx::Rect target_surface_rect, | 73 gfx::Rect target_surface_rect, |
68 gfx::Rect layer_bound_rect, | 74 gfx::Rect layer_bound_rect, |
69 gfx::Rect layer_rect_in_target_space, | 75 gfx::Rect layer_rect_in_target_space, |
70 const gfx::Transform& transform) { | 76 const gfx::Transform& transform) { |
71 if (layer_rect_in_target_space.IsEmpty()) | 77 if (layer_rect_in_target_space.IsEmpty()) |
72 return gfx::Rect(); | 78 return gfx::Rect(); |
73 | 79 |
74 // Is this layer fully contained within the target surface? | 80 // Is this layer fully contained within the target surface? |
75 if (target_surface_rect.Contains(layer_rect_in_target_space)) | 81 if (target_surface_rect.Contains(layer_rect_in_target_space)) |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
447 | 453 |
448 // The layer should not be drawn if (1) it is not double-sided and (2) the | 454 // The layer should not be drawn if (1) it is not double-sided and (2) the |
449 // back of the layer is known to be facing the screen. | 455 // back of the layer is known to be facing the screen. |
450 if (!backface_test_layer->double_sided() && | 456 if (!backface_test_layer->double_sided() && |
451 TransformToScreenIsKnown(backface_test_layer) && | 457 TransformToScreenIsKnown(backface_test_layer) && |
452 IsLayerBackFaceVisible(backface_test_layer)) | 458 IsLayerBackFaceVisible(backface_test_layer)) |
453 return true; | 459 return true; |
454 | 460 |
455 // The layer is visible to events. If it's subject to hit testing, then | 461 // The layer is visible to events. If it's subject to hit testing, then |
456 // we can't skip it. | 462 // we can't skip it. |
457 bool can_accept_input = !layer->touch_event_handler_region().IsEmpty() || | 463 if (!layer->DrawsContent() && !LayerCanAcceptInput(layer)) |
458 layer->have_wheel_event_handlers(); | |
459 if (!layer->DrawsContent() && !can_accept_input) | |
460 return true; | 464 return true; |
461 | 465 |
danakj
2013/10/07 16:29:13
Can you add skipping layers that have draw-opacity
sadrul
2013/10/07 17:16:49
I have updated the code here to look at layer->dra
danakj
2013/10/07 17:37:35
I meant that this function doesn't use draw proper
sadrul
2013/10/07 18:37:24
Ah, I see. Done. (needed both |accumulated_draw_op
danakj
2013/10/07 19:02:36
Oh right, inside a surface the opacity goes back t
| |
462 return false; | 466 return false; |
463 } | 467 } |
464 | 468 |
465 static inline bool SubtreeShouldBeSkipped(LayerImpl* layer, | 469 static inline bool SubtreeShouldBeSkipped(LayerImpl* layer, |
466 bool layer_is_visible) { | 470 bool layer_is_visible) { |
467 // When we need to do a readback/copy of a layer's output, we can not skip | 471 // When we need to do a readback/copy of a layer's output, we can not skip |
468 // it or any of its ancestors. | 472 // it or any of its ancestors. |
469 if (layer->draw_properties().layer_or_descendant_has_copy_request) | 473 if (layer->draw_properties().layer_or_descendant_has_copy_request) |
470 return false; | 474 return false; |
471 | 475 |
472 // If the layer is not visible, then skip it and its subtree. | 476 // If the layer is not visible, then skip it and its subtree. |
473 if (!layer_is_visible) | 477 if (!layer_is_visible) |
474 return true; | 478 return true; |
475 | 479 |
476 // If layer is on the pending tree and opacity is being animated then | 480 // If layer is on the pending tree and opacity is being animated then |
477 // this subtree can't be skipped as we need to create, prioritize and | 481 // this subtree can't be skipped as we need to create, prioritize and |
478 // include tiles for this layer when deciding if tree can be activated. | 482 // include tiles for this layer when deciding if tree can be activated. |
479 if (layer->layer_tree_impl()->IsPendingTree() && layer->OpacityIsAnimating()) | 483 if (layer->layer_tree_impl()->IsPendingTree() && layer->OpacityIsAnimating()) |
480 return false; | 484 return false; |
481 | 485 |
482 // The opacity of a layer always applies to its children (either implicitly | 486 // The opacity of a layer always applies to its children (either implicitly |
483 // via a render surface or explicitly if the parent preserves 3D), so the | 487 // via a render surface or explicitly if the parent preserves 3D), so the |
484 // entire subtree can be skipped if this layer is fully transparent. | 488 // entire subtree can be skipped if this layer is fully transparent, and none |
485 // TODO(sad): Don't skip layers used for hit testing crbug.com/295295. | 489 // of layers in the subtree has event handlers. |
486 return !layer->opacity(); | 490 return !layer->opacity() && |
491 !layer->draw_properties().layer_or_descendant_has_event_handler; | |
487 } | 492 } |
488 | 493 |
489 static inline bool SubtreeShouldBeSkipped(Layer* layer, | 494 static inline bool SubtreeShouldBeSkipped(Layer* layer, |
490 bool layer_is_visible) { | 495 bool layer_is_visible) { |
491 // When we need to do a readback/copy of a layer's output, we can not skip | 496 // When we need to do a readback/copy of a layer's output, we can not skip |
492 // it or any of its ancestors. | 497 // it or any of its ancestors. |
493 if (layer->draw_properties().layer_or_descendant_has_copy_request) | 498 if (layer->draw_properties().layer_or_descendant_has_copy_request) |
494 return false; | 499 return false; |
495 | 500 |
496 // If the layer is not visible, then skip it and its subtree. | 501 // If the layer is not visible, then skip it and its subtree. |
497 if (!layer_is_visible) | 502 if (!layer_is_visible) |
498 return true; | 503 return true; |
499 | 504 |
500 // If the opacity is being animated then the opacity on the main thread is | 505 // If the opacity is being animated then the opacity on the main thread is |
501 // unreliable (since the impl thread may be using a different opacity), so it | 506 // unreliable (since the impl thread may be using a different opacity), so it |
502 // should not be trusted. | 507 // should not be trusted. |
503 // In particular, it should not cause the subtree to be skipped. | 508 // In particular, it should not cause the subtree to be skipped. |
504 // Similarly, for layers that might animate opacity using an impl-only | 509 // Similarly, for layers that might animate opacity using an impl-only |
505 // animation, their subtree should also not be skipped. | 510 // animation, their subtree should also not be skipped. |
506 // TODO(sad): Don't skip layers used for hit testing crbug.com/295295. | |
507 return !layer->opacity() && !layer->OpacityIsAnimating() && | 511 return !layer->opacity() && !layer->OpacityIsAnimating() && |
508 !layer->OpacityCanAnimateOnImplThread(); | 512 !layer->OpacityCanAnimateOnImplThread() && |
513 !layer->draw_properties().layer_or_descendant_has_event_handler; | |
509 } | 514 } |
510 | 515 |
511 // Called on each layer that could be drawn after all information from | 516 // Called on each layer that could be drawn after all information from |
512 // CalcDrawProperties has been updated on that layer. May have some false | 517 // CalcDrawProperties has been updated on that layer. May have some false |
513 // positives (e.g. layers get this called on them but don't actually get drawn). | 518 // positives (e.g. layers get this called on them but don't actually get drawn). |
514 static inline void UpdateTilePrioritiesForLayer(LayerImpl* layer) { | 519 static inline void UpdateTilePrioritiesForLayer(LayerImpl* layer) { |
515 layer->UpdateTilePriorities(); | 520 layer->UpdateTilePriorities(); |
516 | 521 |
517 // Mask layers don't get this call, so explicitly update them so they can | 522 // Mask layers don't get this call, so explicitly update them so they can |
518 // kick off tile rasterization. | 523 // kick off tile rasterization. |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1007 render_surface_layer_list->back()->ClearRenderSurface(); | 1012 render_surface_layer_list->back()->ClearRenderSurface(); |
1008 render_surface_layer_list->pop_back(); | 1013 render_surface_layer_list->pop_back(); |
1009 } | 1014 } |
1010 DCHECK_EQ(render_surface_layer_list->back(), layer_to_remove); | 1015 DCHECK_EQ(render_surface_layer_list->back(), layer_to_remove); |
1011 render_surface_layer_list->pop_back(); | 1016 render_surface_layer_list->pop_back(); |
1012 layer_to_remove->ClearRenderSurface(); | 1017 layer_to_remove->ClearRenderSurface(); |
1013 } | 1018 } |
1014 | 1019 |
1015 struct PreCalculateMetaInformationRecursiveData { | 1020 struct PreCalculateMetaInformationRecursiveData { |
1016 bool layer_or_descendant_has_copy_request; | 1021 bool layer_or_descendant_has_copy_request; |
1022 bool layer_or_descendant_has_event_handler; | |
1017 int num_unclipped_descendants; | 1023 int num_unclipped_descendants; |
1018 | 1024 |
1019 PreCalculateMetaInformationRecursiveData() | 1025 PreCalculateMetaInformationRecursiveData() |
1020 : layer_or_descendant_has_copy_request(false), | 1026 : layer_or_descendant_has_copy_request(false), |
1027 layer_or_descendant_has_event_handler(false), | |
1021 num_unclipped_descendants(0) {} | 1028 num_unclipped_descendants(0) {} |
1022 | 1029 |
1023 void Merge(const PreCalculateMetaInformationRecursiveData& data) { | 1030 void Merge(const PreCalculateMetaInformationRecursiveData& data) { |
1024 layer_or_descendant_has_copy_request |= | 1031 layer_or_descendant_has_copy_request |= |
1025 data.layer_or_descendant_has_copy_request; | 1032 data.layer_or_descendant_has_copy_request; |
1033 layer_or_descendant_has_event_handler |= | |
1034 data.layer_or_descendant_has_event_handler; | |
1026 num_unclipped_descendants += | 1035 num_unclipped_descendants += |
1027 data.num_unclipped_descendants; | 1036 data.num_unclipped_descendants; |
1028 } | 1037 } |
1029 }; | 1038 }; |
1030 | 1039 |
1031 // Recursively walks the layer tree to compute any information that is needed | 1040 // Recursively walks the layer tree to compute any information that is needed |
1032 // before doing the main recursion. | 1041 // before doing the main recursion. |
1033 template <typename LayerType> | 1042 template <typename LayerType> |
1034 static void PreCalculateMetaInformation( | 1043 static void PreCalculateMetaInformation( |
1035 LayerType* layer, | 1044 LayerType* layer, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1077 | 1086 |
1078 if (layer->clip_children()) { | 1087 if (layer->clip_children()) { |
1079 int num_clip_children = layer->clip_children()->size(); | 1088 int num_clip_children = layer->clip_children()->size(); |
1080 DCHECK_GE(recursive_data->num_unclipped_descendants, num_clip_children); | 1089 DCHECK_GE(recursive_data->num_unclipped_descendants, num_clip_children); |
1081 recursive_data->num_unclipped_descendants -= num_clip_children; | 1090 recursive_data->num_unclipped_descendants -= num_clip_children; |
1082 } | 1091 } |
1083 | 1092 |
1084 if (layer->HasCopyRequest()) | 1093 if (layer->HasCopyRequest()) |
1085 recursive_data->layer_or_descendant_has_copy_request = true; | 1094 recursive_data->layer_or_descendant_has_copy_request = true; |
1086 | 1095 |
1096 if (LayerCanAcceptInput(layer)) | |
1097 recursive_data->layer_or_descendant_has_event_handler = true; | |
1098 | |
1087 layer->draw_properties().num_descendants_that_draw_content = | 1099 layer->draw_properties().num_descendants_that_draw_content = |
1088 num_descendants_that_draw_content; | 1100 num_descendants_that_draw_content; |
1089 layer->draw_properties().num_unclipped_descendants = | 1101 layer->draw_properties().num_unclipped_descendants = |
1090 recursive_data->num_unclipped_descendants; | 1102 recursive_data->num_unclipped_descendants; |
1091 layer->draw_properties().descendants_can_clip_selves = | 1103 layer->draw_properties().descendants_can_clip_selves = |
1092 descendants_can_clip_selves; | 1104 descendants_can_clip_selves; |
1093 layer->draw_properties().layer_or_descendant_has_copy_request = | 1105 layer->draw_properties().layer_or_descendant_has_copy_request = |
1094 recursive_data->layer_or_descendant_has_copy_request; | 1106 recursive_data->layer_or_descendant_has_copy_request; |
1107 layer->draw_properties().layer_or_descendant_has_event_handler = | |
1108 recursive_data->layer_or_descendant_has_event_handler; | |
1095 } | 1109 } |
1096 | 1110 |
1097 static void RoundTranslationComponents(gfx::Transform* transform) { | 1111 static void RoundTranslationComponents(gfx::Transform* transform) { |
1098 transform->matrix().set(0, 3, MathUtil::Round(transform->matrix().get(0, 3))); | 1112 transform->matrix().set(0, 3, MathUtil::Round(transform->matrix().get(0, 3))); |
1099 transform->matrix().set(1, 3, MathUtil::Round(transform->matrix().get(1, 3))); | 1113 transform->matrix().set(1, 3, MathUtil::Round(transform->matrix().get(1, 3))); |
1100 } | 1114 } |
1101 | 1115 |
1102 template <typename LayerType> | 1116 template <typename LayerType> |
1103 struct SubtreeGlobals { | 1117 struct SubtreeGlobals { |
1104 LayerSorter* layer_sorter; | 1118 LayerSorter* layer_sorter; |
(...skipping 1141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2246 // At this point, we think the point does hit the touch event handler region | 2260 // At this point, we think the point does hit the touch event handler region |
2247 // on the layer, but we need to walk up the parents to ensure that the layer | 2261 // on the layer, but we need to walk up the parents to ensure that the layer |
2248 // was not clipped in such a way that the hit point actually should not hit | 2262 // was not clipped in such a way that the hit point actually should not hit |
2249 // the layer. | 2263 // the layer. |
2250 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl)) | 2264 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl)) |
2251 return false; | 2265 return false; |
2252 | 2266 |
2253 return true; | 2267 return true; |
2254 } | 2268 } |
2255 } // namespace cc | 2269 } // namespace cc |
OLD | NEW |