Skip to content

Commit

Permalink
Bug 1101620 - Changed mDevPixelsPerCSSPixel of FrameMetrics.h to priv…
Browse files Browse the repository at this point in the history
…ate and all corresponding files using this variables using getters and setters;r=kats
  • Loading branch information
psdh committed Dec 17, 2014
1 parent 8a3e72e commit 74d83cd
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 28 deletions.
14 changes: 7 additions & 7 deletions dom/ipc/TabChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,11 @@ TabChildBase::InitializeRootMetrics()
ParentLayerPoint(),
ParentLayerSize(ViewAs<ParentLayerPixel>(mInnerSize, PixelCastJustification::ScreenIsParentLayerForRoot)));
mLastRootMetrics.SetZoom(mLastRootMetrics.CalculateIntrinsicScale());
mLastRootMetrics.mDevPixelsPerCSSPixel = WebWidget()->GetDefaultScale();
mLastRootMetrics.SetDevPixelsPerCSSPixel(WebWidget()->GetDefaultScale());
// We use ParentLayerToLayerScale(1) below in order to turn the
// async zoom amount into the gecko zoom amount.
mLastRootMetrics.mCumulativeResolution =
mLastRootMetrics.GetZoom() / mLastRootMetrics.mDevPixelsPerCSSPixel * ParentLayerToLayerScale(1);
mLastRootMetrics.GetZoom() / mLastRootMetrics.GetDevPixelsPerCSSPixel() * ParentLayerToLayerScale(1);
// This is the root layer, so the cumulative resolution is the same
// as the resolution.
mLastRootMetrics.mPresShellResolution = mLastRootMetrics.mCumulativeResolution.scale;
Expand Down Expand Up @@ -384,7 +384,7 @@ TabChildBase::HandlePossibleViewportChange(const ScreenIntSize& aOldScreenSize)
ParentLayerPoint(),
ParentLayerSize(ViewAs<ParentLayerPixel>(mInnerSize, PixelCastJustification::ScreenIsParentLayerForRoot)));
metrics.SetRootCompositionSize(
ScreenSize(mInnerSize) * ScreenToLayoutDeviceScale(1.0f) / metrics.mDevPixelsPerCSSPixel);
ScreenSize(mInnerSize) * ScreenToLayoutDeviceScale(1.0f) / metrics.GetDevPixelsPerCSSPixel());

// This change to the zoom accounts for all types of changes I can conceive:
// 1. screen size changes, CSS viewport does not (pages with no meta viewport
Expand Down Expand Up @@ -425,13 +425,13 @@ TabChildBase::HandlePossibleViewportChange(const ScreenIntSize& aOldScreenSize)

if (nsIPresShell* shell = document->GetShell()) {
if (nsPresContext* context = shell->GetPresContext()) {
metrics.mDevPixelsPerCSSPixel = CSSToLayoutDeviceScale(
(float)nsPresContext::AppUnitsPerCSSPixel() / context->AppUnitsPerDevPixel());
metrics.SetDevPixelsPerCSSPixel(CSSToLayoutDeviceScale(
(float)nsPresContext::AppUnitsPerCSSPixel() / context->AppUnitsPerDevPixel()));
}
}

metrics.mCumulativeResolution = metrics.GetZoom()
/ metrics.mDevPixelsPerCSSPixel
/ metrics.GetDevPixelsPerCSSPixel()
* ParentLayerToLayerScale(1);
// This is the root layer, so the cumulative resolution is the same
// as the resolution.
Expand Down Expand Up @@ -468,7 +468,7 @@ TabChildBase::HandlePossibleViewportChange(const ScreenIntSize& aOldScreenSize)
if (viewportInfo.IsZoomAllowed() && scrollIdentifiersValid) {
// If the CSS viewport is narrower than the screen (i.e. width <= device-width)
// then we disable double-tap-to-zoom behaviour.
bool allowDoubleTapZoom = (viewport.width > screenW / metrics.mDevPixelsPerCSSPixel.scale);
bool allowDoubleTapZoom = (viewport.width > screenW / metrics.GetDevPixelsPerCSSPixel().scale);
if (allowDoubleTapZoom != viewportInfo.IsDoubleTapZoomAllowed()) {
viewportInfo.SetAllowDoubleTapZoom(allowDoubleTapZoom);

Expand Down
22 changes: 16 additions & 6 deletions gfx/layers/FrameMetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,17 @@ struct FrameMetrics {
// resolution. This information is provided by Gecko at layout/paint time.
LayoutDeviceToLayerScale mCumulativeResolution;

// The conversion factor between CSS pixels and device pixels for this frame.
// This can vary based on a variety of things, such as reflowing-zoom. The
// conversion factor for device pixels to layers pixels is just the
// resolution.
CSSToLayoutDeviceScale mDevPixelsPerCSSPixel;

public:
void SetDevPixelsPerCSSPixel(const CSSToLayoutDeviceScale& aDevPixelsPerCSSPixel)
{
mDevPixelsPerCSSPixel = aDevPixelsPerCSSPixel;
}

CSSToLayoutDeviceScale GetDevPixelsPerCSSPixel() const
{
return mDevPixelsPerCSSPixel;
}

void SetIsRoot(bool aIsRoot)
{
mIsRoot = aIsRoot;
Expand Down Expand Up @@ -527,6 +531,12 @@ struct FrameMetrics {
// New fields from now on should be made private and old fields should
// be refactored to be private.

// The conversion factor between CSS pixels and device pixels for this frame.
// This can vary based on a variety of things, such as reflowing-zoom. The
// conversion factor for device pixels to layers pixels is just the
// resolution.
CSSToLayoutDeviceScale mDevPixelsPerCSSPixel;

// Whether or not this frame may have touch or scroll wheel listeners.
bool mMayHaveTouchListeners;

Expand Down
2 changes: 1 addition & 1 deletion gfx/layers/LayersLogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,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 er=%.3f)",
m.mDevPixelsPerCSSPixel.scale, m.mPresShellResolution,
m.GetDevPixelsPerCSSPixel().scale, m.mPresShellResolution,
m.mCumulativeResolution.scale, m.GetZoom().scale,
m.GetExtraResolution().scale).get();
aStream << nsPrintfCString(" u=(%d %d %lu)",
Expand Down
4 changes: 2 additions & 2 deletions gfx/layers/apz/src/APZCTreeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ ComputeTouchSensitiveRegion(GeckoContentController* aController,
aMetrics.mCumulativeResolution
/ ParentLayerToLayerScale(aMetrics.mPresShellResolution);
visible = visible.Intersect(touchSensitiveRegion
* aMetrics.mDevPixelsPerCSSPixel
* aMetrics.GetDevPixelsPerCSSPixel()
* parentCumulativeResolution);
}

Expand Down Expand Up @@ -565,7 +565,7 @@ APZCTreeManager::UpdatePanZoomControllerTree(TreeBuildingState& aState,
/ ParentLayerToLayerScale(aLayer.Metrics().mPresShellResolution);
subtreeEventRegions.AndWith(ParentLayerIntRect::ToUntyped(
RoundedIn(touchSensitiveRegion
* aLayer.Metrics().mDevPixelsPerCSSPixel
* aLayer.Metrics().GetDevPixelsPerCSSPixel()
* parentCumulativeResolution)));
}
apzc->AddHitTestRegions(subtreeEventRegions);
Expand Down
12 changes: 6 additions & 6 deletions gfx/layers/apz/src/AsyncPanZoomController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,7 @@ AsyncPanZoomController::ConvertToGecko(const ParentLayerPoint& aPoint, CSSPoint*
LayoutDevicePoint layoutPoint = TransformTo<LayoutDevicePixel>(transformToGecko, aPoint);
{ // scoped lock to access mFrameMetrics
ReentrantMonitorAutoEnter lock(mMonitor);
*aOut = layoutPoint / mFrameMetrics.mDevPixelsPerCSSPixel;
*aOut = layoutPoint / mFrameMetrics.GetDevPixelsPerCSSPixel();
}
return true;
}
Expand Down Expand Up @@ -1487,7 +1487,7 @@ nsEventStatus AsyncPanZoomController::OnScrollWheel(const ScrollWheelInput& aEve
// zoom includes any device : css pixel zoom, we convert to CSS pixels
// before applying the zoom.
LayoutDevicePoint devicePixelDelta(-deltaX, -deltaY);
ParentLayerPoint delta = (devicePixelDelta / mFrameMetrics.mDevPixelsPerCSSPixel) *
ParentLayerPoint delta = (devicePixelDelta / mFrameMetrics.GetDevPixelsPerCSSPixel()) *
mFrameMetrics.GetZoom();

PanGestureInput move(PanGestureInput::PANGESTURE_PAN, aEvent.mTime, aEvent.mTimeStamp,
Expand All @@ -1506,7 +1506,7 @@ nsEventStatus AsyncPanZoomController::OnScrollWheel(const ScrollWheelInput& aEve
}

case ScrollWheelInput::SCROLLMODE_SMOOTH: {
CSSPoint delta = LayoutDevicePoint(deltaX, deltaY) / mFrameMetrics.mDevPixelsPerCSSPixel;
CSSPoint delta = LayoutDevicePoint(deltaX, deltaY) / mFrameMetrics.GetDevPixelsPerCSSPixel();

// If we're already in a smooth scroll animation, don't cancel it. This
// lets us preserve the existing scrolling velocity.
Expand Down Expand Up @@ -2655,7 +2655,7 @@ Matrix4x4 AsyncPanZoomController::GetTransformToLastDispatchedPaint() const {

LayerPoint scrollChange =
(mLastContentPaintMetrics.GetScrollOffset() - mLastDispatchedPaintMetrics.GetScrollOffset())
* mLastContentPaintMetrics.mDevPixelsPerCSSPixel
* mLastContentPaintMetrics.GetDevPixelsPerCSSPixel()
* mLastContentPaintMetrics.mCumulativeResolution
// This transform ("LD" in the terminology of the comment above
// GetScreenToApzcTransform() in APZCTreeManager.h) is applied in a
Expand Down Expand Up @@ -2757,7 +2757,7 @@ void AsyncPanZoomController::NotifyLayersUpdated(const FrameMetrics& aLayerMetri
// determined by Gecko and our copy in mFrameMetrics may be stale.

if (FuzzyEqualsAdditive(mFrameMetrics.mCompositionBounds.width, aLayerMetrics.mCompositionBounds.width) &&
mFrameMetrics.mDevPixelsPerCSSPixel == aLayerMetrics.mDevPixelsPerCSSPixel) {
mFrameMetrics.GetDevPixelsPerCSSPixel() == aLayerMetrics.GetDevPixelsPerCSSPixel()) {
// 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
Expand All @@ -2774,7 +2774,7 @@ void AsyncPanZoomController::NotifyLayersUpdated(const FrameMetrics& aLayerMetri
// Take the new zoom as either device scale or composition width or both
// got changed (e.g. due to orientation change).
mFrameMetrics.SetZoom(aLayerMetrics.GetZoom());
mFrameMetrics.mDevPixelsPerCSSPixel.scale = aLayerMetrics.mDevPixelsPerCSSPixel.scale;
mFrameMetrics.SetDevPixelsPerCSSPixel(aLayerMetrics.GetDevPixelsPerCSSPixel());
}
if (!mFrameMetrics.mScrollableRect.IsEqualEdges(aLayerMetrics.mScrollableRect)) {
mFrameMetrics.mScrollableRect = aLayerMetrics.mScrollableRect;
Expand Down
2 changes: 1 addition & 1 deletion gfx/layers/composite/AsyncCompositionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ 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.mDevPixelsPerCSSPixel * metrics.mCumulativeResolution * LayerToParentLayerScale(1));
CSSToParentLayerScale userZoom(metrics.GetDevPixelsPerCSSPixel() * metrics.mCumulativeResolution * LayerToParentLayerScale(1));
ParentLayerPoint userScroll = metrics.GetScrollOffset() * userZoom;
SyncViewportInfo(displayPort, geckoZoom, mLayersUpdated,
userScroll, userZoom, fixedLayerMargins,
Expand Down
2 changes: 1 addition & 1 deletion gfx/tests/gtest/TestAsyncPanZoomController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ TEST_F(APZCBasicTester, ComplexTransform) {
metrics.mCumulativeResolution = LayoutDeviceToLayerScale(2);
metrics.mPresShellResolution = 2.0f;
metrics.SetZoom(CSSToParentLayerScale(6));
metrics.mDevPixelsPerCSSPixel = CSSToLayoutDeviceScale(3);
metrics.SetDevPixelsPerCSSPixel(CSSToLayoutDeviceScale(3));
metrics.SetScrollId(FrameMetrics::START_SCROLL_ID);

FrameMetrics childMetrics = metrics;
Expand Down
6 changes: 3 additions & 3 deletions layout/base/nsDisplayList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,13 +758,13 @@ nsDisplayScrollLayer::ComputeFrameMetrics(nsIFrame* aForFrame,
* nsLayoutUtils::GetTransformToAncestorScale(aScrollFrame ? aScrollFrame : aForFrame).width);
metrics.SetExtraResolution(metrics.mCumulativeResolution / resolutionToScreen);

metrics.mDevPixelsPerCSSPixel = CSSToLayoutDeviceScale(
(float)nsPresContext::AppUnitsPerCSSPixel() / auPerDevPixel);
metrics.SetDevPixelsPerCSSPixel(CSSToLayoutDeviceScale(
(float)nsPresContext::AppUnitsPerCSSPixel() / auPerDevPixel));

// Initially, AsyncPanZoomController should render the content to the screen
// at the painted resolution.
const LayerToParentLayerScale layerToParentLayerScale(1.0f);
metrics.SetZoom(metrics.mCumulativeResolution * metrics.mDevPixelsPerCSSPixel
metrics.SetZoom(metrics.mCumulativeResolution * metrics.GetDevPixelsPerCSSPixel()
* layerToParentLayerScale);

if (presShell) {
Expand Down
2 changes: 1 addition & 1 deletion layout/base/nsLayoutUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2806,7 +2806,7 @@ CalculateFrameMetricsForDisplayPort(nsIScrollableFrame* aScrollFrame) {
* nsLayoutUtils::GetTransformToAncestorScale(frame).width);

LayerToParentLayerScale layerToParentLayerScale(1.0f);
metrics.mDevPixelsPerCSSPixel = deviceScale;
metrics.SetDevPixelsPerCSSPixel(deviceScale);
metrics.mPresShellResolution = resolution;
metrics.mCumulativeResolution = cumulativeResolution;
metrics.SetZoom(deviceScale * cumulativeResolution * layerToParentLayerScale);
Expand Down

0 comments on commit 74d83cd

Please sign in to comment.