Bug 779152 - Render into a TextureView on Android where available r=kats

This commit is contained in:
James Willcox 2012-07-31 13:30:46 -04:00
parent 02ad32a5d3
commit b5966430df
2 changed files with 67 additions and 15 deletions

View File

@ -169,8 +169,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());

View File

@ -13,11 +13,16 @@ import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.ViewGroup;
import android.view.TextureView;
import android.widget.FrameLayout;
import android.util.AttributeSet;
import android.util.Log;
import android.graphics.PixelFormat;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.os.Build;
import android.graphics.SurfaceTexture;
import java.nio.IntBuffer;
@ -29,7 +34,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;
@ -40,6 +45,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
@ -51,9 +59,20 @@ 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);
}
@ -201,9 +220,7 @@ 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) {
private void onSizeChanged(int width, int height) {
mGLController.surfaceChanged(width, height);
if (mListener != null) {
@ -211,12 +228,7 @@ public class LayerView extends SurfaceView implements SurfaceHolder.Callback {
}
}
/** Implementation of SurfaceHolder.Callback */
public synchronized void surfaceCreated(SurfaceHolder holder) {
}
/** Implementation of SurfaceHolder.Callback */
public synchronized void surfaceDestroyed(SurfaceHolder holder) {
private void onDestroyed() {
mGLController.surfaceDestroyed();
if (mListener != null) {
@ -224,6 +236,13 @@ 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 {
@ -244,5 +263,38 @@ public class LayerView extends SurfaceView implements SurfaceHolder.Callback {
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) {
}
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.
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) {
}
}
}