| 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_impl.h" | 5 #include "cc/trees/layer_tree_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 gfx::SizeF bounds = gfx::SizeF(layer->bounds()); | 373 gfx::SizeF bounds = gfx::SizeF(layer->bounds()); |
| 374 if (clip_node->clip.size() != bounds) { | 374 if (clip_node->clip.size() != bounds) { |
| 375 clip_node->clip.set_size(bounds); | 375 clip_node->clip.set_size(bounds); |
| 376 clip_tree->set_needs_update(true); | 376 clip_tree->set_needs_update(true); |
| 377 } | 377 } |
| 378 } | 378 } |
| 379 } | 379 } |
| 380 } | 380 } |
| 381 | 381 |
| 382 void LayerTreeImpl::SetPropertyTrees(PropertyTrees* property_trees) { | 382 void LayerTreeImpl::SetPropertyTrees(PropertyTrees* property_trees) { |
| 383 EffectTree::StableIdRenderSurfaceList stable_id_render_surface_list = | 383 std::vector<std::unique_ptr<RenderSurfaceImpl>> old_render_surfaces; |
| 384 property_trees_.effect_tree.CreateStableIdRenderSurfaceList(); | 384 property_trees_.effect_tree.TakeRenderSurfaces(&old_render_surfaces); |
| 385 property_trees_ = *property_trees; | 385 property_trees_ = *property_trees; |
| 386 property_trees_.effect_tree.UpdateRenderSurfaceEffectIds( | 386 bool render_surfaces_changed = |
| 387 stable_id_render_surface_list, this); | 387 property_trees_.effect_tree.CreateOrReuseRenderSurfaces( |
| 388 &old_render_surfaces, this); |
| 389 if (render_surfaces_changed) |
| 390 set_needs_update_draw_properties(); |
| 388 property_trees->effect_tree.PushCopyRequestsTo(&property_trees_.effect_tree); | 391 property_trees->effect_tree.PushCopyRequestsTo(&property_trees_.effect_tree); |
| 389 property_trees_.is_main_thread = false; | 392 property_trees_.is_main_thread = false; |
| 390 property_trees_.is_active = IsActiveTree(); | 393 property_trees_.is_active = IsActiveTree(); |
| 391 property_trees_.transform_tree.set_source_to_parent_updates_allowed(false); | 394 property_trees_.transform_tree.set_source_to_parent_updates_allowed(false); |
| 392 // The value of some effect node properties (like is_drawn) depends on | 395 // The value of some effect node properties (like is_drawn) depends on |
| 393 // whether we are on the active tree or not. So, we need to update the | 396 // whether we are on the active tree or not. So, we need to update the |
| 394 // effect tree. | 397 // effect tree. |
| 395 if (IsActiveTree()) | 398 if (IsActiveTree()) |
| 396 property_trees_.effect_tree.set_needs_update(true); | 399 property_trees_.effect_tree.set_needs_update(true); |
| 397 } | 400 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 target_tree->has_ever_been_drawn_ = false; | 500 target_tree->has_ever_been_drawn_ = false; |
| 498 } | 501 } |
| 499 | 502 |
| 500 void LayerTreeImpl::MoveChangeTrackingToLayers() { | 503 void LayerTreeImpl::MoveChangeTrackingToLayers() { |
| 501 // We need to update the change tracking on property trees before we move it | 504 // We need to update the change tracking on property trees before we move it |
| 502 // onto the layers. | 505 // onto the layers. |
| 503 property_trees_.UpdateChangeTracking(); | 506 property_trees_.UpdateChangeTracking(); |
| 504 for (auto* layer : *this) { | 507 for (auto* layer : *this) { |
| 505 if (layer->LayerPropertyChanged()) | 508 if (layer->LayerPropertyChanged()) |
| 506 layer->NoteLayerPropertyChanged(); | 509 layer->NoteLayerPropertyChanged(); |
| 507 if (layer->render_surface() && | 510 } |
| 508 layer->render_surface()->AncestorPropertyChanged()) | 511 EffectTree& effect_tree = property_trees_.effect_tree; |
| 509 layer->render_surface()->NoteAncestorPropertyChanged(); | 512 for (int id = EffectTree::kContentsRootNodeId; |
| 513 id < static_cast<int>(effect_tree.size()); ++id) { |
| 514 RenderSurfaceImpl* render_surface = effect_tree.GetRenderSurface(id); |
| 515 if (render_surface && render_surface->AncestorPropertyChanged()) |
| 516 render_surface->NoteAncestorPropertyChanged(); |
| 510 } | 517 } |
| 511 } | 518 } |
| 512 | 519 |
| 513 void LayerTreeImpl::ForceRecalculateRasterScales() { | 520 void LayerTreeImpl::ForceRecalculateRasterScales() { |
| 514 for (auto* layer : picture_layers_) | 521 for (auto* layer : picture_layers_) |
| 515 layer->ResetRasterScale(); | 522 layer->ResetRasterScale(); |
| 516 } | 523 } |
| 517 | 524 |
| 518 LayerImplList::const_iterator LayerTreeImpl::begin() const { | 525 LayerImplList::const_iterator LayerTreeImpl::begin() const { |
| 519 return layer_list_.cbegin(); | 526 return layer_list_.cbegin(); |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1041 | 1048 |
| 1042 if (it.represents_itself()) { | 1049 if (it.represents_itself()) { |
| 1043 it->draw_properties().occlusion_in_content_space = | 1050 it->draw_properties().occlusion_in_content_space = |
| 1044 occlusion_tracker.GetCurrentOcclusionForLayer(it->DrawTransform()); | 1051 occlusion_tracker.GetCurrentOcclusionForLayer(it->DrawTransform()); |
| 1045 } | 1052 } |
| 1046 | 1053 |
| 1047 if (it.represents_contributing_render_surface()) { | 1054 if (it.represents_contributing_render_surface()) { |
| 1048 const RenderSurfaceImpl* occlusion_surface = | 1055 const RenderSurfaceImpl* occlusion_surface = |
| 1049 occlusion_tracker.OcclusionSurfaceForContributingSurface(); | 1056 occlusion_tracker.OcclusionSurfaceForContributingSurface(); |
| 1050 gfx::Transform draw_transform; | 1057 gfx::Transform draw_transform; |
| 1058 RenderSurfaceImpl* render_surface = it->render_surface(); |
| 1051 if (occlusion_surface) { | 1059 if (occlusion_surface) { |
| 1052 // We are calculating transform between two render surfaces. So, we | 1060 // We are calculating transform between two render surfaces. So, we |
| 1053 // need to apply the surface contents scale at target and remove the | 1061 // need to apply the surface contents scale at target and remove the |
| 1054 // surface contents scale at source. | 1062 // surface contents scale at source. |
| 1055 property_trees()->GetToTarget( | 1063 property_trees()->GetToTarget(render_surface->TransformTreeIndex(), |
| 1056 it->render_surface()->TransformTreeIndex(), | 1064 occlusion_surface->EffectTreeIndex(), |
| 1057 occlusion_surface->EffectTreeIndex(), &draw_transform); | 1065 &draw_transform); |
| 1058 const EffectNode* effect_node = property_trees()->effect_tree.Node( | 1066 const EffectNode* effect_node = property_trees()->effect_tree.Node( |
| 1059 it->render_surface()->EffectTreeIndex()); | 1067 render_surface->EffectTreeIndex()); |
| 1060 draw_property_utils::ConcatInverseSurfaceContentsScale( | 1068 draw_property_utils::ConcatInverseSurfaceContentsScale( |
| 1061 effect_node, &draw_transform); | 1069 effect_node, &draw_transform); |
| 1062 } | 1070 } |
| 1063 | 1071 |
| 1064 Occlusion occlusion = | 1072 Occlusion occlusion = |
| 1065 occlusion_tracker.GetCurrentOcclusionForContributingSurface( | 1073 occlusion_tracker.GetCurrentOcclusionForContributingSurface( |
| 1066 draw_transform); | 1074 draw_transform); |
| 1067 it->render_surface()->set_occlusion_in_content_space(occlusion); | 1075 render_surface->set_occlusion_in_content_space(occlusion); |
| 1068 // Masks are used to draw the contributing surface, so should have | 1076 // Masks are used to draw the contributing surface, so should have |
| 1069 // the same occlusion as the surface (nothing inside the surface | 1077 // the same occlusion as the surface (nothing inside the surface |
| 1070 // occludes them). | 1078 // occludes them). |
| 1071 if (LayerImpl* mask = it->render_surface()->MaskLayer()) { | 1079 if (LayerImpl* mask = render_surface->MaskLayer()) { |
| 1072 mask->draw_properties().occlusion_in_content_space = | 1080 mask->draw_properties().occlusion_in_content_space = |
| 1073 occlusion_tracker.GetCurrentOcclusionForContributingSurface( | 1081 occlusion_tracker.GetCurrentOcclusionForContributingSurface( |
| 1074 draw_transform * it->DrawTransform()); | 1082 draw_transform * it->DrawTransform()); |
| 1075 } | 1083 } |
| 1076 } | 1084 } |
| 1077 | 1085 |
| 1078 occlusion_tracker.LeaveLayer(it); | 1086 occlusion_tracker.LeaveLayer(it); |
| 1079 } | 1087 } |
| 1080 | 1088 |
| 1081 unoccluded_screen_space_region_ = | 1089 unoccluded_screen_space_region_ = |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1761 return false; | 1769 return false; |
| 1762 | 1770 |
| 1763 return layer_space_region.Contains( | 1771 return layer_space_region.Contains( |
| 1764 gfx::ToRoundedPoint(hit_test_point_in_layer_space)); | 1772 gfx::ToRoundedPoint(hit_test_point_in_layer_space)); |
| 1765 } | 1773 } |
| 1766 | 1774 |
| 1767 static const gfx::Transform SurfaceScreenSpaceTransform( | 1775 static const gfx::Transform SurfaceScreenSpaceTransform( |
| 1768 const LayerImpl* layer) { | 1776 const LayerImpl* layer) { |
| 1769 const PropertyTrees* property_trees = | 1777 const PropertyTrees* property_trees = |
| 1770 layer->layer_tree_impl()->property_trees(); | 1778 layer->layer_tree_impl()->property_trees(); |
| 1771 DCHECK(layer->render_surface()); | 1779 RenderSurfaceImpl* render_surface = layer->render_surface(); |
| 1780 DCHECK(render_surface); |
| 1772 return layer->is_drawn_render_surface_layer_list_member() | 1781 return layer->is_drawn_render_surface_layer_list_member() |
| 1773 ? layer->render_surface()->screen_space_transform() | 1782 ? render_surface->screen_space_transform() |
| 1774 : property_trees | 1783 : property_trees |
| 1775 ->ToScreenSpaceTransformWithoutSurfaceContentsScale( | 1784 ->ToScreenSpaceTransformWithoutSurfaceContentsScale( |
| 1776 layer->render_surface()->TransformTreeIndex(), | 1785 render_surface->TransformTreeIndex(), |
| 1777 layer->render_surface()->EffectTreeIndex()); | 1786 render_surface->EffectTreeIndex()); |
| 1778 } | 1787 } |
| 1779 | 1788 |
| 1780 static bool PointIsClippedByAncestorClipNode( | 1789 static bool PointIsClippedByAncestorClipNode( |
| 1781 const gfx::PointF& screen_space_point, | 1790 const gfx::PointF& screen_space_point, |
| 1782 const LayerImpl* layer) { | 1791 const LayerImpl* layer) { |
| 1783 // We need to visit all ancestor clip nodes to check this. Checking with just | 1792 // We need to visit all ancestor clip nodes to check this. Checking with just |
| 1784 // the combined clip stored at a clip node is not enough because parent | 1793 // the combined clip stored at a clip node is not enough because parent |
| 1785 // combined clip can sometimes be smaller than current combined clip. This can | 1794 // combined clip can sometimes be smaller than current combined clip. This can |
| 1786 // happen when we have transforms like rotation that inflate the combined | 1795 // happen when we have transforms like rotation that inflate the combined |
| 1787 // clip's bounds. Also, the point can be clipped by the content rect of an | 1796 // clip's bounds. Also, the point can be clipped by the content rect of an |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1805 | 1814 |
| 1806 gfx::Transform screen_space_transform = | 1815 gfx::Transform screen_space_transform = |
| 1807 transform_tree.ToScreen(clip_node->transform_id); | 1816 transform_tree.ToScreen(clip_node->transform_id); |
| 1808 if (!PointHitsRect(screen_space_point, screen_space_transform, clip, | 1817 if (!PointHitsRect(screen_space_point, screen_space_transform, clip, |
| 1809 NULL)) { | 1818 NULL)) { |
| 1810 return true; | 1819 return true; |
| 1811 } | 1820 } |
| 1812 } | 1821 } |
| 1813 const LayerImpl* clip_node_owner = | 1822 const LayerImpl* clip_node_owner = |
| 1814 layer->layer_tree_impl()->LayerById(clip_node->owning_layer_id); | 1823 layer->layer_tree_impl()->LayerById(clip_node->owning_layer_id); |
| 1815 if (clip_node_owner->render_surface() && | 1824 RenderSurfaceImpl* render_surface = clip_node_owner->render_surface(); |
| 1816 !PointHitsRect( | 1825 if (render_surface && |
| 1817 screen_space_point, SurfaceScreenSpaceTransform(clip_node_owner), | 1826 !PointHitsRect(screen_space_point, |
| 1818 clip_node_owner->render_surface()->content_rect(), NULL)) { | 1827 SurfaceScreenSpaceTransform(clip_node_owner), |
| 1828 render_surface->content_rect(), NULL)) { |
| 1819 return true; | 1829 return true; |
| 1820 } | 1830 } |
| 1821 } | 1831 } |
| 1822 return false; | 1832 return false; |
| 1823 } | 1833 } |
| 1824 | 1834 |
| 1825 static bool PointIsClippedBySurfaceOrClipRect( | 1835 static bool PointIsClippedBySurfaceOrClipRect( |
| 1826 const gfx::PointF& screen_space_point, | 1836 const gfx::PointF& screen_space_point, |
| 1827 const LayerImpl* layer) { | 1837 const LayerImpl* layer) { |
| 1828 // Walk up the layer tree and hit-test any render_surfaces and any layer | 1838 // Walk up the layer tree and hit-test any render_surfaces and any layer |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2093 | 2103 |
| 2094 void LayerTreeImpl::ResetAllChangeTracking() { | 2104 void LayerTreeImpl::ResetAllChangeTracking() { |
| 2095 layers_that_should_push_properties_.clear(); | 2105 layers_that_should_push_properties_.clear(); |
| 2096 // Iterate over all layers, including masks. | 2106 // Iterate over all layers, including masks. |
| 2097 for (auto& layer : *layers_) | 2107 for (auto& layer : *layers_) |
| 2098 layer->ResetChangeTracking(); | 2108 layer->ResetChangeTracking(); |
| 2099 property_trees_.ResetAllChangeTracking(); | 2109 property_trees_.ResetAllChangeTracking(); |
| 2100 } | 2110 } |
| 2101 | 2111 |
| 2102 } // namespace cc | 2112 } // namespace cc |
| OLD | NEW |