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

Side by Side 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 unified diff | Download patch
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_impl.h" 5 #include "cc/trees/layer_tree_impl.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <set> 8 #include <set>
9 9
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL); 112 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL);
113 inner_viewport_scroll_delegate_proxy_.reset(); 113 inner_viewport_scroll_delegate_proxy_.reset();
114 outer_viewport_scroll_delegate_proxy_.reset(); 114 outer_viewport_scroll_delegate_proxy_.reset();
115 115
116 root_layer_ = layer.Pass(); 116 root_layer_ = layer.Pass();
117 currently_scrolling_layer_ = NULL; 117 currently_scrolling_layer_ = NULL;
118 inner_viewport_scroll_layer_ = NULL; 118 inner_viewport_scroll_layer_ = NULL;
119 outer_viewport_scroll_layer_ = NULL; 119 outer_viewport_scroll_layer_ = NULL;
120 page_scale_layer_ = NULL; 120 page_scale_layer_ = NULL;
121 121
122 ClearSelection();
123
122 layer_tree_host_impl_->OnCanDrawStateChangedForTree(); 124 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
123 } 125 }
124 126
125 LayerImpl* LayerTreeImpl::InnerViewportScrollLayer() const { 127 LayerImpl* LayerTreeImpl::InnerViewportScrollLayer() const {
126 return inner_viewport_scroll_layer_; 128 return inner_viewport_scroll_layer_;
127 } 129 }
128 130
129 LayerImpl* LayerTreeImpl::OuterViewportScrollLayer() const { 131 LayerImpl* LayerTreeImpl::OuterViewportScrollLayer() const {
130 return outer_viewport_scroll_layer_; 132 return outer_viewport_scroll_layer_;
131 } 133 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 inner_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL); 173 inner_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL);
172 if (outer_viewport_scroll_layer_) 174 if (outer_viewport_scroll_layer_)
173 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL); 175 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL);
174 inner_viewport_scroll_delegate_proxy_.reset(); 176 inner_viewport_scroll_delegate_proxy_.reset();
175 outer_viewport_scroll_delegate_proxy_.reset(); 177 outer_viewport_scroll_delegate_proxy_.reset();
176 inner_viewport_scroll_layer_ = NULL; 178 inner_viewport_scroll_layer_ = NULL;
177 outer_viewport_scroll_layer_ = NULL; 179 outer_viewport_scroll_layer_ = NULL;
178 page_scale_layer_ = NULL; 180 page_scale_layer_ = NULL;
179 currently_scrolling_layer_ = NULL; 181 currently_scrolling_layer_ = NULL;
180 182
183 ClearSelection();
184
181 render_surface_layer_list_.clear(); 185 render_surface_layer_list_.clear();
182 set_needs_update_draw_properties(); 186 set_needs_update_draw_properties();
183 return root_layer_.Pass(); 187 return root_layer_.Pass();
184 } 188 }
185 189
186 void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) { 190 void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) {
187 // The request queue should have been processed and does not require a push. 191 // The request queue should have been processed and does not require a push.
188 DCHECK_EQ(ui_resource_request_queue_.size(), 0u); 192 DCHECK_EQ(ui_resource_request_queue_.size(), 0u);
189 193
190 if (next_activation_forces_redraw_) { 194 if (next_activation_forces_redraw_) {
(...skipping 11 matching lines...) Expand all
202 206
203 if (page_scale_layer_ && inner_viewport_scroll_layer_) { 207 if (page_scale_layer_ && inner_viewport_scroll_layer_) {
204 target_tree->SetViewportLayersFromIds( 208 target_tree->SetViewportLayersFromIds(
205 page_scale_layer_->id(), 209 page_scale_layer_->id(),
206 inner_viewport_scroll_layer_->id(), 210 inner_viewport_scroll_layer_->id(),
207 outer_viewport_scroll_layer_ ? outer_viewport_scroll_layer_->id() 211 outer_viewport_scroll_layer_ ? outer_viewport_scroll_layer_->id()
208 : Layer::INVALID_ID); 212 : Layer::INVALID_ID);
209 } else { 213 } else {
210 target_tree->ClearViewportLayers(); 214 target_tree->ClearViewportLayers();
211 } 215 }
216
217 target_tree->RegisterSelection(selection_anchor_, selection_focus_);
218
212 // This should match the property synchronization in 219 // This should match the property synchronization in
213 // LayerTreeHost::finishCommitOnImplThread(). 220 // LayerTreeHost::finishCommitOnImplThread().
214 target_tree->set_source_frame_number(source_frame_number()); 221 target_tree->set_source_frame_number(source_frame_number());
215 target_tree->set_background_color(background_color()); 222 target_tree->set_background_color(background_color());
216 target_tree->set_has_transparent_background(has_transparent_background()); 223 target_tree->set_has_transparent_background(has_transparent_background());
217 224
218 if (ContentsTexturesPurged()) 225 if (ContentsTexturesPurged())
219 target_tree->SetContentsTexturesPurged(); 226 target_tree->SetContentsTexturesPurged();
220 else 227 else
221 target_tree->ResetContentsTexturesPurged(); 228 target_tree->ResetContentsTexturesPurged();
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 DCHECK(current); 1017 DCHECK(current);
1011 current->ReleaseResources(); 1018 current->ReleaseResources();
1012 if (current->mask_layer()) 1019 if (current->mask_layer())
1013 ReleaseResourcesRecursive(current->mask_layer()); 1020 ReleaseResourcesRecursive(current->mask_layer());
1014 if (current->replica_layer()) 1021 if (current->replica_layer())
1015 ReleaseResourcesRecursive(current->replica_layer()); 1022 ReleaseResourcesRecursive(current->replica_layer());
1016 for (size_t i = 0; i < current->children().size(); ++i) 1023 for (size_t i = 0; i < current->children().size(); ++i)
1017 ReleaseResourcesRecursive(current->children()[i]); 1024 ReleaseResourcesRecursive(current->children()[i]);
1018 } 1025 }
1019 1026
1027 void LayerTreeImpl::ClearSelection() {
1028 RegisterSelection(LayerSelectionBound(), LayerSelectionBound());
1029 }
1030
1020 template <typename LayerType> 1031 template <typename LayerType>
1021 static inline bool LayerClipsSubtree(LayerType* layer) { 1032 static inline bool LayerClipsSubtree(LayerType* layer) {
1022 return layer->masks_to_bounds() || layer->mask_layer(); 1033 return layer->masks_to_bounds() || layer->mask_layer();
1023 } 1034 }
1024 1035
1025 static bool PointHitsRect( 1036 static bool PointHitsRect(
1026 const gfx::PointF& screen_space_point, 1037 const gfx::PointF& screen_space_point,
1027 const gfx::Transform& local_space_to_screen_space_transform, 1038 const gfx::Transform& local_space_to_screen_space_transform,
1028 const gfx::RectF& local_space_rect, 1039 const gfx::RectF& local_space_rect,
1029 float* distance_to_camera) { 1040 float* distance_to_camera) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 // this point doesn't hit this region. 1101 // this point doesn't hit this region.
1091 if (clipped) 1102 if (clipped)
1092 return false; 1103 return false;
1093 1104
1094 return layer_space_region.Contains( 1105 return layer_space_region.Contains(
1095 gfx::ToRoundedPoint(hit_test_point_in_layer_space)); 1106 gfx::ToRoundedPoint(hit_test_point_in_layer_space));
1096 } 1107 }
1097 1108
1098 static bool PointIsClippedBySurfaceOrClipRect( 1109 static bool PointIsClippedBySurfaceOrClipRect(
1099 const gfx::PointF& screen_space_point, 1110 const gfx::PointF& screen_space_point,
1100 LayerImpl* layer) { 1111 const LayerImpl* layer) {
1101 LayerImpl* current_layer = layer; 1112 const LayerImpl* current_layer = layer;
1102 1113
1103 // Walk up the layer tree and hit-test any render_surfaces and any layer 1114 // Walk up the layer tree and hit-test any render_surfaces and any layer
1104 // clip rects that are active. 1115 // clip rects that are active.
1105 while (current_layer) { 1116 while (current_layer) {
1106 if (current_layer->render_surface() && 1117 if (current_layer->render_surface() &&
1107 !PointHitsRect( 1118 !PointHitsRect(
1108 screen_space_point, 1119 screen_space_point,
1109 current_layer->render_surface()->screen_space_transform(), 1120 current_layer->render_surface()->screen_space_transform(),
1110 current_layer->render_surface()->content_rect(), 1121 current_layer->render_surface()->content_rect(),
1111 NULL)) 1122 NULL))
1112 return true; 1123 return true;
1113 1124
1114 // Note that drawable content rects are actually in target surface space, so 1125 // Note that drawable content rects are actually in target surface space, so
1115 // the transform we have to provide is the target surface's 1126 // the transform we have to provide is the target surface's
1116 // screen_space_transform. 1127 // screen_space_transform.
1117 LayerImpl* render_target = current_layer->render_target(); 1128 const LayerImpl* render_target = current_layer->render_target();
1118 if (LayerClipsSubtree(current_layer) && 1129 if (LayerClipsSubtree(current_layer) &&
1119 !PointHitsRect( 1130 !PointHitsRect(
1120 screen_space_point, 1131 screen_space_point,
1121 render_target->render_surface()->screen_space_transform(), 1132 render_target->render_surface()->screen_space_transform(),
1122 current_layer->drawable_content_rect(), 1133 current_layer->drawable_content_rect(),
1123 NULL)) 1134 NULL))
1124 return true; 1135 return true;
1125 1136
1126 current_layer = current_layer->parent(); 1137 current_layer = current_layer->parent();
1127 } 1138 }
1128 1139
1129 // If we have finished walking all ancestors without having already exited, 1140 // If we have finished walking all ancestors without having already exited,
1130 // then the point is not clipped by any ancestors. 1141 // then the point is not clipped by any ancestors.
1131 return false; 1142 return false;
1132 } 1143 }
1133 1144
1134 static bool PointHitsLayer(LayerImpl* layer, 1145 static bool PointHitsLayer(const LayerImpl* layer,
1135 const gfx::PointF& screen_space_point, 1146 const gfx::PointF& screen_space_point,
1136 float* distance_to_intersection) { 1147 float* distance_to_intersection) {
1137 gfx::RectF content_rect(layer->content_bounds()); 1148 gfx::RectF content_rect(layer->content_bounds());
1138 if (!PointHitsRect(screen_space_point, 1149 if (!PointHitsRect(screen_space_point,
1139 layer->screen_space_transform(), 1150 layer->screen_space_transform(),
1140 content_rect, 1151 content_rect,
1141 distance_to_intersection)) 1152 distance_to_intersection))
1142 return false; 1153 return false;
1143 1154
1144 // At this point, we think the point does hit the layer, but we need to walk 1155 // At this point, we think the point does hit the layer, but we need to walk
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 1279
1269 LayerImpl* LayerTreeImpl::FindLayerThatIsHitByPointInTouchHandlerRegion( 1280 LayerImpl* LayerTreeImpl::FindLayerThatIsHitByPointInTouchHandlerRegion(
1270 const gfx::PointF& screen_space_point) { 1281 const gfx::PointF& screen_space_point) {
1271 FindTouchEventLayerFunctor func = {screen_space_point}; 1282 FindTouchEventLayerFunctor func = {screen_space_point};
1272 FindClosestMatchingLayerDataForRecursion data_for_recursion; 1283 FindClosestMatchingLayerDataForRecursion data_for_recursion;
1273 FindClosestMatchingLayer( 1284 FindClosestMatchingLayer(
1274 screen_space_point, root_layer(), func, &data_for_recursion); 1285 screen_space_point, root_layer(), func, &data_for_recursion);
1275 return data_for_recursion.closest_match; 1286 return data_for_recursion.closest_match;
1276 } 1287 }
1277 1288
1289 void LayerTreeImpl::RegisterSelection(const LayerSelectionBound& anchor,
1290 const LayerSelectionBound& focus) {
1291 selection_anchor_ = anchor;
1292 selection_focus_ = focus;
1293 }
1294
1295 static SelectionBound ComputeViewportSelection(const LayerSelectionBound& bound,
1296 LayerImpl* layer,
1297 float device_scale_factor) {
1298 SelectionBound result;
1299 result.type = bound.type;
1300
1301 if (!layer || bound.type == SELECTION_BOUND_EMPTY ||
1302 bound.type == SELECTION_BOUND_IGNORED)
1303 return result;
1304
1305 gfx::RectF layer_scaled_rect = gfx::ScaleRect(
1306 bound.layer_rect, layer->contents_scale_x(), layer->contents_scale_y());
1307 gfx::RectF screen_rect = MathUtil::ProjectClippedRect(
1308 layer->screen_space_transform(), layer_scaled_rect);
1309
1310 float intersect_distance = 0.f;
1311 result.visible =
1312 PointHitsLayer(layer, screen_rect.bottom_left(), &intersect_distance) ||
1313 PointHitsLayer(layer, screen_rect.top_right(), &intersect_distance) ||
1314 PointHitsLayer(layer, screen_rect.CenterPoint(), &intersect_distance);
1315
1316 screen_rect.Scale(1.f / device_scale_factor);
1317 result.viewport_rect = screen_rect;
1318
1319 return result;
1320 }
1321
1322 void LayerTreeImpl::GetViewportSelection(SelectionBound* anchor,
1323 SelectionBound* focus) {
1324 DCHECK(!needs_update_draw_properties_);
1325 DCHECK(anchor);
1326 DCHECK(focus);
1327
1328 *anchor = ComputeViewportSelection(
1329 selection_anchor_,
1330 selection_anchor_.layer_id ? LayerById(selection_anchor_.layer_id) : NULL,
1331 device_scale_factor());
1332 if (anchor->type == SELECTION_BOUND_CENTER ||
1333 anchor->type == SELECTION_BOUND_EMPTY ||
1334 anchor->type == SELECTION_BOUND_IGNORED) {
1335 *focus = *anchor;
1336 } else {
1337 *focus = ComputeViewportSelection(
1338 selection_focus_,
1339 selection_focus_.layer_id ? LayerById(selection_focus_.layer_id) : NULL,
1340 device_scale_factor());
1341 }
1342 }
1343
1278 } // namespace cc 1344 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698