summaryrefslogtreecommitdiffstats
path: root/gfx
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-21 19:48:32 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-21 19:48:32 +0000
commit0539e6bcb121262b0baebf63628b8968bf893a6d (patch)
treeb579cfe529410604b7b3faadc4390deac02c02df /gfx
parent1f18184a07252103a8cd9652d64de749f41ef09f (diff)
downloadchromium_src-0539e6bcb121262b0baebf63628b8968bf893a6d.zip
chromium_src-0539e6bcb121262b0baebf63628b8968bf893a6d.tar.gz
chromium_src-0539e6bcb121262b0baebf63628b8968bf893a6d.tar.bz2
Fix transforms to be preconcat like skia so multiple transforms are accumulated with each call to TranslateInt/ScaleInt.
BUG=none TEST=see unittest Review URL: http://codereview.chromium.org/3025010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53232 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gfx')
-rw-r--r--gfx/canvas_direct2d.cc18
-rw-r--r--gfx/canvas_direct2d_unittest.cc21
2 files changed, 35 insertions, 4 deletions
diff --git a/gfx/canvas_direct2d.cc b/gfx/canvas_direct2d.cc
index e69de1d..b187455 100644
--- a/gfx/canvas_direct2d.cc
+++ b/gfx/canvas_direct2d.cc
@@ -117,13 +117,23 @@ bool CanvasDirect2D::ClipRectInt(int x, int y, int w, int h) {
}
void CanvasDirect2D::TranslateInt(int x, int y) {
- rt_->SetTransform(D2D1::Matrix3x2F::Translation(static_cast<float>(x),
- static_cast<float>(y)));
+ D2D1_MATRIX_3X2_F raw;
+ rt_->GetTransform(&raw);
+ D2D1::Matrix3x2F transform(raw._11, raw._12, raw._21, raw._22, raw._31,
+ raw._32);
+ transform = D2D1::Matrix3x2F::Translation(static_cast<float>(x),
+ static_cast<float>(y)) * transform;
+ rt_->SetTransform(transform);
}
void CanvasDirect2D::ScaleInt(int x, int y) {
- rt_->SetTransform(D2D1::Matrix3x2F::Scale(static_cast<float>(x),
- static_cast<float>(y)));
+ D2D1_MATRIX_3X2_F raw;
+ rt_->GetTransform(&raw);
+ D2D1::Matrix3x2F transform(raw._11, raw._12, raw._21, raw._22, raw._31,
+ raw._32);
+ transform = D2D1::Matrix3x2F::Scale(static_cast<float>(x),
+ static_cast<float>(y)) * transform;
+ rt_->SetTransform(transform);
}
void CanvasDirect2D::FillRectInt(int x, int y, int w, int h,
diff --git a/gfx/canvas_direct2d_unittest.cc b/gfx/canvas_direct2d_unittest.cc
index 7e2c734..541e3f0 100644
--- a/gfx/canvas_direct2d_unittest.cc
+++ b/gfx/canvas_direct2d_unittest.cc
@@ -181,3 +181,24 @@ TEST(CanvasDirect2D, ClipRectWithTranslate) {
canvas.FillRectInt(SK_ColorRED, 0, 0, 500, 500);
canvas.Restore();
}
+
+TEST(CanvasDirect2D, ClipRectWithScale) {
+ TestWindow window;
+ gfx::CanvasDirect2D canvas(window.rt());
+
+ // Repeat the same rendering as in ClipRect...
+ canvas.Save();
+ canvas.FillRectInt(SK_ColorGREEN, 0, 0, 500, 500);
+ canvas.ClipRectInt(20, 20, 120, 120);
+ canvas.FillRectInt(SK_ColorBLUE, 0, 0, 500, 500);
+ canvas.Restore();
+
+ // ... then translate and scale, clip and fill again relative to the new
+ // origin.
+ canvas.Save();
+ canvas.TranslateInt(150, 150);
+ canvas.ScaleInt(2, 2);
+ canvas.ClipRectInt(10, 10, 110, 110);
+ canvas.FillRectInt(SK_ColorRED, 0, 0, 500, 500);
+ canvas.Restore();
+}