diff options
author | aelias@chromium.org <aelias@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-31 14:00:56 +0000 |
---|---|---|
committer | aelias@chromium.org <aelias@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-31 14:00:56 +0000 |
commit | 5f088535013d0cf033ecea30883ce80b5d3f3a3c (patch) | |
tree | 4c45e9f8bcba01631069074970240ae53c055f15 /cc/base/math_util.cc | |
parent | be411ddee1b212652934e5d3495612911736fd4b (diff) | |
download | chromium_src-5f088535013d0cf033ecea30883ce80b5d3f3a3c.zip chromium_src-5f088535013d0cf033ecea30883ce80b5d3f3a3c.tar.gz chromium_src-5f088535013d0cf033ecea30883ce80b5d3f3a3c.tar.bz2 |
Use Skia's mapMScalars() for mapping homogeneous points.
Skia provides a point mapping method, so we don't need to roll
our own. This deletes some unnecessary code and with any luck compiles
to faster code.
NOTRY=true
BUG=none
Review URL: https://chromiumcodereview.appspot.com/21161004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@214719 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/base/math_util.cc')
-rw-r--r-- | cc/base/math_util.cc | 85 |
1 files changed, 23 insertions, 62 deletions
diff --git a/cc/base/math_util.cc b/cc/base/math_util.cc index 5443956..39a183e 100644 --- a/cc/base/math_util.cc +++ b/cc/base/math_util.cc @@ -29,63 +29,24 @@ static HomogeneousCoordinate ProjectHomogeneousPoint( // happens when the layer is rotated so that it is infinitesimally thin, or // when it is co-planar with the camera origin -- i.e. when the layer is // invisible anyway. - if (!transform.matrix().getDouble(2, 2)) + if (!transform.matrix().get(2, 2)) return HomogeneousCoordinate(0.0, 0.0, 0.0, 1.0); - double x = p.x(); - double y = p.y(); - double z = -(transform.matrix().getDouble(2, 0) * x + - transform.matrix().getDouble(2, 1) * y + - transform.matrix().getDouble(2, 3)) / - transform.matrix().getDouble(2, 2); - // implicit definition of w = 1; - - double out_x = x * transform.matrix().getDouble(0, 0) + - y * transform.matrix().getDouble(0, 1) + - z * transform.matrix().getDouble(0, 2) + - transform.matrix().getDouble(0, 3); - double out_y = x * transform.matrix().getDouble(1, 0) + - y * transform.matrix().getDouble(1, 1) + - z * transform.matrix().getDouble(1, 2) + - transform.matrix().getDouble(1, 3); - double out_z = x * transform.matrix().getDouble(2, 0) + - y * transform.matrix().getDouble(2, 1) + - z * transform.matrix().getDouble(2, 2) + - transform.matrix().getDouble(2, 3); - double out_w = x * transform.matrix().getDouble(3, 0) + - y * transform.matrix().getDouble(3, 1) + - z * transform.matrix().getDouble(3, 2) + - transform.matrix().getDouble(3, 3); - - return HomogeneousCoordinate(out_x, out_y, out_z, out_w); + SkMScalar z = -(transform.matrix().get(2, 0) * p.x() + + transform.matrix().get(2, 1) * p.y() + + transform.matrix().get(2, 3)) / + transform.matrix().get(2, 2); + HomogeneousCoordinate result(p.x(), p.y(), z, 1.0); + transform.matrix().mapMScalars(result.vec, result.vec); + return result; } static HomogeneousCoordinate MapHomogeneousPoint( const gfx::Transform& transform, const gfx::Point3F& p) { - double x = p.x(); - double y = p.y(); - double z = p.z(); - // implicit definition of w = 1; - - double out_x = x * transform.matrix().getDouble(0, 0) + - y * transform.matrix().getDouble(0, 1) + - z * transform.matrix().getDouble(0, 2) + - transform.matrix().getDouble(0, 3); - double out_y = x * transform.matrix().getDouble(1, 0) + - y * transform.matrix().getDouble(1, 1) + - z * transform.matrix().getDouble(1, 2) + - transform.matrix().getDouble(1, 3); - double out_z = x * transform.matrix().getDouble(2, 0) + - y * transform.matrix().getDouble(2, 1) + - z * transform.matrix().getDouble(2, 2) + - transform.matrix().getDouble(2, 3); - double out_w = x * transform.matrix().getDouble(3, 0) + - y * transform.matrix().getDouble(3, 1) + - z * transform.matrix().getDouble(3, 2) + - transform.matrix().getDouble(3, 3); - - return HomogeneousCoordinate(out_x, out_y, out_z, out_w); + HomogeneousCoordinate result(p.x(), p.y(), p.z(), 1.0); + transform.matrix().mapMScalars(result.vec, result.vec); + return result; } static HomogeneousCoordinate ComputeClippedPointForEdge( @@ -106,18 +67,18 @@ static HomogeneousCoordinate ComputeClippedPointForEdge( // Technically this is a special case of the following assertion, but its a // good idea to keep it an explicit sanity check here. - DCHECK_NE(h2.w, h1.w); + DCHECK_NE(h2.w(), h1.w()); // Exactly one of h1 or h2 (but not both) must be on the negative side of the // w plane when this is called. DCHECK(h1.ShouldBeClipped() ^ h2.ShouldBeClipped()); - double w = 0.00001; // or any positive non-zero small epsilon + SkMScalar w = 0.00001; // or any positive non-zero small epsilon - double t = (w - h1.w) / (h2.w - h1.w); + SkMScalar t = (w - h1.w()) / (h2.w() - h1.w()); - double x = (1 - t) * h1.x + t * h2.x; - double y = (1 - t) * h1.y + t * h2.y; - double z = (1 - t) * h1.z + t * h2.z; + SkMScalar x = (1 - t) * h1.x() + t * h2.x(); + SkMScalar y = (1 - t) * h1.y() + t * h2.y(); + SkMScalar z = (1 - t) * h1.z() + t * h2.z(); return HomogeneousCoordinate(x, y, z, w); } @@ -400,7 +361,7 @@ gfx::PointF MathUtil::MapPoint(const gfx::Transform& transform, bool* clipped) { HomogeneousCoordinate h = MapHomogeneousPoint(transform, gfx::Point3F(p)); - if (h.w > 0) { + if (h.w() > 0) { *clipped = false; return h.CartesianPoint2d(); } @@ -409,7 +370,7 @@ gfx::PointF MathUtil::MapPoint(const gfx::Transform& transform, *clipped = true; // Avoid dividing by w if w == 0. - if (!h.w) + if (!h.w()) return gfx::PointF(); // This return value will be invalid because clipped == true, but (1) users of @@ -424,7 +385,7 @@ gfx::Point3F MathUtil::MapPoint(const gfx::Transform& transform, bool* clipped) { HomogeneousCoordinate h = MapHomogeneousPoint(transform, p); - if (h.w > 0) { + if (h.w() > 0) { *clipped = false; return h.CartesianPoint3d(); } @@ -433,7 +394,7 @@ gfx::Point3F MathUtil::MapPoint(const gfx::Transform& transform, *clipped = true; // Avoid dividing by w if w == 0. - if (!h.w) + if (!h.w()) return gfx::Point3F(); // This return value will be invalid because clipped == true, but (1) users of @@ -465,7 +426,7 @@ gfx::PointF MathUtil::ProjectPoint(const gfx::Transform& transform, bool* clipped) { HomogeneousCoordinate h = ProjectHomogeneousPoint(transform, p); - if (h.w > 0) { + if (h.w() > 0) { // The cartesian coordinates will be valid in this case. *clipped = false; return h.CartesianPoint2d(); @@ -475,7 +436,7 @@ gfx::PointF MathUtil::ProjectPoint(const gfx::Transform& transform, *clipped = true; // Avoid dividing by w if w == 0. - if (!h.w) + if (!h.w()) return gfx::PointF(); // This return value will be invalid because clipped == true, but (1) users of |