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

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: Updates 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
« no previous file with comments | « cc/trees/layer_tree_impl.h ('k') | content/browser/android/content_startup_flags.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_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(
218 start_selection_layer_ ? start_selection_layer_->id() : 0,
219 start_selection_handle_,
220 end_selection_layer_ ? end_selection_layer_->id() : 0,
221 end_selection_handle_);
222
212 // This should match the property synchronization in 223 // This should match the property synchronization in
213 // LayerTreeHost::finishCommitOnImplThread(). 224 // LayerTreeHost::finishCommitOnImplThread().
214 target_tree->set_source_frame_number(source_frame_number()); 225 target_tree->set_source_frame_number(source_frame_number());
215 target_tree->set_background_color(background_color()); 226 target_tree->set_background_color(background_color());
216 target_tree->set_has_transparent_background(has_transparent_background()); 227 target_tree->set_has_transparent_background(has_transparent_background());
217 228
218 if (ContentsTexturesPurged()) 229 if (ContentsTexturesPurged())
219 target_tree->SetContentsTexturesPurged(); 230 target_tree->SetContentsTexturesPurged();
220 else 231 else
221 target_tree->ResetContentsTexturesPurged(); 232 target_tree->ResetContentsTexturesPurged();
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 DCHECK(current); 1021 DCHECK(current);
1011 current->ReleaseResources(); 1022 current->ReleaseResources();
1012 if (current->mask_layer()) 1023 if (current->mask_layer())
1013 ReleaseResourcesRecursive(current->mask_layer()); 1024 ReleaseResourcesRecursive(current->mask_layer());
1014 if (current->replica_layer()) 1025 if (current->replica_layer())
1015 ReleaseResourcesRecursive(current->replica_layer()); 1026 ReleaseResourcesRecursive(current->replica_layer());
1016 for (size_t i = 0; i < current->children().size(); ++i) 1027 for (size_t i = 0; i < current->children().size(); ++i)
1017 ReleaseResourcesRecursive(current->children()[i]); 1028 ReleaseResourcesRecursive(current->children()[i]);
1018 } 1029 }
1019 1030
1031 void LayerTreeImpl::ClearSelection() {
1032 RegisterSelection(0, SelectionHandle(), 0, SelectionHandle());
1033 }
1034
1020 template <typename LayerType> 1035 template <typename LayerType>
1021 static inline bool LayerClipsSubtree(LayerType* layer) { 1036 static inline bool LayerClipsSubtree(LayerType* layer) {
1022 return layer->masks_to_bounds() || layer->mask_layer(); 1037 return layer->masks_to_bounds() || layer->mask_layer();
1023 } 1038 }
1024 1039
1025 static bool PointHitsRect( 1040 static bool PointHitsRect(
1026 const gfx::PointF& screen_space_point, 1041 const gfx::PointF& screen_space_point,
1027 const gfx::Transform& local_space_to_screen_space_transform, 1042 const gfx::Transform& local_space_to_screen_space_transform,
1028 const gfx::RectF& local_space_rect, 1043 const gfx::RectF& local_space_rect,
1029 float* distance_to_camera) { 1044 float* distance_to_camera) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 // this point doesn't hit this region. 1105 // this point doesn't hit this region.
1091 if (clipped) 1106 if (clipped)
1092 return false; 1107 return false;
1093 1108
1094 return layer_space_region.Contains( 1109 return layer_space_region.Contains(
1095 gfx::ToRoundedPoint(hit_test_point_in_layer_space)); 1110 gfx::ToRoundedPoint(hit_test_point_in_layer_space));
1096 } 1111 }
1097 1112
1098 static bool PointIsClippedBySurfaceOrClipRect( 1113 static bool PointIsClippedBySurfaceOrClipRect(
1099 const gfx::PointF& screen_space_point, 1114 const gfx::PointF& screen_space_point,
1100 LayerImpl* layer) { 1115 const LayerImpl* layer) {
1101 LayerImpl* current_layer = layer; 1116 const LayerImpl* current_layer = layer;
1102 1117
1103 // Walk up the layer tree and hit-test any render_surfaces and any layer 1118 // Walk up the layer tree and hit-test any render_surfaces and any layer
1104 // clip rects that are active. 1119 // clip rects that are active.
1105 while (current_layer) { 1120 while (current_layer) {
1106 if (current_layer->render_surface() && 1121 if (current_layer->render_surface() &&
1107 !PointHitsRect( 1122 !PointHitsRect(
1108 screen_space_point, 1123 screen_space_point,
1109 current_layer->render_surface()->screen_space_transform(), 1124 current_layer->render_surface()->screen_space_transform(),
1110 current_layer->render_surface()->content_rect(), 1125 current_layer->render_surface()->content_rect(),
1111 NULL)) 1126 NULL))
1112 return true; 1127 return true;
1113 1128
1114 // Note that drawable content rects are actually in target surface space, so 1129 // Note that drawable content rects are actually in target surface space, so
1115 // the transform we have to provide is the target surface's 1130 // the transform we have to provide is the target surface's
1116 // screen_space_transform. 1131 // screen_space_transform.
1117 LayerImpl* render_target = current_layer->render_target(); 1132 const LayerImpl* render_target = current_layer->render_target();
1118 if (LayerClipsSubtree(current_layer) && 1133 if (LayerClipsSubtree(current_layer) &&
1119 !PointHitsRect( 1134 !PointHitsRect(
1120 screen_space_point, 1135 screen_space_point,
1121 render_target->render_surface()->screen_space_transform(), 1136 render_target->render_surface()->screen_space_transform(),
1122 current_layer->drawable_content_rect(), 1137 current_layer->drawable_content_rect(),
1123 NULL)) 1138 NULL))
1124 return true; 1139 return true;
1125 1140
1126 current_layer = current_layer->parent(); 1141 current_layer = current_layer->parent();
1127 } 1142 }
1128 1143
1129 // If we have finished walking all ancestors without having already exited, 1144 // If we have finished walking all ancestors without having already exited,
1130 // then the point is not clipped by any ancestors. 1145 // then the point is not clipped by any ancestors.
1131 return false; 1146 return false;
1132 } 1147 }
1133 1148
1134 static bool PointHitsLayer(LayerImpl* layer, 1149 static bool PointHitsLayer(const LayerImpl* layer,
1135 const gfx::PointF& screen_space_point, 1150 const gfx::PointF& screen_space_point,
1136 float* distance_to_intersection) { 1151 float* distance_to_intersection) {
1137 gfx::RectF content_rect(layer->content_bounds()); 1152 gfx::RectF content_rect(layer->content_bounds());
1138 if (!PointHitsRect(screen_space_point, 1153 if (!PointHitsRect(screen_space_point,
1139 layer->screen_space_transform(), 1154 layer->screen_space_transform(),
1140 content_rect, 1155 content_rect,
1141 distance_to_intersection)) 1156 distance_to_intersection))
1142 return false; 1157 return false;
1143 1158
1144 // At this point, we think the point does hit the layer, but we need to walk 1159 // 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 1283
1269 LayerImpl* LayerTreeImpl::FindLayerThatIsHitByPointInTouchHandlerRegion( 1284 LayerImpl* LayerTreeImpl::FindLayerThatIsHitByPointInTouchHandlerRegion(
1270 const gfx::PointF& screen_space_point) { 1285 const gfx::PointF& screen_space_point) {
1271 FindTouchEventLayerFunctor func = {screen_space_point}; 1286 FindTouchEventLayerFunctor func = {screen_space_point};
1272 FindClosestMatchingLayerDataForRecursion data_for_recursion; 1287 FindClosestMatchingLayerDataForRecursion data_for_recursion;
1273 FindClosestMatchingLayer( 1288 FindClosestMatchingLayer(
1274 screen_space_point, root_layer(), func, &data_for_recursion); 1289 screen_space_point, root_layer(), func, &data_for_recursion);
1275 return data_for_recursion.closest_match; 1290 return data_for_recursion.closest_match;
1276 } 1291 }
1277 1292
1293 void LayerTreeImpl::RegisterSelection(int start_layer_id,
1294 const SelectionHandle& start_handle,
1295 int end_layer_id,
1296 const SelectionHandle& end_handle) {
1297 start_selection_layer_ = start_layer_id ? LayerById(start_layer_id) : NULL;
1298 end_selection_layer_ = end_layer_id ? LayerById(end_layer_id) : NULL;
1299 start_selection_handle_ = start_handle;
1300 end_selection_handle_ = end_handle;
1301 }
1302
1303 static SelectionHandle ComputeSelectionVisibility(const SelectionHandle& handle,
1304 const LayerImpl* layer,
1305 float device_scale_factor) {
1306 if (!layer || handle.type == SelectionHandle::NONE ||
1307 handle.type == SelectionHandle::IGNORED)
1308 return handle;
1309
1310 SelectionHandle result = handle;
1311
1312 gfx::QuadF layer_scaled_quad(gfx::ScaleRect(
1313 handle.bounds, layer->contents_scale_x(), layer->contents_scale_y()));
1314 bool handle_clipped = false;
1315 gfx::QuadF screen_quad = MathUtil::ProjectQuad(
1316 layer->screen_space_transform(), layer_scaled_quad, &handle_clipped);
1317 screen_quad.Scale(1.f / device_scale_factor);
1318 result.bounds = screen_quad.BoundingBox();
1319
1320 // Use the bottom-left coordinate as the visibility anchor point.
1321 result.visible = !handle_clipped &&
jdduke (slow) 2014/06/02 20:06:01 Bah, figured it out, need to be doing the clip tes
1322 !PointIsClippedBySurfaceOrClipRect(screen_quad.p4(), layer);
1323
1324 return result;
1325 }
1326
1327 void LayerTreeImpl::GetViewportSelection(SelectionHandle* start_handle,
1328 SelectionHandle* end_handle) {
1329 DCHECK(!needs_update_draw_properties_);
1330 DCHECK(start_handle);
1331 DCHECK(end_handle);
1332
1333 *start_handle = ComputeSelectionVisibility(
1334 start_selection_handle_, start_selection_layer_, device_scale_factor());
1335
1336 if (start_handle->type == SelectionHandle::CENTER ||
1337 start_handle->type == SelectionHandle::NONE ||
1338 start_handle->type == SelectionHandle::IGNORED) {
1339 *end_handle = *start_handle;
1340 } else {
1341 *end_handle = ComputeSelectionVisibility(
1342 end_selection_handle_, end_selection_layer_, device_scale_factor());
1343 }
1344 }
1345
1278 } // namespace cc 1346 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_impl.h ('k') | content/browser/android/content_startup_flags.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698