Bug 880676 - Convert some things in APZC::SampleContentTransformForFrame. r=kentuckyfriedtakahe
authorKartikaya Gupta <kgupta@mozilla.com>
Fri, 14 Jun 2013 16:11:29 -0400
changeset 135120 f9e66f6ca3771641be71e656b5f007085def183d
parent 135119 1cffa2a5298c009448cfe8ecbad2eb76a465e713
child 135121 89ddf463d04f985fe67376786cea47b25c841973
push idunknown
push userunknown
push dateunknown
reviewerskentuckyfriedtakahe
bugs880676
milestone24.0a1
Bug 880676 - Convert some things in APZC::SampleContentTransformForFrame. r=kentuckyfriedtakahe
gfx/layers/FrameMetrics.h
gfx/layers/ipc/AsyncPanZoomController.cpp
layout/base/Units.h
layout/ipc/RenderFrameParent.cpp
--- a/gfx/layers/FrameMetrics.h
+++ b/gfx/layers/FrameMetrics.h
@@ -84,19 +84,19 @@ public:
     return mScrollId != NULL_SCROLL_ID;
   }
 
   gfxSize LayersPixelsPerCSSPixel() const
   {
     return mResolution * mDevPixelsPerCSSPixel;
   }
 
-  gfxPoint GetScrollOffsetInLayerPixels() const
+  gfx::Point GetScrollOffsetInLayerPixels() const
   {
-    return gfxPoint(
+    return gfx::Point(
       static_cast<gfx::Float>(
         mScrollOffset.x * LayersPixelsPerCSSPixel().width),
       static_cast<gfx::Float>(
         mScrollOffset.y * LayersPixelsPerCSSPixel().height));
   }
 
   // ---------------------------------------------------------------------------
   // The following metrics are all in widget space/device pixels.
--- a/gfx/layers/ipc/AsyncPanZoomController.cpp
+++ b/gfx/layers/ipc/AsyncPanZoomController.cpp
@@ -1096,18 +1096,18 @@ bool AsyncPanZoomController::SampleConte
   bool requestAnimationFrame = false;
 
   const gfx3DMatrix& currentTransform = aLayer->GetTransform();
 
   // Scales on the root layer, on what's currently painted.
   gfxSize rootScale(currentTransform.GetXScale(),
                     currentTransform.GetYScale());
 
-  gfxPoint metricsScrollOffset(0, 0);
-  gfxPoint scrollOffset;
+  LayerPoint metricsScrollOffset;
+  CSSPoint scrollOffset;
   gfxSize localScale;
   const FrameMetrics& frame = aLayer->GetFrameMetrics();
   {
     MonitorAutoLock mon(mMonitor);
 
     switch (mState) {
     case FLING:
       // If a fling is currently happening, apply it now. We can pull
@@ -1154,20 +1154,21 @@ bool AsyncPanZoomController::SampleConte
 
     // Current local transform; this is not what's painted but rather
     // 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.
     localScale = CalculateResolution(mFrameMetrics);
 
     if (frame.IsScrollable()) {
-      metricsScrollOffset = frame.GetScrollOffsetInLayerPixels();
+      metricsScrollOffset = LayerPoint::FromUnknownPoint(
+        frame.GetScrollOffsetInLayerPixels());
     }
 
-    scrollOffset = gfxPoint(mFrameMetrics.mScrollOffset.x, mFrameMetrics.mScrollOffset.y);
+    scrollOffset = mFrameMetrics.mScrollOffset;
     mCurrentAsyncScrollOffset = mFrameMetrics.mScrollOffset;
   }
 
   // Cancel the mAsyncScrollTimeoutTask because we will fire a
   // mozbrowserasyncscroll event or renew the mAsyncScrollTimeoutTask again.
   if (mAsyncScrollTimeoutTask) {
     mAsyncScrollTimeoutTask->Cancel();
     mAsyncScrollTimeoutTask = nullptr;
@@ -1188,21 +1189,25 @@ bool AsyncPanZoomController::SampleConte
   else {
     mAsyncScrollTimeoutTask =
       NewRunnableMethod(this, &AsyncPanZoomController::FireAsyncScrollOnTimeout);
     MessageLoop::current()->PostDelayedTask(FROM_HERE,
                                             mAsyncScrollTimeoutTask,
                                             mAsyncScrollTimeout);
   }
 
-  gfxPoint scrollCompensation(
-    (scrollOffset / rootScale - metricsScrollOffset) * localScale);
+  LayerPoint translation = LayerPoint::FromCSSPoint(scrollOffset,
+                                                    1 / rootScale.width,
+                                                    1 / rootScale.height)
+                           - metricsScrollOffset;
+  gfxPoint scrollCompensation(translation.x * localScale.width,
+                              translation.y * localScale.height);
   *aNewTransform = ViewTransform(-scrollCompensation, localScale);
-  aScrollOffset.x = scrollOffset.x * localScale.width;
-  aScrollOffset.y = scrollOffset.y * localScale.height;
+  aScrollOffset = ScreenPoint::FromCSSPoint(
+    scrollOffset, localScale.width, localScale.height);
 
   mLastSampleTime = aSampleTime;
 
   return requestAnimationFrame;
 }
 
 void AsyncPanZoomController::NotifyLayersUpdated(const FrameMetrics& aViewportFrame, bool aIsFirstPaint) {
   MonitorAutoLock monitor(mMonitor);
--- a/layout/base/Units.h
+++ b/layout/base/Units.h
@@ -75,16 +75,21 @@ typedef gfx::IntRectTyped<CSSPixel> CSSI
  * The pixels that layout rasterizes and delivers to the graphics code.
  * These are generally referred to as "device pixels" in layout code. Layer
  * pixels are affected by:
  * 1) the "display resolution" (see nsIPresShell::SetResolution)
  * 2) the "full zoom" (see nsPresContext::SetFullZoom)
  * 3) the "widget scale" (nsIWidget::GetDefaultScale)
  */
 struct LayerPixel {
+  static gfx::PointTyped<LayerPixel> FromCSSPoint(const CSSPoint& aPoint, float aResolutionX, float aResolutionY) {
+    return gfx::PointTyped<LayerPixel>(aPoint.x * aResolutionX,
+                                       aPoint.y * aResolutionY);
+  }
+
   static gfx::IntPointTyped<LayerPixel> FromCSSPointRounded(const CSSPoint& aPoint, float aResolutionX, float aResolutionY) {
     return gfx::IntPointTyped<LayerPixel>(NS_lround(aPoint.x * aResolutionX),
                                           NS_lround(aPoint.y * aResolutionY));
   }
 
   static gfx::IntRectTyped<LayerPixel> RoundToInt(const gfx::RectTyped<LayerPixel>& aRect) {
     return gfx::IntRectTyped<LayerPixel>(NS_lround(aRect.x),
                                          NS_lround(aRect.y),
@@ -115,16 +120,21 @@ typedef gfx::IntRectTyped<LayerPixel> La
  * On non-OMTC platforms this should be equivalent to LayerPixel units.
  * On OMTC platforms these may diverge from LayerPixel units temporarily,
  * while an asynchronous zoom is happening, but should eventually converge
  * back to LayerPixel units. Some variables (such as those representing
  * chrome UI element sizes) that are not subject to content zoom should
  * generally be represented in ScreenPixel units.
  */
 struct ScreenPixel {
+  static gfx::PointTyped<ScreenPixel> FromCSSPoint(const CSSPoint& aPoint, float aResolutionX, float aResolutionY) {
+    return gfx::PointTyped<ScreenPixel>(aPoint.x * aResolutionX,
+                                        aPoint.y * aResolutionY);
+  }
+
   static CSSPoint ToCSSPoint(const gfx::PointTyped<ScreenPixel>& aPoint, float aResolutionX, float aResolutionY) {
     return CSSPoint(aPoint.x * aResolutionX,
                     aPoint.y * aResolutionY);
   }
 
   static CSSIntRect ToCSSIntRectRoundIn(const gfx::IntRectTyped<ScreenPixel>& aRect, float aResolutionX, float aResolutionY) {
     gfx::IntRectTyped<CSSPixel> ret(aRect.x, aRect.y, aRect.width, aRect.height);
     ret.ScaleInverseRoundIn(aResolutionX, aResolutionY);
--- a/layout/ipc/RenderFrameParent.cpp
+++ b/layout/ipc/RenderFrameParent.cpp
@@ -163,17 +163,17 @@ ComputeShadowTreeTransform(nsIFrame* aCo
   //
   // So we set a compensating translation that moves the content document
   // pixels to where the user wants them to be.
   //
   nscoord auPerDevPixel = aContainerFrame->PresContext()->AppUnitsPerDevPixel();
   nsIntPoint scrollOffset =
     aConfig.mScrollOffset.ToNearestPixels(auPerDevPixel);
   // metricsScrollOffset is in layer coordinates.
-  gfxPoint metricsScrollOffset = aMetrics->GetScrollOffsetInLayerPixels();
+  gfx::Point metricsScrollOffset = aMetrics->GetScrollOffsetInLayerPixels();
   nsIntPoint roundedMetricsScrollOffset =
     nsIntPoint(NS_lround(metricsScrollOffset.x), NS_lround(metricsScrollOffset.y));
 
   if (aRootFrameLoader->AsyncScrollEnabled() && !aMetrics->mDisplayPort.IsEmpty()) {
     // Only use asynchronous scrolling if it is enabled and there is a
     // displayport defined. It is useful to have a scroll layer that is
     // synchronously scrolled for identifying a scroll area before it is
     // being actively scrolled.