Bug 1153841 - Remove the 'it must be 2D' restriction for transforms on fixed-pos layers. r=BenWa,mattwoodrow

This commit is contained in:
Kartikaya Gupta
2015-06-19 22:57:37 -04:00
parent 9f00bd1344
commit a6b9fe6b1c

View File

@@ -141,12 +141,14 @@ AsyncCompositionManager::ComputeRotation()
} }
} }
static bool static void
GetBaseTransform2D(Layer* aLayer, Matrix* aTransform) GetBaseTransform(Layer* aLayer, Matrix4x4* aTransform)
{ {
// Start with the animated transform if there is one // Start with the animated transform if there is one
return (aLayer->AsLayerComposite()->GetShadowTransformSetByAnimation() ? *aTransform =
aLayer->GetLocalTransform() : aLayer->GetTransform()).Is2D(aTransform); (aLayer->AsLayerComposite()->GetShadowTransformSetByAnimation()
? aLayer->GetLocalTransform()
: aLayer->GetTransform());
} }
static void static void
@@ -183,9 +185,9 @@ SetShadowTransform(Layer* aLayer, Matrix4x4 aTransform)
} }
static void static void
TranslateShadowLayer2D(Layer* aLayer, TranslateShadowLayer(Layer* aLayer,
const gfxPoint& aTranslation, const gfxPoint& aTranslation,
bool aAdjustClipRect) bool aAdjustClipRect)
{ {
// This layer might also be a scrollable layer and have an async transform. // This layer might also be a scrollable layer and have an async transform.
// To make sure we don't clobber that, we start with the shadow transform. // To make sure we don't clobber that, we start with the shadow transform.
@@ -193,16 +195,12 @@ TranslateShadowLayer2D(Layer* aLayer,
// Note that the shadow transform is reset on every frame of composition so // Note that the shadow transform is reset on every frame of composition so
// we don't have to worry about the adjustments compounding over successive // we don't have to worry about the adjustments compounding over successive
// frames. // frames.
Matrix layerTransform; Matrix4x4 layerTransform = aLayer->GetLocalTransform();
if (!aLayer->GetLocalTransform().Is2D(&layerTransform)) {
return;
}
// Apply the 2D translation to the layer transform. // Apply the translation to the layer transform.
layerTransform._31 += aTranslation.x; layerTransform.PostTranslate(aTranslation.x, aTranslation.y, 0);
layerTransform._32 += aTranslation.y;
SetShadowTransform(aLayer, Matrix4x4::From2D(layerTransform)); SetShadowTransform(aLayer, layerTransform);
aLayer->AsLayerComposite()->SetShadowTransformSetByAnimation(false); aLayer->AsLayerComposite()->SetShadowTransformSetByAnimation(false);
if (aAdjustClipRect) { if (aAdjustClipRect) {
@@ -212,25 +210,21 @@ TranslateShadowLayer2D(Layer* aLayer,
// If a fixed- or sticky-position layer has a mask layer, that mask should // If a fixed- or sticky-position layer has a mask layer, that mask should
// move along with the layer, so apply the translation to the mask layer too. // move along with the layer, so apply the translation to the mask layer too.
if (Layer* maskLayer = aLayer->GetMaskLayer()) { if (Layer* maskLayer = aLayer->GetMaskLayer()) {
TranslateShadowLayer2D(maskLayer, aTranslation, false); TranslateShadowLayer(maskLayer, aTranslation, false);
} }
} }
static bool static void
AccumulateLayerTransforms2D(Layer* aLayer, AccumulateLayerTransforms(Layer* aLayer,
Layer* aAncestor, Layer* aAncestor,
Matrix& aMatrix) Matrix4x4& aMatrix)
{ {
// Accumulate the transforms between this layer and the subtree root layer. // Accumulate the transforms between this layer and the subtree root layer.
for (Layer* l = aLayer; l && l != aAncestor; l = l->GetParent()) { for (Layer* l = aLayer; l && l != aAncestor; l = l->GetParent()) {
Matrix l2D; Matrix4x4 transform;
if (!GetBaseTransform2D(l, &l2D)) { GetBaseTransform(l, &transform);
return false; aMatrix *= transform;
}
aMatrix *= l2D;
} }
return true;
} }
static LayerPoint static LayerPoint
@@ -312,37 +306,25 @@ AsyncCompositionManager::AlignFixedAndStickyLayers(Layer* aLayer,
// Insert a translation so that the position of the anchor point is the same // Insert a translation so that the position of the anchor point is the same
// before and after the change to the transform of aTransformedSubtreeRoot. // before and after the change to the transform of aTransformedSubtreeRoot.
// This currently only works for fixed layers with 2D transforms.
// Accumulate the transforms between this layer and the subtree root layer. // Accumulate the transforms between this layer and the subtree root layer.
Matrix ancestorTransform; Matrix4x4 ancestorTransform;
if (!AccumulateLayerTransforms2D(aLayer->GetParent(), aTransformedSubtreeRoot, AccumulateLayerTransforms(aLayer->GetParent(), aTransformedSubtreeRoot,
ancestorTransform)) { ancestorTransform);
return;
}
Matrix oldRootTransform;
Matrix newRootTransform;
if (!aPreviousTransformForRoot.Is2D(&oldRootTransform) ||
!aCurrentTransformForRoot.Is2D(&newRootTransform)) {
return;
}
// Calculate the cumulative transforms between the subtree root with the // Calculate the cumulative transforms between the subtree root with the
// old transform and the current transform. // old transform and the current transform.
Matrix oldCumulativeTransform = ancestorTransform * oldRootTransform; Matrix4x4 oldCumulativeTransform = ancestorTransform * aPreviousTransformForRoot;
Matrix newCumulativeTransform = ancestorTransform * newRootTransform; Matrix4x4 newCumulativeTransform = ancestorTransform * aCurrentTransformForRoot;
if (newCumulativeTransform.IsSingular()) { if (newCumulativeTransform.IsSingular()) {
return; return;
} }
Matrix newCumulativeTransformInverse = newCumulativeTransform.Inverse(); Matrix4x4 newCumulativeTransformInverse = newCumulativeTransform.Inverse();
// Now work out the translation necessary to make sure the layer doesn't // Now work out the translation necessary to make sure the layer doesn't
// move given the new sub-tree root transform. // move given the new sub-tree root transform.
Matrix layerTransform; Matrix4x4 layerTransform;
if (!GetBaseTransform2D(aLayer, &layerTransform)) { GetBaseTransform(aLayer, &layerTransform);
return;
}
// Calculate any offset necessary, in previous transform sub-tree root // Calculate any offset necessary, in previous transform sub-tree root
// space. This is used to make sure fixed position content respects // space. This is used to make sure fixed position content respects
@@ -387,7 +369,7 @@ AsyncCompositionManager::AlignFixedAndStickyLayers(Layer* aLayer,
IntervalOverlap(translation.x, stickyInner.x, stickyInner.XMost()); IntervalOverlap(translation.x, stickyInner.x, stickyInner.XMost());
} }
// Finally, apply the 2D translation to the layer transform. Note that in // Finally, apply the translation to the layer transform. Note that in
// general we need to apply the same translation to the layer's clip rect, so // general we need to apply the same translation to the layer's clip rect, so
// that the effective transform on the clip rect takes it back to where it was // that the effective transform on the clip rect takes it back to where it was
// originally, had there been no async scroll. In the case where the // originally, had there been no async scroll. In the case where the
@@ -395,7 +377,7 @@ AsyncCompositionManager::AlignFixedAndStickyLayers(Layer* aLayer,
// rect is not affected by the scroll-induced async scroll transform anyway // rect is not affected by the scroll-induced async scroll transform anyway
// (since the clip is applied post-transform) so we don't need to make the // (since the clip is applied post-transform) so we don't need to make the
// adjustment. // adjustment.
TranslateShadowLayer2D(aLayer, ThebesPoint(translation), aLayer != aTransformedSubtreeRoot); TranslateShadowLayer(aLayer, ThebesPoint(translation), aLayer != aTransformedSubtreeRoot);
} }
static void static void