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

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: Rebased 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
« no previous file with comments | « cc/test/tiled_layer_test_common.cc ('k') | cc/trees/layer_tree_host_common_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 885 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 } 896 }
897 next_scroll_compensation_matrix = 897 next_scroll_compensation_matrix =
898 inverse_surface_draw_transform * next_scroll_compensation_matrix * 898 inverse_surface_draw_transform * next_scroll_compensation_matrix *
899 layer->render_surface()->draw_transform(); 899 layer->render_surface()->draw_transform();
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(
907 float contents_scale, 907 LayerType* layer,
908 float device_scale_factor, 908 float contents_scale,
909 float page_scale_factor, 909 float device_scale_factor,
910 bool animating_transform_to_screen) { 910 float page_scale_factor,
911 float maximum_animation_contents_scale,
912 bool animating_transform_to_screen) {
911 layer->CalculateContentsScale(contents_scale, 913 layer->CalculateContentsScale(contents_scale,
912 device_scale_factor, 914 device_scale_factor,
913 page_scale_factor, 915 page_scale_factor,
916 maximum_animation_contents_scale,
914 animating_transform_to_screen, 917 animating_transform_to_screen,
915 &layer->draw_properties().contents_scale_x, 918 &layer->draw_properties().contents_scale_x,
916 &layer->draw_properties().contents_scale_y, 919 &layer->draw_properties().contents_scale_y,
917 &layer->draw_properties().content_bounds); 920 &layer->draw_properties().content_bounds);
918 921
919 LayerType* mask_layer = layer->mask_layer(); 922 LayerType* mask_layer = layer->mask_layer();
920 if (mask_layer) { 923 if (mask_layer) {
921 mask_layer->CalculateContentsScale( 924 mask_layer->CalculateContentsScale(
922 contents_scale, 925 contents_scale,
923 device_scale_factor, 926 device_scale_factor,
924 page_scale_factor, 927 page_scale_factor,
928 maximum_animation_contents_scale,
925 animating_transform_to_screen, 929 animating_transform_to_screen,
926 &mask_layer->draw_properties().contents_scale_x, 930 &mask_layer->draw_properties().contents_scale_x,
927 &mask_layer->draw_properties().contents_scale_y, 931 &mask_layer->draw_properties().contents_scale_y,
928 &mask_layer->draw_properties().content_bounds); 932 &mask_layer->draw_properties().content_bounds);
929 } 933 }
930 934
931 LayerType* replica_mask_layer = 935 LayerType* replica_mask_layer =
932 layer->replica_layer() ? layer->replica_layer()->mask_layer() : NULL; 936 layer->replica_layer() ? layer->replica_layer()->mask_layer() : NULL;
933 if (replica_mask_layer) { 937 if (replica_mask_layer) {
934 replica_mask_layer->CalculateContentsScale( 938 replica_mask_layer->CalculateContentsScale(
935 contents_scale, 939 contents_scale,
936 device_scale_factor, 940 device_scale_factor,
937 page_scale_factor, 941 page_scale_factor,
942 maximum_animation_contents_scale,
938 animating_transform_to_screen, 943 animating_transform_to_screen,
939 &replica_mask_layer->draw_properties().contents_scale_x, 944 &replica_mask_layer->draw_properties().contents_scale_x,
940 &replica_mask_layer->draw_properties().contents_scale_y, 945 &replica_mask_layer->draw_properties().contents_scale_y,
941 &replica_mask_layer->draw_properties().content_bounds); 946 &replica_mask_layer->draw_properties().content_bounds);
942 } 947 }
943 } 948 }
944 949
945 static inline void UpdateLayerContentsScale( 950 static inline void UpdateLayerContentsScale(
946 LayerImpl* layer, 951 LayerImpl* layer,
947 bool can_adjust_raster_scale, 952 bool can_adjust_raster_scale,
948 float ideal_contents_scale, 953 float ideal_contents_scale,
949 float device_scale_factor, 954 float device_scale_factor,
950 float page_scale_factor, 955 float page_scale_factor,
956 float maximum_animation_contents_scale,
951 bool animating_transform_to_screen) { 957 bool animating_transform_to_screen) {
952 CalculateContentsScale(layer, 958 CalculateContentsScale(layer,
953 ideal_contents_scale, 959 ideal_contents_scale,
954 device_scale_factor, 960 device_scale_factor,
955 page_scale_factor, 961 page_scale_factor,
962 maximum_animation_contents_scale,
956 animating_transform_to_screen); 963 animating_transform_to_screen);
957 } 964 }
958 965
959 static inline void UpdateLayerContentsScale( 966 static inline void UpdateLayerContentsScale(
960 Layer* layer, 967 Layer* layer,
961 bool can_adjust_raster_scale, 968 bool can_adjust_raster_scale,
962 float ideal_contents_scale, 969 float ideal_contents_scale,
963 float device_scale_factor, 970 float device_scale_factor,
964 float page_scale_factor, 971 float page_scale_factor,
972 float maximum_animation_contents_scale,
965 bool animating_transform_to_screen) { 973 bool animating_transform_to_screen) {
966 if (can_adjust_raster_scale) { 974 if (can_adjust_raster_scale) {
967 float ideal_raster_scale = 975 float ideal_raster_scale =
968 ideal_contents_scale / (device_scale_factor * page_scale_factor); 976 ideal_contents_scale / (device_scale_factor * page_scale_factor);
969 977
970 bool need_to_set_raster_scale = layer->raster_scale_is_unknown(); 978 bool need_to_set_raster_scale = layer->raster_scale_is_unknown();
971 979
972 // If we've previously saved a raster_scale but the ideal changes, things 980 // If we've previously saved a raster_scale but the ideal changes, things
973 // are unpredictable and we should just use 1. 981 // are unpredictable and we should just use 1.
974 if (!need_to_set_raster_scale && layer->raster_scale() != 1.f && 982 if (!need_to_set_raster_scale && layer->raster_scale() != 1.f &&
(...skipping 16 matching lines...) Expand all
991 999
992 gfx::Size old_content_bounds = layer->content_bounds(); 1000 gfx::Size old_content_bounds = layer->content_bounds();
993 float old_contents_scale_x = layer->contents_scale_x(); 1001 float old_contents_scale_x = layer->contents_scale_x();
994 float old_contents_scale_y = layer->contents_scale_y(); 1002 float old_contents_scale_y = layer->contents_scale_y();
995 1003
996 float contents_scale = raster_scale * device_scale_factor * page_scale_factor; 1004 float contents_scale = raster_scale * device_scale_factor * page_scale_factor;
997 CalculateContentsScale(layer, 1005 CalculateContentsScale(layer,
998 contents_scale, 1006 contents_scale,
999 device_scale_factor, 1007 device_scale_factor,
1000 page_scale_factor, 1008 page_scale_factor,
1009 maximum_animation_contents_scale,
1001 animating_transform_to_screen); 1010 animating_transform_to_screen);
1002 1011
1003 if (layer->content_bounds() != old_content_bounds || 1012 if (layer->content_bounds() != old_content_bounds ||
1004 layer->contents_scale_x() != old_contents_scale_x || 1013 layer->contents_scale_x() != old_contents_scale_x ||
1005 layer->contents_scale_y() != old_contents_scale_y) 1014 layer->contents_scale_y() != old_contents_scale_y)
1006 layer->SetNeedsPushProperties(); 1015 layer->SetNeedsPushProperties();
1007 } 1016 }
1008 1017
1018 static inline void CalculateAnimationContentsScale(
1019 Layer* layer,
1020 bool ancestor_is_animating_scale,
1021 float ancestor_maximum_animation_contents_scale,
1022 const gfx::Transform& parent_transform,
1023 const gfx::Transform& combined_transform,
1024 bool* combined_is_animating_scale,
1025 float* combined_maximum_animation_contents_scale) {
1026 *combined_is_animating_scale = false;
1027 *combined_maximum_animation_contents_scale = 0.f;
1028 }
1029
1030 static inline void CalculateAnimationContentsScale(
1031 LayerImpl* layer,
1032 bool ancestor_is_animating_scale,
1033 float ancestor_maximum_animation_contents_scale,
1034 const gfx::Transform& ancestor_transform,
1035 const gfx::Transform& combined_transform,
1036 bool* combined_is_animating_scale,
1037 float* combined_maximum_animation_contents_scale) {
1038 if (ancestor_is_animating_scale &&
1039 ancestor_maximum_animation_contents_scale == 0.f) {
1040 // We've already failed to compute a maximum animated scale at an
1041 // ancestor, so we'll continue to fail.
1042 *combined_maximum_animation_contents_scale = 0.f;
1043 *combined_is_animating_scale = true;
1044 return;
1045 }
1046
1047 if (!combined_transform.IsScaleOrTranslation()) {
1048 // Computing maximum animated scale in the presence of
1049 // non-scale/translation transforms isn't supported.
1050 *combined_maximum_animation_contents_scale = 0.f;
1051 *combined_is_animating_scale = true;
1052 return;
1053 }
1054
1055 // We currently only support computing maximum scale for combinations of
1056 // scales and translations. We treat all non-translations as potentially
1057 // affecting scale. Animations that include non-translation/scale components
1058 // will cause the computation of MaximumScale below to fail.
1059 bool layer_is_animating_scale =
1060 !layer->layer_animation_controller()->HasOnlyTranslationTransforms();
1061
1062 if (!layer_is_animating_scale && !ancestor_is_animating_scale) {
1063 *combined_maximum_animation_contents_scale = 0.f;
1064 *combined_is_animating_scale = false;
1065 return;
1066 }
1067
1068 // We don't attempt to accumulate animation scale from multiple nodes,
1069 // because of the risk of significant overestimation. For example, one node
1070 // may be increasing scale from 1 to 10 at the same time as a descendant is
1071 // decreasing scale from 10 to 1. Naively combining these scales would produce
1072 // a scale of 100.
1073 if (layer_is_animating_scale && ancestor_is_animating_scale) {
1074 *combined_maximum_animation_contents_scale = 0.f;
1075 *combined_is_animating_scale = true;
1076 return;
1077 }
1078
1079 // At this point, we know either the layer or an ancestor, but not both,
1080 // is animating scale.
1081 *combined_is_animating_scale = true;
1082 if (!layer_is_animating_scale) {
1083 gfx::Vector2dF layer_transform_scales =
1084 MathUtil::ComputeTransform2dScaleComponents(layer->transform(), 0.f);
1085 *combined_maximum_animation_contents_scale =
1086 ancestor_maximum_animation_contents_scale *
1087 std::max(layer_transform_scales.x(), layer_transform_scales.y());
1088 return;
1089 }
1090
1091 float layer_maximum_animated_scale = 0.f;
1092 if (!layer->layer_animation_controller()->MaximumScale(
1093 &layer_maximum_animated_scale)) {
1094 *combined_maximum_animation_contents_scale = 0.f;
1095 return;
1096 }
1097 gfx::Vector2dF ancestor_transform_scales =
1098 MathUtil::ComputeTransform2dScaleComponents(ancestor_transform, 0.f);
1099 *combined_maximum_animation_contents_scale =
1100 layer_maximum_animated_scale *
1101 std::max(ancestor_transform_scales.x(), ancestor_transform_scales.y());
1102 }
1103
1009 static inline RenderSurface* CreateOrReuseRenderSurface(Layer* layer) { 1104 static inline RenderSurface* CreateOrReuseRenderSurface(Layer* layer) {
1010 // The render surface should always be new on the main thread, as the 1105 // The render surface should always be new on the main thread, as the
1011 // RenderSurfaceLayerList should be a new empty list when given to 1106 // RenderSurfaceLayerList should be a new empty list when given to
1012 // CalculateDrawProperties. 1107 // CalculateDrawProperties.
1013 DCHECK(!layer->render_surface()); 1108 DCHECK(!layer->render_surface());
1014 layer->CreateRenderSurface(); 1109 layer->CreateRenderSurface();
1015 return layer->render_surface(); 1110 return layer->render_surface();
1016 } 1111 }
1017 1112
1018 static inline RenderSurfaceImpl* CreateOrReuseRenderSurface(LayerImpl* layer) { 1113 static inline RenderSurfaceImpl* CreateOrReuseRenderSurface(LayerImpl* layer) {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 // When the layer's children want to compute their visible content rect, they 1253 // 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 1254 // 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 1255 // 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 1256 // 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 1257 // 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 1258 // 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 1259 // while dealing with the parent layer, and then this precomputed value is
1165 // passed down the recursion to the children that actually use it. 1260 // passed down the recursion to the children that actually use it.
1166 gfx::Rect clip_rect_of_target_surface_in_target_space; 1261 gfx::Rect clip_rect_of_target_surface_in_target_space;
1167 1262
1263 // The maximum amount by which this layer will be scaled during the lifetime
1264 // of currently running animations.
1265 float maximum_animation_contents_scale;
1266
1267 bool ancestor_is_animating_scale;
1168 bool ancestor_clips_subtree; 1268 bool ancestor_clips_subtree;
1169 typename LayerType::RenderSurfaceType* 1269 typename LayerType::RenderSurfaceType*
1170 nearest_occlusion_immune_ancestor_surface; 1270 nearest_occlusion_immune_ancestor_surface;
1171 bool in_subtree_of_page_scale_application_layer; 1271 bool in_subtree_of_page_scale_application_layer;
1172 bool subtree_can_use_lcd_text; 1272 bool subtree_can_use_lcd_text;
1173 bool subtree_is_visible_from_ancestor; 1273 bool subtree_is_visible_from_ancestor;
1174 }; 1274 };
1175 1275
1176 template <typename LayerType> 1276 template <typename LayerType>
1177 static LayerType* GetChildContainingLayer(const LayerType& parent, 1277 static LayerType* GetChildContainingLayer(const LayerType& parent,
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
1539 effective_scroll_delta -= 1639 effective_scroll_delta -=
1540 gfx::ScaleVector2d(current_translation - previous_translation, 1640 gfx::ScaleVector2d(current_translation - previous_translation,
1541 1.f / parent_scales.x(), 1641 1.f / parent_scales.x(),
1542 1.f / parent_scales.y()); 1642 1.f / parent_scales.y());
1543 } 1643 }
1544 1644
1545 // Apply adjustment from position constraints. 1645 // Apply adjustment from position constraints.
1546 ApplyPositionAdjustment(layer, data_from_ancestor.fixed_container, 1646 ApplyPositionAdjustment(layer, data_from_ancestor.fixed_container,
1547 data_from_ancestor.scroll_compensation_matrix, &combined_transform); 1647 data_from_ancestor.scroll_compensation_matrix, &combined_transform);
1548 1648
1649 bool combined_is_animating_scale = false;
1650 float combined_maximum_animation_contents_scale = 0.f;
1651 if (globals.can_adjust_raster_scales) {
1652 CalculateAnimationContentsScale(
1653 layer,
1654 data_from_ancestor.ancestor_is_animating_scale,
1655 data_from_ancestor.maximum_animation_contents_scale,
1656 data_from_ancestor.parent_matrix,
1657 combined_transform,
1658 &combined_is_animating_scale,
1659 &combined_maximum_animation_contents_scale);
1660 }
1661 data_for_children.ancestor_is_animating_scale = combined_is_animating_scale;
1662 data_for_children.maximum_animation_contents_scale =
1663 combined_maximum_animation_contents_scale;
1664
1549 // Compute the 2d scale components of the transform hierarchy up to the target 1665 // 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. 1666 // surface. From there, we can decide on a contents scale for the layer.
1551 float layer_scale_factors = globals.device_scale_factor; 1667 float layer_scale_factors = globals.device_scale_factor;
1552 if (data_from_ancestor.in_subtree_of_page_scale_application_layer) 1668 if (data_from_ancestor.in_subtree_of_page_scale_application_layer)
1553 layer_scale_factors *= globals.page_scale_factor; 1669 layer_scale_factors *= globals.page_scale_factor;
1554 gfx::Vector2dF combined_transform_scales = 1670 gfx::Vector2dF combined_transform_scales =
1555 MathUtil::ComputeTransform2dScaleComponents( 1671 MathUtil::ComputeTransform2dScaleComponents(
1556 combined_transform, 1672 combined_transform,
1557 layer_scale_factors); 1673 layer_scale_factors);
1558 1674
1559 float ideal_contents_scale = 1675 float ideal_contents_scale =
1560 globals.can_adjust_raster_scales 1676 globals.can_adjust_raster_scales
1561 ? std::max(combined_transform_scales.x(), 1677 ? std::max(combined_transform_scales.x(),
1562 combined_transform_scales.y()) 1678 combined_transform_scales.y())
1563 : layer_scale_factors; 1679 : layer_scale_factors;
1564 UpdateLayerContentsScale( 1680 UpdateLayerContentsScale(
1565 layer, 1681 layer,
1566 globals.can_adjust_raster_scales, 1682 globals.can_adjust_raster_scales,
1567 ideal_contents_scale, 1683 ideal_contents_scale,
1568 globals.device_scale_factor, 1684 globals.device_scale_factor,
1569 data_from_ancestor.in_subtree_of_page_scale_application_layer ? 1685 data_from_ancestor.in_subtree_of_page_scale_application_layer
1570 globals.page_scale_factor : 1.f, 1686 ? globals.page_scale_factor
1687 : 1.f,
1688 combined_maximum_animation_contents_scale,
1571 animating_transform_to_screen); 1689 animating_transform_to_screen);
1572 1690
1573 // The draw_transform that gets computed below is effectively the layer's 1691 // 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 1692 // draw_transform, unless the layer itself creates a render_surface. In that
1575 // case, the render_surface re-parents the transforms. 1693 // case, the render_surface re-parents the transforms.
1576 layer_draw_properties.target_space_transform = combined_transform; 1694 layer_draw_properties.target_space_transform = combined_transform;
1577 // M[draw] = M[parent] * LT * S[layer2content] 1695 // M[draw] = M[parent] * LT * S[layer2content]
1578 layer_draw_properties.target_space_transform.Scale( 1696 layer_draw_properties.target_space_transform.Scale(
1579 SK_MScalar1 / layer->contents_scale_x(), 1697 SK_MScalar1 / layer->contents_scale_x(),
1580 SK_MScalar1 / layer->contents_scale_y()); 1698 SK_MScalar1 / layer->contents_scale_y());
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
2160 inputs.can_render_to_separate_surface; 2278 inputs.can_render_to_separate_surface;
2161 globals->can_adjust_raster_scales = inputs.can_adjust_raster_scales; 2279 globals->can_adjust_raster_scales = inputs.can_adjust_raster_scales;
2162 2280
2163 data_for_recursion->parent_matrix = scaled_device_transform; 2281 data_for_recursion->parent_matrix = scaled_device_transform;
2164 data_for_recursion->full_hierarchy_matrix = identity_matrix; 2282 data_for_recursion->full_hierarchy_matrix = identity_matrix;
2165 data_for_recursion->scroll_compensation_matrix = identity_matrix; 2283 data_for_recursion->scroll_compensation_matrix = identity_matrix;
2166 data_for_recursion->fixed_container = inputs.root_layer; 2284 data_for_recursion->fixed_container = inputs.root_layer;
2167 data_for_recursion->clip_rect_in_target_space = device_viewport_rect; 2285 data_for_recursion->clip_rect_in_target_space = device_viewport_rect;
2168 data_for_recursion->clip_rect_of_target_surface_in_target_space = 2286 data_for_recursion->clip_rect_of_target_surface_in_target_space =
2169 device_viewport_rect; 2287 device_viewport_rect;
2288 data_for_recursion->maximum_animation_contents_scale = 0.f;
2289 data_for_recursion->ancestor_is_animating_scale = false;
2170 data_for_recursion->ancestor_clips_subtree = true; 2290 data_for_recursion->ancestor_clips_subtree = true;
2171 data_for_recursion->nearest_occlusion_immune_ancestor_surface = NULL; 2291 data_for_recursion->nearest_occlusion_immune_ancestor_surface = NULL;
2172 data_for_recursion->in_subtree_of_page_scale_application_layer = false; 2292 data_for_recursion->in_subtree_of_page_scale_application_layer = false;
2173 data_for_recursion->subtree_can_use_lcd_text = inputs.can_use_lcd_text; 2293 data_for_recursion->subtree_can_use_lcd_text = inputs.can_use_lcd_text;
2174 data_for_recursion->subtree_is_visible_from_ancestor = true; 2294 data_for_recursion->subtree_is_visible_from_ancestor = true;
2175 } 2295 }
2176 2296
2177 void LayerTreeHostCommon::CalculateDrawProperties( 2297 void LayerTreeHostCommon::CalculateDrawProperties(
2178 CalcDrawPropsMainInputs* inputs) { 2298 CalcDrawPropsMainInputs* inputs) {
2179 RenderSurfaceLayerList dummy_layer_list; 2299 RenderSurfaceLayerList dummy_layer_list;
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
2395 // At this point, we think the point does hit the touch event handler region 2515 // At this point, we think the point does hit the touch event handler region
2396 // on the layer, but we need to walk up the parents to ensure that the layer 2516 // on the layer, but we need to walk up the parents to ensure that the layer
2397 // was not clipped in such a way that the hit point actually should not hit 2517 // was not clipped in such a way that the hit point actually should not hit
2398 // the layer. 2518 // the layer.
2399 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl)) 2519 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl))
2400 return false; 2520 return false;
2401 2521
2402 return true; 2522 return true;
2403 } 2523 }
2404 } // namespace cc 2524 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/tiled_layer_test_common.cc ('k') | cc/trees/layer_tree_host_common_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698