Bug 1180295 - Remove the margins information from ImmutableViewportMetrics. r=rbarker
authorKartikaya Gupta <kgupta@mozilla.com>
Tue, 18 Aug 2015 14:27:20 -0400
changeset 258281 5078e84222d716b392eb06b10b67a976f7d8f169
parent 258280 bece031080d6664332029fb02923ca71d3adc3de
child 258282 2b213c98f8a8d85a03aa64aa502abd88048239ce
push id29249
push userryanvm@gmail.com
push dateWed, 19 Aug 2015 11:17:27 +0000
treeherdermozilla-central@706b23a03d1c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrbarker
bugs1180295
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1180295 - Remove the margins information from ImmutableViewportMetrics. r=rbarker
mobile/android/base/gfx/GeckoLayerClient.java
mobile/android/base/gfx/ImmutableViewportMetrics.java
mobile/android/base/gfx/JavaPanZoomController.java
mobile/android/base/gfx/Layer.java
mobile/android/base/gfx/LayerRenderer.java
mobile/android/base/gfx/PluginLayer.java
mobile/android/base/gfx/ScrollbarLayer.java
--- a/mobile/android/base/gfx/GeckoLayerClient.java
+++ b/mobile/android/base/gfx/GeckoLayerClient.java
@@ -819,17 +819,16 @@ class GeckoLayerClient implements LayerV
      */
     private void setViewportMetrics(ImmutableViewportMetrics metrics, boolean notifyGecko) {
         // This class owns the viewport size and the fixed layer margins; don't let other pieces
         // of code clobber either of them. The only place the viewport size should ever be
         // updated is in GeckoLayerClient.setViewportSize, and the only place the margins should
         // ever be updated is in GeckoLayerClient.setFixedLayerMargins; both of these assign to
         // mViewportMetrics directly.
         metrics = metrics.setViewportSize(mViewportMetrics.viewportRectWidth, mViewportMetrics.viewportRectHeight);
-        metrics = metrics.setMarginsFrom(mViewportMetrics);
         mViewportMetrics = metrics;
 
         viewportMetricsChanged(notifyGecko);
     }
 
     /*
      * You must hold the monitor while calling this.
      */
@@ -920,18 +919,16 @@ class GeckoLayerClient implements LayerV
     @Override
     public PointF convertViewPointToLayerPoint(PointF viewPoint) {
         if (!mGeckoIsReady) {
             return null;
         }
 
         ImmutableViewportMetrics viewportMetrics = mViewportMetrics;
         PointF origin = viewportMetrics.getOrigin();
-        PointF offset = viewportMetrics.getMarginOffset();
-        origin.offset(-offset.x, -offset.y);
         float zoom = viewportMetrics.zoomFactor;
         ImmutableViewportMetrics geckoViewport = mGeckoViewport;
         PointF geckoOrigin = geckoViewport.getOrigin();
         float geckoZoom = geckoViewport.zoomFactor;
 
         // viewPoint + origin - offset gives the coordinate in device pixels from the top-left corner of the page.
         // Divided by zoom, this gives us the coordinate in CSS pixels from the top-left corner of the page.
         // geckoOrigin / geckoZoom is where Gecko thinks it is (scrollTo position) in CSS pixels from
--- a/mobile/android/base/gfx/ImmutableViewportMetrics.java
+++ b/mobile/android/base/gfx/ImmutableViewportMetrics.java
@@ -29,31 +29,26 @@ public class ImmutableViewportMetrics {
     public final float cssPageRectTop;
     public final float cssPageRectRight;
     public final float cssPageRectBottom;
     public final float viewportRectLeft;
     public final float viewportRectTop;
     public final int viewportRectWidth;
     public final int viewportRectHeight;
 
-    public final float marginLeft;
-    public final float marginTop;
-    public final float marginRight;
-    public final float marginBottom;
     public final float zoomFactor;
     public final boolean isRTL;
 
     public ImmutableViewportMetrics(DisplayMetrics metrics) {
         viewportRectLeft   = pageRectLeft   = cssPageRectLeft   = 0;
         viewportRectTop    = pageRectTop    = cssPageRectTop    = 0;
         viewportRectWidth = metrics.widthPixels;
         viewportRectHeight = metrics.heightPixels;
         pageRectRight  = cssPageRectRight  = metrics.widthPixels;
         pageRectBottom = cssPageRectBottom = metrics.heightPixels;
-        marginLeft = marginTop = marginRight = marginBottom = 0;
         zoomFactor = 1.0f;
         isRTL = false;
     }
 
     /** This constructor is used by native code in AndroidJavaWrappers.cpp, be
      * careful when modifying the signature.
      */
     @WrapForJNI(allowMultithread = true)
@@ -62,43 +57,37 @@ public class ImmutableViewportMetrics {
         float aCssPageRectTop, float aCssPageRectRight, float aCssPageRectBottom,
         float aViewportRectLeft, float aViewportRectTop, int aViewportRectWidth,
         int aViewportRectHeight, float aZoomFactor)
     {
         this(aPageRectLeft, aPageRectTop,
              aPageRectRight, aPageRectBottom, aCssPageRectLeft,
              aCssPageRectTop, aCssPageRectRight, aCssPageRectBottom,
              aViewportRectLeft, aViewportRectTop, aViewportRectWidth,
-             aViewportRectHeight, 0.0f, 0.0f, 0.0f, 0.0f, aZoomFactor, false);
+             aViewportRectHeight, aZoomFactor, false);
     }
 
     private ImmutableViewportMetrics(float aPageRectLeft, float aPageRectTop,
         float aPageRectRight, float aPageRectBottom, float aCssPageRectLeft,
         float aCssPageRectTop, float aCssPageRectRight, float aCssPageRectBottom,
         float aViewportRectLeft, float aViewportRectTop, int aViewportRectWidth,
-        int aViewportRectHeight, float aMarginLeft,
-        float aMarginTop, float aMarginRight,
-        float aMarginBottom, float aZoomFactor, boolean aIsRTL)
+        int aViewportRectHeight, float aZoomFactor, boolean aIsRTL)
     {
         pageRectLeft = aPageRectLeft;
         pageRectTop = aPageRectTop;
         pageRectRight = aPageRectRight;
         pageRectBottom = aPageRectBottom;
         cssPageRectLeft = aCssPageRectLeft;
         cssPageRectTop = aCssPageRectTop;
         cssPageRectRight = aCssPageRectRight;
         cssPageRectBottom = aCssPageRectBottom;
         viewportRectLeft = aViewportRectLeft;
         viewportRectTop = aViewportRectTop;
         viewportRectWidth = aViewportRectWidth;
         viewportRectHeight = aViewportRectHeight;
-        marginLeft = aMarginLeft;
-        marginTop = aMarginTop;
-        marginRight = aMarginRight;
-        marginBottom = aMarginBottom;
         zoomFactor = aZoomFactor;
         isRTL = aIsRTL;
     }
 
     public float getWidth() {
         return viewportRectWidth;
     }
 
@@ -109,35 +98,20 @@ public class ImmutableViewportMetrics {
     public float viewportRectRight() {
         return viewportRectLeft + viewportRectWidth;
     }
 
     public float viewportRectBottom() {
         return viewportRectTop + viewportRectHeight;
     }
 
-    public float getWidthWithoutMargins() {
-        return viewportRectWidth - marginLeft - marginRight;
-    }
-
-    public float getHeightWithoutMargins() {
-        return viewportRectHeight - marginTop - marginBottom;
-    }
-
     public PointF getOrigin() {
         return new PointF(viewportRectLeft, viewportRectTop);
     }
 
-    public PointF getMarginOffset() {
-        if (isRTL) {
-            return new PointF(marginLeft - marginRight, marginTop);
-        }
-        return new PointF(marginLeft, marginTop);
-    }
-
     public FloatSize getSize() {
         return new FloatSize(viewportRectWidth, viewportRectHeight);
     }
 
     public RectF getViewport() {
         return new RectF(viewportRectLeft,
                          viewportRectTop,
                          viewportRectRight(),
@@ -151,28 +125,20 @@ public class ImmutableViewportMetrics {
     public RectF getPageRect() {
         return new RectF(pageRectLeft, pageRectTop, pageRectRight, pageRectBottom);
     }
 
     public float getPageWidth() {
         return pageRectRight - pageRectLeft;
     }
 
-    public float getPageWidthWithMargins() {
-        return (pageRectRight - pageRectLeft) + marginLeft + marginRight;
-    }
-
     public float getPageHeight() {
         return pageRectBottom - pageRectTop;
     }
 
-    public float getPageHeightWithMargins() {
-        return (pageRectBottom - pageRectTop) + marginTop + marginBottom;
-    }
-
     public RectF getCssPageRect() {
         return new RectF(cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom);
     }
 
     public RectF getOverscroll() {
         return new RectF(Math.max(0, pageRectLeft - viewportRectLeft),
                          Math.max(0, pageRectTop - viewportRectTop),
                          Math.max(0, viewportRectRight() - pageRectRight),
@@ -193,111 +159,81 @@ public class ImmutableViewportMetrics {
             FloatUtils.interpolate(cssPageRectLeft, to.cssPageRectLeft, t),
             FloatUtils.interpolate(cssPageRectTop, to.cssPageRectTop, t),
             FloatUtils.interpolate(cssPageRectRight, to.cssPageRectRight, t),
             FloatUtils.interpolate(cssPageRectBottom, to.cssPageRectBottom, t),
             FloatUtils.interpolate(viewportRectLeft, to.viewportRectLeft, t),
             FloatUtils.interpolate(viewportRectTop, to.viewportRectTop, t),
             (int)FloatUtils.interpolate(viewportRectWidth, to.viewportRectWidth, t),
             (int)FloatUtils.interpolate(viewportRectHeight, to.viewportRectHeight, t),
-            FloatUtils.interpolate(marginLeft, to.marginLeft, t),
-            FloatUtils.interpolate(marginTop, to.marginTop, t),
-            FloatUtils.interpolate(marginRight, to.marginRight, t),
-            FloatUtils.interpolate(marginBottom, to.marginBottom, t),
             FloatUtils.interpolate(zoomFactor, to.zoomFactor, t),
             t >= 0.5 ? to.isRTL : isRTL);
     }
 
     public ImmutableViewportMetrics setViewportSize(int width, int height) {
         if (width == viewportRectWidth && height == viewportRectHeight) {
             return this;
         }
 
         return new ImmutableViewportMetrics(
             pageRectLeft, pageRectTop, pageRectRight, pageRectBottom,
             cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom,
             viewportRectLeft, viewportRectTop, width, height,
-            marginLeft, marginTop, marginRight, marginBottom,
             zoomFactor, isRTL);
     }
 
     public ImmutableViewportMetrics setViewportOrigin(float newOriginX, float newOriginY) {
         return new ImmutableViewportMetrics(
             pageRectLeft, pageRectTop, pageRectRight, pageRectBottom,
             cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom,
             newOriginX, newOriginY, viewportRectWidth, viewportRectHeight,
-            marginLeft, marginTop, marginRight, marginBottom,
             zoomFactor, isRTL);
     }
 
     public ImmutableViewportMetrics setZoomFactor(float newZoomFactor) {
         return new ImmutableViewportMetrics(
             pageRectLeft, pageRectTop, pageRectRight, pageRectBottom,
             cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom,
             viewportRectLeft, viewportRectTop, viewportRectWidth, viewportRectHeight,
-            marginLeft, marginTop, marginRight, marginBottom,
             newZoomFactor, isRTL);
     }
 
     public ImmutableViewportMetrics offsetViewportBy(float dx, float dy) {
         return setViewportOrigin(viewportRectLeft + dx, viewportRectTop + dy);
     }
 
     public ImmutableViewportMetrics offsetViewportByAndClamp(float dx, float dy) {
         if (isRTL) {
             return setViewportOrigin(
-                Math.min(pageRectRight - getWidthWithoutMargins(), Math.max(viewportRectLeft + dx, pageRectLeft)),
-                Math.max(pageRectTop, Math.min(viewportRectTop + dy, pageRectBottom - getHeightWithoutMargins())));
+                Math.min(pageRectRight - getWidth(), Math.max(viewportRectLeft + dx, pageRectLeft)),
+                Math.max(pageRectTop, Math.min(viewportRectTop + dy, pageRectBottom - getHeight())));
         }
         return setViewportOrigin(
-            Math.max(pageRectLeft, Math.min(viewportRectLeft + dx, pageRectRight - getWidthWithoutMargins())),
-            Math.max(pageRectTop, Math.min(viewportRectTop + dy, pageRectBottom - getHeightWithoutMargins())));
+            Math.max(pageRectLeft, Math.min(viewportRectLeft + dx, pageRectRight - getWidth())),
+            Math.max(pageRectTop, Math.min(viewportRectTop + dy, pageRectBottom - getHeight())));
     }
 
     public ImmutableViewportMetrics setPageRect(RectF pageRect, RectF cssPageRect) {
         return new ImmutableViewportMetrics(
             pageRect.left, pageRect.top, pageRect.right, pageRect.bottom,
             cssPageRect.left, cssPageRect.top, cssPageRect.right, cssPageRect.bottom,
             viewportRectLeft, viewportRectTop, viewportRectWidth, viewportRectHeight,
-            marginLeft, marginTop, marginRight, marginBottom,
             zoomFactor, isRTL);
     }
 
-    public ImmutableViewportMetrics setMargins(float left, float top, float right, float bottom) {
-        if (FloatUtils.fuzzyEquals(left, marginLeft)
-                && FloatUtils.fuzzyEquals(top, marginTop)
-                && FloatUtils.fuzzyEquals(right, marginRight)
-                && FloatUtils.fuzzyEquals(bottom, marginBottom)) {
-            return this;
-        }
-
-        return new ImmutableViewportMetrics(
-            pageRectLeft, pageRectTop, pageRectRight, pageRectBottom,
-            cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom,
-            viewportRectLeft, viewportRectTop, viewportRectWidth, viewportRectHeight,
-            left, top, right, bottom, zoomFactor, isRTL);
-    }
-
-    public ImmutableViewportMetrics setMarginsFrom(ImmutableViewportMetrics fromMetrics) {
-        return setMargins(fromMetrics.marginLeft,
-                          fromMetrics.marginTop,
-                          fromMetrics.marginRight,
-                          fromMetrics.marginBottom);
-    }
-
     public ImmutableViewportMetrics setIsRTL(boolean aIsRTL) {
         if (isRTL == aIsRTL) {
             return this;
         }
 
         return new ImmutableViewportMetrics(
             pageRectLeft, pageRectTop, pageRectRight, pageRectBottom,
             cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom,
             viewportRectLeft, viewportRectTop, viewportRectWidth, viewportRectHeight,
-            marginLeft, marginTop, marginRight, marginBottom, zoomFactor, aIsRTL);
+            zoomFactor, aIsRTL);
     }
 
     /* This will set the zoom factor and re-scale page-size and viewport offset
      * accordingly. The given focus will remain at the same point on the screen
      * after scaling.
      */
     public ImmutableViewportMetrics scaleTo(float newZoomFactor, PointF focus) {
         // cssPageRect* is invariant, since we're setting the scale factor
@@ -311,63 +247,47 @@ public class ImmutableViewportMetrics {
         origin.offset(focus.x, focus.y);
         origin = PointUtils.scale(origin, newZoomFactor / zoomFactor);
         origin.offset(-focus.x, -focus.y);
 
         return new ImmutableViewportMetrics(
             newPageRectLeft, newPageRectTop, newPageRectRight, newPageRectBottom,
             cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom,
             origin.x, origin.y, viewportRectWidth, viewportRectHeight,
-            marginLeft, marginTop, marginRight, marginBottom,
             newZoomFactor, isRTL);
     }
 
     /** Clamps the viewport to remain within the page rect. */
-    private ImmutableViewportMetrics clamp(float marginLeft, float marginTop,
-                                           float marginRight, float marginBottom) {
+    public ImmutableViewportMetrics clamp() {
         RectF newViewport = getViewport();
-        PointF offset = getMarginOffset();
 
         // The viewport bounds ought to never exceed the page bounds.
-        if (newViewport.right > pageRectRight + marginLeft + marginRight)
-            newViewport.offset((pageRectRight + marginLeft + marginRight) - newViewport.right, 0);
+        if (newViewport.right > pageRectRight)
+            newViewport.offset((pageRectRight) - newViewport.right, 0);
         if (newViewport.left < pageRectLeft)
             newViewport.offset(pageRectLeft - newViewport.left, 0);
 
-        if (newViewport.bottom > pageRectBottom + marginTop + marginBottom)
-            newViewport.offset(0, (pageRectBottom + marginTop + marginBottom) - newViewport.bottom);
+        if (newViewport.bottom > pageRectBottom)
+            newViewport.offset(0, (pageRectBottom) - newViewport.bottom);
         if (newViewport.top < pageRectTop)
             newViewport.offset(0, pageRectTop - newViewport.top);
 
         // Note that since newViewport is only translated around, the viewport's
         // width and height are unchanged.
         return new ImmutableViewportMetrics(
             pageRectLeft, pageRectTop, pageRectRight, pageRectBottom,
             cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom,
             newViewport.left, newViewport.top, viewportRectWidth, viewportRectHeight,
-            marginLeft, marginTop, marginRight, marginBottom,
             zoomFactor, isRTL);
     }
 
-    public ImmutableViewportMetrics clamp() {
-        return clamp(0, 0, 0, 0);
-    }
-
-    public ImmutableViewportMetrics clampWithMargins() {
-        return clamp(marginLeft, marginTop,
-                     marginRight, marginBottom);
-    }
-
     public boolean fuzzyEquals(ImmutableViewportMetrics other) {
         // Don't bother checking the pageRectXXX values because they are a product
         // of the cssPageRectXXX values and the zoomFactor, except with more rounding
         // error. Checking those is both inefficient and can lead to false negatives.
-        //
-        // This doesn't return false if the margins differ as none of the users
-        // of this function are interested in the margins in that way.
         return FloatUtils.fuzzyEquals(cssPageRectLeft, other.cssPageRectLeft)
             && FloatUtils.fuzzyEquals(cssPageRectTop, other.cssPageRectTop)
             && FloatUtils.fuzzyEquals(cssPageRectRight, other.cssPageRectRight)
             && FloatUtils.fuzzyEquals(cssPageRectBottom, other.cssPageRectBottom)
             && FloatUtils.fuzzyEquals(viewportRectLeft, other.viewportRectLeft)
             && FloatUtils.fuzzyEquals(viewportRectTop, other.viewportRectTop)
             && viewportRectWidth == other.viewportRectWidth
             && viewportRectHeight == other.viewportRectHeight
@@ -375,13 +295,11 @@ public class ImmutableViewportMetrics {
     }
 
     @Override
     public String toString() {
         return "ImmutableViewportMetrics v=(" + viewportRectLeft + "," + viewportRectTop + ","
                 + viewportRectWidth + "x" + viewportRectHeight + ") p=(" + pageRectLeft + ","
                 + pageRectTop + "," + pageRectRight + "," + pageRectBottom + ") c=("
                 + cssPageRectLeft + "," + cssPageRectTop + "," + cssPageRectRight + ","
-                + cssPageRectBottom + ") m=(" + marginLeft + ","
-                + marginTop + "," + marginRight + ","
-                + marginBottom + ") z=" + zoomFactor + ", rtl=" + isRTL;
+                + cssPageRectBottom + ") z=" + zoomFactor + ", rtl=" + isRTL;
     }
 }
--- a/mobile/android/base/gfx/JavaPanZoomController.java
+++ b/mobile/android/base/gfx/JavaPanZoomController.java
@@ -1082,31 +1082,31 @@ class JavaPanZoomController
             PointF center = new PointF(focusX, focusY);
             viewportMetrics = viewportMetrics.scaleTo(minZoomFactor, center);
         } else if (zoomFactor > maxZoomFactor) {
             PointF center = new PointF(viewport.width() / 2.0f, viewport.height() / 2.0f);
             viewportMetrics = viewportMetrics.scaleTo(maxZoomFactor, center);
         }
 
         /* Now we pan to the right origin. */
-        viewportMetrics = viewportMetrics.clampWithMargins();
+        viewportMetrics = viewportMetrics.clamp();
 
         return viewportMetrics;
     }
 
     private class AxisX extends Axis {
         AxisX(SubdocumentScrollHelper subscroller) { super(subscroller); }
         @Override
         public float getOrigin() { return getMetrics().viewportRectLeft; }
         @Override
         protected float getViewportLength() { return getMetrics().getWidth(); }
         @Override
         protected float getPageStart() { return getMetrics().pageRectLeft; }
         @Override
-        protected float getPageLength() { return getMetrics().getPageWidthWithMargins(); }
+        protected float getPageLength() { return getMetrics().getPageWidth(); }
         @Override
         protected float getVisibleEndOfLayerView() {
             return mTarget.getVisibleEndOfLayerView().x;
         }
         @Override
         protected void overscrollFling(final float velocity) {
             if (mOverscroll != null) {
                 mOverscroll.setVelocity(velocity, Overscroll.Axis.X);
@@ -1124,17 +1124,17 @@ class JavaPanZoomController
         AxisY(SubdocumentScrollHelper subscroller) { super(subscroller); }
         @Override
         public float getOrigin() { return getMetrics().viewportRectTop; }
         @Override
         protected float getViewportLength() { return getMetrics().getHeight(); }
         @Override
         protected float getPageStart() { return getMetrics().pageRectTop; }
         @Override
-        protected float getPageLength() { return getMetrics().getPageHeightWithMargins(); }
+        protected float getPageLength() { return getMetrics().getPageHeight(); }
         @Override
         protected float getVisibleEndOfLayerView() {
             return mTarget.getVisibleEndOfLayerView().y;
         }
         @Override
         protected void overscrollFling(final float velocity) {
             if (mOverscroll != null) {
                 mOverscroll.setVelocity(velocity, Overscroll.Axis.Y);
--- a/mobile/android/base/gfx/Layer.java
+++ b/mobile/android/base/gfx/Layer.java
@@ -172,36 +172,33 @@ public abstract class Layer {
         dest[18] = cropRect.right / texWidth;
         dest[19] = cropRect.bottom / texHeight;
     }
 
     public static class RenderContext {
         public final RectF viewport;
         public final RectF pageRect;
         public final float zoomFactor;
-        public final PointF offset;
         public final int positionHandle;
         public final int textureHandle;
         public final FloatBuffer coordBuffer;
 
-        public RenderContext(RectF aViewport, RectF aPageRect, float aZoomFactor, PointF aOffset,
+        public RenderContext(RectF aViewport, RectF aPageRect, float aZoomFactor,
                              int aPositionHandle, int aTextureHandle, FloatBuffer aCoordBuffer) {
             viewport = aViewport;
             pageRect = aPageRect;
             zoomFactor = aZoomFactor;
-            offset = aOffset;
             positionHandle = aPositionHandle;
             textureHandle = aTextureHandle;
             coordBuffer = aCoordBuffer;
         }
 
         public boolean fuzzyEquals(RenderContext other) {
             if (other == null) {
                 return false;
             }
             return RectUtils.fuzzyEquals(viewport, other.viewport)
                 && RectUtils.fuzzyEquals(pageRect, other.pageRect)
-                && FloatUtils.fuzzyEquals(zoomFactor, other.zoomFactor)
-                && FloatUtils.fuzzyEquals(offset, other.offset);
+                && FloatUtils.fuzzyEquals(zoomFactor, other.zoomFactor);
         }
     }
 }
 
--- a/mobile/android/base/gfx/LayerRenderer.java
+++ b/mobile/android/base/gfx/LayerRenderer.java
@@ -318,43 +318,43 @@ public class LayerRenderer implements Ta
                 pixelBuffer.wait();
             } catch (InterruptedException ie) {
             }
             mPixelBuffer = null;
         }
         return pixelBuffer;
     }
 
-    private RenderContext createScreenContext(ImmutableViewportMetrics metrics, PointF offset) {
+    private RenderContext createScreenContext(ImmutableViewportMetrics metrics) {
         RectF viewport = new RectF(0.0f, 0.0f, metrics.getWidth(), metrics.getHeight());
         RectF pageRect = metrics.getPageRect();
 
-        return createContext(viewport, pageRect, 1.0f, offset);
+        return createContext(viewport, pageRect, 1.0f);
     }
 
-    private RenderContext createPageContext(ImmutableViewportMetrics metrics, PointF offset) {
+    private RenderContext createPageContext(ImmutableViewportMetrics metrics) {
         RectF viewport = metrics.getViewport();
         RectF pageRect = metrics.getPageRect();
         float zoomFactor = metrics.zoomFactor;
 
-        return createContext(new RectF(RectUtils.round(viewport)), pageRect, zoomFactor, offset);
+        return createContext(new RectF(RectUtils.round(viewport)), pageRect, zoomFactor);
     }
 
-    private RenderContext createContext(RectF viewport, RectF pageRect, float zoomFactor, PointF offset) {
+    private RenderContext createContext(RectF viewport, RectF pageRect, float zoomFactor) {
         if (mCoordBuffer == null) {
             // Initialize the FloatBuffer that will be used to store all vertices and texture
             // coordinates in draw() commands.
             mCoordByteBuffer = DirectBufferAllocator.allocate(COORD_BUFFER_SIZE * 4);
             mCoordByteBuffer.order(ByteOrder.nativeOrder());
             mCoordBuffer = mCoordByteBuffer.asFloatBuffer();
             if (mCoordBuffer == null) {
                 throw new IllegalStateException();
             }
         }
-        return new RenderContext(viewport, pageRect, zoomFactor, offset,
+        return new RenderContext(viewport, pageRect, zoomFactor,
                                  mPositionHandle, mTextureHandle, mCoordBuffer);
     }
 
     private void updateDroppedFrames(long frameStartTime) {
         int frameElapsedTime = (int)((System.nanoTime() - frameStartTime) / NANOS_PER_MS);
 
         /* Update the running statistics. */
         mFrameTimingsSum -= mFrameTimings[mCurrentFrame];
@@ -430,26 +430,24 @@ public class LayerRenderer implements Ta
         // A fixed snapshot of the viewport metrics that this frame is using to render content.
         private final ImmutableViewportMetrics mFrameMetrics;
         // A rendering context for page-positioned layers, and one for screen-positioned layers.
         private final RenderContext mPageContext, mScreenContext;
         // Whether a layer was updated.
         private boolean mUpdated;
         private final Rect mPageRect;
         private final Rect mAbsolutePageRect;
-        private final PointF mRenderOffset;
 
         public Frame(ImmutableViewportMetrics metrics) {
             mFrameMetrics = metrics;
 
             // Work out the offset due to margins
             Layer rootLayer = mView.getLayerClient().getRoot();
-            mRenderOffset = mFrameMetrics.getMarginOffset();
-            mPageContext = createPageContext(metrics, mRenderOffset);
-            mScreenContext = createScreenContext(metrics, mRenderOffset);
+            mPageContext = createPageContext(metrics);
+            mScreenContext = createScreenContext(metrics);
 
             RectF pageRect = mFrameMetrics.getPageRect();
             mAbsolutePageRect = RectUtils.round(pageRect);
 
             PointF origin = mFrameMetrics.getOrigin();
             pageRect.offset(-origin.x, -origin.y);
             mPageRect = RectUtils.round(pageRect);
         }
@@ -577,18 +575,18 @@ public class LayerRenderer implements Ta
             // because the following line is just a short-circuit
             if (mZoomedViewListeners.size() == 0) {
                 return;
             }
 
             // When scrolling fast, do not request zoomed view render to avoid to slow down
             // the scroll in the main view.
             // Speed is estimated using the offset changes between 2 display frame calls
-            final float viewLeft = context.viewport.left - context.offset.x;
-            final float viewTop = context.viewport.top - context.offset.y;
+            final float viewLeft = context.viewport.left;
+            final float viewTop = context.viewport.top;
             boolean shouldWaitToRender = false;
 
             if (Math.abs(mLastViewLeft - viewLeft) > MAX_SCROLL_SPEED_TO_REQUEST_ZOOM_RENDER ||
                 Math.abs(mLastViewTop - viewTop) > MAX_SCROLL_SPEED_TO_REQUEST_ZOOM_RENDER) {
                 shouldWaitToRender = true;
             }
 
             mLastViewLeft = viewLeft;
--- a/mobile/android/base/gfx/PluginLayer.java
+++ b/mobile/android/base/gfx/PluginLayer.java
@@ -102,17 +102,17 @@ public class PluginLayer extends Layer {
         if (mDestroyed)
             return;
 
         if (!RectUtils.fuzzyEquals(context.viewport, mLastViewport) ||
             !FloatUtils.fuzzyEquals(context.zoomFactor, mLastZoomFactor)) {
 
             mLastZoomFactor = context.zoomFactor;
             mLastViewport = context.viewport;
-            mLayoutParams.reposition(context.viewport, context.offset, context.zoomFactor);
+            mLayoutParams.reposition(context.viewport, context.zoomFactor);
 
             showView();
         }
     }
 
     @Override
     public void draw(RenderContext context) {
     }
@@ -143,20 +143,19 @@ public class PluginLayer extends Layer {
                 }
             }
         }
 
         public void reset(RectF rect) {
             mRect = rect;
         }
 
-        public void reposition(RectF viewport, PointF offset, float zoomFactor) {
+        public void reposition(RectF viewport, float zoomFactor) {
 
             RectF scaled = RectUtils.scale(mRect, zoomFactor);
-            scaled.offset(offset.x, offset.y);
 
             this.x = Math.round(scaled.left - viewport.left);
             this.y = Math.round(scaled.top - viewport.top);
 
             if (!FloatUtils.fuzzyEquals(mLastResolution, zoomFactor)) {
                 width = Math.round(mRect.width() * zoomFactor);
                 height = Math.round(mRect.height() * zoomFactor);
                 mLastResolution = zoomFactor;
--- a/mobile/android/base/gfx/ScrollbarLayer.java
+++ b/mobile/android/base/gfx/ScrollbarLayer.java
@@ -197,17 +197,16 @@ public class ScrollbarLayer extends Laye
 
         GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
         GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, getTextureID());
 
         float viewWidth = context.viewport.width();
         float viewHeight = context.viewport.height();
 
         mBarRectF.set(mBarRect.left, viewHeight - mBarRect.top, mBarRect.right, viewHeight - mBarRect.bottom);
-        mBarRectF.offset(context.offset.x, -context.offset.y);
 
         // We take a 1-pixel slice from the center of the image and scale it to become the bar
         fillRectCoordBuffer(mCoords, mBarRectF, viewWidth, viewHeight, mBodyTexCoords, mTexWidth, mTexHeight);
 
         // Get the buffer and handles from the context
         FloatBuffer coordBuffer = context.coordBuffer;
         int positionHandle = mPositionHandle;
         int textureHandle = mTextureHandle;
@@ -281,32 +280,32 @@ public class ScrollbarLayer extends Laye
         // Enable the default shader program again
         deactivateProgram();
         mRenderer.activateDefaultProgram();
     }
 
     private void getVerticalRect(RenderContext context, RectF dest) {
         RectF viewport = context.viewport;
         RectF pageRect = context.pageRect;
-        float viewportHeight = viewport.height() - context.offset.y;
-        float barStart = ((viewport.top - context.offset.y - pageRect.top) * (viewportHeight / pageRect.height())) + mCapLength;
-        float barEnd = ((viewport.bottom - context.offset.y - pageRect.top) * (viewportHeight / pageRect.height())) - mCapLength;
+        float viewportHeight = viewport.height();
+        float barStart = ((viewport.top - pageRect.top) * (viewportHeight / pageRect.height())) + mCapLength;
+        float barEnd = ((viewport.bottom - pageRect.top) * (viewportHeight / pageRect.height())) - mCapLength;
         if (barStart > barEnd) {
             float middle = (barStart + barEnd) / 2.0f;
             barStart = barEnd = middle;
         }
         dest.set(viewport.width() - mBarWidth, barStart, viewport.width(), barEnd);
     }
 
     private void getHorizontalRect(RenderContext context, RectF dest) {
         RectF viewport = context.viewport;
         RectF pageRect = context.pageRect;
-        float viewportWidth = viewport.width() - context.offset.x;
-        float barStart = ((viewport.left - context.offset.x - pageRect.left) * (viewport.width() / pageRect.width())) + mCapLength;
-        float barEnd = ((viewport.right - context.offset.x - pageRect.left) * (viewport.width() / pageRect.width())) - mCapLength;
+        float viewportWidth = viewport.width();
+        float barStart = ((viewport.left - pageRect.left) * (viewport.width() / pageRect.width())) + mCapLength;
+        float barEnd = ((viewport.right - pageRect.left) * (viewport.width() / pageRect.width())) - mCapLength;
         if (barStart > barEnd) {
             float middle = (barStart + barEnd) / 2.0f;
             barStart = barEnd = middle;
         }
         dest.set(barStart, viewport.height() - mBarWidth, barEnd, viewport.height());
     }
 
     private void validateTexture() {