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

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

Issue 226283004: Rasterize at maximum scale for scale animations on CPU-rasterized layers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
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 889 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 } 900 }
901 901
902 return next_scroll_compensation_matrix; 902 return next_scroll_compensation_matrix;
903 } 903 }
904 904
905 template <typename LayerType> 905 template <typename LayerType>
906 static inline void CalculateContentsScale(LayerType* layer, 906 static inline void CalculateContentsScale(LayerType* layer,
907 float contents_scale, 907 float contents_scale,
908 float device_scale_factor, 908 float device_scale_factor,
909 float page_scale_factor, 909 float page_scale_factor,
910 float maximum_animation_scale_factor,
910 bool animating_transform_to_screen) { 911 bool animating_transform_to_screen) {
911 layer->CalculateContentsScale(contents_scale, 912 layer->CalculateContentsScale(contents_scale,
912 device_scale_factor, 913 device_scale_factor,
913 page_scale_factor, 914 page_scale_factor,
915 maximum_animation_scale_factor,
914 animating_transform_to_screen, 916 animating_transform_to_screen,
915 &layer->draw_properties().contents_scale_x, 917 &layer->draw_properties().contents_scale_x,
916 &layer->draw_properties().contents_scale_y, 918 &layer->draw_properties().contents_scale_y,
917 &layer->draw_properties().content_bounds); 919 &layer->draw_properties().content_bounds);
918 920
919 LayerType* mask_layer = layer->mask_layer(); 921 LayerType* mask_layer = layer->mask_layer();
920 if (mask_layer) { 922 if (mask_layer) {
921 mask_layer->CalculateContentsScale( 923 mask_layer->CalculateContentsScale(
922 contents_scale, 924 contents_scale,
923 device_scale_factor, 925 device_scale_factor,
924 page_scale_factor, 926 page_scale_factor,
927 maximum_animation_scale_factor,
925 animating_transform_to_screen, 928 animating_transform_to_screen,
926 &mask_layer->draw_properties().contents_scale_x, 929 &mask_layer->draw_properties().contents_scale_x,
927 &mask_layer->draw_properties().contents_scale_y, 930 &mask_layer->draw_properties().contents_scale_y,
928 &mask_layer->draw_properties().content_bounds); 931 &mask_layer->draw_properties().content_bounds);
929 } 932 }
930 933
931 LayerType* replica_mask_layer = 934 LayerType* replica_mask_layer =
932 layer->replica_layer() ? layer->replica_layer()->mask_layer() : NULL; 935 layer->replica_layer() ? layer->replica_layer()->mask_layer() : NULL;
933 if (replica_mask_layer) { 936 if (replica_mask_layer) {
934 replica_mask_layer->CalculateContentsScale( 937 replica_mask_layer->CalculateContentsScale(
935 contents_scale, 938 contents_scale,
936 device_scale_factor, 939 device_scale_factor,
937 page_scale_factor, 940 page_scale_factor,
941 maximum_animation_scale_factor,
938 animating_transform_to_screen, 942 animating_transform_to_screen,
939 &replica_mask_layer->draw_properties().contents_scale_x, 943 &replica_mask_layer->draw_properties().contents_scale_x,
940 &replica_mask_layer->draw_properties().contents_scale_y, 944 &replica_mask_layer->draw_properties().contents_scale_y,
941 &replica_mask_layer->draw_properties().content_bounds); 945 &replica_mask_layer->draw_properties().content_bounds);
942 } 946 }
943 } 947 }
944 948
945 static inline void UpdateLayerContentsScale( 949 static inline void UpdateLayerContentsScale(
946 LayerImpl* layer, 950 LayerImpl* layer,
947 bool can_adjust_raster_scale, 951 bool can_adjust_raster_scale,
948 float ideal_contents_scale, 952 float ideal_contents_scale,
949 float device_scale_factor, 953 float device_scale_factor,
950 float page_scale_factor, 954 float page_scale_factor,
955 float maximum_animation_scale_factor,
951 bool animating_transform_to_screen) { 956 bool animating_transform_to_screen) {
952 CalculateContentsScale(layer, 957 CalculateContentsScale(layer,
953 ideal_contents_scale, 958 ideal_contents_scale,
954 device_scale_factor, 959 device_scale_factor,
955 page_scale_factor, 960 page_scale_factor,
961 maximum_animation_scale_factor,
956 animating_transform_to_screen); 962 animating_transform_to_screen);
957 } 963 }
958 964
959 static inline void UpdateLayerContentsScale( 965 static inline void UpdateLayerContentsScale(
960 Layer* layer, 966 Layer* layer,
961 bool can_adjust_raster_scale, 967 bool can_adjust_raster_scale,
962 float ideal_contents_scale, 968 float ideal_contents_scale,
963 float device_scale_factor, 969 float device_scale_factor,
964 float page_scale_factor, 970 float page_scale_factor,
971 float maximum_animation_scale_factor,
965 bool animating_transform_to_screen) { 972 bool animating_transform_to_screen) {
966 if (can_adjust_raster_scale) { 973 if (can_adjust_raster_scale) {
967 float ideal_raster_scale = 974 float ideal_raster_scale =
968 ideal_contents_scale / (device_scale_factor * page_scale_factor); 975 ideal_contents_scale / (device_scale_factor * page_scale_factor);
969 976
970 bool need_to_set_raster_scale = layer->raster_scale_is_unknown(); 977 bool need_to_set_raster_scale = layer->raster_scale_is_unknown();
971 978
972 // If we've previously saved a raster_scale but the ideal changes, things 979 // If we've previously saved a raster_scale but the ideal changes, things
973 // are unpredictable and we should just use 1. 980 // are unpredictable and we should just use 1.
974 if (!need_to_set_raster_scale && layer->raster_scale() != 1.f && 981 if (!need_to_set_raster_scale && layer->raster_scale() != 1.f &&
(...skipping 16 matching lines...) Expand all
991 998
992 gfx::Size old_content_bounds = layer->content_bounds(); 999 gfx::Size old_content_bounds = layer->content_bounds();
993 float old_contents_scale_x = layer->contents_scale_x(); 1000 float old_contents_scale_x = layer->contents_scale_x();
994 float old_contents_scale_y = layer->contents_scale_y(); 1001 float old_contents_scale_y = layer->contents_scale_y();
995 1002
996 float contents_scale = raster_scale * device_scale_factor * page_scale_factor; 1003 float contents_scale = raster_scale * device_scale_factor * page_scale_factor;
997 CalculateContentsScale(layer, 1004 CalculateContentsScale(layer,
998 contents_scale, 1005 contents_scale,
999 device_scale_factor, 1006 device_scale_factor,
1000 page_scale_factor, 1007 page_scale_factor,
1008 maximum_animation_scale_factor,
1001 animating_transform_to_screen); 1009 animating_transform_to_screen);
1002 1010
1003 if (layer->content_bounds() != old_content_bounds || 1011 if (layer->content_bounds() != old_content_bounds ||
1004 layer->contents_scale_x() != old_contents_scale_x || 1012 layer->contents_scale_x() != old_contents_scale_x ||
1005 layer->contents_scale_y() != old_contents_scale_y) 1013 layer->contents_scale_y() != old_contents_scale_y)
1006 layer->SetNeedsPushProperties(); 1014 layer->SetNeedsPushProperties();
1007 } 1015 }
1008 1016
1009 static inline RenderSurface* CreateOrReuseRenderSurface(Layer* layer) { 1017 static inline RenderSurface* CreateOrReuseRenderSurface(Layer* layer) {
1010 // The render surface should always be new on the main thread, as the 1018 // The render surface should always be new on the main thread, as the
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 // When the layer's children want to compute their visible content rect, they 1166 // When the layer's children want to compute their visible content rect, they
1159 // want to know what their target surface's clip rect will be. BUT - they 1167 // want to know what their target surface's clip rect will be. BUT - they
1160 // want to know this clip rect represented in their own target space. This 1168 // want to know this clip rect represented in their own target space. This
1161 // requires inverse-projecting the surface's clip rect from the surface's 1169 // requires inverse-projecting the surface's clip rect from the surface's
1162 // render target space down to the surface's own space. Instead of computing 1170 // render target space down to the surface's own space. Instead of computing
1163 // this value redundantly for each child layer, it is computed only once 1171 // this value redundantly for each child layer, it is computed only once
1164 // while dealing with the parent layer, and then this precomputed value is 1172 // while dealing with the parent layer, and then this precomputed value is
1165 // passed down the recursion to the children that actually use it. 1173 // passed down the recursion to the children that actually use it.
1166 gfx::Rect clip_rect_of_target_surface_in_target_space; 1174 gfx::Rect clip_rect_of_target_surface_in_target_space;
1167 1175
1176 // The maximum factor by which currently running animations will be
1177 // scaling-up the layer during their lifetime.
1178 float maximum_animation_scale_factor;
1179
1180 bool ancestor_is_animating_scale;
1168 bool ancestor_clips_subtree; 1181 bool ancestor_clips_subtree;
1169 typename LayerType::RenderSurfaceType* 1182 typename LayerType::RenderSurfaceType*
1170 nearest_occlusion_immune_ancestor_surface; 1183 nearest_occlusion_immune_ancestor_surface;
1171 bool in_subtree_of_page_scale_application_layer; 1184 bool in_subtree_of_page_scale_application_layer;
1172 bool subtree_can_use_lcd_text; 1185 bool subtree_can_use_lcd_text;
1173 bool subtree_is_visible_from_ancestor; 1186 bool subtree_is_visible_from_ancestor;
1174 }; 1187 };
1175 1188
1176 template <typename LayerType> 1189 template <typename LayerType>
1177 static LayerType* GetChildContainingLayer(const LayerType& parent, 1190 static LayerType* GetChildContainingLayer(const LayerType& parent,
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
1539 effective_scroll_delta -= 1552 effective_scroll_delta -=
1540 gfx::ScaleVector2d(current_translation - previous_translation, 1553 gfx::ScaleVector2d(current_translation - previous_translation,
1541 1.f / parent_scales.x(), 1554 1.f / parent_scales.x(),
1542 1.f / parent_scales.y()); 1555 1.f / parent_scales.y());
1543 } 1556 }
1544 1557
1545 // Apply adjustment from position constraints. 1558 // Apply adjustment from position constraints.
1546 ApplyPositionAdjustment(layer, data_from_ancestor.fixed_container, 1559 ApplyPositionAdjustment(layer, data_from_ancestor.fixed_container,
1547 data_from_ancestor.scroll_compensation_matrix, &combined_transform); 1560 data_from_ancestor.scroll_compensation_matrix, &combined_transform);
1548 1561
1562 bool layer_is_animating_scale =
1563 !layer->layer_animation_controller()->HasOnlyTranslationTransforms();
1564 data_for_children.ancestor_is_animating_scale =
1565 layer_is_animating_scale ||
1566 data_from_ancestor.ancestor_is_animating_scale;
1567 float layer_maximum_animated_scale = 0.f;
1568 float layer_animation_scale_factor = 1.f;
1569 if (!globals.can_adjust_raster_scales ||
Ian Vollick 2014/04/05 02:24:33 Can we avoid the HasOnlyTranslationTransforms work
ajuma 2014/04/07 15:27:00 Done.
1570 !combined_transform.IsScaleOrTranslation()) {
1571 layer_animation_scale_factor = 0.f;
1572 } else if (layer_is_animating_scale) {
1573 if (data_from_ancestor.ancestor_is_animating_scale ||
Ian Vollick 2014/04/05 02:24:33 Might be worth mentioning why aren't we supporting
ajuma 2014/04/07 15:27:00 Done.
1574 !layer->layer_animation_controller()->MaximumScale(
1575 &layer_maximum_animated_scale)) {
1576 layer_animation_scale_factor = 0.f;
1577 } else {
1578 gfx::Vector2dF layer_transform_scales =
1579 MathUtil::ComputeTransform2dScaleComponents(layer->transform(), 0.f);
1580 DCHECK(layer_transform_scales != gfx::Vector2dF());
1581 layer_animation_scale_factor =
Ian Vollick 2014/04/05 02:24:33 This could really use a comment. It took me a whil
ajuma 2014/04/07 15:27:00 Done.
1582 layer_maximum_animated_scale /
1583 std::max(layer_transform_scales.x(), layer_transform_scales.y());
1584 }
1585 }
1586 float combined_maximum_animation_scale_factor =
1587 layer_animation_scale_factor *
1588 data_from_ancestor.maximum_animation_scale_factor;
Ian Vollick 2014/04/05 02:24:33 If I'm following along correctly, the point of thi
ajuma 2014/04/07 15:27:00 Removed the multiplication.
1589 data_for_children.maximum_animation_scale_factor =
1590 combined_maximum_animation_scale_factor;
1591
1549 // Compute the 2d scale components of the transform hierarchy up to the target 1592 // Compute the 2d scale components of the transform hierarchy up to the target
1550 // surface. From there, we can decide on a contents scale for the layer. 1593 // surface. From there, we can decide on a contents scale for the layer.
1551 float layer_scale_factors = globals.device_scale_factor; 1594 float layer_scale_factors = globals.device_scale_factor;
1552 if (data_from_ancestor.in_subtree_of_page_scale_application_layer) 1595 if (data_from_ancestor.in_subtree_of_page_scale_application_layer)
1553 layer_scale_factors *= globals.page_scale_factor; 1596 layer_scale_factors *= globals.page_scale_factor;
1554 gfx::Vector2dF combined_transform_scales = 1597 gfx::Vector2dF combined_transform_scales =
1555 MathUtil::ComputeTransform2dScaleComponents( 1598 MathUtil::ComputeTransform2dScaleComponents(
1556 combined_transform, 1599 combined_transform,
1557 layer_scale_factors); 1600 layer_scale_factors);
1558 1601
1559 float ideal_contents_scale = 1602 float ideal_contents_scale =
1560 globals.can_adjust_raster_scales 1603 globals.can_adjust_raster_scales
1561 ? std::max(combined_transform_scales.x(), 1604 ? std::max(combined_transform_scales.x(),
1562 combined_transform_scales.y()) 1605 combined_transform_scales.y())
1563 : layer_scale_factors; 1606 : layer_scale_factors;
1564 UpdateLayerContentsScale( 1607 UpdateLayerContentsScale(
1565 layer, 1608 layer,
1566 globals.can_adjust_raster_scales, 1609 globals.can_adjust_raster_scales,
1567 ideal_contents_scale, 1610 ideal_contents_scale,
1568 globals.device_scale_factor, 1611 globals.device_scale_factor,
1569 data_from_ancestor.in_subtree_of_page_scale_application_layer ? 1612 data_from_ancestor.in_subtree_of_page_scale_application_layer
1570 globals.page_scale_factor : 1.f, 1613 ? globals.page_scale_factor
1614 : 1.f,
1615 combined_maximum_animation_scale_factor,
1571 animating_transform_to_screen); 1616 animating_transform_to_screen);
1572 1617
1573 // The draw_transform that gets computed below is effectively the layer's 1618 // The draw_transform that gets computed below is effectively the layer's
1574 // draw_transform, unless the layer itself creates a render_surface. In that 1619 // draw_transform, unless the layer itself creates a render_surface. In that
1575 // case, the render_surface re-parents the transforms. 1620 // case, the render_surface re-parents the transforms.
1576 layer_draw_properties.target_space_transform = combined_transform; 1621 layer_draw_properties.target_space_transform = combined_transform;
1577 // M[draw] = M[parent] * LT * S[layer2content] 1622 // M[draw] = M[parent] * LT * S[layer2content]
1578 layer_draw_properties.target_space_transform.Scale( 1623 layer_draw_properties.target_space_transform.Scale(
1579 SK_MScalar1 / layer->contents_scale_x(), 1624 SK_MScalar1 / layer->contents_scale_x(),
1580 SK_MScalar1 / layer->contents_scale_y()); 1625 SK_MScalar1 / layer->contents_scale_y());
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
2148 globals.can_adjust_raster_scales = inputs->can_adjust_raster_scales; 2193 globals.can_adjust_raster_scales = inputs->can_adjust_raster_scales;
2149 2194
2150 DataForRecursion<Layer> data_for_recursion; 2195 DataForRecursion<Layer> data_for_recursion;
2151 data_for_recursion.parent_matrix = scaled_device_transform; 2196 data_for_recursion.parent_matrix = scaled_device_transform;
2152 data_for_recursion.full_hierarchy_matrix = identity_matrix; 2197 data_for_recursion.full_hierarchy_matrix = identity_matrix;
2153 data_for_recursion.scroll_compensation_matrix = identity_matrix; 2198 data_for_recursion.scroll_compensation_matrix = identity_matrix;
2154 data_for_recursion.fixed_container = inputs->root_layer; 2199 data_for_recursion.fixed_container = inputs->root_layer;
2155 data_for_recursion.clip_rect_in_target_space = device_viewport_rect; 2200 data_for_recursion.clip_rect_in_target_space = device_viewport_rect;
2156 data_for_recursion.clip_rect_of_target_surface_in_target_space = 2201 data_for_recursion.clip_rect_of_target_surface_in_target_space =
2157 device_viewport_rect; 2202 device_viewport_rect;
2203 data_for_recursion.maximum_animation_scale_factor = 1.f;
2204 data_for_recursion.ancestor_is_animating_scale = false;
2158 data_for_recursion.ancestor_clips_subtree = true; 2205 data_for_recursion.ancestor_clips_subtree = true;
2159 data_for_recursion.nearest_occlusion_immune_ancestor_surface = NULL; 2206 data_for_recursion.nearest_occlusion_immune_ancestor_surface = NULL;
2160 data_for_recursion.in_subtree_of_page_scale_application_layer = false; 2207 data_for_recursion.in_subtree_of_page_scale_application_layer = false;
2161 data_for_recursion.subtree_can_use_lcd_text = inputs->can_use_lcd_text; 2208 data_for_recursion.subtree_can_use_lcd_text = inputs->can_use_lcd_text;
2162 data_for_recursion.subtree_is_visible_from_ancestor = true; 2209 data_for_recursion.subtree_is_visible_from_ancestor = true;
2163 2210
2164 PreCalculateMetaInformationRecursiveData recursive_data; 2211 PreCalculateMetaInformationRecursiveData recursive_data;
2165 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); 2212 PreCalculateMetaInformation(inputs->root_layer, &recursive_data);
2166 std::vector<AccumulatedSurfaceState<Layer> > accumulated_surface_state; 2213 std::vector<AccumulatedSurfaceState<Layer> > accumulated_surface_state;
2167 CalculateDrawPropertiesInternal<Layer>(inputs->root_layer, 2214 CalculateDrawPropertiesInternal<Layer>(inputs->root_layer,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2206 globals.can_adjust_raster_scales = inputs->can_adjust_raster_scales; 2253 globals.can_adjust_raster_scales = inputs->can_adjust_raster_scales;
2207 2254
2208 DataForRecursion<LayerImpl> data_for_recursion; 2255 DataForRecursion<LayerImpl> data_for_recursion;
2209 data_for_recursion.parent_matrix = scaled_device_transform; 2256 data_for_recursion.parent_matrix = scaled_device_transform;
2210 data_for_recursion.full_hierarchy_matrix = identity_matrix; 2257 data_for_recursion.full_hierarchy_matrix = identity_matrix;
2211 data_for_recursion.scroll_compensation_matrix = identity_matrix; 2258 data_for_recursion.scroll_compensation_matrix = identity_matrix;
2212 data_for_recursion.fixed_container = inputs->root_layer; 2259 data_for_recursion.fixed_container = inputs->root_layer;
2213 data_for_recursion.clip_rect_in_target_space = device_viewport_rect; 2260 data_for_recursion.clip_rect_in_target_space = device_viewport_rect;
2214 data_for_recursion.clip_rect_of_target_surface_in_target_space = 2261 data_for_recursion.clip_rect_of_target_surface_in_target_space =
2215 device_viewport_rect; 2262 device_viewport_rect;
2263 data_for_recursion.maximum_animation_scale_factor = 1.f;
2264 data_for_recursion.ancestor_is_animating_scale = false;
2216 data_for_recursion.ancestor_clips_subtree = true; 2265 data_for_recursion.ancestor_clips_subtree = true;
2217 data_for_recursion.nearest_occlusion_immune_ancestor_surface = NULL; 2266 data_for_recursion.nearest_occlusion_immune_ancestor_surface = NULL;
2218 data_for_recursion.in_subtree_of_page_scale_application_layer = false; 2267 data_for_recursion.in_subtree_of_page_scale_application_layer = false;
2219 data_for_recursion.subtree_can_use_lcd_text = inputs->can_use_lcd_text; 2268 data_for_recursion.subtree_can_use_lcd_text = inputs->can_use_lcd_text;
2220 data_for_recursion.subtree_is_visible_from_ancestor = true; 2269 data_for_recursion.subtree_is_visible_from_ancestor = true;
2221 2270
2222 PreCalculateMetaInformationRecursiveData recursive_data; 2271 PreCalculateMetaInformationRecursiveData recursive_data;
2223 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); 2272 PreCalculateMetaInformation(inputs->root_layer, &recursive_data);
2224 std::vector<AccumulatedSurfaceState<LayerImpl> > 2273 std::vector<AccumulatedSurfaceState<LayerImpl> >
2225 accumulated_surface_state; 2274 accumulated_surface_state;
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
2406 // At this point, we think the point does hit the touch event handler region 2455 // At this point, we think the point does hit the touch event handler region
2407 // on the layer, but we need to walk up the parents to ensure that the layer 2456 // on the layer, but we need to walk up the parents to ensure that the layer
2408 // was not clipped in such a way that the hit point actually should not hit 2457 // was not clipped in such a way that the hit point actually should not hit
2409 // the layer. 2458 // the layer.
2410 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl)) 2459 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl))
2411 return false; 2460 return false;
2412 2461
2413 return true; 2462 return true;
2414 } 2463 }
2415 } // namespace cc 2464 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698