Bug 729528 - Add a DisplayPortMetrics to track the requested display resolution along with the area. r=Cwiiis

This commit is contained in:
Kartikaya Gupta 2012-03-26 13:15:49 -04:00
Родитель d900269514
Коммит c3638fea09
6 изменённых файлов: 72 добавлений и 19 удалений

Просмотреть файл

@ -37,8 +37,8 @@
package org.mozilla.gecko;
import org.mozilla.gecko.gfx.DisplayPortMetrics;
import org.mozilla.gecko.gfx.IntSize;
import org.mozilla.gecko.gfx.RectUtils;
import org.mozilla.gecko.gfx.ViewportMetrics;
import android.os.*;
import android.app.*;
@ -418,7 +418,7 @@ public class GeckoEvent {
return event;
}
public static GeckoEvent createViewportEvent(ViewportMetrics viewport, RectF displayPort) {
public static GeckoEvent createViewportEvent(ViewportMetrics viewport, DisplayPortMetrics displayPort) {
GeckoEvent event = new GeckoEvent(VIEWPORT);
event.mCharacters = "Viewport:Change";
PointF origin = viewport.getOrigin();
@ -426,7 +426,7 @@ public class GeckoEvent {
sb.append("{ \"x\" : ").append(origin.x)
.append(", \"y\" : ").append(origin.y)
.append(", \"zoom\" : ").append(viewport.getZoomFactor())
.append(", \"displayPort\" :").append(RectUtils.toJSON(displayPort))
.append(", \"displayPort\" :").append(displayPort.toJSON())
.append('}');
event.mCharactersExtra = sb.toString();
return event;

Просмотреть файл

@ -120,6 +120,7 @@ FENNEC_JAVA_FILES = \
gfx/CairoImage.java \
gfx/CairoUtils.java \
gfx/CheckerboardImage.java \
gfx/DisplayPortMetrics.java \
gfx/FlexibleGLSurfaceView.java \
gfx/FloatSize.java \
gfx/GeckoLayerClient.java \

Просмотреть файл

@ -0,0 +1,51 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.gfx;
import android.graphics.RectF;
/*
* This class keeps track of the area we request Gecko to paint, as well
* as the resolution of the paint. The area may be different from the visible
* area of the page, and the resolution may be different from the resolution
* used in the compositor to render the page. This is so that we can ask Gecko
* to paint a much larger area without using extra memory, and then render some
* subsection of that with compositor scaling.
*/
public final class DisplayPortMetrics {
private final RectF mPosition;
private final float mResolution;
public DisplayPortMetrics() {
this(0, 0, 0, 0, 1);
}
public DisplayPortMetrics(float left, float top, float right, float bottom, float resolution) {
mPosition = new RectF(left, top, right, bottom);
mResolution = resolution;
}
public boolean contains(RectF rect) {
return mPosition.contains(rect);
}
public String toJSON() {
StringBuffer sb = new StringBuffer(256);
sb.append("{ \"left\": ").append(mPosition.left)
.append(", \"top\": ").append(mPosition.top)
.append(", \"right\": ").append(mPosition.right)
.append(", \"bottom\": ").append(mPosition.bottom)
.append(", \"resolution\": ").append(mResolution)
.append('}');
return sb.toString();
}
public String toString() {
return "DisplayPortMetrics(" + mPosition.left + ","
+ mPosition.top + "," + mPosition.right + ","
+ mPosition.bottom + "," + mResolution + ")";
}
}

Просмотреть файл

@ -68,8 +68,8 @@ public class GeckoLayerClient implements GeckoEventResponder,
private IntSize mScreenSize;
private IntSize mWindowSize;
private RectF mDisplayPort;
private RectF mReturnDisplayPort;
private DisplayPortMetrics mDisplayPort;
private DisplayPortMetrics mReturnDisplayPort;
private VirtualLayer mRootLayer;
@ -95,7 +95,7 @@ public class GeckoLayerClient implements GeckoEventResponder,
// to before being read
mScreenSize = new IntSize(0, 0);
mWindowSize = new IntSize(0, 0);
mDisplayPort = new RectF();
mDisplayPort = new DisplayPortMetrics();
mCurrentViewTransform = new ViewTransform(0, 0, 1);
}
@ -120,7 +120,7 @@ public class GeckoLayerClient implements GeckoEventResponder,
sendResizeEventIfNecessary(true);
}
RectF getDisplayPort() {
DisplayPortMetrics getDisplayPort() {
return mDisplayPort;
}
@ -171,7 +171,7 @@ public class GeckoLayerClient implements GeckoEventResponder,
GeckoAppShell.viewSizeChanged();
}
private static RectF calculateDisplayPort(ImmutableViewportMetrics metrics) {
private static DisplayPortMetrics calculateDisplayPort(ImmutableViewportMetrics metrics) {
float desiredXMargins = 2 * DEFAULT_DISPLAY_PORT_MARGIN;
float desiredYMargins = 2 * DEFAULT_DISPLAY_PORT_MARGIN;
@ -226,10 +226,11 @@ public class GeckoLayerClient implements GeckoEventResponder,
// 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 RectF(metrics.viewportRectLeft - leftMargin,
metrics.viewportRectTop - topMargin,
metrics.viewportRectRight + rightMargin,
metrics.viewportRectBottom + bottomMargin);
return new DisplayPortMetrics(metrics.viewportRectLeft - leftMargin,
metrics.viewportRectTop - topMargin,
metrics.viewportRectRight + rightMargin,
metrics.viewportRectBottom + bottomMargin,
metrics.zoomFactor);
}
private void adjustViewport() {
@ -320,7 +321,7 @@ public class GeckoLayerClient implements GeckoEventResponder,
return "";
}
try {
return RectUtils.toJSON(mReturnDisplayPort);
return mReturnDisplayPort.toJSON();
} finally {
mReturnDisplayPort = null;
}

Просмотреть файл

@ -345,7 +345,7 @@ public class LayerController implements Tabs.OnTabsChangedListener {
if (adjustedViewport.right > pageSize.width) adjustedViewport.right = pageSize.width;
if (adjustedViewport.bottom > pageSize.height) adjustedViewport.bottom = pageSize.height;
RectF displayPort = (mLayerClient == null ? new RectF() : mLayerClient.getDisplayPort());
DisplayPortMetrics displayPort = (mLayerClient == null ? new DisplayPortMetrics() : mLayerClient.getDisplayPort());
return !displayPort.contains(adjustedViewport);
}

Просмотреть файл

@ -1605,7 +1605,7 @@ Tab.prototype = {
return this.browser.docShellIsActive;
},
setDisplayPort: function(aViewportX, aViewportY, aDisplayPortRect) {
setDisplayPort: function(aViewportX, aViewportY, aDisplayPort) {
let zoom = this._zoom;
if (zoom <= 0)
return;
@ -1615,10 +1615,10 @@ Tab.prototype = {
return;
let cwu = window.top.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
cwu.setDisplayPortForElement((aDisplayPortRect.left - aViewportX) / zoom,
(aDisplayPortRect.top - aViewportY) / zoom,
(aDisplayPortRect.right - aDisplayPortRect.left) / zoom,
(aDisplayPortRect.bottom - aDisplayPortRect.top) / zoom,
cwu.setDisplayPortForElement((aDisplayPort.left - aViewportX) / zoom,
(aDisplayPort.top - aViewportY) / zoom,
(aDisplayPort.right - aDisplayPort.left) / zoom,
(aDisplayPort.bottom - aDisplayPort.top) / zoom,
element);
},