diff --git a/android/bifrost.c b/android/bifrost.c
index 8645006652..50bffa97ef 100644
--- a/android/bifrost.c
+++ b/android/bifrost.c
@@ -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);
+}
diff --git a/android/com_retroarch_rruntime.h b/android/com_retroarch_rruntime.h
index fe175336c4..293f7b99a2 100644
--- a/android/com_retroarch_rruntime.h
+++ b/android/com_retroarch_rruntime.h
@@ -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
diff --git a/android/jni/Android.mk b/android/jni/Android.mk
index e7f68fcb73..2ddcdb0d5a 100644
--- a/android/jni/Android.mk
+++ b/android/jni/Android.mk
@@ -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)
diff --git a/android/res/layout/main.xml b/android/res/layout/main.xml
index bc12cd8231..c51a388d09 100644
--- a/android/res/layout/main.xml
+++ b/android/res/layout/main.xml
@@ -4,9 +4,14 @@
android:layout_height="fill_parent"
android:orientation="vertical" >
+
-
\ No newline at end of file
+
diff --git a/android/src/com/retroarch/rruntime.java b/android/src/com/retroarch/rruntime.java
index 3d16dd2d72..bbb9afc6f1 100644
--- a/android/src/com/retroarch/rruntime.java
+++ b/android/src/com/retroarch/rruntime.java
@@ -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);
}
diff --git a/gfx/context/androidegl_ctx.c b/gfx/context/androidegl_ctx.c
index c9d9f0cfe5..baae97e56f 100644
--- a/gfx/context/androidegl_ctx.c
+++ b/gfx/context/androidegl_ctx.c
@@ -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,
diff --git a/gfx/gfx_context.h b/gfx/gfx_context.h
index 92c5d3f7a1..5a5dae5983 100644
--- a/gfx/gfx_context.h
+++ b/gfx/gfx_context.h
@@ -23,6 +23,12 @@
#include "../config.h"
#endif
+#ifdef ANDROID
+#include
+#include /* Requires NDK r5 or newer */
+#include /* 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);