filename | android/src/org/lxdream/LxdreamView.java |
changeset | 1245:01e0020adf88 |
prev | 1241:74f8e11ab4b8 |
author | nkeynes |
date | Fri Mar 02 23:49:10 2012 +1000 (12 years ago) |
permissions | -rw-r--r-- |
last change | Android WIP: * Rename gui_jni.c to gui_android.c - now quite android specific. * Implement generic EGL driver with very minimal Java wrapper * Run emulation in separate thread, and implement simple queue for inter-thread communication. * Add menu/action-bar items for start + reset |
file | annotate | diff | log | raw |
1.1 --- a/android/src/org/lxdream/LxdreamView.java Tue Feb 28 17:27:39 2012 +10001.2 +++ b/android/src/org/lxdream/LxdreamView.java Fri Mar 02 23:49:10 2012 +10001.3 @@ -36,114 +36,39 @@1.5 import android.content.Context;1.6 import android.graphics.PixelFormat;1.7 -import android.opengl.GLSurfaceView;1.8 import android.util.AttributeSet;1.9 import android.util.Log;1.10 import android.view.KeyEvent;1.11 import android.view.MotionEvent;1.12 +import android.view.Surface;1.13 +import android.view.SurfaceHolder;1.14 +import android.view.SurfaceView;1.16 -import javax.microedition.khronos.egl.EGL10;1.17 -import javax.microedition.khronos.egl.EGLConfig;1.18 -import javax.microedition.khronos.egl.EGLContext;1.19 -import javax.microedition.khronos.egl.EGLDisplay;1.20 -import javax.microedition.khronos.opengles.GL10;1.21 -1.22 -/**1.23 - * A simple GLSurfaceView sub-class that demonstrate how to perform1.24 - * OpenGL ES 2.0 rendering into a GL Surface. Note the following important1.25 - * details:1.26 - *1.27 - * - The class must use a custom context factory to enable 2.0 rendering.1.28 - * See ContextFactory class definition below.1.29 - *1.30 - * - The class must use a custom EGLConfigChooser to be able to select1.31 - * an EGLConfig that supports 2.0. This is done by providing a config1.32 - * specification to eglChooseConfig() that has the attribute1.33 - * EGL10.ELG_RENDERABLE_TYPE containing the EGL_OPENGL_ES2_BIT flag1.34 - * set. See ConfigChooser class definition below.1.35 - *1.36 - * - The class must select the surface's format, then choose an EGLConfig1.37 - * that matches it exactly (with regards to red/green/blue/alpha channels1.38 - * bit depths). Failure to do so would result in an EGL_BAD_MATCH error.1.39 - */1.40 -class LxdreamView extends GLSurfaceView {1.41 +class LxdreamView extends SurfaceView implements SurfaceHolder.Callback {1.42 private static String TAG = "LxdreamView";1.43 private static final boolean DEBUG = false;1.45 public LxdreamView(Context context) {1.46 super(context);1.47 - init(false, 0, 0);1.48 + getHolder().addCallback(this);1.49 }1.51 - public LxdreamView(Context context, boolean translucent, int depth, int stencil) {1.52 - super(context);1.53 - init(translucent, depth, stencil);1.54 + @Override1.55 + public void surfaceCreated( SurfaceHolder holder ) {1.56 + /* Ignore */1.57 }1.58 -1.59 - private void init(boolean translucent, int depth, int stencil) {1.60 -1.61 - /* By default, GLSurfaceView() creates a RGB_565 opaque surface.1.62 - * If we want a translucent one, we should change the surface's1.63 - * format here, using PixelFormat.TRANSLUCENT for GL Surfaces1.64 - * is interpreted as any 32-bit surface with alpha by SurfaceFlinger.1.65 - */1.66 - if (translucent) {1.67 - this.getHolder().setFormat(PixelFormat.TRANSLUCENT);1.68 - }1.69 -1.70 - /* Setup the context factory for 2.0 rendering.1.71 - * See ContextFactory class definition below1.72 - */1.73 - setEGLContextFactory(new ContextFactory());1.74 -1.75 - /* We need to choose an EGLConfig that matches the format of1.76 - * our surface exactly. This is going to be done in our1.77 - * custom config chooser. See ConfigChooser class definition1.78 - * below.1.79 - */1.80 - setEGLConfigChooser( translucent ?1.81 - new ConfigChooser(8, 8, 8, 8, depth, stencil) :1.82 - new ConfigChooser(5, 6, 5, 0, depth, stencil) );1.83 -1.84 - /* Set the renderer responsible for frame rendering */1.85 - setRenderer(new Renderer());1.86 +1.87 + @Override1.88 + public void surfaceChanged( SurfaceHolder holder, int format, int width, int height ) {1.89 + setSurface( holder.getSurface(), width, height );1.90 }1.91 -1.92 - private static class ContextFactory implements GLSurfaceView.EGLContextFactory {1.93 - private static int EGL_CONTEXT_CLIENT_VERSION = 0x3098;1.94 - public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) {1.95 - Log.w(TAG, "creating OpenGL ES 2.0 context");1.96 - checkEglError("Before eglCreateContext", egl);1.97 - int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };1.98 - EGLContext context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);1.99 - checkEglError("After eglCreateContext", egl);1.100 - return context;1.101 - }1.102 -1.103 - public void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context) {1.104 - egl.eglDestroyContext(display, context);1.105 - }1.106 +1.107 + @Override1.108 + public void surfaceDestroyed( SurfaceHolder holder ) {1.109 + clearSurface( holder.getSurface() );1.110 }1.111 -1.112 - private static void checkEglError(String prompt, EGL10 egl) {1.113 - int error;1.114 - while ((error = egl.eglGetError()) != EGL10.EGL_SUCCESS) {1.115 - Log.e(TAG, String.format("%s: EGL error: 0x%x", prompt, error));1.116 - }1.117 - }1.118 -1.119 -1.120 - private static class Renderer implements GLSurfaceView.Renderer {1.121 - public void onDrawFrame(GL10 gl) {1.122 - Dreamcast.run();1.123 - }1.124 -1.125 - public void onSurfaceChanged(GL10 gl, int width, int height) {1.126 - Dreamcast.setViewSize(width,height);1.127 - }1.128 -1.129 - public void onSurfaceCreated(GL10 gl, EGLConfig config) {1.130 - // Do nothing.1.131 - }1.132 - }1.133 +1.134 + private native void setSurface( Surface surface, int width, int height );1.135 + private native void clearSurface( Surface surface );1.136 +1.137 }
.