Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: cc/trees/layer_tree_host_common.cc

Issue 26112002: cc: Fix hit-testing in zero-opacity layers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/layers/draw_properties.h ('k') | cc/trees/layer_tree_host_common_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 backface_test_layer = layer->parent(); 451 backface_test_layer = layer->parent();
446 } 452 }
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 // A layer cannot be skipped if it is subject to hit-testing.
456 // we can't skip it. 462 if (LayerCanAcceptInput(layer))
457 bool can_accept_input = !layer->touch_event_handler_region().IsEmpty() || 463 return false;
458 layer->have_wheel_event_handlers(); 464
459 if (!layer->DrawsContent() && !can_accept_input) 465 if (!layer->DrawsContent())
460 return true; 466 return true;
461 467
462 return false; 468 return !layer->draw_opacity() && !layer->draw_opacity_is_animating();
enne (OOO) 2013/10/07 17:27:23 I'm not sure this is adequate. If you have: -A
danakj 2013/10/07 17:37:35 Can you make this a if () return true; and keep re
danakj 2013/10/07 17:37:35 PictureLayerImpl should probably consider its draw
enne (OOO) 2013/10/07 17:45:51 It's more than that. What if you've set a subtree
sadrul 2013/10/07 18:37:24 Done.
sadrul 2013/10/07 18:37:24 I am going through the code to completely grok thi
463 } 469 }
464 470
465 static inline bool SubtreeShouldBeSkipped(LayerImpl* layer, 471 static inline bool SubtreeShouldBeSkipped(LayerImpl* layer,
466 bool layer_is_visible) { 472 bool layer_is_visible) {
467 // When we need to do a readback/copy of a layer's output, we can not skip 473 // When we need to do a readback/copy of a layer's output, we can not skip
468 // it or any of its ancestors. 474 // it or any of its ancestors.
469 if (layer->draw_properties().layer_or_descendant_has_copy_request) 475 if (layer->draw_properties().layer_or_descendant_has_copy_request)
470 return false; 476 return false;
471 477
472 // If the layer is not visible, then skip it and its subtree. 478 // If the layer is not visible, then skip it and its subtree.
473 if (!layer_is_visible) 479 if (!layer_is_visible)
474 return true; 480 return true;
475 481
476 // If layer is on the pending tree and opacity is being animated then 482 // 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 483 // 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. 484 // include tiles for this layer when deciding if tree can be activated.
479 if (layer->layer_tree_impl()->IsPendingTree() && layer->OpacityIsAnimating()) 485 if (layer->layer_tree_impl()->IsPendingTree() && layer->OpacityIsAnimating())
480 return false; 486 return false;
481 487
482 // The opacity of a layer always applies to its children (either implicitly 488 // 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 489 // 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. 490 // 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. 491 // of layers in the subtree has event handlers.
486 return !layer->opacity(); 492 return !layer->opacity() &&
493 !layer->draw_properties().layer_or_descendant_has_event_handler;
487 } 494 }
488 495
489 static inline bool SubtreeShouldBeSkipped(Layer* layer, 496 static inline bool SubtreeShouldBeSkipped(Layer* layer,
490 bool layer_is_visible) { 497 bool layer_is_visible) {
491 // When we need to do a readback/copy of a layer's output, we can not skip 498 // When we need to do a readback/copy of a layer's output, we can not skip
492 // it or any of its ancestors. 499 // it or any of its ancestors.
493 if (layer->draw_properties().layer_or_descendant_has_copy_request) 500 if (layer->draw_properties().layer_or_descendant_has_copy_request)
494 return false; 501 return false;
495 502
496 // If the layer is not visible, then skip it and its subtree. 503 // If the layer is not visible, then skip it and its subtree.
497 if (!layer_is_visible) 504 if (!layer_is_visible)
498 return true; 505 return true;
499 506
500 // If the opacity is being animated then the opacity on the main thread is 507 // 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 508 // unreliable (since the impl thread may be using a different opacity), so it
502 // should not be trusted. 509 // should not be trusted.
503 // In particular, it should not cause the subtree to be skipped. 510 // In particular, it should not cause the subtree to be skipped.
504 // Similarly, for layers that might animate opacity using an impl-only 511 // Similarly, for layers that might animate opacity using an impl-only
505 // animation, their subtree should also not be skipped. 512 // 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() && 513 return !layer->opacity() && !layer->OpacityIsAnimating() &&
508 !layer->OpacityCanAnimateOnImplThread(); 514 !layer->OpacityCanAnimateOnImplThread() &&
515 !layer->draw_properties().layer_or_descendant_has_event_handler;
enne (OOO) 2013/10/07 17:27:23 Can you break out this condition from the rest of
sadrul 2013/10/07 18:37:24 Done.
509 } 516 }
510 517
511 // Called on each layer that could be drawn after all information from 518 // Called on each layer that could be drawn after all information from
512 // CalcDrawProperties has been updated on that layer. May have some false 519 // 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). 520 // positives (e.g. layers get this called on them but don't actually get drawn).
514 static inline void UpdateTilePrioritiesForLayer(LayerImpl* layer) { 521 static inline void UpdateTilePrioritiesForLayer(LayerImpl* layer) {
515 layer->UpdateTilePriorities(); 522 layer->UpdateTilePriorities();
516 523
517 // Mask layers don't get this call, so explicitly update them so they can 524 // Mask layers don't get this call, so explicitly update them so they can
518 // kick off tile rasterization. 525 // kick off tile rasterization.
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 render_surface_layer_list->back()->ClearRenderSurface(); 1014 render_surface_layer_list->back()->ClearRenderSurface();
1008 render_surface_layer_list->pop_back(); 1015 render_surface_layer_list->pop_back();
1009 } 1016 }
1010 DCHECK_EQ(render_surface_layer_list->back(), layer_to_remove); 1017 DCHECK_EQ(render_surface_layer_list->back(), layer_to_remove);
1011 render_surface_layer_list->pop_back(); 1018 render_surface_layer_list->pop_back();
1012 layer_to_remove->ClearRenderSurface(); 1019 layer_to_remove->ClearRenderSurface();
1013 } 1020 }
1014 1021
1015 struct PreCalculateMetaInformationRecursiveData { 1022 struct PreCalculateMetaInformationRecursiveData {
1016 bool layer_or_descendant_has_copy_request; 1023 bool layer_or_descendant_has_copy_request;
1024 bool layer_or_descendant_has_event_handler;
1017 int num_unclipped_descendants; 1025 int num_unclipped_descendants;
1018 1026
1019 PreCalculateMetaInformationRecursiveData() 1027 PreCalculateMetaInformationRecursiveData()
1020 : layer_or_descendant_has_copy_request(false), 1028 : layer_or_descendant_has_copy_request(false),
1029 layer_or_descendant_has_event_handler(false),
1021 num_unclipped_descendants(0) {} 1030 num_unclipped_descendants(0) {}
1022 1031
1023 void Merge(const PreCalculateMetaInformationRecursiveData& data) { 1032 void Merge(const PreCalculateMetaInformationRecursiveData& data) {
1024 layer_or_descendant_has_copy_request |= 1033 layer_or_descendant_has_copy_request |=
1025 data.layer_or_descendant_has_copy_request; 1034 data.layer_or_descendant_has_copy_request;
1035 layer_or_descendant_has_event_handler |=
1036 data.layer_or_descendant_has_event_handler;
1026 num_unclipped_descendants += 1037 num_unclipped_descendants +=
1027 data.num_unclipped_descendants; 1038 data.num_unclipped_descendants;
1028 } 1039 }
1029 }; 1040 };
1030 1041
1031 // Recursively walks the layer tree to compute any information that is needed 1042 // Recursively walks the layer tree to compute any information that is needed
1032 // before doing the main recursion. 1043 // before doing the main recursion.
1033 template <typename LayerType> 1044 template <typename LayerType>
1034 static void PreCalculateMetaInformation( 1045 static void PreCalculateMetaInformation(
1035 LayerType* layer, 1046 LayerType* layer,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 1088
1078 if (layer->clip_children()) { 1089 if (layer->clip_children()) {
1079 int num_clip_children = layer->clip_children()->size(); 1090 int num_clip_children = layer->clip_children()->size();
1080 DCHECK_GE(recursive_data->num_unclipped_descendants, num_clip_children); 1091 DCHECK_GE(recursive_data->num_unclipped_descendants, num_clip_children);
1081 recursive_data->num_unclipped_descendants -= num_clip_children; 1092 recursive_data->num_unclipped_descendants -= num_clip_children;
1082 } 1093 }
1083 1094
1084 if (layer->HasCopyRequest()) 1095 if (layer->HasCopyRequest())
1085 recursive_data->layer_or_descendant_has_copy_request = true; 1096 recursive_data->layer_or_descendant_has_copy_request = true;
1086 1097
1098 if (LayerCanAcceptInput(layer))
1099 recursive_data->layer_or_descendant_has_event_handler = true;
1100
1087 layer->draw_properties().num_descendants_that_draw_content = 1101 layer->draw_properties().num_descendants_that_draw_content =
1088 num_descendants_that_draw_content; 1102 num_descendants_that_draw_content;
1089 layer->draw_properties().num_unclipped_descendants = 1103 layer->draw_properties().num_unclipped_descendants =
1090 recursive_data->num_unclipped_descendants; 1104 recursive_data->num_unclipped_descendants;
1091 layer->draw_properties().descendants_can_clip_selves = 1105 layer->draw_properties().descendants_can_clip_selves =
1092 descendants_can_clip_selves; 1106 descendants_can_clip_selves;
1093 layer->draw_properties().layer_or_descendant_has_copy_request = 1107 layer->draw_properties().layer_or_descendant_has_copy_request =
1094 recursive_data->layer_or_descendant_has_copy_request; 1108 recursive_data->layer_or_descendant_has_copy_request;
1109 layer->draw_properties().layer_or_descendant_has_event_handler =
1110 recursive_data->layer_or_descendant_has_event_handler;
1095 } 1111 }
1096 1112
1097 static void RoundTranslationComponents(gfx::Transform* transform) { 1113 static void RoundTranslationComponents(gfx::Transform* transform) {
1098 transform->matrix().set(0, 3, MathUtil::Round(transform->matrix().get(0, 3))); 1114 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))); 1115 transform->matrix().set(1, 3, MathUtil::Round(transform->matrix().get(1, 3)));
1100 } 1116 }
1101 1117
1102 template <typename LayerType> 1118 template <typename LayerType>
1103 struct SubtreeGlobals { 1119 struct SubtreeGlobals {
1104 LayerSorter* layer_sorter; 1120 LayerSorter* layer_sorter;
(...skipping 1141 matching lines...) Expand 10 before | Expand all | Expand 10 after
2246 // At this point, we think the point does hit the touch event handler region 2262 // 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 2263 // 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 2264 // was not clipped in such a way that the hit point actually should not hit
2249 // the layer. 2265 // the layer.
2250 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl)) 2266 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl))
2251 return false; 2267 return false;
2252 2268
2253 return true; 2269 return true;
2254 } 2270 }
2255 } // namespace cc 2271 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/draw_properties.h ('k') | cc/trees/layer_tree_host_common_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698