Chromium Code Reviews| Index: cc/base/math_util.cc |
| diff --git a/cc/base/math_util.cc b/cc/base/math_util.cc |
| index 7f6178dc60de5ec3b5c7b5a99b34200944693087..e4088b2386cfc2f85f3439a19d37c79296273dd9 100644 |
| --- a/cc/base/math_util.cc |
| +++ b/cc/base/math_util.cc |
| @@ -130,6 +130,57 @@ gfx::Rect MathUtil::MapEnclosingClippedRect(const gfx::Transform& transform, |
| return gfx::ToEnclosingRect(MapClippedRect(transform, gfx::RectF(src_rect))); |
| } |
| +gfx::Rect MathUtil::MapEnclosedClippedRect(const gfx::Transform& transform, |
| + const gfx::Rect& src_rect) { |
| + if (transform.IsIdentityOrIntegerTranslation()) { |
| + return src_rect + |
| + gfx::Vector2d( |
| + static_cast<int>(SkMScalarToFloat(transform.matrix().get(0, 3))), |
| + static_cast<int>( |
| + SkMScalarToFloat(transform.matrix().get(1, 3)))); |
| + } |
| + return gfx::ToEnclosedRect(MapClippedRect(transform, gfx::RectF(src_rect))); |
| +} |
| + |
| +gfx::Rect MathUtil::MapEnclosedNonClippedRect(const gfx::Transform& transform, |
| + const gfx::Rect& src_rect) { |
| + if (transform.IsIdentityOrIntegerTranslation()) { |
| + return src_rect + |
| + gfx::Vector2d( |
| + static_cast<int>(SkMScalarToFloat(transform.matrix().get(0, 3))), |
| + static_cast<int>( |
| + SkMScalarToFloat(transform.matrix().get(1, 3)))); |
| + } |
| + |
| + SkMScalar quad[4 * 2]; // input: 4 x 2D points |
| + quad[0] = src_rect.x(); |
| + quad[1] = src_rect.y(); |
| + quad[2] = src_rect.right(); |
| + quad[3] = src_rect.y(); |
| + quad[4] = src_rect.right(); |
| + quad[5] = src_rect.bottom(); |
| + quad[6] = src_rect.x(); |
| + quad[7] = src_rect.bottom(); |
| + |
| + SkMScalar result[4 * 4]; // output: 4 x 4D homogeneous points |
| + transform.matrix().map2(quad, 4, result); |
| + |
| + HomogeneousCoordinate hc0(result[0], result[1], result[2], result[3]); |
| + HomogeneousCoordinate hc1(result[4], result[5], result[6], result[7]); |
| + HomogeneousCoordinate hc2(result[8], result[9], result[10], result[11]); |
| + HomogeneousCoordinate hc3(result[12], result[13], result[14], result[15]); |
| + DCHECK(!hc0.ShouldBeClipped()); |
| + DCHECK(!hc1.ShouldBeClipped()); |
| + DCHECK(!hc2.ShouldBeClipped()); |
| + DCHECK(!hc3.ShouldBeClipped()); |
| + |
| + gfx::QuadF mapped_quad = gfx::QuadF(hc0.CartesianPoint2d(), |
| + hc1.CartesianPoint2d(), |
| + hc2.CartesianPoint2d(), |
| + hc3.CartesianPoint2d()); |
| + return gfx::ToEnclosedRect(mapped_quad.BoundingBox()); |
| +} |
| + |
| gfx::RectF MathUtil::MapClippedRect(const gfx::Transform& transform, |
| const gfx::RectF& src_rect) { |
| if (transform.IsIdentityOrTranslation()) { |
| @@ -173,6 +224,48 @@ gfx::Rect MathUtil::ProjectEnclosingClippedRect(const gfx::Transform& transform, |
| ProjectClippedRect(transform, gfx::RectF(src_rect))); |
| } |
| +gfx::Rect MathUtil::ProjectEnclosedClippedRect(const gfx::Transform& transform, |
| + const gfx::Rect& src_rect) { |
| + if (transform.IsIdentityOrIntegerTranslation()) { |
| + return src_rect + |
| + gfx::Vector2d( |
| + static_cast<int>(SkMScalarToFloat(transform.matrix().get(0, 3))), |
| + static_cast<int>( |
| + SkMScalarToFloat(transform.matrix().get(1, 3)))); |
| + } |
| + return gfx::ToEnclosedRect( |
| + ProjectClippedRect(transform, gfx::RectF(src_rect))); |
| +} |
| + |
| +gfx::Rect MathUtil::ProjectEnclosedNonClippedRect( |
| + const gfx::Transform& transform, |
| + const gfx::Rect& src_rect) { |
| + if (transform.IsIdentityOrIntegerTranslation()) { |
| + return src_rect + |
| + gfx::Vector2d( |
| + static_cast<int>(SkMScalarToFloat(transform.matrix().get(0, 3))), |
| + static_cast<int>( |
| + SkMScalarToFloat(transform.matrix().get(1, 3)))); |
| + } |
| + |
| + // Perform the projection, but retain the result in homogeneous coordinates. |
| + gfx::QuadF q = gfx::QuadF(src_rect); |
| + HomogeneousCoordinate hc0 = ProjectHomogeneousPoint(transform, q.p1()); |
| + HomogeneousCoordinate hc1 = ProjectHomogeneousPoint(transform, q.p2()); |
| + HomogeneousCoordinate hc2 = ProjectHomogeneousPoint(transform, q.p3()); |
| + HomogeneousCoordinate hc3 = ProjectHomogeneousPoint(transform, q.p4()); |
| + DCHECK(!hc0.ShouldBeClipped()); |
| + DCHECK(!hc1.ShouldBeClipped()); |
| + DCHECK(!hc2.ShouldBeClipped()); |
| + DCHECK(!hc3.ShouldBeClipped()); |
| + |
| + gfx::QuadF projected_quad = gfx::QuadF(hc0.CartesianPoint2d(), |
| + hc1.CartesianPoint2d(), |
| + hc2.CartesianPoint2d(), |
| + hc3.CartesianPoint2d()); |
| + return gfx::ToEnclosedRect(projected_quad.BoundingBox()); |
|
enne (OOO)
2014/08/21 17:54:05
This code was here before, but is this actually ri
danakj
2014/08/21 17:58:08
Ya, good point. I had this thought about everythin
|
| +} |
| + |
| gfx::RectF MathUtil::ProjectClippedRect(const gfx::Transform& transform, |
| const gfx::RectF& src_rect) { |
| if (transform.IsIdentityOrTranslation()) { |