Bug 952977: Remove gfxPointH3D r=nical
authorDavid Zbarsky <dzbarsky@gmail.com>
Fri, 29 Aug 2014 14:47:30 -0400
changeset 224125 8430feba614862cabbbaf26c2ffe4a294317102f
parent 224124 2123851421e66b93cf312045a0d2fc9f762eb569
child 224126 b3f0f2be0ab6459b729122405e8d9d14c4f323af
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical
bugs952977
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 952977: Remove gfxPointH3D r=nical
gfx/2d/Matrix.h
gfx/layers/apz/src/APZCTreeManager.cpp
gfx/layers/apz/src/APZCTreeManager.h
gfx/thebes/gfx3DMatrix.cpp
gfx/thebes/gfx3DMatrix.h
gfx/thebes/gfxPointH3D.h
gfx/thebes/gfxQuaternion.h
gfx/thebes/moz.build
layout/base/nsDisplayList.cpp
layout/style/StyleAnimationValue.cpp
--- a/gfx/2d/Matrix.h
+++ b/gfx/2d/Matrix.h
@@ -306,16 +306,27 @@ public:
     , _41(0.0f), _42(0.0f), _43(0.0f), _44(1.0f)
   {}
 
   Float _11, _12, _13, _14;
   Float _21, _22, _23, _24;
   Float _31, _32, _33, _34;
   Float _41, _42, _43, _44;
 
+  Point4D& operator[](int aIndex)
+  {
+      MOZ_ASSERT(aIndex >= 0 && aIndex <= 3, "Invalid matrix array index");
+      return *reinterpret_cast<Point4D*>((&_11)+4*aIndex);
+  }
+  const Point4D& operator[](int aIndex) const
+  {
+      MOZ_ASSERT(aIndex >= 0 && aIndex <= 3, "Invalid matrix array index");
+      return *reinterpret_cast<const Point4D*>((&_11)+4*aIndex);
+  }
+
   /**
    * Returns true if the matrix is isomorphic to a 2D affine transformation.
    */
   bool Is2D() const
   {
     if (_13 != 0.0f || _14 != 0.0f ||
         _23 != 0.0f || _24 != 0.0f ||
         _31 != 0.0f || _32 != 0.0f || _33 != 1.0f || _34 != 0.0f ||
@@ -399,16 +410,26 @@ public:
     return matrix;
   }
 
   bool Is2DIntegerTranslation() const
   {
     return Is2D() && As2D().IsIntegerTranslation();
   }
 
+  Point4D TransposeTransform4D(const Point4D& aPoint) const
+  {
+      Float x = aPoint.x * _11 + aPoint.y * _12 + aPoint.z * _13 + aPoint.w * _14;
+      Float y = aPoint.x * _21 + aPoint.y * _22 + aPoint.z * _23 + aPoint.w * _24;
+      Float z = aPoint.x * _31 + aPoint.y * _32 + aPoint.z * _33 + aPoint.w * _34;
+      Float w = aPoint.x * _41 + aPoint.y * _42 + aPoint.z * _43 + aPoint.w * _44;
+
+      return Point4D(x, y, z, w);
+  }
+
   Point4D operator *(const Point4D& aPoint) const
   {
     Point4D retPoint;
 
     retPoint.x = aPoint.x * _11 + aPoint.y * _21 + aPoint.z * _31 + _41;
     retPoint.y = aPoint.x * _12 + aPoint.y * _22 + aPoint.z * _32 + _42;
     retPoint.z = aPoint.x * _13 + aPoint.y * _23 + aPoint.z * _33 + _43;
     retPoint.w = aPoint.x * _14 + aPoint.y * _24 + aPoint.z * _34 + _44;
@@ -480,16 +501,31 @@ public:
     _13 += _14 * aZ;
     _23 += _24 * aZ;
     _33 += _34 * aZ;
     _43 += _44 * aZ;
 
     return *this;
   }
 
+  void SkewXY(Float aSkew)
+  {
+    (*this)[1] += (*this)[0] * aSkew;
+  }
+
+  void SkewXZ(Float aSkew)
+  {
+      (*this)[2] += (*this)[0] * aSkew;
+  }
+
+  void SkewYZ(Float aSkew)
+  {
+      (*this)[2] += (*this)[1] * aSkew;
+  }
+
   Matrix4x4 &ChangeBasis(Float aX, Float aY, Float aZ)
   {
     // Translate to the origin before applying this matrix
     Translate(-aX, -aY, -aZ);
 
     // Translate back into position after applying this matrix
     PostTranslate(aX, aY, aZ);
 
@@ -580,16 +616,25 @@ public:
          + _13 * _21 * _32 * _44
          - _11 * _23 * _32 * _44
          - _12 * _21 * _33 * _44
          + _11 * _22 * _33 * _44;
   }
 
   bool Invert();
 
+  void Normalize()
+  {
+      for (int i = 0; i < 4; i++) {
+          for (int j = 0; j < 4; j++) {
+              (*this)[i][j] /= (*this)[3][3];
+         }
+      }
+  }
+
   void ScalePost(Float aX, Float aY, Float aZ)
   {
     _11 *= aX;
     _21 *= aX;
     _31 *= aX;
     _41 *= aX;
 
     _12 *= aY;
@@ -659,16 +704,31 @@ public:
     NudgeToInteger(&_33, error);
     NudgeToInteger(&_34, error);
     NudgeToInteger(&_41, error);
     NudgeToInteger(&_42, error);
     NudgeToInteger(&_43, error);
     NudgeToInteger(&_44, error);
   }
 
+  Point4D TransposedVector(int aIndex) const
+  {
+      MOZ_ASSERT(aIndex >= 0 && aIndex <= 3, "Invalid matrix array index");
+      return Point4D(*((&_11)+aIndex), *((&_21)+aIndex), *((&_31)+aIndex), *((&_41)+aIndex));
+  }
+
+  void SetTransposedVector(int aIndex, Point4D &aVector)
+  {
+      MOZ_ASSERT(aIndex >= 0 && aIndex <= 3, "Invalid matrix array index");
+      *((&_11)+aIndex) = aVector.x;
+      *((&_21)+aIndex) = aVector.y;
+      *((&_31)+aIndex) = aVector.z;
+      *((&_41)+aIndex) = aVector.w;
+  }
+
   // Set all the members of the matrix to NaN
   void SetNAN();
 };
 
 class Matrix5x4
 {
 public:
   Matrix5x4()
--- a/gfx/layers/apz/src/APZCTreeManager.cpp
+++ b/gfx/layers/apz/src/APZCTreeManager.cpp
@@ -28,16 +28,17 @@
 
 #define APZCTM_LOG(...)
 // #define APZCTM_LOG(...) printf_stderr("APZCTM: " __VA_ARGS__)
 
 namespace mozilla {
 namespace layers {
 
 typedef mozilla::gfx::Point Point;
+typedef mozilla::gfx::Point4D Point4D;
 typedef mozilla::gfx::Matrix4x4 Matrix4x4;
 
 float APZCTreeManager::sDPI = 160.0;
 
 struct APZCTreeManager::TreeBuildingState {
   TreeBuildingState(CompositorParent* aCompositor,
                     bool aIsFirstPaint, uint64_t aOriginatingLayersId,
                     APZTestData* aTestData, uint32_t aPaintSequence)
@@ -991,20 +992,19 @@ APZCTreeManager::GetTargetAPZC(const Scr
 }
 
 already_AddRefed<AsyncPanZoomController>
 APZCTreeManager::GetTargetAPZC(const ScreenPoint& aPoint, bool* aOutInOverscrolledApzc)
 {
   MonitorAutoLock lock(mTreeLock);
   nsRefPtr<AsyncPanZoomController> target;
   // The root may have siblings, so check those too
-  gfxPoint point(aPoint.x, aPoint.y);
   bool inOverscrolledApzc = false;
   for (AsyncPanZoomController* apzc = mRootApzc; apzc; apzc = apzc->GetPrevSibling()) {
-    target = GetAPZCAtPoint(apzc, point, &inOverscrolledApzc);
+    target = GetAPZCAtPoint(apzc, aPoint.ToUnknownPoint(), &inOverscrolledApzc);
     // If we hit an overscrolled APZC, 'target' will be nullptr but it's still
     // a hit so we don't search further siblings.
     if (target || inOverscrolledApzc) {
       break;
     }
   }
   // If we are in an overscrolled APZC, we should be returning nullptr.
   MOZ_ASSERT(!(target && inOverscrolledApzc));
@@ -1124,17 +1124,17 @@ APZCTreeManager::FindTargetAPZC(AsyncPan
   if (aApzc->Matches(aGuid)) {
     return aApzc;
   }
   return nullptr;
 }
 
 AsyncPanZoomController*
 APZCTreeManager::GetAPZCAtPoint(AsyncPanZoomController* aApzc,
-                                const gfxPoint& aHitTestPoint,
+                                const Point& aHitTestPoint,
                                 bool* aOutInOverscrolledApzc)
 {
   mTreeLock.AssertCurrentThreadOwns();
 
   // The comments below assume there is a chain of layers L..R with L and P having APZC instances as
   // explained in the comment on GetInputTransforms. This function will recurse with aApzc at L and P, and the
   // comments explain what values are stored in the variables at these two levels. All the comments
   // use standard matrix notation where the leftmost matrix in a multiplication is applied first.
@@ -1144,29 +1144,29 @@ APZCTreeManager::GetAPZCAtPoint(AsyncPan
   // It is PC.Inverse() * OC.Inverse() * NC.Inverse() * MC.Inverse() at recursion level for L,
   //   and RC.Inverse() * QC.Inverse()                               at recursion level for P.
   Matrix4x4 ancestorUntransform = aApzc->GetAncestorTransform();
   ancestorUntransform.Invert();
 
   // Hit testing for this layer takes place in our parent layer coordinates,
   // since the composition bounds (used to initialize the visible rect against
   // which we hit test are in those coordinates).
-  gfxPointH3D hitTestPointForThisLayer = To3DMatrix(ancestorUntransform).ProjectPoint(aHitTestPoint);
+  Point4D hitTestPointForThisLayer = ancestorUntransform.ProjectPoint(aHitTestPoint);
   APZCTM_LOG("Untransformed %f %f to transient coordinates %f %f for hit-testing APZC %p\n",
            aHitTestPoint.x, aHitTestPoint.y,
            hitTestPointForThisLayer.x, hitTestPointForThisLayer.y, aApzc);
 
   // childUntransform takes points from aApzc's parent APZC's CSS-transformed layer coordinates
   // to aApzc's CSS-transformed layer coordinates.
   // It is PC.Inverse() * OC.Inverse() * NC.Inverse() * MC.Inverse() * LA.Inverse() at L
   //   and RC.Inverse() * QC.Inverse() * PA.Inverse()                               at P.
   Matrix4x4 asyncUntransform = aApzc->GetCurrentAsyncTransform();
   asyncUntransform.Invert();
   Matrix4x4 childUntransform = ancestorUntransform * asyncUntransform;
-  gfxPointH3D hitTestPointForChildLayers = To3DMatrix(childUntransform).ProjectPoint(aHitTestPoint);
+  Point4D hitTestPointForChildLayers = childUntransform.ProjectPoint(aHitTestPoint);
   APZCTM_LOG("Untransformed %f %f to layer coordinates %f %f for APZC %p\n",
            aHitTestPoint.x, aHitTestPoint.y,
            hitTestPointForChildLayers.x, hitTestPointForChildLayers.y, aApzc);
 
   AsyncPanZoomController* result = nullptr;
   // This walks the tree in depth-first, reverse order, so that it encounters
   // APZCs front-to-back on the screen.
   if (hitTestPointForChildLayers.HasPositiveWCoord()) {
@@ -1178,17 +1178,17 @@ APZCTreeManager::GetAPZCAtPoint(AsyncPan
       }
       if (match) {
         result = match;
         break;
       }
     }
   }
   if (!result && hitTestPointForThisLayer.HasPositiveWCoord() &&
-      aApzc->VisibleRegionContains(ViewAs<ParentLayerPixel>(hitTestPointForThisLayer.As2DPoint()))) {
+      aApzc->VisibleRegionContains(ParentLayerPoint::FromUnknownPoint(hitTestPointForThisLayer.As2DPoint()))) {
     APZCTM_LOG("Successfully matched untransformed point %f %f to visible region for APZC %p\n",
              hitTestPointForThisLayer.x, hitTestPointForThisLayer.y, aApzc);
     result = aApzc;
   }
 
   // If we are overscrolled, and the point matches us or one of our children,
   // the result is inside an overscrolled APZC, inform our caller of this
   // (callers typically ignore events targeted at overscrolled APZCs).
--- a/gfx/layers/apz/src/APZCTreeManager.h
+++ b/gfx/layers/apz/src/APZCTreeManager.h
@@ -361,17 +361,17 @@ public:
                                                          bool* aOutInOverscrolledApzc);
   void GetInputTransforms(AsyncPanZoomController *aApzc, gfx::Matrix4x4& aTransformToApzcOut,
                           gfx::Matrix4x4& aTransformToGeckoOut);
 private:
   /* Helpers */
   AsyncPanZoomController* FindTargetAPZC(AsyncPanZoomController* aApzc, FrameMetrics::ViewID aScrollId);
   AsyncPanZoomController* FindTargetAPZC(AsyncPanZoomController* aApzc, const ScrollableLayerGuid& aGuid);
   AsyncPanZoomController* GetAPZCAtPoint(AsyncPanZoomController* aApzc,
-                                         const gfxPoint& aHitTestPoint,
+                                         const gfx::Point& aHitTestPoint,
                                          bool* aOutInOverscrolledApzc);
   already_AddRefed<AsyncPanZoomController> CommonAncestor(AsyncPanZoomController* aApzc1, AsyncPanZoomController* aApzc2);
   already_AddRefed<AsyncPanZoomController> RootAPZCForLayersId(AsyncPanZoomController* aApzc);
   already_AddRefed<AsyncPanZoomController> GetTouchInputBlockAPZC(const MultiTouchInput& aEvent,
                                                                   bool* aOutInOverscrolledApzc);
   nsEventStatus ProcessTouchInput(MultiTouchInput& aInput,
                                   ScrollableLayerGuid* aOutTargetGuid);
   nsEventStatus ProcessEvent(WidgetInputEvent& inputEvent,
--- a/gfx/thebes/gfx3DMatrix.cpp
+++ b/gfx/thebes/gfx3DMatrix.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "gfxMatrix.h"
 #include "gfx3DMatrix.h"
+#include "gfx2DGlue.h"
 #include "mozilla/gfx/Tools.h"
 #include <math.h>
 #include <algorithm>
 
 using namespace std;
 using namespace mozilla;
 using namespace mozilla::gfx;
 
@@ -231,34 +232,16 @@ gfx3DMatrix::ChangeBasis(const Point3D& 
   // Translate to the origin before applying this matrix.
   Translate(-aOrigin);
 
   // Translate back into position after applying this matrix.
   TranslatePost(aOrigin);
 }
 
 void
-gfx3DMatrix::SkewXY(double aSkew)
-{
-    (*this)[1] += (*this)[0] * aSkew;
-}
-
-void 
-gfx3DMatrix::SkewXZ(double aSkew)
-{
-    (*this)[2] += (*this)[0] * aSkew;
-}
-
-void
-gfx3DMatrix::SkewYZ(double aSkew)
-{
-    (*this)[2] += (*this)[1] * aSkew;
-}
-
-void
 gfx3DMatrix::Scale(float aX, float aY, float aZ)
 {
     (*this)[0] *= aX;
     (*this)[1] *= aY;
     (*this)[2] *= aZ;
 }
 
 void
@@ -506,17 +489,17 @@ bool
 gfx3DMatrix::IsSingular() const
 {
   return Determinant() == 0.0;
 }
 
 gfx3DMatrix
 gfx3DMatrix::Inverse() const
 {
-  if (TransposedVector(3) == gfxPointH3D(0, 0, 0, 1)) {
+  if (_14 == 0 && _24 == 0 && _34 == 0 && _44 == 1) {
     /** 
      * When the matrix contains no perspective, the inverse
      * is the same as the 3x3 inverse of the rotation components
      * multiplied by the inverse of the translation components.
      * Doing these steps separately is faster and more numerically
      * stable.
      *
      * Inverse of the translation matrix is just negating
@@ -582,44 +565,16 @@ gfx3DMatrix::Inverse() const
   temp._44 = _12*_23*_31 - _13*_22*_31 +
              _13*_21*_32 - _11*_23*_32 -
              _12*_21*_33 + _11*_22*_33;
 
   temp /= det;
   return temp;
 }
 
-gfx3DMatrix&
-gfx3DMatrix::Normalize()
-{
-    for (int i = 0; i < 4; i++) {
-        for (int j = 0; j < 4; j++) {
-            (*this)[i][j] /= (*this)[3][3];
-       }
-    }
-    return *this;
-}
-
-gfx3DMatrix&
-gfx3DMatrix::Transpose()
-{
-    *this = Transposed();
-    return *this;
-}
-
-gfx3DMatrix
-gfx3DMatrix::Transposed() const
-{
-    gfx3DMatrix temp;
-    for (int i = 0; i < 4; i++) {
-        temp[i] = TransposedVector(i);
-    }
-    return temp;
-}
-
 gfxPoint
 gfx3DMatrix::Transform(const gfxPoint& point) const
 {
   Point3D vec3d(point.x, point.y, 0);
   vec3d = Transform3D(vec3d);
   return gfxPoint(vec3d.x, vec3d.y);
 }
 
@@ -633,36 +588,25 @@ gfx3DMatrix::Transform3D(const Point3D& 
 
   x /= w;
   y /= w;
   z /= w;
 
   return Point3D(x, y, z);
 }
 
-gfxPointH3D
-gfx3DMatrix::Transform4D(const gfxPointH3D& aPoint) const
+Point4D
+gfx3DMatrix::Transform4D(const Point4D& aPoint) const
 {
     gfxFloat x = aPoint.x * _11 + aPoint.y * _21 + aPoint.z * _31 + aPoint.w * _41;
     gfxFloat y = aPoint.x * _12 + aPoint.y * _22 + aPoint.z * _32 + aPoint.w * _42;
     gfxFloat z = aPoint.x * _13 + aPoint.y * _23 + aPoint.z * _33 + aPoint.w * _43;
     gfxFloat w = aPoint.x * _14 + aPoint.y * _24 + aPoint.z * _34 + aPoint.w * _44;
 
-    return gfxPointH3D(x, y, z, w);
-}
-
-gfxPointH3D
-gfx3DMatrix::TransposeTransform4D(const gfxPointH3D& aPoint) const
-{
-    gfxFloat x = aPoint.x * _11 + aPoint.y * _12 + aPoint.z * _13 + aPoint.w * _14;
-    gfxFloat y = aPoint.x * _21 + aPoint.y * _22 + aPoint.z * _23 + aPoint.w * _24;
-    gfxFloat z = aPoint.x * _31 + aPoint.y * _32 + aPoint.z * _33 + aPoint.w * _34;
-    gfxFloat w = aPoint.x * _41 + aPoint.y * _42 + aPoint.z * _43 + aPoint.w * _44;
-
-    return gfxPointH3D(x, y, z, w);
+    return Point4D(x, y, z, w);
 }
 
 gfxRect
 gfx3DMatrix::TransformBounds(const gfxRect& rect) const
 {
   gfxPoint points[4];
 
   points[0] = Transform(rect.TopLeft());
@@ -758,28 +702,28 @@ gfx3DMatrix::ProjectTo2D()
   _13 = 0.0f; 
   _23 = 0.0f; 
   _33 = 1.0f; 
   _43 = 0.0f; 
   _34 = 0.0f;
   return *this;
 }
 
-gfxPointH3D gfx3DMatrix::ProjectPoint(const gfxPoint& aPoint) const
+Point4D gfx3DMatrix::ProjectPoint(const gfxPoint& aPoint) const
 {
   // Find a value for z that will transform to 0.
 
   // The transformed value of z is computed as:
   // z' = aPoint.x * _13 + aPoint.y * _23 + z * _33 + _43;
 
   // Solving for z when z' = 0 gives us:
   float z = -(aPoint.x * _13 + aPoint.y * _23 + _43) / _33;
 
   // Compute the transformed point
-  return Transform4D(gfxPointH3D(aPoint.x, aPoint.y, z, 1));
+  return Transform4D(Point4D(aPoint.x, aPoint.y, z, 1));
 }
 
 Point3D gfx3DMatrix::GetNormalVector() const
 {
   // Define a plane in transformed space as the transformations
   // of 3 points on the z=0 screen plane.
   Point3D a = Transform3D(Point3D(0, 0, 0));
   Point3D b = Transform3D(Point3D(0, 1, 0));
--- a/gfx/thebes/gfx3DMatrix.h
+++ b/gfx/thebes/gfx3DMatrix.h
@@ -2,17 +2,17 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_3DMATRIX_H
 #define GFX_3DMATRIX_H
 
 #include <gfxTypes.h>
-#include <gfxPointH3D.h>
+#include "mozilla/gfx/Point.h"
 #include <gfxQuad.h>
 
 class gfxMatrix;
 
 /**
  * This class represents a 3D transformation. The matrix is laid
  * out as follows:
  *
@@ -25,16 +25,17 @@ class gfxMatrix;
  * vectors, this matrix type will be identical in memory to the OpenGL and D3D
  * matrices. OpenGL matrices are column-major, however OpenGL also treats
  * vectors as column vectors, the double transposition makes everything work
  * out nicely.
  */
 class gfx3DMatrix
 {
   typedef mozilla::gfx::Point3D Point3D;
+  typedef mozilla::gfx::Point4D Point4D;
 public:
   /**
    * Create matrix.
    */
   gfx3DMatrix(void);
 
   friend std::ostream& operator<<(std::ostream& stream, const gfx3DMatrix& m) {
     if (m.IsIdentity()) {
@@ -58,25 +59,25 @@ public:
   }
 
   /**
    * Matrix multiplication.
    */
   gfx3DMatrix operator*(const gfx3DMatrix &aMatrix) const;
   gfx3DMatrix& operator*=(const gfx3DMatrix &aMatrix);
 
-  gfxPointH3D& operator[](int aIndex)
+  Point4D& operator[](int aIndex)
   {
       NS_ABORT_IF_FALSE(aIndex >= 0 && aIndex <= 3, "Invalid matrix array index");
-      return *reinterpret_cast<gfxPointH3D*>((&_11)+4*aIndex);
+      return *reinterpret_cast<Point4D*>((&_11)+4*aIndex);
   }
-  const gfxPointH3D& operator[](int aIndex) const
+  const Point4D& operator[](int aIndex) const
   {
       NS_ABORT_IF_FALSE(aIndex >= 0 && aIndex <= 3, "Invalid matrix array index");
-      return *reinterpret_cast<const gfxPointH3D*>((&_11)+4*aIndex);
+      return *reinterpret_cast<const Point4D*>((&_11)+4*aIndex);
   }
 
   /**
    * Return true if this matrix and |aMatrix| are the same matrix.
    */
   bool operator==(const gfx3DMatrix& aMatrix) const;
   bool operator!=(const gfx3DMatrix& aMatrix) const;
 
@@ -152,20 +153,16 @@ public:
    *
    * This creates this temporary matrix:
    * | 1           tan(aYSkew) 0 0 |
    * | tan(aXSkew) 1           0 0 |
    * | 0           0           1 0 |
    * | 0           0           0 1 |
    */
   void SkewXY(double aXSkew, double aYSkew);
-  
-  void SkewXY(double aSkew);
-  void SkewXZ(double aSkew);
-  void SkewYZ(double aSkew);
 
   /**
    * Scale the matrix
    *
    * This creates this temporary matrix:
    * | aX 0  0  0 |
    * | 0  aY 0  0 |
    * | 0  0  aZ 0 |
@@ -272,57 +269,36 @@ public:
 
 
   gfxQuad TransformRect(const gfxRect& aRect) const;
 
   /** 
    * Transforms a 3D vector according to this matrix.
    */
   Point3D Transform3D(const Point3D& point) const;
-  gfxPointH3D Transform4D(const gfxPointH3D& aPoint) const;
-  gfxPointH3D TransposeTransform4D(const gfxPointH3D& aPoint) const;
+  Point4D Transform4D(const Point4D& aPoint) const;
 
   /**
    * Given a point (x,y) find a value for z such that (x,y,z,1) transforms
    * into (x',y',0,w') and returns the latter.
    */
-  gfxPointH3D ProjectPoint(const gfxPoint& aPoint) const;
+  Point4D ProjectPoint(const gfxPoint& aPoint) const;
 
   /**
    * Inverts this matrix, if possible. Otherwise, the matrix is left
    * unchanged.
    */
   gfx3DMatrix Inverse() const;
 
   gfx3DMatrix& Invert()
   {
       *this = Inverse();
       return *this;
   }
 
-  gfx3DMatrix& Normalize();
-
-  gfxPointH3D TransposedVector(int aIndex) const
-  {
-      NS_ABORT_IF_FALSE(aIndex >= 0 && aIndex <= 3, "Invalid matrix array index");
-      return gfxPointH3D(*((&_11)+aIndex), *((&_21)+aIndex), *((&_31)+aIndex), *((&_41)+aIndex));
-  }
-
-  void SetTransposedVector(int aIndex, gfxPointH3D &aVector)
-  {
-      NS_ABORT_IF_FALSE(aIndex >= 0 && aIndex <= 3, "Invalid matrix array index");
-      *((&_11)+aIndex) = aVector.x;
-      *((&_21)+aIndex) = aVector.y;
-      *((&_31)+aIndex) = aVector.z;
-      *((&_41)+aIndex) = aVector.w;
-  }
-
-  gfx3DMatrix& Transpose();
-  gfx3DMatrix Transposed() const;
-
   /**
    * Returns a unit vector that is perpendicular to the plane formed
    * by transform the screen plane (z=0) by this matrix.
    */
   Point3D GetNormalVector() const;
 
   /**
    * Returns true if a plane transformed by this matrix will
deleted file mode 100644
--- a/gfx/thebes/gfxPointH3D.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef GFX_POINTH3D_H
-#define GFX_POINTH3D_H
-
-#include "mozilla/gfx/BasePoint4D.h"
-#include "gfxTypes.h"
-#include "gfxPoint.h"
-
-struct gfxPointH3D : public mozilla::gfx::BasePoint4D<float, gfxPointH3D> {
-    typedef mozilla::gfx::BasePoint4D<float, gfxPointH3D> Super;
-
-    gfxPointH3D() : Super() {}
-    gfxPointH3D(float aX, float aY, float aZ, float aW) : Super(aX, aY, aZ, aW) {}
-
-    bool HasPositiveWCoord() { return w > 0; }
-
-    gfxPoint As2DPoint() {
-      return gfxPoint(x / w, y / w);
-    }
-};
-
-#endif /* GFX_POINTH3D_H */
--- a/gfx/thebes/gfxQuaternion.h
+++ b/gfx/thebes/gfxQuaternion.h
@@ -2,27 +2,27 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_QUATERNION_H
 #define GFX_QUATERNION_H
 
 #include "mozilla/gfx/BasePoint4D.h"
-#include "gfx3DMatrix.h"
+#include "mozilla/gfx/Matrix.h"
 #include "nsAlgorithm.h"
 #include <algorithm>
 
 struct gfxQuaternion : public mozilla::gfx::BasePoint4D<gfxFloat, gfxQuaternion> {
     typedef mozilla::gfx::BasePoint4D<gfxFloat, gfxQuaternion> Super;
 
     gfxQuaternion() : Super() {}
     gfxQuaternion(gfxFloat aX, gfxFloat aY, gfxFloat aZ, gfxFloat aW) : Super(aX, aY, aZ, aW) {}
 
-    gfxQuaternion(const gfx3DMatrix& aMatrix) {
+    gfxQuaternion(const mozilla::gfx::Matrix4x4& aMatrix) {
         w = 0.5 * sqrt(std::max(1 + aMatrix[0][0] + aMatrix[1][1] + aMatrix[2][2], 0.0f));
         x = 0.5 * sqrt(std::max(1 + aMatrix[0][0] - aMatrix[1][1] - aMatrix[2][2], 0.0f));
         y = 0.5 * sqrt(std::max(1 - aMatrix[0][0] + aMatrix[1][1] - aMatrix[2][2], 0.0f));
         z = 0.5 * sqrt(std::max(1 - aMatrix[0][0] - aMatrix[1][1] + aMatrix[2][2], 0.0f));
 
         if(aMatrix[2][1] > aMatrix[1][2])
             x = -x;
         if(aMatrix[0][2] > aMatrix[2][0])
@@ -45,18 +45,18 @@ struct gfxQuaternion : public mozilla::g
         gfxQuaternion right = aOther;
 
         left *= cos(aCoeff*theta) - dot*rightWeight;
         right *= rightWeight;
 
         return left + right;
     }
 
-    gfx3DMatrix ToMatrix() {
-        gfx3DMatrix temp;
+    mozilla::gfx::Matrix4x4 ToMatrix() {
+      mozilla::gfx::Matrix4x4 temp;
 
         temp[0][0] = 1 - 2 * (y * y + z * z);
         temp[0][1] = 2 * (x * y + w * z);
         temp[0][2] = 2 * (x * z - w * y);
         temp[1][0] = 2 * (x * y - w * z);
         temp[1][1] = 1 - 2 * (x * x + z * z);
         temp[1][2] = 2 * (y * z + w * x);
         temp[2][0] = 2 * (x * z + w * y);
--- a/gfx/thebes/moz.build
+++ b/gfx/thebes/moz.build
@@ -26,17 +26,16 @@ EXPORTS += [
     'gfxGradientCache.h',
     'gfxImageSurface.h',
     'gfxLineSegment.h',
     'gfxMathTable.h',
     'gfxMatrix.h',
     'gfxPattern.h',
     'gfxPlatform.h',
     'gfxPoint.h',
-    'gfxPointH3D.h',
     'gfxPrefs.h',
     'gfxQuad.h',
     'gfxQuaternion.h',
     'gfxRect.h',
     'gfxReusableImageSurfaceWrapper.h',
     'gfxReusableSharedImageSurfaceWrapper.h',
     'gfxReusableSurfaceWrapper.h',
     'gfxSharedImageSurface.h',
--- a/layout/base/nsDisplayList.cpp
+++ b/layout/base/nsDisplayList.cpp
@@ -5046,38 +5046,38 @@ void nsDisplayTransform::HitTest(nsDispl
   }
 
   /* We want to go from transformed-space to regular space.
    * Thus we have to invert the matrix, which normally does
    * the reverse operation (e.g. regular->transformed)
    */
 
   /* Now, apply the transform and pass it down the channel. */
+  matrix.Invert();
   nsRect resultingRect;
   if (aRect.width == 1 && aRect.height == 1) {
     // Magic width/height indicating we're hit testing a point, not a rect
-    gfxPointH3D point = To3DMatrix(matrix).Inverse().ProjectPoint(gfxPoint(NSAppUnitsToFloatPixels(aRect.x, factor),
-                                                               NSAppUnitsToFloatPixels(aRect.y, factor)));
+    Point4D point = matrix.ProjectPoint(Point(NSAppUnitsToFloatPixels(aRect.x, factor),
+                                              NSAppUnitsToFloatPixels(aRect.y, factor)));
     if (!point.HasPositiveWCoord()) {
       return;
     }
 
-    gfxPoint point2d = point.As2DPoint();
+    Point point2d = point.As2DPoint();
 
     resultingRect = nsRect(NSFloatPixelsToAppUnits(float(point2d.x), factor),
                            NSFloatPixelsToAppUnits(float(point2d.y), factor),
                            1, 1);
 
   } else {
     Rect originalRect(NSAppUnitsToFloatPixels(aRect.x, factor),
                       NSAppUnitsToFloatPixels(aRect.y, factor),
                       NSAppUnitsToFloatPixels(aRect.width, factor),
                       NSAppUnitsToFloatPixels(aRect.height, factor));
 
-    matrix.Invert();
     Rect rect = matrix.ProjectRectBounds(originalRect);
 
     bool snap;
     nsRect childBounds = mStoredList.GetBounds(aBuilder, &snap);
     Rect childGfxBounds(NSAppUnitsToFloatPixels(childBounds.x, factor),
                         NSAppUnitsToFloatPixels(childBounds.y, factor),
                         NSAppUnitsToFloatPixels(childBounds.width, factor),
                         NSAppUnitsToFloatPixels(childBounds.height, factor));
@@ -5115,21 +5115,23 @@ float
 nsDisplayTransform::GetHitDepthAtPoint(nsDisplayListBuilder* aBuilder, const nsPoint& aPoint)
 {
   // GetTransform always operates in dev pixels.
   float factor = mFrame->PresContext()->AppUnitsPerDevPixel();
   Matrix4x4 matrix = GetTransform();
 
   NS_ASSERTION(IsFrameVisible(mFrame, matrix), "We can't have hit a frame that isn't visible!");
 
-  gfxPointH3D point = To3DMatrix(matrix).Inverse().ProjectPoint(gfxPoint(NSAppUnitsToFloatPixels(aPoint.x, factor),
-                                                             NSAppUnitsToFloatPixels(aPoint.y, factor)));
+  Matrix4x4 inverse = matrix;
+  inverse.Invert();
+  Point4D point = inverse.ProjectPoint(Point(NSAppUnitsToFloatPixels(aPoint.x, factor),
+                                             NSAppUnitsToFloatPixels(aPoint.y, factor)));
   NS_ASSERTION(point.HasPositiveWCoord(), "Why are we trying to get the depth for a point we didn't hit?");
 
-  gfxPoint point2d = point.As2DPoint();
+  Point point2d = point.As2DPoint();
 
   Point3D transformed = matrix * Point3D(point2d.x, point2d.y, 0);
   return transformed.z;
 }
 
 /* The bounding rectangle for the object is the overflow rectangle translated
  * by the reference point.
  */
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -20,16 +20,17 @@
 #include "nsCSSParser.h"
 #include "mozilla/css/Declaration.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/FloatingPoint.h"
 #include "mozilla/Likely.h"
 #include "gfxMatrix.h"
 #include "gfxQuaternion.h"
 #include "nsIDocument.h"
+#include "gfx2DGlue.h"
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 
 // HELPER METHODS
 // --------------
 /*
  * Given two units, this method returns a common unit that they can both be
@@ -1395,32 +1396,32 @@ Decompose2DMatrix(const gfxMatrix &aMatr
  * This, in turn, refers to the unmatrix program in Graphics Gems,
  * available from http://tog.acm.org/resources/GraphicsGems/ , and in
  * particular as the file GraphicsGems/gemsii/unmatrix.c
  * in http://tog.acm.org/resources/GraphicsGems/AllGems.tar.gz
  */
 static bool
 Decompose3DMatrix(const gfx3DMatrix &aMatrix, Point3D &aScale,
                   float aShear[3], gfxQuaternion &aRotate,
-                  Point3D &aTranslate, gfxPointH3D &aPerspective)
+                  Point3D &aTranslate, Point4D &aPerspective)
 {
-  gfx3DMatrix local = aMatrix;
+  Matrix4x4 local = ToMatrix4x4(aMatrix);
 
   if (local[3][3] == 0) {
     return false;
   }
   /* Normalize the matrix */
   local.Normalize();
 
   /**
    * perspective is used to solve for perspective, but it also provides
    * an easy way to test for singularity of the upper 3x3 component.
    */
-  gfx3DMatrix perspective = local;
-  gfxPointH3D empty(0, 0, 0, 1);
+  Matrix4x4 perspective = local;
+  Point4D empty(0, 0, 0, 1);
   perspective.SetTransposedVector(3, empty);
 
   if (perspective.Determinant() == 0.0) {
     return false;
   }
 
   /* First, isolate perspective. */
   if (local[0][3] != 0 || local[1][3] != 0 ||
@@ -1433,17 +1434,17 @@ Decompose3DMatrix(const gfx3DMatrix &aMa
      * aPerspective by the inverse.
      */
     perspective.Invert();
     aPerspective = perspective.TransposeTransform4D(aPerspective);
 
     /* Clear the perspective partition */
     local.SetTransposedVector(3, empty);
   } else {
-    aPerspective = gfxPointH3D(0, 0, 0, 1);
+    aPerspective = Point4D(0, 0, 0, 1);
   }
 
   /* Next take care of translation */
   for (int i = 0; i < 3; i++) {
     aTranslate[i] = local[3][i];
     local[3][i] = 0;
   }
 
@@ -1505,49 +1506,49 @@ StyleAnimationValue::InterpolateTransfor
                                                 const gfx3DMatrix &aMatrix2,
                                                 double aProgress)
 {
   // Decompose both matrices
 
   // TODO: What do we do if one of these returns false (singular matrix)
 
   Point3D scale1(1, 1, 1), translate1;
-  gfxPointH3D perspective1(0, 0, 0, 1);
+  Point4D perspective1(0, 0, 0, 1);
   gfxQuaternion rotate1;
   float shear1[3] = { 0.0f, 0.0f, 0.0f};
 
   Point3D scale2(1, 1, 1), translate2;
-  gfxPointH3D perspective2(0, 0, 0, 1);
+  Point4D perspective2(0, 0, 0, 1);
   gfxQuaternion rotate2;
   float shear2[3] = { 0.0f, 0.0f, 0.0f};
 
   gfxMatrix matrix2d1, matrix2d2;
   if (aMatrix1.Is2D(&matrix2d1) && aMatrix2.Is2D(&matrix2d2)) {
     Decompose2DMatrix(matrix2d1, scale1, shear1, rotate1, translate1);
     Decompose2DMatrix(matrix2d2, scale2, shear2, rotate2, translate2);
   } else {
     Decompose3DMatrix(aMatrix1, scale1, shear1,
                       rotate1, translate1, perspective1);
     Decompose3DMatrix(aMatrix2, scale2, shear2,
                       rotate2, translate2, perspective2);
   }
 
   // Interpolate each of the pieces
-  gfx3DMatrix result;
-
-  gfxPointH3D perspective =
+  Matrix4x4 result;
+
+  Point4D perspective =
     InterpolateNumerically(perspective1, perspective2, aProgress);
   result.SetTransposedVector(3, perspective);
 
   Point3D translate =
     InterpolateNumerically(translate1, translate2, aProgress);
-  result.Translate(translate);
+  result.Translate(translate.x, translate.y, translate.z);
 
   gfxQuaternion q3 = rotate1.Slerp(rotate2, aProgress);
-  gfx3DMatrix rotate = q3.ToMatrix();
+  Matrix4x4 rotate = q3.ToMatrix();
   if (!rotate.IsIdentity()) {
       result = rotate * result;
   }
 
   // TODO: Would it be better to interpolate these as angles? How do we convert back to angles?
   float yzshear =
     InterpolateNumerically(shear1[YZSHEAR], shear2[YZSHEAR], aProgress);
   if (yzshear != 0.0) {
@@ -1567,17 +1568,17 @@ StyleAnimationValue::InterpolateTransfor
   }
 
   Point3D scale =
     InterpolateNumerically(scale1, scale2, aProgress);
   if (scale != Point3D(1.0, 1.0, 1.0)) {
     result.Scale(scale.x, scale.y, scale.z);
   }
 
-  return result;
+  return To3DMatrix(result);
 }
 
 static nsCSSValueList*
 AddDifferentTransformLists(double aCoeff1, const nsCSSValueList* aList1,
                            double aCoeff2, const nsCSSValueList* aList2)
 {
   nsAutoPtr<nsCSSValueList> result;
   nsCSSValueList **resultTail = getter_Transfers(result);