From 1c4b5d248a34d8a1a047a3169526254364932a89 Mon Sep 17 00:00:00 2001 From: David Zbarsky Date: Fri, 1 Aug 2014 08:31:48 -0400 Subject: [PATCH] Bug 952977: More gfx::Matrix cleanup in nsDisplayTransform r=nical --- layout/base/nsDisplayList.cpp | 32 +++++++++++--------- layout/base/nsDisplayList.h | 7 +++-- layout/base/nsLayoutUtils.cpp | 2 +- layout/generic/nsPageFrame.cpp | 4 +-- layout/generic/nsSimplePageSequenceFrame.cpp | 4 +-- 5 files changed, 26 insertions(+), 23 deletions(-) diff --git a/layout/base/nsDisplayList.cpp b/layout/base/nsDisplayList.cpp index 0e152a0ececa..44d94237f521 100644 --- a/layout/base/nsDisplayList.cpp +++ b/layout/base/nsDisplayList.cpp @@ -63,6 +63,8 @@ using namespace mozilla; using namespace mozilla::layers; using namespace mozilla::dom; using namespace mozilla::layout; +using namespace mozilla::gfx; + typedef FrameMetrics::ViewID ViewID; #ifdef DEBUG @@ -4596,7 +4598,7 @@ nsDisplayTransform::GetResultingTransformMatrixInternal(const FrameTransformProp gfx3DMatrix result; // Call IsSVGTransformed() regardless of the value of // disp->mSpecifiedTransform, since we still need any transformFromSVGParent. - mozilla::gfx::Matrix svgTransform, transformFromSVGParent; + Matrix svgTransform, transformFromSVGParent; bool hasSVGTransforms = frame && frame->IsSVGTransformed(&svgTransform, &transformFromSVGParent); /* Transformed frames always have a transform, or are preserving 3d (and might still have perspective!) */ @@ -4771,7 +4773,7 @@ static bool IsFrameVisible(nsIFrame* aFrame, const gfx3DMatrix& aMatrix) return true; } -const gfx3DMatrix& +const Matrix4x4& nsDisplayTransform::GetTransform() { if (mTransform.IsIdentity()) { @@ -4782,7 +4784,7 @@ nsDisplayTransform::GetTransform() 0.0f); if (mTransformGetter) { mTransform = mTransformGetter(mFrame, scale); - mTransform.ChangeBasis(newOrigin); + mTransform.ChangeBasis(newOrigin.x, newOrigin.y, newOrigin.z); } else { /** * Passing true as the final argument means that we want to shift the @@ -4792,9 +4794,9 @@ nsDisplayTransform::GetTransform() * to be an ancestor of the preserve-3d chain, so we only need to do * this once. */ - mTransform = + mTransform = ToMatrix4x4( GetResultingTransformMatrix(mFrame, ToReferenceFrame(), scale, - nullptr, nullptr, true); + nullptr, nullptr, true)); } } return mTransform; @@ -4810,7 +4812,7 @@ already_AddRefed nsDisplayTransform::BuildLayer(nsDisplayListBuilder *aBu LayerManager *aManager, const ContainerLayerParameters& aContainerParameters) { - const gfx3DMatrix& newTransformMatrix = GetTransform(); + const gfx3DMatrix& newTransformMatrix = To3DMatrix(GetTransform()); if (mFrame->StyleDisplay()->mBackfaceVisibility == NS_STYLE_BACKFACE_VISIBILITY_HIDDEN && newTransformMatrix.IsBackfaceVisible()) { @@ -4923,7 +4925,7 @@ void nsDisplayTransform::HitTest(nsDisplayListBuilder *aBuilder, */ // GetTransform always operates in dev pixels. float factor = mFrame->PresContext()->AppUnitsPerDevPixel(); - gfx3DMatrix matrix = GetTransform(); + gfx3DMatrix matrix = To3DMatrix(GetTransform()); if (!IsFrameVisible(mFrame, matrix)) { return; @@ -4999,7 +5001,7 @@ nsDisplayTransform::GetHitDepthAtPoint(nsDisplayListBuilder* aBuilder, const nsP { // GetTransform always operates in dev pixels. float factor = mFrame->PresContext()->AppUnitsPerDevPixel(); - gfx3DMatrix matrix = GetTransform(); + gfx3DMatrix matrix = To3DMatrix(GetTransform()); NS_ASSERTION(IsFrameVisible(mFrame, matrix), "We can't have hit a frame that isn't visible!"); @@ -5025,7 +5027,7 @@ nsRect nsDisplayTransform::GetBounds(nsDisplayListBuilder *aBuilder, bool* aSnap // GetTransform always operates in dev pixels. float factor = mFrame->PresContext()->AppUnitsPerDevPixel(); return nsLayoutUtils::MatrixTransformRect(untransformedBounds, - GetTransform(), + To3DMatrix(GetTransform()), factor); } @@ -5061,10 +5063,10 @@ nsRegion nsDisplayTransform::GetOpaqueRegion(nsDisplayListBuilder *aBuilder, return nsRegion(); } - const gfx3DMatrix& matrix = GetTransform(); + const Matrix4x4& matrix = GetTransform(); nsRegion result; - gfxMatrix matrix2d; + Matrix matrix2d; bool tmpSnap; if (matrix.Is2D(&matrix2d) && matrix2d.PreservesAxisAlignedRectangles() && @@ -5084,9 +5086,9 @@ bool nsDisplayTransform::IsUniform(nsDisplayListBuilder *aBuilder, nscolor* aCol if (!UntransformVisibleRect(aBuilder, &untransformedVisible)) { return false; } - const gfx3DMatrix& matrix = GetTransform(); + const Matrix4x4& matrix = GetTransform(); - gfxMatrix matrix2d; + Matrix matrix2d; return matrix.Is2D(&matrix2d) && matrix2d.PreservesAxisAlignedRectangles() && mStoredList.GetVisibleRect().Contains(untransformedVisible) && @@ -5211,7 +5213,7 @@ bool nsDisplayTransform::UntransformRect(const nsRect &aTransformedBounds, bool nsDisplayTransform::UntransformVisibleRect(nsDisplayListBuilder* aBuilder, nsRect *aOutRect) { - const gfx3DMatrix& matrix = GetTransform(); + const gfx3DMatrix& matrix = To3DMatrix(GetTransform()); if (matrix.IsSingular()) return false; @@ -5243,7 +5245,7 @@ void nsDisplayTransform::WriteDebugInfo(nsACString& aTo) { std::stringstream ss; - AppendToString(ss, gfx::ToMatrix4x4(GetTransform())); + AppendToString(ss, GetTransform()); aTo += ss.str().c_str(); } #endif diff --git a/layout/base/nsDisplayList.h b/layout/base/nsDisplayList.h index b7ae22899be9..c29918e5fad9 100644 --- a/layout/base/nsDisplayList.h +++ b/layout/base/nsDisplayList.h @@ -3157,6 +3157,7 @@ private: */ class nsDisplayTransform: public nsDisplayItem { + typedef mozilla::gfx::Matrix4x4 Matrix4x4; public: /** * Returns a matrix (in pixels) for the current frame. The matrix should be relative to @@ -3165,7 +3166,7 @@ public: * @param aFrame The frame to compute the transform for. * @param aAppUnitsPerPixel The number of app units per graphics unit. */ - typedef gfx3DMatrix (* ComputeTransformFunction)(nsIFrame* aFrame, float aAppUnitsPerPixel); + typedef Matrix4x4 (* ComputeTransformFunction)(nsIFrame* aFrame, float aAppUnitsPerPixel); /* Constructor accepts a display list, empties it, and wraps it up. It also * ferries the underlying frame to the nsDisplayItem constructor. @@ -3244,7 +3245,7 @@ public: INDEX_MAX = UINT32_MAX >> nsDisplayItem::TYPE_BITS }; - const gfx3DMatrix& GetTransform(); + const Matrix4x4& GetTransform(); float GetHitDepthAtPoint(nsDisplayListBuilder* aBuilder, const nsPoint& aPoint); @@ -3387,7 +3388,7 @@ private: bool aOffsetByOrigin); nsDisplayWrapList mStoredList; - gfx3DMatrix mTransform; + Matrix4x4 mTransform; ComputeTransformFunction mTransformGetter; nsRect mChildrenVisibleRect; uint32_t mIndex; diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 023cecbe2c19..20d6d71c9e42 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -2416,7 +2416,7 @@ nsLayoutUtils::GetLayerTransformForFrame(nsIFrame* aFrame, new (&builder) nsDisplayTransform(&builder, aFrame, &list, nsRect()); *aTransform = - item->GetTransform(); + To3DMatrix(item->GetTransform()); item->~nsDisplayTransform(); return true; diff --git a/layout/generic/nsPageFrame.cpp b/layout/generic/nsPageFrame.cpp index 0233e06e26fb..fed2b3937386 100644 --- a/layout/generic/nsPageFrame.cpp +++ b/layout/generic/nsPageFrame.cpp @@ -462,10 +462,10 @@ static void PaintHeaderFooter(nsIFrame* aFrame, nsRenderingContext* aCtx, static_cast(aFrame)->PaintHeaderFooter(*aCtx, aPt); } -static gfx3DMatrix ComputePageTransform(nsIFrame* aFrame, float aAppUnitsPerPixel) +static gfx::Matrix4x4 ComputePageTransform(nsIFrame* aFrame, float aAppUnitsPerPixel) { float scale = aFrame->PresContext()->GetPageScale(); - return gfx3DMatrix::ScalingMatrix(scale, scale, 1); + return gfx::Matrix4x4().Scale(scale, scale, 1); } //------------------------------------------------------------------------------ diff --git a/layout/generic/nsSimplePageSequenceFrame.cpp b/layout/generic/nsSimplePageSequenceFrame.cpp index 1e8b1d74f929..5fb154e044bd 100644 --- a/layout/generic/nsSimplePageSequenceFrame.cpp +++ b/layout/generic/nsSimplePageSequenceFrame.cpp @@ -766,11 +766,11 @@ nsSimplePageSequenceFrame::DoPageEnd() return rv; } -static gfx3DMatrix +static gfx::Matrix4x4 ComputePageSequenceTransform(nsIFrame* aFrame, float aAppUnitsPerPixel) { float scale = aFrame->PresContext()->GetPrintPreviewScale(); - return gfx3DMatrix::ScalingMatrix(scale, scale, 1); + return gfx::Matrix4x4().Scale(scale, scale, 1); } void