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

Unified Diff: cc/trees/property_tree.cc

Issue 2105673003: cc: Compute animation scale on demand (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile error Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: cc/trees/property_tree.cc
diff --git a/cc/trees/property_tree.cc b/cc/trees/property_tree.cc
index 5d70b987cf22edd75f67b71a75f8235144f3e8db..cbe027ab1ed953c9b217bf616afb7a44cf2b9722 100644
--- a/cc/trees/property_tree.cc
+++ b/cc/trees/property_tree.cc
@@ -179,11 +179,7 @@ TransformNodeData::TransformNodeData()
affected_by_outer_viewport_bounds_delta_y(false),
in_subtree_of_page_scale_layer(false),
transform_changed(false),
- post_local_scale_factor(1.0f),
- local_maximum_animation_target_scale(0.f),
- local_starting_animation_scale(0.f),
- combined_maximum_animation_target_scale(0.f),
- combined_starting_animation_scale(0.f) {}
+ post_local_scale_factor(1.0f) {}
TransformNodeData::TransformNodeData(const TransformNodeData& other) = default;
@@ -225,14 +221,6 @@ bool TransformNodeData::operator==(const TransformNodeData& other) const {
other.in_subtree_of_page_scale_layer &&
transform_changed == other.transform_changed &&
post_local_scale_factor == other.post_local_scale_factor &&
- local_maximum_animation_target_scale ==
- other.local_maximum_animation_target_scale &&
- local_starting_animation_scale ==
- other.local_starting_animation_scale &&
- combined_maximum_animation_target_scale ==
- other.combined_maximum_animation_target_scale &&
- combined_starting_animation_scale ==
- other.combined_starting_animation_scale &&
sublayer_scale == other.sublayer_scale &&
scroll_offset == other.scroll_offset &&
scroll_snap == other.scroll_snap &&
@@ -306,13 +294,6 @@ void TransformNodeData::ToProtobuf(proto::TreeNode* proto) const {
data->set_in_subtree_of_page_scale_layer(in_subtree_of_page_scale_layer);
data->set_transform_changed(transform_changed);
data->set_post_local_scale_factor(post_local_scale_factor);
- data->set_local_maximum_animation_target_scale(
- local_maximum_animation_target_scale);
- data->set_local_starting_animation_scale(local_starting_animation_scale);
- data->set_combined_maximum_animation_target_scale(
- combined_maximum_animation_target_scale);
- data->set_combined_starting_animation_scale(
- combined_starting_animation_scale);
Vector2dFToProto(sublayer_scale, data->mutable_sublayer_scale());
ScrollOffsetToProto(scroll_offset, data->mutable_scroll_offset());
@@ -368,12 +349,6 @@ void TransformNodeData::FromProtobuf(const proto::TreeNode& proto) {
in_subtree_of_page_scale_layer = data.in_subtree_of_page_scale_layer();
transform_changed = data.transform_changed();
post_local_scale_factor = data.post_local_scale_factor();
- local_maximum_animation_target_scale =
- data.local_maximum_animation_target_scale();
- local_starting_animation_scale = data.local_starting_animation_scale();
- combined_maximum_animation_target_scale =
- data.combined_maximum_animation_target_scale();
- combined_starting_animation_scale = data.combined_starting_animation_scale();
sublayer_scale = ProtoToVector2dF(data.sublayer_scale());
scroll_offset = ProtoToScrollOffset(data.scroll_offset());
@@ -738,6 +713,12 @@ void TransformTree::clear() {
cached_data_.push_back(TransformCachedNodeData());
}
+void TransformTree::set_needs_update(bool needs_update) {
+ if (needs_update && !PropertyTree::needs_update())
+ property_trees()->UpdateCachedNumber();
jaydasika 2016/06/28 23:08:40 Should be invalidate the cache as soon as we set_n
sunxd 2016/06/30 15:29:43 Hmm, that depends on whether we get animation scal
+ PropertyTree::set_needs_update(needs_update);
+}
+
bool TransformTree::ComputeTransform(int source_id,
int dest_id,
gfx::Transform* transform) const {
@@ -1060,89 +1041,16 @@ void TransformTree::UpdateAnimationProperties(TransformNode* node,
TransformNode* parent_node) {
bool ancestor_is_animating = false;
bool ancestor_is_animating_scale = false;
- float ancestor_maximum_target_scale = 0.f;
- float ancestor_starting_animation_scale = 0.f;
if (parent_node) {
ancestor_is_animating = parent_node->data.to_screen_is_potentially_animated;
ancestor_is_animating_scale =
parent_node->data.to_screen_has_scale_animation;
- ancestor_maximum_target_scale =
- parent_node->data.combined_maximum_animation_target_scale;
- ancestor_starting_animation_scale =
- parent_node->data.combined_starting_animation_scale;
}
node->data.to_screen_is_potentially_animated =
node->data.has_potential_animation || ancestor_is_animating;
node->data.to_screen_has_scale_animation =
!node->data.has_only_translation_animations ||
ancestor_is_animating_scale;
-
- // Once we've failed to compute a maximum animated scale at an ancestor, we
- // continue to fail.
- bool failed_at_ancestor =
jaydasika 2016/06/28 23:08:40 Can we move comments to GetAnimationScales ?
sunxd 2016/06/30 15:29:44 Done.
- ancestor_is_animating_scale && ancestor_maximum_target_scale == 0.f;
-
- // Computing maximum animated scale in the presence of non-scale/translation
- // transforms isn't supported.
- bool failed_for_non_scale_or_translation =
- !ToTarget(node->id).IsScaleOrTranslation();
-
- // We don't attempt to accumulate animation scale from multiple nodes with
- // scale animations, because of the risk of significant overestimation. For
- // example, one node might be increasing scale from 1 to 10 at the same time
- // as another node is decreasing scale from 10 to 1. Naively combining these
- // scales would produce a scale of 100.
- bool failed_for_multiple_scale_animations =
- ancestor_is_animating_scale &&
- !node->data.has_only_translation_animations;
-
- if (failed_at_ancestor || failed_for_non_scale_or_translation ||
- failed_for_multiple_scale_animations) {
- node->data.combined_maximum_animation_target_scale = 0.f;
- node->data.combined_starting_animation_scale = 0.f;
-
- // This ensures that descendants know we've failed to compute a maximum
- // animated scale.
- node->data.to_screen_has_scale_animation = true;
- return;
- }
-
- if (!node->data.to_screen_has_scale_animation) {
- node->data.combined_maximum_animation_target_scale = 0.f;
- node->data.combined_starting_animation_scale = 0.f;
- return;
- }
-
- // At this point, we know exactly one of this node or an ancestor is animating
- // scale.
- if (node->data.has_only_translation_animations) {
- // An ancestor is animating scale.
- gfx::Vector2dF local_scales =
- MathUtil::ComputeTransform2dScaleComponents(node->data.local, 0.f);
- float max_local_scale = std::max(local_scales.x(), local_scales.y());
- node->data.combined_maximum_animation_target_scale =
- max_local_scale * ancestor_maximum_target_scale;
- node->data.combined_starting_animation_scale =
- max_local_scale * ancestor_starting_animation_scale;
- return;
- }
-
- if (node->data.local_starting_animation_scale == 0.f ||
- node->data.local_maximum_animation_target_scale == 0.f) {
- node->data.combined_maximum_animation_target_scale = 0.f;
- node->data.combined_starting_animation_scale = 0.f;
- return;
- }
-
- gfx::Vector2dF ancestor_scales =
- parent_node ? MathUtil::ComputeTransform2dScaleComponents(
- ToTarget(parent_node->id), 0.f)
- : gfx::Vector2dF(1.f, 1.f);
- float max_ancestor_scale = std::max(ancestor_scales.x(), ancestor_scales.y());
- node->data.combined_maximum_animation_target_scale =
- max_ancestor_scale * node->data.local_maximum_animation_target_scale;
- node->data.combined_starting_animation_scale =
- max_ancestor_scale * node->data.local_starting_animation_scale;
}
void TransformTree::UndoSnapping(TransformNode* node) {
@@ -2149,6 +2057,13 @@ gfx::ScrollOffset ScrollTree::ClampScrollOffsetToLimits(
return offset;
}
+PropertyTreesCachedData::PropertyTreesCachedData()
+ : property_tree_update_number(0) {
+ animation_scales.clear();
+}
+
+PropertyTreesCachedData::~PropertyTreesCachedData() {}
+
PropertyTrees::PropertyTrees()
: needs_rebuild(true),
non_root_surfaces_enabled(true),
@@ -2211,6 +2126,7 @@ PropertyTrees& PropertyTrees::operator=(const PropertyTrees& from) {
effect_tree.SetPropertyTrees(this);
clip_tree.SetPropertyTrees(this);
scroll_tree.SetPropertyTrees(this);
+ ResetCachedData();
return *this;
}
@@ -2393,4 +2309,127 @@ std::unique_ptr<base::trace_event::TracedValue> PropertyTrees::AsTracedValue()
return value;
}
+CombinedAnimationScale PropertyTrees::GetAnimationScales(
+ int transform_node_id,
+ LayerTreeImpl* layer_tree_impl) {
+ if (cached_data_.animation_scales[transform_node_id].update_number !=
+ cached_data_.property_tree_update_number) {
+ TransformNode* node = transform_tree.Node(transform_node_id);
+ TransformNode* parent_node = transform_tree.parent(node);
+ bool ancestor_is_animating_scale = false;
+ float ancestor_maximum_target_scale = 0.f;
+ float ancestor_starting_animation_scale = 0.f;
+ if (parent_node) {
+ ancestor_is_animating_scale =
+ parent_node->data.to_screen_has_scale_animation;
+ CombinedAnimationScale combined_animation_scale = GetAnimationScales(
+ transform_tree.Node(transform_node_id)->parent_id, layer_tree_impl);
+ ancestor_maximum_target_scale =
+ combined_animation_scale.maximum_animation_scale;
+ ancestor_starting_animation_scale =
+ combined_animation_scale.starting_animation_scale;
+ }
+
+ bool failed_at_ancestor =
+ ancestor_is_animating_scale && ancestor_maximum_target_scale == 0.f;
+ bool failed_for_non_scale_or_translation =
+ !transform_tree.ToTarget(transform_node_id).IsScaleOrTranslation();
+ bool failed_for_multiple_scale_animations =
+ ancestor_is_animating_scale &&
+ !node->data.has_only_translation_animations;
+
+ if (failed_at_ancestor || failed_for_non_scale_or_translation ||
+ failed_for_multiple_scale_animations) {
+ node->data.to_screen_has_scale_animation = true;
+ cached_data_.animation_scales[transform_node_id]
+ .combined_maximum_animation_target_scale = 0.f;
+ cached_data_.animation_scales[transform_node_id]
+ .combined_starting_animation_scale = 0.f;
+ } else if (!node->data.to_screen_has_scale_animation) {
+ cached_data_.animation_scales[transform_node_id]
+ .combined_maximum_animation_target_scale = 0.f;
+ cached_data_.animation_scales[transform_node_id]
+ .combined_starting_animation_scale = 0.f;
+ } else if (node->data.has_only_translation_animations) {
+ gfx::Vector2dF local_scales =
+ MathUtil::ComputeTransform2dScaleComponents(node->data.local, 0.f);
+ float max_local_scale = std::max(local_scales.x(), local_scales.y());
+ cached_data_.animation_scales[transform_node_id]
+ .combined_maximum_animation_target_scale =
+ max_local_scale * ancestor_maximum_target_scale;
+ cached_data_.animation_scales[transform_node_id]
+ .combined_starting_animation_scale =
+ max_local_scale * ancestor_starting_animation_scale;
+ } else {
+ LayerImpl* layer_impl = layer_tree_impl->LayerById(node->owner_id);
+ layer_tree_impl->MaximumTargetScale(
+ layer_impl, &cached_data_.animation_scales[transform_node_id]
+ .local_maximum_animation_target_scale);
+ layer_tree_impl->AnimationStartScale(
+ layer_impl, &cached_data_.animation_scales[transform_node_id]
+ .local_starting_animation_scale);
+ gfx::Vector2dF local_scales =
+ MathUtil::ComputeTransform2dScaleComponents(node->data.local, 0.f);
+ float max_local_scale = std::max(local_scales.x(), local_scales.y());
+
+ if (cached_data_.animation_scales[transform_node_id]
+ .local_starting_animation_scale == 0.f ||
+ cached_data_.animation_scales[transform_node_id]
+ .local_maximum_animation_target_scale == 0.f) {
+ cached_data_.animation_scales[transform_node_id]
+ .combined_maximum_animation_target_scale =
+ max_local_scale * ancestor_maximum_target_scale;
+ cached_data_.animation_scales[transform_node_id]
+ .combined_starting_animation_scale =
+ max_local_scale * ancestor_starting_animation_scale;
+ } else {
+ gfx::Vector2dF ancestor_scales =
+ parent_node ? MathUtil::ComputeTransform2dScaleComponents(
+ transform_tree.ToTarget(parent_node->id), 0.f)
+ : gfx::Vector2dF(1.f, 1.f);
+ float max_ancestor_scale =
+ std::max(ancestor_scales.x(), ancestor_scales.y());
+ cached_data_.animation_scales[transform_node_id]
+ .combined_maximum_animation_target_scale =
+ max_ancestor_scale *
+ cached_data_.animation_scales[transform_node_id]
+ .local_maximum_animation_target_scale;
+ cached_data_.animation_scales[transform_node_id]
+ .combined_starting_animation_scale =
+ max_ancestor_scale *
+ cached_data_.animation_scales[transform_node_id]
+ .local_starting_animation_scale;
+ }
+ }
+ cached_data_.animation_scales[transform_node_id].update_number =
+ cached_data_.property_tree_update_number;
+ }
+ return CombinedAnimationScale(cached_data_.animation_scales[transform_node_id]
+ .combined_maximum_animation_target_scale,
+ cached_data_.animation_scales[transform_node_id]
+ .combined_starting_animation_scale);
+}
+
+void PropertyTrees::SetAnimationScalesForTesting(
+ int transform_id,
+ float maximum_animation_scale,
+ float starting_animation_scale) {
+ cached_data_.animation_scales[transform_id]
+ .combined_maximum_animation_target_scale = maximum_animation_scale;
+ cached_data_.animation_scales[transform_id]
+ .combined_starting_animation_scale = starting_animation_scale;
+ cached_data_.animation_scales[transform_id].update_number =
+ cached_data_.property_tree_update_number;
+}
+
+void PropertyTrees::ResetCachedData() {
+ cached_data_.property_tree_update_number = 0;
+ cached_data_.animation_scales = std::vector<AnimationScaleData>(
+ transform_tree.nodes().size(), AnimationScaleData());
+}
+
+void PropertyTrees::UpdateCachedNumber() {
+ cached_data_.property_tree_update_number++;
+}
+
jaydasika 2016/06/28 23:08:40 Add cached_data_ to PropertyTrees::operator==
sunxd 2016/06/30 15:29:43 I think cached_data_ should be considered separate
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698