mirror of
https://github.com/libretro/RetroArch
synced 2025-03-25 16:44:01 +00:00
(Android) Make RetroActivity invoke JNI_OnLoad - grab pointer to
RetroActivity class - try to use from camera/android.c
This commit is contained in:
parent
7231fdfa40
commit
21bc30a44c
@ -1,12 +1,15 @@
|
|||||||
package com.retroarch.browser;
|
package com.retroarch.browser;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.retroarch.browser.preferences.util.UserPreferences;
|
import com.retroarch.browser.preferences.util.UserPreferences;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.NativeActivity;
|
import android.app.NativeActivity;
|
||||||
import android.graphics.SurfaceTexture;
|
import android.graphics.SurfaceTexture;
|
||||||
import android.hardware.Camera;
|
import android.hardware.Camera;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
public final class RetroActivity extends NativeActivity
|
public final class RetroActivity extends NativeActivity
|
||||||
{
|
{
|
||||||
@ -14,6 +17,15 @@ public final class RetroActivity extends NativeActivity
|
|||||||
private long lastTimestamp = 0;
|
private long lastTimestamp = 0;
|
||||||
private SurfaceTexture texture;
|
private SurfaceTexture texture;
|
||||||
|
|
||||||
|
static {
|
||||||
|
System.loadLibrary("retroarch-activity");
|
||||||
|
}
|
||||||
|
|
||||||
|
public RetroActivity() {
|
||||||
|
super();
|
||||||
|
Log.i("RetroActivity", "Creating MyNativeActivity");
|
||||||
|
}
|
||||||
|
|
||||||
public void onCameraStart()
|
public void onCameraStart()
|
||||||
{
|
{
|
||||||
mCamera.startPreview();
|
mCamera.startPreview();
|
||||||
|
@ -29,7 +29,6 @@ typedef struct android_camera
|
|||||||
{
|
{
|
||||||
JNIEnv *env;
|
JNIEnv *env;
|
||||||
JavaVM *java_vm;
|
JavaVM *java_vm;
|
||||||
jclass class; // RetroActivity class
|
|
||||||
GLuint tex;
|
GLuint tex;
|
||||||
} androidcamera_t;
|
} androidcamera_t;
|
||||||
|
|
||||||
@ -53,15 +52,12 @@ static void *android_camera_init(const char *device, uint64_t caps, unsigned wid
|
|||||||
androidcamera->java_vm = (JavaVM*)android_app->activity->vm;
|
androidcamera->java_vm = (JavaVM*)android_app->activity->vm;
|
||||||
(*androidcamera->java_vm)->AttachCurrentThread(androidcamera->java_vm, &androidcamera->env, 0);
|
(*androidcamera->java_vm)->AttachCurrentThread(androidcamera->java_vm, &androidcamera->env, 0);
|
||||||
|
|
||||||
GET_OBJECT_CLASS(androidcamera->env, androidcamera->class, android_app->activity->clazz);
|
|
||||||
|
|
||||||
|
|
||||||
jmethodID onCameraInit = NULL;
|
jmethodID onCameraInit = NULL;
|
||||||
GET_METHOD_ID(androidcamera->env, onCameraInit, androidcamera->class, "onCameraInit", "()V");
|
GET_METHOD_ID(androidcamera->env, onCameraInit, globalMyNativeActivityClass, "onCameraInit", "()V");
|
||||||
if (!onCameraInit)
|
if (!onCameraInit)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
CALL_VOID_METHOD(androidcamera->env, androidcamera->class, onCameraInit);
|
CALL_VOID_METHOD(androidcamera->env, globalMyNativeActivityClass, onCameraInit);
|
||||||
|
|
||||||
return androidcamera;
|
return androidcamera;
|
||||||
}
|
}
|
||||||
@ -73,11 +69,11 @@ static void android_camera_free(void *data)
|
|||||||
(void)android_app;
|
(void)android_app;
|
||||||
|
|
||||||
jmethodID onCameraFree = NULL;
|
jmethodID onCameraFree = NULL;
|
||||||
GET_METHOD_ID(androidcamera->env, onCameraFree, androidcamera->class, "onCameraFree", "()V");
|
GET_METHOD_ID(androidcamera->env, onCameraFree, globalMyNativeActivityClass, "onCameraFree", "()V");
|
||||||
if (!onCameraFree)
|
if (!onCameraFree)
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
CALL_VOID_METHOD(androidcamera->env, androidcamera->class, onCameraFree);
|
CALL_VOID_METHOD(androidcamera->env, globalMyNativeActivityClass, onCameraFree);
|
||||||
|
|
||||||
end:
|
end:
|
||||||
(*androidcamera->java_vm)->DetachCurrentThread(androidcamera->java_vm);
|
(*androidcamera->java_vm)->DetachCurrentThread(androidcamera->java_vm);
|
||||||
@ -96,18 +92,18 @@ static bool android_camera_start(void *data)
|
|||||||
glGenTextures(1, &androidcamera->tex);
|
glGenTextures(1, &androidcamera->tex);
|
||||||
|
|
||||||
jmethodID onCameraSetTexture = NULL;
|
jmethodID onCameraSetTexture = NULL;
|
||||||
GET_METHOD_ID(androidcamera->env, onCameraSetTexture, androidcamera->class, "onCameraSetTexture", "(I)V");
|
GET_METHOD_ID(androidcamera->env, onCameraSetTexture, globalMyNativeActivityClass, "onCameraSetTexture", "(I)V");
|
||||||
if (!onCameraSetTexture)
|
if (!onCameraSetTexture)
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
CALL_VOID_METHOD_PARAM(androidcamera->env, androidcamera->class, onCameraSetTexture, (int) androidcamera->tex);
|
CALL_VOID_METHOD_PARAM(androidcamera->env, globalMyNativeActivityClass, onCameraSetTexture, (int) androidcamera->tex);
|
||||||
|
|
||||||
jmethodID onCameraStart = NULL;
|
jmethodID onCameraStart = NULL;
|
||||||
GET_METHOD_ID(androidcamera->env, onCameraSetTexture, androidcamera->class, "onCameraStart", "()V");
|
GET_METHOD_ID(androidcamera->env, onCameraSetTexture, globalMyNativeActivityClass, "onCameraStart", "()V");
|
||||||
if (!onCameraStart)
|
if (!onCameraStart)
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
CALL_VOID_METHOD(androidcamera->env, androidcamera->class, onCameraStart);
|
CALL_VOID_METHOD(androidcamera->env, globalMyNativeActivityClass, onCameraStart);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -123,11 +119,11 @@ static void android_camera_stop(void *data)
|
|||||||
(void)androidcamera;
|
(void)androidcamera;
|
||||||
|
|
||||||
jmethodID onCameraStop = NULL;
|
jmethodID onCameraStop = NULL;
|
||||||
GET_METHOD_ID(androidcamera->env, onCameraStop, androidcamera->class, "onCameraStop", "()V");
|
GET_METHOD_ID(androidcamera->env, onCameraStop, globalMyNativeActivityClass, "onCameraStop", "()V");
|
||||||
if (!onCameraStop)
|
if (!onCameraStop)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CALL_VOID_METHOD(androidcamera->env, androidcamera->class, onCameraStop);
|
CALL_VOID_METHOD(androidcamera->env, globalMyNativeActivityClass, onCameraStop);
|
||||||
|
|
||||||
if (androidcamera->tex)
|
if (androidcamera->tex)
|
||||||
glDeleteTextures(1, &androidcamera->tex);
|
glDeleteTextures(1, &androidcamera->tex);
|
||||||
@ -143,12 +139,12 @@ static bool android_camera_poll(void *data, retro_camera_frame_raw_framebuffer_t
|
|||||||
(void)frame_raw_cb;
|
(void)frame_raw_cb;
|
||||||
|
|
||||||
jmethodID onCameraPoll = NULL;
|
jmethodID onCameraPoll = NULL;
|
||||||
GET_METHOD_ID(androidcamera->env, onCameraPoll, androidcamera->class, "onCameraPoll", "()Z");
|
GET_METHOD_ID(androidcamera->env, onCameraPoll, globalMyNativeActivityClass, "onCameraPoll", "()Z");
|
||||||
if (!onCameraPoll)
|
if (!onCameraPoll)
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
jboolean newFrame;
|
jboolean newFrame;
|
||||||
CALL_BOOLEAN_METHOD(androidcamera->env, newFrame, androidcamera->class, onCameraPoll);
|
CALL_BOOLEAN_METHOD(androidcamera->env, newFrame, globalMyNativeActivityClass, onCameraPoll);
|
||||||
|
|
||||||
if (newFrame)
|
if (newFrame)
|
||||||
{
|
{
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include "../../file.h"
|
#include "../../file.h"
|
||||||
|
|
||||||
struct android_app *g_android;
|
struct android_app *g_android;
|
||||||
|
jclass globalMyNativeActivityClass;
|
||||||
|
|
||||||
//forward decls
|
//forward decls
|
||||||
static void system_deinit(void *data);
|
static void system_deinit(void *data);
|
||||||
@ -375,6 +376,18 @@ static void system_shutdown(bool unused)
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jint JNI_OnLoad(JavaVM* vm, void* reserved)
|
||||||
|
{
|
||||||
|
RARCH_LOG("JNI_OnLoad.\n");
|
||||||
|
JNIEnv* env;
|
||||||
|
if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_6) != JNI_OK)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
globalMyNativeActivityClass = (*env)->NewGlobalRef(env, (*env)->FindClass(env, "com/retroarch/browser/RetroActivity"));
|
||||||
|
|
||||||
|
return JNI_VERSION_1_6;
|
||||||
|
}
|
||||||
|
|
||||||
const frontend_ctx_driver_t frontend_ctx_android = {
|
const frontend_ctx_driver_t frontend_ctx_android = {
|
||||||
get_environment_settings, /* get_environment_settings */
|
get_environment_settings, /* get_environment_settings */
|
||||||
system_init, /* init */
|
system_init, /* init */
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
#include "../../thread.h"
|
#include "../../thread.h"
|
||||||
|
|
||||||
|
extern jclass globalMyNativeActivityClass;
|
||||||
|
|
||||||
struct android_app
|
struct android_app
|
||||||
{
|
{
|
||||||
ANativeActivity* activity;
|
ANativeActivity* activity;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user