From 73194640a06ce6cc8219db79b9d5fc401566ecff Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 14 Oct 2012 01:49:15 +0200 Subject: [PATCH] Revert "(Android) Renamed GUI to RetroArch Android - Phoenix will be Java-only," This reverts commit ad27bedcb49b6c41e84e3c5087f6f58307aca094. --- android/bifrost.c | 24 ++- android/src/com/retroarch/audio_android.java | 146 +++++++++++++++++++ android/src/com/retroarch/main.java | 15 ++ android/src/com/retroarch/rgl.java | 111 ++++++++++++++ android/src/com/retroarch/rruntime.java | 54 +++++++ gfx/context/androidegl_ctx.c | 21 +-- 6 files changed, 356 insertions(+), 15 deletions(-) create mode 100644 android/src/com/retroarch/audio_android.java create mode 100644 android/src/com/retroarch/rgl.java create mode 100644 android/src/com/retroarch/rruntime.java diff --git a/android/bifrost.c b/android/bifrost.c index fd4bb3a19c..50bffa97ef 100644 --- a/android/bifrost.c +++ b/android/bifrost.c @@ -38,36 +38,58 @@ JNIEXPORT jint JNICALL JNI_OnLoad( JavaVM *vm, void *pvt) { + RARCH_LOG("JNI_OnLoad.\n" ); + rarch_main_clear_state(); config_set_defaults(); input_null.init(); + RARCH_LOG("JNI_OnLoad #1.\n" ); + const input_driver_t *input = &input_null; bool find_libretro_file = false; snprintf(default_paths.config_file, sizeof(default_paths.config_file), "/mnt/extsd/retroarch.cfg"); + RARCH_LOG("JNI_OnLoad #1.1.\n" ); + rarch_init_msg_queue(); + RARCH_LOG("JNI_OnLoad #1.2.\n" ); + rarch_settings_set_default(); + RARCH_LOG("JNI_OnLoad #1.3.\n" ); //rarch_input_set_controls_default(input); rarch_config_load(default_paths.config_file, find_libretro_file); + RARCH_LOG("JNI_OnLoad #1.4.\n" ); init_libretro_sym(); + RARCH_LOG("JNI_OnLoad #1.5.\n" ); + + input_null.post_init(); + RARCH_LOG("JNI_OnLoad #1.6.\n" ); //video_gl.start(); + + RARCH_LOG("JNI_OnLoad #1.7.\n" ); + //driver.video = &video_gl; + RARCH_LOG("JNI_OnLoad #1.8.\n" ); + + RARCH_LOG("Reached end of JNI_OnLoad.\n" ); + return JNI_VERSION_1_2; } JNIEXPORT void JNICALL JNI_OnUnLoad( JavaVM *vm, void *pvt) { + RARCH_LOG("JNI_OnUnLoad.\n" ); } JNIEXPORT void JNICALL Java_com_retroarch_rruntime_load_1game @@ -136,7 +158,7 @@ JNIEXPORT void JNICALL Java_com_retroarch_rruntime_settings_1change JNIEXPORT void JNICALL Java_com_retroarch_rruntime_settings_1set_1defaults (JNIEnv *env, jclass class) { - RARCH_LOG("rruntime_settings_set_defaults.\n" ); + RARCH_LOG("* rruntime_settings_set_defaults.\n" ); rarch_settings_set_default(); } diff --git a/android/src/com/retroarch/audio_android.java b/android/src/com/retroarch/audio_android.java new file mode 100644 index 0000000000..1ebe9d8bbf --- /dev/null +++ b/android/src/com/retroarch/audio_android.java @@ -0,0 +1,146 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * Copyright (C) 2011-2012 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +package com.retroarch; + +import android.media.AudioFormat; +import android.media.AudioManager; +import android.media.AudioTrack; + +public class audio_android +{ + private static AudioTrack _track; + private static int _minSamples; + private static float _volume = AudioTrack.getMaxVolume(); + + private static int _rate; + private static int _bits; + private static int _channels; + + + private audio_android() + { + + } + + + public static void pause() + { + if (_track != null && _track.getPlayState() != AudioTrack.PLAYSTATE_PAUSED) + _track.pause(); + } + + + public static void resume() + { + if (_track != null && _track.getPlayState() != AudioTrack.PLAYSTATE_PLAYING) + _track.play(); + } + + public int getMinSamples() + { + return _minSamples; + } + + + public static int write(short[] data, int size) + { + int retVal = 0; + if (_track == null) + return retVal; + + retVal = _track.write(data, 0, size); + + return retVal; + } + + + void set_volume(int vol) + { + final float min = AudioTrack.getMinVolume(); + final float max = AudioTrack.getMaxVolume(); + _volume = min + (max - min) * vol / 100; + + if (_track != null) + _track.setStereoVolume(_volume, _volume); + } + + + public static void free() + { + if (_track != null) + { + _track.pause(); + _track.release(); + _track = null; + } + } + + + public static boolean init(int rate, int bits, int channels) + { + _track = null; + _rate = rate; + _bits = bits; + _channels = channels; + + // generate format + int format = (_bits == 16 + ? AudioFormat.ENCODING_PCM_16BIT + : AudioFormat.ENCODING_PCM_8BIT); + + // determine channel config + int channelConfig = (_channels == 2 + ? AudioFormat.CHANNEL_OUT_STEREO + : AudioFormat.CHANNEL_OUT_MONO); + + int bufferSize = AudioTrack.getMinBufferSize(_rate, channelConfig, + format); + + _minSamples = bufferSize; + + try + { + _track = new AudioTrack( + AudioManager.STREAM_MUSIC, + _rate, + channelConfig, + format, + bufferSize, + AudioTrack.MODE_STREAM); + + if (_track.getState() == AudioTrack.STATE_UNINITIALIZED) + _track = null; + + } + catch (IllegalArgumentException e) + { + _track = null; + return false; + } + + // set max volume + _track.setStereoVolume(_volume, _volume); + + return true; + } + + + public static int getMaxBufferSize() + { + return _minSamples; + } +} diff --git a/android/src/com/retroarch/main.java b/android/src/com/retroarch/main.java index 9d9125f7a1..5f55c62091 100644 --- a/android/src/com/retroarch/main.java +++ b/android/src/com/retroarch/main.java @@ -34,6 +34,7 @@ public class main extends Activity { static private final int ACTIVITY_LOAD_ROM = 0; + private GLSurfaceView ctx_gl; @Override public void onCreate(Bundle savedInstanceState) @@ -41,6 +42,8 @@ public class main extends Activity super.onCreate(savedInstanceState); this.setTitle("RetroArch | Main"); + ctx_gl = new rgl_context(this); + setContentView(ctx_gl); } public boolean onCreateOptionsMenu(Menu menu) @@ -89,11 +92,23 @@ public class main extends Activity protected void onPause() { super.onPause(); + ctx_gl.onPause(); } @Override protected void onResume() { super.onResume(); + ctx_gl.onResume(); } } + +class rgl_context extends GLSurfaceView +{ + public rgl_context(Context context) + { + super(context); + setEGLContextClientVersion(2); + setRenderer(new rgl()); + } +} diff --git a/android/src/com/retroarch/rgl.java b/android/src/com/retroarch/rgl.java new file mode 100644 index 0000000000..b4080ecfd5 --- /dev/null +++ b/android/src/com/retroarch/rgl.java @@ -0,0 +1,111 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * Copyright (C) 2011-2012 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +package com.retroarch; + +import java.nio.ByteBuffer; +import java.nio.FloatBuffer; +import java.nio.ByteOrder; + +import javax.microedition.khronos.egl.EGLConfig; +import javax.microedition.khronos.opengles.GL10; + +import android.opengl.GLES20; +import android.opengl.GLSurfaceView; + +public class rgl implements GLSurfaceView.Renderer +{ + private int cprg; + private int v_position_handle; + private FloatBuffer triangle_vbo; + + private void triangles_init() + { + float triangle_coords[] = { + // X, Y, Z + -0.5f, -0.25f, 0, + 0.5f, -0.25f, 0, + 0.0f, 0.559016994f, 0 + }; + + ByteBuffer vbb = ByteBuffer.allocateDirect(triangle_coords.length * 4); + vbb.order(ByteOrder.nativeOrder()); + triangle_vbo = vbb.asFloatBuffer(); + triangle_vbo.put(triangle_coords); + triangle_vbo.position(0); + } + + private void shader_init() + { + final String vprg = + "attribute vec4 vPosition; \n" + + "void main(){ \n" + + " gl_Position = vPosition; \n" + + "} \n"; + final String fprg = + "precision mediump float; \n" + + "void main(){ \n" + + " gl_FragColor = vec4 (0.63671875, 0.76953125, 0.22265625, 1.0); \n" + + "} \n"; + + int vertex_shader, fragment_shader; + + vertex_shader = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER); + + GLES20.glShaderSource(vertex_shader, vprg); + GLES20.glCompileShader(vertex_shader); + + fragment_shader = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER); + + GLES20.glShaderSource(fragment_shader, fprg); + GLES20.glCompileShader(fragment_shader); + + cprg = GLES20.glCreateProgram(); + GLES20.glAttachShader(cprg, vertex_shader); + GLES20.glAttachShader(cprg, fragment_shader); + GLES20.glLinkProgram(cprg); + + //get handle to the vertex shader's vPosition member + v_position_handle = GLES20.glGetAttribLocation(cprg, "vPosition"); +; } + + public void onSurfaceCreated(GL10 unused, EGLConfig config) + { + //background color + GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f); + + triangles_init(); + shader_init(); + } + + public void onDrawFrame(GL10 unused) + { + GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); + + GLES20.glUseProgram(cprg); + + // Triangle + GLES20.glVertexAttribPointer(v_position_handle, 3, GLES20.GL_FLOAT, false, 12, triangle_vbo); + GLES20.glEnableVertexAttribArray(v_position_handle); + + GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 3); + } + + public void onSurfaceChanged(GL10 unused, int width, int height) + { + GLES20.glViewport(0, 0, width, height); + } +} diff --git a/android/src/com/retroarch/rruntime.java b/android/src/com/retroarch/rruntime.java new file mode 100644 index 0000000000..bbb9afc6f1 --- /dev/null +++ b/android/src/com/retroarch/rruntime.java @@ -0,0 +1,54 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * Copyright (C) 2011-2012 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +package com.retroarch; + +import android.view.Surface; +import android.view.SurfaceView; +import android.view.SurfaceHolder; + +public class rruntime +{ + static + { + System.loadLibrary("retroarch"); + } + + private rruntime() + { + + } + + public static native void load_game(final String j_path, final int j_extract_zip_mode); + + public static native boolean run_frame(); + + public static native void startup(String j_config_path); + + public static native void deinit(); + + public static native void load_state(); + + public static native void save_state(); + + public static native void settings_change(final int j_setting); + + public static native void settings_set_defaults(); + + public static native void set_window(SurfaceHolder surface); + + public static native void free_window(SurfaceHolder surface); +} diff --git a/gfx/context/androidegl_ctx.c b/gfx/context/androidegl_ctx.c index d12b0438ba..baae97e56f 100644 --- a/gfx/context/androidegl_ctx.c +++ b/gfx/context/androidegl_ctx.c @@ -17,8 +17,6 @@ #include "../../driver.h" #include "../gl_common.h" -#include - #include /* Requires NDK r5 or newer */ #include @@ -32,7 +30,7 @@ enum RenderThreadMessage { enum RenderThreadMessage _msg; -EGLNativeWindowType window; /* Requires NDK r5 or newer */ +ANativeWindow *window; /* Requires NDK r5 or newer */ static EGLContext g_egl_ctx; static EGLSurface g_egl_surf; @@ -92,8 +90,6 @@ static void gfx_ctx_destroy(void) _height = 0; } -EGLNativeWindowType android_createDisplaySurface(void); - static bool gfx_ctx_init(void) { const EGLint attribs[] = { @@ -117,8 +113,6 @@ static bool gfx_ctx_init(void) return false; } - window = NULL; - EGLint egl_major, egl_minor; if (!eglInitialize(g_egl_dpy, &egl_major, &egl_minor)) { RARCH_ERR("eglInitialize() returned error %d.\n", eglGetError()); @@ -140,11 +134,7 @@ static bool gfx_ctx_init(void) return false; } - if (!(g_egl_ctx = eglCreateContext(g_egl_dpy, config, 0, 0))) { - RARCH_ERR("eglCreateContext() returned error %d.\n", eglGetError()); - gfx_ctx_destroy(); - return false; - } + ANativeWindow_setBuffersGeometry(window, 0, 0, format); if (!(g_egl_surf = eglCreateWindowSurface(g_egl_dpy, config, window, 0))) { RARCH_ERR("eglCreateWindowSurface() returned error %d.\n", eglGetError()); @@ -152,6 +142,11 @@ static bool gfx_ctx_init(void) return false; } + if (!(g_egl_ctx = eglCreateContext(g_egl_dpy, config, 0, 0))) { + RARCH_ERR("eglCreateContext() returned error %d.\n", eglGetError()); + gfx_ctx_destroy(); + return false; + } if (!eglMakeCurrent(g_egl_dpy, g_egl_surf, g_egl_surf, g_egl_ctx)) { RARCH_ERR("eglMakeCurrent() returned error %d.\n", eglGetError()); @@ -169,8 +164,6 @@ static bool gfx_ctx_init(void) _width = width; _height = height; - RARCH_LOG("Window specs: %d*%d.\n", _width, _height); - /* glDisable(GL_DITHER); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);