Index: cc/trees/draw_property_utils.cc |
diff --git a/cc/trees/draw_property_utils.cc b/cc/trees/draw_property_utils.cc |
index 175c33415100440aa966860f8d6a576a48d6f30e..e91c776a09b1b66f94d7a6b39630c31585cf8c42 100644 |
--- a/cc/trees/draw_property_utils.cc |
+++ b/cc/trees/draw_property_utils.cc |
@@ -388,6 +388,7 @@ void ComputeClips(ClipTree* clip_tree, const TransformTree& transform_tree) { |
// clip adjusted due to intersecting with an ancestor clip. |
const bool is_clipped = clip_node->parent_id > 0; |
if (!is_clipped) { |
+ DCHECK(!clip_node->data.inherit_parent_target_space_clip); |
clip_node->data.combined_clip = clip_node->data.clip; |
continue; |
} |
@@ -409,6 +410,8 @@ void ComputeClips(ClipTree* clip_tree, const TransformTree& transform_tree) { |
gfx::Transform parent_to_target; |
gfx::Transform clip_to_target; |
gfx::Transform target_to_clip; |
+ gfx::Transform parent_to_transform_target; |
+ gfx::Transform transform_target_to_target; |
const bool target_is_root_surface = clip_node->data.target_id == 1; |
// When the target is the root surface, we need to include the root |
@@ -417,8 +420,19 @@ void ComputeClips(ClipTree* clip_tree, const TransformTree& transform_tree) { |
target_is_root_surface ? 0 : clip_node->data.target_id; |
bool success = true; |
- if (parent_transform_node->data.content_target_id == |
- clip_node->data.target_id) { |
+ // When render surface applies clip, we need the clip from the target's |
+ // target space. But, as the combined clip is in parent clip's target |
+ // space, we need to first transform it from parent's target space to |
+ // target's target space. |
+ if (clip_node->data.inherit_parent_target_space_clip) { |
+ success &= transform_tree.ComputeTransformWithDestinationSublayerScale( |
+ parent_transform_node->id, transform_node->data.target_id, |
+ &parent_to_transform_target); |
+ success &= transform_tree.ComputeTransformWithDestinationSublayerScale( |
+ transform_node->data.target_id, target_id, |
+ &transform_target_to_target); |
+ } else if (parent_transform_node->data.content_target_id == |
+ clip_node->data.target_id) { |
parent_to_target = parent_transform_node->data.to_target; |
} else { |
success &= transform_tree.ComputeTransformWithDestinationSublayerScale( |
@@ -448,19 +462,41 @@ void ComputeClips(ClipTree* clip_tree, const TransformTree& transform_tree) { |
// In order to intersect with as small a rect as possible, we do a |
// preliminary clip in target space so that when we project back, there's |
// less likelihood of intersecting the view plane. |
- gfx::RectF inherited_clip_in_target_space = MathUtil::MapClippedRect( |
- parent_to_target, parent_clip_node->data.combined_clip); |
+ gfx::RectF inherited_clip_in_target_space; |
+ if (clip_node->data.inherit_parent_target_space_clip && |
+ parent_transform_node->id > transform_node->data.target_id) { |
+ gfx::RectF combined_clip_in_transform_target_space = |
+ MathUtil::MapClippedRect(parent_to_transform_target, |
+ parent_clip_node->data.combined_clip); |
+ inherited_clip_in_target_space = MathUtil::ProjectClippedRect( |
+ transform_target_to_target, combined_clip_in_transform_target_space); |
+ } else if (parent_transform_node->id > target_id) { |
+ inherited_clip_in_target_space = MathUtil::MapClippedRect( |
+ parent_to_target, parent_clip_node->data.combined_clip); |
+ } else { |
+ inherited_clip_in_target_space = MathUtil::ProjectClippedRect( |
+ parent_to_target, parent_clip_node->data.combined_clip); |
+ } |
- gfx::RectF clip_in_target_space = |
- MathUtil::MapClippedRect(clip_to_target, clip_node->data.clip); |
+ // When render surface applies clip, the layer that created the clip node |
+ // doesn't apply any clip. So, we should clip using the clip value |
+ // stored in the clip node. |
+ gfx::RectF intersected_in_target_space; |
+ if (!clip_node->data.inherit_parent_target_space_clip) { |
+ gfx::RectF clip_in_target_space = |
+ MathUtil::MapClippedRect(clip_to_target, clip_node->data.clip); |
- gfx::RectF intersected_in_target_space = gfx::IntersectRects( |
- inherited_clip_in_target_space, clip_in_target_space); |
+ intersected_in_target_space = gfx::IntersectRects( |
+ inherited_clip_in_target_space, clip_in_target_space); |
+ } else { |
+ intersected_in_target_space = inherited_clip_in_target_space; |
+ } |
clip_node->data.combined_clip = MathUtil::ProjectClippedRect( |
target_to_clip, intersected_in_target_space); |
- clip_node->data.combined_clip.Intersect(clip_node->data.clip); |
+ if (!clip_node->data.inherit_parent_target_space_clip) |
+ clip_node->data.combined_clip.Intersect(clip_node->data.clip); |
} |
clip_tree->set_needs_update(false); |
} |