Commit 5ba48720 authored by yuweih's avatar yuweih Committed by Commit bot

[Remoting Client] Fix scaling bug in ViewMatrix

I've forgot to scale the old offset before adding the offset adjustment :P
This CL fixes that bug and adds a test case to guard that pivot point remains
fixed after scaling.

BUG=714193

Review-Url: https://codereview.chromium.org/2857113002
Cr-Commit-Position: refs/heads/master@{#469047}
parent bb924e18
......@@ -28,6 +28,8 @@ class DesktopViewportTest : public testing::Test {
float offset_x,
float offset_y);
ViewMatrix ReleaseReceivedTransformation();
DesktopViewport viewport_;
private:
......@@ -74,6 +76,13 @@ void DesktopViewportTest::AssertTransformationReceived(
received_transformation_ = ViewMatrix();
}
ViewMatrix DesktopViewportTest::ReleaseReceivedTransformation() {
EXPECT_FALSE(received_transformation_.IsEmpty());
ViewMatrix out = received_transformation_;
received_transformation_ = ViewMatrix();
return out;
}
void DesktopViewportTest::OnTransformationChanged(const ViewMatrix& matrix) {
ASSERT_TRUE(received_transformation_.IsEmpty())
<< "Previous matrix has not been asserted.";
......@@ -251,4 +260,36 @@ TEST_F(DesktopViewportTest, TestSetViewportCenter) {
AssertTransformationReceived(FROM_HERE, 1.25f, -8.f, -4.5f);
}
TEST_F(DesktopViewportTest, TestScaleDesktop) {
// Number in surface coordinate.
//
// +====+------+
// | VP | DP |
// | | | 3
// +====+------+
// 4
viewport_.SetDesktopSize(8, 6);
viewport_.SetSurfaceSize(2, 3);
AssertTransformationReceived(FROM_HERE, 0.5f, 0.f, 0.f);
ViewMatrix old_transformation(0.5f, {0.f, 0.f});
ViewMatrix::Point surface_point = old_transformation.MapPoint({1.2f, 1.3f});
// Scale a little bit at a pivot point.
viewport_.ScaleDesktop(surface_point.x, surface_point.y, 1.1f);
ViewMatrix new_transformation = ReleaseReceivedTransformation();
// Verify the pivot point is fixed.
ViewMatrix::Point new_surface_point =
new_transformation.MapPoint({1.2f, 1.3f});
ASSERT_FLOAT_EQ(surface_point.x, new_surface_point.x);
ASSERT_FLOAT_EQ(surface_point.y, new_surface_point.y);
// Verify the scale is correct.
ASSERT_FLOAT_EQ(old_transformation.GetScale() * 1.1f,
new_transformation.GetScale());
}
} // namespace remoting
......@@ -35,7 +35,9 @@ float ViewMatrix::GetScale() const {
void ViewMatrix::PostScale(const Point& pivot, float scale) {
scale_ *= scale;
offset_.x *= scale;
offset_.x += (1.f - scale) * pivot.x;
offset_.y *= scale;
offset_.y += (1.f - scale) * pivot.y;
}
......
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