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

Unified Diff: cc/trees/layer_tree_impl.cc

Issue 300323005: Route selection bounds updates through the compositor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Defer selection updates until after compositor scheduling Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: cc/trees/layer_tree_impl.cc
diff --git a/cc/trees/layer_tree_impl.cc b/cc/trees/layer_tree_impl.cc
index 9932a33be03d59d47c6ea65ad437c8a46b4e76a6..b0d33f95594b42706df9d2373d36d68415304594 100644
--- a/cc/trees/layer_tree_impl.cc
+++ b/cc/trees/layer_tree_impl.cc
@@ -119,6 +119,8 @@ void LayerTreeImpl::SetRootLayer(scoped_ptr<LayerImpl> layer) {
outer_viewport_scroll_layer_ = NULL;
page_scale_layer_ = NULL;
+ ClearSelection();
+
layer_tree_host_impl_->OnCanDrawStateChangedForTree();
}
@@ -178,6 +180,8 @@ scoped_ptr<LayerImpl> LayerTreeImpl::DetachLayerTree() {
page_scale_layer_ = NULL;
currently_scrolling_layer_ = NULL;
+ ClearSelection();
+
render_surface_layer_list_.clear();
set_needs_update_draw_properties();
return root_layer_.Pass();
@@ -209,6 +213,9 @@ void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) {
} else {
target_tree->ClearViewportLayers();
}
+
+ target_tree->RegisterSelection(selection_anchor_, selection_focus_);
+
// This should match the property synchronization in
// LayerTreeHost::finishCommitOnImplThread().
target_tree->set_source_frame_number(source_frame_number());
@@ -1017,6 +1024,10 @@ void LayerTreeImpl::ReleaseResourcesRecursive(LayerImpl* current) {
ReleaseResourcesRecursive(current->children()[i]);
}
+void LayerTreeImpl::ClearSelection() {
+ RegisterSelection(LayerSelectionBound(), LayerSelectionBound());
+}
+
template <typename LayerType>
static inline bool LayerClipsSubtree(LayerType* layer) {
return layer->masks_to_bounds() || layer->mask_layer();
@@ -1097,8 +1108,8 @@ static bool PointHitsRegion(const gfx::PointF& screen_space_point,
static bool PointIsClippedBySurfaceOrClipRect(
const gfx::PointF& screen_space_point,
- LayerImpl* layer) {
- LayerImpl* current_layer = layer;
+ const LayerImpl* layer) {
+ const LayerImpl* current_layer = layer;
// Walk up the layer tree and hit-test any render_surfaces and any layer
// clip rects that are active.
@@ -1114,7 +1125,7 @@ static bool PointIsClippedBySurfaceOrClipRect(
// Note that drawable content rects are actually in target surface space, so
// the transform we have to provide is the target surface's
// screen_space_transform.
- LayerImpl* render_target = current_layer->render_target();
+ const LayerImpl* render_target = current_layer->render_target();
if (LayerClipsSubtree(current_layer) &&
!PointHitsRect(
screen_space_point,
@@ -1131,7 +1142,7 @@ static bool PointIsClippedBySurfaceOrClipRect(
return false;
}
-static bool PointHitsLayer(LayerImpl* layer,
+static bool PointHitsLayer(const LayerImpl* layer,
const gfx::PointF& screen_space_point,
float* distance_to_intersection) {
gfx::RectF content_rect(layer->content_bounds());
@@ -1275,4 +1286,59 @@ LayerImpl* LayerTreeImpl::FindLayerThatIsHitByPointInTouchHandlerRegion(
return data_for_recursion.closest_match;
}
+void LayerTreeImpl::RegisterSelection(const LayerSelectionBound& anchor,
+ const LayerSelectionBound& focus) {
+ selection_anchor_ = anchor;
+ selection_focus_ = focus;
+}
+
+static SelectionBound ComputeViewportSelection(const LayerSelectionBound& bound,
+ LayerImpl* layer,
+ float device_scale_factor) {
+ SelectionBound result;
+ result.type = bound.type;
+
+ if (!layer || bound.type == SELECTION_BOUND_EMPTY ||
+ bound.type == SELECTION_BOUND_IGNORED)
+ return result;
+
+ gfx::RectF layer_scaled_rect = gfx::ScaleRect(
+ bound.layer_rect, layer->contents_scale_x(), layer->contents_scale_y());
+ gfx::RectF screen_rect = MathUtil::ProjectClippedRect(
+ layer->screen_space_transform(), layer_scaled_rect);
+
+ float intersect_distance = 0.f;
+ result.visible =
+ PointHitsLayer(layer, screen_rect.bottom_left(), &intersect_distance) ||
+ PointHitsLayer(layer, screen_rect.top_right(), &intersect_distance) ||
+ PointHitsLayer(layer, screen_rect.CenterPoint(), &intersect_distance);
+
+ screen_rect.Scale(1.f / device_scale_factor);
+ result.viewport_rect = screen_rect;
+
+ return result;
+}
+
+void LayerTreeImpl::GetViewportSelection(SelectionBound* anchor,
+ SelectionBound* focus) {
+ DCHECK(!needs_update_draw_properties_);
+ DCHECK(anchor);
+ DCHECK(focus);
+
+ *anchor = ComputeViewportSelection(
+ selection_anchor_,
+ selection_anchor_.layer_id ? LayerById(selection_anchor_.layer_id) : NULL,
+ device_scale_factor());
+ if (anchor->type == SELECTION_BOUND_CENTER ||
+ anchor->type == SELECTION_BOUND_EMPTY ||
+ anchor->type == SELECTION_BOUND_IGNORED) {
+ *focus = *anchor;
+ } else {
+ *focus = ComputeViewportSelection(
+ selection_focus_,
+ selection_focus_.layer_id ? LayerById(selection_focus_.layer_id) : NULL,
+ device_scale_factor());
+ }
+}
+
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698