Commit d419df6e authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

[BGPT] Consider intermediate transform animation for 2d axis alignment

Previously we only consider the direct transform of an effect node
for 2d axis alignment, but some intermediate transform animation
can also affect that which should be considered.

Bug: 932719
Change-Id: If55c70cedad73dc14bcc14e0db373ed9a7fb2333
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1575171
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652796}
parent cce1116a
......@@ -3540,8 +3540,9 @@ TEST_P(PaintArtifactCompositorTest, OpacityRenderSurfacesWithBackdropChildren) {
}
TEST_P(PaintArtifactCompositorTest,
DirectCompositingReasonsCausesRenderSurface) {
// When an effect has an animated transform, we should get a render surface.
DirectTransformAnimationCausesRenderSurfaceFor2dAxisMisalignedClip) {
// When a clip is affected by an animated transform, we should get a render
// surface for the effect node.
auto t1 = CreateTransform(t0(), TransformationMatrix(), FloatPoint3D(),
CompositingReason::kActiveTransformAnimation);
auto e1 = CreateOpacityEffect(e0(), *t1, nullptr, 1.f);
......@@ -3558,6 +3559,27 @@ TEST_P(PaintArtifactCompositorTest,
EXPECT_TRUE(effect->has_render_surface);
}
TEST_P(PaintArtifactCompositorTest,
IndirectTransformAnimationCausesRenderSurfaceFor2dAxisMisalignedClip) {
// When a clip is affected by an animated transform, we should get a render
// surface for the effect node.
auto t1 = CreateTransform(t0(), TransformationMatrix(), FloatPoint3D(),
CompositingReason::kActiveTransformAnimation);
auto t2 = Create2DTranslation(*t1, 10, 20);
auto e1 = CreateOpacityEffect(e0(), *t2, nullptr, 1.f);
auto c1 = CreateClip(c0(), t0(), FloatRoundedRect(50, 50, 50, 50));
TestPaintArtifact artifact;
FloatRect r(150, 150, 100, 100);
artifact.Chunk(t0(), c0(), e0()).RectDrawing(r, Color::kWhite);
artifact.Chunk(t0(), *c1, *e1).RectDrawing(r, Color::kWhite);
Update(artifact.Build());
ASSERT_EQ(2u, ContentLayerCount());
const auto* effect = GetPropertyTrees().effect_tree.Node(
ContentLayerAt(1)->effect_tree_index());
EXPECT_TRUE(effect->has_render_surface);
}
TEST_P(PaintArtifactCompositorTest, OpacityIndirectlyAffectingTwoLayers) {
auto opacity = CreateOpacityEffect(e0(), 0.5f);
auto child_composited_effect =
......
......@@ -251,14 +251,32 @@ void PropertyTreeManager::SetupRootScrollNode() {
root_layer_->SetScrollTreeIndex(scroll_node.id);
}
static bool TransformsAre2dAxisAligned(const TransformPaintPropertyNode& a,
const TransformPaintPropertyNode& b) {
static bool TransformsToAncestorHaveActiveAnimation(
const TransformPaintPropertyNode& descendant,
const TransformPaintPropertyNode& ancestor) {
if (&descendant == &ancestor)
return false;
for (const auto* n = &descendant; n != &ancestor; n = n->Parent()) {
if (n->HasActiveTransformAnimation())
return true;
}
return false;
}
static bool TransformsMayBe2dAxisMisaligned(
const TransformPaintPropertyNode& a,
const TransformPaintPropertyNode& b) {
if (&a == &b)
return true;
return false;
const auto& translation_2d_or_matrix =
GeometryMapper::SourceToDestinationProjection(a, b);
return translation_2d_or_matrix.IsIdentityOr2DTranslation() ||
translation_2d_or_matrix.Matrix().Preserves2dAxisAlignment();
if (!translation_2d_or_matrix.IsIdentityOr2DTranslation() &&
!translation_2d_or_matrix.Matrix().Preserves2dAxisAlignment())
return true;
// Assume any animation can cause 2d axis misalignment.
const auto& lca = LowestCommonAncestor(a, b);
return TransformsToAncestorHaveActiveAnimation(a, lca) ||
TransformsToAncestorHaveActiveAnimation(b, lca);
}
void PropertyTreeManager::SetCurrentEffectState(
......@@ -280,9 +298,8 @@ void PropertyTreeManager::SetCurrentEffectState(
} else if (previous_transform &&
!current_.may_be_2d_axis_misaligned_to_render_surface) {
current_.may_be_2d_axis_misaligned_to_render_surface =
!TransformsAre2dAxisAligned(current_.Transform(),
*previous_transform) ||
current_.Transform().Unalias().HasActiveTransformAnimation();
TransformsMayBe2dAxisMisaligned(*previous_transform,
current_.Transform());
}
}
......@@ -686,8 +703,8 @@ PropertyTreeManager::NeedsSyntheticEffect(
// Cc requires that a rectangluar clip is 2d-axis-aligned with the render
// surface to correctly apply the clip.
if (current_.may_be_2d_axis_misaligned_to_render_surface ||
!TransformsAre2dAxisAligned(clip.LocalTransformSpace(),
current_.Transform()))
TransformsMayBe2dAxisMisaligned(clip.LocalTransformSpace(),
current_.Transform()))
return CcEffectType::kSyntheticFor2dAxisAlignment;
return base::nullopt;
......
......@@ -336,7 +336,7 @@ class PLATFORM_EXPORT TransformPaintPropertyNode
CompositingReason::kComboActiveAnimation;
}
bool HasActiveTransformAnimation() const {
return DirectCompositingReasons() &
return state_.direct_compositing_reasons &
CompositingReason::kActiveTransformAnimation;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment