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

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

Issue 1076313006: Animation start scale should be considered for the raster scale (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing and Added more tests Created 5 years, 7 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
« no previous file with comments | « cc/test/animation_test_common.cc ('k') | ui/compositor/transform_animation_curve_adapter.h » ('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/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 #include "cc/base/math_util.h" 10 #include "cc/base/math_util.h"
(...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 } 906 }
907 907
908 return next_scroll_compensation_matrix; 908 return next_scroll_compensation_matrix;
909 } 909 }
910 910
911 template <typename LayerType> 911 template <typename LayerType>
912 static inline void UpdateLayerScaleDrawProperties( 912 static inline void UpdateLayerScaleDrawProperties(
913 LayerType* layer, 913 LayerType* layer,
914 float ideal_contents_scale, 914 float ideal_contents_scale,
915 float maximum_animation_contents_scale, 915 float maximum_animation_contents_scale,
916 float starting_animation_contents_scale,
916 float page_scale_factor, 917 float page_scale_factor,
917 float device_scale_factor) { 918 float device_scale_factor) {
918 layer->draw_properties().ideal_contents_scale = ideal_contents_scale; 919 layer->draw_properties().ideal_contents_scale = ideal_contents_scale;
919 layer->draw_properties().maximum_animation_contents_scale = 920 layer->draw_properties().maximum_animation_contents_scale =
920 maximum_animation_contents_scale; 921 maximum_animation_contents_scale;
922 layer->draw_properties().starting_animation_contents_scale =
923 starting_animation_contents_scale;
921 layer->draw_properties().page_scale_factor = page_scale_factor; 924 layer->draw_properties().page_scale_factor = page_scale_factor;
922 layer->draw_properties().device_scale_factor = device_scale_factor; 925 layer->draw_properties().device_scale_factor = device_scale_factor;
923 } 926 }
924 927
925 static inline void CalculateContentsScale(LayerImpl* layer, 928 static inline void CalculateContentsScale(LayerImpl* layer,
926 float contents_scale) { 929 float contents_scale) {
927 // LayerImpl has all of its content scales and bounds pushed from the Main 930 // LayerImpl has all of its content scales and bounds pushed from the Main
928 // thread during commit and just uses those values as-is. 931 // thread during commit and just uses those values as-is.
929 } 932 }
930 933
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 layer->SetNeedsPushProperties(); 1013 layer->SetNeedsPushProperties();
1011 } 1014 }
1012 1015
1013 static inline void CalculateAnimationContentsScale( 1016 static inline void CalculateAnimationContentsScale(
1014 Layer* layer, 1017 Layer* layer,
1015 bool ancestor_is_animating_scale, 1018 bool ancestor_is_animating_scale,
1016 float ancestor_maximum_animation_contents_scale, 1019 float ancestor_maximum_animation_contents_scale,
1017 const gfx::Transform& parent_transform, 1020 const gfx::Transform& parent_transform,
1018 const gfx::Transform& combined_transform, 1021 const gfx::Transform& combined_transform,
1019 bool* combined_is_animating_scale, 1022 bool* combined_is_animating_scale,
1020 float* combined_maximum_animation_contents_scale) { 1023 float* combined_maximum_animation_contents_scale,
1024 float* combined_starting_animation_contents_scale) {
1021 *combined_is_animating_scale = false; 1025 *combined_is_animating_scale = false;
1022 *combined_maximum_animation_contents_scale = 0.f; 1026 *combined_maximum_animation_contents_scale = 0.f;
1027 *combined_starting_animation_contents_scale = 0.f;
1023 } 1028 }
1024 1029
1025 static inline void CalculateAnimationContentsScale( 1030 static inline void CalculateAnimationContentsScale(
1026 LayerImpl* layer, 1031 LayerImpl* layer,
1027 bool ancestor_is_animating_scale, 1032 bool ancestor_is_animating_scale,
1028 float ancestor_maximum_animation_contents_scale, 1033 float ancestor_maximum_animation_contents_scale,
1029 const gfx::Transform& ancestor_transform, 1034 const gfx::Transform& ancestor_transform,
1030 const gfx::Transform& combined_transform, 1035 const gfx::Transform& combined_transform,
1031 bool* combined_is_animating_scale, 1036 bool* combined_is_animating_scale,
1032 float* combined_maximum_animation_contents_scale) { 1037 float* combined_maximum_animation_contents_scale,
1038 float* combined_starting_animation_contents_scale) {
1033 if (ancestor_is_animating_scale && 1039 if (ancestor_is_animating_scale &&
1034 ancestor_maximum_animation_contents_scale == 0.f) { 1040 ancestor_maximum_animation_contents_scale == 0.f) {
1035 // We've already failed to compute a maximum animated scale at an 1041 // We've already failed to compute a maximum animated scale at an
1036 // ancestor, so we'll continue to fail. 1042 // ancestor, so we'll continue to fail.
1037 *combined_maximum_animation_contents_scale = 0.f; 1043 *combined_maximum_animation_contents_scale = 0.f;
1044 *combined_starting_animation_contents_scale = 0.f;
1038 *combined_is_animating_scale = true; 1045 *combined_is_animating_scale = true;
1039 return; 1046 return;
1040 } 1047 }
1041 1048
1042 if (!combined_transform.IsScaleOrTranslation()) { 1049 if (!combined_transform.IsScaleOrTranslation()) {
1043 // Computing maximum animated scale in the presence of 1050 // Computing maximum animated scale in the presence of
1044 // non-scale/translation transforms isn't supported. 1051 // non-scale/translation transforms isn't supported.
1045 *combined_maximum_animation_contents_scale = 0.f; 1052 *combined_maximum_animation_contents_scale = 0.f;
1053 *combined_starting_animation_contents_scale = 0.f;
1046 *combined_is_animating_scale = true; 1054 *combined_is_animating_scale = true;
1047 return; 1055 return;
1048 } 1056 }
1049 1057
1050 // We currently only support computing maximum scale for combinations of 1058 // We currently only support computing maximum scale for combinations of
1051 // scales and translations. We treat all non-translations as potentially 1059 // scales and translations. We treat all non-translations as potentially
1052 // affecting scale. Animations that include non-translation/scale components 1060 // affecting scale. Animations that include non-translation/scale components
1053 // will cause the computation of MaximumScale below to fail. 1061 // will cause the computation of MaximumScale below to fail.
1054 bool layer_is_animating_scale = 1062 bool layer_is_animating_scale =
1055 !layer->layer_animation_controller()->HasOnlyTranslationTransforms(); 1063 !layer->layer_animation_controller()->HasOnlyTranslationTransforms();
1056 1064
1057 if (!layer_is_animating_scale && !ancestor_is_animating_scale) { 1065 if (!layer_is_animating_scale && !ancestor_is_animating_scale) {
1058 *combined_maximum_animation_contents_scale = 0.f; 1066 *combined_maximum_animation_contents_scale = 0.f;
1067 *combined_starting_animation_contents_scale = 0.f;
1059 *combined_is_animating_scale = false; 1068 *combined_is_animating_scale = false;
1060 return; 1069 return;
1061 } 1070 }
1062 1071
1063 // We don't attempt to accumulate animation scale from multiple nodes, 1072 // We don't attempt to accumulate animation scale from multiple nodes,
1064 // because of the risk of significant overestimation. For example, one node 1073 // because of the risk of significant overestimation. For example, one node
1065 // may be increasing scale from 1 to 10 at the same time as a descendant is 1074 // may be increasing scale from 1 to 10 at the same time as a descendant is
1066 // decreasing scale from 10 to 1. Naively combining these scales would produce 1075 // decreasing scale from 10 to 1. Naively combining these scales would produce
1067 // a scale of 100. 1076 // a scale of 100.
1068 if (layer_is_animating_scale && ancestor_is_animating_scale) { 1077 if (layer_is_animating_scale && ancestor_is_animating_scale) {
1069 *combined_maximum_animation_contents_scale = 0.f; 1078 *combined_maximum_animation_contents_scale = 0.f;
1079 *combined_starting_animation_contents_scale = 0.f;
1070 *combined_is_animating_scale = true; 1080 *combined_is_animating_scale = true;
1071 return; 1081 return;
1072 } 1082 }
1073 1083
1074 // At this point, we know either the layer or an ancestor, but not both, 1084 // At this point, we know either the layer or an ancestor, but not both,
1075 // is animating scale. 1085 // is animating scale.
1076 *combined_is_animating_scale = true; 1086 *combined_is_animating_scale = true;
1077 if (!layer_is_animating_scale) { 1087 if (!layer_is_animating_scale) {
1078 gfx::Vector2dF layer_transform_scales = 1088 gfx::Vector2dF layer_transform_scales =
1079 MathUtil::ComputeTransform2dScaleComponents(layer->transform(), 0.f); 1089 MathUtil::ComputeTransform2dScaleComponents(layer->transform(), 0.f);
1080 *combined_maximum_animation_contents_scale = 1090 *combined_maximum_animation_contents_scale =
1081 ancestor_maximum_animation_contents_scale * 1091 ancestor_maximum_animation_contents_scale *
1082 std::max(layer_transform_scales.x(), layer_transform_scales.y()); 1092 std::max(layer_transform_scales.x(), layer_transform_scales.y());
1093 *combined_starting_animation_contents_scale =
1094 *combined_maximum_animation_contents_scale;
1083 return; 1095 return;
1084 } 1096 }
1085 1097
1086 float layer_maximum_animated_scale = 0.f; 1098 float layer_maximum_animated_scale = 0.f;
1099 float layer_start_animated_scale = 0.f;
1087 if (!layer->layer_animation_controller()->MaximumTargetScale( 1100 if (!layer->layer_animation_controller()->MaximumTargetScale(
1088 &layer_maximum_animated_scale)) { 1101 &layer_maximum_animated_scale)) {
1089 *combined_maximum_animation_contents_scale = 0.f; 1102 *combined_maximum_animation_contents_scale = 0.f;
1090 return; 1103 return;
1091 } 1104 }
1105 if (!layer->layer_animation_controller()->AnimationStartScale(
1106 &layer_start_animated_scale)) {
1107 *combined_starting_animation_contents_scale = 0.f;
1108 return;
1109 }
1110
1092 gfx::Vector2dF ancestor_transform_scales = 1111 gfx::Vector2dF ancestor_transform_scales =
1093 MathUtil::ComputeTransform2dScaleComponents(ancestor_transform, 0.f); 1112 MathUtil::ComputeTransform2dScaleComponents(ancestor_transform, 0.f);
1113 float max_scale_xy =
1114 std::max(ancestor_transform_scales.x(), ancestor_transform_scales.y());
1094 *combined_maximum_animation_contents_scale = 1115 *combined_maximum_animation_contents_scale =
1095 layer_maximum_animated_scale * 1116 layer_maximum_animated_scale * max_scale_xy;
1096 std::max(ancestor_transform_scales.x(), ancestor_transform_scales.y()); 1117 *combined_starting_animation_contents_scale =
1118 layer_start_animated_scale * max_scale_xy;
1097 } 1119 }
1098 1120
1099 template <typename LayerTypePtr> 1121 template <typename LayerTypePtr>
1100 static inline void MarkLayerWithRenderSurfaceLayerListId( 1122 static inline void MarkLayerWithRenderSurfaceLayerListId(
1101 LayerTypePtr layer, 1123 LayerTypePtr layer,
1102 int current_render_surface_layer_list_id) { 1124 int current_render_surface_layer_list_id) {
1103 layer->draw_properties().last_drawn_render_surface_layer_list_id = 1125 layer->draw_properties().last_drawn_render_surface_layer_list_id =
1104 current_render_surface_layer_list_id; 1126 current_render_surface_layer_list_id;
1105 layer->draw_properties().layer_or_descendant_is_drawn = 1127 layer->draw_properties().layer_or_descendant_is_drawn =
1106 !!current_render_surface_layer_list_id; 1128 !!current_render_surface_layer_list_id;
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
1696 1.f / parent_scales.x(), 1718 1.f / parent_scales.x(),
1697 1.f / parent_scales.y()); 1719 1.f / parent_scales.y());
1698 } 1720 }
1699 1721
1700 // Apply adjustment from position constraints. 1722 // Apply adjustment from position constraints.
1701 ApplyPositionAdjustment(layer, data_from_ancestor.fixed_container, 1723 ApplyPositionAdjustment(layer, data_from_ancestor.fixed_container,
1702 data_from_ancestor.scroll_compensation_matrix, &combined_transform); 1724 data_from_ancestor.scroll_compensation_matrix, &combined_transform);
1703 1725
1704 bool combined_is_animating_scale = false; 1726 bool combined_is_animating_scale = false;
1705 float combined_maximum_animation_contents_scale = 0.f; 1727 float combined_maximum_animation_contents_scale = 0.f;
1728 float combined_starting_animation_contents_scale = 0.f;
1706 if (globals.can_adjust_raster_scales) { 1729 if (globals.can_adjust_raster_scales) {
1707 CalculateAnimationContentsScale( 1730 CalculateAnimationContentsScale(
1708 layer, 1731 layer, data_from_ancestor.ancestor_is_animating_scale,
1709 data_from_ancestor.ancestor_is_animating_scale,
1710 data_from_ancestor.maximum_animation_contents_scale, 1732 data_from_ancestor.maximum_animation_contents_scale,
1711 data_from_ancestor.parent_matrix, 1733 data_from_ancestor.parent_matrix, combined_transform,
1712 combined_transform,
1713 &combined_is_animating_scale, 1734 &combined_is_animating_scale,
1714 &combined_maximum_animation_contents_scale); 1735 &combined_maximum_animation_contents_scale,
1736 &combined_starting_animation_contents_scale);
1715 } 1737 }
1716 data_for_children.ancestor_is_animating_scale = combined_is_animating_scale; 1738 data_for_children.ancestor_is_animating_scale = combined_is_animating_scale;
1717 data_for_children.maximum_animation_contents_scale = 1739 data_for_children.maximum_animation_contents_scale =
1718 combined_maximum_animation_contents_scale; 1740 combined_maximum_animation_contents_scale;
1719 1741
1720 // Compute the 2d scale components of the transform hierarchy up to the target 1742 // Compute the 2d scale components of the transform hierarchy up to the target
1721 // surface. From there, we can decide on a contents scale for the layer. 1743 // surface. From there, we can decide on a contents scale for the layer.
1722 float layer_scale_factors = globals.device_scale_factor; 1744 float layer_scale_factors = globals.device_scale_factor;
1723 if (data_from_ancestor.in_subtree_of_page_scale_application_layer) 1745 if (data_from_ancestor.in_subtree_of_page_scale_application_layer)
1724 layer_scale_factors *= globals.page_scale_factor; 1746 layer_scale_factors *= globals.page_scale_factor;
(...skipping 11 matching lines...) Expand all
1736 layer, 1758 layer,
1737 globals.can_adjust_raster_scales, 1759 globals.can_adjust_raster_scales,
1738 ideal_contents_scale, 1760 ideal_contents_scale,
1739 globals.device_scale_factor, 1761 globals.device_scale_factor,
1740 data_from_ancestor.in_subtree_of_page_scale_application_layer 1762 data_from_ancestor.in_subtree_of_page_scale_application_layer
1741 ? globals.page_scale_factor 1763 ? globals.page_scale_factor
1742 : 1.f, 1764 : 1.f,
1743 animating_transform_to_screen); 1765 animating_transform_to_screen);
1744 1766
1745 UpdateLayerScaleDrawProperties( 1767 UpdateLayerScaleDrawProperties(
1746 layer, 1768 layer, ideal_contents_scale, combined_maximum_animation_contents_scale,
1747 ideal_contents_scale, 1769 combined_starting_animation_contents_scale,
1748 combined_maximum_animation_contents_scale,
1749 data_from_ancestor.in_subtree_of_page_scale_application_layer 1770 data_from_ancestor.in_subtree_of_page_scale_application_layer
1750 ? globals.page_scale_factor 1771 ? globals.page_scale_factor
1751 : 1.f, 1772 : 1.f,
1752 globals.device_scale_factor); 1773 globals.device_scale_factor);
1753 1774
1754 LayerType* mask_layer = layer->mask_layer(); 1775 LayerType* mask_layer = layer->mask_layer();
1755 if (mask_layer) { 1776 if (mask_layer) {
1756 UpdateLayerScaleDrawProperties( 1777 UpdateLayerScaleDrawProperties(
1757 mask_layer, 1778 mask_layer, ideal_contents_scale,
1758 ideal_contents_scale,
1759 combined_maximum_animation_contents_scale, 1779 combined_maximum_animation_contents_scale,
1780 combined_starting_animation_contents_scale,
1760 data_from_ancestor.in_subtree_of_page_scale_application_layer 1781 data_from_ancestor.in_subtree_of_page_scale_application_layer
1761 ? globals.page_scale_factor 1782 ? globals.page_scale_factor
1762 : 1.f, 1783 : 1.f,
1763 globals.device_scale_factor); 1784 globals.device_scale_factor);
1764 } 1785 }
1765 1786
1766 LayerType* replica_mask_layer = 1787 LayerType* replica_mask_layer =
1767 layer->replica_layer() ? layer->replica_layer()->mask_layer() : NULL; 1788 layer->replica_layer() ? layer->replica_layer()->mask_layer() : NULL;
1768 if (replica_mask_layer) { 1789 if (replica_mask_layer) {
1769 UpdateLayerScaleDrawProperties( 1790 UpdateLayerScaleDrawProperties(
1770 replica_mask_layer, 1791 replica_mask_layer, ideal_contents_scale,
1771 ideal_contents_scale,
1772 combined_maximum_animation_contents_scale, 1792 combined_maximum_animation_contents_scale,
1793 combined_starting_animation_contents_scale,
1773 data_from_ancestor.in_subtree_of_page_scale_application_layer 1794 data_from_ancestor.in_subtree_of_page_scale_application_layer
1774 ? globals.page_scale_factor 1795 ? globals.page_scale_factor
1775 : 1.f, 1796 : 1.f,
1776 globals.device_scale_factor); 1797 globals.device_scale_factor);
1777 } 1798 }
1778 1799
1779 // The draw_transform that gets computed below is effectively the layer's 1800 // The draw_transform that gets computed below is effectively the layer's
1780 // draw_transform, unless the layer itself creates a render_surface. In that 1801 // draw_transform, unless the layer itself creates a render_surface. In that
1781 // case, the render_surface re-parents the transforms. 1802 // case, the render_surface re-parents the transforms.
1782 layer_draw_properties.target_space_transform = combined_transform; 1803 layer_draw_properties.target_space_transform = combined_transform;
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after
2648 PropertyTrees* trees_from_inputs) { 2669 PropertyTrees* trees_from_inputs) {
2649 return layer->layer_tree_host()->property_trees(); 2670 return layer->layer_tree_host()->property_trees();
2650 } 2671 }
2651 2672
2652 PropertyTrees* GetPropertyTrees(LayerImpl* layer, 2673 PropertyTrees* GetPropertyTrees(LayerImpl* layer,
2653 PropertyTrees* trees_from_inputs) { 2674 PropertyTrees* trees_from_inputs) {
2654 return trees_from_inputs; 2675 return trees_from_inputs;
2655 } 2676 }
2656 2677
2657 } // namespace cc 2678 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/animation_test_common.cc ('k') | ui/compositor/transform_animation_curve_adapter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698