Bug 737510 - Expand the displayport to fill any partial tiles. r=Cwiiis

This commit is contained in:
Kartikaya Gupta 2012-04-23 23:53:44 -04:00
parent 9e44b9992a
commit 81a50d6330

View File

@ -8,6 +8,7 @@ package org.mozilla.gecko.gfx;
import java.util.Map; import java.util.Map;
import android.graphics.PointF; import android.graphics.PointF;
import android.graphics.RectF; import android.graphics.RectF;
import android.util.FloatMath;
import android.util.Log; import android.util.Log;
import org.json.JSONArray; import org.json.JSONArray;
import org.mozilla.gecko.FloatUtils; import org.mozilla.gecko.FloatUtils;
@ -17,6 +18,9 @@ final class DisplayPortCalculator {
private static final String LOGTAG = "GeckoDisplayPortCalculator"; private static final String LOGTAG = "GeckoDisplayPortCalculator";
private static final PointF ZERO_VELOCITY = new PointF(0, 0); 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_STRATEGY = "gfx.displayport.strategy";
private static final String PREF_DISPLAYPORT_FM_MULTIPLIER = "gfx.displayport.strategy_fm.multiplier"; 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"; private static final String PREF_DISPLAYPORT_FM_DANGER_X = "gfx.displayport.strategy_fm.danger_x";
@ -139,6 +143,24 @@ final class DisplayPortCalculator {
return rect; 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 * 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; * 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.bottom = verticalBuffer - margins.top;
margins = shiftMarginsForPageBounds(margins, metrics); margins = shiftMarginsForPageBounds(margins, metrics);
// note that unless the viewport size changes, or the page dimensions change (either because of return getTileAlignedDisplayPortMetrics(margins, metrics.zoomFactor, metrics);
// 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);
} }
public boolean aboutToCheckerboard(ImmutableViewportMetrics metrics, PointF velocity, DisplayPortMetrics displayPort) { public boolean aboutToCheckerboard(ImmutableViewportMetrics metrics, PointF velocity, DisplayPortMetrics displayPort) {
@ -363,11 +377,7 @@ final class DisplayPortCalculator {
RectF margins = velocityBiasedMargins(horizontalBuffer, verticalBuffer, velocity); RectF margins = velocityBiasedMargins(horizontalBuffer, verticalBuffer, velocity);
margins = shiftMarginsForPageBounds(margins, metrics); margins = shiftMarginsForPageBounds(margins, metrics);
return new DisplayPortMetrics(metrics.viewportRectLeft - margins.left, return getTileAlignedDisplayPortMetrics(margins, metrics.zoomFactor, metrics);
metrics.viewportRectTop - margins.top,
metrics.viewportRectRight + margins.right,
metrics.viewportRectBottom + margins.bottom,
metrics.zoomFactor);
} }
public boolean aboutToCheckerboard(ImmutableViewportMetrics metrics, PointF velocity, DisplayPortMetrics displayPort) { public boolean aboutToCheckerboard(ImmutableViewportMetrics metrics, PointF velocity, DisplayPortMetrics displayPort) {