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-22 11:45:44 -08:00
|
|
|
public class GeckoLayerClient implements GeckoEventListener,
|
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-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-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
|
|
|
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. */
|
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-24 07:51:41 -08:00
|
|
|
public Rect beginDrawing(int width, int height, String metadata) {
|
|
|
|
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-22 12:14:28 -08:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
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-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) {
|
2012-02-22 09:02:38 -08:00
|
|
|
// First, find out our ideal displayport. 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());
|
|
|
|
|
|
|
|
Rect currentRect = RectUtils.round(new RectF(currentBestOrigin.x, currentBestOrigin.y,
|
|
|
|
currentBestOrigin.x + width, currentBestOrigin.y + height));
|
|
|
|
|
|
|
|
// Second, store Gecko's displayport.
|
2012-02-23 12:08:05 -08:00
|
|
|
PointF currentOrigin = mNewGeckoViewport.getOrigin();
|
2012-02-16 22:36:49 -08:00
|
|
|
bufferRect = RectUtils.round(new RectF(currentOrigin.x, currentOrigin.y,
|
|
|
|
currentOrigin.x + width, currentOrigin.y + height));
|
|
|
|
|
2012-02-22 09:02:38 -08:00
|
|
|
int area = width * height;
|
2012-02-16 22:36:49 -08:00
|
|
|
|
|
|
|
// Take the intersection of the two as the area we're interested in rendering.
|
|
|
|
if (!bufferRect.intersect(currentRect)) {
|
2012-02-22 09:02:38 -08:00
|
|
|
Log.w(LOGTAG, "Prediction would avoid useless paint of " + area + " pixels (100.0%)");
|
2012-02-16 22:36:49 -08:00
|
|
|
// If there's no intersection, we have no need to render anything,
|
2012-02-23 12:31:40 -08:00
|
|
|
// but make sure to update the page size.
|
|
|
|
updateViewport(true);
|
2012-02-16 22:36:49 -08:00
|
|
|
return null;
|
|
|
|
}
|
2012-02-22 09:02:38 -08:00
|
|
|
|
|
|
|
int wasted = area - (bufferRect.width() * bufferRect.height());
|
|
|
|
Log.w(LOGTAG, "Prediction would avoid useless paint of " + wasted + " pixels (" + ((float)wasted * 100.0f / area) + "%)");
|
|
|
|
|
2012-02-16 22:36:49 -08:00
|
|
|
bufferRect.offset(Math.round(-currentOrigin.x), Math.round(-currentOrigin.y));
|
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-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-23 12:31:40 -08:00
|
|
|
updateViewport(!mUpdateViewportOnEndDraw);
|
|
|
|
mUpdateViewportOnEndDraw = false;
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-22 12:08:46 -08:00
|
|
|
private void updateViewport(boolean onlyUpdatePageSize) {
|
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);
|
|
|
|
|
|
|
|
PointF origin = mGeckoViewport.getOrigin();
|
|
|
|
mRootLayer.setOriginAndResolution(PointUtils.round(origin), mGeckoViewport.getZoomFactor());
|
|
|
|
|
|
|
|
// Set the new origin and resolution instantly.
|
|
|
|
mRootLayer.performUpdates(null);
|
|
|
|
|
|
|
|
Log.e(LOGTAG, "### updateViewport onlyUpdatePageSize=" + onlyUpdatePageSize +
|
|
|
|
" getTileViewport " + mGeckoViewport);
|
|
|
|
|
|
|
|
if (onlyUpdatePageSize) {
|
|
|
|
// Don't adjust page size when zooming unless zoom levels are
|
|
|
|
// approximately equal.
|
|
|
|
if (FloatUtils.fuzzyEquals(mLayerController.getZoomFactor(),
|
|
|
|
mGeckoViewport.getZoomFactor()))
|
|
|
|
mLayerController.setPageSize(mGeckoViewport.getPageSize());
|
|
|
|
} else {
|
|
|
|
mLayerController.setViewportMetrics(mGeckoViewport);
|
|
|
|
mLayerController.abortPanZoomAnimation();
|
2012-02-23 12:31:40 -08:00
|
|
|
}
|
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-17 09:25:52 -08:00
|
|
|
IntSize bufferSize = getBufferSize();
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-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");
|
|
|
|
VirtualLayer virtualLayer = new VirtualLayer();
|
|
|
|
virtualLayer.setSize(getBufferSize());
|
|
|
|
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-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();
|
|
|
|
}
|
|
|
|
|
2012-02-22 12:08:46 -08:00
|
|
|
/** Implementation of 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-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) {
|
|
|
|
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 {
|
|
|
|
public void drawFinished(int x, int y, int width, int height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|