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 840a32b2ef4a59037f22e33e251c9edee72bc649..6dd6b64363f31e67b5066a3b109c87fe8b7f8898 100644 |
--- a/cc/trees/layer_tree_host_common.cc |
+++ b/cc/trees/layer_tree_host_common.cc |
@@ -548,9 +548,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 |
@@ -1106,18 +1105,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, |
@@ -1813,14 +1800,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) && |
@@ -1830,8 +1815,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 |
@@ -2006,8 +1993,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; |
@@ -2034,7 +2019,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; |
@@ -2059,8 +2044,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. |
@@ -2138,7 +2123,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 |
@@ -2177,12 +2163,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; |
@@ -2208,10 +2194,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; |
@@ -2305,7 +2291,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; |
} |
@@ -2383,8 +2369,47 @@ 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) { |
+ if (IsRootLayer(layer) || |
+ (can_render_to_separate_surface && |
+ SubtreeShouldRenderToSeparateSurface( |
+ layer, transform->Preserves2dAxisAlignment()))) { |
+ transform->MakeIdentity(); |
danakj
2014/09/25 16:02:12
Please add a thorough comment explaining this Make
awoloszyn
2014/11/25 15:48:46
Done.
|
+ if (!layer->render_surface()) { |
danakj
2014/09/25 16:02:12
since we always clear them on the main thread, can
awoloszyn
2014/11/25 15:48:46
If we had a render surface and then it was cleaned
|
+ layer->CreateRenderSurface(); |
+ } |
+ layer->SetHasRenderSurface(true); |
+ return; |
+ } |
+ layer->SetHasRenderSurface(false); |
+ if (layer->render_surface()) |
danakj
2014/09/25 16:02:12
can this also DCHECK instead and drop the Clear?
awoloszyn
2014/11/25 15:48:46
Same as above.
|
+ layer->ClearRenderSurface(); |
+} |
+ |
+static void CreateRenderSurfaces(Layer* layer, |
+ bool can_render_to_separate_surface, |
+ const gfx::Transform& parent_transform) { |
+ if (!layer) |
danakj
2014/09/25 16:02:12
why is this needed, you can't call CDP() with a nu
awoloszyn
2014/11/25 15:48:46
Was done for a unit-test originally, but no longer
|
+ return; |
+ gfx::Transform transformForChildren = layer->transform(); |
+ transformForChildren *= parent_transform; |
+ CreateOrDestroyRenderSurface( |
+ layer, can_render_to_separate_surface, &transformForChildren); |
+ |
+ for (size_t i = 0; i < layer->children().size(); ++i) { |
+ CreateRenderSurfaces(layer->children()[i].get(), |
+ can_render_to_separate_surface, |
+ transformForChildren); |
+ } |
+} |
+ |
void LayerTreeHostCommon::CalculateDrawProperties( |
CalcDrawPropsMainInputs* inputs) { |
+ CreateRenderSurfaces(inputs->root_layer, |
+ inputs->can_render_to_separate_surface, |
+ gfx::Transform()); |
LayerList dummy_layer_list; |
SubtreeGlobals<Layer> globals; |
DataForRecursion<Layer> data_for_recursion; |