| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 DCHECK_EQ(scrolls.size(), 0u); | 188 DCHECK_EQ(scrolls.size(), 0u); |
| 189 for (int i = 0; i < proto.scrolls_size(); ++i) { | 189 for (int i = 0; i < proto.scrolls_size(); ++i) { |
| 190 scrolls.push_back(LayerTreeHostCommon::ScrollUpdateInfo()); | 190 scrolls.push_back(LayerTreeHostCommon::ScrollUpdateInfo()); |
| 191 scrolls[i].FromProtobuf(proto.scrolls(i)); | 191 scrolls[i].FromProtobuf(proto.scrolls(i)); |
| 192 } | 192 } |
| 193 page_scale_delta = proto.page_scale_delta(); | 193 page_scale_delta = proto.page_scale_delta(); |
| 194 elastic_overscroll_delta = ProtoToVector2dF(proto.elastic_overscroll_delta()); | 194 elastic_overscroll_delta = ProtoToVector2dF(proto.elastic_overscroll_delta()); |
| 195 top_controls_delta = proto.top_controls_delta(); | 195 top_controls_delta = proto.top_controls_delta(); |
| 196 } | 196 } |
| 197 | 197 |
| 198 inline gfx::Rect CalculateVisibleRectWithCachedLayerRect( | |
| 199 const gfx::Rect& target_surface_rect, | |
| 200 const gfx::Rect& layer_bound_rect, | |
| 201 const gfx::Rect& layer_rect_in_target_space, | |
| 202 const gfx::Transform& transform) { | |
| 203 if (layer_rect_in_target_space.IsEmpty()) | |
| 204 return gfx::Rect(); | |
| 205 | |
| 206 // Is this layer fully contained within the target surface? | |
| 207 if (target_surface_rect.Contains(layer_rect_in_target_space)) | |
| 208 return layer_bound_rect; | |
| 209 | |
| 210 // If the layer doesn't fill up the entire surface, then find the part of | |
| 211 // the surface rect where the layer could be visible. This avoids trying to | |
| 212 // project surface rect points that are behind the projection point. | |
| 213 gfx::Rect minimal_surface_rect = target_surface_rect; | |
| 214 minimal_surface_rect.Intersect(layer_rect_in_target_space); | |
| 215 | |
| 216 if (minimal_surface_rect.IsEmpty()) | |
| 217 return gfx::Rect(); | |
| 218 | |
| 219 // Project the corners of the target surface rect into the layer space. | |
| 220 // This bounding rectangle may be larger than it needs to be (being | |
| 221 // axis-aligned), but is a reasonable filter on the space to consider. | |
| 222 // Non-invertible transforms will create an empty rect here. | |
| 223 | |
| 224 gfx::Transform surface_to_layer(gfx::Transform::kSkipInitialization); | |
| 225 if (!transform.GetInverse(&surface_to_layer)) { | |
| 226 // Because we cannot use the surface bounds to determine what portion of | |
| 227 // the layer is visible, we must conservatively assume the full layer is | |
| 228 // visible. | |
| 229 return layer_bound_rect; | |
| 230 } | |
| 231 | |
| 232 gfx::Rect layer_rect = MathUtil::ProjectEnclosingClippedRect( | |
| 233 surface_to_layer, minimal_surface_rect); | |
| 234 layer_rect.Intersect(layer_bound_rect); | |
| 235 return layer_rect; | |
| 236 } | |
| 237 | |
| 238 gfx::Rect LayerTreeHostCommon::CalculateVisibleRect( | |
| 239 const gfx::Rect& target_surface_rect, | |
| 240 const gfx::Rect& layer_bound_rect, | |
| 241 const gfx::Transform& transform) { | |
| 242 gfx::Rect layer_in_surface_space = | |
| 243 MathUtil::MapEnclosingClippedRect(transform, layer_bound_rect); | |
| 244 return CalculateVisibleRectWithCachedLayerRect( | |
| 245 target_surface_rect, layer_bound_rect, layer_in_surface_space, transform); | |
| 246 } | |
| 247 | |
| 248 static inline bool IsRootLayer(const Layer* layer) { | 198 static inline bool IsRootLayer(const Layer* layer) { |
| 249 return !layer->parent(); | 199 return !layer->parent(); |
| 250 } | 200 } |
| 251 | 201 |
| 252 template <typename LayerType> | 202 template <typename LayerType> |
| 253 static bool HasInvertibleOrAnimatedTransform(LayerType* layer) { | 203 static bool HasInvertibleOrAnimatedTransform(LayerType* layer) { |
| 254 return layer->transform_is_invertible() || | 204 return layer->transform_is_invertible() || |
| 255 layer->HasPotentiallyRunningTransformAnimation(); | 205 layer->HasPotentiallyRunningTransformAnimation(); |
| 256 } | 206 } |
| 257 | 207 |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 | 560 |
| 611 static void ComputeSurfaceContentRects(LayerTreeImpl* layer_tree_impl, | 561 static void ComputeSurfaceContentRects(LayerTreeImpl* layer_tree_impl, |
| 612 PropertyTrees* property_trees, | 562 PropertyTrees* property_trees, |
| 613 LayerImplList* render_surface_layer_list, | 563 LayerImplList* render_surface_layer_list, |
| 614 int max_texture_size) { | 564 int max_texture_size) { |
| 615 // Walk the list backwards, accumulating each surface's content rect into its | 565 // Walk the list backwards, accumulating each surface's content rect into its |
| 616 // target's content rect. | 566 // target's content rect. |
| 617 for (LayerImpl* layer : base::Reversed(*render_surface_layer_list)) { | 567 for (LayerImpl* layer : base::Reversed(*render_surface_layer_list)) { |
| 618 if (layer_tree_impl->IsRootLayer(layer)) { | 568 if (layer_tree_impl->IsRootLayer(layer)) { |
| 619 // The root layer's surface content rect is always the entire viewport. | 569 // The root layer's surface content rect is always the entire viewport. |
| 620 gfx::Rect viewport = | 570 layer->render_surface()->SetContentRectToViewport(); |
| 621 gfx::ToEnclosingRect(property_trees->clip_tree.ViewportClip()); | |
| 622 layer->render_surface()->SetContentRect(viewport); | |
| 623 continue; | 571 continue; |
| 624 } | 572 } |
| 625 | |
| 626 RenderSurfaceImpl* surface = layer->render_surface(); | 573 RenderSurfaceImpl* surface = layer->render_surface(); |
| 627 gfx::Rect surface_content_rect = surface->accumulated_content_rect(); | 574 // Now all contributing drawable content rect has been accumulated to this |
| 628 | 575 // render surface, calculate the content rect. |
| 629 if (!layer->replica_layer() && !layer->HasCopyRequest() && | 576 surface->CalculateContentRectFromAccumulatedContentRect(max_texture_size); |
| 630 surface->is_clipped()) { | |
| 631 // Here, we clip the render surface's content rect with its clip rect. | |
| 632 // As the clip rect of render surface is in the surface's target | |
| 633 // space, we first map the content rect into the target space, | |
| 634 // intersect it with clip rect and project back the result to the | |
| 635 // surface space. | |
| 636 if (!surface_content_rect.IsEmpty()) { | |
| 637 gfx::Rect surface_clip_rect = LayerTreeHostCommon::CalculateVisibleRect( | |
| 638 surface->clip_rect(), surface_content_rect, | |
| 639 surface->draw_transform()); | |
| 640 surface_content_rect.Intersect(surface_clip_rect); | |
| 641 } | |
| 642 } | |
| 643 // The RenderSurfaceImpl backing texture cannot exceed the maximum | |
| 644 // supported texture size. | |
| 645 surface_content_rect.set_width( | |
| 646 std::min(surface_content_rect.width(), max_texture_size)); | |
| 647 surface_content_rect.set_height( | |
| 648 std::min(surface_content_rect.height(), max_texture_size)); | |
| 649 surface->SetContentRect(surface_content_rect); | |
| 650 | 577 |
| 651 // Now the render surface's content rect is calculated correctly, it could | 578 // Now the render surface's content rect is calculated correctly, it could |
| 652 // contribute to its render target. | 579 // contribute to its render target. |
| 653 surface->render_target() | 580 surface->render_target() |
| 654 ->AccumulateContentRectFromContributingRenderSurface(surface); | 581 ->AccumulateContentRectFromContributingRenderSurface(surface); |
| 655 } | 582 } |
| 656 } | 583 } |
| 657 | 584 |
| 658 static void ComputeListOfNonEmptySurfaces( | 585 static void ComputeListOfNonEmptySurfaces( |
| 659 LayerTreeImpl* layer_tree_impl, | 586 LayerTreeImpl* layer_tree_impl, |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 | 863 |
| 937 PropertyTrees* GetPropertyTrees(Layer* layer) { | 864 PropertyTrees* GetPropertyTrees(Layer* layer) { |
| 938 return layer->layer_tree_host()->property_trees(); | 865 return layer->layer_tree_host()->property_trees(); |
| 939 } | 866 } |
| 940 | 867 |
| 941 PropertyTrees* GetPropertyTrees(LayerImpl* layer) { | 868 PropertyTrees* GetPropertyTrees(LayerImpl* layer) { |
| 942 return layer->layer_tree_impl()->property_trees(); | 869 return layer->layer_tree_impl()->property_trees(); |
| 943 } | 870 } |
| 944 | 871 |
| 945 } // namespace cc | 872 } // namespace cc |
| OLD | NEW |