OLD | NEW |
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 inline gfx::Rect CalculateVisibleRectWithCachedLayerRect( | 66 inline gfx::Rect CalculateVisibleRectWithCachedLayerRect( |
67 gfx::Rect target_surface_rect, | 67 const gfx::Rect& target_surface_rect, |
68 gfx::Rect layer_bound_rect, | 68 const gfx::Rect& layer_bound_rect, |
69 gfx::Rect layer_rect_in_target_space, | 69 const gfx::Rect& layer_rect_in_target_space, |
70 const gfx::Transform& transform) { | 70 const gfx::Transform& transform) { |
71 if (layer_rect_in_target_space.IsEmpty()) | 71 if (layer_rect_in_target_space.IsEmpty()) |
72 return gfx::Rect(); | 72 return gfx::Rect(); |
73 | 73 |
74 // Is this layer fully contained within the target surface? | 74 // Is this layer fully contained within the target surface? |
75 if (target_surface_rect.Contains(layer_rect_in_target_space)) | 75 if (target_surface_rect.Contains(layer_rect_in_target_space)) |
76 return layer_bound_rect; | 76 return layer_bound_rect; |
77 | 77 |
78 // If the layer doesn't fill up the entire surface, then find the part of | 78 // If the layer doesn't fill up the entire surface, then find the part of |
79 // the surface rect where the layer could be visible. This avoids trying to | 79 // the surface rect where the layer could be visible. This avoids trying to |
(...skipping 17 matching lines...) Expand all Loading... |
97 return layer_bound_rect; | 97 return layer_bound_rect; |
98 } | 98 } |
99 | 99 |
100 gfx::Rect layer_rect = gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( | 100 gfx::Rect layer_rect = gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( |
101 surface_to_layer, gfx::RectF(minimal_surface_rect))); | 101 surface_to_layer, gfx::RectF(minimal_surface_rect))); |
102 layer_rect.Intersect(layer_bound_rect); | 102 layer_rect.Intersect(layer_bound_rect); |
103 return layer_rect; | 103 return layer_rect; |
104 } | 104 } |
105 | 105 |
106 gfx::Rect LayerTreeHostCommon::CalculateVisibleRect( | 106 gfx::Rect LayerTreeHostCommon::CalculateVisibleRect( |
107 gfx::Rect target_surface_rect, | 107 const gfx::Rect& target_surface_rect, |
108 gfx::Rect layer_bound_rect, | 108 const gfx::Rect& layer_bound_rect, |
109 const gfx::Transform& transform) { | 109 const gfx::Transform& transform) { |
110 gfx::Rect layer_in_surface_space = | 110 gfx::Rect layer_in_surface_space = |
111 MathUtil::MapClippedRect(transform, layer_bound_rect); | 111 MathUtil::MapClippedRect(transform, layer_bound_rect); |
112 return CalculateVisibleRectWithCachedLayerRect( | 112 return CalculateVisibleRectWithCachedLayerRect( |
113 target_surface_rect, layer_bound_rect, layer_in_surface_space, transform); | 113 target_surface_rect, layer_bound_rect, layer_in_surface_space, transform); |
114 } | 114 } |
115 | 115 |
116 template <typename LayerType> | 116 template <typename LayerType> |
117 static LayerType* NextTargetSurface(LayerType* layer) { | 117 static LayerType* NextTargetSurface(LayerType* layer) { |
118 return layer->parent() ? layer->parent()->render_target() : 0; | 118 return layer->parent() ? layer->parent()->render_target() : 0; |
(...skipping 28 matching lines...) Expand all Loading... |
147 } | 147 } |
148 | 148 |
149 enum TranslateRectDirection { | 149 enum TranslateRectDirection { |
150 TranslateRectDirectionToAncestor, | 150 TranslateRectDirectionToAncestor, |
151 TranslateRectDirectionToDescendant | 151 TranslateRectDirectionToDescendant |
152 }; | 152 }; |
153 | 153 |
154 template <typename LayerType> | 154 template <typename LayerType> |
155 static gfx::Rect TranslateRectToTargetSpace(const LayerType& ancestor_layer, | 155 static gfx::Rect TranslateRectToTargetSpace(const LayerType& ancestor_layer, |
156 const LayerType& descendant_layer, | 156 const LayerType& descendant_layer, |
157 gfx::Rect rect, | 157 const gfx::Rect& rect, |
158 TranslateRectDirection direction) { | 158 TranslateRectDirection direction) { |
159 gfx::Vector2dF translation = ComputeChangeOfBasisTranslation<LayerType>( | 159 gfx::Vector2dF translation = ComputeChangeOfBasisTranslation<LayerType>( |
160 ancestor_layer, descendant_layer); | 160 ancestor_layer, descendant_layer); |
161 if (direction == TranslateRectDirectionToDescendant) | 161 if (direction == TranslateRectDirectionToDescendant) |
162 translation.Scale(-1.f); | 162 translation.Scale(-1.f); |
163 return gfx::ToEnclosingRect( | 163 return gfx::ToEnclosingRect( |
164 gfx::RectF(rect.origin() + translation, rect.size())); | 164 gfx::RectF(rect.origin() + translation, rect.size())); |
165 } | 165 } |
166 | 166 |
167 // Attempts to update the clip rects for the given layer. If the layer has a | 167 // Attempts to update the clip rects for the given layer. If the layer has a |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 // The target owning the surface. (We hang onto the target rather than the | 233 // The target owning the surface. (We hang onto the target rather than the |
234 // surface so that we can DCHECK that the surface's draw transform is simply | 234 // surface so that we can DCHECK that the surface's draw transform is simply |
235 // a translation when |render_target| reports that it has no unclipped | 235 // a translation when |render_target| reports that it has no unclipped |
236 // descendants). | 236 // descendants). |
237 LayerType* render_target; | 237 LayerType* render_target; |
238 }; | 238 }; |
239 | 239 |
240 template <typename LayerType> | 240 template <typename LayerType> |
241 void UpdateAccumulatedSurfaceState( | 241 void UpdateAccumulatedSurfaceState( |
242 LayerType* layer, | 242 LayerType* layer, |
243 gfx::Rect drawable_content_rect, | 243 const gfx::Rect& drawable_content_rect, |
244 std::vector<AccumulatedSurfaceState<LayerType> >* | 244 std::vector<AccumulatedSurfaceState<LayerType> >* |
245 accumulated_surface_state) { | 245 accumulated_surface_state) { |
246 if (IsRootLayer(layer)) | 246 if (IsRootLayer(layer)) |
247 return; | 247 return; |
248 | 248 |
249 // We will apply our drawable content rect to the accumulated rects for all | 249 // We will apply our drawable content rect to the accumulated rects for all |
250 // surfaces between us and |render_target| (inclusive). This is either our | 250 // surfaces between us and |render_target| (inclusive). This is either our |
251 // clip parent's target if we are a clip child, or else simply our parent's | 251 // clip parent's target if we are a clip child, or else simply our parent's |
252 // target. We use our parent's target because we're either the owner of a | 252 // target. We use our parent's target because we're either the owner of a |
253 // render surface and we'll want to add our rect to our *surface's* target, or | 253 // render surface and we'll want to add our rect to our *surface's* target, or |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 } | 376 } |
377 | 377 |
378 template <typename LayerType> | 378 template <typename LayerType> |
379 static inline bool LayerClipsSubtree(LayerType* layer) { | 379 static inline bool LayerClipsSubtree(LayerType* layer) { |
380 return layer->masks_to_bounds() || layer->mask_layer(); | 380 return layer->masks_to_bounds() || layer->mask_layer(); |
381 } | 381 } |
382 | 382 |
383 template <typename LayerType> | 383 template <typename LayerType> |
384 static gfx::Rect CalculateVisibleContentRect( | 384 static gfx::Rect CalculateVisibleContentRect( |
385 LayerType* layer, | 385 LayerType* layer, |
386 gfx::Rect clip_rect_of_target_surface_in_target_space, | 386 const gfx::Rect& clip_rect_of_target_surface_in_target_space, |
387 gfx::Rect layer_rect_in_target_space) { | 387 const gfx::Rect& layer_rect_in_target_space) { |
388 DCHECK(layer->render_target()); | 388 DCHECK(layer->render_target()); |
389 | 389 |
390 // Nothing is visible if the layer bounds are empty. | 390 // Nothing is visible if the layer bounds are empty. |
391 if (!layer->DrawsContent() || layer->content_bounds().IsEmpty() || | 391 if (!layer->DrawsContent() || layer->content_bounds().IsEmpty() || |
392 layer->drawable_content_rect().IsEmpty()) | 392 layer->drawable_content_rect().IsEmpty()) |
393 return gfx::Rect(); | 393 return gfx::Rect(); |
394 | 394 |
395 // Compute visible bounds in target surface space. | 395 // Compute visible bounds in target surface space. |
396 gfx::Rect visible_rect_in_target_surface_space = | 396 gfx::Rect visible_rect_in_target_surface_space = |
397 layer->drawable_content_rect(); | 397 layer->drawable_content_rect(); |
(...skipping 1842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2240 // The dummy layer list should not have been used. | 2240 // The dummy layer list should not have been used. |
2241 DCHECK_EQ(0u, dummy_layer_list.size()); | 2241 DCHECK_EQ(0u, dummy_layer_list.size()); |
2242 // A root layer render_surface should always exist after | 2242 // A root layer render_surface should always exist after |
2243 // CalculateDrawProperties. | 2243 // CalculateDrawProperties. |
2244 DCHECK(inputs->root_layer->render_surface()); | 2244 DCHECK(inputs->root_layer->render_surface()); |
2245 } | 2245 } |
2246 | 2246 |
2247 static bool PointHitsRect( | 2247 static bool PointHitsRect( |
2248 gfx::PointF screen_space_point, | 2248 gfx::PointF screen_space_point, |
2249 const gfx::Transform& local_space_to_screen_space_transform, | 2249 const gfx::Transform& local_space_to_screen_space_transform, |
2250 gfx::RectF local_space_rect) { | 2250 const gfx::RectF& local_space_rect) { |
2251 // If the transform is not invertible, then assume that this point doesn't hit | 2251 // If the transform is not invertible, then assume that this point doesn't hit |
2252 // this rect. | 2252 // this rect. |
2253 gfx::Transform inverse_local_space_to_screen_space( | 2253 gfx::Transform inverse_local_space_to_screen_space( |
2254 gfx::Transform::kSkipInitialization); | 2254 gfx::Transform::kSkipInitialization); |
2255 if (!local_space_to_screen_space_transform.GetInverse( | 2255 if (!local_space_to_screen_space_transform.GetInverse( |
2256 &inverse_local_space_to_screen_space)) | 2256 &inverse_local_space_to_screen_space)) |
2257 return false; | 2257 return false; |
2258 | 2258 |
2259 // Transform the hit test point from screen space to the local space of the | 2259 // Transform the hit test point from screen space to the local space of the |
2260 // given rect. | 2260 // given rect. |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2416 // At this point, we think the point does hit the touch event handler region | 2416 // At this point, we think the point does hit the touch event handler region |
2417 // on the layer, but we need to walk up the parents to ensure that the layer | 2417 // on the layer, but we need to walk up the parents to ensure that the layer |
2418 // was not clipped in such a way that the hit point actually should not hit | 2418 // was not clipped in such a way that the hit point actually should not hit |
2419 // the layer. | 2419 // the layer. |
2420 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl)) | 2420 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl)) |
2421 return false; | 2421 return false; |
2422 | 2422 |
2423 return true; | 2423 return true; |
2424 } | 2424 } |
2425 } // namespace cc | 2425 } // namespace cc |
OLD | NEW |