2012-02-02 22:07:05 -08:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* 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/. */
|
2012-02-02 22:07:05 -08:00
|
|
|
|
|
|
|
package org.mozilla.gecko.gfx;
|
|
|
|
|
|
|
|
import org.mozilla.gecko.GeckoAppShell;
|
|
|
|
import org.mozilla.gecko.GeckoEvent;
|
2012-02-28 13:13:20 -08:00
|
|
|
import org.mozilla.gecko.GeckoEventResponder;
|
2012-05-18 08:24:27 -07:00
|
|
|
import org.mozilla.gecko.Tab;
|
2012-04-24 12:13:36 -07:00
|
|
|
import org.mozilla.gecko.Tabs;
|
2012-03-30 06:57:39 -07:00
|
|
|
import org.json.JSONArray;
|
2012-02-02 22:07:05 -08:00
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import android.content.Context;
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
import android.graphics.Bitmap;
|
2012-02-02 22:07:05 -08:00
|
|
|
import android.graphics.PointF;
|
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;
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
import android.view.View;
|
2012-04-13 07:28:10 -07:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.HashMap;
|
2012-02-02 22:07:05 -08:00
|
|
|
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
public class GeckoLayerClient implements GeckoEventResponder,
|
|
|
|
LayerView.Listener {
|
2012-02-02 22:07:05 -08:00
|
|
|
private static final String LOGTAG = "GeckoLayerClient";
|
|
|
|
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07: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-07-27 23:13:34 -07:00
|
|
|
private Context mContext;
|
2012-02-22 12:08:46 -08:00
|
|
|
private IntSize mScreenSize;
|
|
|
|
private IntSize mWindowSize;
|
2012-03-26 10:15:49 -07:00
|
|
|
private DisplayPortMetrics mDisplayPort;
|
|
|
|
private DisplayPortMetrics mReturnDisplayPort;
|
2012-02-02 22:07:05 -08:00
|
|
|
|
2012-04-25 06:53:38 -07:00
|
|
|
private boolean mRecordDrawTimes;
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
private DrawTimingQueue mDrawTimingQueue;
|
2012-04-25 06:53:38 -07:00
|
|
|
|
2012-02-23 13:21:45 -08:00
|
|
|
private VirtualLayer mRootLayer;
|
2012-02-02 22:07:05 -08:00
|
|
|
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
/* The Gecko viewport as per the UI thread. Must be touched only on the UI thread. */
|
2012-02-22 12:08:46 -08:00
|
|
|
private ViewportMetrics mGeckoViewport;
|
2012-02-02 22:07:05 -08:00
|
|
|
|
2012-03-17 08:08:22 -07:00
|
|
|
/*
|
|
|
|
* The viewport metrics being used to draw the current frame. This is only
|
|
|
|
* accessed by the compositor thread, and so needs no synchronisation.
|
|
|
|
*/
|
|
|
|
private ImmutableViewportMetrics mFrameMetrics;
|
|
|
|
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
private String mLastCheckerboardColor;
|
|
|
|
|
2012-02-02 22:07:05 -08:00
|
|
|
/* Used by robocop for testing purposes */
|
|
|
|
private DrawListener mDrawListener;
|
|
|
|
|
2012-03-17 08:08:22 -07:00
|
|
|
/* Used as a temporary ViewTransform by syncViewportInfo */
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
private ViewTransform mCurrentViewTransform;
|
2012-03-02 11:31:27 -08:00
|
|
|
|
2012-07-06 06:48:25 -07:00
|
|
|
/* This is written by the compositor thread and read by the UI thread. */
|
|
|
|
private volatile boolean mCompositorCreated;
|
|
|
|
|
2012-02-02 22:07:05 -08:00
|
|
|
public GeckoLayerClient(Context context) {
|
2012-03-12 09:03:38 -07:00
|
|
|
// we can fill these in with dummy values because they are always written
|
|
|
|
// to before being read
|
2012-07-27 23:13:34 -07:00
|
|
|
mContext = context;
|
2012-02-02 22:07:05 -08:00
|
|
|
mScreenSize = new IntSize(0, 0);
|
2012-03-12 13:20:19 -07:00
|
|
|
mWindowSize = new IntSize(0, 0);
|
2012-03-26 10:15:49 -07:00
|
|
|
mDisplayPort = new DisplayPortMetrics();
|
2012-04-25 06:53:38 -07:00
|
|
|
mRecordDrawTimes = true;
|
|
|
|
mDrawTimingQueue = new DrawTimingQueue();
|
2012-03-02 11:31:27 -08:00
|
|
|
mCurrentViewTransform = new ViewTransform(0, 0, 1);
|
2012-07-06 06:48:25 -07:00
|
|
|
|
|
|
|
mCompositorCreated = false;
|
2012-02-02 22:07:05 -08:00
|
|
|
}
|
|
|
|
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
/** Attaches the root layer to the layer controller so that Gecko appears. */
|
|
|
|
void setLayerController(LayerController layerController) {
|
|
|
|
LayerView view = layerController.getView();
|
2012-03-12 13:20:19 -07:00
|
|
|
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
mLayerController = layerController;
|
2012-02-02 22:07:05 -08:00
|
|
|
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
mRootLayer = new VirtualLayer(new IntSize(view.getWidth(), view.getHeight()));
|
|
|
|
mLayerRenderer = new LayerRenderer(view);
|
2012-02-02 22:07:05 -08:00
|
|
|
|
2012-03-12 09:03:37 -07:00
|
|
|
GeckoAppShell.registerGeckoEventListener("Viewport:Update", this);
|
2012-03-21 07:44:33 -07:00
|
|
|
GeckoAppShell.registerGeckoEventListener("Viewport:PageSize", this);
|
2012-03-15 07:38:43 -07:00
|
|
|
GeckoAppShell.registerGeckoEventListener("Viewport:CalculateDisplayPort", this);
|
2012-03-18 10:26:54 -07:00
|
|
|
GeckoAppShell.registerGeckoEventListener("Checkerboard:Toggle", this);
|
2012-03-30 06:57:39 -07:00
|
|
|
GeckoAppShell.registerGeckoEventListener("Preferences:Data", this);
|
2012-02-02 22:07:05 -08:00
|
|
|
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
view.setListener(this);
|
|
|
|
view.setLayerRenderer(mLayerRenderer);
|
|
|
|
layerController.setRoot(mRootLayer);
|
2012-02-23 08:04:11 -08:00
|
|
|
|
2012-03-12 13:20:19 -07:00
|
|
|
sendResizeEventIfNecessary(true);
|
2012-04-13 07:28:10 -07:00
|
|
|
|
|
|
|
JSONArray prefs = new JSONArray();
|
|
|
|
DisplayPortCalculator.addPrefNames(prefs);
|
2012-04-27 13:04:47 -07:00
|
|
|
PluginLayer.addPrefNames(prefs);
|
2012-04-13 07:28:10 -07:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Preferences:Get", prefs.toString()));
|
2012-02-02 22:07:05 -08:00
|
|
|
}
|
|
|
|
|
2012-07-13 07:17:03 -07:00
|
|
|
public void destroy() {
|
|
|
|
GeckoAppShell.unregisterGeckoEventListener("Viewport:Update", this);
|
|
|
|
GeckoAppShell.unregisterGeckoEventListener("Viewport:PageSize", this);
|
|
|
|
GeckoAppShell.unregisterGeckoEventListener("Viewport:CalculateDisplayPort", this);
|
|
|
|
GeckoAppShell.unregisterGeckoEventListener("Checkerboard:Toggle", this);
|
|
|
|
GeckoAppShell.unregisterGeckoEventListener("Preferences:Data", this);
|
|
|
|
}
|
|
|
|
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
DisplayPortMetrics getDisplayPort() {
|
|
|
|
return mDisplayPort;
|
2012-08-01 07:48:19 -07: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-07-27 23:13:34 -07:00
|
|
|
DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
View view = mLayerController.getView();
|
2012-02-17 09:25:52 -08:00
|
|
|
|
|
|
|
IntSize newScreenSize = new IntSize(metrics.widthPixels, metrics.heightPixels);
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
IntSize newWindowSize = new IntSize(view.getWidth(), view.getHeight());
|
2012-02-17 09:25:52 -08:00
|
|
|
|
2012-03-12 13:20:19 -07:00
|
|
|
boolean screenSizeChanged = !mScreenSize.equals(newScreenSize);
|
|
|
|
boolean windowSizeChanged = !mWindowSize.equals(newWindowSize);
|
2012-02-17 09:25:52 -08:00
|
|
|
|
|
|
|
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) {
|
2012-03-12 13:20:19 -07:00
|
|
|
Log.d(LOGTAG, "Screen-size changed to " + mScreenSize);
|
2012-02-17 09:25:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (windowSizeChanged) {
|
2012-03-12 13:20:19 -07:00
|
|
|
Log.d(LOGTAG, "Window-size changed to " + mWindowSize);
|
2012-02-17 09:25:52 -08:00
|
|
|
}
|
2012-02-02 22:07:05 -08:00
|
|
|
|
2012-03-12 13:20:19 -07:00
|
|
|
GeckoEvent event = GeckoEvent.createSizeChangedEvent(mWindowSize.width, mWindowSize.height,
|
|
|
|
mScreenSize.width, mScreenSize.height);
|
2012-02-02 22:07:05 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(event);
|
2012-06-14 07:59:28 -07:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Window:Resize", ""));
|
2012-02-02 22:07:05 -08:00
|
|
|
}
|
|
|
|
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
public Bitmap getBitmap() {
|
|
|
|
return null;
|
|
|
|
}
|
2012-08-01 07:48:19 -07:00
|
|
|
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
void viewportSizeChanged() {
|
|
|
|
// here we send gecko a resize message. The code in browser.js is responsible for
|
|
|
|
// picking up on that resize event, modifying the viewport as necessary, and informing
|
|
|
|
// us of the new viewport.
|
|
|
|
sendResizeEventIfNecessary(true);
|
|
|
|
// the following call also sends gecko a message, which will be processed after the resize
|
|
|
|
// message above has updated the viewport. this message ensures that if we have just put
|
|
|
|
// focus in a text field, we scroll the content so that the text field is in view.
|
|
|
|
GeckoAppShell.viewSizeChanged();
|
2012-08-01 07:48:19 -07:00
|
|
|
}
|
|
|
|
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
void adjustViewport(DisplayPortMetrics displayPort) {
|
|
|
|
ImmutableViewportMetrics metrics = mLayerController.getViewportMetrics();
|
2012-02-02 22:07:05 -08:00
|
|
|
|
2012-04-02 14:14:33 -07:00
|
|
|
ViewportMetrics clampedMetrics = new ViewportMetrics(metrics);
|
|
|
|
clampedMetrics.setViewport(clampedMetrics.getClampedViewport());
|
2012-02-02 22:07:05 -08:00
|
|
|
|
2012-04-02 14:14:33 -07:00
|
|
|
if (displayPort == null) {
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
displayPort = DisplayPortCalculator.calculate(metrics,
|
|
|
|
mLayerController.getPanZoomController().getVelocityVector());
|
2012-04-02 14:14:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mDisplayPort = displayPort;
|
|
|
|
mGeckoViewport = clampedMetrics;
|
|
|
|
|
2012-04-25 06:53:38 -07:00
|
|
|
if (mRecordDrawTimes) {
|
|
|
|
mDrawTimingQueue.add(displayPort);
|
|
|
|
}
|
|
|
|
|
2012-04-02 14:14:33 -07:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createViewportEvent(clampedMetrics, displayPort));
|
2012-02-02 22:07:05 -08:00
|
|
|
}
|
|
|
|
|
2012-03-21 07:44:33 -07:00
|
|
|
/**
|
|
|
|
* The different types of Viewport messages handled. All viewport events
|
|
|
|
* expect a display-port to be returned, but can handle one not being
|
|
|
|
* returned.
|
|
|
|
*/
|
|
|
|
private enum ViewportMessageType {
|
|
|
|
UPDATE, // The viewport has changed and should be entirely updated
|
|
|
|
PAGE_SIZE // The viewport's page-size has changed
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Viewport message handler. */
|
|
|
|
private void handleViewportMessage(JSONObject message, ViewportMessageType type) throws JSONException {
|
|
|
|
ViewportMetrics messageMetrics = new ViewportMetrics(message);
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
synchronized (mLayerController) {
|
2012-03-21 07:44:33 -07:00
|
|
|
final ViewportMetrics newMetrics;
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
ImmutableViewportMetrics oldMetrics = mLayerController.getViewportMetrics();
|
2012-03-21 07:44:33 -07:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
default:
|
|
|
|
case UPDATE:
|
|
|
|
newMetrics = messageMetrics;
|
|
|
|
// Keep the old viewport size
|
|
|
|
newMetrics.setSize(oldMetrics.getSize());
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
mLayerController.abortPanZoomAnimation();
|
2012-03-21 07:44:33 -07:00
|
|
|
break;
|
|
|
|
case PAGE_SIZE:
|
2012-04-01 11:30:35 -07:00
|
|
|
// adjust the page dimensions to account for differences in zoom
|
|
|
|
// between the rendered content (which is what Gecko tells us)
|
|
|
|
// and our zoom level (which may have diverged).
|
|
|
|
float scaleFactor = oldMetrics.zoomFactor / messageMetrics.getZoomFactor();
|
2012-03-21 07:44:33 -07:00
|
|
|
newMetrics = new ViewportMetrics(oldMetrics);
|
2012-05-23 07:49:52 -07:00
|
|
|
newMetrics.setPageRect(RectUtils.scale(messageMetrics.getPageRect(), scaleFactor), messageMetrics.getCssPageRect());
|
2012-03-21 07:44:33 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
mLayerController.post(new Runnable() {
|
2012-03-21 07:44:33 -07:00
|
|
|
public void run() {
|
|
|
|
mGeckoViewport = newMetrics;
|
|
|
|
}
|
|
|
|
});
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
mLayerController.setViewportMetrics(newMetrics);
|
|
|
|
mDisplayPort = DisplayPortCalculator.calculate(mLayerController.getViewportMetrics(), null);
|
2012-03-21 07:44:33 -07:00
|
|
|
}
|
|
|
|
mReturnDisplayPort = mDisplayPort;
|
|
|
|
}
|
|
|
|
|
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) {
|
2012-03-15 07:38:43 -07:00
|
|
|
try {
|
|
|
|
if ("Viewport:Update".equals(event)) {
|
2012-03-21 07:44:33 -07:00
|
|
|
handleViewportMessage(message, ViewportMessageType.UPDATE);
|
|
|
|
} else if ("Viewport:PageSize".equals(event)) {
|
|
|
|
handleViewportMessage(message, ViewportMessageType.PAGE_SIZE);
|
2012-03-15 07:38:43 -07:00
|
|
|
} else if ("Viewport:CalculateDisplayPort".equals(event)) {
|
|
|
|
ImmutableViewportMetrics newMetrics = new ImmutableViewportMetrics(new ViewportMetrics(message));
|
2012-03-26 10:15:50 -07:00
|
|
|
mReturnDisplayPort = DisplayPortCalculator.calculate(newMetrics, null);
|
2012-03-18 10:26:54 -07:00
|
|
|
} else if ("Checkerboard:Toggle".equals(event)) {
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
boolean showChecks = message.getBoolean("value");
|
|
|
|
mLayerController.setCheckerboardShowChecks(showChecks);
|
|
|
|
Log.i(LOGTAG, "Showing checks: " + showChecks);
|
2012-03-30 06:57:39 -07:00
|
|
|
} else if ("Preferences:Data".equals(event)) {
|
|
|
|
JSONArray jsonPrefs = message.getJSONArray("preferences");
|
2012-04-13 07:28:10 -07:00
|
|
|
Map<String, Integer> prefValues = new HashMap<String, Integer>();
|
2012-03-30 06:57:39 -07:00
|
|
|
for (int i = jsonPrefs.length() - 1; i >= 0; i--) {
|
|
|
|
JSONObject pref = jsonPrefs.getJSONObject(i);
|
2012-04-17 08:33:19 -07:00
|
|
|
String name = pref.getString("name");
|
|
|
|
try {
|
|
|
|
prefValues.put(name, pref.getInt("value"));
|
|
|
|
} catch (JSONException je) {
|
|
|
|
// the pref value couldn't be parsed as an int. drop this pref
|
|
|
|
// and continue with the rest
|
|
|
|
}
|
2012-04-13 07:28:10 -07:00
|
|
|
}
|
2012-04-13 07:29:14 -07:00
|
|
|
// check return value from setStrategy to make sure that this is the
|
|
|
|
// right batch of prefs, since other java code may also have sent requests
|
|
|
|
// for prefs.
|
2012-04-27 13:04:47 -07:00
|
|
|
if (DisplayPortCalculator.setStrategy(prefValues) && PluginLayer.setUsePlaceholder(prefValues)) {
|
2012-04-13 07:28:10 -07:00
|
|
|
GeckoAppShell.unregisterGeckoEventListener("Preferences:Data", this);
|
2012-03-18 10:26:54 -07:00
|
|
|
}
|
2012-03-12 09:03:38 -07:00
|
|
|
}
|
2012-03-15 07:38:43 -07:00
|
|
|
} catch (JSONException e) {
|
2012-03-30 06:57:39 -07:00
|
|
|
Log.e(LOGTAG, "Error decoding JSON in " + event + " handler", e);
|
2012-02-02 22:07:05 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-28 13:13:20 -08:00
|
|
|
/** Implementation of GeckoEventResponder. */
|
|
|
|
public String getResponse() {
|
2012-03-12 09:03:38 -07:00
|
|
|
// We are responding to the events handled in handleMessage() above with the
|
2012-03-15 07:38:43 -07:00
|
|
|
// display port we calculated. Different messages will generate different
|
|
|
|
// display ports and put them in mReturnDisplayPort, so we just return that.
|
|
|
|
// Note that mReturnDisplayPort is always touched on the Gecko thread, so
|
|
|
|
// no synchronization is needed for it.
|
|
|
|
if (mReturnDisplayPort == null) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
try {
|
2012-03-26 10:15:49 -07:00
|
|
|
return mReturnDisplayPort.toJSON();
|
2012-03-15 07:38:43 -07:00
|
|
|
} finally {
|
|
|
|
mReturnDisplayPort = null;
|
|
|
|
}
|
2012-02-28 13:13:20 -08:00
|
|
|
}
|
|
|
|
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
void geometryChanged() {
|
|
|
|
/* Let Gecko know if the screensize has changed */
|
|
|
|
sendResizeEventIfNecessary(false);
|
|
|
|
if (mLayerController.getRedrawHint())
|
|
|
|
adjustViewport(null);
|
2012-08-01 07:48:19 -07:00
|
|
|
}
|
|
|
|
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
/*
|
|
|
|
* This function returns the last viewport that we sent to Gecko. If any additional events are
|
|
|
|
* being sent to Gecko that are relative on the Gecko viewport position, they must (a) be relative
|
|
|
|
* to this viewport, and (b) be sent on the UI thread to avoid races. As long as these two
|
|
|
|
* conditions are satisfied, and the events being sent to Gecko are processed in FIFO order, the
|
|
|
|
* events will properly be relative to the Gecko viewport position. Note that if Gecko updates
|
|
|
|
* its viewport independently, we get notified synchronously and also update this on the UI thread.
|
|
|
|
*/
|
|
|
|
public ViewportMetrics getGeckoViewportMetrics() {
|
|
|
|
return mGeckoViewport;
|
2012-08-01 07:48:19 -07:00
|
|
|
}
|
|
|
|
|
2012-03-12 13:20:19 -07:00
|
|
|
/** This function is invoked by Gecko via JNI; be careful when modifying signature.
|
|
|
|
* The compositor invokes this function just before compositing a frame where the document
|
|
|
|
* is different from the document composited on the last frame. In these cases, the viewport
|
|
|
|
* information we have in Java is no longer valid and needs to be replaced with the new
|
2012-05-23 07:51:39 -07:00
|
|
|
* viewport information provided. setPageRect will never be invoked on the same frame that
|
2012-03-17 08:08:22 -07:00
|
|
|
* this function is invoked on; and this function will always be called prior to syncViewportInfo.
|
2012-03-12 13:20:19 -07:00
|
|
|
*/
|
2012-05-23 07:51:39 -07:00
|
|
|
public void setFirstPaintViewport(float offsetX, float offsetY, float zoom,
|
|
|
|
float pageLeft, float pageTop, float pageRight, float pageBottom,
|
|
|
|
float cssPageLeft, float cssPageTop, float cssPageRight, float cssPageBottom) {
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
synchronized (mLayerController) {
|
|
|
|
final ViewportMetrics currentMetrics = new ViewportMetrics(mLayerController.getViewportMetrics());
|
2012-03-12 08:50:21 -07:00
|
|
|
currentMetrics.setOrigin(new PointF(offsetX, offsetY));
|
|
|
|
currentMetrics.setZoomFactor(zoom);
|
2012-05-23 07:51:39 -07:00
|
|
|
currentMetrics.setPageRect(new RectF(pageLeft, pageTop, pageRight, pageBottom),
|
|
|
|
new RectF(cssPageLeft, cssPageTop, cssPageRight, cssPageBottom));
|
2012-05-08 10:33:48 -07:00
|
|
|
// Since we have switched to displaying a different document, we need to update any
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
// viewport-related state we have lying around. This includes mGeckoViewport and the
|
|
|
|
// viewport in mLayerController. Usually this information is updated via handleViewportMessage
|
2012-05-08 10:33:48 -07:00
|
|
|
// while we remain on the same document.
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
mLayerController.post(new Runnable() {
|
2012-05-08 10:33:48 -07:00
|
|
|
public void run() {
|
|
|
|
mGeckoViewport = currentMetrics;
|
|
|
|
}
|
|
|
|
});
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
mLayerController.setViewportMetrics(currentMetrics);
|
2012-05-18 08:24:27 -07:00
|
|
|
|
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
mLayerController.setCheckerboardColor(tab.getCheckerboardColor());
|
|
|
|
mLayerController.setAllowZoom(tab.getAllowZoom());
|
|
|
|
mLayerController.setDefaultZoom(tab.getDefaultZoom());
|
|
|
|
mLayerController.setMinZoom(tab.getMinZoom());
|
|
|
|
mLayerController.setMaxZoom(tab.getMaxZoom());
|
2012-05-18 08:24:27 -07:00
|
|
|
|
2012-03-12 09:03:38 -07:00
|
|
|
// At this point, we have just switched to displaying a different document than we
|
|
|
|
// we previously displaying. This means we need to abort any panning/zooming animations
|
|
|
|
// that are in progress and send an updated display port request to browser.js as soon
|
|
|
|
// as possible. We accomplish this by passing true to abortPanZoomAnimation, which
|
|
|
|
// sends the request after aborting the animation. The display port request is actually
|
|
|
|
// a full viewport update, which is fine because if browser.js has somehow moved to
|
|
|
|
// be out of sync with this first-paint viewport, then we force them back in sync.
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
mLayerController.abortPanZoomAnimation();
|
|
|
|
mLayerController.getView().setPaintState(LayerView.PAINT_BEFORE_FIRST);
|
2012-03-12 08:50:21 -07:00
|
|
|
}
|
2012-04-25 06:53:38 -07:00
|
|
|
DisplayPortCalculator.resetPageState();
|
|
|
|
mDrawTimingQueue.reset();
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
mLayerController.getView().getRenderer().resetCheckerboard();
|
2012-04-24 12:13:36 -07:00
|
|
|
GeckoAppShell.screenshotWholePage(Tabs.getInstance().getSelectedTab());
|
2012-03-12 08:50:21 -07:00
|
|
|
}
|
|
|
|
|
2012-03-12 13:20:19 -07:00
|
|
|
/** This function is invoked by Gecko via JNI; be careful when modifying signature.
|
2012-05-23 07:51:39 -07:00
|
|
|
* The compositor invokes this function whenever it determines that the page rect
|
2012-03-12 13:20:19 -07:00
|
|
|
* has changed (based on the information it gets from layout). If setFirstPaintViewport
|
|
|
|
* is invoked on a frame, then this function will not be. For any given frame, this
|
2012-03-17 08:08:22 -07:00
|
|
|
* function will be invoked before syncViewportInfo.
|
2012-03-12 13:20:19 -07:00
|
|
|
*/
|
2012-06-13 10:49:40 -07:00
|
|
|
public void setPageRect(float cssPageLeft, float cssPageTop, float cssPageRight, float cssPageBottom) {
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
synchronized (mLayerController) {
|
2012-05-23 07:51:39 -07:00
|
|
|
RectF cssPageRect = new RectF(cssPageLeft, cssPageTop, cssPageRight, cssPageBottom);
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
float ourZoom = mLayerController.getZoomFactor();
|
|
|
|
mLayerController.setPageRect(RectUtils.scale(cssPageRect, ourZoom), cssPageRect);
|
2012-03-12 09:03:38 -07:00
|
|
|
// Here the page size of the document has changed, but the document being displayed
|
|
|
|
// is still the same. Therefore, we don't need to send anything to browser.js; any
|
|
|
|
// changes we need to make to the display port will get sent the next time we call
|
|
|
|
// adjustViewport().
|
2012-03-12 08:50:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-12 13:20:19 -07:00
|
|
|
/** This function is invoked by Gecko via JNI; be careful when modifying signature.
|
|
|
|
* The compositor invokes this function on every frame to figure out what part of the
|
2012-03-17 08:08:22 -07:00
|
|
|
* page to display, and to inform Java of the current display port. Since it is called
|
|
|
|
* on every frame, it needs to be ultra-fast.
|
2012-03-12 13:20:19 -07:00
|
|
|
* It avoids taking any locks or allocating any objects. We keep around a
|
|
|
|
* mCurrentViewTransform so we don't need to allocate a new ViewTransform
|
|
|
|
* everytime we're called. NOTE: we might be able to return a ImmutableViewportMetrics
|
|
|
|
* which would avoid the copy into mCurrentViewTransform.
|
|
|
|
*/
|
2012-03-19 21:06:56 -07:00
|
|
|
public ViewTransform syncViewportInfo(int x, int y, int width, int height, float resolution, boolean layersUpdated) {
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
// getViewportMetrics is thread safe so we don't need to synchronize
|
|
|
|
// on mLayerController.
|
2012-03-17 08:08:22 -07:00
|
|
|
// We save the viewport metrics here, so we later use it later in
|
|
|
|
// createFrame (which will be called by nsWindow::DrawWindowUnderlay on
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
// the native side, by the compositor). The LayerController's viewport
|
2012-03-17 08:08:22 -07:00
|
|
|
// metrics can change between here and there, as it's accessed outside
|
|
|
|
// of the compositor thread.
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
mFrameMetrics = mLayerController.getViewportMetrics();
|
2012-03-17 08:08:22 -07:00
|
|
|
|
|
|
|
mCurrentViewTransform.x = mFrameMetrics.viewportRectLeft;
|
|
|
|
mCurrentViewTransform.y = mFrameMetrics.viewportRectTop;
|
|
|
|
mCurrentViewTransform.scale = mFrameMetrics.zoomFactor;
|
|
|
|
|
2012-03-19 21:07:42 -07:00
|
|
|
mRootLayer.setPositionAndResolution(x, y, x + width, y + height, resolution);
|
2012-03-17 08:08:22 -07:00
|
|
|
|
2012-04-25 06:53:38 -07:00
|
|
|
if (layersUpdated && mRecordDrawTimes) {
|
|
|
|
// If we got a layers update, that means a draw finished. Check to see if the area drawn matches
|
|
|
|
// one of our requested displayports; if it does calculate the draw time and notify the
|
|
|
|
// DisplayPortCalculator
|
|
|
|
DisplayPortMetrics drawn = new DisplayPortMetrics(x, y, x + width, y + height, resolution);
|
|
|
|
long time = mDrawTimingQueue.findTimeFor(drawn);
|
|
|
|
if (time >= 0) {
|
|
|
|
long now = SystemClock.uptimeMillis();
|
|
|
|
time = now - time;
|
|
|
|
mRecordDrawTimes = DisplayPortCalculator.drawTimeUpdate(time, width * height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-19 21:06:56 -07:00
|
|
|
if (layersUpdated && mDrawListener != null) {
|
|
|
|
/* Used by robocop for testing purposes */
|
|
|
|
mDrawListener.drawFinished();
|
|
|
|
}
|
|
|
|
|
2012-03-02 11:31:27 -08:00
|
|
|
return mCurrentViewTransform;
|
2012-02-22 11:45:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** 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-03-02 04:12:08 -08:00
|
|
|
mLayerRenderer.createDefaultProgram();
|
2012-02-22 11:45:44 -08:00
|
|
|
mLayerRendererInitialized = true;
|
|
|
|
}
|
|
|
|
|
2012-04-17 22:34:05 -07:00
|
|
|
return mLayerRenderer.createFrame(mFrameMetrics);
|
2012-02-22 11:45:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** This function is invoked by Gecko via JNI; be careful when modifying signature. */
|
|
|
|
public void activateProgram() {
|
2012-03-02 04:12:08 -08:00
|
|
|
mLayerRenderer.activateDefaultProgram();
|
2012-02-22 11:45:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** This function is invoked by Gecko via JNI; be careful when modifying signature. */
|
|
|
|
public void deactivateProgram() {
|
2012-03-02 04:12:08 -08:00
|
|
|
mLayerRenderer.deactivateDefaultProgram();
|
2012-02-22 11:45:44 -08:00
|
|
|
}
|
2012-02-22 12:08:46 -08:00
|
|
|
|
2012-04-05 08:28:50 -07:00
|
|
|
/** Implementation of LayerView.Listener */
|
2012-02-17 07:33:23 -08:00
|
|
|
public void renderRequested() {
|
|
|
|
GeckoAppShell.scheduleComposite();
|
|
|
|
}
|
|
|
|
|
2012-04-05 08:28:50 -07:00
|
|
|
/** Implementation of LayerView.Listener */
|
2012-02-17 07:33:23 -08:00
|
|
|
public void compositionPauseRequested() {
|
2012-03-28 15:00:38 -07:00
|
|
|
// We need to coordinate with Gecko when pausing composition, to ensure
|
|
|
|
// that Gecko never executes a draw event while the compositor is paused.
|
2012-05-09 19:32:54 -07:00
|
|
|
// This is sent synchronously to make sure that we don't attempt to use
|
|
|
|
// any outstanding Surfaces after we call this (such as from a
|
|
|
|
// surfaceDestroyed notification), and to make sure that any in-flight
|
|
|
|
// Gecko draw events have been processed. When this returns, composition is
|
|
|
|
// definitely paused -- it'll synchronize with the Gecko event loop, which
|
|
|
|
// in turn will synchronize with the compositor thread.
|
2012-07-06 06:48:25 -07:00
|
|
|
if (mCompositorCreated) {
|
|
|
|
GeckoAppShell.sendEventToGeckoSync(GeckoEvent.createCompositorPauseEvent());
|
|
|
|
}
|
2012-02-17 07:33:23 -08:00
|
|
|
}
|
|
|
|
|
2012-04-05 08:28:50 -07:00
|
|
|
/** Implementation of LayerView.Listener */
|
2012-04-20 08:46:30 -07:00
|
|
|
public void compositionResumeRequested(int width, int height) {
|
2012-03-28 15:00:38 -07:00
|
|
|
// Asking Gecko to resume the compositor takes too long (see
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=735230#c23), so we
|
|
|
|
// resume the compositor directly. We still need to inform Gecko about
|
|
|
|
// the compositor resuming, so that Gecko knows that it can now draw.
|
2012-07-06 06:48:25 -07:00
|
|
|
if (mCompositorCreated) {
|
|
|
|
GeckoAppShell.scheduleResumeComposition(width, height);
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createCompositorResumeEvent());
|
|
|
|
}
|
2012-02-17 07:33:23 -08:00
|
|
|
}
|
|
|
|
|
2012-04-05 08:28:50 -07:00
|
|
|
/** Implementation of LayerView.Listener */
|
2012-02-17 07:33:23 -08:00
|
|
|
public void surfaceChanged(int width, int height) {
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
mLayerController.setViewportSize(new FloatSize(width, height));
|
2012-03-28 15:00:38 -07:00
|
|
|
|
|
|
|
// We need to make this call even when the compositor isn't currently
|
|
|
|
// paused (e.g. during an orientation change), to make the compositor
|
|
|
|
// aware of the changed surface.
|
2012-04-20 08:46:30 -07:00
|
|
|
compositionResumeRequested(width, height);
|
2012-02-17 07:33:23 -08:00
|
|
|
renderRequested();
|
|
|
|
}
|
|
|
|
|
2012-07-06 06:48:25 -07:00
|
|
|
/** Implementation of LayerView.Listener */
|
|
|
|
public void compositorCreated() {
|
|
|
|
mCompositorCreated = true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
Backout d2ee4c12c0b3 (bug 777351), 5aa6f94160dd (bug 777351), b47c470168fc (bug 777351), 5fb303ba52f7 (bug 777351), be81e4c3d928 (bug 777351), abc5b9a922dc (bug 777075), 8f1fc980f1f1 (bug 777075), 0b194a7f47d4 (bug 777075), d10df9bfef60 (bug 777075), 65393fe32cce (bug 777075), b52dc1df2fde (bug 777075), 8aeda525c094 (bug 777075) for Android native R1 failures on a CLOSED TREE
2012-08-01 10:42:05 -07:00
|
|
|
|