2012-02-02 22:07:05 -08:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Android code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2009-2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Patrick Walton <pcwalton@mozilla.com>
|
|
|
|
* Chris Lord <chrislord.net@gmail.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
package org.mozilla.gecko.gfx;
|
|
|
|
|
|
|
|
import org.mozilla.gecko.FloatUtils;
|
|
|
|
import org.mozilla.gecko.GeckoApp;
|
|
|
|
import org.mozilla.gecko.GeckoAppShell;
|
|
|
|
import org.mozilla.gecko.GeckoEvent;
|
|
|
|
import org.mozilla.gecko.GeckoEventListener;
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import android.content.Context;
|
2012-02-02 23:30:41 -08:00
|
|
|
import android.graphics.Bitmap;
|
2012-02-02 22:07:05 -08:00
|
|
|
import android.graphics.Color;
|
2012-02-17 07:33:23 -08:00
|
|
|
import android.graphics.Point;
|
2012-02-02 22:07:05 -08:00
|
|
|
import android.graphics.PointF;
|
|
|
|
import android.graphics.Rect;
|
2012-02-16 22:36:49 -08:00
|
|
|
import android.graphics.RectF;
|
2012-02-02 22:07:05 -08:00
|
|
|
import android.os.SystemClock;
|
|
|
|
import android.util.DisplayMetrics;
|
|
|
|
import android.util.Log;
|
2012-02-17 07:33:23 -08:00
|
|
|
import android.view.View;
|
2012-02-02 22:07:05 -08:00
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
2012-02-17 07:33:23 -08:00
|
|
|
public abstract class GeckoLayerClient implements GeckoEventListener,
|
|
|
|
FlexibleGLSurfaceView.Listener,
|
|
|
|
VirtualLayer.Listener {
|
2012-02-02 22:07:05 -08:00
|
|
|
private static final String LOGTAG = "GeckoLayerClient";
|
|
|
|
|
2012-02-17 07:03:28 -08:00
|
|
|
protected LayerController mLayerController;
|
2012-02-17 07:33:23 -08:00
|
|
|
protected LayerRenderer mLayerRenderer;
|
2012-02-17 07:03:28 -08:00
|
|
|
|
2012-02-02 22:07:05 -08:00
|
|
|
protected IntSize mScreenSize;
|
|
|
|
protected IntSize mBufferSize;
|
|
|
|
|
|
|
|
protected Layer mTileLayer;
|
|
|
|
|
|
|
|
/* The viewport that Gecko is currently displaying. */
|
|
|
|
protected ViewportMetrics mGeckoViewport;
|
|
|
|
|
|
|
|
/* The viewport that Gecko will display when drawing is finished */
|
|
|
|
protected ViewportMetrics mNewGeckoViewport;
|
|
|
|
|
2012-02-07 23:10:58 -08:00
|
|
|
private static final long MIN_VIEWPORT_CHANGE_DELAY = 25L;
|
2012-02-02 22:07:05 -08:00
|
|
|
private long mLastViewportChangeTime;
|
|
|
|
private boolean mPendingViewportAdjust;
|
|
|
|
private boolean mViewportSizeChanged;
|
|
|
|
|
|
|
|
// mUpdateViewportOnEndDraw is used to indicate that we received a
|
|
|
|
// viewport update notification while drawing. therefore, when the
|
|
|
|
// draw finishes, we need to update the entire viewport rather than
|
|
|
|
// just the page size. this boolean should always be accessed from
|
|
|
|
// inside a transaction, so no synchronization is needed.
|
|
|
|
private boolean mUpdateViewportOnEndDraw;
|
|
|
|
|
2012-02-16 09:04:37 -08:00
|
|
|
private String mLastCheckerboardColor;
|
|
|
|
|
2012-02-02 22:07:05 -08:00
|
|
|
private static Pattern sColorPattern;
|
|
|
|
|
|
|
|
/* Used by robocop for testing purposes */
|
|
|
|
private DrawListener mDrawListener;
|
|
|
|
|
|
|
|
public GeckoLayerClient(Context context) {
|
|
|
|
mScreenSize = new IntSize(0, 0);
|
|
|
|
mBufferSize = new IntSize(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Attaches the root layer to the layer controller so that Gecko appears. */
|
|
|
|
public void setLayerController(LayerController layerController) {
|
2012-02-17 07:03:28 -08:00
|
|
|
mLayerController = layerController;
|
2012-02-02 22:07:05 -08:00
|
|
|
|
|
|
|
layerController.setRoot(mTileLayer);
|
|
|
|
if (mGeckoViewport != null) {
|
|
|
|
layerController.setViewportMetrics(mGeckoViewport);
|
|
|
|
}
|
|
|
|
|
|
|
|
GeckoAppShell.registerGeckoEventListener("Viewport:UpdateAndDraw", this);
|
|
|
|
GeckoAppShell.registerGeckoEventListener("Viewport:UpdateLater", this);
|
|
|
|
|
|
|
|
sendResizeEventIfNecessary();
|
2012-02-17 07:33:23 -08:00
|
|
|
|
|
|
|
LayerView view = layerController.getView();
|
|
|
|
view.setListener(this);
|
|
|
|
|
|
|
|
mLayerRenderer = new LayerRenderer(view);
|
2012-02-02 22:07:05 -08:00
|
|
|
}
|
|
|
|
|
2012-02-17 07:13:56 -08:00
|
|
|
/** This function is invoked by Gecko via JNI; be careful when modifying signature. */
|
2012-02-16 22:36:49 -08:00
|
|
|
public Rect beginDrawing(int width, int height, int tileWidth, int tileHeight,
|
|
|
|
String metadata, boolean hasDirectTexture) {
|
2012-02-03 15:48:26 -08:00
|
|
|
Log.e(LOGTAG, "### beginDrawing " + width + " " + height + " " + tileWidth + " " +
|
|
|
|
tileHeight + " " + hasDirectTexture);
|
|
|
|
|
2012-02-02 22:07:05 -08:00
|
|
|
// If we've changed surface types, cancel this draw
|
|
|
|
if (handleDirectTextureChange(hasDirectTexture)) {
|
2012-02-03 15:48:26 -08:00
|
|
|
Log.e(LOGTAG, "### Cancelling draw due to direct texture change");
|
2012-02-16 22:36:49 -08:00
|
|
|
return null;
|
2012-02-02 22:07:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!shouldDrawProceed(tileWidth, tileHeight)) {
|
2012-02-03 15:48:26 -08:00
|
|
|
Log.e(LOGTAG, "### Cancelling draw due to shouldDrawProceed()");
|
2012-02-16 22:36:49 -08:00
|
|
|
return null;
|
2012-02-02 22:07:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
JSONObject viewportObject = new JSONObject(metadata);
|
|
|
|
mNewGeckoViewport = new ViewportMetrics(viewportObject);
|
|
|
|
|
2012-02-03 23:31:05 -08:00
|
|
|
Log.e(LOGTAG, "### beginDrawing new Gecko viewport " + mNewGeckoViewport);
|
|
|
|
|
2012-02-02 22:07:05 -08:00
|
|
|
// Update the background color, if it's present.
|
|
|
|
String backgroundColorString = viewportObject.optString("backgroundColor");
|
2012-02-16 09:04:37 -08:00
|
|
|
if (backgroundColorString != null && !backgroundColorString.equals(mLastCheckerboardColor)) {
|
|
|
|
mLastCheckerboardColor = backgroundColorString;
|
2012-02-17 07:03:28 -08:00
|
|
|
mLayerController.setCheckerboardColor(parseColorFromGecko(backgroundColorString));
|
2012-02-02 22:07:05 -08:00
|
|
|
}
|
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.e(LOGTAG, "Aborting draw, bad viewport description: " + metadata);
|
2012-02-16 22:36:49 -08:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Make sure we don't spend time painting areas we aren't interested in.
|
|
|
|
// Only do this if the Gecko viewport isn't going to override our viewport.
|
|
|
|
Rect bufferRect = new Rect(0, 0, width, height);
|
|
|
|
|
|
|
|
if (!mUpdateViewportOnEndDraw) {
|
|
|
|
// First, find out our ideal displayport. We do this by taking the
|
|
|
|
// clamped viewport origin and taking away the optimum viewport offset.
|
|
|
|
// This would be what we would send to Gecko if adjustViewport were
|
|
|
|
// called now.
|
2012-02-17 07:03:28 -08:00
|
|
|
ViewportMetrics currentMetrics = mLayerController.getViewportMetrics();
|
2012-02-16 22:36:49 -08:00
|
|
|
PointF currentBestOrigin = RectUtils.getOrigin(currentMetrics.getClampedViewport());
|
|
|
|
PointF viewportOffset = currentMetrics.getOptimumViewportOffset(new IntSize(width, height));
|
|
|
|
currentBestOrigin.offset(-viewportOffset.x, -viewportOffset.y);
|
|
|
|
|
|
|
|
Rect currentRect = RectUtils.round(new RectF(currentBestOrigin.x, currentBestOrigin.y,
|
|
|
|
currentBestOrigin.x + width, currentBestOrigin.y + height));
|
|
|
|
|
|
|
|
// Second, store Gecko's displayport.
|
|
|
|
PointF currentOrigin = mNewGeckoViewport.getDisplayportOrigin();
|
|
|
|
bufferRect = RectUtils.round(new RectF(currentOrigin.x, currentOrigin.y,
|
|
|
|
currentOrigin.x + width, currentOrigin.y + height));
|
|
|
|
|
|
|
|
|
|
|
|
// Take the intersection of the two as the area we're interested in rendering.
|
|
|
|
if (!bufferRect.intersect(currentRect)) {
|
|
|
|
// If there's no intersection, we have no need to render anything,
|
|
|
|
// but make sure to update the viewport size.
|
2012-02-17 07:03:28 -08:00
|
|
|
mTileLayer.beginTransaction(mLayerController.getView());
|
2012-02-16 22:36:49 -08:00
|
|
|
try {
|
|
|
|
updateViewport(true);
|
|
|
|
} finally {
|
2012-02-17 07:03:28 -08:00
|
|
|
mTileLayer.endTransaction();
|
2012-02-16 22:36:49 -08:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
bufferRect.offset(Math.round(-currentOrigin.x), Math.round(-currentOrigin.y));
|
2012-02-02 22:07:05 -08:00
|
|
|
}
|
|
|
|
|
2012-02-17 07:03:28 -08:00
|
|
|
mTileLayer.beginTransaction(mLayerController.getView());
|
2012-02-17 07:33:23 -08:00
|
|
|
|
|
|
|
// Be sure to adjust the buffer size; if it's not at least as large as the viewport size,
|
|
|
|
// ViewportMetrics.getOptimumViewportOffset() gets awfully confused and severe display
|
|
|
|
// corruption results!
|
|
|
|
if (mBufferSize.width != width || mBufferSize.height != height) {
|
|
|
|
mBufferSize = new IntSize(width, height);
|
|
|
|
}
|
|
|
|
|
2012-02-16 22:36:49 -08:00
|
|
|
return bufferRect;
|
2012-02-02 22:07:05 -08:00
|
|
|
}
|
|
|
|
|
2012-02-17 07:13:56 -08:00
|
|
|
/** This function is invoked by Gecko via JNI; be careful when modifying signature.
|
|
|
|
*
|
2012-02-02 22:07:05 -08:00
|
|
|
* TODO: Would be cleaner if this took an android.graphics.Rect instead, but that would require
|
|
|
|
* a little more JNI magic.
|
|
|
|
*/
|
|
|
|
public void endDrawing(int x, int y, int width, int height) {
|
2012-02-17 07:03:28 -08:00
|
|
|
synchronized (mLayerController) {
|
2012-02-02 22:07:05 -08:00
|
|
|
try {
|
|
|
|
updateViewport(!mUpdateViewportOnEndDraw);
|
|
|
|
mUpdateViewportOnEndDraw = false;
|
|
|
|
|
|
|
|
Rect rect = new Rect(x, y, x + width, y + height);
|
|
|
|
updateLayerAfterDraw(rect);
|
|
|
|
} finally {
|
2012-02-17 07:03:28 -08:00
|
|
|
mTileLayer.endTransaction();
|
2012-02-02 22:07:05 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Log.i(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - endDrawing");
|
|
|
|
|
|
|
|
/* Used by robocop for testing purposes */
|
|
|
|
if (mDrawListener != null) {
|
|
|
|
mDrawListener.drawFinished(x, y, width, height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void updateViewport(boolean onlyUpdatePageSize) {
|
|
|
|
// save and restore the viewport size stored in java; never let the
|
|
|
|
// JS-side viewport dimensions override the java-side ones because
|
|
|
|
// java is the One True Source of this information, and allowing JS
|
|
|
|
// to override can lead to race conditions where this data gets clobbered.
|
2012-02-17 07:03:28 -08:00
|
|
|
FloatSize viewportSize = mLayerController.getViewportSize();
|
2012-02-02 22:07:05 -08:00
|
|
|
mGeckoViewport = mNewGeckoViewport;
|
|
|
|
mGeckoViewport.setSize(viewportSize);
|
|
|
|
|
|
|
|
PointF displayportOrigin = mGeckoViewport.getDisplayportOrigin();
|
|
|
|
mTileLayer.setOrigin(PointUtils.round(displayportOrigin));
|
|
|
|
mTileLayer.setResolution(mGeckoViewport.getZoomFactor());
|
|
|
|
|
2012-02-03 23:31:05 -08:00
|
|
|
this.tileLayerUpdated();
|
|
|
|
Log.e(LOGTAG, "### updateViewport onlyUpdatePageSize=" + onlyUpdatePageSize +
|
|
|
|
" getTileViewport " + mGeckoViewport);
|
|
|
|
|
2012-02-02 22:07:05 -08:00
|
|
|
if (onlyUpdatePageSize) {
|
|
|
|
// Don't adjust page size when zooming unless zoom levels are
|
|
|
|
// approximately equal.
|
2012-02-17 07:03:28 -08:00
|
|
|
if (FloatUtils.fuzzyEquals(mLayerController.getZoomFactor(),
|
2012-02-02 22:07:05 -08:00
|
|
|
mGeckoViewport.getZoomFactor()))
|
2012-02-17 07:03:28 -08:00
|
|
|
mLayerController.setPageSize(mGeckoViewport.getPageSize());
|
2012-02-02 22:07:05 -08:00
|
|
|
} else {
|
2012-02-17 07:03:28 -08:00
|
|
|
mLayerController.setViewportMetrics(mGeckoViewport);
|
|
|
|
mLayerController.abortPanZoomAnimation();
|
2012-02-02 22:07:05 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Informs Gecko that the screen size has changed. */
|
|
|
|
protected void sendResizeEventIfNecessary(boolean force) {
|
2012-02-03 15:48:26 -08:00
|
|
|
Log.e(LOGTAG, "### sendResizeEventIfNecessary " + force);
|
|
|
|
|
2012-02-17 07:33:23 -08:00
|
|
|
IntSize newSize = getBufferSize();
|
|
|
|
if (!force && mScreenSize != null && mScreenSize.equals(newSize)) {
|
2012-02-02 22:07:05 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-17 07:33:23 -08:00
|
|
|
mScreenSize = newSize;
|
2012-02-02 22:07:05 -08:00
|
|
|
|
2012-02-03 15:48:26 -08:00
|
|
|
Log.e(LOGTAG, "### Screen-size changed to " + mScreenSize);
|
2012-02-17 07:33:23 -08:00
|
|
|
GeckoEvent event = GeckoEvent.createSizeChangedEvent(mScreenSize.width, mScreenSize.height,
|
|
|
|
mScreenSize.width, mScreenSize.height,
|
|
|
|
mScreenSize.width, mScreenSize.height);
|
2012-02-02 22:07:05 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parses a color from an RGB triple of the form "rgb([0-9]+, [0-9]+, [0-9]+)". If the color
|
|
|
|
// cannot be parsed, returns white.
|
|
|
|
private static int parseColorFromGecko(String string) {
|
|
|
|
if (sColorPattern == null) {
|
|
|
|
sColorPattern = Pattern.compile("rgb\\((\\d+),\\s*(\\d+),\\s*(\\d+)\\)");
|
|
|
|
}
|
|
|
|
|
|
|
|
Matcher matcher = sColorPattern.matcher(string);
|
|
|
|
if (!matcher.matches()) {
|
|
|
|
return Color.WHITE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int r = Integer.parseInt(matcher.group(1));
|
|
|
|
int g = Integer.parseInt(matcher.group(2));
|
|
|
|
int b = Integer.parseInt(matcher.group(3));
|
|
|
|
return Color.rgb(r, g, b);
|
|
|
|
}
|
|
|
|
|
2012-02-17 07:33:23 -08:00
|
|
|
protected boolean handleDirectTextureChange(boolean hasDirectTexture) {
|
|
|
|
Log.e(LOGTAG, "### handleDirectTextureChange");
|
|
|
|
if (mTileLayer != null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Log.e(LOGTAG, "### Creating virtual layer");
|
|
|
|
VirtualLayer virtualLayer = new VirtualLayer();
|
|
|
|
virtualLayer.setListener(this);
|
|
|
|
virtualLayer.setSize(getBufferSize());
|
|
|
|
mLayerController.setRoot(virtualLayer);
|
|
|
|
mTileLayer = virtualLayer;
|
|
|
|
|
|
|
|
sendResizeEventIfNecessary(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean shouldDrawProceed(int tileWidth, int tileHeight) {
|
|
|
|
Log.e(LOGTAG, "### shouldDrawProceed");
|
|
|
|
// Always draw.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void updateLayerAfterDraw(Rect updatedRect) {
|
|
|
|
Log.e(LOGTAG, "### updateLayerAfterDraw");
|
|
|
|
// Nothing to do.
|
|
|
|
}
|
|
|
|
|
|
|
|
protected IntSize getBufferSize() {
|
|
|
|
View view = mLayerController.getView();
|
|
|
|
IntSize size = new IntSize(view.getWidth(), view.getHeight());
|
|
|
|
Log.e(LOGTAG, "### getBufferSize " + size);
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected IntSize getTileSize() {
|
|
|
|
Log.e(LOGTAG, "### getTileSize " + getBufferSize());
|
|
|
|
return getBufferSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void tileLayerUpdated() {
|
|
|
|
// Set the new origin and resolution instantly.
|
|
|
|
mTileLayer.performUpdates(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Bitmap getBitmap() {
|
|
|
|
Log.e(LOGTAG, "### getBitmap");
|
|
|
|
IntSize size = getBufferSize();
|
|
|
|
try {
|
|
|
|
return Bitmap.createBitmap(size.width, size.height, Bitmap.Config.RGB_565);
|
|
|
|
} catch (OutOfMemoryError oom) {
|
|
|
|
Log.e(LOGTAG, "Unable to create bitmap", oom);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-02 22:07:05 -08:00
|
|
|
public void render() {
|
|
|
|
adjustViewportWithThrottling();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void adjustViewportWithThrottling() {
|
2012-02-17 07:03:28 -08:00
|
|
|
if (!mLayerController.getRedrawHint())
|
2012-02-13 22:48:00 -08:00
|
|
|
return;
|
2012-02-02 22:07:05 -08:00
|
|
|
|
|
|
|
if (mPendingViewportAdjust)
|
|
|
|
return;
|
|
|
|
|
|
|
|
long timeDelta = System.currentTimeMillis() - mLastViewportChangeTime;
|
|
|
|
if (timeDelta < MIN_VIEWPORT_CHANGE_DELAY) {
|
2012-02-17 07:03:28 -08:00
|
|
|
mLayerController.getView().postDelayed(
|
2012-02-02 22:07:05 -08:00
|
|
|
new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
mPendingViewportAdjust = false;
|
|
|
|
adjustViewport();
|
|
|
|
}
|
|
|
|
}, MIN_VIEWPORT_CHANGE_DELAY - timeDelta);
|
|
|
|
mPendingViewportAdjust = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
adjustViewport();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void viewportSizeChanged() {
|
|
|
|
mViewportSizeChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void adjustViewport() {
|
|
|
|
ViewportMetrics viewportMetrics =
|
2012-02-17 07:03:28 -08:00
|
|
|
new ViewportMetrics(mLayerController.getViewportMetrics());
|
2012-02-02 22:07:05 -08:00
|
|
|
|
|
|
|
PointF viewportOffset = viewportMetrics.getOptimumViewportOffset(mBufferSize);
|
|
|
|
viewportMetrics.setViewportOffset(viewportOffset);
|
|
|
|
viewportMetrics.setViewport(viewportMetrics.getClampedViewport());
|
|
|
|
|
2012-02-16 18:06:54 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createViewportEvent(viewportMetrics));
|
2012-02-02 22:07:05 -08:00
|
|
|
if (mViewportSizeChanged) {
|
|
|
|
mViewportSizeChanged = false;
|
|
|
|
GeckoAppShell.viewSizeChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
mLastViewportChangeTime = System.currentTimeMillis();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void handleMessage(String event, JSONObject message) {
|
|
|
|
if ("Viewport:UpdateAndDraw".equals(event)) {
|
2012-02-03 23:31:05 -08:00
|
|
|
Log.e(LOGTAG, "### Java side Viewport:UpdateAndDraw()!");
|
2012-02-02 22:07:05 -08:00
|
|
|
mUpdateViewportOnEndDraw = true;
|
|
|
|
|
|
|
|
// Redraw everything.
|
|
|
|
Rect rect = new Rect(0, 0, mBufferSize.width, mBufferSize.height);
|
2012-02-16 18:06:54 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createDrawEvent(rect));
|
2012-02-02 22:07:05 -08:00
|
|
|
} else if ("Viewport:UpdateLater".equals(event)) {
|
2012-02-03 23:31:05 -08:00
|
|
|
Log.e(LOGTAG, "### Java side Viewport:UpdateLater()!");
|
2012-02-02 22:07:05 -08:00
|
|
|
mUpdateViewportOnEndDraw = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void geometryChanged() {
|
|
|
|
/* Let Gecko know if the screensize has changed */
|
|
|
|
sendResizeEventIfNecessary();
|
|
|
|
render();
|
|
|
|
}
|
|
|
|
|
2012-02-02 23:30:41 -08:00
|
|
|
public int getWidth() {
|
|
|
|
return mBufferSize.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getHeight() {
|
|
|
|
return mBufferSize.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ViewportMetrics getGeckoViewportMetrics() {
|
|
|
|
// Return a copy, as we modify this inside the Gecko thread
|
|
|
|
if (mGeckoViewport != null)
|
|
|
|
return new ViewportMetrics(mGeckoViewport);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-02-02 22:07:05 -08:00
|
|
|
private void sendResizeEventIfNecessary() {
|
|
|
|
sendResizeEventIfNecessary(false);
|
|
|
|
}
|
|
|
|
|
2012-02-17 07:33:23 -08:00
|
|
|
/** Implementation of FlexibleGLSurfaceView.Listener */
|
|
|
|
public void renderRequested() {
|
|
|
|
Log.e(LOGTAG, "### Render requested, scheduling composite");
|
|
|
|
GeckoAppShell.scheduleComposite();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Implementation of FlexibleGLSurfaceView.Listener */
|
|
|
|
public void compositionPauseRequested() {
|
|
|
|
Log.e(LOGTAG, "### Scheduling PauseComposition");
|
|
|
|
GeckoAppShell.schedulePauseComposition();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Implementation of FlexibleGLSurfaceView.Listener */
|
|
|
|
public void compositionResumeRequested() {
|
|
|
|
Log.e(LOGTAG, "### Scheduling ResumeComposition");
|
|
|
|
GeckoAppShell.scheduleResumeComposition();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Implementation of FlexibleGLSurfaceView.Listener */
|
|
|
|
public void surfaceChanged(int width, int height) {
|
|
|
|
compositionPauseRequested();
|
|
|
|
mLayerController.setViewportSize(new FloatSize(width, height));
|
|
|
|
compositionResumeRequested();
|
|
|
|
renderRequested();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Implementation of VirtualLayer.Listener */
|
|
|
|
public void dimensionsChanged(Point newOrigin, float newResolution) {
|
|
|
|
Log.e(LOGTAG, "### dimensionsChanged " + newOrigin + " " + newResolution);
|
|
|
|
}
|
|
|
|
|
2012-02-02 22:07:05 -08:00
|
|
|
/** Used by robocop for testing purposes. Not for production use! This is called via reflection by robocop. */
|
|
|
|
public void setDrawListener(DrawListener listener) {
|
|
|
|
mDrawListener = listener;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Used by robocop for testing purposes. Not for production use! This is used via reflection by robocop. */
|
|
|
|
public interface DrawListener {
|
|
|
|
public void drawFinished(int x, int y, int width, int height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|