--- a/android/src/org/lxdream/LxdreamView.java Tue Feb 28 17:27:39 2012 +1000 +++ b/android/src/org/lxdream/LxdreamView.java Fri Mar 02 23:49:10 2012 +1000 @@ -36,114 +36,39 @@ import android.content.Context; import android.graphics.PixelFormat; -import android.opengl.GLSurfaceView; import android.util.AttributeSet; import android.util.Log; import android.view.KeyEvent; import android.view.MotionEvent; +import android.view.Surface; +import android.view.SurfaceHolder; +import android.view.SurfaceView; -import javax.microedition.khronos.egl.EGL10; -import javax.microedition.khronos.egl.EGLConfig; -import javax.microedition.khronos.egl.EGLContext; -import javax.microedition.khronos.egl.EGLDisplay; -import javax.microedition.khronos.opengles.GL10; - -/** - * A simple GLSurfaceView sub-class that demonstrate how to perform - * OpenGL ES 2.0 rendering into a GL Surface. Note the following important - * details: - * - * - The class must use a custom context factory to enable 2.0 rendering. - * See ContextFactory class definition below. - * - * - The class must use a custom EGLConfigChooser to be able to select - * an EGLConfig that supports 2.0. This is done by providing a config - * specification to eglChooseConfig() that has the attribute - * EGL10.ELG_RENDERABLE_TYPE containing the EGL_OPENGL_ES2_BIT flag - * set. See ConfigChooser class definition below. - * - * - The class must select the surface's format, then choose an EGLConfig - * that matches it exactly (with regards to red/green/blue/alpha channels - * bit depths). Failure to do so would result in an EGL_BAD_MATCH error. - */ -class LxdreamView extends GLSurfaceView { +class LxdreamView extends SurfaceView implements SurfaceHolder.Callback { private static String TAG = "LxdreamView"; private static final boolean DEBUG = false; public LxdreamView(Context context) { super(context); - init(false, 0, 0); + getHolder().addCallback(this); } - public LxdreamView(Context context, boolean translucent, int depth, int stencil) { - super(context); - init(translucent, depth, stencil); + @Override + public void surfaceCreated( SurfaceHolder holder ) { + /* Ignore */ } - - private void init(boolean translucent, int depth, int stencil) { - - /* By default, GLSurfaceView() creates a RGB_565 opaque surface. - * If we want a translucent one, we should change the surface's - * format here, using PixelFormat.TRANSLUCENT for GL Surfaces - * is interpreted as any 32-bit surface with alpha by SurfaceFlinger. - */ - if (translucent) { - this.getHolder().setFormat(PixelFormat.TRANSLUCENT); - } - - /* Setup the context factory for 2.0 rendering. - * See ContextFactory class definition below - */ - setEGLContextFactory(new ContextFactory()); - - /* We need to choose an EGLConfig that matches the format of - * our surface exactly. This is going to be done in our - * custom config chooser. See ConfigChooser class definition - * below. - */ - setEGLConfigChooser( translucent ? - new ConfigChooser(8, 8, 8, 8, depth, stencil) : - new ConfigChooser(5, 6, 5, 0, depth, stencil) ); - - /* Set the renderer responsible for frame rendering */ - setRenderer(new Renderer()); + + @Override + public void surfaceChanged( SurfaceHolder holder, int format, int width, int height ) { + setSurface( holder.getSurface(), width, height ); } - - private static class ContextFactory implements GLSurfaceView.EGLContextFactory { - private static int EGL_CONTEXT_CLIENT_VERSION = 0x3098; - public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) { - Log.w(TAG, "creating OpenGL ES 2.0 context"); - checkEglError("Before eglCreateContext", egl); - int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE }; - EGLContext context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list); - checkEglError("After eglCreateContext", egl); - return context; - } - - public void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context) { - egl.eglDestroyContext(display, context); - } + + @Override + public void surfaceDestroyed( SurfaceHolder holder ) { + clearSurface( holder.getSurface() ); } - - private static void checkEglError(String prompt, EGL10 egl) { - int error; - while ((error = egl.eglGetError()) != EGL10.EGL_SUCCESS) { - Log.e(TAG, String.format("%s: EGL error: 0x%x", prompt, error)); - } - } - - - private static class Renderer implements GLSurfaceView.Renderer { - public void onDrawFrame(GL10 gl) { - Dreamcast.run(); - } - - public void onSurfaceChanged(GL10 gl, int width, int height) { - Dreamcast.setViewSize(width,height); - } - - public void onSurfaceCreated(GL10 gl, EGLConfig config) { - // Do nothing. - } - } + + private native void setSurface( Surface surface, int width, int height ); + private native void clearSurface( Surface surface ); + }