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

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: child is zero-opacity no-handler, grandchild has handler 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 | « no previous file | 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
72 template <typename LayerType>
73 static bool LayerSubtreeCanAcceptInput(LayerType* layer) {
sadrul 2013/10/05 07:57:32 This should be called only for subtrees where the
enne (OOO) 2013/10/05 16:40:18 What about setting a flag in the prerecursion, lik
sadrul 2013/10/05 21:09:05 Oh, cool. That looks much better. Done.
74 if (LayerCanAcceptInput(layer))
75 return true;
76 for (size_t i = 0; i < layer->children().size(); ++i) {
77 LayerType* child =
78 LayerTreeHostCommon::get_child_as_raw_ptr(layer->children(), i);
79 if (LayerSubtreeCanAcceptInput(child))
80 return true;
81 }
82 return false;
83 }
84
66 inline gfx::Rect CalculateVisibleRectWithCachedLayerRect( 85 inline gfx::Rect CalculateVisibleRectWithCachedLayerRect(
67 gfx::Rect target_surface_rect, 86 gfx::Rect target_surface_rect,
68 gfx::Rect layer_bound_rect, 87 gfx::Rect layer_bound_rect,
69 gfx::Rect layer_rect_in_target_space, 88 gfx::Rect layer_rect_in_target_space,
70 const gfx::Transform& transform) { 89 const gfx::Transform& transform) {
71 if (layer_rect_in_target_space.IsEmpty()) 90 if (layer_rect_in_target_space.IsEmpty())
72 return gfx::Rect(); 91 return gfx::Rect();
73 92
74 // Is this layer fully contained within the target surface? 93 // Is this layer fully contained within the target surface?
75 if (target_surface_rect.Contains(layer_rect_in_target_space)) 94 if (target_surface_rect.Contains(layer_rect_in_target_space))
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 466
448 // The layer should not be drawn if (1) it is not double-sided and (2) the 467 // 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. 468 // back of the layer is known to be facing the screen.
450 if (!backface_test_layer->double_sided() && 469 if (!backface_test_layer->double_sided() &&
451 TransformToScreenIsKnown(backface_test_layer) && 470 TransformToScreenIsKnown(backface_test_layer) &&
452 IsLayerBackFaceVisible(backface_test_layer)) 471 IsLayerBackFaceVisible(backface_test_layer))
453 return true; 472 return true;
454 473
455 // The layer is visible to events. If it's subject to hit testing, then 474 // The layer is visible to events. If it's subject to hit testing, then
456 // we can't skip it. 475 // we can't skip it.
457 bool can_accept_input = !layer->touch_event_handler_region().IsEmpty() || 476 if (!layer->DrawsContent() && !LayerCanAcceptInput(layer))
458 layer->have_wheel_event_handlers();
459 if (!layer->DrawsContent() && !can_accept_input)
460 return true; 477 return true;
461 478
462 return false; 479 return false;
463 } 480 }
464 481
465 static inline bool SubtreeShouldBeSkipped(LayerImpl* layer, 482 static inline bool SubtreeShouldBeSkipped(LayerImpl* layer,
466 bool layer_is_visible) { 483 bool layer_is_visible) {
467 // When we need to do a readback/copy of a layer's output, we can not skip 484 // When we need to do a readback/copy of a layer's output, we can not skip
468 // it or any of its ancestors. 485 // it or any of its ancestors.
469 if (layer->draw_properties().layer_or_descendant_has_copy_request) 486 if (layer->draw_properties().layer_or_descendant_has_copy_request)
470 return false; 487 return false;
471 488
472 // If the layer is not visible, then skip it and its subtree. 489 // If the layer is not visible, then skip it and its subtree.
473 if (!layer_is_visible) 490 if (!layer_is_visible)
474 return true; 491 return true;
475 492
476 // If layer is on the pending tree and opacity is being animated then 493 // 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 494 // 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. 495 // include tiles for this layer when deciding if tree can be activated.
479 if (layer->layer_tree_impl()->IsPendingTree() && layer->OpacityIsAnimating()) 496 if (layer->layer_tree_impl()->IsPendingTree() && layer->OpacityIsAnimating())
480 return false; 497 return false;
481 498
482 // The opacity of a layer always applies to its children (either implicitly 499 // 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 500 // 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. 501 // 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. 502 // of layers in the subtree has event handlers.
486 return !layer->opacity(); 503 return !layer->opacity() && !LayerSubtreeCanAcceptInput(layer);
487 } 504 }
488 505
489 static inline bool SubtreeShouldBeSkipped(Layer* layer, 506 static inline bool SubtreeShouldBeSkipped(Layer* layer,
490 bool layer_is_visible) { 507 bool layer_is_visible) {
491 // When we need to do a readback/copy of a layer's output, we can not skip 508 // When we need to do a readback/copy of a layer's output, we can not skip
492 // it or any of its ancestors. 509 // it or any of its ancestors.
493 if (layer->draw_properties().layer_or_descendant_has_copy_request) 510 if (layer->draw_properties().layer_or_descendant_has_copy_request)
494 return false; 511 return false;
495 512
496 // If the layer is not visible, then skip it and its subtree. 513 // If the layer is not visible, then skip it and its subtree.
497 if (!layer_is_visible) 514 if (!layer_is_visible)
498 return true; 515 return true;
499 516
500 // If the opacity is being animated then the opacity on the main thread is 517 // 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 518 // unreliable (since the impl thread may be using a different opacity), so it
502 // should not be trusted. 519 // should not be trusted.
503 // In particular, it should not cause the subtree to be skipped. 520 // In particular, it should not cause the subtree to be skipped.
504 // Similarly, for layers that might animate opacity using an impl-only 521 // Similarly, for layers that might animate opacity using an impl-only
505 // animation, their subtree should also not be skipped. 522 // 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() && 523 return !layer->opacity() && !layer->OpacityIsAnimating() &&
508 !layer->OpacityCanAnimateOnImplThread(); 524 !layer->OpacityCanAnimateOnImplThread() &&
525 !LayerSubtreeCanAcceptInput(layer);
509 } 526 }
510 527
511 // Called on each layer that could be drawn after all information from 528 // Called on each layer that could be drawn after all information from
512 // CalcDrawProperties has been updated on that layer. May have some false 529 // 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). 530 // positives (e.g. layers get this called on them but don't actually get drawn).
514 static inline void UpdateTilePrioritiesForLayer(LayerImpl* layer) { 531 static inline void UpdateTilePrioritiesForLayer(LayerImpl* layer) {
515 layer->UpdateTilePriorities(); 532 layer->UpdateTilePriorities();
516 533
517 // Mask layers don't get this call, so explicitly update them so they can 534 // Mask layers don't get this call, so explicitly update them so they can
518 // kick off tile rasterization. 535 // kick off tile rasterization.
(...skipping 1727 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 2263 // 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 2264 // 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 2265 // was not clipped in such a way that the hit point actually should not hit
2249 // the layer. 2266 // the layer.
2250 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl)) 2267 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl))
2251 return false; 2268 return false;
2252 2269
2253 return true; 2270 return true;
2254 } 2271 }
2255 } // namespace cc 2272 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/trees/layer_tree_host_common_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698