2011-11-18 18:28:17 +00:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
2012-05-21 11:12:37 +00: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/. */
|
2011-11-18 18:28:17 +00:00
|
|
|
|
|
|
|
package org.mozilla.gecko.gfx;
|
|
|
|
|
2012-07-15 20:20:43 +00:00
|
|
|
import org.mozilla.gecko.GeckoApp;
|
2013-02-08 14:13:09 +00:00
|
|
|
import org.mozilla.gecko.OnInterceptTouchListener;
|
2012-08-07 14:39:04 +00:00
|
|
|
import org.mozilla.gecko.R;
|
2012-08-20 19:43:53 +00:00
|
|
|
import org.mozilla.gecko.ZoomConstraints;
|
2012-08-20 19:43:53 +00:00
|
|
|
import org.mozilla.gecko.util.EventDispatcher;
|
2012-08-20 22:29:22 +00:00
|
|
|
import org.mozilla.gecko.GeckoAccessibility;
|
2012-07-15 20:20:43 +00:00
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
import android.content.Context;
|
2012-08-07 14:39:04 +00:00
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.BitmapFactory;
|
2012-08-20 19:43:53 +00:00
|
|
|
import android.graphics.Color;
|
2012-07-28 00:53:54 +00:00
|
|
|
import android.graphics.PixelFormat;
|
2012-08-20 19:43:53 +00:00
|
|
|
import android.graphics.PointF;
|
2012-10-19 17:06:08 +00:00
|
|
|
import android.graphics.Rect;
|
2012-07-28 00:53:54 +00:00
|
|
|
import android.graphics.SurfaceTexture;
|
2013-02-08 21:07:12 +00:00
|
|
|
import android.os.Handler;
|
2012-07-28 00:53:54 +00:00
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.util.Log;
|
2011-11-18 18:28:17 +00:00
|
|
|
import android.view.KeyEvent;
|
|
|
|
import android.view.MotionEvent;
|
2012-07-28 00:53:54 +00:00
|
|
|
import android.view.SurfaceHolder;
|
|
|
|
import android.view.SurfaceView;
|
|
|
|
import android.view.TextureView;
|
2012-08-03 17:40:33 +00:00
|
|
|
import android.view.View;
|
2012-07-28 00:53:54 +00:00
|
|
|
import android.view.ViewGroup;
|
2011-11-18 18:28:17 +00:00
|
|
|
import android.view.inputmethod.EditorInfo;
|
|
|
|
import android.view.inputmethod.InputConnection;
|
2012-07-31 17:30:46 +00:00
|
|
|
import android.widget.FrameLayout;
|
2012-04-05 15:28:50 +00:00
|
|
|
|
2012-07-15 20:20:43 +00:00
|
|
|
import java.nio.IntBuffer;
|
2012-04-05 15:28:50 +00:00
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
/**
|
|
|
|
* A view rendered by the layer compositor.
|
|
|
|
*
|
2012-03-22 17:35:19 +00:00
|
|
|
* Note that LayerView is accessed by Robocop via reflection.
|
2011-11-18 18:28:17 +00:00
|
|
|
*/
|
2012-07-31 17:30:46 +00:00
|
|
|
public class LayerView extends FrameLayout {
|
2012-07-18 00:54:54 +00:00
|
|
|
private static String LOGTAG = "GeckoLayerView";
|
2012-04-07 07:09:26 +00:00
|
|
|
|
2012-08-07 14:39:04 +00:00
|
|
|
private GeckoLayerClient mLayerClient;
|
2013-02-08 14:13:09 +00:00
|
|
|
private PanZoomController mPanZoomController;
|
2012-04-05 15:28:50 +00:00
|
|
|
private GLController mGLController;
|
2011-11-18 18:28:17 +00:00
|
|
|
private InputConnectionHandler mInputConnectionHandler;
|
|
|
|
private LayerRenderer mRenderer;
|
2012-03-22 22:07:00 +00:00
|
|
|
/* Must be a PAINT_xxx constant */
|
2012-08-20 19:43:53 +00:00
|
|
|
private int mPaintState;
|
2012-12-15 15:43:57 +00:00
|
|
|
private int mBackgroundColor;
|
2012-11-24 22:32:08 +00:00
|
|
|
private boolean mFullScreen;
|
2012-03-22 22:07:00 +00:00
|
|
|
|
2012-07-31 17:30:46 +00:00
|
|
|
private SurfaceView mSurfaceView;
|
|
|
|
private TextureView mTextureView;
|
|
|
|
|
2012-04-05 15:28:50 +00:00
|
|
|
private Listener mListener;
|
2013-02-08 14:13:09 +00:00
|
|
|
private OnInterceptTouchListener mTouchIntercepter;
|
2012-04-05 15:28:50 +00:00
|
|
|
|
2012-10-10 20:51:31 +00:00
|
|
|
/* Flags used to determine when to show the painted surface. */
|
2012-10-18 07:01:20 +00:00
|
|
|
public static final int PAINT_START = 0;
|
|
|
|
public static final int PAINT_BEFORE_FIRST = 1;
|
|
|
|
public static final int PAINT_AFTER_FIRST = 2;
|
2012-02-02 01:08:04 +00:00
|
|
|
|
2012-10-12 11:57:07 +00:00
|
|
|
public boolean shouldUseTextureView() {
|
2012-10-12 11:57:07 +00:00
|
|
|
// Disable TextureView support for now as it causes panning/zooming
|
|
|
|
// performance regressions (see bug 792259). Uncomment the code below
|
|
|
|
// once this bug is fixed.
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/*
|
2012-08-03 17:40:33 +00:00
|
|
|
// we can only use TextureView on ICS or higher
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
|
|
|
Log.i(LOGTAG, "Not using TextureView: not on ICS+");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
// and then we can only use it if we have a hardware accelerated window
|
2012-08-07 17:57:19 +00:00
|
|
|
Method m = View.class.getMethod("isHardwareAccelerated", (Class[]) null);
|
2012-08-03 17:40:33 +00:00
|
|
|
return (Boolean) m.invoke(this);
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.i(LOGTAG, "Not using TextureView: caught exception checking for hw accel: " + e.toString());
|
|
|
|
return false;
|
2012-10-12 11:57:07 +00:00
|
|
|
} */
|
2012-08-03 17:40:33 +00:00
|
|
|
}
|
|
|
|
|
2012-07-28 14:33:51 +00:00
|
|
|
public LayerView(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2013-02-28 18:28:23 +00:00
|
|
|
mGLController = GLController.getInstance(this);
|
2012-10-18 07:01:20 +00:00
|
|
|
mPaintState = PAINT_START;
|
2012-12-15 15:43:57 +00:00
|
|
|
mBackgroundColor = Color.WHITE;
|
2012-10-12 11:57:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void initializeView(EventDispatcher eventDispatcher) {
|
2012-08-20 19:43:53 +00:00
|
|
|
mLayerClient = new GeckoLayerClient(getContext(), this, eventDispatcher);
|
2013-02-08 14:13:09 +00:00
|
|
|
mPanZoomController = mLayerClient.getPanZoomController();
|
2012-08-20 19:43:53 +00:00
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
mRenderer = new LayerRenderer(this);
|
|
|
|
mInputConnectionHandler = null;
|
|
|
|
|
|
|
|
setFocusable(true);
|
|
|
|
setFocusableInTouchMode(true);
|
2012-08-20 22:29:22 +00:00
|
|
|
|
|
|
|
GeckoAccessibility.setDelegate(this);
|
2012-08-20 19:43:53 +00:00
|
|
|
}
|
2012-08-20 19:43:53 +00:00
|
|
|
|
2012-10-22 14:51:29 +00:00
|
|
|
public void show() {
|
|
|
|
// Fix this if TextureView support is turned back on above
|
|
|
|
mSurfaceView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void hide() {
|
|
|
|
// Fix this if TextureView support is turned back on above
|
|
|
|
mSurfaceView.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
|
2012-08-20 19:43:53 +00:00
|
|
|
public void destroy() {
|
|
|
|
if (mLayerClient != null) {
|
|
|
|
mLayerClient.destroy();
|
|
|
|
}
|
2012-10-18 03:53:40 +00:00
|
|
|
if (mRenderer != null) {
|
|
|
|
mRenderer.destroy();
|
|
|
|
}
|
2013-02-08 14:13:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setTouchIntercepter(final OnInterceptTouchListener touchIntercepter) {
|
|
|
|
// this gets run on the gecko thread, but for thread safety we want the assignment
|
|
|
|
// on the UI thread.
|
|
|
|
post(new Runnable() {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2013-02-08 14:13:09 +00:00
|
|
|
public void run() {
|
|
|
|
mTouchIntercepter = touchIntercepter;
|
|
|
|
}
|
|
|
|
});
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
2013-02-08 14:13:09 +00:00
|
|
|
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
|
2012-06-08 18:43:17 +00:00
|
|
|
requestFocus();
|
2013-02-08 14:13:09 +00:00
|
|
|
}
|
2012-06-08 18:43:17 +00:00
|
|
|
|
2013-02-08 14:13:09 +00:00
|
|
|
if (mTouchIntercepter != null && mTouchIntercepter.onInterceptTouchEvent(this, event)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (mPanZoomController != null && mPanZoomController.onTouchEvent(event)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (mTouchIntercepter != null && mTouchIntercepter.onTouch(this, event)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2012-06-15 22:34:22 +00:00
|
|
|
@Override
|
|
|
|
public boolean onHoverEvent(MotionEvent event) {
|
2013-02-08 14:13:09 +00:00
|
|
|
if (mTouchIntercepter != null && mTouchIntercepter.onTouch(this, event)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onGenericMotionEvent(MotionEvent event) {
|
|
|
|
if (mPanZoomController != null && mPanZoomController.onMotionEvent(event)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2012-06-15 22:34:22 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 16:59:18 +00:00
|
|
|
@Override
|
|
|
|
protected void onAttachedToWindow() {
|
|
|
|
// This check should not be done before the view is attached to a window
|
|
|
|
// as hardware acceleration will not be enabled at that point.
|
|
|
|
// We must create and add the SurfaceView instance before the view tree
|
|
|
|
// is fully created to avoid flickering (see bug 801477).
|
|
|
|
if (shouldUseTextureView()) {
|
|
|
|
mTextureView = new TextureView(getContext());
|
|
|
|
mTextureView.setSurfaceTextureListener(new SurfaceTextureListener());
|
|
|
|
mTextureView.setBackgroundColor(Color.WHITE);
|
|
|
|
addView(mTextureView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
|
|
} else {
|
|
|
|
// This will stop PropertyAnimator from creating a drawing cache (i.e. a bitmap)
|
|
|
|
// from a SurfaceView, which is just not possible (the bitmap will be transparent).
|
|
|
|
setWillNotCacheDrawing(false);
|
|
|
|
|
2013-01-10 17:32:43 +00:00
|
|
|
mSurfaceView = new LayerSurfaceView(getContext(), this);
|
2012-10-17 16:59:18 +00:00
|
|
|
mSurfaceView.setBackgroundColor(Color.WHITE);
|
|
|
|
addView(mSurfaceView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
|
|
|
|
|
|
SurfaceHolder holder = mSurfaceView.getHolder();
|
|
|
|
holder.addCallback(new SurfaceListener());
|
|
|
|
holder.setFormat(PixelFormat.RGB_565);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-07 14:39:04 +00:00
|
|
|
public GeckoLayerClient getLayerClient() { return mLayerClient; }
|
2013-02-08 14:13:09 +00:00
|
|
|
public PanZoomController getPanZoomController() { return mPanZoomController; }
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2012-08-20 19:43:53 +00:00
|
|
|
public ImmutableViewportMetrics getViewportMetrics() {
|
|
|
|
return mLayerClient.getViewportMetrics();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void abortPanning() {
|
2013-03-02 03:50:49 +00:00
|
|
|
if (mPanZoomController != null) {
|
|
|
|
mPanZoomController.abortPanning();
|
|
|
|
}
|
2012-08-20 19:43:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public PointF convertViewPointToLayerPoint(PointF viewPoint) {
|
|
|
|
return mLayerClient.convertViewPointToLayerPoint(viewPoint);
|
|
|
|
}
|
|
|
|
|
2012-12-15 15:43:57 +00:00
|
|
|
int getBackgroundColor() {
|
|
|
|
return mBackgroundColor;
|
2012-08-20 19:43:53 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-12-15 15:43:57 +00:00
|
|
|
public void setBackgroundColor(int newColor) {
|
|
|
|
mBackgroundColor = newColor;
|
2012-08-20 19:43:53 +00:00
|
|
|
requestRender();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setZoomConstraints(ZoomConstraints constraints) {
|
|
|
|
mLayerClient.setZoomConstraints(constraints);
|
|
|
|
}
|
|
|
|
|
2012-08-02 18:56:52 +00:00
|
|
|
public void setInputConnectionHandler(InputConnectionHandler inputConnectionHandler) {
|
|
|
|
mInputConnectionHandler = inputConnectionHandler;
|
2013-01-09 16:21:04 +00:00
|
|
|
mLayerClient.forceRedraw();
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 21:07:12 +00:00
|
|
|
@Override
|
|
|
|
public Handler getHandler() {
|
|
|
|
if (mInputConnectionHandler != null)
|
|
|
|
return mInputConnectionHandler.getHandler(super.getHandler());
|
|
|
|
return super.getHandler();
|
|
|
|
}
|
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
@Override
|
|
|
|
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
|
|
|
|
if (mInputConnectionHandler != null)
|
|
|
|
return mInputConnectionHandler.onCreateInputConnection(outAttrs);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
|
2013-03-02 03:50:49 +00:00
|
|
|
if (mInputConnectionHandler != null && mInputConnectionHandler.onKeyPreIme(keyCode, event)) {
|
|
|
|
return true;
|
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
2013-03-02 03:50:49 +00:00
|
|
|
if (mPanZoomController != null && mPanZoomController.onKeyEvent(event)) {
|
2013-03-02 03:50:48 +00:00
|
|
|
return true;
|
2013-03-02 03:50:49 +00:00
|
|
|
}
|
|
|
|
if (mInputConnectionHandler != null && mInputConnectionHandler.onKeyDown(keyCode, event)) {
|
|
|
|
return true;
|
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
|
2013-03-02 03:50:49 +00:00
|
|
|
if (mInputConnectionHandler != null && mInputConnectionHandler.onKeyLongPress(keyCode, event)) {
|
|
|
|
return true;
|
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
|
2013-03-02 03:50:49 +00:00
|
|
|
if (mInputConnectionHandler != null && mInputConnectionHandler.onKeyMultiple(keyCode, repeatCount, event)) {
|
|
|
|
return true;
|
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
2013-03-02 03:50:49 +00:00
|
|
|
if (mInputConnectionHandler != null && mInputConnectionHandler.onKeyUp(keyCode, event)) {
|
|
|
|
return true;
|
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-11-30 17:27:13 +00:00
|
|
|
|
2012-11-01 20:11:02 +00:00
|
|
|
public boolean isIMEEnabled() {
|
|
|
|
if (mInputConnectionHandler != null) {
|
|
|
|
return mInputConnectionHandler.isIMEEnabled();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-10 02:32:54 +00:00
|
|
|
public void requestRender() {
|
2012-04-05 15:28:50 +00:00
|
|
|
if (mListener != null) {
|
|
|
|
mListener.renderRequested();
|
2011-11-30 17:27:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-31 14:40:58 +00:00
|
|
|
public void addLayer(Layer layer) {
|
|
|
|
mRenderer.addLayer(layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removeLayer(Layer layer) {
|
|
|
|
mRenderer.removeLayer(layer);
|
|
|
|
}
|
|
|
|
|
2011-12-15 23:45:52 +00:00
|
|
|
public int getMaxTextureSize() {
|
|
|
|
return mRenderer.getMaxTextureSize();
|
|
|
|
}
|
2012-01-26 19:23:13 +00:00
|
|
|
|
2012-08-14 12:55:58 +00:00
|
|
|
/** Used by robocop for testing purposes. Not for production use! */
|
2012-01-31 03:45:38 +00:00
|
|
|
public IntBuffer getPixels() {
|
|
|
|
return mRenderer.getPixels();
|
|
|
|
}
|
2012-03-12 17:03:54 +00:00
|
|
|
|
2012-10-10 20:51:31 +00:00
|
|
|
/* paintState must be a PAINT_xxx constant. */
|
2012-03-22 22:07:00 +00:00
|
|
|
public void setPaintState(int paintState) {
|
2012-10-10 20:51:31 +00:00
|
|
|
mPaintState = paintState;
|
2012-03-22 22:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getPaintState() {
|
|
|
|
return mPaintState;
|
|
|
|
}
|
2012-04-05 15:27:02 +00:00
|
|
|
|
2012-04-24 19:13:36 +00:00
|
|
|
public LayerRenderer getRenderer() {
|
2012-04-05 15:28:50 +00:00
|
|
|
return mRenderer;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setListener(Listener listener) {
|
|
|
|
mListener = listener;
|
|
|
|
}
|
|
|
|
|
2012-07-13 14:19:46 +00:00
|
|
|
Listener getListener() {
|
|
|
|
return mListener;
|
|
|
|
}
|
|
|
|
|
2012-05-10 02:32:54 +00:00
|
|
|
public GLController getGLController() {
|
2012-04-05 15:28:50 +00:00
|
|
|
return mGLController;
|
|
|
|
}
|
|
|
|
|
2012-08-07 14:39:04 +00:00
|
|
|
private Bitmap getDrawable(int resId) {
|
|
|
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
|
|
|
options.inScaled = false;
|
|
|
|
return BitmapFactory.decodeResource(getContext().getResources(), resId, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
Bitmap getShadowPattern() {
|
|
|
|
return getDrawable(R.drawable.shadow);
|
|
|
|
}
|
|
|
|
|
2012-12-29 20:24:01 +00:00
|
|
|
Bitmap getScrollbarImage() {
|
|
|
|
return getDrawable(R.drawable.scrollbar);
|
|
|
|
}
|
|
|
|
|
2013-01-10 17:32:43 +00:00
|
|
|
/* When using a SurfaceView (mSurfaceView != null), resizing happens in two
|
|
|
|
* phases. First, the LayerView changes size, then, often some frames later,
|
|
|
|
* the SurfaceView changes size. Because of this, we need to split the
|
|
|
|
* resize into two phases to avoid jittering.
|
|
|
|
*
|
|
|
|
* The first phase is the LayerView size change. mListener is notified so
|
|
|
|
* that a synchronous draw can be performed (otherwise a blank frame will
|
|
|
|
* appear).
|
|
|
|
*
|
|
|
|
* The second phase is the SurfaceView size change. At this point, the
|
|
|
|
* backing GL surface is resized and another synchronous draw is performed.
|
|
|
|
* Gecko is also sent the new window size, and this will likely cause an
|
|
|
|
* extra draw a few frames later, after it's re-rendered and caught up.
|
|
|
|
*
|
|
|
|
* In the case that there is no valid GL surface (for example, when
|
|
|
|
* resuming, or when coming back from the awesomescreen), or we're using a
|
|
|
|
* TextureView instead of a SurfaceView, the first phase is skipped.
|
|
|
|
*/
|
2012-07-31 17:30:46 +00:00
|
|
|
private void onSizeChanged(int width, int height) {
|
2013-01-10 17:32:43 +00:00
|
|
|
if (!mGLController.hasValidSurface() || mSurfaceView == null) {
|
|
|
|
surfaceChanged(width, height);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mListener != null) {
|
|
|
|
mListener.sizeChanged(width, height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void surfaceChanged(int width, int height) {
|
2012-05-18 19:58:46 +00:00
|
|
|
mGLController.surfaceChanged(width, height);
|
2012-04-05 15:28:50 +00:00
|
|
|
|
|
|
|
if (mListener != null) {
|
|
|
|
mListener.surfaceChanged(width, height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-31 17:30:46 +00:00
|
|
|
private void onDestroyed() {
|
2012-04-05 15:28:50 +00:00
|
|
|
mGLController.surfaceDestroyed();
|
|
|
|
}
|
|
|
|
|
2012-07-31 17:30:46 +00:00
|
|
|
public Object getNativeWindow() {
|
2012-08-03 17:40:33 +00:00
|
|
|
if (mSurfaceView != null)
|
2012-07-31 17:30:46 +00:00
|
|
|
return mSurfaceView.getHolder();
|
|
|
|
|
|
|
|
return mTextureView.getSurfaceTexture();
|
|
|
|
}
|
|
|
|
|
2012-04-05 15:28:50 +00:00
|
|
|
/** This function is invoked by Gecko (compositor thread) via JNI; be careful when modifying signature. */
|
|
|
|
public static GLController registerCxxCompositor() {
|
|
|
|
try {
|
2012-08-20 19:43:53 +00:00
|
|
|
LayerView layerView = GeckoApp.mAppContext.getLayerView();
|
2013-02-28 18:28:23 +00:00
|
|
|
GLController controller = layerView.getGLController();
|
|
|
|
controller.compositorCreated();
|
|
|
|
return controller;
|
2012-04-05 15:28:50 +00:00
|
|
|
} catch (Exception e) {
|
2012-07-23 19:04:28 +00:00
|
|
|
Log.e(LOGTAG, "Error registering compositor!", e);
|
2012-04-05 15:28:50 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface Listener {
|
|
|
|
void renderRequested();
|
2013-01-10 17:32:43 +00:00
|
|
|
void sizeChanged(int width, int height);
|
2012-04-05 15:28:50 +00:00
|
|
|
void surfaceChanged(int width, int height);
|
|
|
|
}
|
2012-07-18 00:54:54 +00:00
|
|
|
|
2012-07-31 17:30:46 +00:00
|
|
|
private class SurfaceListener implements SurfaceHolder.Callback {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-07-31 17:30:46 +00:00
|
|
|
public void surfaceChanged(SurfaceHolder holder, int format, int width,
|
|
|
|
int height) {
|
|
|
|
onSizeChanged(width, height);
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-07-31 17:30:46 +00:00
|
|
|
public void surfaceCreated(SurfaceHolder holder) {
|
|
|
|
}
|
2012-07-18 00:54:54 +00:00
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-07-31 17:30:46 +00:00
|
|
|
public void surfaceDestroyed(SurfaceHolder holder) {
|
|
|
|
onDestroyed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-10 17:32:43 +00:00
|
|
|
/* A subclass of SurfaceView to listen to layout changes, as
|
|
|
|
* View.OnLayoutChangeListener requires API level 11.
|
|
|
|
*/
|
|
|
|
private class LayerSurfaceView extends SurfaceView {
|
|
|
|
LayerView mParent;
|
|
|
|
|
|
|
|
public LayerSurfaceView(Context aContext, LayerView aParent) {
|
|
|
|
super(aContext);
|
|
|
|
mParent = aParent;
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2013-01-10 17:32:43 +00:00
|
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
|
|
if (changed) {
|
|
|
|
mParent.surfaceChanged(right - left, bottom - top);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-31 17:30:46 +00:00
|
|
|
private class SurfaceTextureListener implements TextureView.SurfaceTextureListener {
|
|
|
|
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
|
|
|
|
// We don't do this for surfaceCreated above because it is always followed by a surfaceChanged,
|
|
|
|
// but that is not the case here.
|
|
|
|
onSizeChanged(width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
|
|
|
|
onDestroyed();
|
|
|
|
return true; // allow Android to call release() on the SurfaceTexture, we are done drawing to it
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
|
|
|
|
onSizeChanged(width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2012-09-12 20:36:36 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setOverScrollMode(int overscrollMode) {
|
|
|
|
super.setOverScrollMode(overscrollMode);
|
2013-03-02 03:50:49 +00:00
|
|
|
if (mPanZoomController != null) {
|
|
|
|
mPanZoomController.setOverScrollMode(overscrollMode);
|
|
|
|
}
|
2012-09-12 20:36:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getOverScrollMode() {
|
2013-03-02 03:50:49 +00:00
|
|
|
if (mPanZoomController != null) {
|
|
|
|
return mPanZoomController.getOverScrollMode();
|
|
|
|
}
|
2012-09-12 20:36:36 +00:00
|
|
|
return super.getOverScrollMode();
|
|
|
|
}
|
2012-10-19 17:06:08 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFocusChanged (boolean gainFocus, int direction, Rect previouslyFocusedRect) {
|
|
|
|
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
|
|
|
|
GeckoAccessibility.onLayerViewFocusChanged(this, gainFocus);
|
|
|
|
}
|
2012-11-24 22:32:08 +00:00
|
|
|
|
|
|
|
public void setFullScreen(boolean fullScreen) {
|
|
|
|
mFullScreen = fullScreen;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isFullScreen() {
|
|
|
|
return mFullScreen;
|
|
|
|
}
|
2012-04-05 15:28:50 +00:00
|
|
|
}
|