(Android) Add some initial funtions for setting native window

This commit is contained in:
twinaphex 2012-10-06 06:51:42 +02:00
parent 2c1980b7b0
commit 350b15b0f2
7 changed files with 73 additions and 5 deletions

View File

@ -161,3 +161,18 @@ JNIEXPORT void JNICALL Java_com_retroarch_rruntime_settings_1set_1defaults
RARCH_LOG("* rruntime_settings_set_defaults.\n" );
rarch_settings_set_default();
}
void gfx_ctx_set_window(JNIEnv *jenv,jobject obj, jobject surface);
void gfx_ctx_free_window(JNIEnv *jenv,jobject obj, jobject surface);
JNIEXPORT void JNICALL Java_com_retroarch_rruntime_set_window
(JNIEnv *env, jclass class, jobject obj, jobject surface)
{
gfx_ctx_set_window(env, obj, surface);
}
JNIEXPORT void JNICALL Java_com_retroarch_rruntime_free_window
(JNIEnv *env, jclass class, jobject obj, jobject surface)
{
gfx_ctx_free_window(env, obj, surface);
}

View File

@ -71,6 +71,22 @@ JNIEXPORT void JNICALL Java_com_retroarch_rruntime_settings_1change
JNIEXPORT void JNICALL Java_com_retroarch_rruntime_settings_1set_1defaults
(JNIEnv *, jclass);
/*
* Class: com_retroarch_rruntime
* Method: set_window
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_retroarch_rruntime_set_window
(JNIEnv *, jclass, jobject, jobject);
/*
* Class: com_retroarch_rruntime
* Method: free_window
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_retroarch_rruntime_free_window
(JNIEnv *, jclass, jobject, jobject);
#ifdef __cplusplus
}
#endif

View File

@ -10,6 +10,6 @@ LOCAL_SRC_FILES = ../../console/griffin/griffin.c ../../console/rzlib/rzlib.c
LOCAL_CFLAGS = -DPERF_TEST -marm -DANDROID -DHAVE_DYNAMIC -DHAVE_DYLIB -DHAVE_OPENGL -DHAVE_OPENGLES -DHAVE_OPENGLES2 -DHAVE_GLSL -DHAVE_VID_CONTEXT -DHAVE_ZLIB -DHAVE_RARCH_MAIN_WRAP -DINLINE=inline -DRARCH_CONSOLE -DLSB_FIRST -D__LIBRETRO__ -DHAVE_CONFIGFILE=1 -DHAVE_GRIFFIN=1 -DPACKAGE_VERSION=\"$(RARCH_VERSION)\" -Dmain=rarch_main -std=gnu99
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -landroid -lEGL -lGLESv2 -llog -ldl
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -landroid -lEGL -lGLESv2 -llog -ldl -lz
include $(BUILD_SHARED_LIBRARY)

View File

@ -4,9 +4,14 @@
android:layout_height="fill_parent"
android:orientation="vertical" >
<SurfaceView
android:id="@+id/surfaceview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>
</LinearLayout>

View File

@ -16,6 +16,10 @@
package com.retroarch;
import android.view.Surface;
import android.view.SurfaceView;
import android.view.SurfaceHolder;
public class rruntime
{
static
@ -43,4 +47,8 @@ public class rruntime
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);
}

View File

@ -30,7 +30,7 @@ enum RenderThreadMessage {
enum RenderThreadMessage _msg;
ANativeWindow* _window; /* Requires NDK r5 or newer */
ANativeWindow *window; /* Requires NDK r5 or newer */
static EGLContext g_egl_ctx;
static EGLSurface g_egl_surf;
@ -134,9 +134,9 @@ static bool gfx_ctx_init(void)
return false;
}
ANativeWindow_setBuffersGeometry(_window, 0, 0, format);
ANativeWindow_setBuffersGeometry(window, 0, 0, format);
if (!(g_egl_surf = eglCreateWindowSurface(g_egl_dpy, config, _window, 0))) {
if (!(g_egl_surf = eglCreateWindowSurface(g_egl_dpy, config, window, 0))) {
RARCH_ERR("eglCreateWindowSurface() returned error %d.\n", eglGetError());
gfx_ctx_destroy();
return false;
@ -233,6 +233,16 @@ static void gfx_ctx_update_window_title(bool reset)
(void)reset;
}
void gfx_ctx_set_window(JNIEnv *jenv,jobject obj, jobject surface)
{
window = ANativeWindow_fromSurface(jenv, surface);
}
void gfx_ctx_free_window(JNIEnv *jenv,jobject obj, jobject surface)
{
ANativeWindow_release(window);
}
static void gfx_ctx_get_video_size(unsigned *width, unsigned *height)
{
(void)width;
@ -319,6 +329,10 @@ const gfx_ctx_driver_t gfx_ctx_android = {
NULL,
gfx_ctx_update_window_title,
gfx_ctx_check_window,
#ifdef ANDROID
gfx_ctx_set_window,
gfx_ctx_free_window,
#endif
gfx_ctx_set_resize,
gfx_ctx_has_focus,
gfx_ctx_swap_buffers,

View File

@ -23,6 +23,12 @@
#include "../config.h"
#endif
#ifdef ANDROID
#include <jni.h>
#include <android/native_window.h> /* Requires NDK r5 or newer */
#include <android/native_window_jni.h> /* Requires NDK r5 or newer */
#endif
enum gfx_ctx_api
{
GFX_CTX_OPENGL_API,
@ -63,6 +69,10 @@ typedef struct gfx_ctx_driver
// Queries for resize and quit events.
// Also processes events.
void (*check_window)(bool*, bool*, unsigned*, unsigned*, unsigned);
#ifdef ANDROID
void (*gfx_ctx_set_window)(JNIEnv *jenv,jobject obj, jobject surface);
void (*gfx_ctx_free_window)(JNIEnv *jenv,jobject obj, jobject surface);
#endif
// Acknowledge a resize event. This is needed for some APIs. Most backends will ignore this.
void (*set_resize)(unsigned, unsigned);