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

Unified Diff: cc/trees/draw_property_utils.cc

Issue 2148383005: cc: Use sublayer scale from effect tree (2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/sublayer_scale/surface_contents_scale Created 4 years, 5 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/draw_property_utils.cc
diff --git a/cc/trees/draw_property_utils.cc b/cc/trees/draw_property_utils.cc
index 1fe57213e6c7cc02c3146a455bd348c4b1830a4d..af8919e1842bf19198f8e93d802f0083944f9c8a 100644
--- a/cc/trees/draw_property_utils.cc
+++ b/cc/trees/draw_property_utils.cc
@@ -54,26 +54,31 @@ static void ValidateRenderSurfaceForLayer(LayerImpl* layer) {
DCHECK(effect_node->background_filters.IsEmpty());
}
-void VerifySublayerScalesMatch(const int effect_node_id,
+void VerifySublayerScalesMatch(const int target_effect_id,
const int target_transform_id,
const EffectTree& effect_tree,
const TransformTree& transform_tree) {
const TransformNode* target_transform_node =
transform_tree.Node(target_transform_id);
- const EffectNode* effect_node = effect_tree.Node(effect_node_id);
- const EffectNode* target_effect_node =
- effect_node->has_render_surface
- ? effect_node
- : effect_tree.Node(effect_node->target_id);
- DCHECK(target_transform_node->sublayer_scale ==
- target_effect_node->sublayer_scale)
+ const EffectNode* target_effect_node = effect_tree.Node(target_effect_id);
+ DCHECK(target_transform_node->surface_contents_scale ==
+ target_effect_node->surface_contents_scale)
<< " sublayer scale from transform tree: "
- << target_transform_node->sublayer_scale.ToString()
+ << target_transform_node->surface_contents_scale.ToString()
<< " sublayer scale from effect tree: "
- << target_effect_node->sublayer_scale.ToString();
+ << target_effect_node->surface_contents_scale.ToString();
}
#endif
+static const EffectNode* ContentsTargetEffectNode(
+ const int effect_tree_index,
+ const EffectTree& effect_tree) {
+ const EffectNode* effect_node = effect_tree.Node(effect_tree_index);
+ return effect_node->has_render_surface
+ ? effect_node
+ : effect_tree.Node(effect_node->target_id);
+}
+
template <typename LayerType>
bool ComputeClipRectInTargetSpace(const LayerType* layer,
const ClipNode* clip_node,
@@ -93,20 +98,23 @@ bool ComputeClipRectInTargetSpace(const LayerType* layer,
target_node_id, &clip_to_target)) {
// We don't have to apply sublayer scale when target is root.
if (target_node_id != 0) {
- PostConcatSublayerScale(layer->effect_tree_index(), effect_tree,
- &clip_to_target);
+ const EffectNode* target_effect_node =
+ ContentsTargetEffectNode(layer->effect_tree_index(), effect_tree);
+ PostConcatSublayerScale(target_effect_node, &clip_to_target);
#if DCHECK_IS_ON()
VerifySublayerScalesMatch(layer->effect_tree_index(), target_node_id,
effect_tree, transform_tree);
#endif
}
- const TransformNode* source_node =
- transform_tree.Node(clip_node->target_transform_id);
- if (source_node->sublayer_scale.x() != 0.f &&
- source_node->sublayer_scale.y() != 0.f)
- clip_to_target.Scale(1.0f / source_node->sublayer_scale.x(),
- 1.0f / source_node->sublayer_scale.y());
+ const EffectNode* source_node =
+ effect_tree.Node(clip_node->target_effect_id);
+ ConcatInverseSublayerScale(source_node, &clip_to_target);
+#if DCHECK_IS_ON()
+ VerifySublayerScalesMatch(clip_node->target_effect_id,
+ clip_node->target_transform_id, effect_tree,
+ transform_tree);
+#endif
*clip_rect_in_target_space = MathUtil::MapClippedRect(
clip_to_target, clip_node->clip_in_target_space);
} else {
@@ -132,13 +140,18 @@ struct ConditionalClip {
static ConditionalClip ComputeTargetRectInLocalSpace(
gfx::RectF rect,
const TransformTree& transform_tree,
+ const EffectTree& effect_tree,
int current_transform_id,
- int target_transform_id) {
+ int target_transform_id,
+ const int current_effect_id) {
gfx::Transform current_to_target;
- if (!transform_tree.ComputeTransformWithSourceSublayerScale(
- current_transform_id, target_transform_id, &current_to_target))
+ bool success = transform_tree.ComputeTransform(
+ current_transform_id, target_transform_id, &current_to_target);
+ if (!success)
// If transform is not invertible, cannot apply clip.
return ConditionalClip{false, gfx::RectF()};
+ const EffectNode* current_effect_node = effect_tree.Node(current_effect_id);
+ ConcatInverseSublayerScale(current_effect_node, &current_to_target);
if (current_transform_id > target_transform_id)
return ConditionalClip{true, // is_clipped.
@@ -162,7 +175,8 @@ static ConditionalClip ComputeLocalRectInTargetSpace(
return ConditionalClip{false, gfx::RectF()};
// We don't have to apply sublayer scale when target is root.
if (target_transform_id != 0) {
- PostConcatSublayerScale(target_effect_id, effect_tree, &current_to_target);
+ const EffectNode* target_effect_node = effect_tree.Node(target_effect_id);
+ PostConcatSublayerScale(target_effect_node, &current_to_target);
#if DCHECK_IS_ON()
VerifySublayerScalesMatch(target_effect_id, target_transform_id,
effect_tree, transform_tree);
@@ -188,10 +202,10 @@ static ConditionalClip ComputeCurrentClip(const ClipNode* clip_node,
target_transform_id, target_effect_id);
gfx::RectF current_clip = clip_node->clip;
- gfx::Vector2dF sublayer_scale =
- transform_tree.Node(target_transform_id)->sublayer_scale;
- if (sublayer_scale.x() > 0 && sublayer_scale.y() > 0)
- current_clip.Scale(sublayer_scale.x(), sublayer_scale.y());
+ gfx::Vector2dF surface_contents_scale =
+ effect_tree.Node(target_effect_id)->surface_contents_scale;
+ if (surface_contents_scale.x() > 0 && surface_contents_scale.y() > 0)
+ current_clip.Scale(surface_contents_scale.x(), surface_contents_scale.y());
return ConditionalClip{true /* is_clipped */, current_clip};
}
@@ -374,9 +388,9 @@ void CalculateVisibleRects(
const EffectNode* copy_request_effect_node =
effect_tree.Node(effect_ancestor_with_copy_request);
ConditionalClip clip_in_layer_space = ComputeTargetRectInLocalSpace(
- accumulated_clip_in_copy_request_space, transform_tree,
- copy_request_effect_node->transform_id,
- layer->transform_tree_index());
+ accumulated_clip_in_copy_request_space, transform_tree, effect_tree,
+ copy_request_effect_node->transform_id, layer->transform_tree_index(),
+ copy_request_effect_node->id);
if (clip_in_layer_space.is_clipped) {
gfx::RectF clip_rect = clip_in_layer_space.clip_rect;
@@ -491,16 +505,25 @@ void CalculateVisibleRects(
if (transform_node->ancestors_are_invertible) {
target_to_layer = transform_tree.FromTarget(transform_node->id);
} else {
- if (!transform_tree.ComputeTransformWithSourceSublayerScale(
- target_node_id, transform_node->id, &target_to_layer)) {
+ bool success = transform_tree.ComputeTransform(
+ target_node_id, transform_node->id, &target_to_layer);
+ if (!success) {
// An animated singular transform may become non-singular during the
// animation, so we still need to compute a visible rect. In this
// situation, we treat the entire layer as visible.
layer->set_visible_layer_rect(gfx::Rect(layer_bounds));
continue;
}
+ if (target_node_id != 0) {
+ const EffectNode* target_effect_node =
+ ContentsTargetEffectNode(layer->effect_tree_index(), effect_tree);
+ ConcatInverseSublayerScale(target_effect_node, &target_to_layer);
+#if DCHECK_IS_ON()
+ VerifySublayerScalesMatch(target_effect_node->id, target_node_id,
+ effect_tree, transform_tree);
+#endif
+ }
}
-
gfx::Transform target_to_content;
target_to_content.Translate(-layer->offset_to_transform_parent().x(),
-layer->offset_to_transform_parent().y());
@@ -700,28 +723,20 @@ static void ResetIfHasNanCoordinate(gfx::RectF* rect) {
*rect = gfx::RectF();
}
-void PostConcatSublayerScale(const int effect_node_id,
- const EffectTree& effect_tree,
+void PostConcatSublayerScale(const EffectNode* effect_node,
gfx::Transform* transform) {
- // TODO(jaydasika): This function should not compute target effect node id. It
- // should receive it from callers.
- const EffectNode* effect_node = effect_tree.Node(effect_node_id);
- const EffectNode* target_effect_node =
- effect_node->has_render_surface
- ? effect_node
- : effect_tree.Node(effect_node->target_id);
- transform->matrix().postScale(target_effect_node->sublayer_scale.x(),
- target_effect_node->sublayer_scale.y(), 1.f);
+ DCHECK(effect_node->has_render_surface);
+ transform->matrix().postScale(effect_node->surface_contents_scale.x(),
+ effect_node->surface_contents_scale.y(), 1.f);
}
-void ConcatInverseSublayerScale(const int effect_node_id,
- const EffectTree& effect_tree,
+void ConcatInverseSublayerScale(const EffectNode* effect_node,
gfx::Transform* transform) {
- const EffectNode* effect_node = effect_tree.Node(effect_node_id);
- if (effect_node->sublayer_scale.x() != 0.0 &&
- effect_node->sublayer_scale.y() != 0.0)
- transform->Scale(1.0 / effect_node->sublayer_scale.x(),
- 1.0 / effect_node->sublayer_scale.y());
+ DCHECK(effect_node->has_render_surface);
+ if (effect_node->surface_contents_scale.x() != 0.0 &&
+ effect_node->surface_contents_scale.y() != 0.0)
+ transform->Scale(1.0 / effect_node->surface_contents_scale.x(),
+ 1.0 / effect_node->surface_contents_scale.y());
}
void ComputeClips(ClipTree* clip_tree,
@@ -770,19 +785,26 @@ void ComputeClips(ClipTree* clip_tree,
&parent_to_current);
// We don't have to apply sublayer scale when target is root.
if (clip_node->target_transform_id != 0) {
- PostConcatSublayerScale(clip_node->target_effect_id, effect_tree,
- &parent_to_current);
+ const EffectNode* target_effect_node =
+ effect_tree.Node(clip_node->target_effect_id);
+ PostConcatSublayerScale(target_effect_node, &parent_to_current);
#if DCHECK_IS_ON()
VerifySublayerScalesMatch(clip_node->target_effect_id,
clip_node->target_transform_id, effect_tree,
transform_tree);
#endif
}
- if (parent_target_transform_node->sublayer_scale.x() > 0 &&
- parent_target_transform_node->sublayer_scale.y() > 0)
- parent_to_current.Scale(
- 1.f / parent_target_transform_node->sublayer_scale.x(),
- 1.f / parent_target_transform_node->sublayer_scale.y());
+ if (parent_clip_node->target_transform_id != 0) {
+ const EffectNode* parent_target_effect_node =
+ effect_tree.Node(parent_clip_node->target_effect_id);
+ ConcatInverseSublayerScale(parent_target_effect_node,
+ &parent_to_current);
+#if DCHECK_IS_ON()
+ VerifySublayerScalesMatch(parent_clip_node->target_effect_id,
+ parent_clip_node->target_transform_id,
+ effect_tree, transform_tree);
+#endif
+ }
// If we can't compute a transform, it's because we had to use the inverse
// of a singular transform. We won't draw in this case, so there's no need
// to compute clips.
@@ -844,8 +866,9 @@ void ComputeClips(ClipTree* clip_tree,
&source_to_target);
// We don't have to apply sublayer scale when target is root.
if (clip_node->target_transform_id != 0) {
- PostConcatSublayerScale(clip_node->target_effect_id, effect_tree,
- &source_to_target);
+ const EffectNode* target_effect_node =
+ effect_tree.Node(clip_node->target_effect_id);
+ PostConcatSublayerScale(target_effect_node, &source_to_target);
#if DCHECK_IS_ON()
VerifySublayerScalesMatch(clip_node->target_effect_id,
clip_node->target_transform_id, effect_tree,
@@ -1006,8 +1029,9 @@ static void VerifyDrawTransformsMatch(LayerImpl* layer,
&draw_transform);
// We don't have to apply sublayer scale when target is root.
if (destination_id != 0) {
- PostConcatSublayerScale(layer->effect_tree_index(),
- property_trees->effect_tree, &draw_transform);
+ const EffectNode* target_effect_node = ContentsTargetEffectNode(
+ layer->effect_tree_index(), property_trees->effect_tree);
+ PostConcatSublayerScale(target_effect_node, &draw_transform);
#if DCHECK_IS_ON()
VerifySublayerScalesMatch(layer->effect_tree_index(), destination_id,
property_trees->effect_tree,
@@ -1178,7 +1202,8 @@ gfx::Transform DrawTransform(const LayerImpl* layer,
layer->offset_to_transform_parent().y());
} else {
// Surfaces need to apply their sublayer scale.
- xform.Scale(node->sublayer_scale.x(), node->sublayer_scale.y());
+ xform.Scale(node->surface_contents_scale.x(),
+ node->surface_contents_scale.y());
}
return xform;
}
@@ -1203,19 +1228,20 @@ static void SetSurfaceDrawTransform(const TransformTree& transform_tree,
&render_surface_transform);
// We don't have to apply sublayer scale when target is root.
if (target_transform_node->id != 0) {
- PostConcatSublayerScale(effect_node->target_id, effect_tree,
- &render_surface_transform);
+ const EffectNode* target_effect_node =
+ effect_tree.Node(effect_node->target_id);
+ PostConcatSublayerScale(target_effect_node, &render_surface_transform);
#if DCHECK_IS_ON()
VerifySublayerScalesMatch(effect_node->target_id, target_transform_node->id,
effect_tree, transform_tree);
#endif
}
- DCHECK(transform_node->sublayer_scale == effect_node->sublayer_scale);
- if (effect_node->sublayer_scale.x() != 0.0 &&
- effect_node->sublayer_scale.y() != 0.0)
- render_surface_transform.Scale(1.0 / effect_node->sublayer_scale.x(),
- 1.0 / effect_node->sublayer_scale.y());
+ ConcatInverseSublayerScale(effect_node, &render_surface_transform);
+#if DCHECK_IS_ON()
+ VerifySublayerScalesMatch(effect_node->id, transform_node->id, effect_tree,
+ transform_tree);
+#endif
render_surface->SetDrawTransform(render_surface_transform);
}
@@ -1261,8 +1287,9 @@ static void SetSurfaceClipRect(const ClipNode* parent_clip_node,
// We don't have to apply sublayer scale when target is root.
if (transform_tree.TargetId(transform_node->id) != 0) {
- PostConcatSublayerScale(render_surface->EffectTreeIndex(), effect_tree,
- &clip_parent_target_to_target);
+ const EffectNode* effect_node =
+ effect_tree.Node(render_surface->EffectTreeIndex());
+ PostConcatSublayerScale(effect_node, &clip_parent_target_to_target);
#if DCHECK_IS_ON()
VerifySublayerScalesMatch(render_surface->EffectTreeIndex(),
transform_tree.TargetId(transform_node->id),
@@ -1348,8 +1375,8 @@ static gfx::Transform ReplicaToSurfaceTransform(
const LayerImpl* replica_layer = render_surface->ReplicaLayer();
const TransformNode* surface_transform_node =
tree.Node(render_surface->TransformTreeIndex());
- replica_to_surface.Scale(surface_transform_node->sublayer_scale.x(),
- surface_transform_node->sublayer_scale.y());
+ replica_to_surface.Scale(surface_transform_node->surface_contents_scale.x(),
+ surface_transform_node->surface_contents_scale.y());
replica_to_surface.Translate(replica_layer->offset_to_transform_parent().x(),
replica_layer->offset_to_transform_parent().y());
gfx::Transform replica_transform_node_to_surface;
@@ -1357,10 +1384,11 @@ static gfx::Transform ReplicaToSurfaceTransform(
render_surface->TransformTreeIndex(),
&replica_transform_node_to_surface);
replica_to_surface.PreconcatTransform(replica_transform_node_to_surface);
- if (surface_transform_node->sublayer_scale.x() != 0 &&
- surface_transform_node->sublayer_scale.y() != 0) {
- replica_to_surface.Scale(1.0 / surface_transform_node->sublayer_scale.x(),
- 1.0 / surface_transform_node->sublayer_scale.y());
+ if (surface_transform_node->surface_contents_scale.x() != 0 &&
+ surface_transform_node->surface_contents_scale.y() != 0) {
+ replica_to_surface.Scale(
+ 1.0 / surface_transform_node->surface_contents_scale.x(),
+ 1.0 / surface_transform_node->surface_contents_scale.y());
}
return replica_to_surface;
}

Powered by Google App Engine
This is Rietveld 408576698