Bug 811950 - Refactoring to use gfxPoint and gfxSize more. r=cjones

This commit is contained in:
Anthony Jones 2012-12-23 10:51:39 -05:00
parent f0fee81267
commit 8ada9278ac
5 changed files with 31 additions and 36 deletions

View File

@ -85,9 +85,9 @@ public:
return mResolution * mDevPixelsPerCSSPixel;
}
gfx::Point GetScrollOffsetInLayerPixels() const
gfxPoint GetScrollOffsetInLayerPixels() const
{
return gfx::Point(
return gfxPoint(
static_cast<gfx::Float>(
mScrollOffset.x * LayersPixelsPerCSSPixel().width),
static_cast<gfx::Float>(

View File

@ -992,12 +992,12 @@ bool AsyncPanZoomController::SampleContentTransformForFrame(const TimeStamp& aSa
const gfx3DMatrix& currentTransform = aLayer->GetTransform();
// Scales on the root layer, on what's currently painted.
float rootScaleX = currentTransform.GetXScale(),
rootScaleY = currentTransform.GetYScale();
gfxSize rootScale(currentTransform.GetXScale(),
currentTransform.GetYScale());
gfx::Point metricsScrollOffset(0, 0);
gfx::Point scrollOffset;
float localScaleX, localScaleY;
gfxPoint metricsScrollOffset(0, 0);
gfxPoint scrollOffset;
gfxSize localScale;
const FrameMetrics& frame = aLayer->GetFrameMetrics();
{
MonitorAutoLock mon(mMonitor);
@ -1049,22 +1049,19 @@ bool AsyncPanZoomController::SampleContentTransformForFrame(const TimeStamp& aSa
// what PZC has transformed due to touches like panning or
// pinching. Eventually, the root layer transform will become this
// during runtime, but we must wait for Gecko to repaint.
gfxSize localScale = CalculateResolution(mFrameMetrics);
localScaleX = localScale.width;
localScaleY = localScale.height;
localScale = CalculateResolution(mFrameMetrics);
if (frame.IsScrollable()) {
metricsScrollOffset = frame.GetScrollOffsetInLayerPixels();
}
scrollOffset = mFrameMetrics.mScrollOffset;
scrollOffset = gfxPoint(mFrameMetrics.mScrollOffset.x, mFrameMetrics.mScrollOffset.y);
}
nsIntPoint scrollCompensation(
NS_lround((scrollOffset.x / rootScaleX - metricsScrollOffset.x) * localScaleX),
NS_lround((scrollOffset.y / rootScaleY - metricsScrollOffset.y) * localScaleY));
*aNewTransform = ViewTransform(-scrollCompensation, localScaleX, localScaleY);
((scrollOffset / rootScale - metricsScrollOffset) * localScale)
.RoundedAwayFromZero());
*aNewTransform = ViewTransform(-scrollCompensation, localScale);
mLastSampleTime = aSampleTime;

View File

@ -657,7 +657,7 @@ Translate2D(gfx3DMatrix& aTransform, const gfxPoint& aOffset)
void
CompositorParent::TransformFixedLayers(Layer* aLayer,
const gfxPoint& aTranslation,
const gfxPoint& aScaleDiff)
const gfxSize& aScaleDiff)
{
if (aLayer->GetIsFixedPosition() &&
!aLayer->GetParent()->GetIsFixedPosition()) {
@ -665,8 +665,7 @@ CompositorParent::TransformFixedLayers(Layer* aLayer,
// 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.x - (anchor.x - anchor.x / aScaleDiff.x),
aTranslation.y - (anchor.y - anchor.y / aScaleDiff.y));
gfxPoint translation(aTranslation - (anchor - anchor / aScaleDiff));
// The transform already takes the resolution scale into account. Since we
// will apply the resolution scale again when computing the effective
@ -875,9 +874,8 @@ CompositorParent::ApplyAsyncContentTransformToTree(TimeStamp aCurrentFrame,
TransformFixedLayers(
aLayer,
-gfxPoint(treeTransform.mTranslation.x / treeTransform.mXScale,
treeTransform.mTranslation.y / treeTransform.mYScale),
gfxPoint(treeTransform.mXScale, treeTransform.mYScale));
-gfxPoint(treeTransform.mTranslation) / treeTransform.mScale,
treeTransform.mScale);
appliedTransform = true;
}
@ -921,7 +919,7 @@ CompositorParent::TransformShadowTree(TimeStamp aCurrentFrame)
// Translate fixed position layers so that they stay in the correct position
// when mScrollOffset and metricsScrollOffset differ.
gfxPoint offset;
gfxPoint scaleDiff;
gfxSize scaleDiff;
float rootScaleX = rootTransform.GetXScale(),
rootScaleY = rootTransform.GetYScale();
@ -931,7 +929,7 @@ CompositorParent::TransformShadowTree(TimeStamp aCurrentFrame)
// as a FrameMetrics helper because it's a deprecated conversion.
float devPixelRatioX = 1 / rootScaleX, devPixelRatioY = 1 / rootScaleY;
gfx::Point scrollOffsetLayersPixels(metrics.GetScrollOffsetInLayerPixels());
gfxPoint scrollOffsetLayersPixels(metrics.GetScrollOffsetInLayerPixels());
nsIntPoint scrollOffsetDevPixels(
NS_lround(scrollOffsetLayersPixels.x * devPixelRatioX),
NS_lround(scrollOffsetLayersPixels.y * devPixelRatioY));
@ -983,29 +981,30 @@ CompositorParent::TransformShadowTree(TimeStamp aCurrentFrame)
nsIntPoint scrollCompensation(
(mScrollOffset.x / tempScaleDiffX - metricsScrollOffset.x) * mXScale,
(mScrollOffset.y / tempScaleDiffY - metricsScrollOffset.y) * mYScale);
treeTransform = gfx3DMatrix(ViewTransform(-scrollCompensation, mXScale, mYScale));
treeTransform = gfx3DMatrix(ViewTransform(-scrollCompensation,
gfxSize(mXScale, mYScale)));
// If the contents can fit entirely within the widget area on a particular
// dimenson, we need to translate and scale so that the fixed layers remain
// within the page boundaries.
if (mContentRect.width * tempScaleDiffX < mWidgetSize.width) {
offset.x = -metricsScrollOffset.x;
scaleDiff.x = NS_MIN(1.0f, mWidgetSize.width / (float)mContentRect.width);
scaleDiff.height = NS_MIN(1.0f, mWidgetSize.width / (float)mContentRect.width);
} else {
offset.x = clamped(mScrollOffset.x / tempScaleDiffX, (float)mContentRect.x,
mContentRect.XMost() - mWidgetSize.width / tempScaleDiffX) -
metricsScrollOffset.x;
scaleDiff.x = tempScaleDiffX;
scaleDiff.height = tempScaleDiffX;
}
if (mContentRect.height * tempScaleDiffY < mWidgetSize.height) {
offset.y = -metricsScrollOffset.y;
scaleDiff.y = NS_MIN(1.0f, mWidgetSize.height / (float)mContentRect.height);
scaleDiff.width = NS_MIN(1.0f, mWidgetSize.height / (float)mContentRect.height);
} else {
offset.y = clamped(mScrollOffset.y / tempScaleDiffY, (float)mContentRect.y,
mContentRect.YMost() - mWidgetSize.height / tempScaleDiffY) -
metricsScrollOffset.y;
scaleDiff.y = tempScaleDiffY;
scaleDiff.width = tempScaleDiffY;
}
// The transform already takes the resolution scale into account. Since we

View File

@ -36,22 +36,21 @@ class LayerManager;
// Represents (affine) transforms that are calculated from a content view.
struct ViewTransform {
ViewTransform(nsIntPoint aTranslation = nsIntPoint(0, 0), float aXScale = 1, float aYScale = 1)
ViewTransform(nsIntPoint aTranslation = nsIntPoint(0, 0),
gfxSize aScale = gfxSize(1, 1))
: mTranslation(aTranslation)
, mXScale(aXScale)
, mYScale(aYScale)
, mScale(aScale)
{}
operator gfx3DMatrix() const
{
return
gfx3DMatrix::ScalingMatrix(mXScale, mYScale, 1) *
gfx3DMatrix::ScalingMatrix(mScale.width, mScale.height, 1) *
gfx3DMatrix::Translation(mTranslation.x, mTranslation.y, 0);
}
nsIntPoint mTranslation;
float mXScale;
float mYScale;
gfxSize mScale;
};
class CompositorParent : public PCompositorParent,
@ -249,7 +248,7 @@ private:
*/
void TransformFixedLayers(Layer* aLayer,
const gfxPoint& aTranslation,
const gfxPoint& aScaleDiff);
const gfxSize& aScaleDiff);
virtual PGrallocBufferParent* AllocPGrallocBuffer(
const gfxIntSize&, const uint32_t&, const uint32_t&,

View File

@ -165,7 +165,7 @@ ComputeShadowTreeTransform(nsIFrame* aContainerFrame,
nsIntPoint scrollOffset =
aConfig.mScrollOffset.ToNearestPixels(auPerDevPixel);
// metricsScrollOffset is in layer coordinates.
gfx::Point metricsScrollOffset = aMetrics->GetScrollOffsetInLayerPixels();
gfxPoint metricsScrollOffset = aMetrics->GetScrollOffsetInLayerPixels();
nsIntPoint roundedMetricsScrollOffset =
nsIntPoint(NS_lround(metricsScrollOffset.x), NS_lround(metricsScrollOffset.y));