Chromium Code Reviews| Index: cc/trees/layer_tree_host_common.cc |
| diff --git a/cc/trees/layer_tree_host_common.cc b/cc/trees/layer_tree_host_common.cc |
| index 0ff66084cc76ad08a064d933edc6058dde880d18..c283ecd31cbad4c602bacb7986a70acabfec9b7a 100644 |
| --- a/cc/trees/layer_tree_host_common.cc |
| +++ b/cc/trees/layer_tree_host_common.cc |
| @@ -550,9 +550,8 @@ static inline void SavePaintPropertiesLayer(Layer* layer) { |
| layer->replica_layer()->mask_layer()->SavePaintProperties(); |
| } |
| -template <typename LayerType> |
| static bool SubtreeShouldRenderToSeparateSurface( |
| - LayerType* layer, |
| + Layer* layer, |
| bool axis_aligned_with_respect_to_parent) { |
| // |
| // A layer and its descendants should render onto a new RenderSurfaceImpl if |
| @@ -1108,18 +1107,6 @@ static inline void CalculateAnimationContentsScale( |
| std::max(ancestor_transform_scales.x(), ancestor_transform_scales.y()); |
| } |
| -template <typename LayerType> |
| -static inline typename LayerType::RenderSurfaceType* CreateOrReuseRenderSurface( |
| - LayerType* layer) { |
| - if (!layer->render_surface()) { |
| - layer->CreateRenderSurface(); |
| - return layer->render_surface(); |
| - } |
| - |
| - layer->render_surface()->ClearLayerLists(); |
| - return layer->render_surface(); |
| -} |
| - |
| template <typename LayerTypePtr> |
| static inline void MarkLayerWithRenderSurfaceLayerListId( |
| LayerTypePtr layer, |
| @@ -1816,14 +1803,12 @@ static void CalculateDrawPropertiesInternal( |
| ? combined_transform_scales |
| : gfx::Vector2dF(layer_scale_factors, layer_scale_factors); |
| - bool render_to_separate_surface; |
| - if (globals.can_render_to_separate_surface) { |
| - render_to_separate_surface = SubtreeShouldRenderToSeparateSurface( |
| - layer, combined_transform.Preserves2dAxisAlignment()); |
| - } else { |
| - render_to_separate_surface = IsRootLayer(layer); |
| - } |
| + bool render_to_separate_surface = |
| + IsRootLayer(layer) || |
| + (globals.can_render_to_separate_surface && layer->render_surface()); |
| + |
| if (render_to_separate_surface) { |
| + DCHECK(layer->render_surface()); |
| // Check back-face visibility before continuing with this surface and its |
| // subtree |
| if (!layer->double_sided() && TransformToParentIsKnown(layer) && |
| @@ -1833,8 +1818,10 @@ static void CalculateDrawPropertiesInternal( |
| } |
| typename LayerType::RenderSurfaceType* render_surface = |
| - CreateOrReuseRenderSurface(layer); |
| + layer->render_surface(); |
| + layer->ClearRenderSurfaceLayerList(); |
| + layer_draw_properties.render_target = layer; |
| if (IsRootLayer(layer)) { |
| // The root layer's render surface size is predetermined and so the root |
| // layer can't directly support non-identity transforms. It should just |
| @@ -2014,8 +2001,6 @@ static void CalculateDrawPropertiesInternal( |
| animating_opacity_to_screen; |
| data_for_children.parent_matrix = combined_transform; |
| - layer->ClearRenderSurface(); |
| - |
| // Layers without render_surfaces directly inherit the ancestor's clip |
| // status. |
| layer_or_ancestor_clips_descendants = ancestor_clips_subtree; |
| @@ -2042,7 +2027,7 @@ static void CalculateDrawPropertiesInternal( |
| if (LayerClipsSubtree(layer)) { |
| layer_or_ancestor_clips_descendants = true; |
| - if (ancestor_clips_subtree && !layer->render_surface()) { |
| + if (ancestor_clips_subtree && !render_to_separate_surface) { |
| // A layer without render surface shares the same target as its ancestor. |
| clip_rect_in_target_space = |
| ancestor_clip_rect_in_target_space; |
| @@ -2067,8 +2052,8 @@ static void CalculateDrawPropertiesInternal( |
| } |
| typename LayerType::LayerListType& descendants = |
| - (layer->render_surface() ? layer->render_surface()->layer_list() |
| - : *layer_list); |
| + (render_to_separate_surface ? layer->render_surface()->layer_list() |
| + : *layer_list); |
| // Any layers that are appended after this point are in the layer's subtree |
| // and should be included in the sorting process. |
| @@ -2146,7 +2131,8 @@ static void CalculateDrawPropertiesInternal( |
| &descendants, |
| accumulated_surface_state, |
| current_render_surface_layer_list_id); |
| - if (child->render_surface() && |
| + // If the child is its own render target, then it has a render surface. |
| + if (child->render_target() == child && |
| !child->render_surface()->layer_list().empty() && |
| !child->render_surface()->content_rect().IsEmpty()) { |
| // This child will contribute its render surface, which means |
| @@ -2185,12 +2171,12 @@ static void CalculateDrawPropertiesInternal( |
| // target surface space). |
| gfx::Rect local_drawable_content_rect_of_subtree = |
| accumulated_surface_state->back().drawable_content_rect; |
| - if (layer->render_surface()) { |
| + if (render_to_separate_surface) { |
| DCHECK(accumulated_surface_state->back().render_target == layer); |
| accumulated_surface_state->pop_back(); |
| } |
| - if (layer->render_surface() && !IsRootLayer(layer) && |
| + if (render_to_separate_surface && !IsRootLayer(layer) && |
| layer->render_surface()->layer_list().empty()) { |
| RemoveSurfaceForEarlyExit(layer, render_surface_layer_list); |
| return; |
| @@ -2216,10 +2202,10 @@ static void CalculateDrawPropertiesInternal( |
| // one. |
| if (IsRootLayer(layer)) { |
| // The root layer's surface's content_rect is always the entire viewport. |
| - DCHECK(layer->render_surface()); |
| + DCHECK(render_to_separate_surface); |
| layer->render_surface()->SetContentRect( |
| ancestor_clip_rect_in_target_space); |
| - } else if (layer->render_surface()) { |
| + } else if (render_to_separate_surface) { |
| typename LayerType::RenderSurfaceType* render_surface = |
| layer->render_surface(); |
| gfx::Rect clipped_content_rect = local_drawable_content_rect_of_subtree; |
| @@ -2313,7 +2299,7 @@ static void CalculateDrawPropertiesInternal( |
| // If neither this layer nor any of its children were added, early out. |
| if (sorting_start_index == descendants.size()) { |
| - DCHECK(!layer->render_surface() || IsRootLayer(layer)); |
| + DCHECK(!render_to_separate_surface || IsRootLayer(layer)); |
| return; |
| } |
| @@ -2391,8 +2377,56 @@ static void ProcessCalcDrawPropsInputs( |
| data_for_recursion->subtree_is_visible_from_ancestor = true; |
| } |
| +void CreateOrDestroyRenderSurface(Layer* layer, |
| + bool can_render_to_separate_surface, |
| + gfx::Transform* transform, |
| + bool *non_aligned_animated_transform) { |
| + bool preserves_2d_axis_alignment = transform->Preserves2dAxisAlignment() && |
| + !*non_aligned_animated_transform; |
| + if (IsRootLayer(layer) || (can_render_to_separate_surface && |
| + SubtreeShouldRenderToSeparateSurface( |
| + layer, preserves_2d_axis_alignment))) { |
| + // We reset the transform here so that any axis-changing transforms |
| + // will now be relative to this Render Surface. |
|
enne (OOO)
2014/12/12 21:26:32
nit: RenderSurface or "render surface", but not Re
awoloszyn
2014/12/15 20:24:53
Done.
|
| + transform->MakeIdentity(); |
| + *non_aligned_animated_transform = false; |
|
enne (OOO)
2014/12/12 21:26:32
nit: What about draw_transform_is_axis_aligned? I
awoloszyn
2014/12/15 20:24:53
Done.
|
| + if (!layer->render_surface()) { |
| + layer->CreateRenderSurface(); |
| + } |
| + layer->SetHasRenderSurface(true); |
| + return; |
| + } |
| + layer->SetHasRenderSurface(false); |
| + if (layer->render_surface()) |
| + layer->ClearRenderSurface(); |
| +} |
| + |
| +static void CreateRenderSurfaces(Layer* layer, |
|
enne (OOO)
2014/12/12 21:26:32
nit: Can you name these functions consistently? Cr
awoloszyn
2014/12/15 20:24:53
Done.
awoloszyn
2014/12/15 20:24:53
Done.
|
| + bool can_render_to_separate_surface, |
| + const gfx::Transform& parent_transform, |
| + bool non_aligned_animated_transform) { |
| + gfx::Transform transformForChildren = layer->transform(); |
|
enne (OOO)
2014/12/12 21:26:32
transform_for_children
awoloszyn
2014/12/15 20:24:53
Done.
|
| + transformForChildren *= parent_transform; |
| + non_aligned_animated_transform |= |
| + layer->HasNotAxisAlignedTransformAnimation(); |
| + CreateOrDestroyRenderSurface(layer, can_render_to_separate_surface, |
| + &transformForChildren, |
| + &non_aligned_animated_transform); |
| + |
| + for (size_t i = 0; i < layer->children().size(); ++i) { |
| + CreateRenderSurfaces(layer->children()[i].get(), |
| + can_render_to_separate_surface, |
| + transformForChildren, |
| + non_aligned_animated_transform); |
| + } |
| +} |
| + |
| void LayerTreeHostCommon::CalculateDrawProperties( |
| CalcDrawPropsMainInputs* inputs) { |
| + CreateRenderSurfaces(inputs->root_layer, |
| + inputs->can_render_to_separate_surface, |
| + gfx::Transform(), |
| + false); |
| LayerList dummy_layer_list; |
| SubtreeGlobals<Layer> globals; |
| DataForRecursion<Layer> data_for_recursion; |