Bug 706179 Part 2: Add a BaseTransform and scaling to layers, r=roc, cjones

This commit is contained in:
David Zbarsky 2012-07-30 19:20:00 -07:00
parent c6b51c42c1
commit c83e9b7631
13 changed files with 75 additions and 28 deletions

View File

@ -361,12 +361,24 @@ Layer::CalculateScissorRect(const nsIntRect& aCurrentScissorRect,
return currentClip.Intersect(scissor);
}
const gfx3DMatrix&
const gfx3DMatrix
Layer::GetTransform()
{
gfx3DMatrix transform = mTransform;
transform.Scale(mXScale, mYScale, 1);
return transform;
}
const gfx3DMatrix
Layer::GetLocalTransform()
{
gfx3DMatrix transform;
if (ShadowLayer* shadow = AsShadowLayer())
return shadow->GetShadowTransform();
return mTransform;
transform = shadow->GetShadowTransform();
else
transform = mTransform;
transform.Scale(mXScale, mYScale, 1);
return transform;
}
float

View File

@ -634,12 +634,19 @@ public:
* XXX Currently only transformations corresponding to 2D affine transforms
* are supported.
*/
void SetTransform(const gfx3DMatrix& aMatrix)
void SetBaseTransform(const gfx3DMatrix& aMatrix)
{
mTransform = aMatrix;
Mutated();
}
void SetScale(float aXScale, float aYScale)
{
mXScale = aXScale;
mYScale = aYScale;
Mutated();
}
/**
* CONSTRUCTION PHASE ONLY
* A layer is "fixed position" when it draws content from a content
@ -667,7 +674,10 @@ public:
Layer* GetPrevSibling() { return mPrevSibling; }
virtual Layer* GetFirstChild() { return nullptr; }
virtual Layer* GetLastChild() { return nullptr; }
const gfx3DMatrix& GetTransform() { return mTransform; }
const gfx3DMatrix GetTransform();
const gfx3DMatrix& GetBaseTransform() { return mTransform; }
float GetXScale() { return mXScale; }
float GetYScale() { return mYScale; }
bool GetIsFixedPosition() { return mIsFixedPosition; }
gfxPoint GetFixedPositionAnchor() { return mAnchor; }
Layer* GetMaskLayer() { return mMaskLayer; }
@ -879,6 +889,8 @@ protected:
mPrevSibling(nullptr),
mImplData(aImplData),
mMaskLayer(nullptr),
mXScale(1.0f),
mYScale(1.0f),
mOpacity(1.0),
mContentFlags(0),
mUseClipRect(false),
@ -900,7 +912,7 @@ protected:
* Returns the local transform for this layer: either mTransform or,
* for shadow layers, GetShadowTransform()
*/
const gfx3DMatrix& GetLocalTransform();
const gfx3DMatrix GetLocalTransform();
/**
* Computes a tweaked version of aTransform that snaps a point or a rectangle
@ -926,6 +938,8 @@ protected:
gfx::UserData mUserData;
nsIntRegion mVisibleRegion;
gfx3DMatrix mTransform;
float mXScale;
float mYScale;
gfx3DMatrix mEffectiveTransform;
float mOpacity;
nsIntRect mClipRect;

View File

@ -510,7 +510,10 @@ CompositorParent::TransformFixedLayers(Layer* aLayer,
gfxPoint translation(aTranslation.x - (anchor.x - anchor.x / aScaleDiff.x),
aTranslation.y - (anchor.y - anchor.y / aScaleDiff.y));
gfx3DMatrix layerTransform = aLayer->GetTransform();
// We are only translating the transform, so it is OK to translate the
// transform without the resolution scale. This allows us to avoid applying
// the resolution scale and its inverse an extra time.
gfx3DMatrix layerTransform = aLayer->GetBaseTransform();
Translate2D(layerTransform, translation);
ShadowLayer* shadow = aLayer->AsShadowLayer();
shadow->SetShadowTransform(layerTransform);
@ -536,7 +539,8 @@ SetShadowProperties(Layer* aLayer)
{
// FIXME: Bug 717688 -- Do these updates in ShadowLayersParent::RecvUpdate.
ShadowLayer* shadow = aLayer->AsShadowLayer();
shadow->SetShadowTransform(aLayer->GetTransform());
// Set the shadow's base transform to the layer's base transform.
shadow->SetShadowTransform(aLayer->GetBaseTransform());
shadow->SetShadowVisibleRegion(aLayer->GetVisibleRegion());
shadow->SetShadowClipRect(aLayer->GetClipRect());
@ -592,6 +596,8 @@ CompositorParent::TransformShadowTree(TimeStamp aCurrentFrame)
Layer* root = mLayerManager->GetRoot();
const FrameMetrics& metrics = container->GetFrameMetrics();
// We must apply the resolution scale before a pan/zoom transform, so we call
// GetTransform here.
const gfx3DMatrix& rootTransform = root->GetTransform();
const gfx3DMatrix& currentTransform = layer->GetTransform();
@ -683,7 +689,14 @@ CompositorParent::TransformShadowTree(TimeStamp aCurrentFrame)
scaleDiff.y = tempScaleDiffY;
}
shadow->SetShadowTransform(treeTransform * currentTransform);
// 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/layer->GetXScale(),
1.0f/layer->GetYScale(),
1);
shadow->SetShadowTransform(computedTransform);
TransformFixedLayers(layer, offset, scaleDiff);
}

View File

@ -54,6 +54,8 @@ union CanvasSurface {
// Change a layer's attributes
struct CommonLayerAttributes {
nsIntRegion visibleRegion;
float xScale;
float yScale;
gfx3DMatrix transform;
PRUint32 contentFlags;
float opacity;

View File

@ -298,7 +298,9 @@ ShadowLayerForwarder::EndTransaction(InfallibleTArray<EditReply>* aReplies)
LayerAttributes attrs;
CommonLayerAttributes& common = attrs.common();
common.visibleRegion() = mutant->GetVisibleRegion();
common.transform() = mutant->GetTransform();
common.xScale() = mutant->GetXScale();
common.yScale() = mutant->GetYScale();
common.transform() = mutant->GetBaseTransform();
common.contentFlags() = mutant->GetContentFlags();
common.opacity() = mutant->GetOpacity();
common.useClipRect() = !!mutant->GetClipRect();

View File

@ -216,7 +216,8 @@ ShadowLayersParent::RecvUpdate(const InfallibleTArray<Edit>& cset,
layer->SetContentFlags(common.contentFlags());
layer->SetOpacity(common.opacity());
layer->SetClipRect(common.useClipRect() ? &common.clipRect() : NULL);
layer->SetTransform(common.transform());
layer->SetBaseTransform(common.transform());
layer->SetScale(common.xScale(), common.yScale());
static bool fixedPositionLayersEnabled = getenv("MOZ_ENABLE_FIXED_POSITION_LAYERS") != 0;
if (fixedPositionLayersEnabled) {
layer->SetIsFixedPosition(common.isFixedPosition());

View File

@ -944,6 +944,7 @@ ContainerState::CreateOrRecycleColorLayer()
// We will reapply any necessary clipping.
layer->SetClipRect(nullptr);
layer->SetMaskLayer(nullptr);
layer->SetScale(1.0f, 1.0f);
} else {
// Create a new layer
layer = mManager->CreateColorLayer();
@ -967,6 +968,7 @@ ContainerState::CreateOrRecycleImageLayer()
// We will reapply any necessary clipping.
layer->SetClipRect(nullptr);
layer->SetMaskLayer(nullptr);
layer->SetScale(1.0f, 1.0f);
} else {
// Create a new layer
layer = mManager->CreateImageLayer();
@ -1058,6 +1060,7 @@ ContainerState::CreateOrRecycleThebesLayer(nsIFrame* aActiveScrolledRoot)
// We will reapply any necessary clipping.
layer->SetClipRect(nullptr);
layer->SetMaskLayer(nullptr);
layer->SetScale(1.0f, 1.0f);
data = static_cast<ThebesDisplayItemLayerUserData*>
(layer->GetUserData(&gThebesDisplayItemLayerUserData));
@ -1111,7 +1114,8 @@ ContainerState::CreateOrRecycleThebesLayer(nsIFrame* aActiveScrolledRoot)
RoundToMatchResidual(scaledOffset.y, data->mActiveScrolledRootPosition.y));
gfxMatrix matrix;
matrix.Translate(gfxPoint(pixOffset.x, pixOffset.y));
layer->SetTransform(gfx3DMatrix::From2D(matrix));
layer->SetBaseTransform(gfx3DMatrix::From2D(matrix));
layer->SetScale(1.0f, 1.0f);
// FIXME: Temporary workaround for bug 681192 and bug 724786.
#ifndef MOZ_JAVA_COMPOSITOR
@ -1266,7 +1270,7 @@ ContainerState::PopThebesLayerData()
// The layer's current transform is applied first, then the result is scaled.
gfx3DMatrix transform = imageLayer->GetTransform()*
gfx3DMatrix::ScalingMatrix(mParameters.mXScale, mParameters.mYScale, 1.0f);
imageLayer->SetTransform(transform);
imageLayer->SetBaseTransform(transform);
if (data->mItemClip.mHaveClipRect) {
nsIntRect clip = ScaleToNearestPixels(data->mItemClip.mClipRect);
imageLayer->IntersectClipRect(clip);
@ -1278,7 +1282,8 @@ ContainerState::PopThebesLayerData()
colorLayer->SetColor(data->mSolidColor);
// Copy transform
colorLayer->SetTransform(data->mLayer->GetTransform());
colorLayer->SetBaseTransform(data->mLayer->GetBaseTransform());
colorLayer->SetScale(data->mLayer->GetXScale(), data->mLayer->GetYScale());
// Clip colorLayer to its visible region, since ColorLayers are
// allowed to paint outside the visible region. Here we rely on the
@ -1777,7 +1782,7 @@ ContainerState::ProcessDisplayItems(const nsDisplayList& aList,
// The layer's current transform is applied first, then the result is scaled.
gfx3DMatrix transform = ownLayer->GetTransform()*
gfx3DMatrix::ScalingMatrix(mParameters.mXScale, mParameters.mYScale, 1.0f);
ownLayer->SetTransform(transform);
ownLayer->SetBaseTransform(transform);
}
ownLayer->SetIsFixedPosition(
@ -2123,7 +2128,7 @@ ChooseScaleAndSetTransform(FrameLayerBuilder* aLayerBuilder,
// Apply the inverse of our resolution-scale before the rest of our transform
transform = gfx3DMatrix::ScalingMatrix(1.0/scale.width, 1.0/scale.height, 1.0)*transform;
aLayer->SetTransform(transform);
aLayer->SetBaseTransform(transform);
FrameLayerBuilder::ContainerParameters
result(scale.width, scale.height, aIncomingScale);
@ -3129,7 +3134,7 @@ ContainerState::SetupMaskLayer(Layer *aLayer, const FrameLayerBuilder::Clip& aCl
}
maskLayer->SetContainer(container);
maskLayer->SetTransform(gfx3DMatrix::From2D(maskTransform.Invert()));
maskLayer->SetBaseTransform(gfx3DMatrix::From2D(maskTransform.Invert()));
// save the details of the clip in user data
userData->mScaleX = newData.mScaleX;

View File

@ -620,10 +620,8 @@ void nsDisplayList::PaintForFrame(nsDisplayListBuilder* aBuilder,
return;
}
// Root is being scaled up by the X/Y resolution. Scale it back down.
gfx3DMatrix rootTransform = root->GetTransform()*
gfx3DMatrix::ScalingMatrix(1.0f/containerParameters.mXScale,
1.0f/containerParameters.mYScale, 1.0f);
root->SetTransform(rootTransform);
root->SetScale(1.0f/containerParameters.mXScale,
1.0f/containerParameters.mYScale);
ViewID id = presContext->IsRootContentDocument() ? FrameMetrics::ROOT_SCROLL_ID
: FrameMetrics::NULL_SCROLL_ID;
@ -1282,7 +1280,7 @@ nsDisplayBackground::ConfigureLayer(ImageLayer* aLayer)
transform.Translate(mDestRect.TopLeft());
transform.Scale(mDestRect.width/imageSize.width,
mDestRect.height/imageSize.height);
aLayer->SetTransform(gfx3DMatrix::From2D(transform));
aLayer->SetBaseTransform(gfx3DMatrix::From2D(transform));
aLayer->SetVisibleRegion(nsIntRect(0, 0, imageSize.width, imageSize.height));
}

View File

@ -278,7 +278,7 @@ nsHTMLCanvasFrame::BuildLayer(nsDisplayListBuilder* aBuilder,
gfxMatrix transform;
transform.Translate(r.TopLeft());
transform.Scale(r.Width()/canvasSize.width, r.Height()/canvasSize.height);
layer->SetTransform(gfx3DMatrix::From2D(transform));
layer->SetBaseTransform(gfx3DMatrix::From2D(transform));
layer->SetFilter(nsLayoutUtils::GetGraphicsFilterForFrame(this));
layer->SetVisibleRegion(nsIntRect(0, 0, canvasSize.width, canvasSize.height));

View File

@ -1289,7 +1289,7 @@ nsDisplayImage::ConfigureLayer(ImageLayer *aLayer)
transform.Translate(destRect.TopLeft());
transform.Scale(destRect.Width()/imageWidth,
destRect.Height()/imageHeight);
aLayer->SetTransform(gfx3DMatrix::From2D(transform));
aLayer->SetBaseTransform(gfx3DMatrix::From2D(transform));
aLayer->SetVisibleRegion(nsIntRect(0, 0, imageWidth, imageHeight));
}

View File

@ -1723,7 +1723,7 @@ nsObjectFrame::BuildLayer(nsDisplayListBuilder* aBuilder,
gfxMatrix transform;
transform.Translate(r.TopLeft());
layer->SetTransform(gfx3DMatrix::From2D(transform));
layer->SetBaseTransform(gfx3DMatrix::From2D(transform));
layer->SetVisibleRegion(nsIntRect(0, 0, size.width, size.height));
return layer.forget();
}

View File

@ -206,7 +206,7 @@ nsVideoFrame::BuildLayer(nsDisplayListBuilder* aBuilder,
gfxMatrix transform;
transform.Translate(r.TopLeft());
transform.Scale(r.Width()/frameSize.width, r.Height()/frameSize.height);
layer->SetTransform(gfx3DMatrix::From2D(transform));
layer->SetBaseTransform(gfx3DMatrix::From2D(transform));
layer->SetVisibleRegion(nsIntRect(0, 0, frameSize.width, frameSize.height));
nsRefPtr<Layer> result = layer.forget();
return result.forget();

View File

@ -248,7 +248,7 @@ TransformShadowTree(nsDisplayListBuilder* aBuilder, nsFrameLoader* aFrameLoader,
const FrameMetrics* metrics = GetFrameMetrics(aLayer);
gfx3DMatrix shadowTransform = aLayer->GetTransform();
gfx3DMatrix shadowTransform = aLayer->GetBaseTransform();
ViewTransform layerTransform = aTransform;
if (metrics && metrics->IsScrollable()) {
@ -603,7 +603,7 @@ RenderFrameParent::BuildLayer(nsDisplayListBuilder* aBuilder,
layer->SetReferentId(id);
layer->SetVisibleRegion(aVisibleRect);
nsIntPoint rootFrameOffset = GetRootFrameOffset(aFrame, aBuilder);
layer->SetTransform(
layer->SetBaseTransform(
gfx3DMatrix::Translation(rootFrameOffset.x, rootFrameOffset.y, 0.0));
return layer.forget();