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"
|
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
# include <android/log.h>
|
|
|
|
# include "AndroidBridge.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "CompositorParent.h"
|
|
|
|
#include "LayerManagerComposite.h"
|
|
|
|
|
|
|
|
#include "nsStyleAnimation.h"
|
|
|
|
#include "nsDisplayList.h"
|
|
|
|
#include "AnimationCommon.h"
|
|
|
|
#include "nsAnimationManager.h"
|
|
|
|
#include "mozilla/layers/AsyncPanZoomController.h"
|
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
enum Op { Resolve, Detach };
|
|
|
|
|
|
|
|
static bool
|
|
|
|
IsSameDimension(ScreenOrientation o1, ScreenOrientation o2)
|
|
|
|
{
|
|
|
|
bool isO1portrait = (o1 == eScreenOrientation_PortraitPrimary || o1 == eScreenOrientation_PortraitSecondary);
|
|
|
|
bool isO2portrait = (o2 == eScreenOrientation_PortraitPrimary || o2 == eScreenOrientation_PortraitSecondary);
|
|
|
|
return !(isO1portrait ^ isO2portrait);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
ContentMightReflowOnOrientationChange(const nsIntRect& rect)
|
|
|
|
{
|
|
|
|
return rect.width != rect.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<Op OP>
|
|
|
|
static void
|
|
|
|
WalkTheTree(Layer* aLayer,
|
|
|
|
Layer* aParent,
|
|
|
|
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()) {
|
|
|
|
ScreenOrientation chromeOrientation = aTargetConfig.orientation();
|
|
|
|
ScreenOrientation contentOrientation = state->mTargetConfig.orientation();
|
|
|
|
if (!IsSameDimension(chromeOrientation, contentOrientation) &&
|
|
|
|
ContentMightReflowOnOrientationChange(aTargetConfig.clientBounds())) {
|
|
|
|
aReady = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OP == Resolve) {
|
|
|
|
ref->ConnectReferentLayer(referent);
|
|
|
|
if (AsyncPanZoomController* apzc = state->mController) {
|
|
|
|
referent->SetAsyncPanZoomController(apzc);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ref->DetachReferentLayer(referent);
|
|
|
|
referent->SetAsyncPanZoomController(nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (Layer* child = aLayer->GetFirstChild();
|
|
|
|
child; child = child->GetNextSibling()) {
|
|
|
|
WalkTheTree<OP>(child, aLayer, aReady, aTargetConfig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AsyncCompositionManager::ResolveRefLayers()
|
|
|
|
{
|
|
|
|
WalkTheTree<Resolve>(mLayerManager->GetRoot(),
|
|
|
|
nullptr,
|
|
|
|
mReadyForCompose,
|
|
|
|
mTargetConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AsyncCompositionManager::DetachRefLayers()
|
|
|
|
{
|
|
|
|
WalkTheTree<Detach>(mLayerManager->GetRoot(),
|
|
|
|
nullptr,
|
|
|
|
mReadyForCompose,
|
|
|
|
mTargetConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AsyncCompositionManager::ComputeRotation()
|
|
|
|
{
|
|
|
|
if (!mTargetConfig.naturalBounds().IsEmpty()) {
|
|
|
|
mLayerManager->SetWorldTransform(
|
|
|
|
ComputeTransformForRotation(mTargetConfig.naturalBounds(),
|
|
|
|
mTargetConfig.rotation()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do a breadth-first search to find the first layer in the tree that is
|
|
|
|
// scrollable.
|
|
|
|
static void
|
|
|
|
Translate2D(gfx3DMatrix& aTransform, const gfxPoint& aOffset)
|
|
|
|
{
|
|
|
|
aTransform._41 += aOffset.x;
|
|
|
|
aTransform._42 += aOffset.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AsyncCompositionManager::TransformFixedLayers(Layer* aLayer,
|
|
|
|
const gfxPoint& aTranslation,
|
|
|
|
const gfxSize& aScaleDiff,
|
|
|
|
const gfx::Margin& aFixedLayerMargins)
|
|
|
|
{
|
|
|
|
if (aLayer->GetIsFixedPosition() &&
|
|
|
|
!aLayer->GetParent()->GetIsFixedPosition()) {
|
|
|
|
// When a scale has been applied to a layer, it focuses around (0,0).
|
|
|
|
// The anchor position is used here as a scale focus point (assuming that
|
|
|
|
// aScaleDiff has already been applied) to re-focus the scale.
|
|
|
|
const gfxPoint& anchor = aLayer->GetFixedPositionAnchor();
|
|
|
|
gfxPoint translation(aTranslation - (anchor - anchor / aScaleDiff));
|
|
|
|
|
|
|
|
// Offset this translation by the fixed layer margins, depending on what
|
|
|
|
// side of the viewport the layer is anchored to, reconciling the
|
|
|
|
// difference between the current fixed layer margins and the Gecko-side
|
|
|
|
// fixed layer margins.
|
|
|
|
// aFixedLayerMargins are the margins we expect to be at at the current
|
|
|
|
// time, obtained via SyncViewportInfo, and fixedMargins are the margins
|
|
|
|
// that were used during layout.
|
|
|
|
// If top/left of fixedMargins are negative, that indicates that this layer
|
|
|
|
// represents auto-positioned elements, and should not be affected by
|
|
|
|
// fixed margins at all.
|
|
|
|
const gfx::Margin& fixedMargins = aLayer->GetFixedPositionMargins();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-05-16 16:34:24 +04:00
|
|
|
LayerComposite* layerComposite = aLayer->AsLayerComposite();
|
|
|
|
gfx3DMatrix layerTransform;
|
|
|
|
if (layerComposite->GetShadowTransformSetByAnimation()) {
|
|
|
|
// Start with the animated transform
|
|
|
|
layerTransform = aLayer->GetLocalTransform();
|
|
|
|
} else {
|
|
|
|
layerTransform = aLayer->GetTransform();
|
|
|
|
}
|
2013-04-28 10:46:30 +04:00
|
|
|
Translate2D(layerTransform, translation);
|
|
|
|
if (ContainerLayer* c = aLayer->AsContainerLayer()) {
|
|
|
|
layerTransform.Scale(1.0f/c->GetPreXScale(),
|
|
|
|
1.0f/c->GetPreYScale(),
|
|
|
|
1);
|
|
|
|
}
|
|
|
|
layerTransform.ScalePost(1.0f/aLayer->GetPostXScale(),
|
|
|
|
1.0f/aLayer->GetPostYScale(),
|
|
|
|
1);
|
|
|
|
layerComposite->SetShadowTransform(layerTransform);
|
2013-05-16 16:34:24 +04:00
|
|
|
layerComposite->SetShadowTransformSetByAnimation(false);
|
2013-04-28 10:46:30 +04:00
|
|
|
|
|
|
|
const nsIntRect* clipRect = aLayer->GetClipRect();
|
|
|
|
if (clipRect) {
|
|
|
|
nsIntRect transformedClipRect(*clipRect);
|
|
|
|
transformedClipRect.MoveBy(translation.x, translation.y);
|
|
|
|
layerComposite->SetShadowClipRect(&transformedClipRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The transform has now been applied, so there's no need to iterate over
|
|
|
|
// child layers.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Layer* child = aLayer->GetFirstChild();
|
|
|
|
child; child = child->GetNextSibling()) {
|
|
|
|
TransformFixedLayers(child, aTranslation, aScaleDiff, aFixedLayerMargins);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SampleValue(float aPortion, Animation& aAnimation, nsStyleAnimation::Value& aStart,
|
|
|
|
nsStyleAnimation::Value& aEnd, Animatable* aValue)
|
|
|
|
{
|
|
|
|
nsStyleAnimation::Value interpolatedValue;
|
|
|
|
NS_ASSERTION(aStart.GetUnit() == aEnd.GetUnit() ||
|
|
|
|
aStart.GetUnit() == nsStyleAnimation::eUnit_None ||
|
|
|
|
aEnd.GetUnit() == nsStyleAnimation::eUnit_None, "Must have same unit");
|
|
|
|
nsStyleAnimation::Interpolate(aAnimation.property(), aStart, aEnd,
|
|
|
|
aPortion, interpolatedValue);
|
|
|
|
if (aAnimation.property() == eCSSProperty_opacity) {
|
|
|
|
*aValue = interpolatedValue.GetFloatValue();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValueList* interpolatedList = interpolatedValue.GetCSSValueListValue();
|
|
|
|
|
|
|
|
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());
|
|
|
|
gfxPoint3D mozOrigin = data.mozOrigin();
|
|
|
|
mozOrigin.x = mozOrigin.x * cssPerDev;
|
|
|
|
mozOrigin.y = mozOrigin.y * cssPerDev;
|
|
|
|
gfxPoint3D perspectiveOrigin = data.perspectiveOrigin();
|
|
|
|
perspectiveOrigin.x = perspectiveOrigin.x * cssPerDev;
|
|
|
|
perspectiveOrigin.y = perspectiveOrigin.y * cssPerDev;
|
|
|
|
nsDisplayTransform::FrameTransformProperties props(interpolatedList,
|
|
|
|
mozOrigin,
|
|
|
|
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;
|
|
|
|
functions.AppendElement(TransformMatrix(transform));
|
|
|
|
*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];
|
|
|
|
|
|
|
|
double numIterations = animation.numIterations() != -1 ?
|
|
|
|
animation.numIterations() : NS_IEEEPositiveInfinity();
|
|
|
|
double positionInIteration =
|
|
|
|
ElementAnimations::GetPositionInIteration(aPoint - animation.startTime(),
|
|
|
|
animation.duration(),
|
|
|
|
numIterations,
|
|
|
|
animation.direction());
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(0.0 <= positionInIteration &&
|
|
|
|
positionInIteration <= 1.0,
|
|
|
|
"position should be in [0-1]");
|
|
|
|
|
|
|
|
int segmentIndex = 0;
|
|
|
|
AnimationSegment* segment = animation.segments().Elements();
|
|
|
|
while (segment->endPortion() < positionInIteration) {
|
|
|
|
++segment;
|
|
|
|
++segmentIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
double positionInSegment = (positionInIteration - segment->startPortion()) /
|
|
|
|
(segment->endPortion() - segment->startPortion());
|
|
|
|
|
|
|
|
double portion = animData.mFunctions[segmentIndex]->GetValue(positionInSegment);
|
|
|
|
|
|
|
|
activeAnimations = true;
|
|
|
|
|
|
|
|
// 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:
|
|
|
|
{
|
|
|
|
gfx3DMatrix matrix = interpolatedValue.get_ArrayOfTransformFunction()[0].get_TransformMatrix().value();
|
|
|
|
if (ContainerLayer* c = aLayer->AsContainerLayer()) {
|
|
|
|
matrix.ScalePost(c->GetInheritedXScale(),
|
|
|
|
c->GetInheritedYScale(),
|
|
|
|
1);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (AsyncPanZoomController* controller = aLayer->GetAsyncPanZoomController()) {
|
|
|
|
LayerComposite* layerComposite = aLayer->AsLayerComposite();
|
|
|
|
|
|
|
|
ViewTransform treeTransform;
|
2013-05-01 18:49:27 +04:00
|
|
|
gfx::Point scrollOffset;
|
2013-04-28 10:46:30 +04:00
|
|
|
*aWantNextFrame |=
|
|
|
|
controller->SampleContentTransformForFrame(aCurrentFrame,
|
|
|
|
container,
|
|
|
|
&treeTransform,
|
2013-05-01 18:49:27 +04:00
|
|
|
scrollOffset);
|
2013-04-28 10:46:30 +04:00
|
|
|
|
2013-05-01 18:49:27 +04:00
|
|
|
const gfx3DMatrix& rootTransform = mLayerManager->GetRoot()->GetTransform();
|
|
|
|
const FrameMetrics& metrics = container->GetFrameMetrics();
|
2013-06-10 17:05:42 +04:00
|
|
|
CSSRect displayPort(metrics.mCriticalDisplayPort.IsEmpty() ?
|
|
|
|
metrics.mDisplayPort : metrics.mCriticalDisplayPort);
|
2013-04-28 10:46:30 +04:00
|
|
|
gfx::Margin fixedLayerMargins(0, 0, 0, 0);
|
2013-06-03 18:00:02 +04:00
|
|
|
ScreenPoint offset(0, 0);
|
2013-05-01 18:49:27 +04:00
|
|
|
SyncFrameMetrics(scrollOffset, treeTransform.mScale.width, metrics.mScrollableRect,
|
2013-06-10 17:05:42 +04:00
|
|
|
mLayersUpdated, displayPort, 1 / rootTransform.GetXScale(),
|
2013-05-01 22:12:08 +04:00
|
|
|
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
|
|
|
|
|
|
|
gfx3DMatrix transform(gfx3DMatrix(treeTransform) * aLayer->GetTransform());
|
|
|
|
// 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.
|
|
|
|
transform.Scale(1.0f/container->GetPreXScale(),
|
|
|
|
1.0f/container->GetPreYScale(),
|
|
|
|
1);
|
|
|
|
transform.ScalePost(1.0f/aLayer->GetPostXScale(),
|
|
|
|
1.0f/aLayer->GetPostYScale(),
|
|
|
|
1);
|
|
|
|
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
|
|
|
|
|
|
|
TransformFixedLayers(
|
|
|
|
aLayer,
|
|
|
|
-treeTransform.mTranslation / treeTransform.mScale,
|
|
|
|
treeTransform.mScale,
|
|
|
|
fixedLayerMargins);
|
|
|
|
|
|
|
|
appliedTransform = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return appliedTransform;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AsyncCompositionManager::TransformScrollableLayer(Layer* aLayer, const gfx3DMatrix& aRootTransform)
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
const gfx3DMatrix& currentTransform = aLayer->GetTransform();
|
|
|
|
|
|
|
|
gfx3DMatrix treeTransform;
|
|
|
|
|
2013-06-03 17:58:07 +04:00
|
|
|
float layerPixelRatioX = 1 / aRootTransform.GetXScale(),
|
|
|
|
layerPixelRatioY = 1 / aRootTransform.GetYScale();
|
|
|
|
|
|
|
|
LayerIntPoint scrollOffsetLayerPixels = LayerIntPoint::FromCSSPointRounded(
|
|
|
|
metrics.mScrollOffset, layerPixelRatioX, layerPixelRatioY);
|
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,
|
|
|
|
layerPixelRatioX,
|
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-10 17:05:42 +04:00
|
|
|
LayerIntRect displayPort =
|
|
|
|
LayerIntRect::FromCSSRectRounded(metrics.mCriticalDisplayPort.IsEmpty()
|
|
|
|
? metrics.mDisplayPort
|
|
|
|
: metrics.mCriticalDisplayPort,
|
|
|
|
layerPixelRatioX, layerPixelRatioY);
|
|
|
|
displayPort += scrollOffsetLayerPixels;
|
2013-04-28 10:46:30 +04:00
|
|
|
|
|
|
|
gfx::Margin fixedLayerMargins(0, 0, 0, 0);
|
2013-06-03 18:00:02 +04:00
|
|
|
ScreenPoint offset(0, 0);
|
2013-06-03 17:53:32 +04:00
|
|
|
ScreenPoint scrollOffset(0, 0);
|
|
|
|
float scaleX = 1.0,
|
|
|
|
scaleY = 1.0;
|
2013-06-03 17:58:07 +04:00
|
|
|
SyncViewportInfo(displayPort, layerPixelRatioX, mLayersUpdated,
|
2013-06-03 17:53:32 +04:00
|
|
|
scrollOffset, scaleX, scaleY, 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
|
|
|
|
// primary scrollable layer. We compare this to the desired zoom and scroll
|
|
|
|
// offset in the view transform we obtained from Java in order to compute the
|
|
|
|
// transformation we need to apply.
|
2013-06-03 17:58:07 +04:00
|
|
|
float tempScaleDiffX = aRootTransform.GetXScale() * scaleX;
|
|
|
|
float tempScaleDiffY = aRootTransform.GetYScale() * scaleY;
|
2013-04-28 10:46:30 +04:00
|
|
|
|
2013-06-03 17:58:07 +04:00
|
|
|
LayerIntPoint metricsScrollOffset(0, 0);
|
2013-04-28 10:46:30 +04:00
|
|
|
if (metrics.IsScrollable()) {
|
2013-06-03 17:58:07 +04:00
|
|
|
metricsScrollOffset = scrollOffsetLayerPixels;
|
2013-04-28 10:46:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIntPoint scrollCompensation(
|
2013-06-03 17:53:32 +04:00
|
|
|
(scrollOffset.x / tempScaleDiffX - metricsScrollOffset.x) * scaleX,
|
|
|
|
(scrollOffset.y / tempScaleDiffY - metricsScrollOffset.y) * scaleY);
|
2013-04-28 10:46:30 +04:00
|
|
|
treeTransform = gfx3DMatrix(ViewTransform(-scrollCompensation,
|
2013-06-03 17:53:32 +04:00
|
|
|
gfxSize(scaleX, scaleY)));
|
2013-04-28 10:46:30 +04:00
|
|
|
|
2013-05-01 22:12:08 +04:00
|
|
|
// Translate fixed position layers so that they stay in the correct position
|
2013-06-03 17:53:32 +04:00
|
|
|
// when scrollOffset and metricsScrollOffset differ.
|
2013-05-01 22:12:08 +04:00
|
|
|
gfxPoint fixedOffset;
|
|
|
|
gfxSize scaleDiff;
|
|
|
|
|
2013-06-11 17:46:51 +04:00
|
|
|
LayerRect content = LayerRect::FromCSSRect(mContentRect,
|
|
|
|
1 / aRootTransform.GetXScale(),
|
|
|
|
1 / aRootTransform.GetYScale());
|
2013-04-28 10:46:30 +04:00
|
|
|
// If the contents can fit entirely within the widget area on a particular
|
2013-06-11 17:46:51 +04:00
|
|
|
// dimension, we need to translate and scale so that the fixed layers remain
|
2013-04-28 10:46:30 +04:00
|
|
|
// within the page boundaries.
|
2013-06-11 17:46:51 +04:00
|
|
|
if (mContentRect.width * scaleX < metrics.mCompositionBounds.width) {
|
2013-05-01 22:12:08 +04:00
|
|
|
fixedOffset.x = -metricsScrollOffset.x;
|
2013-06-11 17:46:51 +04:00
|
|
|
scaleDiff.width = std::min(1.0f, metrics.mCompositionBounds.width / content.width);
|
2013-04-28 10:46:30 +04:00
|
|
|
} else {
|
2013-06-11 17:46:51 +04:00
|
|
|
fixedOffset.x = clamped(scrollOffset.x / tempScaleDiffX, content.x,
|
|
|
|
content.XMost() - metrics.mCompositionBounds.width / tempScaleDiffX) - metricsScrollOffset.x;
|
2013-04-28 10:46:30 +04:00
|
|
|
scaleDiff.width = tempScaleDiffX;
|
|
|
|
}
|
|
|
|
|
2013-06-11 17:46:51 +04:00
|
|
|
if (mContentRect.height * scaleY < metrics.mCompositionBounds.height) {
|
2013-05-01 22:12:08 +04:00
|
|
|
fixedOffset.y = -metricsScrollOffset.y;
|
2013-06-11 17:46:51 +04:00
|
|
|
scaleDiff.height = std::min(1.0f, metrics.mCompositionBounds.height / content.height);
|
2013-04-28 10:46:30 +04:00
|
|
|
} else {
|
2013-06-11 17:46:51 +04:00
|
|
|
fixedOffset.y = clamped(scrollOffset.y / tempScaleDiffY, content.y,
|
|
|
|
content.YMost() - metrics.mCompositionBounds.height / tempScaleDiffY) - metricsScrollOffset.y;
|
2013-04-28 10:46:30 +04:00
|
|
|
scaleDiff.height = tempScaleDiffY;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
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);
|
|
|
|
layerComposite->SetShadowTransform(computedTransform);
|
2013-05-16 16:34:24 +04:00
|
|
|
NS_ASSERTION(!layerComposite->GetShadowTransformSetByAnimation(),
|
|
|
|
"overwriting animated transform!");
|
2013-05-01 22:12:08 +04:00
|
|
|
TransformFixedLayers(aLayer, fixedOffset, scaleDiff, fixedLayerMargins);
|
2013-04-28 10:46:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AsyncCompositionManager::TransformShadowTree(TimeStamp aCurrentFrame)
|
|
|
|
{
|
|
|
|
Layer* root = mLayerManager->GetRoot();
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
const gfx3DMatrix& rootTransform = root->GetTransform();
|
|
|
|
|
|
|
|
// 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]) {
|
|
|
|
TransformScrollableLayer(scrollableLayers[i], rootTransform);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return wantNextFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-03 17:58:07 +04:00
|
|
|
AsyncCompositionManager::SetFirstPaintViewport(const LayerIntPoint& aOffset,
|
2013-04-28 10:46:30 +04:00
|
|
|
float 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-04-28 10:46:30 +04:00
|
|
|
float aDisplayResolution,
|
|
|
|
bool aLayersUpdated,
|
2013-06-03 17:53:32 +04:00
|
|
|
ScreenPoint& aScrollOffset,
|
2013-04-28 10:46:30 +04:00
|
|
|
float& aScaleX, float& aScaleY,
|
|
|
|
gfx::Margin& 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,
|
|
|
|
aScaleX, aScaleY,
|
|
|
|
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-05-01 22:12:08 +04:00
|
|
|
AsyncCompositionManager::SyncFrameMetrics(const gfx::Point& 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-05-01 18:49:27 +04:00
|
|
|
float aDisplayResolution,
|
|
|
|
bool aIsFirstPaint,
|
|
|
|
gfx::Margin& 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
|