Bug 1036967 - Use ScaleFactors2D instead of ScaleFactor where appropriate in APZ and surrounding code. r=kats

--HG--
extra : rebase_source : bbdd433260c2e5244602275aa8516723f87d5740
extra : source : a2dbf7ec87c50f35a089470e39d6b4b448992e3d
This commit is contained in:
Botond Ballo 2015-03-06 13:54:10 -05:00
parent 4f5da1dd25
commit cda50e28d3
18 changed files with 158 additions and 111 deletions

View File

@ -199,14 +199,14 @@ TabChildBase::InitializeRootMetrics()
mLastRootMetrics.mCompositionBounds = ParentLayerRect(
ParentLayerPoint(),
ParentLayerSize(ViewAs<ParentLayerPixel>(mInnerSize, PixelCastJustification::ScreenIsParentLayerForRoot)));
mLastRootMetrics.SetZoom(mLastRootMetrics.CalculateIntrinsicScale());
mLastRootMetrics.SetZoom(CSSToParentLayerScale2D(mLastRootMetrics.CalculateIntrinsicScale()));
mLastRootMetrics.SetDevPixelsPerCSSPixel(WebWidget()->GetDefaultScale());
// We use ParentLayerToLayerScale(1) below in order to turn the
// async zoom amount into the gecko zoom amount.
mLastRootMetrics.SetCumulativeResolution(mLastRootMetrics.GetZoom() / mLastRootMetrics.GetDevPixelsPerCSSPixel() * ParentLayerToLayerScale(1));
// This is the root layer, so the cumulative resolution is the same
// as the resolution.
mLastRootMetrics.SetPresShellResolution(mLastRootMetrics.GetCumulativeResolution().scale);
mLastRootMetrics.SetPresShellResolution(mLastRootMetrics.GetCumulativeResolution().ToScaleFactor().scale);
mLastRootMetrics.SetScrollOffset(CSSPoint(0, 0));
TABC_LOG("After InitializeRootMetrics, mLastRootMetrics is %s\n",
@ -372,7 +372,7 @@ TabChildBase::HandlePossibleViewportChange(const ScreenIntSize& aOldScreenSize)
CSSToScreenScale defaultZoom = viewportInfo.GetDefaultZoom();
MOZ_ASSERT(viewportInfo.GetMinZoom() <= defaultZoom &&
defaultZoom <= viewportInfo.GetMaxZoom());
metrics.SetZoom(ConvertScaleForRoot(defaultZoom));
metrics.SetZoom(CSSToParentLayerScale2D(ConvertScaleForRoot(defaultZoom)));
metrics.SetScrollId(viewId);
}
@ -389,7 +389,7 @@ TabChildBase::HandlePossibleViewportChange(const ScreenIntSize& aOldScreenSize)
* ParentLayerToLayerScale(1));
// This is the root layer, so the cumulative resolution is the same
// as the resolution.
metrics.SetPresShellResolution(metrics.GetCumulativeResolution().scale);
metrics.SetPresShellResolution(metrics.GetCumulativeResolution().ToScaleFactor().scale);
utils->SetResolutionAndScaleTo(metrics.GetPresShellResolution(), metrics.GetPresShellResolution());
CSSSize scrollPort = metrics.CalculateCompositedSizeInCssPixels();

View File

@ -231,7 +231,7 @@ nsPluginInstanceOwner::GetImageContainer()
// NotifySize() causes Flash to do a bunch of stuff like ask for surfaces to render
// into, set y-flip flags, etc, so we do this at the beginning.
gfxSize resolution = mPluginFrame->PresContext()->PresShell()->GetCumulativeResolution();
ScreenSize screenSize = (r * LayoutDeviceToScreenScale(resolution.width, resolution.height)).Size();
ScreenSize screenSize = (r * LayoutDeviceToScreenScale2D(resolution.width, resolution.height)).Size();
mInstance->NotifySize(nsIntSize(screenSize.width, screenSize.height));
container = LayerManager::CreateImageContainer();

View File

@ -44,14 +44,14 @@ public:
, mDisplayPort(0, 0, 0, 0)
, mCriticalDisplayPort(0, 0, 0, 0)
, mScrollableRect(0, 0, 0, 0)
, mCumulativeResolution(1)
, mCumulativeResolution()
, mDevPixelsPerCSSPixel(1)
, mIsRoot(false)
, mHasScrollgrab(false)
, mScrollId(NULL_SCROLL_ID)
, mScrollParentId(NULL_SCROLL_ID)
, mScrollOffset(0, 0)
, mZoom(1)
, mZoom()
, mUpdateScrollOffset(false)
, mScrollGeneration(0)
, mDoSmoothScroll(false)
@ -61,7 +61,7 @@ public:
, mUseDisplayPortMargins(false)
, mPresShellId(-1)
, mViewport(0, 0, 0, 0)
, mExtraResolution(1)
, mExtraResolution()
, mBackgroundColor(0, 0, 0, 0)
, mLineScrollAmount(0, 0)
, mAllowVerticalScrollWithWheel(false)
@ -121,7 +121,7 @@ public:
return mScrollId != NULL_SCROLL_ID;
}
CSSToScreenScale DisplayportPixelsPerCSSPixel() const
CSSToScreenScale2D DisplayportPixelsPerCSSPixel() const
{
// Note: use 'mZoom * ParentLayerToLayerScale(1.0f)' as the CSS-to-Layer scale
// instead of LayersPixelsPerCSSPixel(), because displayport calculations
@ -133,15 +133,17 @@ public:
return mZoom * ParentLayerToLayerScale(1.0f) / mExtraResolution;
}
CSSToLayerScale LayersPixelsPerCSSPixel() const
CSSToLayerScale2D LayersPixelsPerCSSPixel() const
{
return mCumulativeResolution * mDevPixelsPerCSSPixel;
return mDevPixelsPerCSSPixel * mCumulativeResolution;
}
// Get the amount by which this frame has been zoomed since the last repaint.
LayerToParentLayerScale GetAsyncZoom() const
{
return mZoom / LayersPixelsPerCSSPixel();
// The async portion of the zoom should be the same along the x and y
// axes.
return (mZoom / LayersPixelsPerCSSPixel()).ToScaleFactor();
}
// Ensure the scrollableRect is at least as big as the compositionBounds
@ -201,9 +203,15 @@ public:
mScrollOffset += aPoint;
}
void ZoomBy(float aFactor)
void ZoomBy(float aScale)
{
mZoom.scale *= aFactor;
ZoomBy(gfxSize(aScale, aScale));
}
void ZoomBy(const gfxSize& aScale)
{
mZoom.xScale *= aScale.width;
mZoom.yScale *= aScale.height;
}
void CopyScrollInfoFrom(const FrameMetrics& aOther)
@ -251,7 +259,7 @@ public:
ParentLayerRect mCompositionBounds;
public:
void SetPresShellResolution(const float aPresShellResolution)
void SetPresShellResolution(float aPresShellResolution)
{
mPresShellResolution = aPresShellResolution;
}
@ -281,12 +289,12 @@ public:
return mCriticalDisplayPort;
}
void SetCumulativeResolution(const LayoutDeviceToLayerScale& aCumulativeResolution)
void SetCumulativeResolution(const LayoutDeviceToLayerScale2D& aCumulativeResolution)
{
mCumulativeResolution = aCumulativeResolution;
}
LayoutDeviceToLayerScale GetCumulativeResolution() const
LayoutDeviceToLayerScale2D GetCumulativeResolution() const
{
return mCumulativeResolution;
}
@ -341,12 +349,12 @@ public:
return mSmoothScrollOffset;
}
void SetZoom(const CSSToParentLayerScale& aZoom)
void SetZoom(const CSSToParentLayerScale2D& aZoom)
{
mZoom = aZoom;
}
CSSToParentLayerScale GetZoom() const
CSSToParentLayerScale2D GetZoom() const
{
return mZoom;
}
@ -448,12 +456,12 @@ public:
return mViewport;
}
void SetExtraResolution(const ScreenToLayerScale& aExtraResolution)
void SetExtraResolution(const ScreenToLayerScale2D& aExtraResolution)
{
mExtraResolution = aExtraResolution;
}
ScreenToLayerScale GetExtraResolution() const
ScreenToLayerScale2D GetExtraResolution() const
{
return mExtraResolution;
}
@ -557,7 +565,10 @@ private:
// 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;
// Note that this is allowed to have different x- and y-scales, but only
// for subframes (mIsRoot = false). (The same applies to other scales that
// "inherit" the 2D-ness of this one, such as mZoom.)
LayoutDeviceToLayerScale2D mCumulativeResolution;
// New fields from now on should be made private and old fields should
// be refactored to be private.
@ -601,7 +612,7 @@ private:
// but will be drawn to the screen at mZoom. In the steady state, the
// two will be the same, but during an async zoom action the two may
// diverge. This information is initialized in Gecko but updated in the APZC.
CSSToParentLayerScale mZoom;
CSSToParentLayerScale2D mZoom;
// Whether mScrollOffset was updated by something other than the APZ code, and
// if the APZC receiving this metrics should update its local copy.
@ -640,7 +651,7 @@ private:
// The extra resolution at which content in this scroll frame is drawn beyond
// that necessary to draw one Layer pixel per Screen pixel.
ScreenToLayerScale mExtraResolution;
ScreenToLayerScale2D mExtraResolution;
// The background color to use when overscrolling.
gfxRGBA mBackgroundColor;

View File

@ -183,17 +183,17 @@ AppendToString(std::stringstream& aStream, const FrameMetrics& m,
if (m.GetScrollParentId() != FrameMetrics::NULL_SCROLL_ID) {
AppendToString(aStream, m.GetScrollParentId(), "] [scrollParent=");
}
aStream << nsPrintfCString("] [z=%.3f] }", m.GetZoom().scale).get();
AppendToString(aStream, m.GetZoom(), "] [z=", "] }");
} else {
AppendToString(aStream, m.GetDisplayPortMargins(), " [dpm=");
aStream << nsPrintfCString("] um=%d", m.GetUseDisplayPortMargins()).get();
AppendToString(aStream, m.GetRootCompositionSize(), "] [rcs=");
AppendToString(aStream, m.GetViewport(), "] [v=");
aStream << nsPrintfCString("] [z=(ld=%.3f r=%.3f cr=%.3f z=%.3f er=%.3f)",
m.GetDevPixelsPerCSSPixel().scale, m.GetPresShellResolution(),
m.GetCumulativeResolution().scale, m.GetZoom().scale,
m.GetExtraResolution().scale).get();
aStream << nsPrintfCString("] [u=(%d %d %lu)",
aStream << nsPrintfCString("] [z=(ld=%.3f r=%.3f").get();
AppendToString(aStream, m.GetCumulativeResolution(), " cr=");
AppendToString(aStream, m.GetZoom(), " z=");
AppendToString(aStream, m.GetExtraResolution(), " er=");
aStream << nsPrintfCString(")] [u=(%d %d %lu)",
m.GetScrollOffsetUpdated(), m.GetDoSmoothScroll(),
m.GetScrollGeneration()).get();
AppendToString(aStream, m.GetScrollParentId(), "] [p=");

View File

@ -161,6 +161,20 @@ AppendToString(std::stringstream& aStream, const mozilla::gfx::IntSizeTyped<T>&
aStream << sfx;
}
template<class src, class dst>
void
AppendToString(std::stringstream& aStream, const mozilla::gfx::ScaleFactors2D<src, dst>& scale,
const char* pfx="", const char* sfx="")
{
std::streamsize oldPrecision = aStream.precision(3);
if (scale.AreScalesSame()) {
aStream << scale.xScale;
} else {
aStream << '(' << scale.xScale << ',' << scale.yScale << ')';
}
aStream.precision(oldPrecision);
}
void
AppendToString(std::stringstream& aStream, const mozilla::gfx::Matrix4x4& m,
const char* pfx="", const char* sfx="");

View File

@ -223,7 +223,7 @@ ComputeClipRegion(GeckoContentController* aController,
// 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 =
LayoutDeviceToParentLayerScale2D parentCumulativeResolution =
aLayer.Metrics().GetCumulativeResolution()
/ ParentLayerToLayerScale(aLayer.Metrics().GetPresShellResolution());
// Not sure what rounding option is the most correct here, but if we ever

View File

@ -588,8 +588,8 @@ private:
class ZoomAnimation: public AsyncPanZoomAnimation {
public:
ZoomAnimation(CSSPoint aStartOffset, CSSToParentLayerScale aStartZoom,
CSSPoint aEndOffset, CSSToParentLayerScale aEndZoom)
ZoomAnimation(CSSPoint aStartOffset, CSSToParentLayerScale2D aStartZoom,
CSSPoint aEndOffset, CSSToParentLayerScale2D aEndZoom)
: mTotalDuration(TimeDuration::FromMilliseconds(gfxPrefs::APZZoomAnimationDuration()))
, mStartOffset(aStartOffset)
, mStartZoom(aStartZoom)
@ -615,9 +615,9 @@ public:
// We scale the scrollOffset linearly with sampledPosition, so the zoom
// needs to scale inversely to match.
aFrameMetrics.SetZoom(CSSToParentLayerScale(1 /
(sampledPosition / mEndZoom.scale +
(1 - sampledPosition) / mStartZoom.scale)));
aFrameMetrics.SetZoom(CSSToParentLayerScale2D(
1 / (sampledPosition / mEndZoom.xScale + (1 - sampledPosition) / mStartZoom.xScale),
1 / (sampledPosition / mEndZoom.yScale + (1 - sampledPosition) / mStartZoom.yScale)));
aFrameMetrics.SetScrollOffset(CSSPoint::FromUnknownPoint(gfx::Point(
mEndOffset.x * sampledPosition + mStartOffset.x * (1 - sampledPosition),
@ -636,13 +636,13 @@ private:
// interpolate between the start and end frames. We only use the
// |mViewportScrollOffset| and |mResolution| fields on this.
CSSPoint mStartOffset;
CSSToParentLayerScale mStartZoom;
CSSToParentLayerScale2D mStartZoom;
// Target metrics for a zoom to animation. This is only valid when we are in
// the "ANIMATED_ZOOM" state. We only use the |mViewportScrollOffset| and
// |mResolution| fields on this.
CSSPoint mEndOffset;
CSSToParentLayerScale mEndZoom;
CSSToParentLayerScale2D mEndZoom;
};
class OverscrollAnimation: public AsyncPanZoomAnimation {
@ -721,7 +721,7 @@ public:
}
// If we overscroll, hand off to a fling animation that will complete the
// spring back.
CSSToParentLayerScale zoom = aFrameMetrics.GetZoom();
CSSToParentLayerScale2D zoom = aFrameMetrics.GetZoom();
ParentLayerPoint displacement = (position - aFrameMetrics.GetScrollOffset()) * zoom;
ParentLayerPoint overscroll;
@ -1283,6 +1283,14 @@ nsEventStatus AsyncPanZoomController::OnScaleBegin(const PinchGestureInput& aEve
nsEventStatus AsyncPanZoomController::OnScale(const PinchGestureInput& aEvent) {
APZC_LOG("%p got a scale in state %d\n", this, mState);
// Only the root APZC is zoomable, and the root APZC is not allowed to have
// different x and y scales. If it did, the calculations in this function
// would have to be adjusted (as e.g. it would no longer be valid to take
// the minimum or maximum of the ratios of the widths and heights of the
// page rect and the composition bounds).
MOZ_ASSERT(mFrameMetrics.IsRootScrollable());
MOZ_ASSERT(mFrameMetrics.GetZoom().AreScalesSame());
if (HasReadyTouchBlock() && !CurrentTouchBlock()->TouchActionAllowsPinchZoom()) {
return nsEventStatus_eIgnore;
}
@ -1302,7 +1310,7 @@ nsEventStatus AsyncPanZoomController::OnScale(const PinchGestureInput& aEvent) {
{
ReentrantMonitorAutoEnter lock(mMonitor);
CSSToParentLayerScale userZoom = mFrameMetrics.GetZoom();
CSSToParentLayerScale userZoom = mFrameMetrics.GetZoom().ToScaleFactor();
ParentLayerPoint focusPoint = aEvent.mLocalFocusPoint - mFrameMetrics.mCompositionBounds.TopLeft();
CSSPoint cssFocusPoint = focusPoint / mFrameMetrics.GetZoom();
@ -2635,10 +2643,10 @@ Matrix4x4 AsyncPanZoomController::GetTransformToLastDispatchedPaint() const {
* mLastContentPaintMetrics.GetDevPixelsPerCSSPixel()
* mLastContentPaintMetrics.GetCumulativeResolution();
float zoomChange = mLastContentPaintMetrics.GetZoom().scale / mLastDispatchedPaintMetrics.GetZoom().scale;
gfxSize zoomChange = mLastContentPaintMetrics.GetZoom() / mLastDispatchedPaintMetrics.GetZoom();
return Matrix4x4::Translation(scrollChange.x, scrollChange.y, 0).
PostScale(zoomChange, zoomChange, 1);
PostScale(zoomChange.width, zoomChange.height, 1);
}
bool AsyncPanZoomController::IsCurrentlyCheckerboarding() const {
@ -2734,8 +2742,8 @@ void AsyncPanZoomController::NotifyLayersUpdated(const FrameMetrics& aLayerMetri
// 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.GetCumulativeResolution().scale
/ mFrameMetrics.GetCumulativeResolution().scale;
gfxSize totalResolutionChange = aLayerMetrics.GetCumulativeResolution()
/ mFrameMetrics.GetCumulativeResolution();
float presShellResolutionChange = aLayerMetrics.GetPresShellResolution()
/ mFrameMetrics.GetPresShellResolution();
mFrameMetrics.ZoomBy(totalResolutionChange / presShellResolutionChange);
@ -2838,6 +2846,14 @@ void AsyncPanZoomController::ZoomToRect(CSSRect aRect) {
return;
}
// Only the root APZC is zoomable, and the root APZC is not allowed to have
// different x and y scales. If it did, the calculations in this function
// would have to be adjusted (as e.g. it would no longer be valid to take
// the minimum or maximum of the ratios of the widths and heights of the
// page rect and the composition bounds).
MOZ_ASSERT(mFrameMetrics.IsRootScrollable());
MOZ_ASSERT(mFrameMetrics.GetZoom().AreScalesSame());
SetState(ANIMATING_ZOOM);
{
@ -2846,7 +2862,7 @@ void AsyncPanZoomController::ZoomToRect(CSSRect aRect) {
ParentLayerRect compositionBounds = mFrameMetrics.mCompositionBounds;
CSSRect cssPageRect = mFrameMetrics.GetScrollableRect();
CSSPoint scrollOffset = mFrameMetrics.GetScrollOffset();
CSSToParentLayerScale currentZoom = mFrameMetrics.GetZoom();
CSSToParentLayerScale currentZoom = mFrameMetrics.GetZoom().ToScaleFactor();
CSSToParentLayerScale targetZoom;
// The minimum zoom to prevent over-zoom-out.
@ -2889,7 +2905,7 @@ void AsyncPanZoomController::ZoomToRect(CSSRect aRect) {
targetZoom.scale = clamped(targetZoom.scale, localMinZoom.scale, localMaxZoom.scale);
FrameMetrics endZoomToMetrics = mFrameMetrics;
endZoomToMetrics.SetZoom(targetZoom);
endZoomToMetrics.SetZoom(CSSToParentLayerScale2D(targetZoom));
// Adjust the zoomToRect to a sensible position to prevent overscrolling.
CSSSize sizeAfterZoom = endZoomToMetrics.CalculateCompositedSizeInCssPixels();

View File

@ -434,7 +434,7 @@ ParentLayerCoord Axis::DisplacementWillOverscrollAmount(ParentLayerCoord aDispla
CSSCoord Axis::ScaleWillOverscrollAmount(float aScale, CSSCoord aFocus) const {
// Internally, do computations in ParentLayer coordinates *before* the scale
// is applied.
CSSToParentLayerScale zoom = GetFrameMetrics().GetZoom();
CSSToParentLayerScale zoom = GetFrameMetrics().GetZoom().ToScaleFactor();
ParentLayerCoord focus = aFocus * zoom;
ParentLayerCoord originAfterScale = (GetOrigin() + focus) - (focus / aScale);

View File

@ -764,7 +764,7 @@ ClientLayerManager::ProgressiveUpdateCallback(bool aHasPendingNewThebesContent,
MOZ_ASSERT(aMetrics.IsScrollable());
// This is derived from the code in
// gfx/layers/ipc/CompositorParent.cpp::TransformShadowTree.
CSSToLayerScale paintScale = aMetrics.LayersPixelsPerCSSPixel();
CSSToLayerScale paintScale = aMetrics.LayersPixelsPerCSSPixel().ToScaleFactor();
const CSSRect& metricsDisplayPort =
(aDrawingCritical && !aMetrics.GetCriticalDisplayPort().IsEmpty()) ?
aMetrics.GetCriticalDisplayPort() : aMetrics.GetDisplayPort();
@ -776,7 +776,7 @@ ClientLayerManager::ProgressiveUpdateCallback(bool aHasPendingNewThebesContent,
aHasPendingNewThebesContent, displayPort, paintScale.scale, aDrawingCritical,
scrollOffset, zoom);
aMetrics.SetScrollOffset(scrollOffset / zoom);
aMetrics.SetZoom(zoom);
aMetrics.SetZoom(CSSToParentLayerScale2D(zoom));
return ret;
#else
return false;

View File

@ -199,9 +199,10 @@ SharedFrameMetricsHelper::UpdateFromCompositorFrameMetrics(
// Always abort updates if the resolution has changed. There's no use
// in drawing at the incorrect resolution.
if (!FuzzyEquals(compositorMetrics.GetZoom().scale, contentMetrics.GetZoom().scale)) {
TILING_LOG("TILING: Aborting because resolution changed from %f to %f\n",
contentMetrics.GetZoom().scale, compositorMetrics.GetZoom().scale);
if (!FuzzyEquals(compositorMetrics.GetZoom().xScale, contentMetrics.GetZoom().xScale) ||
!FuzzyEquals(compositorMetrics.GetZoom().yScale, contentMetrics.GetZoom().yScale)) {
TILING_LOG("TILING: Aborting because resolution changed from %s to %s\n",
ToString(contentMetrics.GetZoom()).c_str(), ToString(compositorMetrics.GetZoom()).c_str());
return true;
}
@ -855,7 +856,8 @@ ClientTiledLayerBuffer::GetSurfaceDescriptorTiles()
}
return SurfaceDescriptorTiles(mValidRegion, mPaintedRegion,
tiles, mRetainedWidth, mRetainedHeight,
mResolution, mFrameResolution.scale);
mResolution, mFrameResolution.xScale,
mFrameResolution.yScale);
}
void

View File

@ -318,7 +318,7 @@ struct BasicTiledLayerPaintData {
* The render resolution of the document that the content this layer
* represents is in.
*/
CSSToParentLayerScale mResolution;
CSSToParentLayerScale2D mResolution;
/*
* The composition bounds of the layer, in Layer coordinates. This is
@ -420,9 +420,9 @@ public:
void DiscardBuffers();
const CSSToParentLayerScale& GetFrameResolution() { return mFrameResolution; }
const CSSToParentLayerScale2D& GetFrameResolution() { return mFrameResolution; }
void SetFrameResolution(const CSSToParentLayerScale& aResolution) { mFrameResolution = aResolution; }
void SetFrameResolution(const CSSToParentLayerScale2D& aResolution) { mFrameResolution = aResolution; }
bool HasFormatChanged() const;
@ -461,7 +461,7 @@ private:
ClientLayerManager* mManager;
LayerManager::DrawPaintedLayerCallback mCallback;
void* mCallbackData;
CSSToParentLayerScale mFrameResolution;
CSSToParentLayerScale2D mFrameResolution;
gfxContentType mLastPaintContentType;
SurfaceMode mLastPaintSurfaceMode;

View File

@ -603,15 +603,10 @@ AsyncCompositionManager::ApplyAsyncContentTransformToTree(Layer *aLayer)
}
const FrameMetrics& metrics = aLayer->GetFrameMetrics(i);
CSSToLayerScale paintScale = metrics.LayersPixelsPerCSSPixel();
CSSRect displayPort(metrics.GetCriticalDisplayPort().IsEmpty() ?
metrics.GetDisplayPort() : metrics.GetCriticalDisplayPort());
ScreenPoint offset(0, 0);
// XXX this call to SyncFrameMetrics is not currently being used. It will be cleaned
// up as part of bug 776030 or one of its dependencies.
SyncFrameMetrics(scrollOffset, asyncTransformWithoutOverscroll.mScale.scale,
metrics.GetScrollableRect(), mLayersUpdated, displayPort,
paintScale, mIsFirstPaint, fixedLayerMargins, offset);
// TODO: When we enable APZ on Fennec, we'll need to call SyncFrameMetrics here.
// When doing so, it might be useful to look at how it was called here before
// bug 1036967 removed the (dead) call.
mIsFirstPaint = false;
mLayersUpdated = false;
@ -730,7 +725,7 @@ ApplyAsyncTransformToScrollbarForContent(Layer* aScrollbar,
// Note: |metrics.GetZoom()| doesn't yet include the async zoom, so
// |metrics.CalculateCompositedSizeInCssPixels()| would not give a correct
// result.
const CSSToParentLayerScale effectiveZoom(metrics.GetZoom().scale * asyncZoomY);
const CSSToParentLayerScale effectiveZoom(metrics.GetZoom().yScale * asyncZoomY);
const CSSCoord compositedHeight = (metrics.mCompositionBounds / effectiveZoom).height;
const CSSCoord scrollableHeight = metrics.GetScrollableRect().height;
@ -782,7 +777,7 @@ ApplyAsyncTransformToScrollbarForContent(Layer* aScrollbar,
const float xScale = 1.f / asyncZoomX;
const CSSToParentLayerScale effectiveZoom(metrics.GetZoom().scale * asyncZoomX);
const CSSToParentLayerScale effectiveZoom(metrics.GetZoom().xScale * asyncZoomX);
const CSSCoord compositedWidth = (metrics.mCompositionBounds / effectiveZoom).width;
const CSSCoord scrollableWidth = metrics.GetScrollableRect().width;
@ -922,7 +917,7 @@ AsyncCompositionManager::TransformScrollableLayer(Layer* aLayer)
// GetTransform here.
Matrix4x4 oldTransform = aLayer->GetTransform();
CSSToLayerScale geckoZoom = metrics.LayersPixelsPerCSSPixel();
CSSToLayerScale geckoZoom = metrics.LayersPixelsPerCSSPixel().ToScaleFactor();
LayerIntPoint scrollOffsetLayerPixels = RoundedToInt(metrics.GetScrollOffset() * geckoZoom);
@ -955,7 +950,11 @@ AsyncCompositionManager::TransformScrollableLayer(Layer* aLayer)
// 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.
CSSToParentLayerScale userZoom(metrics.GetDevPixelsPerCSSPixel() * metrics.GetCumulativeResolution() * LayerToParentLayerScale(1));
CSSToParentLayerScale userZoom(metrics.GetDevPixelsPerCSSPixel()
// This function only applies to the root scrollable frame,
// for which we can assume that x and y scales are equal.
* metrics.GetCumulativeResolution().ToScaleFactor()
* LayerToParentLayerScale(1));
ParentLayerPoint userScroll = metrics.GetScrollOffset() * userZoom;
SyncViewportInfo(displayPort, geckoZoom, mLayersUpdated,
userScroll, userZoom, fixedLayerMargins,
@ -976,7 +975,7 @@ AsyncCompositionManager::TransformScrollableLayer(Layer* aLayer)
geckoScroll = metrics.GetScrollOffset() * userZoom;
}
LayerToParentLayerScale asyncZoom = userZoom / metrics.LayersPixelsPerCSSPixel();
LayerToParentLayerScale asyncZoom = userZoom / metrics.LayersPixelsPerCSSPixel().ToScaleFactor();
ParentLayerPoint translation = userScroll - geckoScroll;
Matrix4x4 treeTransform = ViewTransform(asyncZoom, -translation);

View File

@ -28,7 +28,7 @@ namespace layers {
class Layer;
TiledLayerBufferComposite::TiledLayerBufferComposite()
: mFrameResolution(1.0)
: mFrameResolution()
, mHasDoubleBufferedTiles(false)
, mIsValid(false)
{}
@ -51,7 +51,8 @@ TiledLayerBufferComposite::TiledLayerBufferComposite(ISurfaceAllocator* aAllocat
mRetainedWidth = aDescriptor.retainedWidth();
mRetainedHeight = aDescriptor.retainedHeight();
mResolution = aDescriptor.resolution();
mFrameResolution = CSSToParentLayerScale(aDescriptor.frameResolution());
mFrameResolution = CSSToParentLayerScale2D(aDescriptor.frameXResolution(),
aDescriptor.frameYResolution());
if (mResolution == 0 || IsNaN(mResolution)) {
// There are divisions by mResolution so this protects the compositor process
// against malicious content processes and fuzzing.
@ -561,9 +562,10 @@ TiledContentHost::RenderLayerBuffer(TiledLayerBufferComposite& aLayerBuffer,
// precision layer buffer. Compensate for a changing frame resolution when
// rendering the low precision buffer.
if (aLayerBuffer.GetFrameResolution() != mTiledBuffer.GetFrameResolution()) {
const CSSToParentLayerScale& layerResolution = aLayerBuffer.GetFrameResolution();
const CSSToParentLayerScale& localResolution = mTiledBuffer.GetFrameResolution();
layerScale.width = layerScale.height = layerResolution.scale / localResolution.scale;
const CSSToParentLayerScale2D& layerResolution = aLayerBuffer.GetFrameResolution();
const CSSToParentLayerScale2D& localResolution = mTiledBuffer.GetFrameResolution();
layerScale.width = layerResolution.xScale / localResolution.xScale;
layerScale.height = layerResolution.yScale / localResolution.yScale;
aVisibleRegion.ScaleRoundOut(layerScale.width, layerScale.height);
}

View File

@ -136,7 +136,7 @@ public:
// Stores the absolute resolution of the containing frame, calculated
// by the sum of the resolutions of all parent layers' FrameMetrics.
const CSSToParentLayerScale& GetFrameResolution() { return mFrameResolution; }
const CSSToParentLayerScale2D& GetFrameResolution() { return mFrameResolution; }
void ReadUnlock();
@ -176,7 +176,7 @@ protected:
void UnlockTile(TileHost aTile) {}
void PostValidate(const nsIntRegion& aPaintRegion) {}
private:
CSSToParentLayerScale mFrameResolution;
CSSToParentLayerScale2D mFrameResolution;
bool mHasDoubleBufferedTiles;
bool mIsValid;
};

View File

@ -325,7 +325,8 @@ struct SurfaceDescriptorTiles {
int retainedWidth;
int retainedHeight;
float resolution;
float frameResolution;
float frameXResolution;
float frameYResolution;
};
struct OpUseTiledLayerBuffer {

View File

@ -650,7 +650,9 @@ protected:
fm.mCompositionBounds = ParentLayerRect(200, 200, 100, 200);
fm.SetScrollableRect(CSSRect(0, 0, 980, 1000));
fm.SetScrollOffset(CSSPoint(300, 300));
fm.SetZoom(CSSToParentLayerScale(2.0));
fm.SetZoom(CSSToParentLayerScale2D(2.0, 2.0));
// APZC only allows zooming on the root scrollable frame.
fm.SetIsRoot(true);
// the visible area of the document in CSS pixels is x=300 y=300 w=50 h=100
return fm;
}
@ -680,20 +682,20 @@ protected:
if (aShouldTriggerPinch) {
// the visible area of the document in CSS pixels is now x=305 y=310 w=40 h=80
EXPECT_EQ(2.5f, fm.GetZoom().scale);
EXPECT_EQ(2.5f, fm.GetZoom().ToScaleFactor().scale);
EXPECT_EQ(305, fm.GetScrollOffset().x);
EXPECT_EQ(310, fm.GetScrollOffset().y);
} else {
// The frame metrics should stay the same since touch-action:none makes
// apzc ignore pinch gestures.
EXPECT_EQ(2.0f, fm.GetZoom().scale);
EXPECT_EQ(2.0f, fm.GetZoom().ToScaleFactor().scale);
EXPECT_EQ(300, fm.GetScrollOffset().x);
EXPECT_EQ(300, fm.GetScrollOffset().y);
}
// part 2 of the test, move to the top-right corner of the page and pinch and
// make sure we stay in the correct spot
fm.SetZoom(CSSToParentLayerScale(2.0));
fm.SetZoom(CSSToParentLayerScale2D(2.0, 2.0));
fm.SetScrollOffset(CSSPoint(930, 5));
apzc->SetFrameMetrics(fm);
// the visible area of the document in CSS pixels is x=930 y=5 w=50 h=100
@ -708,11 +710,11 @@ protected:
if (aShouldTriggerPinch) {
// the visible area of the document in CSS pixels is now x=880 y=0 w=100 h=200
EXPECT_EQ(1.0f, fm.GetZoom().scale);
EXPECT_EQ(1.0f, fm.GetZoom().ToScaleFactor().scale);
EXPECT_EQ(880, fm.GetScrollOffset().x);
EXPECT_EQ(0, fm.GetScrollOffset().y);
} else {
EXPECT_EQ(2.0f, fm.GetZoom().scale);
EXPECT_EQ(2.0f, fm.GetZoom().ToScaleFactor().scale);
EXPECT_EQ(930, fm.GetScrollOffset().x);
EXPECT_EQ(5, fm.GetScrollOffset().y);
}
@ -781,7 +783,7 @@ TEST_F(APZCPinchGestureDetectorTester, Pinch_PreventDefault) {
// verify the metrics didn't change (i.e. the pinch was ignored)
FrameMetrics fm = apzc->GetFrameMetrics();
EXPECT_EQ(originalMetrics.GetZoom().scale, fm.GetZoom().scale);
EXPECT_EQ(originalMetrics.GetZoom(), fm.GetZoom());
EXPECT_EQ(originalMetrics.GetScrollOffset().x, fm.GetScrollOffset().x);
EXPECT_EQ(originalMetrics.GetScrollOffset().y, fm.GetScrollOffset().y);
@ -794,7 +796,8 @@ TEST_F(APZCBasicTester, Overzoom) {
fm.mCompositionBounds = ParentLayerRect(0, 0, 100, 100);
fm.SetScrollableRect(CSSRect(0, 0, 125, 150));
fm.SetScrollOffset(CSSPoint(10, 0));
fm.SetZoom(CSSToParentLayerScale(1.0));
fm.SetZoom(CSSToParentLayerScale2D(1.0, 1.0));
fm.SetIsRoot(true);
apzc->SetFrameMetrics(fm);
MakeApzcZoomable();
@ -805,7 +808,7 @@ TEST_F(APZCBasicTester, Overzoom) {
PinchWithPinchInputAndCheckStatus(apzc, 50, 50, 0.5, true);
fm = apzc->GetFrameMetrics();
EXPECT_EQ(0.8f, fm.GetZoom().scale);
EXPECT_EQ(0.8f, fm.GetZoom().ToScaleFactor().scale);
// bug 936721 - PGO builds introduce rounding error so
// use a fuzzy match instead
EXPECT_LT(abs(fm.GetScrollOffset().x), 1e-5);
@ -862,9 +865,9 @@ TEST_F(APZCBasicTester, ComplexTransform) {
metrics.SetDisplayPort(CSSRect(-1, -1, 6, 6));
metrics.SetScrollOffset(CSSPoint(10, 10));
metrics.SetScrollableRect(CSSRect(0, 0, 50, 50));
metrics.SetCumulativeResolution(LayoutDeviceToLayerScale(2));
metrics.SetCumulativeResolution(LayoutDeviceToLayerScale2D(2, 2));
metrics.SetPresShellResolution(2.0f);
metrics.SetZoom(CSSToParentLayerScale(6));
metrics.SetZoom(CSSToParentLayerScale2D(6, 6));
metrics.SetDevPixelsPerCSSPixel(CSSToLayoutDeviceScale(3));
metrics.SetScrollId(FrameMetrics::START_SCROLL_ID);

View File

@ -809,14 +809,12 @@ nsDisplayScrollLayer::ComputeFrameMetrics(nsIFrame* aForFrame,
// all the pres shells from here up to the root, as well as any css-driven
// resolution. We don't need to compute it as it's already stored in the
// container parameters.
// TODO(botond): As a workaround for bug 1071018, avoid asserting if
// mYScale is different from mXScale. This will be handled properly in
// bug 1036967.
metrics.SetCumulativeResolution(LayoutDeviceToLayerScale(aContainerParameters.mXScale));
metrics.SetCumulativeResolution(LayoutDeviceToLayerScale2D(aContainerParameters.mXScale,
aContainerParameters.mYScale));
LayoutDeviceToScreenScale resolutionToScreen(
presShell->GetCumulativeResolution().width
* nsLayoutUtils::GetTransformToAncestorScale(aScrollFrame ? aScrollFrame : aForFrame).width);
LayoutDeviceToScreenScale2D resolutionToScreen(
presShell->GetCumulativeResolution()
* nsLayoutUtils::GetTransformToAncestorScale(aScrollFrame ? aScrollFrame : aForFrame));
metrics.SetExtraResolution(metrics.GetCumulativeResolution() / resolutionToScreen);
metrics.SetDevPixelsPerCSSPixel(CSSToLayoutDeviceScale(
@ -888,10 +886,10 @@ nsDisplayScrollLayer::ComputeFrameMetrics(nsIFrame* aForFrame,
} else {
LayoutDeviceIntSize contentSize;
if (nsLayoutUtils::GetContentViewerSize(presContext, contentSize)) {
LayoutDeviceToParentLayerScale scale(1.0f);
LayoutDeviceToParentLayerScale2D scale;
if (presContext->GetParentPresContext()) {
gfxSize res = presContext->GetParentPresContext()->PresShell()->GetCumulativeResolution();
scale = LayoutDeviceToParentLayerScale(res.width, res.height);
scale = LayoutDeviceToParentLayerScale2D(res.width, res.height);
}
metrics.mCompositionBounds.SizeTo(contentSize * scale);
}

View File

@ -885,16 +885,17 @@ GetDisplayPortFromMarginsData(nsIContent* aContent,
nsPresContext* presContext = frame->PresContext();
int32_t auPerDevPixel = presContext->AppUnitsPerDevPixel();
LayoutDeviceToScreenScale res(presContext->PresShell()->GetCumulativeResolution().width
* nsLayoutUtils::GetTransformToAncestorScale(frame).width);
LayoutDeviceToScreenScale2D res(presContext->PresShell()->GetCumulativeResolution()
* nsLayoutUtils::GetTransformToAncestorScale(frame));
// First convert the base rect to screen pixels
LayoutDeviceToScreenScale parentRes = res;
LayoutDeviceToScreenScale2D parentRes = res;
if (isRoot) {
// the base rect for root scroll frames is specified in the parent document
// coordinate space, so it doesn't include the local resolution.
gfxSize localRes = presContext->PresShell()->GetResolution();
parentRes.scale /= localRes.width;
parentRes.xScale /= localRes.width;
parentRes.yScale /= localRes.height;
}
ScreenRect screenRect = LayoutDeviceRect::FromAppUnits(base, auPerDevPixel)
* parentRes;
@ -2821,9 +2822,9 @@ CalculateFrameMetricsForDisplayPort(nsIScrollableFrame* aScrollFrame) {
// divides out mExtraResolution anyways, so we get the correct result by
// setting the mCumulativeResolution to everything except the extra resolution
// and leaving mExtraResolution at 1.
LayoutDeviceToLayerScale cumulativeResolution(
presShell->GetCumulativeResolution().width
* nsLayoutUtils::GetTransformToAncestorScale(frame).width);
LayoutDeviceToLayerScale2D cumulativeResolution(
presShell->GetCumulativeResolution()
* nsLayoutUtils::GetTransformToAncestorScale(frame));
LayerToParentLayerScale layerToParentLayerScale(1.0f);
metrics.SetDevPixelsPerCSSPixel(deviceScale);
@ -2834,11 +2835,11 @@ CalculateFrameMetricsForDisplayPort(nsIScrollableFrame* aScrollFrame) {
// Only the size of the composition bounds is relevant to the
// displayport calculation, not its origin.
nsSize compositionSize = nsLayoutUtils::CalculateCompositionSizeForFrame(frame);
LayoutDeviceToParentLayerScale compBoundsScale(1.0f);
LayoutDeviceToParentLayerScale2D compBoundsScale;
if (frame == presShell->GetRootScrollFrame() && presContext->IsRootContentDocument()) {
if (presContext->GetParentPresContext()) {
gfxSize res = presContext->GetParentPresContext()->PresShell()->GetCumulativeResolution();
compBoundsScale = LayoutDeviceToParentLayerScale(res.width, res.height);
compBoundsScale = LayoutDeviceToParentLayerScale2D(res.width, res.height);
}
} else {
compBoundsScale = cumulativeResolution * layerToParentLayerScale;
@ -7543,11 +7544,11 @@ nsLayoutUtils::CalculateCompositionSizeForFrame(nsIFrame* aFrame)
#ifdef MOZ_WIDGET_ANDROID
nsRect frameRect = aFrame->GetRect();
gfxSize cumulativeResolution = presShell->GetCumulativeResolution();
LayoutDeviceToParentLayerScale layoutToParentLayerScale =
LayoutDeviceToParentLayerScale2D layoutToParentLayerScale =
// The ScreenToParentLayerScale should be mTransformScale which is
// not calculated yet, but we don't yet handle CSS transforms, so we
// assume it's 1 here.
LayoutDeviceToLayerScale(cumulativeResolution.width, cumulativeResolution.height) *
LayoutDeviceToLayerScale2D(cumulativeResolution.width, cumulativeResolution.height) *
LayerToScreenScale(1.0) * ScreenToParentLayerScale(1.0);
ParentLayerRect frameRectPixels =
LayoutDeviceRect::FromAppUnits(frameRect, auPerDevPixel)
@ -7629,10 +7630,10 @@ nsLayoutUtils::CalculateRootCompositionSize(nsIFrame* aFrame,
} else {
LayoutDeviceIntSize contentSize;
if (nsLayoutUtils::GetContentViewerSize(rootPresContext, contentSize)) {
LayoutDeviceToLayerScale scale(1.0f);
LayoutDeviceToLayerScale2D scale;
if (rootPresContext->GetParentPresContext()) {
gfxSize res = rootPresContext->GetParentPresContext()->PresShell()->GetCumulativeResolution();
scale = LayoutDeviceToLayerScale(res.width, res.height);
scale = LayoutDeviceToLayerScale2D(res.width, res.height);
}
rootCompositionSize = contentSize * scale * LayerToScreenScale(1.0f);
}