From 77d55905b1ee712d09e0e3ce7d6ddde46bde4cf5 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 31 May 2017 11:47:49 +0200 Subject: [PATCH] wineandroid: Register a JNI callback for reporting desktop size changes. Signed-off-by: Alexandre Julliard --- dlls/wineandroid.drv/android.h | 13 +++++++ dlls/wineandroid.drv/init.c | 68 ++++++++++++++++++++++++++++++++++ dlls/wineandroid.drv/window.c | 11 ++++++ 3 files changed, 92 insertions(+) diff --git a/dlls/wineandroid.drv/android.h b/dlls/wineandroid.drv/android.h index 7c708f3699..ab4a431cc3 100644 --- a/dlls/wineandroid.drv/android.h +++ b/dlls/wineandroid.drv/android.h @@ -25,6 +25,7 @@ #include #include #include +#include #include "windef.h" #include "winbase.h" @@ -33,6 +34,15 @@ #include "wine/gdi_driver.h" +/************************************************************************** + * Android interface + */ + +#define DECL_FUNCPTR(f) extern typeof(f) * p##f DECLSPEC_HIDDEN +DECL_FUNCPTR( __android_log_print ); +#undef DECL_FUNCPTR + + /************************************************************************** * USER driver */ @@ -44,6 +54,9 @@ extern MONITORINFOEXW default_monitor DECLSPEC_HIDDEN; extern void init_monitors( int width, int height ) DECLSPEC_HIDDEN; +/* JNI entry points */ +extern void desktop_changed( JNIEnv *env, jobject obj, jint width, jint height ) DECLSPEC_HIDDEN; + extern JavaVM *wine_get_java_vm(void); extern jobject wine_get_java_object(void); diff --git a/dlls/wineandroid.drv/init.c b/dlls/wineandroid.drv/init.c index 3a3ce80b5b..406edf911d 100644 --- a/dlls/wineandroid.drv/init.c +++ b/dlls/wineandroid.drv/init.c @@ -385,3 +385,71 @@ const struct gdi_dc_funcs * CDECL ANDROID_get_gdi_driver( unsigned int version ) } return &android_drv_funcs; } + + +static const JNINativeMethod methods[] = +{ + { "wine_desktop_changed", "(II)V", desktop_changed }, +}; + +#define DECL_FUNCPTR(f) typeof(f) * p##f = NULL +#define LOAD_FUNCPTR(lib, func) do { \ + if ((p##func = wine_dlsym( lib, #func, NULL, 0 )) == NULL) \ + { ERR( "can't find symbol %s\n", #func); return; } \ + } while(0) + +DECL_FUNCPTR( __android_log_print ); + +static void load_android_libs(void) +{ + void *liblog; + char error[1024]; + + if (!(liblog = wine_dlopen( "liblog.so", RTLD_GLOBAL, error, sizeof(error) ))) + { + ERR( "failed to load liblog.so: %s\n", error ); + return; + } + LOAD_FUNCPTR( liblog, __android_log_print ); +} + +#undef DECL_FUNCPTR +#undef LOAD_FUNCPTR + +static BOOL process_attach(void) +{ + jclass class; + jobject object = wine_get_java_object(); + JNIEnv *jni_env; + JavaVM *java_vm; + + if ((java_vm = wine_get_java_vm())) /* running under Java */ + { +#ifdef __i386__ + WORD old_fs = wine_get_fs(); +#endif + load_android_libs(); + (*java_vm)->AttachCurrentThread( java_vm, &jni_env, 0 ); + class = (*jni_env)->GetObjectClass( jni_env, object ); + (*jni_env)->RegisterNatives( jni_env, class, methods, sizeof(methods)/sizeof(methods[0]) ); + (*jni_env)->DeleteLocalRef( jni_env, class ); +#ifdef __i386__ + wine_set_fs( old_fs ); /* the Java VM hijacks %fs for its own purposes, restore it */ +#endif + } + return TRUE; +} + +/*********************************************************************** + * dll initialisation routine + */ +BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved ) +{ + switch (reason) + { + case DLL_PROCESS_ATTACH: + DisableThreadLibraryCalls( inst ); + return process_attach(); + } + return TRUE; +} diff --git a/dlls/wineandroid.drv/window.c b/dlls/wineandroid.drv/window.c index f8744587ed..e7c83b09b0 100644 --- a/dlls/wineandroid.drv/window.c +++ b/dlls/wineandroid.drv/window.c @@ -133,6 +133,17 @@ static void release_win_data( struct android_win_data *data ) } +/*********************************************************************** + * desktop_changed + * + * JNI callback, runs in the context of the Java thread. + */ +void desktop_changed( JNIEnv *env, jobject obj, jint width, jint height ) +{ + p__android_log_print( ANDROID_LOG_INFO, "wine", "desktop_changed: %ux%u", width, height ); +} + + /*********************************************************************** * ANDROID_DestroyWindow */