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 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
543 | 543 |
544 static inline void SavePaintPropertiesLayer(Layer* layer) { | 544 static inline void SavePaintPropertiesLayer(Layer* layer) { |
545 layer->SavePaintProperties(); | 545 layer->SavePaintProperties(); |
546 | 546 |
547 if (layer->mask_layer()) | 547 if (layer->mask_layer()) |
548 layer->mask_layer()->SavePaintProperties(); | 548 layer->mask_layer()->SavePaintProperties(); |
549 if (layer->replica_layer() && layer->replica_layer()->mask_layer()) | 549 if (layer->replica_layer() && layer->replica_layer()->mask_layer()) |
550 layer->replica_layer()->mask_layer()->SavePaintProperties(); | 550 layer->replica_layer()->mask_layer()->SavePaintProperties(); |
551 } | 551 } |
552 | 552 |
553 template <typename LayerType> | |
554 static bool SubtreeShouldRenderToSeparateSurface( | 553 static bool SubtreeShouldRenderToSeparateSurface( |
555 LayerType* layer, | 554 Layer* layer, |
556 bool axis_aligned_with_respect_to_parent) { | 555 bool axis_aligned_with_respect_to_parent) { |
557 // | 556 // |
558 // A layer and its descendants should render onto a new RenderSurfaceImpl if | 557 // A layer and its descendants should render onto a new RenderSurfaceImpl if |
559 // any of these rules hold: | 558 // any of these rules hold: |
560 // | 559 // |
561 | 560 |
562 // The root layer owns a render surface, but it never acts as a contributing | 561 // The root layer owns a render surface, but it never acts as a contributing |
563 // surface to another render target. Compositor features that are applied via | 562 // surface to another render target. Compositor features that are applied via |
564 // a contributing surface can not be applied to the root layer. In order to | 563 // a contributing surface can not be applied to the root layer. In order to |
565 // use these effects, another child of the root would need to be introduced | 564 // 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 Loading... | |
1101 *combined_maximum_animation_contents_scale = 0.f; | 1100 *combined_maximum_animation_contents_scale = 0.f; |
1102 return; | 1101 return; |
1103 } | 1102 } |
1104 gfx::Vector2dF ancestor_transform_scales = | 1103 gfx::Vector2dF ancestor_transform_scales = |
1105 MathUtil::ComputeTransform2dScaleComponents(ancestor_transform, 0.f); | 1104 MathUtil::ComputeTransform2dScaleComponents(ancestor_transform, 0.f); |
1106 *combined_maximum_animation_contents_scale = | 1105 *combined_maximum_animation_contents_scale = |
1107 layer_maximum_animated_scale * | 1106 layer_maximum_animated_scale * |
1108 std::max(ancestor_transform_scales.x(), ancestor_transform_scales.y()); | 1107 std::max(ancestor_transform_scales.x(), ancestor_transform_scales.y()); |
1109 } | 1108 } |
1110 | 1109 |
1111 template <typename LayerType> | |
1112 static inline typename LayerType::RenderSurfaceType* CreateOrReuseRenderSurface( | |
1113 LayerType* layer) { | |
1114 if (!layer->render_surface()) { | |
1115 layer->CreateRenderSurface(); | |
1116 return layer->render_surface(); | |
1117 } | |
1118 | |
1119 layer->render_surface()->ClearLayerLists(); | |
1120 return layer->render_surface(); | |
1121 } | |
1122 | |
1123 template <typename LayerTypePtr> | 1110 template <typename LayerTypePtr> |
1124 static inline void MarkLayerWithRenderSurfaceLayerListId( | 1111 static inline void MarkLayerWithRenderSurfaceLayerListId( |
1125 LayerTypePtr layer, | 1112 LayerTypePtr layer, |
1126 int current_render_surface_layer_list_id) { | 1113 int current_render_surface_layer_list_id) { |
1127 layer->draw_properties().last_drawn_render_surface_layer_list_id = | 1114 layer->draw_properties().last_drawn_render_surface_layer_list_id = |
1128 current_render_surface_layer_list_id; | 1115 current_render_surface_layer_list_id; |
1129 } | 1116 } |
1130 | 1117 |
1131 template <typename LayerTypePtr> | 1118 template <typename LayerTypePtr> |
1132 static inline void MarkMasksWithRenderSurfaceLayerListId( | 1119 static inline void MarkMasksWithRenderSurfaceLayerListId( |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1196 void Merge(const PreCalculateMetaInformationRecursiveData& data) { | 1183 void Merge(const PreCalculateMetaInformationRecursiveData& data) { |
1197 layer_or_descendant_has_copy_request |= | 1184 layer_or_descendant_has_copy_request |= |
1198 data.layer_or_descendant_has_copy_request; | 1185 data.layer_or_descendant_has_copy_request; |
1199 layer_or_descendant_has_input_handler |= | 1186 layer_or_descendant_has_input_handler |= |
1200 data.layer_or_descendant_has_input_handler; | 1187 data.layer_or_descendant_has_input_handler; |
1201 num_unclipped_descendants += | 1188 num_unclipped_descendants += |
1202 data.num_unclipped_descendants; | 1189 data.num_unclipped_descendants; |
1203 } | 1190 } |
1204 }; | 1191 }; |
1205 | 1192 |
1193 static bool ValidateRenderSurface(LayerImpl* layer) { | |
1194 // There are a few cases in which it is incorrect to not have a | |
1195 // render_surface. | |
1196 return (layer->render_surface() || | |
enne (OOO)
2014/12/16 22:00:16
I think this would be easier to read with an early
| |
1197 (layer->filters().IsEmpty() && | |
1198 layer->background_filters().IsEmpty() && | |
1199 !layer->mask_layer() && | |
1200 !layer->replica_layer() && | |
1201 !IsRootLayer(layer) && | |
1202 !layer->is_root_for_isolated_group() && | |
1203 !layer->HasCopyRequest())); | |
1204 } | |
1205 | |
1206 static bool ValidateRenderSurface(Layer* layer) { | |
1207 return true; | |
1208 } | |
1209 | |
1206 // Recursively walks the layer tree to compute any information that is needed | 1210 // Recursively walks the layer tree to compute any information that is needed |
1207 // before doing the main recursion. | 1211 // before doing the main recursion. |
1208 template <typename LayerType> | 1212 template <typename LayerType> |
1209 static void PreCalculateMetaInformation( | 1213 static void PreCalculateMetaInformation( |
1210 LayerType* layer, | 1214 LayerType* layer, |
1211 PreCalculateMetaInformationRecursiveData* recursive_data) { | 1215 PreCalculateMetaInformationRecursiveData* recursive_data) { |
1216 DCHECK(ValidateRenderSurface(layer)); | |
1212 | 1217 |
1213 layer->draw_properties().sorted_for_recursion = false; | 1218 layer->draw_properties().sorted_for_recursion = false; |
1214 layer->draw_properties().has_child_with_a_scroll_parent = false; | 1219 layer->draw_properties().has_child_with_a_scroll_parent = false; |
1215 | 1220 |
1216 if (!HasInvertibleOrAnimatedTransform(layer)) { | 1221 if (!HasInvertibleOrAnimatedTransform(layer)) { |
1217 // Layers with singular transforms should not be drawn, the whole subtree | 1222 // Layers with singular transforms should not be drawn, the whole subtree |
1218 // can be skipped. | 1223 // can be skipped. |
1219 return; | 1224 return; |
1220 } | 1225 } |
1221 | 1226 |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1816 data_from_ancestor.full_hierarchy_matrix; | 1821 data_from_ancestor.full_hierarchy_matrix; |
1817 | 1822 |
1818 // If the subtree will scale layer contents by the transform hierarchy, then | 1823 // If the subtree will scale layer contents by the transform hierarchy, then |
1819 // we should scale things into the render surface by the transform hierarchy | 1824 // we should scale things into the render surface by the transform hierarchy |
1820 // to take advantage of that. | 1825 // to take advantage of that. |
1821 gfx::Vector2dF render_surface_sublayer_scale = | 1826 gfx::Vector2dF render_surface_sublayer_scale = |
1822 globals.can_adjust_raster_scales | 1827 globals.can_adjust_raster_scales |
1823 ? combined_transform_scales | 1828 ? combined_transform_scales |
1824 : gfx::Vector2dF(layer_scale_factors, layer_scale_factors); | 1829 : gfx::Vector2dF(layer_scale_factors, layer_scale_factors); |
1825 | 1830 |
1826 bool render_to_separate_surface; | 1831 bool render_to_separate_surface = |
1827 if (globals.can_render_to_separate_surface) { | 1832 IsRootLayer(layer) || |
1828 render_to_separate_surface = SubtreeShouldRenderToSeparateSurface( | 1833 (globals.can_render_to_separate_surface && layer->render_surface()); |
1829 layer, combined_transform.Preserves2dAxisAlignment()); | 1834 |
1830 } else { | |
1831 render_to_separate_surface = IsRootLayer(layer); | |
1832 } | |
1833 if (render_to_separate_surface) { | 1835 if (render_to_separate_surface) { |
1836 DCHECK(layer->render_surface()); | |
1834 // Check back-face visibility before continuing with this surface and its | 1837 // Check back-face visibility before continuing with this surface and its |
1835 // subtree | 1838 // subtree |
1836 if (!layer->double_sided() && TransformToParentIsKnown(layer) && | 1839 if (!layer->double_sided() && TransformToParentIsKnown(layer) && |
1837 IsSurfaceBackFaceVisible(layer, combined_transform)) { | 1840 IsSurfaceBackFaceVisible(layer, combined_transform)) { |
1838 layer->ClearRenderSurfaceLayerList(); | 1841 layer->ClearRenderSurfaceLayerList(); |
1839 return; | 1842 return; |
1840 } | 1843 } |
1841 | 1844 |
1842 typename LayerType::RenderSurfaceType* render_surface = | 1845 typename LayerType::RenderSurfaceType* render_surface = |
1843 CreateOrReuseRenderSurface(layer); | 1846 layer->render_surface(); |
1847 layer->ClearRenderSurfaceLayerList(); | |
1844 | 1848 |
1849 layer_draw_properties.render_target = layer; | |
1845 if (IsRootLayer(layer)) { | 1850 if (IsRootLayer(layer)) { |
1846 // The root layer's render surface size is predetermined and so the root | 1851 // The root layer's render surface size is predetermined and so the root |
1847 // layer can't directly support non-identity transforms. It should just | 1852 // layer can't directly support non-identity transforms. It should just |
1848 // forward top-level transforms to the rest of the tree. | 1853 // forward top-level transforms to the rest of the tree. |
1849 data_for_children.parent_matrix = combined_transform; | 1854 data_for_children.parent_matrix = combined_transform; |
1850 | 1855 |
1851 // The root surface does not contribute to any other surface, it has no | 1856 // The root surface does not contribute to any other surface, it has no |
1852 // target. | 1857 // target. |
1853 layer->render_surface()->set_contributes_to_drawn_surface(false); | 1858 layer->render_surface()->set_contributes_to_drawn_surface(false); |
1854 } else { | 1859 } else { |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2014 animating_transform_to_target; | 2019 animating_transform_to_target; |
2015 layer_draw_properties.screen_space_transform_is_animating = | 2020 layer_draw_properties.screen_space_transform_is_animating = |
2016 animating_transform_to_screen; | 2021 animating_transform_to_screen; |
2017 layer_draw_properties.opacity = accumulated_draw_opacity; | 2022 layer_draw_properties.opacity = accumulated_draw_opacity; |
2018 layer_draw_properties.blend_mode = layer->blend_mode(); | 2023 layer_draw_properties.blend_mode = layer->blend_mode(); |
2019 layer_draw_properties.opacity_is_animating = animating_opacity_to_target; | 2024 layer_draw_properties.opacity_is_animating = animating_opacity_to_target; |
2020 layer_draw_properties.screen_space_opacity_is_animating = | 2025 layer_draw_properties.screen_space_opacity_is_animating = |
2021 animating_opacity_to_screen; | 2026 animating_opacity_to_screen; |
2022 data_for_children.parent_matrix = combined_transform; | 2027 data_for_children.parent_matrix = combined_transform; |
2023 | 2028 |
2024 layer->ClearRenderSurface(); | |
2025 | |
2026 // Layers without render_surfaces directly inherit the ancestor's clip | 2029 // Layers without render_surfaces directly inherit the ancestor's clip |
2027 // status. | 2030 // status. |
2028 layer_or_ancestor_clips_descendants = ancestor_clips_subtree; | 2031 layer_or_ancestor_clips_descendants = ancestor_clips_subtree; |
2029 if (ancestor_clips_subtree) { | 2032 if (ancestor_clips_subtree) { |
2030 clip_rect_in_target_space = | 2033 clip_rect_in_target_space = |
2031 ancestor_clip_rect_in_target_space; | 2034 ancestor_clip_rect_in_target_space; |
2032 } | 2035 } |
2033 | 2036 |
2034 // The surface's cached clip rect value propagates regardless of what | 2037 // The surface's cached clip rect value propagates regardless of what |
2035 // clipping goes on between layers here. | 2038 // clipping goes on between layers here. |
2036 clip_rect_of_target_surface_in_target_space = | 2039 clip_rect_of_target_surface_in_target_space = |
2037 data_from_ancestor.clip_rect_of_target_surface_in_target_space; | 2040 data_from_ancestor.clip_rect_of_target_surface_in_target_space; |
2038 | 2041 |
2039 // Layers that are not their own render_target will render into the target | 2042 // Layers that are not their own render_target will render into the target |
2040 // of their nearest ancestor. | 2043 // of their nearest ancestor. |
2041 layer_draw_properties.render_target = layer->parent()->render_target(); | 2044 layer_draw_properties.render_target = layer->parent()->render_target(); |
2042 } | 2045 } |
2043 | 2046 |
2044 if (adjust_text_aa) | 2047 if (adjust_text_aa) |
2045 layer_draw_properties.can_use_lcd_text = layer_can_use_lcd_text; | 2048 layer_draw_properties.can_use_lcd_text = layer_can_use_lcd_text; |
2046 | 2049 |
2047 gfx::Rect rect_in_target_space = | 2050 gfx::Rect rect_in_target_space = |
2048 MathUtil::MapEnclosingClippedRect(layer->draw_transform(), content_rect); | 2051 MathUtil::MapEnclosingClippedRect(layer->draw_transform(), content_rect); |
2049 | 2052 |
2050 if (LayerClipsSubtree(layer)) { | 2053 if (LayerClipsSubtree(layer)) { |
2051 layer_or_ancestor_clips_descendants = true; | 2054 layer_or_ancestor_clips_descendants = true; |
2052 if (ancestor_clips_subtree && !layer->render_surface()) { | 2055 if (ancestor_clips_subtree && !render_to_separate_surface) { |
2053 // A layer without render surface shares the same target as its ancestor. | 2056 // A layer without render surface shares the same target as its ancestor. |
2054 clip_rect_in_target_space = | 2057 clip_rect_in_target_space = |
2055 ancestor_clip_rect_in_target_space; | 2058 ancestor_clip_rect_in_target_space; |
2056 clip_rect_in_target_space.Intersect(rect_in_target_space); | 2059 clip_rect_in_target_space.Intersect(rect_in_target_space); |
2057 } else { | 2060 } else { |
2058 clip_rect_in_target_space = rect_in_target_space; | 2061 clip_rect_in_target_space = rect_in_target_space; |
2059 } | 2062 } |
2060 } | 2063 } |
2061 | 2064 |
2062 // Tell the layer the rect that it's clipped by. In theory we could use a | 2065 // Tell the layer the rect that it's clipped by. In theory we could use a |
2063 // tighter clip rect here (drawable_content_rect), but that actually does not | 2066 // tighter clip rect here (drawable_content_rect), but that actually does not |
2064 // reduce how much would be drawn, and instead it would create unnecessary | 2067 // reduce how much would be drawn, and instead it would create unnecessary |
2065 // changes to scissor state affecting GPU performance. Our clip information | 2068 // changes to scissor state affecting GPU performance. Our clip information |
2066 // is used in the recursion below, so we must set it beforehand. | 2069 // is used in the recursion below, so we must set it beforehand. |
2067 layer_draw_properties.is_clipped = layer_or_ancestor_clips_descendants; | 2070 layer_draw_properties.is_clipped = layer_or_ancestor_clips_descendants; |
2068 if (layer_or_ancestor_clips_descendants) { | 2071 if (layer_or_ancestor_clips_descendants) { |
2069 layer_draw_properties.clip_rect = clip_rect_in_target_space; | 2072 layer_draw_properties.clip_rect = clip_rect_in_target_space; |
2070 } else { | 2073 } else { |
2071 // Initialize the clip rect to a safe value that will not clip the | 2074 // Initialize the clip rect to a safe value that will not clip the |
2072 // layer, just in case clipping is still accidentally used. | 2075 // layer, just in case clipping is still accidentally used. |
2073 layer_draw_properties.clip_rect = rect_in_target_space; | 2076 layer_draw_properties.clip_rect = rect_in_target_space; |
2074 } | 2077 } |
2075 | 2078 |
2076 typename LayerType::LayerListType& descendants = | 2079 typename LayerType::LayerListType& descendants = |
2077 (layer->render_surface() ? layer->render_surface()->layer_list() | 2080 (render_to_separate_surface ? layer->render_surface()->layer_list() |
2078 : *layer_list); | 2081 : *layer_list); |
2079 | 2082 |
2080 // Any layers that are appended after this point are in the layer's subtree | 2083 // Any layers that are appended after this point are in the layer's subtree |
2081 // and should be included in the sorting process. | 2084 // and should be included in the sorting process. |
2082 size_t sorting_start_index = descendants.size(); | 2085 size_t sorting_start_index = descendants.size(); |
2083 | 2086 |
2084 if (!LayerShouldBeSkipped(layer, layer_is_drawn)) { | 2087 if (!LayerShouldBeSkipped(layer, layer_is_drawn)) { |
2085 MarkLayerWithRenderSurfaceLayerListId(layer, | 2088 MarkLayerWithRenderSurfaceLayerListId(layer, |
2086 current_render_surface_layer_list_id); | 2089 current_render_surface_layer_list_id); |
2087 descendants.push_back(layer); | 2090 descendants.push_back(layer); |
2088 } | 2091 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2146 render_surface_layer_list->size(); | 2149 render_surface_layer_list->size(); |
2147 | 2150 |
2148 CalculateDrawPropertiesInternal<LayerType>( | 2151 CalculateDrawPropertiesInternal<LayerType>( |
2149 child, | 2152 child, |
2150 globals, | 2153 globals, |
2151 data_for_children, | 2154 data_for_children, |
2152 render_surface_layer_list, | 2155 render_surface_layer_list, |
2153 &descendants, | 2156 &descendants, |
2154 accumulated_surface_state, | 2157 accumulated_surface_state, |
2155 current_render_surface_layer_list_id); | 2158 current_render_surface_layer_list_id); |
2156 if (child->render_surface() && | 2159 // If the child is its own render target, then it has a render surface. |
2160 if (child->render_target() == child && | |
2157 !child->render_surface()->layer_list().empty() && | 2161 !child->render_surface()->layer_list().empty() && |
2158 !child->render_surface()->content_rect().IsEmpty()) { | 2162 !child->render_surface()->content_rect().IsEmpty()) { |
2159 // This child will contribute its render surface, which means | 2163 // This child will contribute its render surface, which means |
2160 // we need to mark just the mask layer (and replica mask layer) | 2164 // we need to mark just the mask layer (and replica mask layer) |
2161 // with the id. | 2165 // with the id. |
2162 MarkMasksWithRenderSurfaceLayerListId( | 2166 MarkMasksWithRenderSurfaceLayerListId( |
2163 child, current_render_surface_layer_list_id); | 2167 child, current_render_surface_layer_list_id); |
2164 descendants.push_back(child); | 2168 descendants.push_back(child); |
2165 } | 2169 } |
2166 | 2170 |
(...skipping 18 matching lines...) Expand all Loading... | |
2185 *layer, | 2189 *layer, |
2186 &descendants, | 2190 &descendants, |
2187 layer_list_child_sorting_start_index, | 2191 layer_list_child_sorting_start_index, |
2188 &GetNewDescendantsStartIndexAndCount<LayerType>); | 2192 &GetNewDescendantsStartIndexAndCount<LayerType>); |
2189 } | 2193 } |
2190 | 2194 |
2191 // Compute the total drawable_content_rect for this subtree (the rect is in | 2195 // Compute the total drawable_content_rect for this subtree (the rect is in |
2192 // target surface space). | 2196 // target surface space). |
2193 gfx::Rect local_drawable_content_rect_of_subtree = | 2197 gfx::Rect local_drawable_content_rect_of_subtree = |
2194 accumulated_surface_state->back().drawable_content_rect; | 2198 accumulated_surface_state->back().drawable_content_rect; |
2195 if (layer->render_surface()) { | 2199 if (render_to_separate_surface) { |
2196 DCHECK(accumulated_surface_state->back().render_target == layer); | 2200 DCHECK(accumulated_surface_state->back().render_target == layer); |
2197 accumulated_surface_state->pop_back(); | 2201 accumulated_surface_state->pop_back(); |
2198 } | 2202 } |
2199 | 2203 |
2200 if (layer->render_surface() && !IsRootLayer(layer) && | 2204 if (render_to_separate_surface && !IsRootLayer(layer) && |
2201 layer->render_surface()->layer_list().empty()) { | 2205 layer->render_surface()->layer_list().empty()) { |
2202 RemoveSurfaceForEarlyExit(layer, render_surface_layer_list); | 2206 RemoveSurfaceForEarlyExit(layer, render_surface_layer_list); |
2203 return; | 2207 return; |
2204 } | 2208 } |
2205 | 2209 |
2206 // Compute the layer's drawable content rect (the rect is in target surface | 2210 // Compute the layer's drawable content rect (the rect is in target surface |
2207 // space). | 2211 // space). |
2208 layer_draw_properties.drawable_content_rect = rect_in_target_space; | 2212 layer_draw_properties.drawable_content_rect = rect_in_target_space; |
2209 if (layer_or_ancestor_clips_descendants) { | 2213 if (layer_or_ancestor_clips_descendants) { |
2210 layer_draw_properties.drawable_content_rect.Intersect( | 2214 layer_draw_properties.drawable_content_rect.Intersect( |
2211 clip_rect_in_target_space); | 2215 clip_rect_in_target_space); |
2212 } | 2216 } |
2213 if (layer->DrawsContent()) { | 2217 if (layer->DrawsContent()) { |
2214 local_drawable_content_rect_of_subtree.Union( | 2218 local_drawable_content_rect_of_subtree.Union( |
2215 layer_draw_properties.drawable_content_rect); | 2219 layer_draw_properties.drawable_content_rect); |
2216 } | 2220 } |
2217 | 2221 |
2218 // Compute the layer's visible content rect (the rect is in content space). | 2222 // Compute the layer's visible content rect (the rect is in content space). |
2219 layer_draw_properties.visible_content_rect = CalculateVisibleContentRect( | 2223 layer_draw_properties.visible_content_rect = CalculateVisibleContentRect( |
2220 layer, clip_rect_of_target_surface_in_target_space, rect_in_target_space); | 2224 layer, clip_rect_of_target_surface_in_target_space, rect_in_target_space); |
2221 | 2225 |
2222 // Compute the remaining properties for the render surface, if the layer has | 2226 // Compute the remaining properties for the render surface, if the layer has |
2223 // one. | 2227 // one. |
2224 if (IsRootLayer(layer)) { | 2228 if (IsRootLayer(layer)) { |
2225 // The root layer's surface's content_rect is always the entire viewport. | 2229 // The root layer's surface's content_rect is always the entire viewport. |
2226 DCHECK(layer->render_surface()); | 2230 DCHECK(render_to_separate_surface); |
2227 layer->render_surface()->SetContentRect( | 2231 layer->render_surface()->SetContentRect( |
2228 ancestor_clip_rect_in_target_space); | 2232 ancestor_clip_rect_in_target_space); |
2229 } else if (layer->render_surface()) { | 2233 } else if (render_to_separate_surface) { |
2230 typename LayerType::RenderSurfaceType* render_surface = | 2234 typename LayerType::RenderSurfaceType* render_surface = |
2231 layer->render_surface(); | 2235 layer->render_surface(); |
2232 gfx::Rect clipped_content_rect = local_drawable_content_rect_of_subtree; | 2236 gfx::Rect clipped_content_rect = local_drawable_content_rect_of_subtree; |
2233 | 2237 |
2234 // Don't clip if the layer is reflected as the reflection shouldn't be | 2238 // Don't clip if the layer is reflected as the reflection shouldn't be |
2235 // clipped. If the layer is animating, then the surface's transform to | 2239 // clipped. If the layer is animating, then the surface's transform to |
2236 // its target is not known on the main thread, and we should not use it | 2240 // its target is not known on the main thread, and we should not use it |
2237 // to clip. | 2241 // to clip. |
2238 if (!layer->replica_layer() && TransformToParentIsKnown(layer)) { | 2242 if (!layer->replica_layer() && TransformToParentIsKnown(layer)) { |
2239 // Note, it is correct to use data_from_ancestor.ancestor_clips_subtree | 2243 // Note, it is correct to use data_from_ancestor.ancestor_clips_subtree |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2313 surface_origin_to_replica_origin_transform; | 2317 surface_origin_to_replica_origin_transform; |
2314 render_surface->SetReplicaScreenSpaceTransform( | 2318 render_surface->SetReplicaScreenSpaceTransform( |
2315 replica_screen_space_transform); | 2319 replica_screen_space_transform); |
2316 } | 2320 } |
2317 } | 2321 } |
2318 | 2322 |
2319 SavePaintPropertiesLayer(layer); | 2323 SavePaintPropertiesLayer(layer); |
2320 | 2324 |
2321 // If neither this layer nor any of its children were added, early out. | 2325 // If neither this layer nor any of its children were added, early out. |
2322 if (sorting_start_index == descendants.size()) { | 2326 if (sorting_start_index == descendants.size()) { |
2323 DCHECK(!layer->render_surface() || IsRootLayer(layer)); | 2327 DCHECK(!render_to_separate_surface || IsRootLayer(layer)); |
2324 return; | 2328 return; |
2325 } | 2329 } |
2326 | 2330 |
2327 // If preserves-3d then sort all the descendants in 3D so that they can be | 2331 // If preserves-3d then sort all the descendants in 3D so that they can be |
2328 // drawn from back to front. If the preserves-3d property is also set on the | 2332 // drawn from back to front. If the preserves-3d property is also set on the |
2329 // parent then skip the sorting as the parent will sort all the descendants | 2333 // parent then skip the sorting as the parent will sort all the descendants |
2330 // anyway. | 2334 // anyway. |
2331 if (globals.layer_sorter && descendants.size() && layer->Is3dSorted() && | 2335 if (globals.layer_sorter && descendants.size() && layer->Is3dSorted() && |
2332 !LayerIsInExisting3DRenderingContext(layer)) { | 2336 !LayerIsInExisting3DRenderingContext(layer)) { |
2333 SortLayers(descendants.begin() + sorting_start_index, | 2337 SortLayers(descendants.begin() + sorting_start_index, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2393 device_viewport_rect; | 2397 device_viewport_rect; |
2394 data_for_recursion->maximum_animation_contents_scale = 0.f; | 2398 data_for_recursion->maximum_animation_contents_scale = 0.f; |
2395 data_for_recursion->ancestor_is_animating_scale = false; | 2399 data_for_recursion->ancestor_is_animating_scale = false; |
2396 data_for_recursion->ancestor_clips_subtree = true; | 2400 data_for_recursion->ancestor_clips_subtree = true; |
2397 data_for_recursion->nearest_occlusion_immune_ancestor_surface = NULL; | 2401 data_for_recursion->nearest_occlusion_immune_ancestor_surface = NULL; |
2398 data_for_recursion->in_subtree_of_page_scale_application_layer = false; | 2402 data_for_recursion->in_subtree_of_page_scale_application_layer = false; |
2399 data_for_recursion->subtree_can_use_lcd_text = inputs.can_use_lcd_text; | 2403 data_for_recursion->subtree_can_use_lcd_text = inputs.can_use_lcd_text; |
2400 data_for_recursion->subtree_is_visible_from_ancestor = true; | 2404 data_for_recursion->subtree_is_visible_from_ancestor = true; |
2401 } | 2405 } |
2402 | 2406 |
2407 void LayerTreeHostCommon::UpdateRenderSurface( | |
2408 Layer* layer, | |
2409 bool can_render_to_separate_surface, | |
2410 gfx::Transform* transform, | |
2411 bool* draw_transform_is_axis_aligned) { | |
2412 bool preserves_2d_axis_alignment = | |
2413 transform->Preserves2dAxisAlignment() && *draw_transform_is_axis_aligned; | |
2414 if (IsRootLayer(layer) || (can_render_to_separate_surface && | |
2415 SubtreeShouldRenderToSeparateSurface( | |
2416 layer, preserves_2d_axis_alignment))) { | |
2417 // We reset the transform here so that any axis-changing transforms | |
2418 // will now be relative to this RenderSurface. | |
2419 transform->MakeIdentity(); | |
2420 *draw_transform_is_axis_aligned = true; | |
2421 if (!layer->render_surface()) { | |
2422 layer->CreateRenderSurface(); | |
2423 } | |
2424 layer->SetHasRenderSurface(true); | |
2425 return; | |
2426 } | |
2427 layer->SetHasRenderSurface(false); | |
2428 if (layer->render_surface()) | |
2429 layer->ClearRenderSurface(); | |
2430 } | |
2431 | |
2432 void LayerTreeHostCommon::UpdateRenderSurfaces( | |
2433 Layer* layer, | |
2434 bool can_render_to_separate_surface, | |
2435 const gfx::Transform& parent_transform, | |
2436 bool draw_transform_is_axis_aligned) { | |
2437 gfx::Transform transform_for_children = layer->transform(); | |
2438 transform_for_children *= parent_transform; | |
2439 draw_transform_is_axis_aligned &= layer->AnimationsPreserveAxisAlignment(); | |
2440 UpdateRenderSurface(layer, can_render_to_separate_surface, | |
2441 &transform_for_children, &draw_transform_is_axis_aligned); | |
2442 | |
2443 for (size_t i = 0; i < layer->children().size(); ++i) { | |
2444 UpdateRenderSurfaces(layer->children()[i].get(), | |
2445 can_render_to_separate_surface, transform_for_children, | |
2446 draw_transform_is_axis_aligned); | |
2447 } | |
2448 } | |
2449 | |
2403 void LayerTreeHostCommon::CalculateDrawProperties( | 2450 void LayerTreeHostCommon::CalculateDrawProperties( |
2404 CalcDrawPropsMainInputs* inputs) { | 2451 CalcDrawPropsMainInputs* inputs) { |
2452 UpdateRenderSurfaces(inputs->root_layer, | |
2453 inputs->can_render_to_separate_surface, gfx::Transform(), | |
2454 false); | |
2405 LayerList dummy_layer_list; | 2455 LayerList dummy_layer_list; |
2406 SubtreeGlobals<Layer> globals; | 2456 SubtreeGlobals<Layer> globals; |
2407 DataForRecursion<Layer> data_for_recursion; | 2457 DataForRecursion<Layer> data_for_recursion; |
2408 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); | 2458 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); |
2409 | 2459 |
2410 PreCalculateMetaInformationRecursiveData recursive_data; | 2460 PreCalculateMetaInformationRecursiveData recursive_data; |
2411 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); | 2461 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); |
2412 std::vector<AccumulatedSurfaceState<Layer>> accumulated_surface_state; | 2462 std::vector<AccumulatedSurfaceState<Layer>> accumulated_surface_state; |
2413 CalculateDrawPropertiesInternal<Layer>( | 2463 CalculateDrawPropertiesInternal<Layer>( |
2414 inputs->root_layer, | 2464 inputs->root_layer, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2449 inputs->current_render_surface_layer_list_id); | 2499 inputs->current_render_surface_layer_list_id); |
2450 | 2500 |
2451 // The dummy layer list should not have been used. | 2501 // The dummy layer list should not have been used. |
2452 DCHECK_EQ(0u, dummy_layer_list.size()); | 2502 DCHECK_EQ(0u, dummy_layer_list.size()); |
2453 // A root layer render_surface should always exist after | 2503 // A root layer render_surface should always exist after |
2454 // CalculateDrawProperties. | 2504 // CalculateDrawProperties. |
2455 DCHECK(inputs->root_layer->render_surface()); | 2505 DCHECK(inputs->root_layer->render_surface()); |
2456 } | 2506 } |
2457 | 2507 |
2458 } // namespace cc | 2508 } // namespace cc |
OLD | NEW |