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 5d0c9afc1929f57e8fa69ab66dd5e2d0b3069ff4..f933dcfef6217b5d37c44d975fa2eba2331dd7c1 100644 |
| --- a/cc/trees/layer_tree_host_common.cc |
| +++ b/cc/trees/layer_tree_host_common.cc |
| @@ -907,10 +907,12 @@ static inline void CalculateContentsScale(LayerType* layer, |
| float contents_scale, |
| float device_scale_factor, |
| float page_scale_factor, |
| + float maximum_animation_scale_factor, |
| bool animating_transform_to_screen) { |
| layer->CalculateContentsScale(contents_scale, |
| device_scale_factor, |
| page_scale_factor, |
| + maximum_animation_scale_factor, |
| animating_transform_to_screen, |
| &layer->draw_properties().contents_scale_x, |
| &layer->draw_properties().contents_scale_y, |
| @@ -922,6 +924,7 @@ static inline void CalculateContentsScale(LayerType* layer, |
| contents_scale, |
| device_scale_factor, |
| page_scale_factor, |
| + maximum_animation_scale_factor, |
| animating_transform_to_screen, |
| &mask_layer->draw_properties().contents_scale_x, |
| &mask_layer->draw_properties().contents_scale_y, |
| @@ -935,6 +938,7 @@ static inline void CalculateContentsScale(LayerType* layer, |
| contents_scale, |
| device_scale_factor, |
| page_scale_factor, |
| + maximum_animation_scale_factor, |
| animating_transform_to_screen, |
| &replica_mask_layer->draw_properties().contents_scale_x, |
| &replica_mask_layer->draw_properties().contents_scale_y, |
| @@ -948,11 +952,13 @@ static inline void UpdateLayerContentsScale( |
| float ideal_contents_scale, |
| float device_scale_factor, |
| float page_scale_factor, |
| + float maximum_animation_scale_factor, |
| bool animating_transform_to_screen) { |
| CalculateContentsScale(layer, |
| ideal_contents_scale, |
| device_scale_factor, |
| page_scale_factor, |
| + maximum_animation_scale_factor, |
| animating_transform_to_screen); |
| } |
| @@ -962,6 +968,7 @@ static inline void UpdateLayerContentsScale( |
| float ideal_contents_scale, |
| float device_scale_factor, |
| float page_scale_factor, |
| + float maximum_animation_scale_factor, |
| bool animating_transform_to_screen) { |
| if (can_adjust_raster_scale) { |
| float ideal_raster_scale = |
| @@ -998,6 +1005,7 @@ static inline void UpdateLayerContentsScale( |
| contents_scale, |
| device_scale_factor, |
| page_scale_factor, |
| + maximum_animation_scale_factor, |
| animating_transform_to_screen); |
| if (layer->content_bounds() != old_content_bounds || |
| @@ -1006,6 +1014,60 @@ static inline void UpdateLayerContentsScale( |
| layer->SetNeedsPushProperties(); |
| } |
| +template <typename LayerType> |
| +static inline void CalculateAnimationScaleFactor( |
|
enne (OOO)
2014/04/08 14:19:41
Can you template this to only do work for LayerImp
ajuma
2014/04/08 18:59:17
Done.
|
| + LayerType* layer, |
| + bool ancestor_is_animating_scale, |
| + float ancestor_maximum_animation_scale_factor, |
| + const gfx::Transform& combined_transform, |
| + bool* combined_is_animating_scale, |
| + float* combined_maximum_animation_scale_factor) { |
| + if (ancestor_maximum_animation_scale_factor == 0.f || |
| + !combined_transform.IsScaleOrTranslation()) { |
| + *combined_maximum_animation_scale_factor = 0.f; |
| + *combined_is_animating_scale = true; |
| + return; |
| + } |
| + |
| + bool layer_is_animating_scale = |
| + !layer->layer_animation_controller()->HasOnlyTranslationTransforms(); |
| + if (!layer_is_animating_scale) { |
| + *combined_is_animating_scale = ancestor_is_animating_scale; |
| + *combined_maximum_animation_scale_factor = |
| + ancestor_maximum_animation_scale_factor; |
| + return; |
| + } |
| + |
| + *combined_is_animating_scale = true; |
| + // We don't attempt to accumulate animation scale factors from multiple nodes, |
| + // because of the risk of significant overestimation. For example, one node |
| + // may be increasing scale from 1 to 10 at the same time as a descendant is |
| + // decreasing scale from 10 to 1. Naively combining these scales would produce |
| + // a scale of 100. |
| + if (ancestor_is_animating_scale) { |
| + *combined_maximum_animation_scale_factor = 0.f; |
| + return; |
| + } |
| + DCHECK(ancestor_maximum_animation_scale_factor == 1.f); |
| + |
| + float layer_maximum_animated_scale = 0.f; |
| + if (!layer->layer_animation_controller()->MaximumScale( |
| + &layer_maximum_animated_scale)) { |
| + *combined_maximum_animation_scale_factor = 0.f; |
| + return; |
| + } |
| + |
| + // Now that we know the maximum scale during the animation, we need to find |
| + // the layer's current scale to determine the factor by which the layer will |
| + // be further scaled up. |
| + gfx::Vector2dF layer_transform_scales = |
| + MathUtil::ComputeTransform2dScaleComponents(layer->transform(), 0.f); |
| + DCHECK(layer_transform_scales != gfx::Vector2dF()); |
|
enne (OOO)
2014/04/08 14:19:41
Can you convince me this is legit? It seems like a
ajuma
2014/04/08 18:59:17
This code has now been removed, but the reason we
|
| + *combined_maximum_animation_scale_factor = |
| + layer_maximum_animated_scale / |
| + std::max(layer_transform_scales.x(), layer_transform_scales.y()); |
|
enne (OOO)
2014/04/08 14:19:41
This scares me.
How do you prevent multiple tilin
ajuma
2014/04/08 18:59:17
I've removed the division-based approach. We no lo
|
| +} |
| + |
| static inline RenderSurface* CreateOrReuseRenderSurface(Layer* layer) { |
| // The render surface should always be new on the main thread, as the |
| // RenderSurfaceLayerList should be a new empty list when given to |
| @@ -1165,6 +1227,11 @@ struct DataForRecursion { |
| // passed down the recursion to the children that actually use it. |
| gfx::Rect clip_rect_of_target_surface_in_target_space; |
| + // The maximum factor by which currently running animations will be |
| + // scaling-up the layer during their lifetime. |
| + float maximum_animation_scale_factor; |
| + |
| + bool ancestor_is_animating_scale; |
| bool ancestor_clips_subtree; |
| typename LayerType::RenderSurfaceType* |
| nearest_occlusion_immune_ancestor_surface; |
| @@ -1546,6 +1613,21 @@ static void CalculateDrawPropertiesInternal( |
| ApplyPositionAdjustment(layer, data_from_ancestor.fixed_container, |
| data_from_ancestor.scroll_compensation_matrix, &combined_transform); |
| + bool combined_is_animating_scale = false; |
| + float combined_maximum_animation_scale_factor = 1.f; |
| + if (globals.can_adjust_raster_scales) { |
| + CalculateAnimationScaleFactor( |
| + layer, |
| + data_from_ancestor.ancestor_is_animating_scale, |
| + data_from_ancestor.maximum_animation_scale_factor, |
| + combined_transform, |
| + &combined_is_animating_scale, |
| + &combined_maximum_animation_scale_factor); |
| + } |
| + data_for_children.ancestor_is_animating_scale = combined_is_animating_scale; |
| + data_for_children.maximum_animation_scale_factor = |
| + combined_maximum_animation_scale_factor; |
| + |
| // Compute the 2d scale components of the transform hierarchy up to the target |
| // surface. From there, we can decide on a contents scale for the layer. |
| float layer_scale_factors = globals.device_scale_factor; |
| @@ -1566,8 +1648,10 @@ static void CalculateDrawPropertiesInternal( |
| globals.can_adjust_raster_scales, |
| ideal_contents_scale, |
| globals.device_scale_factor, |
| - data_from_ancestor.in_subtree_of_page_scale_application_layer ? |
| - globals.page_scale_factor : 1.f, |
| + data_from_ancestor.in_subtree_of_page_scale_application_layer |
| + ? globals.page_scale_factor |
| + : 1.f, |
| + combined_maximum_animation_scale_factor, |
| animating_transform_to_screen); |
| // The draw_transform that gets computed below is effectively the layer's |
| @@ -2155,6 +2239,8 @@ void LayerTreeHostCommon::CalculateDrawProperties( |
| data_for_recursion.clip_rect_in_target_space = device_viewport_rect; |
| data_for_recursion.clip_rect_of_target_surface_in_target_space = |
| device_viewport_rect; |
| + data_for_recursion.maximum_animation_scale_factor = 1.f; |
| + data_for_recursion.ancestor_is_animating_scale = false; |
| data_for_recursion.ancestor_clips_subtree = true; |
| data_for_recursion.nearest_occlusion_immune_ancestor_surface = NULL; |
| data_for_recursion.in_subtree_of_page_scale_application_layer = false; |
| @@ -2213,6 +2299,8 @@ void LayerTreeHostCommon::CalculateDrawProperties( |
| data_for_recursion.clip_rect_in_target_space = device_viewport_rect; |
| data_for_recursion.clip_rect_of_target_surface_in_target_space = |
| device_viewport_rect; |
| + data_for_recursion.maximum_animation_scale_factor = 1.f; |
| + data_for_recursion.ancestor_is_animating_scale = false; |
| data_for_recursion.ancestor_clips_subtree = true; |
| data_for_recursion.nearest_occlusion_immune_ancestor_surface = NULL; |
| data_for_recursion.in_subtree_of_page_scale_application_layer = false; |