summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.com>2014-10-04 15:53:44 +0200
committerTomaž Vajngerl <tomaz.vajngerl@collabora.com>2014-10-04 17:53:13 +0200
commit488d19de01670c37b638e67bec99dc178d4792a5 (patch)
tree64ecc65858387a036550d2cbd77478b69d66b220 /android
parent67be577f163831e460e19aee958bdcf7187b8a56 (diff)
android: use TextureView instead of SurfaceView for ICS+ devices
Change-Id: I4c5585d5eac4faf46ad9bed2d3992fe87b3d9a03
Diffstat (limited to 'android')
-rw-r--r--android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GLController.java28
-rw-r--r--android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoLayerClient.java8
-rw-r--r--android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerView.java94
3 files changed, 94 insertions, 36 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GLController.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GLController.java
index 9bd7d2f68a48..e296f4760f68 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GLController.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GLController.java
@@ -5,8 +5,6 @@
package org.mozilla.gecko.gfx;
-import android.view.SurfaceHolder;
-
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGL11;
import javax.microedition.khronos.egl.EGLConfig;
@@ -119,8 +117,15 @@ public class GLController {
return true;
}
+ // This function is invoked by JNI
+ public synchronized void resumeCompositorIfValid() {
+ if (mSurfaceValid) {
+ mView.getListener().compositionResumeRequested(mWidth, mHeight);
+ }
+ }
+
// Wait until we are allowed to use EGL functions on the Surface backing
- // this window.
+ // this window. This function is invoked by JNI
public synchronized void waitForValidSurface() {
while (!mSurfaceValid) {
try {
@@ -139,19 +144,16 @@ public class GLController {
return mHeight;
}
- synchronized void surfaceCreated() {
- mSurfaceValid = true;
- notifyAll();
- }
-
synchronized void surfaceDestroyed() {
mSurfaceValid = false;
notifyAll();
}
- synchronized void sizeChanged(int newWidth, int newHeight) {
+ synchronized void surfaceChanged(int newWidth, int newHeight) {
mWidth = newWidth;
mHeight = newHeight;
+ mSurfaceValid = true;
+ notifyAll();
}
private void initEGL() {
@@ -218,8 +220,8 @@ public class GLController {
}
private void createEGLSurface() {
- SurfaceHolder surfaceHolder = mView.getHolder();
- mEGLSurface = mEGL.eglCreateWindowSurface(mEGLDisplay, mEGLConfig, surfaceHolder, null);
+ Object window = mView.getNativeWindow();
+ mEGLSurface = mEGL.eglCreateWindowSurface(mEGLDisplay, mEGLConfig, window, null);
if (mEGLSurface == null || mEGLSurface == EGL10.EGL_NO_SURFACE) {
throw new GLControllerException("EGL window surface could not be created! " +
getEGLError());
@@ -248,8 +250,8 @@ public class GLController {
initEGL();
}
- SurfaceHolder surfaceHolder = mView.getHolder();
- EGLSurface surface = mEGL.eglCreateWindowSurface(mEGLDisplay, mEGLConfig, surfaceHolder, null);
+ Object window = mView.getNativeWindow();
+ EGLSurface surface = mEGL.eglCreateWindowSurface(mEGLDisplay, mEGLConfig, window, null);
if (surface == null || surface == EGL10.EGL_NO_SURFACE) {
throw new GLControllerException("EGL window surface could not be created! " +
getEGLError());
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoLayerClient.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoLayerClient.java
index cf4ba343c78f..9b7dd39684c7 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoLayerClient.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoLayerClient.java
@@ -227,23 +227,23 @@ public class GeckoLayerClient implements LayerView.Listener {
}
@Override
- public void renderRequested() {
+ public void compositorCreated() {
+ }
+ @Override
+ public void renderRequested() {
}
@Override
public void compositionPauseRequested() {
-
}
@Override
public void compositionResumeRequested(int width, int height) {
-
}
@Override
public void surfaceChanged(int width, int height) {
- compositionResumeRequested(width, height);
renderRequested();
}
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerView.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerView.java
index 874d10ae8be4..505f933524a2 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerView.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerView.java
@@ -9,14 +9,19 @@ package org.mozilla.gecko.gfx;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.PixelFormat;
+import android.graphics.SurfaceTexture;
+import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
+import android.view.TextureView;
+import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
+import android.widget.FrameLayout;
import org.libreoffice.LibreOfficeMainActivity;
@@ -30,7 +35,7 @@ import java.nio.IntBuffer;
*
* Note that LayerView is accessed by Robocop via reflection.
*/
-public class LayerView extends SurfaceView implements SurfaceHolder.Callback {
+public class LayerView extends FrameLayout {
private static String LOGTAG = "GeckoLayerView";
private LayerController mController;
@@ -43,6 +48,9 @@ public class LayerView extends SurfaceView implements SurfaceHolder.Callback {
/* Must be a PAINT_xxx constant */
private int mPaintState = PAINT_NONE;
+ private SurfaceView mSurfaceView;
+ private TextureView mTextureView;
+
private Listener mListener;
/* Flags used to determine when to show the painted surface. The integer
@@ -54,9 +62,19 @@ public class LayerView extends SurfaceView implements SurfaceHolder.Callback {
public LayerView(Context context, AttributeSet attrs) {
super(context, attrs);
- SurfaceHolder holder = getHolder();
- holder.addCallback(this);
- holder.setFormat(PixelFormat.RGB_565);
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
+ mSurfaceView = new SurfaceView(context);
+ addView(mSurfaceView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
+
+ SurfaceHolder holder = mSurfaceView.getHolder();
+ holder.addCallback(new SurfaceListener());
+ holder.setFormat(PixelFormat.RGB_565);
+ } else {
+ mTextureView = new TextureView(context);
+ mTextureView.setSurfaceTextureListener(new SurfaceTextureListener());
+
+ addView(mTextureView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
+ }
mGLController = new GLController(this);
}
@@ -217,10 +235,8 @@ public class LayerView extends SurfaceView implements SurfaceHolder.Callback {
return mGLController;
}
- /** Implementation of SurfaceHolder.Callback */
- public synchronized void surfaceChanged(SurfaceHolder holder, int format, int width,
- int height) {
- mGLController.sizeChanged(width, height);
+ private void onSizeChanged(int width, int height) {
+ mGLController.surfaceChanged(width, height);
if (mGLThread != null) {
mGLThread.surfaceChanged(width, height);
@@ -231,16 +247,7 @@ public class LayerView extends SurfaceView implements SurfaceHolder.Callback {
}
}
- /** Implementation of SurfaceHolder.Callback */
- public synchronized void surfaceCreated(SurfaceHolder holder) {
- mGLController.surfaceCreated();
- if (mGLThread != null) {
- mGLThread.surfaceCreated();
- }
- }
-
- /** Implementation of SurfaceHolder.Callback */
- public synchronized void surfaceDestroyed(SurfaceHolder holder) {
+ private void onDestroyed() {
mGLController.surfaceDestroyed();
if (mGLThread != null) {
@@ -252,24 +259,73 @@ public class LayerView extends SurfaceView implements SurfaceHolder.Callback {
}
}
+ public Object getNativeWindow() {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH)
+ return mSurfaceView.getHolder();
+
+ return mTextureView.getSurfaceTexture();
+ }
+
/** This function is invoked by Gecko (compositor thread) via JNI; be careful when modifying signature. */
public static GLController registerCxxCompositor() {
try {
LayerView layerView = LibreOfficeMainActivity.mAppContext.getLayerController().getView();
+ layerView.mListener.compositorCreated();
return layerView.getGLController();
} catch (Exception e) {
- Log.e(LOGTAG, "### Exception! " + e);
+ Log.e(LOGTAG, "Error registering compositor!", e);
return null;
}
}
public interface Listener {
+ void compositorCreated();
void renderRequested();
void compositionPauseRequested();
void compositionResumeRequested(int width, int height);
void surfaceChanged(int width, int height);
}
+ private class SurfaceListener implements SurfaceHolder.Callback {
+ public void surfaceChanged(SurfaceHolder holder, int format, int width,
+ int height) {
+ onSizeChanged(width, height);
+ }
+
+ public void surfaceCreated(SurfaceHolder holder) {
+ if (mGLThread != null) {
+ mGLThread.surfaceCreated();
+ }
+ }
+
+ public void surfaceDestroyed(SurfaceHolder holder) {
+ onDestroyed();
+ }
+ }
+
+ 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.
+ if (mGLThread != null) {
+ mGLThread.surfaceCreated();
+ }
+ 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) {
+ }
+ }
+
private GLThread mGLThread; // Protected by this class's monitor.
public synchronized void createGLThread() {