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

Side by Side Diff: cc/trees/layer_tree_host_common.cc

Issue 817653003: Update from https://crrev.com/309717 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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_host_common.h ('k') | cc/trees/layer_tree_host_common_perftest.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_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 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 546
547 static inline void SavePaintPropertiesLayer(Layer* layer) { 547 static inline void SavePaintPropertiesLayer(Layer* layer) {
548 layer->SavePaintProperties(); 548 layer->SavePaintProperties();
549 549
550 if (layer->mask_layer()) 550 if (layer->mask_layer())
551 layer->mask_layer()->SavePaintProperties(); 551 layer->mask_layer()->SavePaintProperties();
552 if (layer->replica_layer() && layer->replica_layer()->mask_layer()) 552 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
553 layer->replica_layer()->mask_layer()->SavePaintProperties(); 553 layer->replica_layer()->mask_layer()->SavePaintProperties();
554 } 554 }
555 555
556 template <typename LayerType>
557 static bool SubtreeShouldRenderToSeparateSurface( 556 static bool SubtreeShouldRenderToSeparateSurface(
558 LayerType* layer, 557 Layer* layer,
559 bool axis_aligned_with_respect_to_parent) { 558 bool axis_aligned_with_respect_to_parent) {
560 // 559 //
561 // A layer and its descendants should render onto a new RenderSurfaceImpl if 560 // A layer and its descendants should render onto a new RenderSurfaceImpl if
562 // any of these rules hold: 561 // any of these rules hold:
563 // 562 //
564 563
565 // The root layer owns a render surface, but it never acts as a contributing 564 // The root layer owns a render surface, but it never acts as a contributing
566 // surface to another render target. Compositor features that are applied via 565 // surface to another render target. Compositor features that are applied via
567 // a contributing surface can not be applied to the root layer. In order to 566 // a contributing surface can not be applied to the root layer. In order to
568 // use these effects, another child of the root would need to be introduced 567 // use these effects, another child of the root would need to be introduced
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 *combined_maximum_animation_contents_scale = 0.f; 1103 *combined_maximum_animation_contents_scale = 0.f;
1105 return; 1104 return;
1106 } 1105 }
1107 gfx::Vector2dF ancestor_transform_scales = 1106 gfx::Vector2dF ancestor_transform_scales =
1108 MathUtil::ComputeTransform2dScaleComponents(ancestor_transform, 0.f); 1107 MathUtil::ComputeTransform2dScaleComponents(ancestor_transform, 0.f);
1109 *combined_maximum_animation_contents_scale = 1108 *combined_maximum_animation_contents_scale =
1110 layer_maximum_animated_scale * 1109 layer_maximum_animated_scale *
1111 std::max(ancestor_transform_scales.x(), ancestor_transform_scales.y()); 1110 std::max(ancestor_transform_scales.x(), ancestor_transform_scales.y());
1112 } 1111 }
1113 1112
1114 template <typename LayerType>
1115 static inline typename LayerType::RenderSurfaceType* CreateOrReuseRenderSurface(
1116 LayerType* layer) {
1117 if (!layer->render_surface()) {
1118 layer->CreateRenderSurface();
1119 return layer->render_surface();
1120 }
1121
1122 layer->render_surface()->ClearLayerLists();
1123 return layer->render_surface();
1124 }
1125
1126 template <typename LayerTypePtr> 1113 template <typename LayerTypePtr>
1127 static inline void MarkLayerWithRenderSurfaceLayerListId( 1114 static inline void MarkLayerWithRenderSurfaceLayerListId(
1128 LayerTypePtr layer, 1115 LayerTypePtr layer,
1129 int current_render_surface_layer_list_id) { 1116 int current_render_surface_layer_list_id) {
1130 layer->draw_properties().last_drawn_render_surface_layer_list_id = 1117 layer->draw_properties().last_drawn_render_surface_layer_list_id =
1131 current_render_surface_layer_list_id; 1118 current_render_surface_layer_list_id;
1132 } 1119 }
1133 1120
1134 template <typename LayerTypePtr> 1121 template <typename LayerTypePtr>
1135 static inline void MarkMasksWithRenderSurfaceLayerListId( 1122 static inline void MarkMasksWithRenderSurfaceLayerListId(
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 void Merge(const PreCalculateMetaInformationRecursiveData& data) { 1186 void Merge(const PreCalculateMetaInformationRecursiveData& data) {
1200 layer_or_descendant_has_copy_request |= 1187 layer_or_descendant_has_copy_request |=
1201 data.layer_or_descendant_has_copy_request; 1188 data.layer_or_descendant_has_copy_request;
1202 layer_or_descendant_has_input_handler |= 1189 layer_or_descendant_has_input_handler |=
1203 data.layer_or_descendant_has_input_handler; 1190 data.layer_or_descendant_has_input_handler;
1204 num_unclipped_descendants += 1191 num_unclipped_descendants +=
1205 data.num_unclipped_descendants; 1192 data.num_unclipped_descendants;
1206 } 1193 }
1207 }; 1194 };
1208 1195
1196 static bool ValidateRenderSurface(LayerImpl* layer) {
1197 // There are a few cases in which it is incorrect to not have a
1198 // render_surface.
1199 if (layer->render_surface())
1200 return true;
1201
1202 return layer->filters().IsEmpty() && layer->background_filters().IsEmpty() &&
1203 !layer->mask_layer() && !layer->replica_layer() &&
1204 !IsRootLayer(layer) && !layer->is_root_for_isolated_group() &&
1205 !layer->HasCopyRequest();
1206 }
1207
1208 static bool ValidateRenderSurface(Layer* layer) {
1209 return true;
1210 }
1211
1209 // Recursively walks the layer tree to compute any information that is needed 1212 // Recursively walks the layer tree to compute any information that is needed
1210 // before doing the main recursion. 1213 // before doing the main recursion.
1211 template <typename LayerType> 1214 template <typename LayerType>
1212 static void PreCalculateMetaInformation( 1215 static void PreCalculateMetaInformation(
1213 LayerType* layer, 1216 LayerType* layer,
1214 PreCalculateMetaInformationRecursiveData* recursive_data) { 1217 PreCalculateMetaInformationRecursiveData* recursive_data) {
1218 DCHECK(ValidateRenderSurface(layer));
1215 1219
1216 layer->draw_properties().sorted_for_recursion = false; 1220 layer->draw_properties().sorted_for_recursion = false;
1217 layer->draw_properties().has_child_with_a_scroll_parent = false; 1221 layer->draw_properties().has_child_with_a_scroll_parent = false;
1218 1222
1219 if (!HasInvertibleOrAnimatedTransform(layer)) { 1223 if (!HasInvertibleOrAnimatedTransform(layer)) {
1220 // Layers with singular transforms should not be drawn, the whole subtree 1224 // Layers with singular transforms should not be drawn, the whole subtree
1221 // can be skipped. 1225 // can be skipped.
1222 return; 1226 return;
1223 } 1227 }
1224 1228
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
1602 // the right results. 1606 // the right results.
1603 const bool layer_is_visible = 1607 const bool layer_is_visible =
1604 data_from_ancestor.subtree_is_visible_from_ancestor && 1608 data_from_ancestor.subtree_is_visible_from_ancestor &&
1605 !layer->hide_layer_and_subtree(); 1609 !layer->hide_layer_and_subtree();
1606 const bool layer_is_drawn = layer_is_visible || layer->HasCopyRequest(); 1610 const bool layer_is_drawn = layer_is_visible || layer->HasCopyRequest();
1607 1611
1608 // The root layer cannot skip CalcDrawProperties. 1612 // The root layer cannot skip CalcDrawProperties.
1609 if (!IsRootLayer(layer) && SubtreeShouldBeSkipped(layer, layer_is_drawn)) { 1613 if (!IsRootLayer(layer) && SubtreeShouldBeSkipped(layer, layer_is_drawn)) {
1610 if (layer->render_surface()) 1614 if (layer->render_surface())
1611 layer->ClearRenderSurfaceLayerList(); 1615 layer->ClearRenderSurfaceLayerList();
1616 layer->draw_properties().render_target = nullptr;
1612 return; 1617 return;
1613 } 1618 }
1614 1619
1615 // We need to circumvent the normal recursive flow of information for clip 1620 // We need to circumvent the normal recursive flow of information for clip
1616 // children (they don't inherit their direct ancestor's clip information). 1621 // children (they don't inherit their direct ancestor's clip information).
1617 // This is unfortunate, and would be unnecessary if we were to formally 1622 // This is unfortunate, and would be unnecessary if we were to formally
1618 // separate the clipping hierarchy from the layer hierarchy. 1623 // separate the clipping hierarchy from the layer hierarchy.
1619 bool ancestor_clips_subtree = data_from_ancestor.ancestor_clips_subtree; 1624 bool ancestor_clips_subtree = data_from_ancestor.ancestor_clips_subtree;
1620 gfx::Rect ancestor_clip_rect_in_target_space = 1625 gfx::Rect ancestor_clip_rect_in_target_space =
1621 data_from_ancestor.clip_rect_in_target_space; 1626 data_from_ancestor.clip_rect_in_target_space;
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1827 data_from_ancestor.full_hierarchy_matrix; 1832 data_from_ancestor.full_hierarchy_matrix;
1828 1833
1829 // If the subtree will scale layer contents by the transform hierarchy, then 1834 // If the subtree will scale layer contents by the transform hierarchy, then
1830 // we should scale things into the render surface by the transform hierarchy 1835 // we should scale things into the render surface by the transform hierarchy
1831 // to take advantage of that. 1836 // to take advantage of that.
1832 gfx::Vector2dF render_surface_sublayer_scale = 1837 gfx::Vector2dF render_surface_sublayer_scale =
1833 globals.can_adjust_raster_scales 1838 globals.can_adjust_raster_scales
1834 ? combined_transform_scales 1839 ? combined_transform_scales
1835 : gfx::Vector2dF(layer_scale_factors, layer_scale_factors); 1840 : gfx::Vector2dF(layer_scale_factors, layer_scale_factors);
1836 1841
1837 bool render_to_separate_surface; 1842 bool render_to_separate_surface =
1838 if (globals.can_render_to_separate_surface) { 1843 IsRootLayer(layer) ||
1839 render_to_separate_surface = SubtreeShouldRenderToSeparateSurface( 1844 (globals.can_render_to_separate_surface && layer->render_surface());
1840 layer, combined_transform.Preserves2dAxisAlignment());
1841 } else {
1842 render_to_separate_surface = IsRootLayer(layer);
1843 }
1844
1845 layer->SetHasRenderSurface(render_to_separate_surface);
1846 1845
1847 if (render_to_separate_surface) { 1846 if (render_to_separate_surface) {
1847 DCHECK(layer->render_surface());
1848 // Check back-face visibility before continuing with this surface and its 1848 // Check back-face visibility before continuing with this surface and its
1849 // subtree 1849 // subtree
1850 if (!layer->double_sided() && TransformToParentIsKnown(layer) && 1850 if (!layer->double_sided() && TransformToParentIsKnown(layer) &&
1851 IsSurfaceBackFaceVisible(layer, combined_transform)) { 1851 IsSurfaceBackFaceVisible(layer, combined_transform)) {
1852 layer->ClearRenderSurfaceLayerList(); 1852 layer->ClearRenderSurfaceLayerList();
1853 layer->draw_properties().render_target = nullptr;
1853 return; 1854 return;
1854 } 1855 }
1855 1856
1856 typename LayerType::RenderSurfaceType* render_surface = 1857 typename LayerType::RenderSurfaceType* render_surface =
1857 CreateOrReuseRenderSurface(layer); 1858 layer->render_surface();
1859 layer->ClearRenderSurfaceLayerList();
1858 1860
1861 layer_draw_properties.render_target = layer;
1859 if (IsRootLayer(layer)) { 1862 if (IsRootLayer(layer)) {
1860 // The root layer's render surface size is predetermined and so the root 1863 // The root layer's render surface size is predetermined and so the root
1861 // layer can't directly support non-identity transforms. It should just 1864 // layer can't directly support non-identity transforms. It should just
1862 // forward top-level transforms to the rest of the tree. 1865 // forward top-level transforms to the rest of the tree.
1863 data_for_children.parent_matrix = combined_transform; 1866 data_for_children.parent_matrix = combined_transform;
1864 1867
1865 // The root surface does not contribute to any other surface, it has no 1868 // The root surface does not contribute to any other surface, it has no
1866 // target. 1869 // target.
1867 layer->render_surface()->set_contributes_to_drawn_surface(false); 1870 layer->render_surface()->set_contributes_to_drawn_surface(false);
1868 } else { 1871 } else {
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
2028 animating_transform_to_target; 2031 animating_transform_to_target;
2029 layer_draw_properties.screen_space_transform_is_animating = 2032 layer_draw_properties.screen_space_transform_is_animating =
2030 animating_transform_to_screen; 2033 animating_transform_to_screen;
2031 layer_draw_properties.opacity = accumulated_draw_opacity; 2034 layer_draw_properties.opacity = accumulated_draw_opacity;
2032 layer_draw_properties.blend_mode = layer->blend_mode(); 2035 layer_draw_properties.blend_mode = layer->blend_mode();
2033 layer_draw_properties.opacity_is_animating = animating_opacity_to_target; 2036 layer_draw_properties.opacity_is_animating = animating_opacity_to_target;
2034 layer_draw_properties.screen_space_opacity_is_animating = 2037 layer_draw_properties.screen_space_opacity_is_animating =
2035 animating_opacity_to_screen; 2038 animating_opacity_to_screen;
2036 data_for_children.parent_matrix = combined_transform; 2039 data_for_children.parent_matrix = combined_transform;
2037 2040
2038 layer->ClearRenderSurface();
2039
2040 // Layers without render_surfaces directly inherit the ancestor's clip 2041 // Layers without render_surfaces directly inherit the ancestor's clip
2041 // status. 2042 // status.
2042 layer_or_ancestor_clips_descendants = ancestor_clips_subtree; 2043 layer_or_ancestor_clips_descendants = ancestor_clips_subtree;
2043 if (ancestor_clips_subtree) { 2044 if (ancestor_clips_subtree) {
2044 clip_rect_in_target_space = 2045 clip_rect_in_target_space =
2045 ancestor_clip_rect_in_target_space; 2046 ancestor_clip_rect_in_target_space;
2046 } 2047 }
2047 2048
2048 // The surface's cached clip rect value propagates regardless of what 2049 // The surface's cached clip rect value propagates regardless of what
2049 // clipping goes on between layers here. 2050 // clipping goes on between layers here.
(...skipping 20 matching lines...) Expand all
2070 // Thus we can omit contents scale in the following calculation. 2071 // Thus we can omit contents scale in the following calculation.
2071 gfx::Vector2d bounds_delta = BoundsDelta(layer); 2072 gfx::Vector2d bounds_delta = BoundsDelta(layer);
2072 content_size_affected_by_delta.Enlarge(bounds_delta.x(), bounds_delta.y()); 2073 content_size_affected_by_delta.Enlarge(bounds_delta.x(), bounds_delta.y());
2073 2074
2074 gfx::Rect rect_in_target_space = MathUtil::MapEnclosingClippedRect( 2075 gfx::Rect rect_in_target_space = MathUtil::MapEnclosingClippedRect(
2075 layer->draw_transform(), 2076 layer->draw_transform(),
2076 gfx::Rect(content_size_affected_by_delta)); 2077 gfx::Rect(content_size_affected_by_delta));
2077 2078
2078 if (LayerClipsSubtree(layer)) { 2079 if (LayerClipsSubtree(layer)) {
2079 layer_or_ancestor_clips_descendants = true; 2080 layer_or_ancestor_clips_descendants = true;
2080 if (ancestor_clips_subtree && !layer->render_surface()) { 2081 if (ancestor_clips_subtree && !render_to_separate_surface) {
2081 // A layer without render surface shares the same target as its ancestor. 2082 // A layer without render surface shares the same target as its ancestor.
2082 clip_rect_in_target_space = 2083 clip_rect_in_target_space =
2083 ancestor_clip_rect_in_target_space; 2084 ancestor_clip_rect_in_target_space;
2084 clip_rect_in_target_space.Intersect(rect_in_target_space); 2085 clip_rect_in_target_space.Intersect(rect_in_target_space);
2085 } else { 2086 } else {
2086 clip_rect_in_target_space = rect_in_target_space; 2087 clip_rect_in_target_space = rect_in_target_space;
2087 } 2088 }
2088 } 2089 }
2089 2090
2090 // Tell the layer the rect that it's clipped by. In theory we could use a 2091 // Tell the layer the rect that it's clipped by. In theory we could use a
2091 // tighter clip rect here (drawable_content_rect), but that actually does not 2092 // tighter clip rect here (drawable_content_rect), but that actually does not
2092 // reduce how much would be drawn, and instead it would create unnecessary 2093 // reduce how much would be drawn, and instead it would create unnecessary
2093 // changes to scissor state affecting GPU performance. Our clip information 2094 // changes to scissor state affecting GPU performance. Our clip information
2094 // is used in the recursion below, so we must set it beforehand. 2095 // is used in the recursion below, so we must set it beforehand.
2095 layer_draw_properties.is_clipped = layer_or_ancestor_clips_descendants; 2096 layer_draw_properties.is_clipped = layer_or_ancestor_clips_descendants;
2096 if (layer_or_ancestor_clips_descendants) { 2097 if (layer_or_ancestor_clips_descendants) {
2097 layer_draw_properties.clip_rect = clip_rect_in_target_space; 2098 layer_draw_properties.clip_rect = clip_rect_in_target_space;
2098 } else { 2099 } else {
2099 // Initialize the clip rect to a safe value that will not clip the 2100 // Initialize the clip rect to a safe value that will not clip the
2100 // layer, just in case clipping is still accidentally used. 2101 // layer, just in case clipping is still accidentally used.
2101 layer_draw_properties.clip_rect = rect_in_target_space; 2102 layer_draw_properties.clip_rect = rect_in_target_space;
2102 } 2103 }
2103 2104
2104 typename LayerType::LayerListType& descendants = 2105 typename LayerType::LayerListType& descendants =
2105 (layer->render_surface() ? layer->render_surface()->layer_list() 2106 (render_to_separate_surface ? layer->render_surface()->layer_list()
2106 : *layer_list); 2107 : *layer_list);
2107 2108
2108 // Any layers that are appended after this point are in the layer's subtree 2109 // Any layers that are appended after this point are in the layer's subtree
2109 // and should be included in the sorting process. 2110 // and should be included in the sorting process.
2110 size_t sorting_start_index = descendants.size(); 2111 size_t sorting_start_index = descendants.size();
2111 2112
2112 if (!LayerShouldBeSkipped(layer, layer_is_drawn)) { 2113 if (!LayerShouldBeSkipped(layer, layer_is_drawn)) {
2113 MarkLayerWithRenderSurfaceLayerListId(layer, 2114 MarkLayerWithRenderSurfaceLayerListId(layer,
2114 current_render_surface_layer_list_id); 2115 current_render_surface_layer_list_id);
2115 descendants.push_back(layer); 2116 descendants.push_back(layer);
2116 } 2117 }
2117 2118
2118 // Any layers that are appended after this point may need to be sorted if we 2119 // Any layers that are appended after this point may need to be sorted if we
2119 // visit the children out of order. 2120 // visit the children out of order.
2120 size_t render_surface_layer_list_child_sorting_start_index = 2121 size_t render_surface_layer_list_child_sorting_start_index =
2121 render_surface_layer_list->size(); 2122 render_surface_layer_list->size();
2122 size_t layer_list_child_sorting_start_index = descendants.size(); 2123 size_t layer_list_child_sorting_start_index = descendants.size();
2123 2124
2124 if (!layer->children().empty()) { 2125 if (!layer->children().empty()) {
2125 if (layer == globals.page_scale_application_layer) { 2126 if (layer == globals.page_scale_application_layer) {
2126 data_for_children.parent_matrix.Scale( 2127 data_for_children.parent_matrix.Scale(
2127 globals.page_scale_factor, 2128 globals.page_scale_factor,
2128 globals.page_scale_factor); 2129 globals.page_scale_factor);
2129 data_for_children.in_subtree_of_page_scale_application_layer = true; 2130 data_for_children.in_subtree_of_page_scale_application_layer = true;
2130 } 2131 }
2131 if (layer == globals.elastic_overscroll_application_layer) { 2132 if (layer == globals.elastic_overscroll_application_layer) {
2132 data_for_children.parent_matrix.Translate(globals.elastic_overscroll.x(), 2133 data_for_children.parent_matrix.Translate(
2133 globals.elastic_overscroll.y()); 2134 -globals.elastic_overscroll.x(), -globals.elastic_overscroll.y());
2134 } 2135 }
2135 2136
2136 // Flatten to 2D if the layer doesn't preserve 3D. 2137 // Flatten to 2D if the layer doesn't preserve 3D.
2137 if (layer->should_flatten_transform()) 2138 if (layer->should_flatten_transform())
2138 data_for_children.parent_matrix.FlattenTo2d(); 2139 data_for_children.parent_matrix.FlattenTo2d();
2139 2140
2140 data_for_children.scroll_compensation_matrix = 2141 data_for_children.scroll_compensation_matrix =
2141 ComputeScrollCompensationMatrixForChildren( 2142 ComputeScrollCompensationMatrixForChildren(
2142 layer, 2143 layer,
2143 data_from_ancestor.parent_matrix, 2144 data_from_ancestor.parent_matrix,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2178 render_surface_layer_list->size(); 2179 render_surface_layer_list->size();
2179 2180
2180 CalculateDrawPropertiesInternal<LayerType>( 2181 CalculateDrawPropertiesInternal<LayerType>(
2181 child, 2182 child,
2182 globals, 2183 globals,
2183 data_for_children, 2184 data_for_children,
2184 render_surface_layer_list, 2185 render_surface_layer_list,
2185 &descendants, 2186 &descendants,
2186 accumulated_surface_state, 2187 accumulated_surface_state,
2187 current_render_surface_layer_list_id); 2188 current_render_surface_layer_list_id);
2188 if (child->render_surface() && 2189 // If the child is its own render target, then it has a render surface.
2190 if (child->render_target() == child &&
2189 !child->render_surface()->layer_list().empty() && 2191 !child->render_surface()->layer_list().empty() &&
2190 !child->render_surface()->content_rect().IsEmpty()) { 2192 !child->render_surface()->content_rect().IsEmpty()) {
2191 // This child will contribute its render surface, which means 2193 // This child will contribute its render surface, which means
2192 // we need to mark just the mask layer (and replica mask layer) 2194 // we need to mark just the mask layer (and replica mask layer)
2193 // with the id. 2195 // with the id.
2194 MarkMasksWithRenderSurfaceLayerListId( 2196 MarkMasksWithRenderSurfaceLayerListId(
2195 child, current_render_surface_layer_list_id); 2197 child, current_render_surface_layer_list_id);
2196 descendants.push_back(child); 2198 descendants.push_back(child);
2197 } 2199 }
2198 2200
(...skipping 18 matching lines...) Expand all
2217 *layer, 2219 *layer,
2218 &descendants, 2220 &descendants,
2219 layer_list_child_sorting_start_index, 2221 layer_list_child_sorting_start_index,
2220 &GetNewDescendantsStartIndexAndCount<LayerType>); 2222 &GetNewDescendantsStartIndexAndCount<LayerType>);
2221 } 2223 }
2222 2224
2223 // Compute the total drawable_content_rect for this subtree (the rect is in 2225 // Compute the total drawable_content_rect for this subtree (the rect is in
2224 // target surface space). 2226 // target surface space).
2225 gfx::Rect local_drawable_content_rect_of_subtree = 2227 gfx::Rect local_drawable_content_rect_of_subtree =
2226 accumulated_surface_state->back().drawable_content_rect; 2228 accumulated_surface_state->back().drawable_content_rect;
2227 if (layer->render_surface()) { 2229 if (render_to_separate_surface) {
2228 DCHECK(accumulated_surface_state->back().render_target == layer); 2230 DCHECK(accumulated_surface_state->back().render_target == layer);
2229 accumulated_surface_state->pop_back(); 2231 accumulated_surface_state->pop_back();
2230 } 2232 }
2231 2233
2232 if (layer->render_surface() && !IsRootLayer(layer) && 2234 if (render_to_separate_surface && !IsRootLayer(layer) &&
2233 layer->render_surface()->layer_list().empty()) { 2235 layer->render_surface()->layer_list().empty()) {
2234 RemoveSurfaceForEarlyExit(layer, render_surface_layer_list); 2236 RemoveSurfaceForEarlyExit(layer, render_surface_layer_list);
2235 return; 2237 return;
2236 } 2238 }
2237 2239
2238 // Compute the layer's drawable content rect (the rect is in target surface 2240 // Compute the layer's drawable content rect (the rect is in target surface
2239 // space). 2241 // space).
2240 layer_draw_properties.drawable_content_rect = rect_in_target_space; 2242 layer_draw_properties.drawable_content_rect = rect_in_target_space;
2241 if (layer_or_ancestor_clips_descendants) { 2243 if (layer_or_ancestor_clips_descendants) {
2242 layer_draw_properties.drawable_content_rect.Intersect( 2244 layer_draw_properties.drawable_content_rect.Intersect(
2243 clip_rect_in_target_space); 2245 clip_rect_in_target_space);
2244 } 2246 }
2245 if (layer->DrawsContent()) { 2247 if (layer->DrawsContent()) {
2246 local_drawable_content_rect_of_subtree.Union( 2248 local_drawable_content_rect_of_subtree.Union(
2247 layer_draw_properties.drawable_content_rect); 2249 layer_draw_properties.drawable_content_rect);
2248 } 2250 }
2249 2251
2250 // Compute the layer's visible content rect (the rect is in content space). 2252 // Compute the layer's visible content rect (the rect is in content space).
2251 layer_draw_properties.visible_content_rect = CalculateVisibleContentRect( 2253 layer_draw_properties.visible_content_rect = CalculateVisibleContentRect(
2252 layer, clip_rect_of_target_surface_in_target_space, rect_in_target_space); 2254 layer, clip_rect_of_target_surface_in_target_space, rect_in_target_space);
2253 2255
2254 // Compute the remaining properties for the render surface, if the layer has 2256 // Compute the remaining properties for the render surface, if the layer has
2255 // one. 2257 // one.
2256 if (IsRootLayer(layer)) { 2258 if (IsRootLayer(layer)) {
2257 // The root layer's surface's content_rect is always the entire viewport. 2259 // The root layer's surface's content_rect is always the entire viewport.
2258 DCHECK(layer->render_surface()); 2260 DCHECK(render_to_separate_surface);
2259 layer->render_surface()->SetContentRect( 2261 layer->render_surface()->SetContentRect(
2260 ancestor_clip_rect_in_target_space); 2262 ancestor_clip_rect_in_target_space);
2261 } else if (layer->render_surface()) { 2263 } else if (render_to_separate_surface) {
2262 typename LayerType::RenderSurfaceType* render_surface = 2264 typename LayerType::RenderSurfaceType* render_surface =
2263 layer->render_surface(); 2265 layer->render_surface();
2264 gfx::Rect clipped_content_rect = local_drawable_content_rect_of_subtree; 2266 gfx::Rect clipped_content_rect = local_drawable_content_rect_of_subtree;
2265 2267
2266 // Don't clip if the layer is reflected as the reflection shouldn't be 2268 // Don't clip if the layer is reflected as the reflection shouldn't be
2267 // clipped. If the layer is animating, then the surface's transform to 2269 // clipped. If the layer is animating, then the surface's transform to
2268 // its target is not known on the main thread, and we should not use it 2270 // its target is not known on the main thread, and we should not use it
2269 // to clip. 2271 // to clip.
2270 if (!layer->replica_layer() && TransformToParentIsKnown(layer)) { 2272 if (!layer->replica_layer() && TransformToParentIsKnown(layer)) {
2271 // Note, it is correct to use data_from_ancestor.ancestor_clips_subtree 2273 // Note, it is correct to use data_from_ancestor.ancestor_clips_subtree
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
2345 surface_origin_to_replica_origin_transform; 2347 surface_origin_to_replica_origin_transform;
2346 render_surface->SetReplicaScreenSpaceTransform( 2348 render_surface->SetReplicaScreenSpaceTransform(
2347 replica_screen_space_transform); 2349 replica_screen_space_transform);
2348 } 2350 }
2349 } 2351 }
2350 2352
2351 SavePaintPropertiesLayer(layer); 2353 SavePaintPropertiesLayer(layer);
2352 2354
2353 // If neither this layer nor any of its children were added, early out. 2355 // If neither this layer nor any of its children were added, early out.
2354 if (sorting_start_index == descendants.size()) { 2356 if (sorting_start_index == descendants.size()) {
2355 DCHECK(!layer->render_surface() || IsRootLayer(layer)); 2357 DCHECK(!render_to_separate_surface || IsRootLayer(layer));
2356 return; 2358 return;
2357 } 2359 }
2358 2360
2359 // If preserves-3d then sort all the descendants in 3D so that they can be 2361 // If preserves-3d then sort all the descendants in 3D so that they can be
2360 // drawn from back to front. If the preserves-3d property is also set on the 2362 // drawn from back to front. If the preserves-3d property is also set on the
2361 // parent then skip the sorting as the parent will sort all the descendants 2363 // parent then skip the sorting as the parent will sort all the descendants
2362 // anyway. 2364 // anyway.
2363 if (globals.layer_sorter && descendants.size() && layer->Is3dSorted() && 2365 if (globals.layer_sorter && descendants.size() && layer->Is3dSorted() &&
2364 !LayerIsInExisting3DRenderingContext(layer)) { 2366 !LayerIsInExisting3DRenderingContext(layer)) {
2365 SortLayers(descendants.begin() + sorting_start_index, 2367 SortLayers(descendants.begin() + sorting_start_index,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
2428 device_viewport_rect; 2430 device_viewport_rect;
2429 data_for_recursion->maximum_animation_contents_scale = 0.f; 2431 data_for_recursion->maximum_animation_contents_scale = 0.f;
2430 data_for_recursion->ancestor_is_animating_scale = false; 2432 data_for_recursion->ancestor_is_animating_scale = false;
2431 data_for_recursion->ancestor_clips_subtree = true; 2433 data_for_recursion->ancestor_clips_subtree = true;
2432 data_for_recursion->nearest_occlusion_immune_ancestor_surface = NULL; 2434 data_for_recursion->nearest_occlusion_immune_ancestor_surface = NULL;
2433 data_for_recursion->in_subtree_of_page_scale_application_layer = false; 2435 data_for_recursion->in_subtree_of_page_scale_application_layer = false;
2434 data_for_recursion->subtree_can_use_lcd_text = inputs.can_use_lcd_text; 2436 data_for_recursion->subtree_can_use_lcd_text = inputs.can_use_lcd_text;
2435 data_for_recursion->subtree_is_visible_from_ancestor = true; 2437 data_for_recursion->subtree_is_visible_from_ancestor = true;
2436 } 2438 }
2437 2439
2440 void LayerTreeHostCommon::UpdateRenderSurface(
2441 Layer* layer,
2442 bool can_render_to_separate_surface,
2443 gfx::Transform* transform,
2444 bool* draw_transform_is_axis_aligned) {
2445 bool preserves_2d_axis_alignment =
2446 transform->Preserves2dAxisAlignment() && *draw_transform_is_axis_aligned;
2447 if (IsRootLayer(layer) || (can_render_to_separate_surface &&
2448 SubtreeShouldRenderToSeparateSurface(
2449 layer, preserves_2d_axis_alignment))) {
2450 // We reset the transform here so that any axis-changing transforms
2451 // will now be relative to this RenderSurface.
2452 transform->MakeIdentity();
2453 *draw_transform_is_axis_aligned = true;
2454 if (!layer->render_surface()) {
2455 layer->CreateRenderSurface();
2456 }
2457 layer->SetHasRenderSurface(true);
2458 return;
2459 }
2460 layer->SetHasRenderSurface(false);
2461 if (layer->render_surface())
2462 layer->ClearRenderSurface();
2463 }
2464
2465 void LayerTreeHostCommon::UpdateRenderSurfaces(
2466 Layer* layer,
2467 bool can_render_to_separate_surface,
2468 const gfx::Transform& parent_transform,
2469 bool draw_transform_is_axis_aligned) {
2470 gfx::Transform transform_for_children = layer->transform();
2471 transform_for_children *= parent_transform;
2472 draw_transform_is_axis_aligned &= layer->AnimationsPreserveAxisAlignment();
2473 UpdateRenderSurface(layer, can_render_to_separate_surface,
2474 &transform_for_children, &draw_transform_is_axis_aligned);
2475
2476 for (size_t i = 0; i < layer->children().size(); ++i) {
2477 UpdateRenderSurfaces(layer->children()[i].get(),
2478 can_render_to_separate_surface, transform_for_children,
2479 draw_transform_is_axis_aligned);
2480 }
2481 }
2482
2438 static bool ApproximatelyEqual(const gfx::Rect& r1, const gfx::Rect& r2) { 2483 static bool ApproximatelyEqual(const gfx::Rect& r1, const gfx::Rect& r2) {
2439 static const int tolerance = 1; 2484 static const int tolerance = 1;
2440 return std::abs(r1.x() - r2.x()) <= tolerance && 2485 return std::abs(r1.x() - r2.x()) <= tolerance &&
2441 std::abs(r1.y() - r2.y()) <= tolerance && 2486 std::abs(r1.y() - r2.y()) <= tolerance &&
2442 std::abs(r1.width() - r2.width()) <= tolerance && 2487 std::abs(r1.width() - r2.width()) <= tolerance &&
2443 std::abs(r1.height() - r2.height()) <= tolerance; 2488 std::abs(r1.height() - r2.height()) <= tolerance;
2444 } 2489 }
2445 2490
2446 void LayerTreeHostCommon::CalculateDrawProperties( 2491 void LayerTreeHostCommon::CalculateDrawProperties(
2447 CalcDrawPropsMainInputs* inputs) { 2492 CalcDrawPropsMainInputs* inputs) {
2493 UpdateRenderSurfaces(inputs->root_layer,
2494 inputs->can_render_to_separate_surface, gfx::Transform(),
2495 false);
2448 LayerList dummy_layer_list; 2496 LayerList dummy_layer_list;
2449 SubtreeGlobals<Layer> globals; 2497 SubtreeGlobals<Layer> globals;
2450 DataForRecursion<Layer> data_for_recursion; 2498 DataForRecursion<Layer> data_for_recursion;
2451 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); 2499 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion);
2452 2500
2453 PreCalculateMetaInformationRecursiveData recursive_data; 2501 PreCalculateMetaInformationRecursiveData recursive_data;
2454 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); 2502 PreCalculateMetaInformation(inputs->root_layer, &recursive_data);
2455 std::vector<AccumulatedSurfaceState<Layer>> accumulated_surface_state; 2503 std::vector<AccumulatedSurfaceState<Layer>> accumulated_surface_state;
2456 CalculateDrawPropertiesInternal<Layer>( 2504 CalculateDrawPropertiesInternal<Layer>(
2457 inputs->root_layer, 2505 inputs->root_layer,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2522 inputs->current_render_surface_layer_list_id); 2570 inputs->current_render_surface_layer_list_id);
2523 2571
2524 // The dummy layer list should not have been used. 2572 // The dummy layer list should not have been used.
2525 DCHECK_EQ(0u, dummy_layer_list.size()); 2573 DCHECK_EQ(0u, dummy_layer_list.size());
2526 // A root layer render_surface should always exist after 2574 // A root layer render_surface should always exist after
2527 // CalculateDrawProperties. 2575 // CalculateDrawProperties.
2528 DCHECK(inputs->root_layer->render_surface()); 2576 DCHECK(inputs->root_layer->render_surface());
2529 } 2577 }
2530 2578
2531 } // namespace cc 2579 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_common.h ('k') | cc/trees/layer_tree_host_common_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698