Skip to content

Commit

Permalink
cc: Make impl-thread property trees handle fixed-position layers
Browse files Browse the repository at this point in the history
This makes impl-thread property trees correctly handle fixed-position
layers, as long as there's no bounds_delta (handling bounds_delta is
left for another CL). This CL makes the offset between a fixed-position
layer and its container unchangeable on the compositor thread, so that
it remains unaffected by impl scrolling of intermediate layers. This
also changes the transform node used as the parent of a fixed-position
node when the fixed-position container is scrollable: since scrolls of
this container aren't supposed to affect contained fixed-position
layers, yet do contribute to this node's local transform, this node's
parent is used as the transform tree parent of contained fixed-position
nodes.

This makes the portions of LayerPostionConstraintTests that do not
involve bounds_delta pass with verification enabled.

BUG=481585
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel

Review URL: https://codereview.chromium.org/1144993004

Cr-Commit-Position: refs/heads/master@{#332055}
  • Loading branch information
alijuma authored and Commit bot committed May 29, 2015
1 parent 9641ea0 commit 5e47dec
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 12 deletions.
1 change: 1 addition & 0 deletions cc/layers/layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,7 @@ gfx::Vector2dF LayerImpl::ScrollDelta() const {

void LayerImpl::SetScrollDelta(const gfx::Vector2dF& delta) {
DCHECK(IsActive());
DCHECK(scrollable() || delta.IsZero());
SetCurrentScrollOffset(scroll_offset_->ActiveBase() +
gfx::ScrollOffset(delta));
}
Expand Down
1 change: 1 addition & 0 deletions cc/layers/layer_position_constraint_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,7 @@ TEST_F(LayerPositionConstraintTest,
child_->SetIsContainerForFixedPositionLayers(true);
grand_child_->SetPositionConstraint(fixed_to_top_left_);
great_grand_child_->SetIsContainerForFixedPositionLayers(true);
great_grand_child_->SetScrollClipLayerId(root_->id());
great_great_grand_child->SetPositionConstraint(fixed_to_top_left_);

CommitAndUpdateImplPointers();
Expand Down
1 change: 1 addition & 0 deletions cc/trees/layer_tree_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class CC_EXPORT LayerTreeImpl {

void SetPropertyTrees(const PropertyTrees& property_trees) {
property_trees_ = property_trees;
property_trees_.transform_tree.set_source_to_parent_updates_allowed(false);
}
PropertyTrees* property_trees() { return &property_trees_; }

Expand Down
20 changes: 14 additions & 6 deletions cc/trees/property_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ template <typename T>
PropertyTree<T>::~PropertyTree() {
}

TransformTree::TransformTree() : source_to_parent_updates_allowed_(true) {
}

template <typename T>
int PropertyTree<T>::Insert(const T& tree_node, int parent_id) {
DCHECK_GT(nodes_.size(), 0u);
Expand Down Expand Up @@ -137,12 +140,17 @@ bool TransformTree::Are2DAxisAligned(int source_id, int dest_id) const {
transform.Preserves2dAxisAlignment();
}

bool TransformTree::NeedsSourceToParentUpdate(TransformNode* node) {
return (source_to_parent_updates_allowed() &&
node->parent_id != node->data.source_node_id);
}

void TransformTree::UpdateTransforms(int id) {
TransformNode* node = Node(id);
TransformNode* parent_node = parent(node);
TransformNode* target_node = Node(node->data.target_id);
if (node->data.needs_local_transform_update ||
node->parent_id != node->data.source_node_id)
NeedsSourceToParentUpdate(node))
UpdateLocalTransform(node);
UpdateScreenSpaceTransform(node, parent_node, target_node);
UpdateSublayerScale(node);
Expand Down Expand Up @@ -274,14 +282,14 @@ bool TransformTree::CombineInversesBetween(int source_id,

void TransformTree::UpdateLocalTransform(TransformNode* node) {
gfx::Transform transform = node->data.post_local;
gfx::Vector2dF source_to_parent;
if (node->parent_id != node->data.source_node_id) {
if (NeedsSourceToParentUpdate(node)) {
gfx::Transform to_parent;
ComputeTransform(node->data.source_node_id, node->parent_id, &to_parent);
source_to_parent = to_parent.To2dTranslation();
node->data.source_to_parent = to_parent.To2dTranslation();
}
transform.Translate(source_to_parent.x() - node->data.scroll_offset.x(),
source_to_parent.y() - node->data.scroll_offset.y());
transform.Translate(
node->data.source_to_parent.x() - node->data.scroll_offset.x(),
node->data.source_to_parent.y() - node->data.scroll_offset.y());
transform.PreconcatTransform(node->data.local);
transform.PreconcatTransform(node->data.pre_local);
node->data.set_to_parent(transform);
Expand Down
21 changes: 21 additions & 0 deletions cc/trees/property_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ struct CC_EXPORT TransformNodeData {

// TODO(vollick): will be moved when accelerated effects are implemented.
gfx::Vector2dF source_offset;
gfx::Vector2dF source_to_parent;

void set_to_parent(const gfx::Transform& transform) {
to_parent = transform;
Expand Down Expand Up @@ -175,6 +176,8 @@ class CC_EXPORT PropertyTree {

class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> {
public:
TransformTree();

// Computes the change of basis transform from node |source_id| to |dest_id|.
// The function returns false iff the inverse of a singular transform was
// used (and the result should, therefore, not be trusted). Transforms may
Expand Down Expand Up @@ -212,6 +215,21 @@ class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> {
// Updates the parent, target, and screen space transforms and snapping.
void UpdateTransforms(int id);

// A TransformNode's source_to_parent value is used to account for the fact
// that fixed-position layers are positioned by Blink wrt to their layer tree
// parent (their "source"), but are parented in the transform tree by their
// fixed-position container. This value needs to be updated on main-thread
// property trees (for position changes initiated by Blink), but not on the
// compositor thread (since the offset from a node corresponding to a
// fixed-position layer to its fixed-position container is unaffected by
// compositor-driven effects).
void set_source_to_parent_updates_allowed(bool allowed) {
source_to_parent_updates_allowed_ = allowed;
}
bool source_to_parent_updates_allowed() const {
return source_to_parent_updates_allowed_;
}

private:
// Returns true iff the node at |desc_id| is a descendant of the node at
// |anc_id|.
Expand Down Expand Up @@ -240,6 +258,9 @@ class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> {
TransformNode* target_node);
void UpdateIsAnimated(TransformNode* node, TransformNode* parent_node);
void UpdateSnapping(TransformNode* node);
bool NeedsSourceToParentUpdate(TransformNode* node);

bool source_to_parent_updates_allowed_;
};

class CC_EXPORT ClipTree final : public PropertyTree<ClipNode> {};
Expand Down
16 changes: 10 additions & 6 deletions cc/trees/property_tree_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,13 @@ bool AddTransformNodeIfNeeded(
}

if (layer->IsContainerForFixedPositionLayers() || is_root) {
DCHECK(!is_scrollable || layer->transform().IsIdentity());
data_for_children->transform_fixed_parent = layer;
if (is_scrollable) {
DCHECK(!is_root);
DCHECK(layer->transform().IsIdentity());
data_for_children->transform_fixed_parent = layer->parent();
} else {
data_for_children->transform_fixed_parent = layer;
}
}
data_for_children->transform_tree_parent = layer;

Expand Down Expand Up @@ -386,6 +391,9 @@ void BuildPropertyTreesTopLevelInternal(LayerType* root_layer,
const gfx::Rect& viewport,
const gfx::Transform& device_transform,
PropertyTrees* property_trees) {
if (!property_trees->needs_rebuild)
return;

property_trees->sequence_number++;

DataForRecursion<LayerType> data_for_recursion;
Expand Down Expand Up @@ -433,10 +441,6 @@ void PropertyTreeBuilder::BuildPropertyTrees(
const gfx::Rect& viewport,
const gfx::Transform& device_transform,
PropertyTrees* property_trees) {
// TODO(enne): hoist this out of here
if (!property_trees->needs_rebuild)
return;

BuildPropertyTreesTopLevelInternal(
root_layer, page_scale_layer, page_scale_factor, device_scale_factor,
viewport, device_transform, property_trees);
Expand Down

0 comments on commit 5e47dec

Please sign in to comment.