wineandroid: Register a JNI callback for reporting desktop size changes.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2017-05-31 11:47:49 +02:00
parent 2ecca01008
commit 77d55905b1
3 changed files with 92 additions and 0 deletions

View File

@ -25,6 +25,7 @@
#include <stdarg.h>
#include <stdlib.h>
#include <jni.h>
#include <android/log.h>
#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);

View File

@ -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;
}

View File

@ -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
*/