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;
|
2012-02-28 13:13:20 -08:00
|
|
|
import org.mozilla.gecko.GeckoEventResponder;
|
2012-02-02 22:07:05 -08:00
|
|
|
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-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
|
|
|
|
2012-02-28 13:13:20 -08:00
|
|
|
public class GeckoLayerClient implements GeckoEventResponder,
|
2012-02-23 07:09:38 -08:00
|
|
|
FlexibleGLSurfaceView.Listener {
|
2012-02-02 22:07:05 -08:00
|
|
|
private static final String LOGTAG = "GeckoLayerClient";
|
|
|
|
|
2012-02-28 13:13:20 -08:00
|
|
|
private static final int DEFAULT_DISPLAY_PORT_MARGIN = 300;
|
|
|
|
|
2012-02-22 12:08:46 -08:00
|
|
|
private LayerController mLayerController;
|
2012-02-22 11:45:44 -08:00
|
|
|
private LayerRenderer mLayerRenderer;
|
|
|
|
private boolean mLayerRendererInitialized;
|
2012-02-17 07:03:28 -08:00
|
|
|
|
2012-02-22 12:08:46 -08:00
|
|
|
private IntSize mScreenSize;
|
|
|
|
private IntSize mWindowSize;
|
|
|
|
private IntSize mBufferSize;
|
2012-02-28 13:13:20 -08:00
|
|
|
private Rect mDisplayPortMargins;
|
2012-02-02 22:07:05 -08:00
|
|
|
|
2012-02-23 13:21:45 -08:00
|
|
|
private VirtualLayer mRootLayer;
|
2012-02-02 22:07:05 -08:00
|
|
|
|
|
|
|
/* The viewport that Gecko is currently displaying. */
|
2012-02-22 12:08:46 -08:00
|
|
|
private ViewportMetrics mGeckoViewport;
|
2012-02-02 22:07:05 -08:00
|
|
|
|
|
|
|
/* The viewport that Gecko will display when drawing is finished */
|
2012-02-22 12:08:46 -08:00
|
|
|
private ViewportMetrics mNewGeckoViewport;
|
2012-02-02 22:07:05 -08:00
|
|
|
|
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;
|
2012-02-22 12:14:28 -08:00
|
|
|
private boolean mIgnorePaintsPendingViewportSizeChange;
|
|
|
|
private boolean mFirstPaint = true;
|
2012-02-02 22:07:05 -08:00
|
|
|
|
|
|
|
// 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
|
|
|
/* Used by robocop for testing purposes */
|
|
|
|
private DrawListener mDrawListener;
|
|
|
|
|
|
|
|
public GeckoLayerClient(Context context) {
|
|
|
|
mScreenSize = new IntSize(0, 0);
|
|
|
|
mBufferSize = new IntSize(0, 0);
|
2012-02-28 13:13:20 -08:00
|
|
|
mDisplayPortMargins = new Rect(DEFAULT_DISPLAY_PORT_MARGIN,
|
|
|
|
DEFAULT_DISPLAY_PORT_MARGIN,
|
|
|
|
DEFAULT_DISPLAY_PORT_MARGIN,
|
|
|
|
DEFAULT_DISPLAY_PORT_MARGIN);
|
2012-02-02 22:07:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Attaches the root layer to the layer controller so that Gecko appears. */
|
2012-02-22 12:08:46 -08:00
|
|
|
void setLayerController(LayerController layerController) {
|
2012-02-17 07:03:28 -08:00
|
|
|
mLayerController = layerController;
|
2012-02-02 22:07:05 -08:00
|
|
|
|
2012-02-23 13:21:45 -08:00
|
|
|
layerController.setRoot(mRootLayer);
|
2012-02-02 22:07:05 -08:00
|
|
|
if (mGeckoViewport != null) {
|
|
|
|
layerController.setViewportMetrics(mGeckoViewport);
|
|
|
|
}
|
|
|
|
|
|
|
|
GeckoAppShell.registerGeckoEventListener("Viewport:UpdateAndDraw", this);
|
|
|
|
GeckoAppShell.registerGeckoEventListener("Viewport:UpdateLater", this);
|
|
|
|
|
2012-02-22 12:08:46 -08:00
|
|
|
sendResizeEventIfNecessary(false);
|
2012-02-17 07:33:23 -08:00
|
|
|
|
|
|
|
LayerView view = layerController.getView();
|
2012-02-23 08:04:11 -08:00
|
|
|
view.setListener(this);
|
|
|
|
|
2012-02-17 07:33:23 -08:00
|
|
|
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-26 07:47:45 -08:00
|
|
|
public boolean beginDrawing(int width, int height, String metadata) {
|
2012-02-24 07:51:41 -08:00
|
|
|
Log.e(LOGTAG, "### beginDrawing " + width + " " + height);
|
2012-02-03 15:48:26 -08:00
|
|
|
|
2012-02-22 12:14:28 -08:00
|
|
|
// If the viewport has changed but we still don't have the latest viewport
|
|
|
|
// from Gecko, ignore the viewport passed to us from Gecko since that is going
|
|
|
|
// to be wrong.
|
2012-02-22 14:15:53 -08:00
|
|
|
if (!mFirstPaint && mIgnorePaintsPendingViewportSizeChange) {
|
2012-02-26 07:47:45 -08:00
|
|
|
return false;
|
2012-02-22 12:14:28 -08:00
|
|
|
}
|
|
|
|
mFirstPaint = false;
|
|
|
|
|
2012-02-02 22:07:05 -08:00
|
|
|
// If we've changed surface types, cancel this draw
|
2012-02-23 11:55:15 -08:00
|
|
|
if (initializeVirtualLayer()) {
|
|
|
|
Log.e(LOGTAG, "### Cancelling draw due to virtual layer initialization");
|
2012-02-26 07:47:45 -08:00
|
|
|
return false;
|
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
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.e(LOGTAG, "Aborting draw, bad viewport description: " + metadata);
|
2012-02-26 07:47:45 -08:00
|
|
|
return false;
|
2012-02-02 22:07:05 -08:00
|
|
|
}
|
|
|
|
|
2012-02-17 07:33:23 -08:00
|
|
|
if (mBufferSize.width != width || mBufferSize.height != height) {
|
|
|
|
mBufferSize = new IntSize(width, height);
|
|
|
|
}
|
|
|
|
|
2012-02-26 07:47:45 -08:00
|
|
|
return true;
|
2012-02-02 22:07:05 -08:00
|
|
|
}
|
|
|
|
|
2012-02-24 09:11:29 -08:00
|
|
|
/** This function is invoked by Gecko via JNI; be careful when modifying signature. */
|
|
|
|
public void endDrawing() {
|
2012-02-23 13:29:22 -08:00
|
|
|
synchronized (mLayerController) {
|
|
|
|
// 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.
|
|
|
|
FloatSize viewportSize = mLayerController.getViewportSize();
|
|
|
|
mGeckoViewport = mNewGeckoViewport;
|
|
|
|
mGeckoViewport.setSize(viewportSize);
|
|
|
|
|
2012-02-26 07:47:47 -08:00
|
|
|
RectF position = mGeckoViewport.getViewport();
|
|
|
|
mRootLayer.setPositionAndResolution(RectUtils.round(position), mGeckoViewport.getZoomFactor());
|
2012-02-23 13:29:22 -08:00
|
|
|
|
2012-02-28 13:13:26 -08:00
|
|
|
Log.e(LOGTAG, "### updateViewport onlyUpdatePageSize=" + !mUpdateViewportOnEndDraw +
|
2012-02-23 13:29:22 -08:00
|
|
|
" getTileViewport " + mGeckoViewport);
|
|
|
|
|
2012-02-28 13:13:26 -08:00
|
|
|
if (mUpdateViewportOnEndDraw) {
|
|
|
|
mLayerController.setViewportMetrics(mGeckoViewport);
|
|
|
|
mLayerController.abortPanZoomAnimation();
|
|
|
|
mUpdateViewportOnEndDraw = false;
|
|
|
|
} else {
|
2012-02-23 13:29:22 -08:00
|
|
|
// Don't adjust page size when zooming unless zoom levels are
|
|
|
|
// approximately equal.
|
|
|
|
if (FloatUtils.fuzzyEquals(mLayerController.getZoomFactor(),
|
|
|
|
mGeckoViewport.getZoomFactor()))
|
|
|
|
mLayerController.setPageSize(mGeckoViewport.getPageSize());
|
2012-02-23 12:31:40 -08:00
|
|
|
}
|
2012-02-02 22:07:05 -08:00
|
|
|
}
|
2012-02-28 13:13:26 -08:00
|
|
|
|
|
|
|
Log.i(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - endDrawing");
|
|
|
|
/* Used by robocop for testing purposes */
|
|
|
|
if (mDrawListener != null) {
|
|
|
|
mDrawListener.drawFinished();
|
|
|
|
}
|
2012-02-02 22:07:05 -08:00
|
|
|
}
|
|
|
|
|
2012-02-28 13:14:14 -08:00
|
|
|
RectF getDisplayPort() {
|
|
|
|
RectF displayPort = new RectF(mRootLayer.getPosition());
|
|
|
|
displayPort.left -= mDisplayPortMargins.left;
|
|
|
|
displayPort.top -= mDisplayPortMargins.top;
|
|
|
|
displayPort.right += mDisplayPortMargins.right;
|
|
|
|
displayPort.bottom += mDisplayPortMargins.bottom;
|
|
|
|
return displayPort;
|
|
|
|
}
|
|
|
|
|
2012-02-02 22:07:05 -08:00
|
|
|
/* Informs Gecko that the screen size has changed. */
|
2012-02-22 12:08:46 -08:00
|
|
|
private void sendResizeEventIfNecessary(boolean force) {
|
2012-02-17 09:25:52 -08:00
|
|
|
Log.d(LOGTAG, "### sendResizeEventIfNecessary " + force);
|
2012-02-03 15:48:26 -08:00
|
|
|
|
2012-02-17 09:25:52 -08:00
|
|
|
DisplayMetrics metrics = new DisplayMetrics();
|
|
|
|
GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
|
|
|
|
|
|
|
IntSize newScreenSize = new IntSize(metrics.widthPixels, metrics.heightPixels);
|
|
|
|
IntSize newWindowSize = getBufferSize();
|
|
|
|
|
|
|
|
boolean screenSizeChanged = mScreenSize == null || !mScreenSize.equals(newScreenSize);
|
|
|
|
boolean windowSizeChanged = mWindowSize == null || !mWindowSize.equals(newWindowSize);
|
|
|
|
|
|
|
|
if (!force && !screenSizeChanged && !windowSizeChanged) {
|
2012-02-02 22:07:05 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-17 09:25:52 -08:00
|
|
|
mScreenSize = newScreenSize;
|
|
|
|
mWindowSize = newWindowSize;
|
|
|
|
|
|
|
|
if (screenSizeChanged) {
|
|
|
|
Log.i(LOGTAG, "### Screen-size changed to " + mScreenSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (windowSizeChanged) {
|
|
|
|
Log.i(LOGTAG, "### Window-size changed to " + mWindowSize);
|
|
|
|
}
|
2012-02-02 22:07:05 -08:00
|
|
|
|
2012-02-24 07:51:41 -08:00
|
|
|
GeckoEvent event = GeckoEvent.createSizeChangedEvent(mWindowSize.width, mWindowSize.height, // Window (buffer) size
|
|
|
|
mScreenSize.width, mScreenSize.height); // Screen size
|
2012-02-02 22:07:05 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(event);
|
|
|
|
}
|
|
|
|
|
2012-02-23 11:55:15 -08:00
|
|
|
private boolean initializeVirtualLayer() {
|
2012-02-23 13:21:45 -08:00
|
|
|
if (mRootLayer != null) {
|
2012-02-17 07:33:23 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Log.e(LOGTAG, "### Creating virtual layer");
|
2012-02-26 07:47:47 -08:00
|
|
|
VirtualLayer virtualLayer = new VirtualLayer(getBufferSize());
|
2012-02-17 07:33:23 -08:00
|
|
|
mLayerController.setRoot(virtualLayer);
|
2012-02-23 13:21:45 -08:00
|
|
|
mRootLayer = virtualLayer;
|
2012-02-17 07:33:23 -08:00
|
|
|
|
|
|
|
sendResizeEventIfNecessary(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-02-22 12:08:46 -08:00
|
|
|
private IntSize getBufferSize() {
|
2012-02-17 07:33:23 -08:00
|
|
|
View view = mLayerController.getView();
|
|
|
|
IntSize size = new IntSize(view.getWidth(), view.getHeight());
|
|
|
|
Log.e(LOGTAG, "### getBufferSize " + size);
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Bitmap getBitmap() {
|
2012-02-20 22:22:56 -08:00
|
|
|
return null;
|
2012-02-17 07:33:23 -08:00
|
|
|
}
|
|
|
|
|
2012-02-02 22:07:05 -08:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2012-02-22 12:08:46 -08:00
|
|
|
void viewportSizeChanged() {
|
2012-02-02 22:07:05 -08:00
|
|
|
mViewportSizeChanged = true;
|
2012-02-22 12:14:28 -08:00
|
|
|
mIgnorePaintsPendingViewportSizeChange = true;
|
2012-02-02 22:07:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
viewportMetrics.setViewport(viewportMetrics.getClampedViewport());
|
|
|
|
|
2012-02-28 13:13:20 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createViewportEvent(viewportMetrics, mDisplayPortMargins));
|
2012-02-02 22:07:05 -08:00
|
|
|
if (mViewportSizeChanged) {
|
|
|
|
mViewportSizeChanged = false;
|
|
|
|
GeckoAppShell.viewSizeChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
mLastViewportChangeTime = System.currentTimeMillis();
|
|
|
|
}
|
|
|
|
|
2012-02-28 13:13:20 -08:00
|
|
|
/** Implementation of GeckoEventResponder/GeckoEventListener. */
|
2012-02-02 22:07:05 -08:00
|
|
|
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;
|
2012-02-22 12:14:28 -08:00
|
|
|
mIgnorePaintsPendingViewportSizeChange = false;
|
2012-02-02 22:07:05 -08:00
|
|
|
|
|
|
|
// 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;
|
2012-02-22 12:14:28 -08:00
|
|
|
mIgnorePaintsPendingViewportSizeChange = false;
|
2012-02-02 22:07:05 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-28 13:13:20 -08:00
|
|
|
/** Implementation of GeckoEventResponder. */
|
|
|
|
public String getResponse() {
|
|
|
|
// We are responding to the events handled in handleMessage() above with
|
|
|
|
// the display port margins we want. Note that both messages we are currently
|
|
|
|
// handling (Viewport:UpdateAndDraw and Viewport:UpdateLater) require this
|
|
|
|
// response, so we can just return this indiscriminately.
|
|
|
|
return RectUtils.toJSON(mDisplayPortMargins);
|
|
|
|
}
|
|
|
|
|
2012-02-22 12:08:46 -08:00
|
|
|
void geometryChanged() {
|
2012-02-02 22:07:05 -08:00
|
|
|
/* Let Gecko know if the screensize has changed */
|
2012-02-22 12:08:46 -08:00
|
|
|
sendResizeEventIfNecessary(false);
|
|
|
|
adjustViewportWithThrottling();
|
2012-02-02 22:07:05 -08:00
|
|
|
}
|
|
|
|
|
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-22 11:45:44 -08:00
|
|
|
/** This function is invoked by Gecko via JNI; be careful when modifying signature. */
|
|
|
|
public ViewTransform getViewTransform() {
|
|
|
|
Log.e(LOGTAG, "### getViewTransform()");
|
|
|
|
|
|
|
|
// NB: We don't begin a transaction here because this can be called in a synchronous
|
|
|
|
// manner between beginDrawing() and endDrawing(), and that will cause a deadlock.
|
|
|
|
|
|
|
|
synchronized (mLayerController) {
|
|
|
|
ViewportMetrics viewportMetrics = mLayerController.getViewportMetrics();
|
|
|
|
PointF viewportOrigin = viewportMetrics.getOrigin();
|
|
|
|
float scrollX = viewportOrigin.x;
|
|
|
|
float scrollY = viewportOrigin.y;
|
|
|
|
float zoomFactor = viewportMetrics.getZoomFactor();
|
|
|
|
Log.e(LOGTAG, "### Viewport metrics = " + viewportMetrics + " tile reso = " +
|
2012-02-23 13:21:45 -08:00
|
|
|
mRootLayer.getResolution());
|
2012-02-22 11:45:44 -08:00
|
|
|
return new ViewTransform(scrollX, scrollY, zoomFactor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** This function is invoked by Gecko via JNI; be careful when modifying signature. */
|
|
|
|
public LayerRenderer.Frame createFrame() {
|
|
|
|
// Create the shaders and textures if necessary.
|
|
|
|
if (!mLayerRendererInitialized) {
|
2012-02-29 11:08:23 -08:00
|
|
|
mLayerRenderer.checkMonitoringEnabled();
|
2012-02-22 11:45:44 -08:00
|
|
|
mLayerRenderer.createProgram();
|
|
|
|
mLayerRendererInitialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the contexts and create the frame.
|
|
|
|
Layer.RenderContext pageContext = mLayerRenderer.createPageContext();
|
|
|
|
Layer.RenderContext screenContext = mLayerRenderer.createScreenContext();
|
|
|
|
return mLayerRenderer.createFrame(pageContext, screenContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** This function is invoked by Gecko via JNI; be careful when modifying signature. */
|
|
|
|
public void activateProgram() {
|
|
|
|
mLayerRenderer.activateProgram();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** This function is invoked by Gecko via JNI; be careful when modifying signature. */
|
|
|
|
public void deactivateProgram() {
|
|
|
|
mLayerRenderer.deactivateProgram();
|
|
|
|
}
|
2012-02-22 12:08:46 -08:00
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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 {
|
2012-02-24 09:11:29 -08:00
|
|
|
public void drawFinished();
|
2012-02-02 22:07:05 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|