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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 DCHECK_EQ(scrolls.size(), 0u); | 187 DCHECK_EQ(scrolls.size(), 0u); |
188 for (int i = 0; i < proto.scrolls_size(); ++i) { | 188 for (int i = 0; i < proto.scrolls_size(); ++i) { |
189 scrolls.push_back(LayerTreeHostCommon::ScrollUpdateInfo()); | 189 scrolls.push_back(LayerTreeHostCommon::ScrollUpdateInfo()); |
190 scrolls[i].FromProtobuf(proto.scrolls(i)); | 190 scrolls[i].FromProtobuf(proto.scrolls(i)); |
191 } | 191 } |
192 page_scale_delta = proto.page_scale_delta(); | 192 page_scale_delta = proto.page_scale_delta(); |
193 elastic_overscroll_delta = ProtoToVector2dF(proto.elastic_overscroll_delta()); | 193 elastic_overscroll_delta = ProtoToVector2dF(proto.elastic_overscroll_delta()); |
194 top_controls_delta = proto.top_controls_delta(); | 194 top_controls_delta = proto.top_controls_delta(); |
195 } | 195 } |
196 | 196 |
197 inline gfx::Rect CalculateVisibleRectWithCachedLayerRect( | |
198 const gfx::Rect& target_surface_rect, | |
199 const gfx::Rect& layer_bound_rect, | |
200 const gfx::Rect& layer_rect_in_target_space, | |
201 const gfx::Transform& transform) { | |
202 if (layer_rect_in_target_space.IsEmpty()) | |
203 return gfx::Rect(); | |
204 | |
205 // Is this layer fully contained within the target surface? | |
206 if (target_surface_rect.Contains(layer_rect_in_target_space)) | |
207 return layer_bound_rect; | |
208 | |
209 // If the layer doesn't fill up the entire surface, then find the part of | |
210 // the surface rect where the layer could be visible. This avoids trying to | |
211 // project surface rect points that are behind the projection point. | |
212 gfx::Rect minimal_surface_rect = target_surface_rect; | |
213 minimal_surface_rect.Intersect(layer_rect_in_target_space); | |
214 | |
215 if (minimal_surface_rect.IsEmpty()) | |
216 return gfx::Rect(); | |
217 | |
218 // Project the corners of the target surface rect into the layer space. | |
219 // This bounding rectangle may be larger than it needs to be (being | |
220 // axis-aligned), but is a reasonable filter on the space to consider. | |
221 // Non-invertible transforms will create an empty rect here. | |
222 | |
223 gfx::Transform surface_to_layer(gfx::Transform::kSkipInitialization); | |
224 if (!transform.GetInverse(&surface_to_layer)) { | |
225 // Because we cannot use the surface bounds to determine what portion of | |
226 // the layer is visible, we must conservatively assume the full layer is | |
227 // visible. | |
228 return layer_bound_rect; | |
229 } | |
230 | |
231 gfx::Rect layer_rect = MathUtil::ProjectEnclosingClippedRect( | |
232 surface_to_layer, minimal_surface_rect); | |
233 layer_rect.Intersect(layer_bound_rect); | |
234 return layer_rect; | |
235 } | |
236 | |
237 gfx::Rect LayerTreeHostCommon::CalculateVisibleRect( | |
238 const gfx::Rect& target_surface_rect, | |
239 const gfx::Rect& layer_bound_rect, | |
240 const gfx::Transform& transform) { | |
241 gfx::Rect layer_in_surface_space = | |
242 MathUtil::MapEnclosingClippedRect(transform, layer_bound_rect); | |
243 return CalculateVisibleRectWithCachedLayerRect( | |
244 target_surface_rect, layer_bound_rect, layer_in_surface_space, transform); | |
245 } | |
246 | |
247 static inline bool IsRootLayer(const Layer* layer) { | 197 static inline bool IsRootLayer(const Layer* layer) { |
248 return !layer->parent(); | 198 return !layer->parent(); |
249 } | 199 } |
250 | 200 |
251 static inline bool IsRootLayer(const LayerImpl* layer) { | 201 static inline bool IsRootLayer(const LayerImpl* layer) { |
252 return layer->layer_tree_impl()->IsRootLayer(layer); | 202 return layer->layer_tree_impl()->IsRootLayer(layer); |
253 } | 203 } |
254 | 204 |
255 template <typename LayerType> | 205 template <typename LayerType> |
256 static bool HasInvertibleOrAnimatedTransform(LayerType* layer) { | 206 static bool HasInvertibleOrAnimatedTransform(LayerType* layer) { |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 | 609 |
660 // The render surface's content rect is the union of drawable content rects | 610 // The render surface's content rect is the union of drawable content rects |
661 // of the layers that draw into the surface. If the render surface is clipped, | 611 // of the layers that draw into the surface. If the render surface is clipped, |
662 // it is also intersected with the render's surface clip rect. | 612 // it is also intersected with the render's surface clip rect. |
663 if (!IsRootLayer(layer)) { | 613 if (!IsRootLayer(layer)) { |
664 // Layer contriubutes its drawable content rect to its render target. | 614 // Layer contriubutes its drawable content rect to its render target. |
665 if (layer->DrawsContent()) | 615 if (layer->DrawsContent()) |
666 layer->render_target()->AccumulateContentRectFromContributingLayer(layer); | 616 layer->render_target()->AccumulateContentRectFromContributingLayer(layer); |
667 | 617 |
668 if (render_to_separate_surface) { | 618 if (render_to_separate_surface) { |
669 gfx::Rect surface_content_rect = | 619 // Now all contributing drawable content rect has been accumulated to this |
670 layer->render_surface()->accumulated_content_rect(); | 620 // render surface, calculate the content rect. |
671 | 621 layer->render_surface()->CalculateContentRectFromAccumulatedContentRect( |
672 if (!layer->replica_layer() && !layer->HasCopyRequest() && | 622 max_texture_size); |
673 layer->render_surface()->is_clipped()) { | |
674 // Here, we clip the render surface's content rect with its clip rect. | |
675 // As the clip rect of render surface is in the surface's target | |
676 // space, we first map the content rect into the target space, | |
677 // intersect it with clip rect and project back the result to the | |
678 // surface space. | |
679 if (!surface_content_rect.IsEmpty()) { | |
680 gfx::Rect surface_clip_rect = | |
681 LayerTreeHostCommon::CalculateVisibleRect( | |
682 layer->render_surface()->clip_rect(), surface_content_rect, | |
683 layer->render_surface()->draw_transform()); | |
684 surface_content_rect.Intersect(surface_clip_rect); | |
685 } | |
686 } | |
687 // The RenderSurfaceImpl backing texture cannot exceed the maximum | |
688 // supported texture size. | |
689 surface_content_rect.set_width( | |
690 std::min(surface_content_rect.width(), max_texture_size)); | |
691 surface_content_rect.set_height( | |
692 std::min(surface_content_rect.height(), max_texture_size)); | |
693 layer->render_surface()->SetContentRect(surface_content_rect); | |
694 | |
695 // Now the render surface's content rect is calculated correctly, it could | 623 // Now the render surface's content rect is calculated correctly, it could |
696 // contribute to its render target. | 624 // contribute to its render target. |
697 layer->render_surface() | 625 layer->render_surface() |
698 ->render_target() | 626 ->render_target() |
699 ->AccumulateContentRectFromContributingRenderSurface( | 627 ->AccumulateContentRectFromContributingRenderSurface( |
700 layer->render_surface()); | 628 layer->render_surface()); |
701 } | 629 } |
702 } else { | 630 } else { |
703 // The root layer's surface content rect is always the entire viewport. | 631 // The root layer's surface content rect is always the entire viewport. |
704 gfx::Rect viewport = | 632 layer->render_surface()->SetContentRectToViewport(); |
705 gfx::ToEnclosingRect(property_trees->clip_tree.ViewportClip()); | |
706 layer->render_surface()->SetContentRect(viewport); | |
707 } | 633 } |
708 | 634 |
709 if (render_to_separate_surface && !IsRootLayer(layer) && | 635 if (render_to_separate_surface && !IsRootLayer(layer) && |
710 layer->render_surface()->DrawableContentRect().IsEmpty()) { | 636 layer->render_surface()->DrawableContentRect().IsEmpty()) { |
711 RemoveSurfaceForEarlyExit(layer, render_surface_layer_list); | 637 RemoveSurfaceForEarlyExit(layer, render_surface_layer_list); |
712 return; | 638 return; |
713 } | 639 } |
714 | 640 |
715 // If neither this layer nor any of its children were added, early out. | 641 // If neither this layer nor any of its children were added, early out. |
716 if (descendants_size == descendants->size()) { | 642 if (descendants_size == descendants->size()) { |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 | 855 |
930 PropertyTrees* GetPropertyTrees(Layer* layer) { | 856 PropertyTrees* GetPropertyTrees(Layer* layer) { |
931 return layer->layer_tree_host()->property_trees(); | 857 return layer->layer_tree_host()->property_trees(); |
932 } | 858 } |
933 | 859 |
934 PropertyTrees* GetPropertyTrees(LayerImpl* layer) { | 860 PropertyTrees* GetPropertyTrees(LayerImpl* layer) { |
935 return layer->layer_tree_impl()->property_trees(); | 861 return layer->layer_tree_impl()->property_trees(); |
936 } | 862 } |
937 | 863 |
938 } // namespace cc | 864 } // namespace cc |
OLD | NEW |