Bug 1076163 - Clean up the resolution-related fields and methods in FrameMetrics. r=kats

This commit is contained in:
Botond Ballo 2014-10-20 17:12:35 -04:00
parent 08963b106d
commit 2124b8b94c
14 changed files with 83 additions and 75 deletions

View File

@ -250,7 +250,7 @@ TabChildBase::InitializeRootMetrics()
mLastRootMetrics.GetZoom() / mLastRootMetrics.mDevPixelsPerCSSPixel * ScreenToLayerScale(1);
// This is the root layer, so the cumulative resolution is the same
// as the resolution.
mLastRootMetrics.mResolution = mLastRootMetrics.mCumulativeResolution / LayoutDeviceToParentLayerScale(1);
mLastRootMetrics.mPresShellResolution = mLastRootMetrics.mCumulativeResolution / LayoutDeviceToParentLayerScale(1);
mLastRootMetrics.SetScrollOffset(CSSPoint(0, 0));
TABC_LOG("After InitializeRootMetrics, mLastRootMetrics is %s\n",
@ -417,8 +417,8 @@ TabChildBase::HandlePossibleViewportChange(const ScreenIntSize& aOldScreenSize)
metrics.mCumulativeResolution = metrics.GetZoom() / metrics.mDevPixelsPerCSSPixel * ScreenToLayerScale(1);
// This is the root layer, so the cumulative resolution is the same
// as the resolution.
metrics.mResolution = metrics.mCumulativeResolution / LayoutDeviceToParentLayerScale(1);
utils->SetResolution(metrics.mResolution.scale, metrics.mResolution.scale);
metrics.mPresShellResolution = metrics.mCumulativeResolution / LayoutDeviceToParentLayerScale(1);
utils->SetResolution(metrics.mPresShellResolution.scale, metrics.mPresShellResolution.scale);
CSSSize scrollPort = metrics.CalculateCompositedSizeInCssPixels();
utils->SetScrollPositionClampingScrollPortSize(scrollPort.width, scrollPort.height);
@ -907,8 +907,8 @@ TabChild::Observe(nsISupports *aSubject,
// until we we get an inner size.
if (HasValidInnerSize()) {
InitializeRootMetrics();
utils->SetResolution(mLastRootMetrics.mResolution.scale,
mLastRootMetrics.mResolution.scale);
utils->SetResolution(mLastRootMetrics.mPresShellResolution.scale,
mLastRootMetrics.mPresShellResolution.scale);
HandlePossibleViewportChange(mInnerSize);
}
}

View File

@ -741,7 +741,7 @@ struct ParamTraits<mozilla::layers::FrameMetrics>
WriteParam(aMsg, aParam.mRootCompositionSize);
WriteParam(aMsg, aParam.mScrollId);
WriteParam(aMsg, aParam.mScrollParentId);
WriteParam(aMsg, aParam.mResolution);
WriteParam(aMsg, aParam.mPresShellResolution);
WriteParam(aMsg, aParam.mCumulativeResolution);
WriteParam(aMsg, aParam.mZoom);
WriteParam(aMsg, aParam.mDevPixelsPerCSSPixel);
@ -783,7 +783,7 @@ struct ParamTraits<mozilla::layers::FrameMetrics>
ReadParam(aMsg, aIter, &aResult->mRootCompositionSize) &&
ReadParam(aMsg, aIter, &aResult->mScrollId) &&
ReadParam(aMsg, aIter, &aResult->mScrollParentId) &&
ReadParam(aMsg, aIter, &aResult->mResolution) &&
ReadParam(aMsg, aIter, &aResult->mPresShellResolution) &&
ReadParam(aMsg, aIter, &aResult->mCumulativeResolution) &&
ReadParam(aMsg, aIter, &aResult->mZoom) &&
ReadParam(aMsg, aIter, &aResult->mDevPixelsPerCSSPixel) &&

View File

@ -76,7 +76,7 @@ public:
, mDisplayPort(0, 0, 0, 0)
, mCriticalDisplayPort(0, 0, 0, 0)
, mScrollableRect(0, 0, 0, 0)
, mResolution(1)
, mPresShellResolution(1)
, mCumulativeResolution(1)
, mTransformScale(1)
, mDevPixelsPerCSSPixel(1)
@ -114,7 +114,7 @@ public:
mCriticalDisplayPort.IsEqualEdges(aOther.mCriticalDisplayPort) &&
mViewport.IsEqualEdges(aOther.mViewport) &&
mScrollableRect.IsEqualEdges(aOther.mScrollableRect) &&
mResolution == aOther.mResolution &&
mPresShellResolution == aOther.mPresShellResolution &&
mCumulativeResolution == aOther.mCumulativeResolution &&
mDevPixelsPerCSSPixel == aOther.mDevPixelsPerCSSPixel &&
mMayHaveTouchListeners == aOther.mMayHaveTouchListeners &&
@ -171,14 +171,10 @@ public:
return mCumulativeResolution * mDevPixelsPerCSSPixel;
}
LayerPoint GetScrollOffsetInLayerPixels() const
// Get the amount by which this frame has been zoomed since the last repaint.
LayerToScreenScale GetAsyncZoom() const
{
return GetScrollOffset() * LayersPixelsPerCSSPixel();
}
LayoutDeviceToParentLayerScale GetParentResolution() const
{
return mCumulativeResolution / mResolution;
return mZoom / LayersPixelsPerCSSPixel();
}
// Ensure the scrollableRect is at least as big as the compositionBounds
@ -343,14 +339,17 @@ public:
// The following metrics are dimensionless.
//
// The incremental resolution that the current frame has been painted at
// relative to the parent frame's resolution. This information is provided
// by Gecko at layout/paint time.
ParentLayerToLayerScale mResolution;
// The pres-shell resolution that has been induced on the document containing
// this scroll frame as a result of zooming this scroll frame (whether via
// user action, or choosing an initial zoom level on page load). This can
// only be different from 1.0 for frames that are zoomable, which currently
// is just the root content document's root scroll frame (mIsRoot = true).
ParentLayerToLayerScale mPresShellResolution;
// The cumulative resolution that the current frame has been painted at.
// This is the product of our mResolution and the mResolutions of our parent frames.
// This information is provided by Gecko at layout/paint time.
// This is the product of the pres-shell resolutions of the document
// containing this scroll frame and its ancestors, and any css-driven
// resolution. This information is provided by Gecko at layout/paint time.
LayoutDeviceToLayerScale mCumulativeResolution;
// TODO(botond): This is now always 1 and should be removed (see bug 1055741).

View File

@ -159,7 +159,7 @@ AppendToString(std::stringstream& aStream, const FrameMetrics& m,
AppendToString(aStream, m.GetRootCompositionSize(), " rcs=");
AppendToString(aStream, m.GetViewport(), " v=");
aStream << nsPrintfCString(" z=(ld=%.3f r=%.3f cr=%.3f z=%.3f ts=%.3f)",
m.mDevPixelsPerCSSPixel.scale, m.mResolution.scale,
m.mDevPixelsPerCSSPixel.scale, m.mPresShellResolution.scale,
m.mCumulativeResolution.scale, m.GetZoom().scale,
m.mTransformScale.scale).get();
aStream << nsPrintfCString(" u=(%d %d %lu)",

View File

@ -197,12 +197,17 @@ ComputeTouchSensitiveRegion(GeckoContentController* aController,
ParentLayerRect visible(aMetrics.mCompositionBounds);
CSSRect touchSensitiveRegion;
if (aController->GetTouchSensitiveRegion(&touchSensitiveRegion)) {
// Note: we assume here that touchSensitiveRegion is in the CSS pixels
// of our parent layer, which makes this coordinate conversion
// correct.
// Here we assume 'touchSensitiveRegion' is in the CSS pixels of the
// parent frame. To convert it to ParentLayer pixels, we therefore need
// the cumulative resolution of the parent frame. We approximate this as
// the quotient of our cumulative resolution and our pres shell resolution;
// this approximation may not be accurate in the presence of a css-driven
// resolution.
LayoutDeviceToParentLayerScale parentCumulativeResolution =
aMetrics.mCumulativeResolution / aMetrics.mPresShellResolution;
visible = visible.Intersect(touchSensitiveRegion
* aMetrics.mDevPixelsPerCSSPixel
* aMetrics.GetParentResolution());
* parentCumulativeResolution);
}
// Not sure what rounding option is the most correct here, but if we ever

View File

@ -2588,9 +2588,8 @@ ViewTransform AsyncPanZoomController::GetCurrentAsyncTransform() const {
}
}
ParentLayerToScreenScale scale = mFrameMetrics.GetZoom()
/ mLastContentPaintMetrics.mDevPixelsPerCSSPixel
/ mFrameMetrics.GetParentResolution();
ParentLayerToScreenScale scale = mFrameMetrics.mPresShellResolution // non-transient portion
* mFrameMetrics.GetAsyncZoom(); // transient portion
ScreenPoint translation = (currentScrollOffset - lastPaintScrollOffset)
* mFrameMetrics.GetZoom();
@ -2599,24 +2598,27 @@ ViewTransform AsyncPanZoomController::GetCurrentAsyncTransform() const {
Matrix4x4 AsyncPanZoomController::GetNontransientAsyncTransform() const {
ReentrantMonitorAutoEnter lock(mMonitor);
return Matrix4x4::Scaling(mLastContentPaintMetrics.mResolution.scale,
mLastContentPaintMetrics.mResolution.scale,
return Matrix4x4::Scaling(mLastContentPaintMetrics.mPresShellResolution.scale,
mLastContentPaintMetrics.mPresShellResolution.scale,
1.0f);
}
Matrix4x4 AsyncPanZoomController::GetTransformToLastDispatchedPaint() const {
ReentrantMonitorAutoEnter lock(mMonitor);
// Technically we should be taking the scroll delta in the coordinate space
// of transformed layer pixels (i.e. this layer's LayerPixels, with the layer
// transform applied). However in the absence of actual CSS transforms, we
// can use the parent-layer space instead.
// When we fix bug 993525 and properly support CSS transforms we might have
// to revisit this.
ParentLayerPoint scrollChange =
(mLastContentPaintMetrics.GetScrollOffset() - mLastDispatchedPaintMetrics.GetScrollOffset())
* mLastContentPaintMetrics.mDevPixelsPerCSSPixel
* mLastContentPaintMetrics.GetParentResolution();
* mLastContentPaintMetrics.mCumulativeResolution
// This transform ("LD" in the terminology of the comment above
// GetScreenToApzcTransform() in APZCTreeManager.h) is applied in a
// coordinate space that includes the APZC's CSS transform ("LC").
// This CSS transform is the identity unless this APZC sets a pres-shell
// resolution, in which case the transform has a post-scale that cancels
// out the pres-shell resolution. We simulate applying the "LC" transform
// by dividing by the pres-shell resolution. This will go away once
// bug 1076192 is fixed.
/ mLastContentPaintMetrics.mPresShellResolution;
float zoomChange = mLastContentPaintMetrics.GetZoom().scale / mLastDispatchedPaintMetrics.GetZoom().scale;
@ -2710,9 +2712,18 @@ void AsyncPanZoomController::NotifyLayersUpdated(const FrameMetrics& aLayerMetri
if (FuzzyEqualsAdditive(mFrameMetrics.mCompositionBounds.width, aLayerMetrics.mCompositionBounds.width) &&
mFrameMetrics.mDevPixelsPerCSSPixel == aLayerMetrics.mDevPixelsPerCSSPixel) {
float parentResolutionChange = aLayerMetrics.GetParentResolution().scale
/ mFrameMetrics.GetParentResolution().scale;
mFrameMetrics.ZoomBy(parentResolutionChange);
// Any change to the pres shell resolution was requested by APZ and is
// already included in our zoom; however, other components of the
// cumulative resolution (a parent document's pres-shell resolution, or
// the css-driven resolution) may have changed, and we need to update
// our zoom to reflect that. Note that we can't just take
// aLayerMetrics.mZoom because the APZ may have additional async zoom
// since the repaint request.
float totalResolutionChange = aLayerMetrics.mCumulativeResolution.scale
/ mFrameMetrics.mCumulativeResolution.scale;
float presShellResolutionChange = aLayerMetrics.mPresShellResolution.scale
/ mFrameMetrics.mPresShellResolution.scale;
mFrameMetrics.ZoomBy(totalResolutionChange / presShellResolutionChange);
} else {
// Take the new zoom as either device scale or composition width or both
// got changed (e.g. due to orientation change).
@ -2725,7 +2736,7 @@ void AsyncPanZoomController::NotifyLayersUpdated(const FrameMetrics& aLayerMetri
}
mFrameMetrics.mCompositionBounds = aLayerMetrics.mCompositionBounds;
mFrameMetrics.SetRootCompositionSize(aLayerMetrics.GetRootCompositionSize());
mFrameMetrics.mResolution = aLayerMetrics.mResolution;
mFrameMetrics.mPresShellResolution = aLayerMetrics.mPresShellResolution;
mFrameMetrics.mCumulativeResolution = aLayerMetrics.mCumulativeResolution;
mFrameMetrics.SetHasScrollgrab(aLayerMetrics.GetHasScrollgrab());

View File

@ -142,19 +142,12 @@ APZCCallbackHelper::UpdateRootFrame(nsIDOMWindowUtils* aUtils,
aMetrics.SetScrollOffset(actualScrollOffset);
// The mZoom variable on the frame metrics stores the CSS-to-screen scale for this
// frame. This scale includes all of the (cumulative) resolutions set on the presShells
// from the root down to this frame. However, when setting the resolution, we only
// want the piece of the resolution that corresponds to this presShell, rather than
// all of the cumulative stuff, so we need to divide out the parent resolutions.
// Finally, we multiply by a ScreenToLayerScale of 1.0f because the goal here is to
// take the async zoom calculated by the APZC and tell gecko about it (turning it into
// a "sync" zoom) which will update the resolution at which the layer is painted.
ParentLayerToLayerScale presShellResolution =
aMetrics.GetZoom()
/ aMetrics.mDevPixelsPerCSSPixel
/ aMetrics.GetParentResolution()
* ScreenToLayerScale(1.0f);
// The pres shell resolution is updated by the the async zoom since the
// last paint. The ScreenToLayerScale(1.0f) reflects this async zoom being
// turned into a "sync" zoom during the repaint.
ParentLayerToLayerScale presShellResolution = aMetrics.mPresShellResolution
* aMetrics.GetAsyncZoom()
* ScreenToLayerScale(1.0f);
aUtils->SetResolution(presShellResolution.scale, presShellResolution.scale);
// Finally, we set the displayport.

View File

@ -75,7 +75,7 @@ GetTransformToAncestorsParentLayer(Layer* aStart, const LayerMetricsWrapper& aAn
// If the layer has a non-transient async transform then we need to apply it here
// because it will get applied by the APZ in the compositor as well
const FrameMetrics& metrics = iter.Metrics();
transform.PostScale(metrics.mResolution.scale, metrics.mResolution.scale, 1.f);
transform.PostScale(metrics.mPresShellResolution.scale, metrics.mPresShellResolution.scale, 1.f);
}
return transform;
}
@ -167,7 +167,7 @@ ClientTiledPaintedLayer::BeginPaint()
// Store the resolution from the displayport ancestor layer. Because this is Gecko-side,
// before any async transforms have occurred, we can use the zoom for this.
mPaintData.mResolution = displayportMetrics.GetZoomToParent();
TILING_LOG("TILING %p: Resolution %f\n", this, mPaintData.mResolution.scale);
TILING_LOG("TILING %p: Resolution %f\n", this, mPaintData.mPresShellResolution.scale);
// Store the applicable composition bounds in this layer's Layer units.
mPaintData.mTransformToCompBounds =

View File

@ -150,9 +150,8 @@ ComputeViewTransform(const FrameMetrics& aContentMetrics, const FrameMetrics& aC
// but with aContentMetrics used in place of mLastContentPaintMetrics, because they
// should be equivalent, modulo race conditions while transactions are inflight.
ParentLayerToScreenScale scale = aCompositorMetrics.GetZoom()
/ aContentMetrics.mDevPixelsPerCSSPixel
/ aCompositorMetrics.GetParentResolution();
ParentLayerToScreenScale scale = aCompositorMetrics.mPresShellResolution
* aCompositorMetrics.GetAsyncZoom();
ScreenPoint translation = (aCompositorMetrics.GetScrollOffset() - aContentMetrics.GetScrollOffset())
* aCompositorMetrics.GetZoom();
return ViewTransform(scale, -translation);
@ -1311,7 +1310,7 @@ ClientTiledLayerBuffer::ValidateTile(TileClient aTile,
#ifdef GFX_TILEDLAYER_DEBUG_OVERLAY
DrawDebugOverlay(drawTarget, aTileOrigin.x * mResolution,
aTileOrigin.y * mResolution, GetTileLength(), GetTileLength());
aTileOrigin.y * mPresShellResolution, GetTileLength(), GetTileLength());
#endif
ctxt = nullptr;
@ -1367,8 +1366,8 @@ GetCompositorSideCompositionBounds(const LayerMetricsWrapper& aScrollAncestor,
const ViewTransform& aAPZTransform)
{
Matrix4x4 nonTransientAPZUntransform = Matrix4x4::Scaling(
aScrollAncestor.Metrics().mResolution.scale,
aScrollAncestor.Metrics().mResolution.scale,
aScrollAncestor.Metrics().mPresShellResolution.scale,
aScrollAncestor.Metrics().mPresShellResolution.scale,
1.f);
nonTransientAPZUntransform.Invert();

View File

@ -718,7 +718,7 @@ ApplyAsyncTransformToScrollbarForContent(Layer* aScrollbar,
// aScrollbarIsDescendant hunk below we unapply the entire async
// transform, which includes the nontransientasync transform and would
// normally account for the resolution.
scale *= metrics.mResolution.scale;
scale *= metrics.mPresShellResolution.scale;
}
scrollbarTransform.PostScale(1.f, 1.f / transientTransform._22, 1.f);
scrollbarTransform.PostTranslate(0, -transientTransform._42 * scale, 0);
@ -726,7 +726,7 @@ ApplyAsyncTransformToScrollbarForContent(Layer* aScrollbar,
if (aScrollbar->GetScrollbarDirection() == Layer::HORIZONTAL) {
float scale = metrics.CalculateCompositedSizeInCssPixels().width / metrics.mScrollableRect.width;
if (aScrollbarIsDescendant) {
scale *= metrics.mResolution.scale;
scale *= metrics.mPresShellResolution.scale;
}
scrollbarTransform.PostScale(1.f / transientTransform._11, 1.f, 1.f);
scrollbarTransform.PostTranslate(-transientTransform._41 * scale, 0, 0);
@ -888,9 +888,10 @@ AsyncCompositionManager::TransformScrollableLayer(Layer* aLayer)
if (metrics.IsScrollable()) {
geckoScroll = metrics.GetScrollOffset() * userZoom;
}
ParentLayerToScreenScale scale = userZoom
/ metrics.mDevPixelsPerCSSPixel
/ metrics.GetParentResolution();
LayerToScreenScale asyncZoom = userZoom / metrics.LayersPixelsPerCSSPixel();
ParentLayerToScreenScale scale = metrics.mPresShellResolution
* asyncZoom;
ScreenPoint translation = userScroll - geckoScroll;
Matrix4x4 treeTransform = ViewTransform(scale, -translation);
@ -900,7 +901,7 @@ AsyncCompositionManager::TransformScrollableLayer(Layer* aLayer)
// Apply resolution scaling to the old transform - the layer tree as it is
// doesn't have the necessary transform to display correctly.
oldTransform.PreScale(metrics.mResolution.scale, metrics.mResolution.scale, 1);
oldTransform.PreScale(metrics.mPresShellResolution.scale, metrics.mPresShellResolution.scale, 1);
// Make sure that overscroll and under-zoom are represented in the old
// transform so that fixed position content moves and scales accordingly.

View File

@ -907,7 +907,7 @@ LayerManagerComposite::ComputeRenderIntegrity()
Layer* rootScrollable = rootScrollableLayers[0];
const FrameMetrics& metrics = LayerMetricsWrapper::TopmostScrollableMetrics(rootScrollable);
Matrix4x4 transform = rootScrollable->GetEffectiveTransform();
transform.PostScale(metrics.mResolution.scale, metrics.mResolution.scale, 1);
transform.PostScale(metrics.mPresShellResolution.scale, metrics.mPresShellResolution.scale, 1);
// Clip the screen rect to the document bounds
Rect documentBounds =

View File

@ -778,7 +778,7 @@ TEST_F(APZCBasicTester, ComplexTransform) {
metrics.SetScrollOffset(CSSPoint(10, 10));
metrics.mScrollableRect = CSSRect(0, 0, 50, 50);
metrics.mCumulativeResolution = LayoutDeviceToLayerScale(2);
metrics.mResolution = ParentLayerToLayerScale(2);
metrics.mPresShellResolution = ParentLayerToLayerScale(2);
metrics.SetZoom(CSSToScreenScale(6));
metrics.mDevPixelsPerCSSPixel = CSSToLayoutDeviceScale(3);
metrics.SetScrollId(FrameMetrics::START_SCROLL_ID);

View File

@ -724,10 +724,10 @@ nsDisplayScrollLayer::ComputeFrameMetrics(nsIFrame* aForFrame,
// Only the root scrollable frame for a given presShell should pick up
// the presShell's resolution. All the other frames are 1.0.
if (aScrollFrame == presShell->GetRootScrollFrame()) {
metrics.mResolution = ParentLayerToLayerScale(presShell->GetXResolution(),
metrics.mPresShellResolution = ParentLayerToLayerScale(presShell->GetXResolution(),
presShell->GetYResolution());
} else {
metrics.mResolution = ParentLayerToLayerScale(1.0f);
metrics.mPresShellResolution = ParentLayerToLayerScale(1.0f);
}
// The cumulative resolution is the resolution at which the scroll frame's
// content is actually rendered. It includes the pres shell resolutions of

View File

@ -2802,7 +2802,7 @@ CalculateFrameMetricsForDisplayPort(nsIFrame* aScrollFrame,
* nsLayoutUtils::GetTransformToAncestorScale(aScrollFrame).width);
metrics.mDevPixelsPerCSSPixel = deviceScale;
metrics.mResolution = resolution;
metrics.mPresShellResolution = resolution;
metrics.mCumulativeResolution = cumulativeResolution;
metrics.SetZoom(deviceScale * cumulativeResolution * LayerToScreenScale(1));