Bug 1040906 - Replace the out-param on matrix conversion helpers with a return value. r=Bas
authorKartikaya Gupta <kgupta@mozilla.com>
Tue, 22 Jul 2014 09:12:14 -0400
changeset 195423 e6a2c46ad0b5fa647b3059133ca648692712a956
parent 195422 4b985c02b8610ee4add90b0a0ba9dc43735f90b3
child 195424 ad750acfe3fc74e1c24f9ac0f639a9698ede5906
push id46593
push userkgupta@mozilla.com
push dateTue, 22 Jul 2014 13:12:59 +0000
treeherdermozilla-inbound@e6a2c46ad0b5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas
bugs1040906
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 1040906 - Replace the out-param on matrix conversion helpers with a return value. r=Bas
gfx/layers/LayerSorter.cpp
gfx/layers/LayerTreeInvalidation.cpp
gfx/layers/apz/src/APZCTreeManager.cpp
gfx/layers/basic/BasicCompositor.cpp
gfx/layers/basic/BasicLayerManager.cpp
gfx/layers/client/ClientTiledThebesLayer.cpp
gfx/layers/client/TiledContentClient.cpp
gfx/layers/composite/AsyncCompositionManager.cpp
gfx/layers/composite/LayerManagerComposite.cpp
gfx/layers/ipc/LayerTransactionParent.cpp
gfx/tests/gtest/TestLayers.cpp
gfx/thebes/gfx2DGlue.h
layout/base/FrameLayerBuilder.cpp
layout/base/nsDisplayList.cpp
layout/generic/nsFrame.cpp
layout/ipc/RenderFrameParent.cpp
widget/cocoa/nsChildView.mm
--- a/gfx/layers/LayerSorter.cpp
+++ b/gfx/layers/LayerSorter.cpp
@@ -75,20 +75,18 @@ static gfxFloat RecoverZDepth(const gfx3
  * in particular) and this generates the 'correct' looking ordering. For planes
  * that truely intersect, then there is no correct ordering and this remains
  * unsolved without changing our rendering code.
  */
 static LayerSortOrder CompareDepth(Layer* aOne, Layer* aTwo) {
   gfxRect ourRect = aOne->GetEffectiveVisibleRegion().GetBounds();
   gfxRect otherRect = aTwo->GetEffectiveVisibleRegion().GetBounds();
 
-  gfx3DMatrix ourTransform;
-  To3DMatrix(aOne->GetTransform(), ourTransform);
-  gfx3DMatrix otherTransform;
-  To3DMatrix(aTwo->GetTransform(), otherTransform);
+  gfx3DMatrix ourTransform = To3DMatrix(aOne->GetTransform());
+  gfx3DMatrix otherTransform = To3DMatrix(aTwo->GetTransform());
 
   // Transform both rectangles and project into 2d space.
   gfxQuad ourTransformedRect = ourTransform.TransformRect(ourRect);
   gfxQuad otherTransformedRect = otherTransform.TransformRect(otherRect);
 
   gfxRect ourBounds = ourTransformedRect.GetBounds();
   gfxRect otherBounds = otherTransformedRect.GetBounds();
 
--- a/gfx/layers/LayerTreeInvalidation.cpp
+++ b/gfx/layers/LayerTreeInvalidation.cpp
@@ -109,17 +109,17 @@ struct LayerPropertiesBase : public Laye
   {
     MOZ_COUNT_CTOR(LayerPropertiesBase);
     if (aLayer->GetMaskLayer()) {
       mMaskLayer = CloneLayerTreePropertiesInternal(aLayer->GetMaskLayer());
     }
     if (mUseClipRect) {
       mClipRect = *aLayer->GetClipRect();
     }
-    gfx::To3DMatrix(aLayer->GetTransform(), mTransform);
+    mTransform = gfx::To3DMatrix(aLayer->GetTransform());
   }
   LayerPropertiesBase()
     : mLayer(nullptr)
     , mMaskLayer(nullptr)
   {
     MOZ_COUNT_CTOR(LayerPropertiesBase);
   }
   ~LayerPropertiesBase()
@@ -131,18 +131,17 @@ struct LayerPropertiesBase : public Laye
                                          NotifySubDocInvalidationFunc aCallback,
                                          bool* aGeometryChanged);
 
   virtual void MoveBy(const nsIntPoint& aOffset);
 
   nsIntRegion ComputeChange(NotifySubDocInvalidationFunc aCallback,
                             bool& aGeometryChanged)
   {
-    gfx3DMatrix transform;
-    gfx::To3DMatrix(mLayer->GetTransform(), transform);
+    gfx3DMatrix transform = gfx::To3DMatrix(mLayer->GetTransform());
     bool transformChanged = !mTransform.FuzzyEqual(transform) ||
                             mLayer->GetPostXScale() != mPostXScale ||
                             mLayer->GetPostYScale() != mPostYScale;
     Layer* otherMask = mLayer->GetMaskLayer();
     const nsIntRect* otherClip = mLayer->GetClipRect();
     nsIntRegion result;
     if ((mMaskLayer ? mMaskLayer->mLayer : nullptr) != otherMask ||
         (mUseClipRect != !!otherClip) ||
@@ -180,19 +179,18 @@ struct LayerPropertiesBase : public Laye
     }
 
     mLayer->ClearInvalidRect();
     return result;
   }
 
   nsIntRect NewTransformedBounds()
   {
-    gfx3DMatrix transform;
-    gfx::To3DMatrix(mLayer->GetTransform(), transform);
-    return TransformRect(mLayer->GetVisibleRegion().GetBounds(), transform);
+    return TransformRect(mLayer->GetVisibleRegion().GetBounds(),
+                         gfx::To3DMatrix(mLayer->GetTransform()));
   }
 
   nsIntRect OldTransformedBounds()
   {
     return TransformRect(mVisibleRegion.GetBounds(), mTransform);
   }
 
   virtual nsIntRegion ComputeChangeInternal(NotifySubDocInvalidationFunc aCallback,
@@ -289,19 +287,18 @@ struct ContainerLayerProperties : public
           invalidateChildsCurrentArea = true;
         }
       } else {
         // |child| is new, or was reordered to a higher index
         invalidateChildsCurrentArea = true;
       }
       if (invalidateChildsCurrentArea) {
         aGeometryChanged = true;
-        gfx3DMatrix transform;
-        gfx::To3DMatrix(child->GetTransform(), transform);
-        AddTransformedRegion(result, child->GetVisibleRegion(), transform);
+        AddTransformedRegion(result, child->GetVisibleRegion(),
+                             gfx::To3DMatrix(child->GetTransform()));
         if (aCallback) {
           NotifySubdocumentInvalidationRecursive(child, aCallback);
         } else {
           ClearInvalidations(child);
         }
       }
     }
 
@@ -310,19 +307,17 @@ struct ContainerLayerProperties : public
       AddRegion(result, mChildren[i]->OldTransformedBounds());
       i++;
     }
 
     if (aCallback) {
       aCallback(container, result);
     }
 
-    gfx3DMatrix transform;
-    gfx::To3DMatrix(mLayer->GetTransform(), transform);
-    result.Transform(transform);
+    result.Transform(gfx::To3DMatrix(mLayer->GetTransform()));
     return result;
   }
 
   // The old list of children:
   nsAutoTArray<nsAutoPtr<LayerPropertiesBase>,1> mChildren;
   float mPreXScale;
   float mPreYScale;
 };
@@ -442,18 +437,17 @@ LayerPropertiesBase::ComputeDifferences(
 {
   NS_ASSERTION(aRoot, "Must have a layer tree to compare against!");
   if (mLayer != aRoot) {
     if (aCallback) {
       NotifySubdocumentInvalidationRecursive(aRoot, aCallback);
     } else {
       ClearInvalidations(aRoot);
     }
-    gfx3DMatrix transform;
-    gfx::To3DMatrix(aRoot->GetTransform(), transform);
+    gfx3DMatrix transform = gfx::To3DMatrix(aRoot->GetTransform());
     nsIntRect result = TransformRect(aRoot->GetVisibleRegion().GetBounds(), transform);
     result = result.Union(OldTransformedBounds());
     if (aGeometryChanged != nullptr) {
       *aGeometryChanged = true;
     }
     return result;
   } else {
     bool geometryChanged = (aGeometryChanged != nullptr) ? *aGeometryChanged : false;
--- a/gfx/layers/apz/src/APZCTreeManager.cpp
+++ b/gfx/layers/apz/src/APZCTreeManager.cpp
@@ -239,18 +239,17 @@ APZCTreeManager::UpdatePanZoomController
         if (state->mController->GetTouchSensitiveRegion(&touchSensitiveRegion)) {
           // Note: we assume here that touchSensitiveRegion is in the CSS pixels
           // of our parent layer, which makes this coordinate conversion
           // correct.
           visible = visible.Intersect(touchSensitiveRegion
                                       * metrics.mDevPixelsPerCSSPixel
                                       * metrics.GetParentResolution());
         }
-        gfx3DMatrix transform;
-        gfx::To3DMatrix(aLayer->GetTransform(), transform);
+        gfx3DMatrix transform = gfx::To3DMatrix(aLayer->GetTransform());
 
         apzc->SetLayerHitTestData(visible, aTransform, transform);
         APZCTM_LOG("Setting rect(%f %f %f %f) as visible region for APZC %p\n", visible.x, visible.y,
                                                                               visible.width, visible.height,
                                                                               apzc);
 
         mApzcTreeLog << "APZC " << guid
                      << "\tcb=" << visible
@@ -307,19 +306,17 @@ APZCTreeManager::UpdatePanZoomController
   mApzcTreeLog << '\n';
 
   // Accumulate the CSS transform between layers that have an APZC, but exclude any
   // any layers that do have an APZC, and reset the accumulation at those layers.
   if (apzc) {
     aTransform = gfx3DMatrix();
   } else {
     // Multiply child layer transforms on the left so they get applied first
-    gfx3DMatrix matrix;
-    gfx::To3DMatrix(aLayer->GetTransform(), matrix);
-    aTransform = matrix * aTransform;
+    aTransform = gfx::To3DMatrix(aLayer->GetTransform()) * aTransform;
   }
 
   uint64_t childLayersId = (aLayer->AsRefLayer() ? aLayer->AsRefLayer()->GetReferentId() : aLayersId);
   // If there's no APZC at this level, any APZCs for our child layers will
   // have our siblings as siblings.
   AsyncPanZoomController* next = apzc ? nullptr : aNextSibling;
   for (Layer* child = aLayer->GetLastChild(); child; child = child->GetPrevSibling()) {
     gfx::TreeAutoIndent indent(mApzcTreeLog);
--- a/gfx/layers/basic/BasicCompositor.cpp
+++ b/gfx/layers/basic/BasicCompositor.cpp
@@ -257,17 +257,17 @@ BasicCompositor::DrawQuad(const gfx::Rec
       return;
     }
 
     Matrix destTransform;
     destTransform.Translate(-aRect.x, -aRect.y);
     dest->SetTransform(destTransform);
 
     // Get the bounds post-transform.
-    To3DMatrix(aTransform, new3DTransform);
+    new3DTransform = To3DMatrix(aTransform);
     gfxRect bounds = new3DTransform.TransformBounds(ThebesRect(aRect));
     bounds.IntersectRect(bounds, gfxRect(offset.x, offset.y, buffer->GetSize().width, buffer->GetSize().height));
 
     transformBounds = ToRect(bounds);
     transformBounds.RoundOut();
 
     // Propagate the coordinate offset to our 2D draw target.
     newTransform.Translate(transformBounds.x, transformBounds.y);
--- a/gfx/layers/basic/BasicLayerManager.cpp
+++ b/gfx/layers/basic/BasicLayerManager.cpp
@@ -892,18 +892,17 @@ BasicLayerManager::PaintLayer(gfxContext
                      (aLayer->GetDebugColorIndex() & 4) ? 1.0 : 0.0,
                      1.0);
 
       nsRefPtr<gfxContext> temp = new gfxContext(untransformedDT, Point(bounds.x, bounds.y));
       temp->SetColor(color);
       temp->Paint();
     }
 #endif
-    gfx3DMatrix effectiveTransform;
-    gfx::To3DMatrix(aLayer->GetEffectiveTransform(), effectiveTransform);
+    gfx3DMatrix effectiveTransform = gfx::To3DMatrix(aLayer->GetEffectiveTransform());
     nsRefPtr<gfxASurface> result =
       Transform3D(untransformedDT->Snapshot(), aTarget, bounds,
                   effectiveTransform, destRect);
 
     if (result) {
       aTarget->SetSource(result, destRect.TopLeft());
       // Azure doesn't support EXTEND_NONE, so to avoid extending the edges
       // of the source surface out to the current clip region, clip to
--- a/gfx/layers/client/ClientTiledThebesLayer.cpp
+++ b/gfx/layers/client/ClientTiledThebesLayer.cpp
@@ -72,19 +72,17 @@ GetTransformToAncestorsParentLayer(Layer
     if (iter->AsContainerLayer()) {
       // If the layer has a non-transient async transform then we need to apply it here
       // because it will get applied by the APZ in the compositor as well
       const FrameMetrics& metrics = iter->AsContainerLayer()->GetFrameMetrics();
       transform = transform * gfx::Matrix4x4().Scale(metrics.mResolution.scale, metrics.mResolution.scale, 1.f);
     }
     transform = transform * iter->GetTransform();
   }
-  gfx3DMatrix ret;
-  gfx::To3DMatrix(transform, ret);
-  return ret;
+  return gfx::To3DMatrix(transform);
 }
 
 void
 ClientTiledThebesLayer::GetAncestorLayers(ContainerLayer** aOutScrollAncestor,
                                           ContainerLayer** aOutDisplayPortAncestor)
 {
   ContainerLayer* scrollAncestor = nullptr;
   ContainerLayer* displayPortAncestor = nullptr;
--- a/gfx/layers/client/TiledContentClient.cpp
+++ b/gfx/layers/client/TiledContentClient.cpp
@@ -1076,18 +1076,17 @@ GetCompositorSideCompositionBounds(Conta
                                    const gfx3DMatrix& aTransformToCompBounds,
                                    const ViewTransform& aAPZTransform)
 {
   gfx3DMatrix nonTransientAPZTransform = gfx3DMatrix::ScalingMatrix(
     aScrollAncestor->GetFrameMetrics().mResolution.scale,
     aScrollAncestor->GetFrameMetrics().mResolution.scale,
     1.f);
 
-  gfx3DMatrix layerTransform;
-  gfx::To3DMatrix(aScrollAncestor->GetTransform(), layerTransform);
+  gfx3DMatrix layerTransform = gfx::To3DMatrix(aScrollAncestor->GetTransform());
 
   // First take off the last two "terms" of aTransformToCompBounds, which
   // are the scroll ancestor's local transform and the APZ's nontransient async
   // transform.
   gfx3DMatrix transform = aTransformToCompBounds;
   transform = transform * layerTransform.Inverse();
   transform = transform * nonTransientAPZTransform.Inverse();
 
--- a/gfx/layers/composite/AsyncCompositionManager.cpp
+++ b/gfx/layers/composite/AsyncCompositionManager.cpp
@@ -400,19 +400,17 @@ SampleValue(float aPortion, Animation& a
   gfxPoint3D scaledOrigin =
     gfxPoint3D(NS_round(NSAppUnitsToFloatPixels(origin.x, data.appUnitsPerDevPixel())),
                NS_round(NSAppUnitsToFloatPixels(origin.y, data.appUnitsPerDevPixel())),
                0.0f);
 
   transform.Translate(scaledOrigin);
 
   InfallibleTArray<TransformFunction> functions;
-  Matrix4x4 realTransform;
-  ToMatrix4x4(transform, realTransform);
-  functions.AppendElement(TransformMatrix(realTransform));
+  functions.AppendElement(TransformMatrix(ToMatrix4x4(transform)));
   *aValue = functions;
 }
 
 static bool
 SampleAnimations(Layer* aLayer, TimeStamp aPoint)
 {
   AnimationArray& animations = aLayer->GetAnimations();
   InfallibleTArray<AnimData>& animationData = aLayer->GetAnimationData();
@@ -508,20 +506,17 @@ SampleAnimations(Layer* aLayer, TimeStam
   }
 
   return activeAnimations;
 }
 
 Matrix4x4
 CombineWithCSSTransform(const gfx3DMatrix& treeTransform, Layer* aLayer)
 {
-  Matrix4x4 result;
-  ToMatrix4x4(treeTransform, result);
-  result = result * aLayer->GetTransform();
-  return result;
+  return ToMatrix4x4(treeTransform) * aLayer->GetTransform();
 }
 
 bool
 AsyncCompositionManager::ApplyAsyncContentTransformToTree(TimeStamp aCurrentFrame,
                                                           Layer *aLayer,
                                                           bool* aWantNextFrame)
 {
   bool appliedTransform = false;
@@ -696,19 +691,17 @@ ApplyAsyncTransformToScrollbarForContent
   Matrix4x4 transform = scrollbarTransform * aScrollbar->GetTransform();
 
   if (aScrollbarIsChild) {
     // If the scrollbar layer is a child of the content it is a scrollbar for, then we
     // need to do an extra untransform to cancel out the transient async transform on
     // the content. This is needed because otherwise that transient async transform is
     // part of the effective transform of this scrollbar, and the scrollbar will jitter
     // as the content scrolls.
-    Matrix4x4 targetUntransform;
-    ToMatrix4x4(transientTransform.Inverse(), targetUntransform);
-    transform = transform * targetUntransform;
+    transform = transform * ToMatrix4x4(transientTransform.Inverse());
   }
 
   // GetTransform already takes the pre- and post-scale into account.  Since we
   // will apply the pre- and post-scale again when computing the effective
   // transform, we must apply the inverses here.
   transform.Scale(1.0f/aScrollbar->GetPreXScale(),
                   1.0f/aScrollbar->GetPreYScale(),
                   1);
@@ -766,18 +759,17 @@ void
 AsyncCompositionManager::TransformScrollableLayer(Layer* aLayer)
 {
   LayerComposite* layerComposite = aLayer->AsLayerComposite();
   ContainerLayer* container = aLayer->AsContainerLayer();
 
   const FrameMetrics& metrics = container->GetFrameMetrics();
   // We must apply the resolution scale before a pan/zoom transform, so we call
   // GetTransform here.
-  gfx3DMatrix currentTransform;
-  To3DMatrix(aLayer->GetTransform(), currentTransform);
+  gfx3DMatrix currentTransform = To3DMatrix(aLayer->GetTransform());
   Matrix4x4 oldTransform = aLayer->GetTransform();
 
   gfx3DMatrix treeTransform;
 
   CSSToLayerScale geckoZoom = metrics.LayersPixelsPerCSSPixel();
 
   LayerIntPoint scrollOffsetLayerPixels = RoundedToInt(metrics.GetScrollOffset() * geckoZoom);
 
@@ -844,19 +836,17 @@ AsyncCompositionManager::TransformScroll
   // transform, we must apply the inverse resolution scale here.
   gfx3DMatrix computedTransform = treeTransform * currentTransform;
   computedTransform.Scale(1.0f/container->GetPreXScale(),
                           1.0f/container->GetPreYScale(),
                           1);
   computedTransform.ScalePost(1.0f/container->GetPostXScale(),
                               1.0f/container->GetPostYScale(),
                               1);
-  Matrix4x4 matrix;
-  ToMatrix4x4(computedTransform, matrix);
-  layerComposite->SetShadowTransform(matrix);
+  layerComposite->SetShadowTransform(ToMatrix4x4(computedTransform));
   NS_ASSERTION(!layerComposite->GetShadowTransformSetByAnimation(),
                "overwriting animated transform!");
 
   // Apply resolution scaling to the old transform - the layer tree as it is
   // doesn't have the necessary transform to display correctly.
   oldTransform.Scale(metrics.mResolution.scale, metrics.mResolution.scale, 1);
 
   // Make sure that overscroll and under-zoom are represented in the old
--- a/gfx/layers/composite/LayerManagerComposite.cpp
+++ b/gfx/layers/composite/LayerManagerComposite.cpp
@@ -582,17 +582,17 @@ LayerManagerComposite::ComputeRenderInte
   }
 
   // If the layer's a container, recurse into all of its children
   ContainerLayer* container = aLayer->AsContainerLayer();
   if (container) {
     // Accumulate the transform of intermediate surfaces
     gfx3DMatrix transform = aTransform;
     if (container->UseIntermediateSurface()) {
-      gfx::To3DMatrix(aLayer->GetEffectiveTransform(), transform);
+      transform = gfx::To3DMatrix(aLayer->GetEffectiveTransform());
       transform.PreMultiply(aTransform);
     }
     for (Layer* child = aLayer->GetFirstChild(); child;
          child = child->GetNextSibling()) {
       ComputeRenderIntegrityInternal(child, aScreenRegion, aLowPrecisionScreenRegion, transform);
     }
     return;
   }
@@ -604,18 +604,17 @@ LayerManagerComposite::ComputeRenderInte
   }
 
   // See if there's any incomplete rendering
   nsIntRegion incompleteRegion = aLayer->GetEffectiveVisibleRegion();
   incompleteRegion.Sub(incompleteRegion, thebesLayer->GetValidRegion());
 
   if (!incompleteRegion.IsEmpty()) {
     // Calculate the transform to get between screen and layer space
-    gfx3DMatrix transformToScreen;
-    To3DMatrix(aLayer->GetEffectiveTransform(), transformToScreen);
+    gfx3DMatrix transformToScreen = To3DMatrix(aLayer->GetEffectiveTransform());
     transformToScreen.PreMultiply(aTransform);
 
     SubtractTransformedRegion(aScreenRegion, incompleteRegion, transformToScreen);
 
     // See if there's any incomplete low-precision rendering
     TiledLayerComposer* composer = nullptr;
     LayerComposite* shadow = aLayer->AsLayerComposite();
     if (shadow) {
@@ -684,18 +683,17 @@ LayerManagerComposite::ComputeRenderInte
 #ifdef MOZ_ANDROID_OMTC
   // Use the transform on the primary scrollable layer and its FrameMetrics
   // to find out how much of the viewport the current displayport covers
   Layer* primaryScrollable = GetPrimaryScrollableLayer();
   if (primaryScrollable) {
     // This is derived from the code in
     // AsyncCompositionManager::TransformScrollableLayer
     const FrameMetrics& metrics = primaryScrollable->AsContainerLayer()->GetFrameMetrics();
-    gfx3DMatrix transform;
-    gfx::To3DMatrix(primaryScrollable->GetEffectiveTransform(), transform);
+    gfx3DMatrix transform = gfx::To3DMatrix(primaryScrollable->GetEffectiveTransform());
     transform.ScalePost(metrics.mResolution.scale, metrics.mResolution.scale, 1);
 
     // Clip the screen rect to the document bounds
     gfxRect documentBounds =
       transform.TransformBounds(gfxRect(metrics.mScrollableRect.x - metrics.GetScrollOffset().x,
                                         metrics.mScrollableRect.y - metrics.GetScrollOffset().y,
                                         metrics.mScrollableRect.width,
                                         metrics.mScrollableRect.height));
--- a/gfx/layers/ipc/LayerTransactionParent.cpp
+++ b/gfx/layers/ipc/LayerTransactionParent.cpp
@@ -624,18 +624,17 @@ LayerTransactionParent::RecvGetAnimation
     *aTransform = mozilla::void_t();
     return true;
   }
 
   // The following code recovers the untranslated transform
   // from the shadow transform by undoing the translations in
   // AsyncCompositionManager::SampleValue.
 
-  gfx3DMatrix transform;
-  gfx::To3DMatrix(layer->AsLayerComposite()->GetShadowTransform(), transform);
+  gfx3DMatrix transform = gfx::To3DMatrix(layer->AsLayerComposite()->GetShadowTransform());
   if (ContainerLayer* c = layer->AsContainerLayer()) {
     // Undo the scale transform applied by AsyncCompositionManager::SampleValue
     transform.ScalePost(1.0f/c->GetInheritedXScale(),
                         1.0f/c->GetInheritedYScale(),
                         1.0f);
   }
   float scale = 1;
   gfxPoint3D scaledOrigin;
--- a/gfx/tests/gtest/TestLayers.cpp
+++ b/gfx/tests/gtest/TestLayers.cpp
@@ -189,19 +189,17 @@ already_AddRefed<Layer> CreateLayerTree(
       parentContainerLayer = parentContainerLayer->GetParent();
       lastLayer = nullptr;
     } else {
       nsRefPtr<Layer> layer = CreateLayer(aLayerTreeDescription[i], manager.get());
       if (aVisibleRegions) {
         layer->SetVisibleRegion(aVisibleRegions[layerNumber]);
       }
       if (aTransforms) {
-        Matrix4x4 transform;
-        ToMatrix4x4(aTransforms[layerNumber], transform);
-        layer->SetBaseTransform(transform);
+        layer->SetBaseTransform(ToMatrix4x4(aTransforms[layerNumber]));
       }
       aLayersOut.AppendElement(layer);
       layerNumber++;
       if (rootLayer && !parentContainerLayer) {
         MOZ_CRASH();
       }
       if (!rootLayer) {
         rootLayer = layer;
--- a/gfx/thebes/gfx2DGlue.h
+++ b/gfx/thebes/gfx2DGlue.h
@@ -371,54 +371,58 @@ inline gfxContext::GraphicsOperator Theb
     return gfxContext::OPERATOR_COLOR;
   case CompositionOp::OP_LUMINOSITY:
     return gfxContext::OPERATOR_LUMINOSITY;
   default:
     return gfxContext::OPERATOR_OVER;
   }
 }
 
-inline void
-ToMatrix4x4(const gfx3DMatrix& aIn, Matrix4x4& aOut)
+inline Matrix4x4
+ToMatrix4x4(const gfx3DMatrix& aIn)
 {
-  aOut._11 = aIn._11;
-  aOut._12 = aIn._12;
-  aOut._13 = aIn._13;
-  aOut._14 = aIn._14;
-  aOut._21 = aIn._21;
-  aOut._22 = aIn._22;
-  aOut._23 = aIn._23;
-  aOut._24 = aIn._24;
-  aOut._31 = aIn._31;
-  aOut._32 = aIn._32;
-  aOut._33 = aIn._33;
-  aOut._34 = aIn._34;
-  aOut._41 = aIn._41;
-  aOut._42 = aIn._42;
-  aOut._43 = aIn._43;
-  aOut._44 = aIn._44;
+  Matrix4x4 m;
+  m._11 = aIn._11;
+  m._12 = aIn._12;
+  m._13 = aIn._13;
+  m._14 = aIn._14;
+  m._21 = aIn._21;
+  m._22 = aIn._22;
+  m._23 = aIn._23;
+  m._24 = aIn._24;
+  m._31 = aIn._31;
+  m._32 = aIn._32;
+  m._33 = aIn._33;
+  m._34 = aIn._34;
+  m._41 = aIn._41;
+  m._42 = aIn._42;
+  m._43 = aIn._43;
+  m._44 = aIn._44;
+  return m;
 }
 
-inline void
-To3DMatrix(const Matrix4x4& aIn, gfx3DMatrix& aOut)
+inline gfx3DMatrix
+To3DMatrix(const Matrix4x4& aIn)
 {
-  aOut._11 = aIn._11;
-  aOut._12 = aIn._12;
-  aOut._13 = aIn._13;
-  aOut._14 = aIn._14;
-  aOut._21 = aIn._21;
-  aOut._22 = aIn._22;
-  aOut._23 = aIn._23;
-  aOut._24 = aIn._24;
-  aOut._31 = aIn._31;
-  aOut._32 = aIn._32;
-  aOut._33 = aIn._33;
-  aOut._34 = aIn._34;
-  aOut._41 = aIn._41;
-  aOut._42 = aIn._42;
-  aOut._43 = aIn._43;
-  aOut._44 = aIn._44;
+  gfx3DMatrix m;
+  m._11 = aIn._11;
+  m._12 = aIn._12;
+  m._13 = aIn._13;
+  m._14 = aIn._14;
+  m._21 = aIn._21;
+  m._22 = aIn._22;
+  m._23 = aIn._23;
+  m._24 = aIn._24;
+  m._31 = aIn._31;
+  m._32 = aIn._32;
+  m._33 = aIn._33;
+  m._34 = aIn._34;
+  m._41 = aIn._41;
+  m._42 = aIn._42;
+  m._43 = aIn._43;
+  m._44 = aIn._44;
+  return m;
 }
 
 }
 }
 
 #endif
--- a/layout/base/FrameLayerBuilder.cpp
+++ b/layout/base/FrameLayerBuilder.cpp
@@ -1706,18 +1706,17 @@ AppUnitsPerDevPixel(nsDisplayItem* aItem
  * aLayerContentsVisibleRect, if non-null, is a rectangle in the layer's
  * own coordinate system to which the layer's visible region is restricted.
  * Consumes *aOuterVisibleRegion.
  */
 static void
 SetOuterVisibleRegion(Layer* aLayer, nsIntRegion* aOuterVisibleRegion,
                       const nsIntRect* aLayerContentsVisibleRect = nullptr)
 {
-  gfx3DMatrix transform;
-  To3DMatrix(aLayer->GetTransform(), transform);
+  gfx3DMatrix transform = To3DMatrix(aLayer->GetTransform());
   gfxMatrix transform2D;
   if (transform.Is2D(&transform2D) && !transform2D.HasNonIntegerTranslation()) {
     aOuterVisibleRegion->MoveBy(-int(transform2D._31), -int(transform2D._32));
     if (aLayerContentsVisibleRect) {
       aOuterVisibleRegion->And(*aOuterVisibleRegion, *aLayerContentsVisibleRect);
     }
   } else {
     nsIntRect outerRect = aOuterVisibleRegion->GetBounds();
@@ -3642,19 +3641,17 @@ ChooseScaleAndSetTransform(FrameLayerBui
     if (aTransform) {
       RestrictScaleToMaxLayerSize(scale, aVisibleRect, aContainerFrame, aLayer);
     }
   } else {
     scale = gfxSize(1.0, 1.0);
   }
 
   // Store the inverse of our resolution-scale on the layer
-  Matrix4x4 baseTransform;
-  ToMatrix4x4(transform, baseTransform);
-  aLayer->SetBaseTransform(baseTransform);
+  aLayer->SetBaseTransform(ToMatrix4x4(transform));
   aLayer->SetPreScale(1.0f/float(scale.width),
                       1.0f/float(scale.height));
   aLayer->SetInheritedScale(aIncomingScale.mXScale,
                             aIncomingScale.mYScale);
 
   aOutgoingScale =
     ContainerLayerParameters(scale.width, scale.height, -offset, aIncomingScale);
   if (aTransform) {
--- a/layout/base/nsDisplayList.cpp
+++ b/layout/base/nsDisplayList.cpp
@@ -279,19 +279,17 @@ static void AddTransformFunctions(nsCSSV
       case eCSSKeyword_interpolatematrix:
       {
         gfx3DMatrix matrix;
         nsStyleTransformMatrix::ProcessInterpolateMatrix(matrix, array,
                                                          aContext,
                                                          aPresContext,
                                                          canStoreInRuleTree,
                                                          aBounds);
-        gfx::Matrix4x4 transform;
-        gfx::ToMatrix4x4(matrix, transform);
-        aFunctions.AppendElement(TransformMatrix(transform));
+        aFunctions.AppendElement(TransformMatrix(gfx::ToMatrix4x4(matrix)));
         break;
       }
       case eCSSKeyword_perspective:
       {
         aFunctions.AppendElement(Perspective(array->Item(1).GetFloatValue()));
         break;
       }
       default:
@@ -5146,20 +5144,18 @@ bool nsDisplayTransform::UntransformVisi
 
   return true;
 }
 
 #ifdef MOZ_DUMP_PAINTING
 void
 nsDisplayTransform::WriteDebugInfo(nsACString& aTo)
 {
-  gfx::Matrix4x4 transform;
-  gfx::ToMatrix4x4(GetTransform(), transform);
   std::stringstream ss;
-  AppendToString(ss, transform);
+  AppendToString(ss, gfx::ToMatrix4x4(GetTransform()));
   aTo += ss.str().c_str();
 }
 #endif
 
 nsDisplaySVGEffects::nsDisplaySVGEffects(nsDisplayListBuilder* aBuilder,
                                          nsIFrame* aFrame, nsDisplayList* aList)
     : nsDisplayWrapList(aBuilder, aFrame, aList),
       mEffectsBounds(aFrame->GetVisualOverflowRectRelativeToSelf())
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -4970,19 +4970,17 @@ nsIFrame::TryUpdateTransformOnly(Layer**
   if (!transform3d.Is2D(&transform) ||
       !layer->GetBaseTransform().Is2D(&previousTransform) ||
       !gfx::FuzzyEqual(transform._11, previousTransform._11, kError) ||
       !gfx::FuzzyEqual(transform._22, previousTransform._22, kError) ||
       !gfx::FuzzyEqual(transform._21, previousTransform._21, kError) ||
       !gfx::FuzzyEqual(transform._12, previousTransform._12, kError)) {
     return false;
   }
-  gfx::Matrix4x4 matrix;
-  gfx::ToMatrix4x4(transform3d, matrix);
-  layer->SetBaseTransformForNextTransaction(matrix);
+  layer->SetBaseTransformForNextTransaction(gfx::ToMatrix4x4(transform3d));
   *aLayerResult = layer;
   return true;
 }
 
 bool 
 nsIFrame::IsInvalid(nsRect& aRect)
 {
   if (!HasAnyStateBits(NS_FRAME_NEEDS_PAINT)) {
--- a/layout/ipc/RenderFrameParent.cpp
+++ b/layout/ipc/RenderFrameParent.cpp
@@ -223,19 +223,17 @@ BuildListForLayer(Layer* aLayer,
     // Calculate transform for this layer.
     nsContentView* view =
       aRootFrameLoader->GetCurrentRemoteFrame()->GetContentView(scrollId);
     // XXX why don't we include aLayer->GetTransform() in the inverse-scale here?
     // This seems wrong, but it doesn't seem to cause bugs!
     gfx3DMatrix applyTransform = ComputeShadowTreeTransform(
       aSubdocFrame, aRootFrameLoader, metrics, view->GetViewConfig(),
       1 / GetXScale(aTransform), 1 / GetYScale(aTransform));
-    gfx3DMatrix layerTransform;
-    To3DMatrix(aLayer->GetTransform(), layerTransform);
-    transform = applyTransform * layerTransform * aTransform;
+    transform = applyTransform * To3DMatrix(aLayer->GetTransform()) * aTransform;
 
     // As mentioned above, bounds calculation also depends on the scale
     // of this layer.
     gfx3DMatrix tmpTransform = aTransform;
     Scale(tmpTransform, GetXScale(applyTransform), GetYScale(applyTransform));
 
     // Calculate rect for this layer based on aTransform.
     nsRect bounds;
@@ -244,19 +242,17 @@ BuildListForLayer(Layer* aLayer,
       nscoord auPerDevPixel = aSubdocFrame->PresContext()->AppUnitsPerDevPixel();
       ApplyTransform(bounds, tmpTransform, auPerDevPixel);
     }
 
     aShadowTree.AppendToTop(
       new (aBuilder) nsDisplayRemoteShadow(aBuilder, aSubdocFrame, bounds, scrollId));
 
   } else {
-    gfx3DMatrix layerTransform;
-    To3DMatrix(aLayer->GetTransform(), layerTransform);
-    transform = layerTransform * aTransform;
+    transform = To3DMatrix(aLayer->GetTransform()) * aTransform;
   }
 
   for (Layer* child = aLayer->GetFirstChild(); child;
        child = child->GetNextSibling()) {
     BuildListForLayer(child, aRootFrameLoader, transform,
                       aBuilder, aShadowTree, aSubdocFrame);
   }
 }
@@ -271,27 +267,25 @@ TransformShadowTree(nsDisplayListBuilder
 {
   LayerComposite* shadow = aLayer->AsLayerComposite();
   shadow->SetShadowClipRect(aLayer->GetClipRect());
   shadow->SetShadowVisibleRegion(aLayer->GetVisibleRegion());
   shadow->SetShadowOpacity(aLayer->GetOpacity());
 
   const FrameMetrics* metrics = GetFrameMetrics(aLayer);
 
-  gfx3DMatrix shadowTransform;
-  To3DMatrix(aLayer->GetTransform(), shadowTransform);
+  gfx3DMatrix shadowTransform = To3DMatrix(aLayer->GetTransform());
   ViewTransform layerTransform = aTransform;
 
   if (metrics && metrics->IsScrollable()) {
     const ViewID scrollId = metrics->GetScrollId();
     const nsContentView* view =
       aFrameLoader->GetCurrentRemoteFrame()->GetContentView(scrollId);
     NS_ABORT_IF_FALSE(view, "Array of views should be consistent with layer tree");
-    gfx3DMatrix currentTransform;
-    To3DMatrix(aLayer->GetTransform(), currentTransform);
+    gfx3DMatrix currentTransform = To3DMatrix(aLayer->GetTransform());
 
     const ViewConfig& config = view->GetViewConfig();
     // With temporary scale we should compensate translation
     // using temporary scale value
     aTempScaleDiffX *= GetXScale(shadowTransform) * config.mXScale;
     aTempScaleDiffY *= GetYScale(shadowTransform) * config.mYScale;
     ViewTransform viewTransform = ComputeShadowTreeTransform(
       aFrame, aFrameLoader, metrics, view->GetViewConfig(),
@@ -333,19 +327,17 @@ TransformShadowTree(nsDisplayListBuilder
     shadowTransform.Scale(1.0f/c->GetPreXScale(),
                           1.0f/c->GetPreYScale(),
                           1);
   }
   shadowTransform.ScalePost(1.0f/aLayer->GetPostXScale(),
                             1.0f/aLayer->GetPostYScale(),
                             1);
 
-  gfx::Matrix4x4 realShadowTransform;
-  ToMatrix4x4(shadowTransform, realShadowTransform);
-  shadow->SetShadowTransform(realShadowTransform);
+  shadow->SetShadowTransform(gfx::ToMatrix4x4(shadowTransform));
   for (Layer* child = aLayer->GetFirstChild();
        child; child = child->GetNextSibling()) {
     TransformShadowTree(aBuilder, aFrameLoader, aFrame, child, layerTransform,
                         aTempScaleDiffX, aTempScaleDiffY);
   }
 }
 
 static void
@@ -379,18 +371,17 @@ BuildViewMap(ViewMap& oldContentViews, V
              float aXScale = 1, float aYScale = 1,
              float aAccConfigXScale = 1, float aAccConfigYScale = 1)
 {
   ContainerLayer* container = aLayer->AsContainerLayer();
   if (!container)
     return;
   const FrameMetrics metrics = container->GetFrameMetrics();
   const ViewID scrollId = metrics.GetScrollId();
-  gfx3DMatrix transform;
-  To3DMatrix(aLayer->GetTransform(), transform);
+  gfx3DMatrix transform = To3DMatrix(aLayer->GetTransform());
   aXScale *= GetXScale(transform);
   aYScale *= GetYScale(transform);
 
   if (metrics.IsScrollable()) {
     nscoord auPerDevPixel = aFrameLoader->GetPrimaryFrameOfOwningContent()
                                         ->PresContext()->AppUnitsPerDevPixel();
     nscoord auPerCSSPixel = auPerDevPixel * metrics.mDevPixelsPerCSSPixel.scale;
     nsContentView* view = FindViewForId(oldContentViews, scrollId);
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -2853,18 +2853,17 @@ RectTextureImage::Draw(GLManager* aManag
 {
   ShaderProgramOGL* program = aManager->GetProgram(LOCAL_GL_TEXTURE_RECTANGLE_ARB,
                                                    gfx::SurfaceFormat::R8G8B8A8);
 
   aManager->gl()->fBindTexture(LOCAL_GL_TEXTURE_RECTANGLE_ARB, mTexture);
 
   program->Activate();
   program->SetProjectionMatrix(aManager->GetProjMatrix());
-  gfx::Matrix4x4 transform;
-  gfx::ToMatrix4x4(aTransform, transform);
+  gfx::Matrix4x4 transform = gfx::ToMatrix4x4(aTransform);
   program->SetLayerTransform(transform * gfx::Matrix4x4().Translate(aLocation.x, aLocation.y, 0));
   program->SetTextureTransform(gfx::Matrix4x4());
   program->SetRenderOffset(nsIntPoint(0, 0));
   program->SetTexCoordMultiplier(mUsedSize.width, mUsedSize.height);
   program->SetTextureUnit(0);
 
   aManager->BindAndDrawQuad(program,
                             gfx::Rect(0.0, 0.0, mUsedSize.width, mUsedSize.height),