From 6fa0d2f621ac7352072a71afade8108f2255ab31 Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Thu, 26 Nov 2015 22:32:35 +1300 Subject: [PATCH] Bug 1168263 - Simplify GetResultingTransformMatrix calculations to avoid unnecessary origin changes. r=roc --- .../composite/AsyncCompositionManager.cpp | 9 ++---- gfx/layers/ipc/LayerTransactionParent.cpp | 7 ++--- layout/base/nsDisplayList.cpp | 28 ++++++++++--------- 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/gfx/layers/composite/AsyncCompositionManager.cpp b/gfx/layers/composite/AsyncCompositionManager.cpp index 2ed95fabd11b..8b430bd67cea 100644 --- a/gfx/layers/composite/AsyncCompositionManager.cpp +++ b/gfx/layers/composite/AsyncCompositionManager.cpp @@ -533,13 +533,8 @@ SampleValue(float aPortion, Animation& aAnimation, StyleAnimationValue& aStart, Matrix4x4 transform = nsDisplayTransform::GetResultingTransformMatrix(props, origin, data.appUnitsPerDevPixel(), - 0, &data.bounds()); - Point3D scaledOrigin = - Point3D(NS_round(NSAppUnitsToFloatPixels(origin.x, data.appUnitsPerDevPixel())), - NS_round(NSAppUnitsToFloatPixels(origin.y, data.appUnitsPerDevPixel())), - 0.0f); - - transform.PreTranslate(scaledOrigin); + nsDisplayTransform::OFFSET_BY_ORIGIN, + &data.bounds()); InfallibleTArray functions; functions.AppendElement(TransformMatrix(transform)); diff --git a/gfx/layers/ipc/LayerTransactionParent.cpp b/gfx/layers/ipc/LayerTransactionParent.cpp index 994db444df31..287c818116c4 100644 --- a/gfx/layers/ipc/LayerTransactionParent.cpp +++ b/gfx/layers/ipc/LayerTransactionParent.cpp @@ -744,14 +744,11 @@ LayerTransactionParent::RecvGetAnimationTransform(PLayerParent* aParent, } } - // Undo the translation to the origin of the reference frame applied by - // AsyncCompositionManager::SampleValue - transform.PreTranslate(-scaledOrigin.x, -scaledOrigin.y, -scaledOrigin.z); + transform.PostTranslate(-scaledOrigin.x, -scaledOrigin.y, -scaledOrigin.z); // Undo the rebasing applied by // nsDisplayTransform::GetResultingTransformMatrixInternal - Point3D basis = -scaledOrigin - transformOrigin; - transform.ChangeBasis(basis.x, basis.y, basis.z); + transform.ChangeBasis(-transformOrigin); // Convert to CSS pixels (this undoes the operations performed by // nsStyleTransformMatrix::ProcessTranslatePart which is called from diff --git a/layout/base/nsDisplayList.cpp b/layout/base/nsDisplayList.cpp index c8135937efd7..087fc44543fb 100644 --- a/layout/base/nsDisplayList.cpp +++ b/layout/base/nsDisplayList.cpp @@ -5134,13 +5134,17 @@ nsDisplayTransform::GetDeltaToPerspectiveOrigin(const nsIFrame* aFrame, } } - nsPoint parentOffset = aFrame->GetOffsetTo(cbFrame); - Point3D gfxOffset( - NSAppUnitsToFloatPixels(parentOffset.x, aAppUnitsPerPixel), - NSAppUnitsToFloatPixels(parentOffset.y, aAppUnitsPerPixel), + /* GetOffsetTo computes the offset required to move from 0,0 in cbFrame to 0,0 + * in aFrame. Although we actually want the inverse of this, it's faster to + * compute this way. + */ + nsPoint frameToCbOffset = -aFrame->GetOffsetTo(cbFrame); + Point3D frameToCbGfxOffset( + NSAppUnitsToFloatPixels(frameToCbOffset.x, aAppUnitsPerPixel), + NSAppUnitsToFloatPixels(frameToCbOffset.y, aAppUnitsPerPixel), 0.0f); - return result - gfxOffset; + return result + frameToCbGfxOffset; } nsDisplayTransform::FrameTransformProperties::FrameTransformProperties(const nsIFrame* aFrame, @@ -5266,7 +5270,6 @@ nsDisplayTransform::GetResultingTransformMatrixInternal(const FrameTransformProp // This is a simplification of the following |else| block, the // simplification being possible because we don't need to apply // mToTransformOrigin between two transforms. - Point3D offsets = roundedOrigin + aProperties.mToTransformOrigin; if ((aFlags & OFFSET_BY_ORIGIN) && !hasPerspective) { // We can fold the final translation by roundedOrigin into the first matrix @@ -5274,9 +5277,9 @@ nsDisplayTransform::GetResultingTransformMatrixInternal(const FrameTransformProp // insufficient floating point precision than reversing the translation // afterwards. result.PreTranslate(-aProperties.mToTransformOrigin); - result.PostTranslate(offsets); + result.PostTranslate(roundedOrigin + aProperties.mToTransformOrigin); } else { - result.ChangeBasis(offsets); + result.ChangeBasis(aProperties.mToTransformOrigin); } } else { Point3D refBoxOffset(NSAppUnitsToFloatPixels(refBox.X(), aAppUnitsPerPixel), @@ -5301,13 +5304,12 @@ nsDisplayTransform::GetResultingTransformMatrixInternal(const FrameTransformProp // Similar to the code in the |if| block above, but since we've accounted // for mToTransformOrigin so we don't include that. We also need to reapply // refBoxOffset. - Point3D offsets = roundedOrigin + refBoxOffset; if ((aFlags & OFFSET_BY_ORIGIN) && !hasPerspective) { result.PreTranslate(-refBoxOffset); - result.PostTranslate(offsets); + result.PostTranslate(roundedOrigin + refBoxOffset); } else { - result.ChangeBasis(offsets); + result.ChangeBasis(refBoxOffset); } } @@ -5316,11 +5318,11 @@ nsDisplayTransform::GetResultingTransformMatrixInternal(const FrameTransformProp perspective._34 = -1.0 / NSAppUnitsToFloatPixels(aProperties.mChildPerspective, aAppUnitsPerPixel); - perspective.ChangeBasis(aProperties.GetToPerspectiveOrigin() + roundedOrigin); + perspective.ChangeBasis(aProperties.GetToPerspectiveOrigin()); result = result * perspective; if (aFlags & OFFSET_BY_ORIGIN) { - result.PreTranslate(roundedOrigin); + result.PostTranslate(roundedOrigin); } }