2013-04-28 10:46:30 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set sw=2 ts=2 et tw=80 : */
|
|
|
|
/* 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 "mozilla/layers/AsyncCompositionManager.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include <stdint.h> // for uint32_t
|
|
|
|
#include "AnimationCommon.h" // for ComputedTimingFunction
|
|
|
|
#include "CompositorParent.h" // for CompositorParent, etc
|
|
|
|
#include "FrameMetrics.h" // for FrameMetrics
|
|
|
|
#include "LayerManagerComposite.h" // for LayerManagerComposite, etc
|
|
|
|
#include "Layers.h" // for Layer, ContainerLayer, etc
|
|
|
|
#include "gfxPoint.h" // for gfxPoint, gfxSize
|
|
|
|
#include "gfxPoint3D.h" // for gfxPoint3D
|
|
|
|
#include "mozilla/WidgetUtils.h" // for ComputeTransformForRotation
|
|
|
|
#include "mozilla/gfx/BaseRect.h" // for BaseRect
|
|
|
|
#include "mozilla/gfx/Point.h" // for RoundedToInt, PointTyped
|
|
|
|
#include "mozilla/gfx/Rect.h" // for RoundedToInt, RectTyped
|
|
|
|
#include "mozilla/gfx/ScaleFactor.h" // for ScaleFactor
|
|
|
|
#include "mozilla/layers/AsyncPanZoomController.h"
|
|
|
|
#include "mozilla/layers/Compositor.h" // for Compositor
|
|
|
|
#include "nsAnimationManager.h" // for ElementAnimations
|
|
|
|
#include "nsCSSPropList.h"
|
|
|
|
#include "nsCoord.h" // for NSAppUnitsToFloatPixels, etc
|
|
|
|
#include "nsDebug.h" // for NS_ASSERTION, etc
|
|
|
|
#include "nsDeviceContext.h" // for nsDeviceContext
|
|
|
|
#include "nsDisplayList.h" // for nsDisplayTransform, etc
|
|
|
|
#include "nsMathUtils.h" // for NS_round
|
|
|
|
#include "nsPoint.h" // for nsPoint
|
|
|
|
#include "nsRect.h" // for nsIntRect
|
|
|
|
#include "nsRegion.h" // for nsIntRegion
|
2014-06-24 10:29:54 +04:00
|
|
|
#include "nsStyleAnimation.h" // for StyleAnimationValue, etc
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "nsTArray.h" // for nsTArray, nsTArray_Impl, etc
|
|
|
|
#include "nsTArrayForwardDeclare.h" // for InfallibleTArray
|
2013-04-28 10:46:30 +04:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
# include <android/log.h>
|
|
|
|
# include "AndroidBridge.h"
|
|
|
|
#endif
|
2013-09-10 23:56:49 +04:00
|
|
|
#include "GeckoProfiler.h"
|
2013-04-28 10:46:30 +04:00
|
|
|
|
2013-12-12 06:09:44 +04:00
|
|
|
struct nsCSSValueSharedList;
|
2013-04-28 10:46:30 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2014-05-22 14:11:45 +04:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2013-04-28 10:46:30 +04:00
|
|
|
enum Op { Resolve, Detach };
|
|
|
|
|
|
|
|
static bool
|
2014-05-22 14:11:45 +04:00
|
|
|
IsSameDimension(dom::ScreenOrientation o1, dom::ScreenOrientation o2)
|
2013-04-28 10:46:30 +04:00
|
|
|
{
|
2014-05-22 14:11:45 +04:00
|
|
|
bool isO1portrait = (o1 == dom::eScreenOrientation_PortraitPrimary || o1 == dom::eScreenOrientation_PortraitSecondary);
|
|
|
|
bool isO2portrait = (o2 == dom::eScreenOrientation_PortraitPrimary || o2 == dom::eScreenOrientation_PortraitSecondary);
|
2013-04-28 10:46:30 +04:00
|
|
|
return !(isO1portrait ^ isO2portrait);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
ContentMightReflowOnOrientationChange(const nsIntRect& rect)
|
|
|
|
{
|
|
|
|
return rect.width != rect.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<Op OP>
|
|
|
|
static void
|
|
|
|
WalkTheTree(Layer* aLayer,
|
|
|
|
bool& aReady,
|
|
|
|
const TargetConfig& aTargetConfig)
|
|
|
|
{
|
|
|
|
if (RefLayer* ref = aLayer->AsRefLayer()) {
|
|
|
|
if (const CompositorParent::LayerTreeState* state = CompositorParent::GetIndirectShadowTree(ref->GetReferentId())) {
|
|
|
|
if (Layer* referent = state->mRoot) {
|
|
|
|
if (!ref->GetVisibleRegion().IsEmpty()) {
|
2014-05-22 14:11:45 +04:00
|
|
|
dom::ScreenOrientation chromeOrientation = aTargetConfig.orientation();
|
|
|
|
dom::ScreenOrientation contentOrientation = state->mTargetConfig.orientation();
|
2013-04-28 10:46:30 +04:00
|
|
|
if (!IsSameDimension(chromeOrientation, contentOrientation) &&
|
|
|
|
ContentMightReflowOnOrientationChange(aTargetConfig.clientBounds())) {
|
|
|
|
aReady = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OP == Resolve) {
|
|
|
|
ref->ConnectReferentLayer(referent);
|
|
|
|
} else {
|
|
|
|
ref->DetachReferentLayer(referent);
|
2014-06-11 09:44:39 +04:00
|
|
|
WalkTheTree<OP>(referent, aReady, aTargetConfig);
|
2013-04-28 10:46:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (Layer* child = aLayer->GetFirstChild();
|
|
|
|
child; child = child->GetNextSibling()) {
|
2013-06-29 22:53:49 +04:00
|
|
|
WalkTheTree<OP>(child, aReady, aTargetConfig);
|
2013-04-28 10:46:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AsyncCompositionManager::ResolveRefLayers()
|
|
|
|
{
|
2014-02-11 08:01:20 +04:00
|
|
|
if (!mLayerManager->GetRoot()) {
|
|
|
|
return;
|
|
|
|
}
|
2014-04-24 13:43:00 +04:00
|
|
|
|
|
|
|
mReadyForCompose = true;
|
2013-04-28 10:46:30 +04:00
|
|
|
WalkTheTree<Resolve>(mLayerManager->GetRoot(),
|
|
|
|
mReadyForCompose,
|
|
|
|
mTargetConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AsyncCompositionManager::DetachRefLayers()
|
|
|
|
{
|
2014-02-11 08:01:20 +04:00
|
|
|
if (!mLayerManager->GetRoot()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-04-28 10:46:30 +04:00
|
|
|
WalkTheTree<Detach>(mLayerManager->GetRoot(),
|
|
|
|
mReadyForCompose,
|
|
|
|
mTargetConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AsyncCompositionManager::ComputeRotation()
|
|
|
|
{
|
|
|
|
if (!mTargetConfig.naturalBounds().IsEmpty()) {
|
|
|
|
mLayerManager->SetWorldTransform(
|
|
|
|
ComputeTransformForRotation(mTargetConfig.naturalBounds(),
|
|
|
|
mTargetConfig.rotation()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-24 05:34:33 +04:00
|
|
|
static bool
|
2014-01-27 19:28:47 +04:00
|
|
|
GetBaseTransform2D(Layer* aLayer, Matrix* aTransform)
|
2013-04-28 10:46:30 +04:00
|
|
|
{
|
2013-06-24 05:34:33 +04:00
|
|
|
// Start with the animated transform if there is one
|
|
|
|
return (aLayer->AsLayerComposite()->GetShadowTransformSetByAnimation() ?
|
2014-01-27 19:28:47 +04:00
|
|
|
aLayer->GetLocalTransform() : aLayer->GetTransform()).Is2D(aTransform);
|
2013-04-28 10:46:30 +04:00
|
|
|
}
|
|
|
|
|
2013-07-22 12:50:05 +04:00
|
|
|
static void
|
|
|
|
TranslateShadowLayer2D(Layer* aLayer,
|
|
|
|
const gfxPoint& aTranslation)
|
|
|
|
{
|
2014-01-27 19:28:47 +04:00
|
|
|
Matrix layerTransform;
|
2013-07-22 12:50:05 +04:00
|
|
|
if (!GetBaseTransform2D(aLayer, &layerTransform)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply the 2D translation to the layer transform.
|
2014-01-27 19:28:47 +04:00
|
|
|
layerTransform._31 += aTranslation.x;
|
|
|
|
layerTransform._32 += aTranslation.y;
|
2013-07-22 12:50:05 +04:00
|
|
|
|
|
|
|
// The transform already takes the resolution scale into account. Since we
|
|
|
|
// will apply the resolution scale again when computing the effective
|
|
|
|
// transform, we must apply the inverse resolution scale here.
|
2014-01-27 19:28:47 +04:00
|
|
|
Matrix4x4 layerTransform3D = Matrix4x4::From2D(layerTransform);
|
2013-07-22 12:50:05 +04:00
|
|
|
if (ContainerLayer* c = aLayer->AsContainerLayer()) {
|
|
|
|
layerTransform3D.Scale(1.0f/c->GetPreXScale(),
|
|
|
|
1.0f/c->GetPreYScale(),
|
|
|
|
1);
|
|
|
|
}
|
2014-01-27 19:28:47 +04:00
|
|
|
layerTransform3D = layerTransform3D *
|
|
|
|
Matrix4x4().Scale(1.0f/aLayer->GetPostXScale(),
|
|
|
|
1.0f/aLayer->GetPostYScale(),
|
|
|
|
1);
|
2013-07-22 12:50:05 +04:00
|
|
|
|
|
|
|
LayerComposite* layerComposite = aLayer->AsLayerComposite();
|
2014-01-27 19:29:27 +04:00
|
|
|
layerComposite->SetShadowTransform(layerTransform3D);
|
2013-07-22 12:50:05 +04:00
|
|
|
layerComposite->SetShadowTransformSetByAnimation(false);
|
|
|
|
|
|
|
|
const nsIntRect* clipRect = aLayer->GetClipRect();
|
|
|
|
if (clipRect) {
|
|
|
|
nsIntRect transformedClipRect(*clipRect);
|
|
|
|
transformedClipRect.MoveBy(aTranslation.x, aTranslation.y);
|
|
|
|
layerComposite->SetShadowClipRect(&transformedClipRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
AccumulateLayerTransforms2D(Layer* aLayer,
|
|
|
|
Layer* aAncestor,
|
2014-01-28 00:25:21 +04:00
|
|
|
Matrix& aMatrix)
|
2013-07-22 12:50:05 +04:00
|
|
|
{
|
|
|
|
// Accumulate the transforms between this layer and the subtree root layer.
|
|
|
|
for (Layer* l = aLayer; l && l != aAncestor; l = l->GetParent()) {
|
2014-01-27 19:28:47 +04:00
|
|
|
Matrix l2D;
|
2013-07-22 12:50:05 +04:00
|
|
|
if (!GetBaseTransform2D(l, &l2D)) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-28 00:25:21 +04:00
|
|
|
aMatrix *= l2D;
|
2013-07-22 12:50:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-22 12:50:09 +04:00
|
|
|
static LayerPoint
|
2013-07-22 12:50:05 +04:00
|
|
|
GetLayerFixedMarginsOffset(Layer* aLayer,
|
2013-07-22 12:50:13 +04:00
|
|
|
const LayerMargin& aFixedLayerMargins)
|
2013-07-22 12:50:05 +04:00
|
|
|
{
|
|
|
|
// Work out the necessary translation, in root scrollable layer space.
|
|
|
|
// Because fixed layer margins are stored relative to the root scrollable
|
|
|
|
// layer, we can just take the difference between these values.
|
2013-07-22 12:50:09 +04:00
|
|
|
LayerPoint translation;
|
|
|
|
const LayerPoint& anchor = aLayer->GetFixedPositionAnchor();
|
2013-07-22 12:50:13 +04:00
|
|
|
const LayerMargin& fixedMargins = aLayer->GetFixedPositionMargins();
|
2013-07-22 12:50:05 +04:00
|
|
|
|
|
|
|
if (fixedMargins.left >= 0) {
|
|
|
|
if (anchor.x > 0) {
|
|
|
|
translation.x -= aFixedLayerMargins.right - fixedMargins.right;
|
|
|
|
} else {
|
|
|
|
translation.x += aFixedLayerMargins.left - fixedMargins.left;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fixedMargins.top >= 0) {
|
|
|
|
if (anchor.y > 0) {
|
|
|
|
translation.y -= aFixedLayerMargins.bottom - fixedMargins.bottom;
|
|
|
|
} else {
|
|
|
|
translation.y += aFixedLayerMargins.top - fixedMargins.top;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return translation;
|
|
|
|
}
|
|
|
|
|
2013-09-12 08:24:32 +04:00
|
|
|
static gfxFloat
|
|
|
|
IntervalOverlap(gfxFloat aTranslation, gfxFloat aMin, gfxFloat aMax)
|
|
|
|
{
|
|
|
|
// Determine the amount of overlap between the 1D vector |aTranslation|
|
|
|
|
// and the interval [aMin, aMax].
|
|
|
|
if (aTranslation > 0) {
|
|
|
|
return std::max(0.0, std::min(aMax, aTranslation) - std::max(aMin, 0.0));
|
|
|
|
} else {
|
|
|
|
return std::min(0.0, std::max(aMin, aTranslation) - std::min(aMax, 0.0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-28 10:46:30 +04:00
|
|
|
void
|
2013-09-12 08:24:32 +04:00
|
|
|
AsyncCompositionManager::AlignFixedAndStickyLayers(Layer* aLayer,
|
|
|
|
Layer* aTransformedSubtreeRoot,
|
2014-01-28 00:25:21 +04:00
|
|
|
const Matrix4x4& aPreviousTransformForRoot,
|
2014-06-13 04:27:32 +04:00
|
|
|
const Matrix4x4& aCurrentTransformForRoot,
|
2013-09-12 08:24:32 +04:00
|
|
|
const LayerMargin& aFixedLayerMargins)
|
2013-04-28 10:46:30 +04:00
|
|
|
{
|
2013-09-12 08:24:32 +04:00
|
|
|
bool isRootFixed = aLayer->GetIsFixedPosition() &&
|
|
|
|
!aLayer->GetParent()->GetIsFixedPosition();
|
|
|
|
bool isStickyForSubtree = aLayer->GetIsStickyPosition() &&
|
|
|
|
aTransformedSubtreeRoot->AsContainerLayer() &&
|
|
|
|
aLayer->GetStickyScrollContainerId() ==
|
2014-03-22 01:48:08 +04:00
|
|
|
aTransformedSubtreeRoot->AsContainerLayer()->GetFrameMetrics().GetScrollId();
|
2013-09-12 08:24:32 +04:00
|
|
|
if (aLayer != aTransformedSubtreeRoot && (isRootFixed || isStickyForSubtree)) {
|
2013-06-24 05:34:33 +04:00
|
|
|
// Insert a translation so that the position of the anchor point is the same
|
|
|
|
// 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.
|
2014-01-28 00:25:21 +04:00
|
|
|
Matrix ancestorTransform;
|
2013-07-22 12:50:05 +04:00
|
|
|
if (!AccumulateLayerTransforms2D(aLayer->GetParent(), aTransformedSubtreeRoot,
|
|
|
|
ancestorTransform)) {
|
|
|
|
return;
|
2013-04-28 10:46:30 +04:00
|
|
|
}
|
|
|
|
|
2014-01-28 00:25:21 +04:00
|
|
|
Matrix oldRootTransform;
|
2014-01-27 19:28:18 +04:00
|
|
|
Matrix newRootTransform;
|
2013-06-24 05:34:33 +04:00
|
|
|
if (!aPreviousTransformForRoot.Is2D(&oldRootTransform) ||
|
2014-06-13 04:27:32 +04:00
|
|
|
!aCurrentTransformForRoot.Is2D(&newRootTransform)) {
|
2013-06-24 05:34:33 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the cumulative transforms between the subtree root with the
|
|
|
|
// old transform and the current transform.
|
2014-01-28 00:25:21 +04:00
|
|
|
Matrix oldCumulativeTransform = ancestorTransform * oldRootTransform;
|
|
|
|
Matrix newCumulativeTransform = ancestorTransform * newRootTransform;
|
2013-06-24 05:34:33 +04:00
|
|
|
if (newCumulativeTransform.IsSingular()) {
|
|
|
|
return;
|
|
|
|
}
|
2014-01-28 00:25:21 +04:00
|
|
|
Matrix newCumulativeTransformInverse = newCumulativeTransform;
|
2013-06-24 05:34:33 +04:00
|
|
|
newCumulativeTransformInverse.Invert();
|
|
|
|
|
2013-07-22 12:50:09 +04:00
|
|
|
// Now work out the translation necessary to make sure the layer doesn't
|
|
|
|
// move given the new sub-tree root transform.
|
2014-01-27 19:28:47 +04:00
|
|
|
Matrix layerTransform;
|
2013-07-22 12:50:09 +04:00
|
|
|
if (!GetBaseTransform2D(aLayer, &layerTransform)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-22 12:50:05 +04:00
|
|
|
// Calculate any offset necessary, in previous transform sub-tree root
|
|
|
|
// space. This is used to make sure fixed position content respects
|
|
|
|
// content document fixed position margins.
|
2013-07-22 12:50:09 +04:00
|
|
|
LayerPoint offsetInOldSubtreeLayerSpace = GetLayerFixedMarginsOffset(aLayer, aFixedLayerMargins);
|
|
|
|
|
|
|
|
// Add the above offset to the anchor point so we can offset the layer by
|
|
|
|
// and amount that's specified in old subtree layer space.
|
|
|
|
const LayerPoint& anchorInOldSubtreeLayerSpace = aLayer->GetFixedPositionAnchor();
|
|
|
|
LayerPoint offsetAnchorInOldSubtreeLayerSpace = anchorInOldSubtreeLayerSpace + offsetInOldSubtreeLayerSpace;
|
|
|
|
|
|
|
|
// Add the local layer transform to the two points to make the equation
|
|
|
|
// below this section more convenient.
|
2014-01-27 19:28:47 +04:00
|
|
|
Point anchor(anchorInOldSubtreeLayerSpace.x, anchorInOldSubtreeLayerSpace.y);
|
|
|
|
Point offsetAnchor(offsetAnchorInOldSubtreeLayerSpace.x, offsetAnchorInOldSubtreeLayerSpace.y);
|
|
|
|
Point locallyTransformedAnchor = layerTransform * anchor;
|
|
|
|
Point locallyTransformedOffsetAnchor = layerTransform * offsetAnchor;
|
2013-07-22 12:50:05 +04:00
|
|
|
|
2013-06-24 05:34:33 +04:00
|
|
|
// Transforming the locallyTransformedAnchor by oldCumulativeTransform
|
|
|
|
// returns the layer's anchor point relative to the parent of
|
|
|
|
// aTransformedSubtreeRoot, before the new transform was applied.
|
|
|
|
// Then, applying newCumulativeTransformInverse maps that point relative
|
|
|
|
// to the layer's parent, which is the same coordinate space as
|
|
|
|
// locallyTransformedAnchor again, allowing us to subtract them and find
|
|
|
|
// out the offset necessary to make sure the layer stays stationary.
|
2014-01-28 00:25:21 +04:00
|
|
|
Point oldAnchorPositionInNewSpace =
|
|
|
|
newCumulativeTransformInverse * (oldCumulativeTransform * locallyTransformedOffsetAnchor);
|
|
|
|
Point translation = oldAnchorPositionInNewSpace - locallyTransformedAnchor;
|
2013-06-24 05:34:33 +04:00
|
|
|
|
2013-09-12 08:24:32 +04:00
|
|
|
if (aLayer->GetIsStickyPosition()) {
|
|
|
|
// For sticky positioned layers, the difference between the two rectangles
|
|
|
|
// defines a pair of translation intervals in each dimension through which
|
|
|
|
// the layer should not move relative to the scroll container. To
|
|
|
|
// accomplish this, we limit each dimension of the |translation| to that
|
|
|
|
// part of it which overlaps those intervals.
|
|
|
|
const LayerRect& stickyOuter = aLayer->GetStickyScrollRangeOuter();
|
|
|
|
const LayerRect& stickyInner = aLayer->GetStickyScrollRangeInner();
|
|
|
|
|
|
|
|
translation.y = IntervalOverlap(translation.y, stickyOuter.y, stickyOuter.YMost()) -
|
|
|
|
IntervalOverlap(translation.y, stickyInner.y, stickyInner.YMost());
|
|
|
|
translation.x = IntervalOverlap(translation.x, stickyOuter.x, stickyOuter.XMost()) -
|
|
|
|
IntervalOverlap(translation.x, stickyInner.x, stickyInner.XMost());
|
|
|
|
}
|
|
|
|
|
2013-06-24 05:34:33 +04:00
|
|
|
// Finally, apply the 2D translation to the layer transform.
|
2014-01-28 00:25:21 +04:00
|
|
|
TranslateShadowLayer2D(aLayer, ThebesPoint(translation));
|
2013-04-28 10:46:30 +04:00
|
|
|
|
|
|
|
// The transform has now been applied, so there's no need to iterate over
|
|
|
|
// child layers.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-15 16:15:50 +04:00
|
|
|
// Fixed layers are relative to their nearest scrollable layer, so when we
|
2014-06-13 00:40:35 +04:00
|
|
|
// encounter a scrollable layer, bail. ApplyAsyncContentTransformToTree will
|
|
|
|
// have already recursed on this layer and called AlignFixedAndStickyLayers
|
|
|
|
// on it with its own transforms.
|
2014-01-15 16:15:50 +04:00
|
|
|
if (aLayer->AsContainerLayer() &&
|
|
|
|
aLayer->AsContainerLayer()->GetFrameMetrics().IsScrollable() &&
|
|
|
|
aLayer != aTransformedSubtreeRoot) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-28 10:46:30 +04:00
|
|
|
for (Layer* child = aLayer->GetFirstChild();
|
|
|
|
child; child = child->GetNextSibling()) {
|
2013-09-12 08:24:32 +04:00
|
|
|
AlignFixedAndStickyLayers(child, aTransformedSubtreeRoot,
|
2014-06-13 04:27:32 +04:00
|
|
|
aPreviousTransformForRoot,
|
|
|
|
aCurrentTransformForRoot, aFixedLayerMargins);
|
2013-04-28 10:46:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-06-24 10:29:54 +04:00
|
|
|
SampleValue(float aPortion, Animation& aAnimation, StyleAnimationValue& aStart,
|
|
|
|
StyleAnimationValue& aEnd, Animatable* aValue)
|
2013-04-28 10:46:30 +04:00
|
|
|
{
|
2014-06-24 10:29:54 +04:00
|
|
|
StyleAnimationValue interpolatedValue;
|
2013-04-28 10:46:30 +04:00
|
|
|
NS_ASSERTION(aStart.GetUnit() == aEnd.GetUnit() ||
|
2014-06-24 10:29:54 +04:00
|
|
|
aStart.GetUnit() == StyleAnimationValue::eUnit_None ||
|
|
|
|
aEnd.GetUnit() == StyleAnimationValue::eUnit_None,
|
|
|
|
"Must have same unit");
|
|
|
|
StyleAnimationValue::Interpolate(aAnimation.property(), aStart, aEnd,
|
2013-04-28 10:46:30 +04:00
|
|
|
aPortion, interpolatedValue);
|
|
|
|
if (aAnimation.property() == eCSSProperty_opacity) {
|
|
|
|
*aValue = interpolatedValue.GetFloatValue();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-12-12 06:09:44 +04:00
|
|
|
nsCSSValueSharedList* interpolatedList =
|
|
|
|
interpolatedValue.GetCSSValueSharedListValue();
|
2013-04-28 10:46:30 +04:00
|
|
|
|
|
|
|
TransformData& data = aAnimation.data().get_TransformData();
|
|
|
|
nsPoint origin = data.origin();
|
|
|
|
// we expect all our transform data to arrive in css pixels, so here we must
|
|
|
|
// adjust to dev pixels.
|
|
|
|
double cssPerDev = double(nsDeviceContext::AppUnitsPerCSSPixel())
|
|
|
|
/ double(data.appUnitsPerDevPixel());
|
2013-10-24 16:46:00 +04:00
|
|
|
gfxPoint3D transformOrigin = data.transformOrigin();
|
|
|
|
transformOrigin.x = transformOrigin.x * cssPerDev;
|
|
|
|
transformOrigin.y = transformOrigin.y * cssPerDev;
|
2013-04-28 10:46:30 +04:00
|
|
|
gfxPoint3D perspectiveOrigin = data.perspectiveOrigin();
|
|
|
|
perspectiveOrigin.x = perspectiveOrigin.x * cssPerDev;
|
|
|
|
perspectiveOrigin.y = perspectiveOrigin.y * cssPerDev;
|
|
|
|
nsDisplayTransform::FrameTransformProperties props(interpolatedList,
|
2013-10-24 16:46:00 +04:00
|
|
|
transformOrigin,
|
2013-04-28 10:46:30 +04:00
|
|
|
perspectiveOrigin,
|
|
|
|
data.perspective());
|
|
|
|
gfx3DMatrix transform =
|
|
|
|
nsDisplayTransform::GetResultingTransformMatrix(props, origin,
|
|
|
|
data.appUnitsPerDevPixel(),
|
|
|
|
&data.bounds());
|
|
|
|
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;
|
2014-01-27 19:28:33 +04:00
|
|
|
Matrix4x4 realTransform;
|
|
|
|
ToMatrix4x4(transform, realTransform);
|
|
|
|
functions.AppendElement(TransformMatrix(realTransform));
|
2013-04-28 10:46:30 +04:00
|
|
|
*aValue = functions;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
SampleAnimations(Layer* aLayer, TimeStamp aPoint)
|
|
|
|
{
|
|
|
|
AnimationArray& animations = aLayer->GetAnimations();
|
|
|
|
InfallibleTArray<AnimData>& animationData = aLayer->GetAnimationData();
|
|
|
|
|
|
|
|
bool activeAnimations = false;
|
|
|
|
|
|
|
|
for (uint32_t i = animations.Length(); i-- !=0; ) {
|
|
|
|
Animation& animation = animations[i];
|
|
|
|
AnimData& animData = animationData[i];
|
|
|
|
|
2014-03-05 05:19:15 +04:00
|
|
|
activeAnimations = true;
|
|
|
|
|
|
|
|
TimeDuration elapsedDuration = aPoint - animation.startTime();
|
|
|
|
// Skip animations that are yet to start.
|
|
|
|
//
|
|
|
|
// Currently, this should only happen when the refresh driver is under test
|
|
|
|
// control and is made to produce a time in the past or is restored from
|
|
|
|
// test control causing it to jump backwards in time.
|
|
|
|
//
|
|
|
|
// Since activeAnimations is true, this could mean we keep compositing
|
|
|
|
// unnecessarily during the delay, but so long as this only happens while
|
|
|
|
// the refresh driver is under test control that should be ok.
|
|
|
|
if (elapsedDuration.ToSeconds() < 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-05-28 11:51:49 +04:00
|
|
|
AnimationTiming timing;
|
|
|
|
timing.mIterationDuration = animation.duration();
|
2014-06-20 07:39:23 +04:00
|
|
|
// Currently animations run on the compositor have their delay factored
|
|
|
|
// into their start time, hence the delay is effectively zero.
|
|
|
|
timing.mDelay = TimeDuration(0);
|
2014-05-28 11:51:50 +04:00
|
|
|
timing.mIterationCount = animation.iterationCount();
|
2014-05-28 11:51:49 +04:00
|
|
|
timing.mDirection = animation.direction();
|
|
|
|
// Animations typically only run on the compositor during their active
|
|
|
|
// interval but if we end up sampling them outside that range (for
|
|
|
|
// example, while they are waiting to be removed) we currently just
|
|
|
|
// assume that we should fill.
|
|
|
|
timing.mFillMode = NS_STYLE_ANIMATION_FILL_MODE_BOTH;
|
|
|
|
|
2014-05-28 11:51:49 +04:00
|
|
|
ComputedTiming computedTiming =
|
2014-05-28 11:51:50 +04:00
|
|
|
ElementAnimation::GetComputedTimingAt(elapsedDuration, timing);
|
2013-04-28 10:46:30 +04:00
|
|
|
|
2014-05-28 11:51:49 +04:00
|
|
|
NS_ABORT_IF_FALSE(0.0 <= computedTiming.mTimeFraction &&
|
|
|
|
computedTiming.mTimeFraction <= 1.0,
|
|
|
|
"time fraction should be in [0-1]");
|
2013-04-28 10:46:30 +04:00
|
|
|
|
|
|
|
int segmentIndex = 0;
|
|
|
|
AnimationSegment* segment = animation.segments().Elements();
|
2014-05-28 11:51:49 +04:00
|
|
|
while (segment->endPortion() < computedTiming.mTimeFraction) {
|
2013-04-28 10:46:30 +04:00
|
|
|
++segment;
|
|
|
|
++segmentIndex;
|
|
|
|
}
|
|
|
|
|
2014-05-28 11:51:49 +04:00
|
|
|
double positionInSegment =
|
|
|
|
(computedTiming.mTimeFraction - segment->startPortion()) /
|
|
|
|
(segment->endPortion() - segment->startPortion());
|
2013-04-28 10:46:30 +04:00
|
|
|
|
2014-05-28 11:51:49 +04:00
|
|
|
double portion =
|
|
|
|
animData.mFunctions[segmentIndex]->GetValue(positionInSegment);
|
2013-04-28 10:46:30 +04:00
|
|
|
|
|
|
|
// interpolate the property
|
|
|
|
Animatable interpolatedValue;
|
|
|
|
SampleValue(portion, animation, animData.mStartValues[segmentIndex],
|
|
|
|
animData.mEndValues[segmentIndex], &interpolatedValue);
|
|
|
|
LayerComposite* layerComposite = aLayer->AsLayerComposite();
|
|
|
|
switch (animation.property()) {
|
|
|
|
case eCSSProperty_opacity:
|
|
|
|
{
|
|
|
|
layerComposite->SetShadowOpacity(interpolatedValue.get_float());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSProperty_transform:
|
|
|
|
{
|
2014-01-27 19:29:27 +04:00
|
|
|
Matrix4x4 matrix = interpolatedValue.get_ArrayOfTransformFunction()[0].get_TransformMatrix().value();
|
2013-04-28 10:46:30 +04:00
|
|
|
if (ContainerLayer* c = aLayer->AsContainerLayer()) {
|
2014-01-27 19:29:27 +04:00
|
|
|
matrix = matrix * Matrix4x4().Scale(c->GetInheritedXScale(),
|
|
|
|
c->GetInheritedYScale(),
|
|
|
|
1);
|
2013-04-28 10:46:30 +04:00
|
|
|
}
|
|
|
|
layerComposite->SetShadowTransform(matrix);
|
2013-05-16 16:34:24 +04:00
|
|
|
layerComposite->SetShadowTransformSetByAnimation(true);
|
2013-04-28 10:46:30 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
NS_WARNING("Unhandled animated property");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Layer* child = aLayer->GetFirstChild(); child;
|
|
|
|
child = child->GetNextSibling()) {
|
|
|
|
activeAnimations |= SampleAnimations(child, aPoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
return activeAnimations;
|
|
|
|
}
|
|
|
|
|
2014-06-13 04:27:32 +04:00
|
|
|
Matrix4x4
|
|
|
|
CombineWithCSSTransform(const gfx3DMatrix& treeTransform, Layer* aLayer)
|
|
|
|
{
|
|
|
|
Matrix4x4 result;
|
|
|
|
ToMatrix4x4(treeTransform, result);
|
|
|
|
result = result * aLayer->GetTransform();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-04-28 10:46:30 +04:00
|
|
|
bool
|
|
|
|
AsyncCompositionManager::ApplyAsyncContentTransformToTree(TimeStamp aCurrentFrame,
|
|
|
|
Layer *aLayer,
|
|
|
|
bool* aWantNextFrame)
|
|
|
|
{
|
|
|
|
bool appliedTransform = false;
|
|
|
|
for (Layer* child = aLayer->GetFirstChild();
|
|
|
|
child; child = child->GetNextSibling()) {
|
|
|
|
appliedTransform |=
|
|
|
|
ApplyAsyncContentTransformToTree(aCurrentFrame, child, aWantNextFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
ContainerLayer* container = aLayer->AsContainerLayer();
|
|
|
|
if (!container) {
|
|
|
|
return appliedTransform;
|
|
|
|
}
|
|
|
|
|
2013-07-02 20:01:46 +04:00
|
|
|
if (AsyncPanZoomController* controller = container->GetAsyncPanZoomController()) {
|
2013-04-28 10:46:30 +04:00
|
|
|
LayerComposite* layerComposite = aLayer->AsLayerComposite();
|
2014-01-28 00:25:21 +04:00
|
|
|
Matrix4x4 oldTransform = aLayer->GetTransform();
|
2013-04-28 10:46:30 +04:00
|
|
|
|
2014-06-13 04:27:32 +04:00
|
|
|
ViewTransform treeTransformWithoutOverscroll, overscrollTransform;
|
2013-06-15 00:11:29 +04:00
|
|
|
ScreenPoint scrollOffset;
|
2013-04-28 10:46:30 +04:00
|
|
|
*aWantNextFrame |=
|
|
|
|
controller->SampleContentTransformForFrame(aCurrentFrame,
|
2014-06-13 04:27:32 +04:00
|
|
|
&treeTransformWithoutOverscroll,
|
|
|
|
scrollOffset,
|
|
|
|
&overscrollTransform);
|
2013-04-28 10:46:30 +04:00
|
|
|
|
2013-05-01 18:49:27 +04:00
|
|
|
const FrameMetrics& metrics = container->GetFrameMetrics();
|
2013-10-29 17:27:50 +04:00
|
|
|
CSSToLayerScale paintScale = metrics.LayersPixelsPerCSSPixel();
|
2013-06-10 17:05:42 +04:00
|
|
|
CSSRect displayPort(metrics.mCriticalDisplayPort.IsEmpty() ?
|
|
|
|
metrics.mDisplayPort : metrics.mCriticalDisplayPort);
|
2013-07-22 12:50:13 +04:00
|
|
|
LayerMargin fixedLayerMargins(0, 0, 0, 0);
|
2013-06-03 18:00:02 +04:00
|
|
|
ScreenPoint offset(0, 0);
|
2014-06-13 04:27:32 +04:00
|
|
|
SyncFrameMetrics(scrollOffset, treeTransformWithoutOverscroll.mScale.scale,
|
|
|
|
metrics.mScrollableRect, mLayersUpdated, displayPort,
|
|
|
|
paintScale, mIsFirstPaint, fixedLayerMargins, offset);
|
2013-05-01 18:49:27 +04:00
|
|
|
|
2013-04-28 10:46:30 +04:00
|
|
|
mIsFirstPaint = false;
|
|
|
|
mLayersUpdated = false;
|
|
|
|
|
|
|
|
// Apply the render offset
|
2013-05-01 22:12:08 +04:00
|
|
|
mLayerManager->GetCompositor()->SetScreenRenderOffset(offset);
|
2013-04-28 10:46:30 +04:00
|
|
|
|
2014-06-13 04:27:32 +04:00
|
|
|
Matrix4x4 transform = CombineWithCSSTransform(
|
|
|
|
treeTransformWithoutOverscroll * overscrollTransform, aLayer);
|
2014-01-27 19:29:27 +04:00
|
|
|
|
2013-12-10 07:14:54 +04:00
|
|
|
// 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.
|
2013-04-28 10:46:30 +04:00
|
|
|
transform.Scale(1.0f/container->GetPreXScale(),
|
|
|
|
1.0f/container->GetPreYScale(),
|
|
|
|
1);
|
2014-01-27 19:29:27 +04:00
|
|
|
transform = transform * Matrix4x4().Scale(1.0f/aLayer->GetPostXScale(),
|
|
|
|
1.0f/aLayer->GetPostYScale(),
|
|
|
|
1);
|
2013-04-28 10:46:30 +04:00
|
|
|
layerComposite->SetShadowTransform(transform);
|
2013-05-16 16:34:24 +04:00
|
|
|
NS_ASSERTION(!layerComposite->GetShadowTransformSetByAnimation(),
|
|
|
|
"overwriting animated transform!");
|
2013-04-28 10:46:30 +04:00
|
|
|
|
2013-06-24 05:34:33 +04:00
|
|
|
// Apply resolution scaling to the old transform - the layer tree as it is
|
|
|
|
// doesn't have the necessary transform to display correctly.
|
2013-09-06 02:26:59 +04:00
|
|
|
LayoutDeviceToLayerScale resolution = metrics.mCumulativeResolution;
|
2013-06-24 05:34:33 +04:00
|
|
|
oldTransform.Scale(resolution.scale, resolution.scale, 1);
|
|
|
|
|
2014-06-13 04:27:32 +04:00
|
|
|
// For the purpose of aligning fixed and sticky layers, we disregard
|
|
|
|
// the overscroll transform when computing the 'aCurrentTransformForRoot'
|
|
|
|
// parameter. This ensures that the overscroll transform is not unapplied,
|
|
|
|
// and therefore that the visual effect applies to fixed and sticky layers.
|
|
|
|
Matrix4x4 transformWithoutOverscroll = CombineWithCSSTransform(
|
|
|
|
treeTransformWithoutOverscroll, aLayer);
|
|
|
|
AlignFixedAndStickyLayers(aLayer, aLayer, oldTransform,
|
|
|
|
transformWithoutOverscroll, fixedLayerMargins);
|
2013-04-28 10:46:30 +04:00
|
|
|
|
|
|
|
appliedTransform = true;
|
|
|
|
}
|
|
|
|
|
2013-12-12 22:34:50 +04:00
|
|
|
if (container->GetScrollbarDirection() != Layer::NONE) {
|
2014-04-12 04:12:44 +04:00
|
|
|
ApplyAsyncTransformToScrollbar(aCurrentFrame, container);
|
2013-12-10 07:14:54 +04:00
|
|
|
}
|
2013-04-28 10:46:30 +04:00
|
|
|
return appliedTransform;
|
|
|
|
}
|
|
|
|
|
2014-01-22 18:25:44 +04:00
|
|
|
static bool
|
|
|
|
LayerHasNonContainerDescendants(ContainerLayer* aContainer)
|
|
|
|
{
|
|
|
|
for (Layer* child = aContainer->GetFirstChild();
|
|
|
|
child; child = child->GetNextSibling()) {
|
|
|
|
ContainerLayer* container = child->AsContainerLayer();
|
|
|
|
if (!container || LayerHasNonContainerDescendants(container)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-12 04:12:44 +04:00
|
|
|
static bool
|
|
|
|
LayerIsContainerForScrollbarTarget(Layer* aTarget, ContainerLayer* aScrollbar)
|
|
|
|
{
|
|
|
|
if (!aTarget->AsContainerLayer()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
AsyncPanZoomController* apzc = aTarget->AsContainerLayer()->GetAsyncPanZoomController();
|
|
|
|
if (!apzc) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const FrameMetrics& metrics = aTarget->AsContainerLayer()->GetFrameMetrics();
|
|
|
|
if (metrics.GetScrollId() != aScrollbar->GetScrollbarTargetContainerId()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ApplyAsyncTransformToScrollbarForContent(TimeStamp aCurrentFrame, ContainerLayer* aScrollbar,
|
|
|
|
Layer* aContent, bool aScrollbarIsChild)
|
|
|
|
{
|
|
|
|
ContainerLayer* content = aContent->AsContainerLayer();
|
2014-06-04 16:44:26 +04:00
|
|
|
|
|
|
|
// We only apply the transform if the scroll-target layer has non-container
|
|
|
|
// children (i.e. when it has some possibly-visible content). This is to
|
|
|
|
// avoid moving scroll-bars in the situation that only a scroll information
|
|
|
|
// layer has been built for a scroll frame, as this would result in a
|
|
|
|
// disparity between scrollbars and visible content.
|
2014-04-12 04:12:44 +04:00
|
|
|
if (!LayerHasNonContainerDescendants(content)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const FrameMetrics& metrics = content->GetFrameMetrics();
|
|
|
|
AsyncPanZoomController* apzc = content->GetAsyncPanZoomController();
|
|
|
|
|
|
|
|
if (aScrollbarIsChild) {
|
|
|
|
// Because we try to apply the scrollbar transform before we apply the async transform on
|
|
|
|
// the actual content, we need to ensure that the APZC has updated any pending animations
|
|
|
|
// to the current frame timestamp before we extract the transforms from it. The code in this
|
|
|
|
// block accomplishes that and throws away the temp variables.
|
|
|
|
// TODO: it might be cleaner to do a pass through the layer tree to advance all the APZC
|
|
|
|
// transforms before updating the layer shadow transforms. That will allow removal of this code.
|
|
|
|
ViewTransform treeTransform;
|
|
|
|
ScreenPoint scrollOffset;
|
|
|
|
apzc->SampleContentTransformForFrame(aCurrentFrame, &treeTransform, scrollOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx3DMatrix asyncTransform = gfx3DMatrix(apzc->GetCurrentAsyncTransform());
|
|
|
|
gfx3DMatrix nontransientTransform = apzc->GetNontransientAsyncTransform();
|
|
|
|
gfx3DMatrix transientTransform = asyncTransform * nontransientTransform.Inverse();
|
|
|
|
|
|
|
|
// |transientTransform| represents the amount by which we have scrolled and
|
|
|
|
// zoomed since the last paint. Because the scrollbar was sized and positioned based
|
|
|
|
// on the painted content, we need to adjust it based on transientTransform so that
|
|
|
|
// it reflects what the user is actually seeing now.
|
|
|
|
// - The scroll thumb needs to be scaled in the direction of scrolling by the inverse
|
|
|
|
// of the transientTransform scale (representing the zoom). This is because zooming
|
|
|
|
// in decreases the fraction of the whole scrollable rect that is in view.
|
|
|
|
// - It needs to be translated in opposite direction of the transientTransform
|
|
|
|
// translation (representing the scroll). This is because scrolling down, which
|
|
|
|
// translates the layer content up, should result in moving the scroll thumb down.
|
|
|
|
// The amount of the translation to the scroll thumb should be such that the ratio
|
|
|
|
// of the translation to the size of the scroll port is the same as the ratio
|
|
|
|
// of the scroll amount to the size of the scrollable rect.
|
|
|
|
Matrix4x4 scrollbarTransform;
|
|
|
|
if (aScrollbar->GetScrollbarDirection() == Layer::VERTICAL) {
|
|
|
|
float scale = metrics.CalculateCompositedSizeInCssPixels().height / metrics.mScrollableRect.height;
|
|
|
|
scrollbarTransform = scrollbarTransform * Matrix4x4().Scale(1.f, 1.f / transientTransform.GetYScale(), 1.f);
|
|
|
|
scrollbarTransform = scrollbarTransform * Matrix4x4().Translate(0, -transientTransform._42 * scale, 0);
|
|
|
|
}
|
|
|
|
if (aScrollbar->GetScrollbarDirection() == Layer::HORIZONTAL) {
|
|
|
|
float scale = metrics.CalculateCompositedSizeInCssPixels().width / metrics.mScrollableRect.width;
|
|
|
|
scrollbarTransform = scrollbarTransform * Matrix4x4().Scale(1.f / transientTransform.GetXScale(), 1.f, 1.f);
|
|
|
|
scrollbarTransform = scrollbarTransform * Matrix4x4().Translate(-transientTransform._41 * scale, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
transform = transform * Matrix4x4().Scale(1.0f/aScrollbar->GetPostXScale(),
|
|
|
|
1.0f/aScrollbar->GetPostYScale(),
|
|
|
|
1);
|
|
|
|
aScrollbar->AsLayerComposite()->SetShadowTransform(transform);
|
|
|
|
}
|
|
|
|
|
2014-06-04 16:44:26 +04:00
|
|
|
static Layer*
|
|
|
|
FindScrolledLayerForScrollbar(ContainerLayer* aLayer, bool* aOutIsAncestor)
|
|
|
|
{
|
|
|
|
// Search all siblings of aLayer and of its ancestors.
|
|
|
|
for (Layer* ancestor = aLayer; ancestor; ancestor = ancestor->GetParent()) {
|
|
|
|
for (Layer* scrollTarget = ancestor;
|
|
|
|
scrollTarget;
|
|
|
|
scrollTarget = scrollTarget->GetPrevSibling()) {
|
|
|
|
if (scrollTarget != aLayer &&
|
|
|
|
LayerIsContainerForScrollbarTarget(scrollTarget, aLayer)) {
|
|
|
|
*aOutIsAncestor = (scrollTarget == ancestor);
|
|
|
|
return scrollTarget;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (Layer* scrollTarget = ancestor->GetNextSibling();
|
|
|
|
scrollTarget;
|
|
|
|
scrollTarget = scrollTarget->GetNextSibling()) {
|
|
|
|
if (LayerIsContainerForScrollbarTarget(scrollTarget, aLayer)) {
|
|
|
|
*aOutIsAncestor = false;
|
|
|
|
return scrollTarget;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-12-10 07:14:54 +04:00
|
|
|
void
|
2014-04-12 04:12:44 +04:00
|
|
|
AsyncCompositionManager::ApplyAsyncTransformToScrollbar(TimeStamp aCurrentFrame, ContainerLayer* aLayer)
|
2013-12-10 07:14:54 +04:00
|
|
|
{
|
2014-04-12 04:12:44 +04:00
|
|
|
// If this layer corresponds to a scrollbar, then there should be a layer that
|
|
|
|
// is a previous sibling or a parent that has a matching ViewID on its FrameMetrics.
|
|
|
|
// That is the content that this scrollbar is for. We pick up the transient
|
|
|
|
// async transform from that layer and use it to update the scrollbar position.
|
2013-12-10 07:14:54 +04:00
|
|
|
// Note that it is possible that the content layer is no longer there; in
|
|
|
|
// this case we don't need to do anything because there can't be an async
|
|
|
|
// transform on the content.
|
2014-06-04 16:44:26 +04:00
|
|
|
bool isAncestor = false;
|
|
|
|
Layer* scrollTarget = FindScrolledLayerForScrollbar(aLayer, &isAncestor);
|
|
|
|
if (scrollTarget) {
|
|
|
|
ApplyAsyncTransformToScrollbarForContent(aCurrentFrame, aLayer, scrollTarget,
|
|
|
|
isAncestor);
|
2013-12-10 07:14:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-28 10:46:30 +04:00
|
|
|
void
|
2013-10-29 17:27:50 +04:00
|
|
|
AsyncCompositionManager::TransformScrollableLayer(Layer* aLayer)
|
2013-04-28 10:46:30 +04:00
|
|
|
{
|
|
|
|
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.
|
2014-01-27 19:28:47 +04:00
|
|
|
gfx3DMatrix currentTransform;
|
|
|
|
To3DMatrix(aLayer->GetTransform(), currentTransform);
|
2014-01-28 00:25:21 +04:00
|
|
|
Matrix4x4 oldTransform = aLayer->GetTransform();
|
2013-04-28 10:46:30 +04:00
|
|
|
|
|
|
|
gfx3DMatrix treeTransform;
|
|
|
|
|
2013-10-29 17:27:50 +04:00
|
|
|
CSSToLayerScale geckoZoom = metrics.LayersPixelsPerCSSPixel();
|
2013-06-03 17:58:07 +04:00
|
|
|
|
2014-03-13 10:34:34 +04:00
|
|
|
LayerIntPoint scrollOffsetLayerPixels = RoundedToInt(metrics.GetScrollOffset() * geckoZoom);
|
2013-04-28 10:46:30 +04:00
|
|
|
|
|
|
|
if (mIsFirstPaint) {
|
2013-06-11 17:46:51 +04:00
|
|
|
mContentRect = metrics.mScrollableRect;
|
2013-06-03 17:58:07 +04:00
|
|
|
SetFirstPaintViewport(scrollOffsetLayerPixels,
|
2013-06-22 01:03:56 +04:00
|
|
|
geckoZoom,
|
2013-06-11 17:46:51 +04:00
|
|
|
mContentRect);
|
2013-04-28 10:46:30 +04:00
|
|
|
mIsFirstPaint = false;
|
2013-06-11 17:46:51 +04:00
|
|
|
} else if (!metrics.mScrollableRect.IsEqualEdges(mContentRect)) {
|
|
|
|
mContentRect = metrics.mScrollableRect;
|
|
|
|
SetPageRect(mContentRect);
|
2013-04-28 10:46:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// We synchronise the viewport information with Java after sending the above
|
|
|
|
// notifications, so that Java can take these into account in its response.
|
|
|
|
// Calculate the absolute display port to send to Java
|
2013-06-15 00:11:31 +04:00
|
|
|
LayerIntRect displayPort = RoundedToInt(
|
|
|
|
(metrics.mCriticalDisplayPort.IsEmpty()
|
|
|
|
? metrics.mDisplayPort
|
|
|
|
: metrics.mCriticalDisplayPort
|
|
|
|
) * geckoZoom);
|
2013-06-10 17:05:42 +04:00
|
|
|
displayPort += scrollOffsetLayerPixels;
|
2013-04-28 10:46:30 +04:00
|
|
|
|
2013-07-22 12:50:13 +04:00
|
|
|
LayerMargin fixedLayerMargins(0, 0, 0, 0);
|
2013-06-03 18:00:02 +04:00
|
|
|
ScreenPoint offset(0, 0);
|
2013-06-22 01:03:57 +04:00
|
|
|
|
|
|
|
// Ideally we would initialize userZoom to AsyncPanZoomController::CalculateResolution(metrics)
|
|
|
|
// but this causes a reftest-ipc test to fail (see bug 883646 comment 27). The reason for this
|
|
|
|
// appears to be that metrics.mZoom is poorly initialized in some scenarios. In these scenarios,
|
|
|
|
// however, we can assume there is no async zooming in progress and so the following statement
|
|
|
|
// works fine.
|
2013-09-06 02:26:59 +04:00
|
|
|
CSSToScreenScale userZoom(metrics.mDevPixelsPerCSSPixel * metrics.mCumulativeResolution * LayerToScreenScale(1));
|
2014-03-13 10:34:34 +04:00
|
|
|
ScreenPoint userScroll = metrics.GetScrollOffset() * userZoom;
|
2013-06-22 01:03:56 +04:00
|
|
|
SyncViewportInfo(displayPort, geckoZoom, mLayersUpdated,
|
|
|
|
userScroll, userZoom, fixedLayerMargins,
|
2013-05-01 22:12:08 +04:00
|
|
|
offset);
|
2013-04-28 10:46:30 +04:00
|
|
|
mLayersUpdated = false;
|
|
|
|
|
|
|
|
// Apply the render offset
|
2013-05-01 22:12:08 +04:00
|
|
|
mLayerManager->GetCompositor()->SetScreenRenderOffset(offset);
|
2013-04-28 10:46:30 +04:00
|
|
|
|
|
|
|
// Handle transformations for asynchronous panning and zooming. We determine the
|
|
|
|
// zoom used by Gecko from the transformation set on the root layer, and we
|
|
|
|
// determine the scroll offset used by Gecko from the frame metrics of the
|
2013-06-15 00:11:31 +04:00
|
|
|
// primary scrollable layer. We compare this to the user zoom and scroll
|
2013-04-28 10:46:30 +04:00
|
|
|
// offset in the view transform we obtained from Java in order to compute the
|
|
|
|
// transformation we need to apply.
|
2013-08-12 16:32:11 +04:00
|
|
|
LayerToScreenScale zoomAdjust = userZoom / geckoZoom;
|
2013-04-28 10:46:30 +04:00
|
|
|
|
2013-10-29 17:27:50 +04:00
|
|
|
LayerPoint geckoScroll(0, 0);
|
2013-04-28 10:46:30 +04:00
|
|
|
if (metrics.IsScrollable()) {
|
2014-03-13 10:34:34 +04:00
|
|
|
geckoScroll = metrics.GetScrollOffset() * geckoZoom;
|
2013-04-28 10:46:30 +04:00
|
|
|
}
|
|
|
|
|
2013-08-12 16:32:11 +04:00
|
|
|
LayerPoint translation = (userScroll / zoomAdjust) - geckoScroll;
|
2013-09-06 02:26:59 +04:00
|
|
|
treeTransform = gfx3DMatrix(ViewTransform(-translation,
|
|
|
|
userZoom
|
|
|
|
/ metrics.mDevPixelsPerCSSPixel
|
|
|
|
/ metrics.GetParentResolution()));
|
2013-04-28 10:46:30 +04:00
|
|
|
|
|
|
|
// The transform already takes the resolution scale into account. Since we
|
|
|
|
// will apply the resolution scale again when computing the effective
|
|
|
|
// transform, we must apply the inverse resolution scale here.
|
2013-08-12 16:32:11 +04:00
|
|
|
gfx3DMatrix computedTransform = treeTransform * currentTransform;
|
2013-04-28 10:46:30 +04:00
|
|
|
computedTransform.Scale(1.0f/container->GetPreXScale(),
|
|
|
|
1.0f/container->GetPreYScale(),
|
|
|
|
1);
|
|
|
|
computedTransform.ScalePost(1.0f/container->GetPostXScale(),
|
|
|
|
1.0f/container->GetPostYScale(),
|
|
|
|
1);
|
2014-01-27 19:29:27 +04:00
|
|
|
Matrix4x4 matrix;
|
|
|
|
ToMatrix4x4(computedTransform, matrix);
|
|
|
|
layerComposite->SetShadowTransform(matrix);
|
2013-05-16 16:34:24 +04:00
|
|
|
NS_ASSERTION(!layerComposite->GetShadowTransformSetByAnimation(),
|
|
|
|
"overwriting animated transform!");
|
2013-06-24 05:34:33 +04:00
|
|
|
|
|
|
|
// Apply resolution scaling to the old transform - the layer tree as it is
|
|
|
|
// doesn't have the necessary transform to display correctly.
|
2013-10-29 17:27:50 +04:00
|
|
|
oldTransform.Scale(metrics.mResolution.scale, metrics.mResolution.scale, 1);
|
2013-06-24 05:34:33 +04:00
|
|
|
|
2013-07-22 12:50:07 +04:00
|
|
|
// Make sure that overscroll and under-zoom are represented in the old
|
|
|
|
// transform so that fixed position content moves and scales accordingly.
|
|
|
|
// These calculations will effectively scale and offset fixed position layers
|
|
|
|
// in screen space when the compensatory transform is performed in
|
2013-09-12 08:24:32 +04:00
|
|
|
// AlignFixedAndStickyLayers.
|
2013-07-22 12:50:07 +04:00
|
|
|
ScreenRect contentScreenRect = mContentRect * userZoom;
|
|
|
|
gfxPoint3D overscrollTranslation;
|
|
|
|
if (userScroll.x < contentScreenRect.x) {
|
|
|
|
overscrollTranslation.x = contentScreenRect.x - userScroll.x;
|
|
|
|
} else if (userScroll.x + metrics.mCompositionBounds.width > contentScreenRect.XMost()) {
|
|
|
|
overscrollTranslation.x = contentScreenRect.XMost() -
|
|
|
|
(userScroll.x + metrics.mCompositionBounds.width);
|
|
|
|
}
|
|
|
|
if (userScroll.y < contentScreenRect.y) {
|
|
|
|
overscrollTranslation.y = contentScreenRect.y - userScroll.y;
|
|
|
|
} else if (userScroll.y + metrics.mCompositionBounds.height > contentScreenRect.YMost()) {
|
|
|
|
overscrollTranslation.y = contentScreenRect.YMost() -
|
|
|
|
(userScroll.y + metrics.mCompositionBounds.height);
|
|
|
|
}
|
2014-01-28 00:25:21 +04:00
|
|
|
oldTransform.Translate(overscrollTranslation.x,
|
|
|
|
overscrollTranslation.y,
|
|
|
|
overscrollTranslation.z);
|
2013-07-22 12:50:07 +04:00
|
|
|
|
2013-12-13 21:31:53 +04:00
|
|
|
gfx::Size underZoomScale(1.0f, 1.0f);
|
2013-07-22 12:50:07 +04:00
|
|
|
if (mContentRect.width * userZoom.scale < metrics.mCompositionBounds.width) {
|
|
|
|
underZoomScale.width = (mContentRect.width * userZoom.scale) /
|
|
|
|
metrics.mCompositionBounds.width;
|
|
|
|
}
|
|
|
|
if (mContentRect.height * userZoom.scale < metrics.mCompositionBounds.height) {
|
|
|
|
underZoomScale.height = (mContentRect.height * userZoom.scale) /
|
|
|
|
metrics.mCompositionBounds.height;
|
|
|
|
}
|
|
|
|
oldTransform.Scale(underZoomScale.width, underZoomScale.height, 1);
|
|
|
|
|
2013-06-24 05:34:33 +04:00
|
|
|
// Make sure fixed position layers don't move away from their anchor points
|
|
|
|
// when we're asynchronously panning or zooming
|
2014-06-13 04:27:32 +04:00
|
|
|
AlignFixedAndStickyLayers(aLayer, aLayer, oldTransform,
|
|
|
|
aLayer->GetLocalTransform(), fixedLayerMargins);
|
2013-04-28 10:46:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AsyncCompositionManager::TransformShadowTree(TimeStamp aCurrentFrame)
|
|
|
|
{
|
2014-05-24 01:12:29 +04:00
|
|
|
PROFILER_LABEL("AsyncCompositionManager", "TransformShadowTree",
|
|
|
|
js::ProfileEntry::Category::GRAPHICS);
|
|
|
|
|
2013-04-28 10:46:30 +04:00
|
|
|
Layer* root = mLayerManager->GetRoot();
|
2013-07-31 01:45:42 +04:00
|
|
|
if (!root) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-04-28 10:46:30 +04:00
|
|
|
|
|
|
|
// NB: we must sample animations *before* sampling pan/zoom
|
|
|
|
// transforms.
|
2013-05-28 03:47:45 +04:00
|
|
|
bool wantNextFrame = SampleAnimations(root, aCurrentFrame);
|
2013-04-28 10:46:30 +04:00
|
|
|
|
|
|
|
// FIXME/bug 775437: unify this interface with the ~native-fennec
|
|
|
|
// derived code
|
|
|
|
//
|
|
|
|
// Attempt to apply an async content transform to any layer that has
|
|
|
|
// an async pan zoom controller (which means that it is rendered
|
|
|
|
// async using Gecko). If this fails, fall back to transforming the
|
|
|
|
// primary scrollable layer. "Failing" here means that we don't
|
|
|
|
// find a frame that is async scrollable. Note that the fallback
|
|
|
|
// code also includes Fennec which is rendered async. Fennec uses
|
|
|
|
// its own platform-specific async rendering that is done partially
|
|
|
|
// in Gecko and partially in Java.
|
|
|
|
if (!ApplyAsyncContentTransformToTree(aCurrentFrame, root, &wantNextFrame)) {
|
|
|
|
nsAutoTArray<Layer*,1> scrollableLayers;
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
scrollableLayers.AppendElement(mLayerManager->GetPrimaryScrollableLayer());
|
|
|
|
#else
|
|
|
|
mLayerManager->GetScrollableLayers(scrollableLayers);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < scrollableLayers.Length(); i++) {
|
|
|
|
if (scrollableLayers[i]) {
|
2013-10-29 17:27:50 +04:00
|
|
|
TransformScrollableLayer(scrollableLayers[i]);
|
2013-04-28 10:46:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return wantNextFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-03 17:58:07 +04:00
|
|
|
AsyncCompositionManager::SetFirstPaintViewport(const LayerIntPoint& aOffset,
|
2013-06-22 01:03:56 +04:00
|
|
|
const CSSToLayerScale& aZoom,
|
2013-06-03 17:52:44 +04:00
|
|
|
const CSSRect& aCssPageRect)
|
2013-04-28 10:46:30 +04:00
|
|
|
{
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2013-06-11 17:46:51 +04:00
|
|
|
AndroidBridge::Bridge()->SetFirstPaintViewport(aOffset, aZoom, aCssPageRect);
|
2013-04-28 10:46:30 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-03 17:52:44 +04:00
|
|
|
AsyncCompositionManager::SetPageRect(const CSSRect& aCssPageRect)
|
2013-04-28 10:46:30 +04:00
|
|
|
{
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
AndroidBridge::Bridge()->SetPageRect(aCssPageRect);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-03 17:58:07 +04:00
|
|
|
AsyncCompositionManager::SyncViewportInfo(const LayerIntRect& aDisplayPort,
|
2013-06-22 01:03:56 +04:00
|
|
|
const CSSToLayerScale& aDisplayResolution,
|
2013-04-28 10:46:30 +04:00
|
|
|
bool aLayersUpdated,
|
2013-06-03 17:53:32 +04:00
|
|
|
ScreenPoint& aScrollOffset,
|
2013-06-22 01:03:56 +04:00
|
|
|
CSSToScreenScale& aScale,
|
2013-07-22 12:50:13 +04:00
|
|
|
LayerMargin& aFixedLayerMargins,
|
2013-06-03 18:00:02 +04:00
|
|
|
ScreenPoint& aOffset)
|
2013-04-28 10:46:30 +04:00
|
|
|
{
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
AndroidBridge::Bridge()->SyncViewportInfo(aDisplayPort,
|
|
|
|
aDisplayResolution,
|
|
|
|
aLayersUpdated,
|
|
|
|
aScrollOffset,
|
2013-06-22 01:03:56 +04:00
|
|
|
aScale,
|
2013-04-28 10:46:30 +04:00
|
|
|
aFixedLayerMargins,
|
2013-05-01 22:12:08 +04:00
|
|
|
aOffset);
|
2013-04-28 10:46:30 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-05-01 18:49:27 +04:00
|
|
|
void
|
2013-06-15 00:11:29 +04:00
|
|
|
AsyncCompositionManager::SyncFrameMetrics(const ScreenPoint& aScrollOffset,
|
2013-05-01 18:49:27 +04:00
|
|
|
float aZoom,
|
2013-06-03 17:52:44 +04:00
|
|
|
const CSSRect& aCssPageRect,
|
2013-05-01 18:49:27 +04:00
|
|
|
bool aLayersUpdated,
|
2013-06-10 17:05:42 +04:00
|
|
|
const CSSRect& aDisplayPort,
|
2013-06-22 01:03:56 +04:00
|
|
|
const CSSToLayerScale& aDisplayResolution,
|
2013-05-01 18:49:27 +04:00
|
|
|
bool aIsFirstPaint,
|
2013-07-22 12:50:13 +04:00
|
|
|
LayerMargin& aFixedLayerMargins,
|
2013-06-03 18:00:02 +04:00
|
|
|
ScreenPoint& aOffset)
|
2013-05-01 18:49:27 +04:00
|
|
|
{
|
2013-05-02 00:10:17 +04:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2013-05-01 22:12:08 +04:00
|
|
|
AndroidBridge::Bridge()->SyncFrameMetrics(aScrollOffset, aZoom, aCssPageRect,
|
2013-05-01 18:49:27 +04:00
|
|
|
aLayersUpdated, aDisplayPort,
|
|
|
|
aDisplayResolution, aIsFirstPaint,
|
2013-05-01 22:12:08 +04:00
|
|
|
aFixedLayerMargins, aOffset);
|
2013-05-01 18:49:27 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-04-28 10:46:30 +04:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|