From 81a50d63306da24944976ad9d1fabd09856f69b5 Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Mon, 23 Apr 2012 23:53:44 -0400 Subject: [PATCH] Bug 737510 - Expand the displayport to fill any partial tiles. r=Cwiiis --- .../base/gfx/DisplayPortCalculator.java | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/mobile/android/base/gfx/DisplayPortCalculator.java b/mobile/android/base/gfx/DisplayPortCalculator.java index 4efe1ddfe851..7de9cc5b0370 100644 --- a/mobile/android/base/gfx/DisplayPortCalculator.java +++ b/mobile/android/base/gfx/DisplayPortCalculator.java @@ -8,6 +8,7 @@ package org.mozilla.gecko.gfx; import java.util.Map; import android.graphics.PointF; import android.graphics.RectF; +import android.util.FloatMath; import android.util.Log; import org.json.JSONArray; import org.mozilla.gecko.FloatUtils; @@ -17,6 +18,9 @@ final class DisplayPortCalculator { private static final String LOGTAG = "GeckoDisplayPortCalculator"; private static final PointF ZERO_VELOCITY = new PointF(0, 0); + // Keep this in sync with the TILEDLAYERBUFFER_TILE_SIZE defined in gfx/layers/TiledLayerBuffer.h + private static final int TILE_SIZE = 256; + private static final String PREF_DISPLAYPORT_STRATEGY = "gfx.displayport.strategy"; private static final String PREF_DISPLAYPORT_FM_MULTIPLIER = "gfx.displayport.strategy_fm.multiplier"; private static final String PREF_DISPLAYPORT_FM_DANGER_X = "gfx.displayport.strategy_fm.danger_x"; @@ -139,6 +143,24 @@ final class DisplayPortCalculator { return rect; } + /** + * Expand the given margins such that when they are applied on the viewport, the resulting rect + * does not have any partial tiles, except when it is clipped by the page bounds. This assumes + * the tiles are TILE_SIZE by TILE_SIZE and start at the origin, such that there will always be + * a tile at (0,0)-(TILE_SIZE,TILE_SIZE)). + */ + private static DisplayPortMetrics getTileAlignedDisplayPortMetrics(RectF margins, float zoom, ImmutableViewportMetrics metrics) { + float left = metrics.viewportRectLeft - margins.left; + float top = metrics.viewportRectTop - margins.top; + float right = metrics.viewportRectRight + margins.right; + float bottom = metrics.viewportRectBottom + margins.bottom; + left = Math.max(0.0f, TILE_SIZE * FloatMath.floor(left / TILE_SIZE)); + top = Math.max(0.0f, TILE_SIZE * FloatMath.floor(top / TILE_SIZE)); + right = Math.min(metrics.pageSizeWidth, TILE_SIZE * FloatMath.ceil(right / TILE_SIZE)); + bottom = Math.min(metrics.pageSizeHeight, TILE_SIZE * FloatMath.ceil(bottom / TILE_SIZE)); + return new DisplayPortMetrics(left, top, right, bottom, zoom); + } + /** * Adjust the given margins so if they are applied on the viewport in the metrics, the resulting rect * does not exceed the page bounds. This code will maintain the total margin amount for a given axis; @@ -246,15 +268,7 @@ final class DisplayPortCalculator { margins.bottom = verticalBuffer - margins.top; margins = shiftMarginsForPageBounds(margins, metrics); - // note that unless the viewport size changes, or the page dimensions change (either because of - // content changes or zooming), the size of the display port should remain constant. this - // is intentional to avoid re-creating textures and all sorts of other reallocations in the - // draw and composition code. - return new DisplayPortMetrics(metrics.viewportRectLeft - margins.left, - metrics.viewportRectTop - margins.top, - metrics.viewportRectRight + margins.right, - metrics.viewportRectBottom + margins.bottom, - metrics.zoomFactor); + return getTileAlignedDisplayPortMetrics(margins, metrics.zoomFactor, metrics); } public boolean aboutToCheckerboard(ImmutableViewportMetrics metrics, PointF velocity, DisplayPortMetrics displayPort) { @@ -363,11 +377,7 @@ final class DisplayPortCalculator { RectF margins = velocityBiasedMargins(horizontalBuffer, verticalBuffer, velocity); margins = shiftMarginsForPageBounds(margins, metrics); - return new DisplayPortMetrics(metrics.viewportRectLeft - margins.left, - metrics.viewportRectTop - margins.top, - metrics.viewportRectRight + margins.right, - metrics.viewportRectBottom + margins.bottom, - metrics.zoomFactor); + return getTileAlignedDisplayPortMetrics(margins, metrics.zoomFactor, metrics); } public boolean aboutToCheckerboard(ImmutableViewportMetrics metrics, PointF velocity, DisplayPortMetrics displayPort) {