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

TransformPaintPropertyNode::MatrixWithOriginApplied()

It returns the matrix with transform origin applied. Useful where we
want to get whole matrix that this transform node will apply.

Also fix a bug in CullRect::ApplyTransforms() where we missed the
origin.

Change-Id: If671470a5c9ea0e8a46e128692862bb0779d005f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1757081Reviewed-by: default avatarvmpstr <vmpstr@chromium.org>
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688609}
parent 708a3b80
......@@ -58,7 +58,7 @@ static void MapRect(const TransformPaintPropertyNode& transform,
float_rect.Move(-transform.Translation2D());
rect = EnclosingIntRect(float_rect);
} else {
rect = transform.Matrix().Inverse().MapRect(rect);
rect = transform.MatrixWithOriginApplied().Inverse().MapRect(rect);
}
}
......
......@@ -289,6 +289,16 @@ TEST_F(CullRectTest, ApplyTransformsSingleScrollWholeScrollingContents) {
EXPECT_EQ(IntRect(-3970, -3975, 8040, 8050), cull_rect3.Rect());
}
TEST_F(CullRectTest, ApplyTransformsWithOrigin) {
ScopedCompositeAfterPaintForTest cap(true);
auto t1 = CreateTransform(t0(), TransformationMatrix().Translate(1, 2));
auto t2 = CreateTransform(*t1, TransformationMatrix().Scale(0.5),
FloatPoint3D(50, 100, 0));
CullRect cull_rect1(IntRect(0, 0, 50, 200));
cull_rect1.ApplyTransforms(*t1, *t2, base::nullopt);
EXPECT_EQ(IntRect(-50, -100, 100, 400), cull_rect1.Rect());
}
TEST_F(CullRectTest, ApplyTransformsSingleScrollPartialScrollingContents) {
ScopedCompositeAfterPaintForTest cap(true);
auto t1 = CreateTransform(t0(), TransformationMatrix().Translate(1, 2));
......
......@@ -70,9 +70,7 @@ void GeometryMapperTransformCache::Update(
root_of_2d_translation_ = &node;
to_2d_translation_root_ = FloatSize();
TransformationMatrix local = node.Matrix();
local.ApplyTransformOrigin(node.Origin());
TransformationMatrix local = node.MatrixWithOriginApplied();
bool is_plane_root = !local.IsFlat() || !local.IsInvertible();
if (is_plane_root && root_of_2d_translation_ == &node) {
// We don't need plane root transform because the plane root is the same
......@@ -123,9 +121,7 @@ void GeometryMapperTransformCache::UpdateScreenTransform(
screen_transform_->to_screen.Translate(translation.Width(),
translation.Height());
} else {
TransformationMatrix local = node.Matrix();
local.ApplyTransformOrigin(node.Origin());
screen_transform_->to_screen.Multiply(local);
screen_transform_->to_screen.Multiply(node.MatrixWithOriginApplied());
}
auto to_screen_flattened = screen_transform_->to_screen;
......
......@@ -263,6 +263,9 @@ class PLATFORM_EXPORT TransformPaintPropertyNode
const TransformationMatrix& Matrix() const {
return state_.transform_and_origin.Matrix();
}
TransformationMatrix MatrixWithOriginApplied() const {
return TransformationMatrix(Matrix()).ApplyTransformOrigin(Origin());
}
// The slow version always return meaningful TransformationMatrix regardless
// of IsIdentityOr2DTranslation(). Should be used only in contexts that are
// not performance sensitive.
......
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