From: Jacek Caban jacek@codeweavers.com
Signed-off-by: Jacek Caban jacek@codeweavers.com --- dlls/wineandroid.drv/Makefile.in | 5 +++-- dlls/wineandroid.drv/android.h | 2 ++ dlls/wineandroid.drv/init.c | 6 ++++++ dlls/wineandroid.drv/opengl.c | 25 +++++++++---------------- 4 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/dlls/wineandroid.drv/Makefile.in b/dlls/wineandroid.drv/Makefile.in index 3f9a16bea4f..5426fc75b94 100644 --- a/dlls/wineandroid.drv/Makefile.in +++ b/dlls/wineandroid.drv/Makefile.in @@ -1,6 +1,7 @@ EXTRADEFS = -DWINE_NO_LONG_TYPES -MODULE = wineandroid.drv -IMPORTS = user32 ntoskrnl win32u +MODULE = wineandroid.drv +IMPORTS = user32 ntoskrnl win32u +EXTRALIBS = $(PTHREAD_LIBS)
EXTRADLLFLAGS = -mcygwin
diff --git a/dlls/wineandroid.drv/android.h b/dlls/wineandroid.drv/android.h index 91f6dc83791..4348818aaf2 100644 --- a/dlls/wineandroid.drv/android.h +++ b/dlls/wineandroid.drv/android.h @@ -24,6 +24,7 @@ #include <limits.h> #include <stdarg.h> #include <stdlib.h> +#include <pthread.h> #include <jni.h> #include <android/log.h> #include <android/input.h> @@ -51,6 +52,7 @@ DECL_FUNCPTR( ANativeWindow_release ); * OpenGL driver */
+extern pthread_mutex_t drawable_mutex DECLSPEC_HIDDEN; extern void update_gl_drawable( HWND hwnd ) DECLSPEC_HIDDEN; extern void destroy_gl_drawable( HWND hwnd ) DECLSPEC_HIDDEN; extern struct opengl_funcs *get_wgl_driver( UINT version ) DECLSPEC_HIDDEN; diff --git a/dlls/wineandroid.drv/init.c b/dlls/wineandroid.drv/init.c index f06eb6471c5..33acb4376c5 100644 --- a/dlls/wineandroid.drv/init.c +++ b/dlls/wineandroid.drv/init.c @@ -558,6 +558,7 @@ unsigned short *p_java_gdt_sel = NULL;
static BOOL process_attach(void) { + pthread_mutexattr_t attr; jclass class; jobject object; JNIEnv *jni_env; @@ -574,6 +575,11 @@ static BOOL process_attach(void)
load_hardware_libs();
+ pthread_mutexattr_init( &attr ); + pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_RECURSIVE ); + pthread_mutex_init( &drawable_mutex, &attr ); + pthread_mutexattr_destroy( &attr ); + if ((java_vm = *p_java_vm)) /* running under Java */ { #ifdef __i386__ diff --git a/dlls/wineandroid.drv/opengl.c b/dlls/wineandroid.drv/opengl.c index afd1ef3f7a5..0c4f14e7cff 100644 --- a/dlls/wineandroid.drv/opengl.c +++ b/dlls/wineandroid.drv/opengl.c @@ -105,14 +105,7 @@ static struct list gl_drawables = LIST_INIT( gl_drawables ); static void (*pglFinish)(void); static void (*pglFlush)(void);
-static CRITICAL_SECTION drawable_section; -static CRITICAL_SECTION_DEBUG critsect_debug = -{ - 0, 0, &drawable_section, - { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList }, - 0, 0, { (DWORD_PTR)(__FILE__ ": drawable_section") } -}; -static CRITICAL_SECTION drawable_section = { &critsect_debug, -1, 0, 0, 0, 0 }; +pthread_mutex_t drawable_mutex;
static inline BOOL is_onscreen_pixel_format( int format ) { @@ -130,7 +123,7 @@ static struct gl_drawable *create_gl_drawable( HWND hwnd, HDC hdc, int format ) gl->window = create_ioctl_window( hwnd, TRUE, 1.0f ); gl->surface = 0; gl->pbuffer = p_eglCreatePbufferSurface( display, pixel_formats[gl->format - 1].config, attribs ); - EnterCriticalSection( &drawable_section ); + pthread_mutex_lock( &drawable_mutex ); list_add_head( &gl_drawables, &gl->entry ); return gl; } @@ -139,26 +132,26 @@ static struct gl_drawable *get_gl_drawable( HWND hwnd, HDC hdc ) { struct gl_drawable *gl;
- EnterCriticalSection( &drawable_section ); + pthread_mutex_lock( &drawable_mutex ); LIST_FOR_EACH_ENTRY( gl, &gl_drawables, struct gl_drawable, entry ) { if (hwnd && gl->hwnd == hwnd) return gl; if (hdc && gl->hdc == hdc) return gl; } - LeaveCriticalSection( &drawable_section ); + pthread_mutex_unlock( &drawable_mutex ); return NULL; }
static void release_gl_drawable( struct gl_drawable *gl ) { - if (gl) LeaveCriticalSection( &drawable_section ); + if (gl) pthread_mutex_unlock( &drawable_mutex ); }
void destroy_gl_drawable( HWND hwnd ) { struct gl_drawable *gl;
- EnterCriticalSection( &drawable_section ); + pthread_mutex_lock( &drawable_mutex ); LIST_FOR_EACH_ENTRY( gl, &gl_drawables, struct gl_drawable, entry ) { if (gl->hwnd != hwnd) continue; @@ -169,7 +162,7 @@ void destroy_gl_drawable( HWND hwnd ) HeapFree( GetProcessHeap(), 0, gl ); break; } - LeaveCriticalSection( &drawable_section ); + pthread_mutex_unlock( &drawable_mutex ); }
static BOOL refresh_context( struct wgl_context *ctx ) @@ -439,9 +432,9 @@ static struct wgl_context * WINAPI android_wglCreateContext( HDC hdc ) */ static BOOL WINAPI android_wglDeleteContext( struct wgl_context *ctx ) { - EnterCriticalSection( &drawable_section ); + pthread_mutex_lock( &drawable_mutex ); list_remove( &ctx->entry ); - LeaveCriticalSection( &drawable_section ); + pthread_mutex_unlock( &drawable_mutex ); p_eglDestroyContext( display, ctx->context ); return HeapFree( GetProcessHeap(), 0, ctx ); }
From: Jacek Caban jacek@codeweavers.com
Signed-off-by: Jacek Caban jacek@codeweavers.com --- dlls/wineandroid.drv/android.h | 1 + dlls/wineandroid.drv/init.c | 1 + dlls/wineandroid.drv/window.c | 19 ++++++------------- 3 files changed, 8 insertions(+), 13 deletions(-)
diff --git a/dlls/wineandroid.drv/android.h b/dlls/wineandroid.drv/android.h index 4348818aaf2..8008db52cfb 100644 --- a/dlls/wineandroid.drv/android.h +++ b/dlls/wineandroid.drv/android.h @@ -81,6 +81,7 @@ extern int ioctl_set_cursor( int id, int width, int height, * USER driver */
+extern pthread_mutex_t win_data_mutex DECLSPEC_HIDDEN; extern INT ANDROID_GetKeyNameText( LONG lparam, LPWSTR buffer, INT size ) DECLSPEC_HIDDEN; extern UINT ANDROID_MapVirtualKeyEx( UINT code, UINT maptype, HKL hkl ) DECLSPEC_HIDDEN; extern SHORT ANDROID_VkKeyScanEx( WCHAR ch, HKL hkl ) DECLSPEC_HIDDEN; diff --git a/dlls/wineandroid.drv/init.c b/dlls/wineandroid.drv/init.c index 33acb4376c5..f769608befd 100644 --- a/dlls/wineandroid.drv/init.c +++ b/dlls/wineandroid.drv/init.c @@ -578,6 +578,7 @@ static BOOL process_attach(void) pthread_mutexattr_init( &attr ); pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_RECURSIVE ); pthread_mutex_init( &drawable_mutex, &attr ); + pthread_mutex_init( &win_data_mutex, &attr ); pthread_mutexattr_destroy( &attr );
if ((java_vm = *p_java_vm)) /* running under Java */ diff --git a/dlls/wineandroid.drv/window.c b/dlls/wineandroid.drv/window.c index 6b019445805..18ae919651d 100644 --- a/dlls/wineandroid.drv/window.c +++ b/dlls/wineandroid.drv/window.c @@ -60,14 +60,7 @@ struct android_win_data
#define SWP_AGG_NOPOSCHANGE (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
-static CRITICAL_SECTION win_data_section; -static CRITICAL_SECTION_DEBUG critsect_debug = -{ - 0, 0, &win_data_section, - { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList }, - 0, 0, { (DWORD_PTR)(__FILE__ ": win_data_section") } -}; -static CRITICAL_SECTION win_data_section = { &critsect_debug, -1, 0, 0, 0, 0 }; +pthread_mutex_t win_data_mutex;
static struct android_win_data *win_data_context[32768];
@@ -130,7 +123,7 @@ static struct android_win_data *alloc_win_data( HWND hwnd ) data->hwnd = hwnd; data->window = create_ioctl_window( hwnd, FALSE, (float)get_win_monitor_dpi( hwnd ) / NtUserGetDpiForWindow( hwnd )); - EnterCriticalSection( &win_data_section ); + pthread_mutex_lock( &win_data_mutex ); win_data_context[context_idx(hwnd)] = data; } return data; @@ -143,7 +136,7 @@ static struct android_win_data *alloc_win_data( HWND hwnd ) static void free_win_data( struct android_win_data *data ) { win_data_context[context_idx( data->hwnd )] = NULL; - LeaveCriticalSection( &win_data_section ); + pthread_mutex_unlock( &win_data_mutex ); if (data->window) release_ioctl_window( data->window ); HeapFree( GetProcessHeap(), 0, data ); } @@ -159,9 +152,9 @@ static struct android_win_data *get_win_data( HWND hwnd ) struct android_win_data *data;
if (!hwnd) return NULL; - EnterCriticalSection( &win_data_section ); + pthread_mutex_lock( &win_data_mutex ); if ((data = win_data_context[context_idx(hwnd)]) && data->hwnd == hwnd) return data; - LeaveCriticalSection( &win_data_section ); + pthread_mutex_unlock( &win_data_mutex ); return NULL; }
@@ -173,7 +166,7 @@ static struct android_win_data *get_win_data( HWND hwnd ) */ static void release_win_data( struct android_win_data *data ) { - if (data) LeaveCriticalSection( &win_data_section ); + if (data) pthread_mutex_unlock( &win_data_mutex ); }
From: Jacek Caban jacek@codeweavers.com
Signed-off-by: Jacek Caban jacek@codeweavers.com --- dlls/wineandroid.drv/window.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/dlls/wineandroid.drv/window.c b/dlls/wineandroid.drv/window.c index 18ae919651d..53c270eb7f3 100644 --- a/dlls/wineandroid.drv/window.c +++ b/dlls/wineandroid.drv/window.c @@ -579,7 +579,7 @@ struct android_window_surface BYTE alpha; COLORREF color_key; void *bits; - CRITICAL_SECTION crit; + pthread_mutex_t mutex; BITMAPINFO info; /* variable size, must be last */ };
@@ -652,7 +652,7 @@ static void android_surface_lock( struct window_surface *window_surface ) { struct android_window_surface *surface = get_android_surface( window_surface );
- EnterCriticalSection( &surface->crit ); + pthread_mutex_lock( &surface->mutex ); }
/*********************************************************************** @@ -662,7 +662,7 @@ static void android_surface_unlock( struct window_surface *window_surface ) { struct android_window_surface *surface = get_android_surface( window_surface );
- LeaveCriticalSection( &surface->crit ); + pthread_mutex_unlock( &surface->mutex ); }
/*********************************************************************** @@ -802,8 +802,6 @@ static void android_surface_destroy( struct window_surface *window_surface )
TRACE( "freeing %p bits %p\n", surface, surface->bits );
- surface->crit.DebugInfo->Spare[0] = 0; - DeleteCriticalSection( &surface->crit ); HeapFree( GetProcessHeap(), 0, surface->region_data ); if (surface->region) NtGdiDeleteObjectApp( surface->region ); release_ioctl_window( surface->window ); @@ -902,6 +900,7 @@ static struct window_surface *create_surface( HWND hwnd, const RECT *rect, { struct android_window_surface *surface; int width = rect->right - rect->left, height = rect->bottom - rect->top; + pthread_mutexattr_t attr;
surface = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, FIELD_OFFSET( struct android_window_surface, info.bmiColors[3] )); @@ -912,8 +911,10 @@ static struct window_surface *create_surface( HWND hwnd, const RECT *rect, surface->info.bmiHeader.biPlanes = 1; surface->info.bmiHeader.biSizeImage = get_dib_image_size( &surface->info );
- InitializeCriticalSection( &surface->crit ); - surface->crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": surface"); + pthread_mutexattr_init( &attr ); + pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_RECURSIVE ); + pthread_mutex_init( &surface->mutex, &attr ); + pthread_mutexattr_destroy( &attr );
surface->header.funcs = &android_surface_funcs; surface->header.rect = *rect;
From: Jacek Caban jacek@codeweavers.com
Signed-off-by: Jacek Caban jacek@codeweavers.com --- dlls/wineandroid.drv/Makefile.in | 1 + dlls/wineandroid.drv/android.h | 1 + dlls/wineandroid.drv/dllmain.c | 36 ++++++++++++++++++++++++++++++++ dlls/wineandroid.drv/init.c | 29 ++++++++++++------------- dlls/wineandroid.drv/unixlib.h | 30 ++++++++++++++++++++++++++ 5 files changed, 83 insertions(+), 14 deletions(-) create mode 100644 dlls/wineandroid.drv/dllmain.c create mode 100644 dlls/wineandroid.drv/unixlib.h
diff --git a/dlls/wineandroid.drv/Makefile.in b/dlls/wineandroid.drv/Makefile.in index 5426fc75b94..4c4b63d2e78 100644 --- a/dlls/wineandroid.drv/Makefile.in +++ b/dlls/wineandroid.drv/Makefile.in @@ -7,6 +7,7 @@ EXTRADLLFLAGS = -mcygwin
C_SRCS = \ device.c \ + dllmain.c \ init.c \ keyboard.c \ opengl.c \ diff --git a/dlls/wineandroid.drv/android.h b/dlls/wineandroid.drv/android.h index 8008db52cfb..8b62bec862d 100644 --- a/dlls/wineandroid.drv/android.h +++ b/dlls/wineandroid.drv/android.h @@ -34,6 +34,7 @@ #include "winbase.h" #include "ntgdi.h" #include "wine/gdi_driver.h" +#include "unixlib.h" #include "android_native.h"
diff --git a/dlls/wineandroid.drv/dllmain.c b/dlls/wineandroid.drv/dllmain.c new file mode 100644 index 00000000000..7886efe4b58 --- /dev/null +++ b/dlls/wineandroid.drv/dllmain.c @@ -0,0 +1,36 @@ +/* + * wineandroid.drv entry points + * + * Copyright 2022 Jacek Caban for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include <stdarg.h> +#include "windef.h" +#include "winbase.h" +#include "unixlib.h" + + +/*********************************************************************** + * dll initialisation routine + */ +BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved ) +{ + if (reason == DLL_PROCESS_ATTACH) return TRUE; + + DisableThreadLibraryCalls( inst ); + return !ANDROID_CALL(init, NULL); +} diff --git a/dlls/wineandroid.drv/init.c b/dlls/wineandroid.drv/init.c index f769608befd..c0b3332df30 100644 --- a/dlls/wineandroid.drv/init.c +++ b/dlls/wineandroid.drv/init.c @@ -556,7 +556,7 @@ JavaVM **p_java_vm = NULL; jobject *p_java_object = NULL; unsigned short *p_java_gdt_sel = NULL;
-static BOOL process_attach(void) +static HRESULT android_init( void *arg ) { pthread_mutexattr_t attr; jclass class; @@ -565,7 +565,7 @@ static BOOL process_attach(void) JavaVM *java_vm; void *ntdll;
- if (!(ntdll = dlopen( "ntdll.so", RTLD_NOW ))) return FALSE; + if (!(ntdll = dlopen( "ntdll.so", RTLD_NOW ))) return STATUS_UNSUCCESSFUL;
p_java_vm = dlsym( ntdll, "java_vm" ); p_java_object = dlsym( ntdll, "java_object" ); @@ -598,19 +598,20 @@ static BOOL process_attach(void) #endif } __wine_set_user_driver( &android_drv_funcs, WINE_GDI_DRIVER_VERSION ); - return TRUE; + return STATUS_SUCCESS; }
-/*********************************************************************** - * dll initialisation routine - */ -BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved ) +const unixlib_entry_t __wine_unix_call_funcs[] = { - switch (reason) - { - case DLL_PROCESS_ATTACH: - DisableThreadLibraryCalls( inst ); - return process_attach(); - } - return TRUE; + android_init, +}; + + +C_ASSERT( ARRAYSIZE(__wine_unix_call_funcs) == unix_funcs_count ); + + +/* FIXME: Use __wine_unix_call instead */ +NTSTATUS unix_call( enum android_funcs code, void *params ) +{ + return __wine_unix_call_funcs[code]( params ); } diff --git a/dlls/wineandroid.drv/unixlib.h b/dlls/wineandroid.drv/unixlib.h new file mode 100644 index 00000000000..d8327b30f08 --- /dev/null +++ b/dlls/wineandroid.drv/unixlib.h @@ -0,0 +1,30 @@ +/* + * Copyright 2022 Jacek Caban for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "ntuser.h" +#include "wine/unixlib.h" + +enum android_funcs +{ + unix_init, + unix_funcs_count +}; + +/* FIXME: Use __wine_unix_call when the rest of the stack is ready */ +extern NTSTATUS unix_call( enum android_funcs func, void *arg ) DECLSPEC_HIDDEN; +#define ANDROID_CALL(func, params) unix_call( unix_ ## func, params )
From: Jacek Caban jacek@codeweavers.com
Signed-off-by: Jacek Caban jacek@codeweavers.com --- dlls/wineandroid.drv/android.h | 4 ++++ dlls/wineandroid.drv/dllmain.c | 9 +++++++++ dlls/wineandroid.drv/init.c | 1 + dlls/wineandroid.drv/unixlib.h | 1 + dlls/wineandroid.drv/window.c | 6 +++--- dlls/wineandroid.drv/wineandroid.drv.spec | 2 +- 6 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/dlls/wineandroid.drv/android.h b/dlls/wineandroid.drv/android.h index 8b62bec862d..2a09d4195ef 100644 --- a/dlls/wineandroid.drv/android.h +++ b/dlls/wineandroid.drv/android.h @@ -112,6 +112,10 @@ extern void ANDROID_WindowPosChanged( HWND hwnd, HWND insert_after, UINT swp_fla const RECT *visible_rect, const RECT *valid_rects, struct window_surface *surface ) DECLSPEC_HIDDEN;
+/* unixlib interface */ + +extern NTSTATUS android_create_desktop( void *arg ) DECLSPEC_HIDDEN; + extern unsigned int screen_width DECLSPEC_HIDDEN; extern unsigned int screen_height DECLSPEC_HIDDEN; extern RECT virtual_screen_rect DECLSPEC_HIDDEN; diff --git a/dlls/wineandroid.drv/dllmain.c b/dlls/wineandroid.drv/dllmain.c index 7886efe4b58..42719798f33 100644 --- a/dlls/wineandroid.drv/dllmain.c +++ b/dlls/wineandroid.drv/dllmain.c @@ -34,3 +34,12 @@ BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved ) DisableThreadLibraryCalls( inst ); return !ANDROID_CALL(init, NULL); } + + +/*********************************************************************** + * wine_create_desktop (wineandroid.@) + */ +BOOL CDECL wine_create_desktop( UINT width, UINT height ) +{ + return ANDROID_CALL( create_desktop, NULL ); +} diff --git a/dlls/wineandroid.drv/init.c b/dlls/wineandroid.drv/init.c index c0b3332df30..b7ee7d8a9b8 100644 --- a/dlls/wineandroid.drv/init.c +++ b/dlls/wineandroid.drv/init.c @@ -603,6 +603,7 @@ static HRESULT android_init( void *arg )
const unixlib_entry_t __wine_unix_call_funcs[] = { + android_create_desktop, android_init, };
diff --git a/dlls/wineandroid.drv/unixlib.h b/dlls/wineandroid.drv/unixlib.h index d8327b30f08..10fe401dea0 100644 --- a/dlls/wineandroid.drv/unixlib.h +++ b/dlls/wineandroid.drv/unixlib.h @@ -21,6 +21,7 @@
enum android_funcs { + unix_create_desktop, unix_init, unix_funcs_count }; diff --git a/dlls/wineandroid.drv/window.c b/dlls/wineandroid.drv/window.c index 53c270eb7f3..d5e6a6961a9 100644 --- a/dlls/wineandroid.drv/window.c +++ b/dlls/wineandroid.drv/window.c @@ -1668,9 +1668,9 @@ LRESULT ANDROID_WindowMessage( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
/*********************************************************************** - * ANDROID_create_desktop + * android_create_desktop */ -BOOL CDECL ANDROID_create_desktop( UINT width, UINT height ) +NTSTATUS android_create_desktop( void *arg ) { /* wait until we receive the surface changed event */ while (!screen_width) @@ -1682,5 +1682,5 @@ BOOL CDECL ANDROID_create_desktop( UINT width, UINT height ) } process_events( QS_ALLINPUT ); } - return TRUE; + return 0; } diff --git a/dlls/wineandroid.drv/wineandroid.drv.spec b/dlls/wineandroid.drv/wineandroid.drv.spec index 400f5ccb991..22b97356521 100644 --- a/dlls/wineandroid.drv/wineandroid.drv.spec +++ b/dlls/wineandroid.drv/wineandroid.drv.spec @@ -1,2 +1,2 @@ # Desktop -@ cdecl wine_create_desktop(long long) ANDROID_create_desktop +@ cdecl wine_create_desktop(long long)
From: Jacek Caban jacek@codeweavers.com
Signed-off-by: Jacek Caban jacek@codeweavers.com --- dlls/wineandroid.drv/device.c | 16 ++++++------- dlls/wineandroid.drv/init.c | 4 ++-- dlls/wineandroid.drv/opengl.c | 17 ++++++------- dlls/wineandroid.drv/window.c | 45 +++++++++++++++++------------------ 4 files changed, 41 insertions(+), 41 deletions(-)
diff --git a/dlls/wineandroid.drv/device.c b/dlls/wineandroid.drv/device.c index 45009d61a79..b54eabbcc75 100644 --- a/dlls/wineandroid.drv/device.c +++ b/dlls/wineandroid.drv/device.c @@ -486,7 +486,7 @@ static void free_native_win_data( struct native_win_data *data )
InterlockedCompareExchangePointer( (void **)&capture_window, 0, data->hwnd ); release_native_window( data ); - HeapFree( GetProcessHeap(), 0, data ); + free( data ); data_map[idx] = NULL; }
@@ -500,7 +500,7 @@ static struct native_win_data *create_native_win_data( HWND hwnd, BOOL opengl ) WARN( "data for %p not freed correctly\n", data->hwnd ); free_native_win_data( data ); } - if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) ))) return NULL; + if (!(data = calloc( 1, sizeof(*data) ))) return NULL; data->hwnd = hwnd; data->opengl = opengl; if (!opengl) data->api = NATIVE_WINDOW_API_CPU; @@ -1255,7 +1255,7 @@ static void buffer_decRef( struct android_native_base_t *base ) { if (!is_in_desktop_process()) gralloc_release_buffer( &buffer->buffer ); if (buffer->bits) UnmapViewOfFile( buffer->bits ); - HeapFree( GetProcessHeap(), 0, buffer ); + free( buffer ); } }
@@ -1277,7 +1277,7 @@ static int dequeueBuffer( struct ANativeWindow *window, struct ANativeWindowBuff /* if we received the native handle, this is a new buffer */ if (size > offsetof( struct ioctl_android_dequeueBuffer, native_handle )) { - struct native_buffer_wrapper *buf = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*buf) ); + struct native_buffer_wrapper *buf = calloc( 1, sizeof(*buf) );
buf->buffer.common.magic = ANDROID_NATIVE_BUFFER_MAGIC; buf->buffer.common.version = sizeof( buf->buffer ); @@ -1534,7 +1534,7 @@ static int perform( ANativeWindow *window, int operation, ... ) struct ANativeWindow *create_ioctl_window( HWND hwnd, BOOL opengl, float scale ) { struct ioctl_android_create_window req; - struct native_win_wrapper *win = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*win) ); + struct native_win_wrapper *win = calloc( 1, sizeof(*win) );
if (!win) return NULL;
@@ -1585,7 +1585,7 @@ void release_ioctl_window( struct ANativeWindow *window ) if (win->buffers[i]) win->buffers[i]->buffer.common.decRef( &win->buffers[i]->buffer.common );
destroy_ioctl_window( win->hwnd, win->opengl ); - HeapFree( GetProcessHeap(), 0, win ); + free( win ); }
void destroy_ioctl_window( HWND hwnd, BOOL opengl ) @@ -1641,7 +1641,7 @@ int ioctl_set_cursor( int id, int width, int height, unsigned int size = offsetof( struct ioctl_android_set_cursor, bits[width * height] ); int ret;
- if (!(req = HeapAlloc( GetProcessHeap(), 0, size ))) return -ENOMEM; + if (!(req = malloc( size ))) return -ENOMEM; req->hdr.hwnd = 0; /* unused */ req->hdr.opengl = FALSE; req->id = id; @@ -1651,6 +1651,6 @@ int ioctl_set_cursor( int id, int width, int height, req->hotspoty = hotspoty; memcpy( req->bits, bits, width * height * sizeof(req->bits[0]) ); ret = android_ioctl( IOCTL_SET_CURSOR, req, size, NULL, NULL ); - HeapFree( GetProcessHeap(), 0, req ); + free( req ); return ret; } diff --git a/dlls/wineandroid.drv/init.c b/dlls/wineandroid.drv/init.c index b7ee7d8a9b8..3739d4e4cb4 100644 --- a/dlls/wineandroid.drv/init.c +++ b/dlls/wineandroid.drv/init.c @@ -210,7 +210,7 @@ static ANDROID_PDEVICE *create_android_physdev(void)
if (!device_init_done) device_init();
- if (!(physdev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*physdev) ))) return NULL; + if (!(physdev = calloc( 1, sizeof(*physdev) ))) return NULL; return physdev; }
@@ -248,7 +248,7 @@ static BOOL CDECL ANDROID_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev ) */ static BOOL CDECL ANDROID_DeleteDC( PHYSDEV dev ) { - HeapFree( GetProcessHeap(), 0, dev ); + free( dev ); return TRUE; }
diff --git a/dlls/wineandroid.drv/opengl.c b/dlls/wineandroid.drv/opengl.c index 0c4f14e7cff..d7026be6599 100644 --- a/dlls/wineandroid.drv/opengl.c +++ b/dlls/wineandroid.drv/opengl.c @@ -115,7 +115,7 @@ static inline BOOL is_onscreen_pixel_format( int format ) static struct gl_drawable *create_gl_drawable( HWND hwnd, HDC hdc, int format ) { static const int attribs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE }; - struct gl_drawable *gl = HeapAlloc( GetProcessHeap(), 0, sizeof(*gl) ); + struct gl_drawable *gl = malloc( sizeof(*gl) );
gl->hwnd = hwnd; gl->hdc = hdc; @@ -159,7 +159,7 @@ void destroy_gl_drawable( HWND hwnd ) if (gl->surface) p_eglDestroySurface( display, gl->surface ); if (gl->pbuffer) p_eglDestroySurface( display, gl->pbuffer ); release_ioctl_window( gl->window ); - HeapFree( GetProcessHeap(), 0, gl ); + free( gl ); break; } pthread_mutex_unlock( &drawable_mutex ); @@ -250,7 +250,7 @@ static struct wgl_context *create_context( HDC hdc, struct wgl_context *share, c
if (!(gl = get_gl_drawable( NtUserWindowFromDC( hdc ), hdc ))) return NULL;
- ctx = HeapAlloc( GetProcessHeap(), 0, sizeof(*ctx) ); + ctx = malloc( sizeof(*ctx) );
ctx->config = pixel_formats[gl->format - 1].config; ctx->surface = 0; @@ -436,7 +436,8 @@ static BOOL WINAPI android_wglDeleteContext( struct wgl_context *ctx ) list_remove( &ctx->entry ); pthread_mutex_unlock( &drawable_mutex ); p_eglDestroyContext( display, ctx->context ); - return HeapFree( GetProcessHeap(), 0, ctx ); + free( ctx ); + return TRUE; }
/*********************************************************************** @@ -980,13 +981,13 @@ static BOOL egl_init(void) TRACE( "display %p version %u.%u\n", display, major, minor );
p_eglGetConfigs( display, NULL, 0, &count ); - configs = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*configs) ); - pixel_formats = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*pixel_formats) ); + configs = malloc( count * sizeof(*configs) ); + pixel_formats = malloc( count * sizeof(*pixel_formats) ); p_eglGetConfigs( display, configs, count, &count ); if (!count || !configs || !pixel_formats) { - HeapFree( GetProcessHeap(), 0, configs ); - HeapFree( GetProcessHeap(), 0, pixel_formats ); + free( configs ); + free( pixel_formats ); ERR( "eglGetConfigs returned no configs\n" ); return 0; } diff --git a/dlls/wineandroid.drv/window.c b/dlls/wineandroid.drv/window.c index d5e6a6961a9..a5d6a98cd3f 100644 --- a/dlls/wineandroid.drv/window.c +++ b/dlls/wineandroid.drv/window.c @@ -118,7 +118,7 @@ static struct android_win_data *alloc_win_data( HWND hwnd ) { struct android_win_data *data;
- if ((data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data)))) + if ((data = calloc( 1, sizeof(*data) ))) { data->hwnd = hwnd; data->window = create_ioctl_window( hwnd, FALSE, @@ -138,7 +138,7 @@ static void free_win_data( struct android_win_data *data ) win_data_context[context_idx( data->hwnd )] = NULL; pthread_mutex_unlock( &win_data_mutex ); if (data->window) release_ioctl_window( data->window ); - HeapFree( GetProcessHeap(), 0, data ); + free( data ); }
@@ -402,13 +402,13 @@ static void pull_events(void)
for (;;) { - if (!(event = HeapAlloc( GetProcessHeap(), 0, sizeof(*event) ))) break; + if (!(event = malloc( sizeof(*event) ))) break;
res = read( event_pipe[0], &event->data, sizeof(event->data) ); if (res != sizeof(event->data)) break; list_add_tail( &event_queue, &event->entry ); } - HeapFree( GetProcessHeap(), 0, event ); + free( event ); }
@@ -533,7 +533,7 @@ static int process_events( DWORD mask ) default: FIXME( "got event %u\n", event->data.type ); } - HeapFree( GetProcessHeap(), 0, event ); + free( event ); count++; /* next may have been removed by a recursive call, so reset it to the beginning of the list */ next = LIST_ENTRY( event_queue.next, struct java_event, entry ); @@ -802,11 +802,11 @@ static void android_surface_destroy( struct window_surface *window_surface )
TRACE( "freeing %p bits %p\n", surface, surface->bits );
- HeapFree( GetProcessHeap(), 0, surface->region_data ); + free( surface->region_data ); if (surface->region) NtGdiDeleteObjectApp( surface->region ); release_ioctl_window( surface->window ); - HeapFree( GetProcessHeap(), 0, surface->bits ); - HeapFree( GetProcessHeap(), 0, surface ); + free( surface->bits ); + free( surface ); }
static const struct window_surface_funcs android_surface_funcs = @@ -875,17 +875,17 @@ static void set_surface_region( struct window_surface *window_surface, HRGN win_ if (surface->region) NtGdiCombineRgn( region, region, surface->region, RGN_AND );
if (!(size = NtGdiGetRegionData( region, 0, NULL ))) goto done; - if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) goto done; + if (!(data = malloc( size ))) goto done;
if (!NtGdiGetRegionData( region, size, data )) { - HeapFree( GetProcessHeap(), 0, data ); + free( data ); data = NULL; }
done: window_surface->funcs->lock( window_surface ); - HeapFree( GetProcessHeap(), 0, surface->region_data ); + free( surface->region_data ); surface->region_data = data; *window_surface->funcs->get_bounds( window_surface ) = surface->header.rect; window_surface->funcs->unlock( window_surface ); @@ -902,8 +902,7 @@ static struct window_surface *create_surface( HWND hwnd, const RECT *rect, int width = rect->right - rect->left, height = rect->bottom - rect->top; pthread_mutexattr_t attr;
- surface = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, - FIELD_OFFSET( struct android_window_surface, info.bmiColors[3] )); + surface = calloc( 1, FIELD_OFFSET( struct android_window_surface, info.bmiColors[3] )); if (!surface) return NULL; set_color_info( &surface->info, src_alpha ); surface->info.bmiHeader.biWidth = width; @@ -926,7 +925,7 @@ static struct window_surface *create_surface( HWND hwnd, const RECT *rect, set_surface_region( &surface->header, (HRGN)1 ); reset_bounds( &surface->bounds );
- if (!(surface->bits = HeapAlloc( GetProcessHeap(), 0, surface->info.bmiHeader.biSizeImage ))) + if (!(surface->bits = malloc( surface->info.bmiHeader.biSizeImage ))) goto failed;
TRACE( "created %p hwnd %p %s bits %p-%p\n", surface, hwnd, wine_dbgstr_rect(rect), @@ -974,12 +973,12 @@ static unsigned int *get_mono_icon_argb( HDC hdc, HBITMAP bmp, unsigned int *wid if (!NtGdiExtGetObjectW( bmp, sizeof(bm), &bm )) return NULL; stride = ((bm.bmWidth + 15) >> 3) & ~1; mask_size = stride * bm.bmHeight; - if (!(mask = HeapAlloc( GetProcessHeap(), 0, mask_size ))) return NULL; + if (!(mask = malloc( mask_size ))) return NULL; if (!NtGdiGetBitmapBits( bmp, mask_size, mask )) goto done;
bm.bmHeight /= 2; bits_size = bm.bmWidth * bm.bmHeight * sizeof(*bits); - if (!(bits = HeapAlloc( GetProcessHeap(), 0, bits_size ))) goto done; + if (!(bits = malloc( bits_size ))) goto done;
ptr = bits; for (i = 0; i < bm.bmHeight; i++) @@ -1000,7 +999,7 @@ static unsigned int *get_mono_icon_argb( HDC hdc, HBITMAP bmp, unsigned int *wid *height = bm.bmHeight;
done: - HeapFree( GetProcessHeap(), 0, mask ); + free( mask ); return bits; }
@@ -1034,7 +1033,7 @@ static unsigned int *get_bitmap_argb( HDC hdc, HBITMAP color, HBITMAP mask, unsi info->bmiHeader.biYPelsPerMeter = 0; info->bmiHeader.biClrUsed = 0; info->bmiHeader.biClrImportant = 0; - if (!(bits = HeapAlloc( GetProcessHeap(), 0, bm.bmWidth * bm.bmHeight * sizeof(unsigned int) ))) + if (!(bits = malloc( bm.bmWidth * bm.bmHeight * sizeof(unsigned int) ))) goto failed; if (!NtGdiGetDIBitsInternal( hdc, color, 0, bm.bmHeight, bits, info, DIB_RGB_COLORS, 0, 0 )) goto failed; @@ -1051,21 +1050,21 @@ static unsigned int *get_bitmap_argb( HDC hdc, HBITMAP color, HBITMAP mask, unsi /* generate alpha channel from the mask */ info->bmiHeader.biBitCount = 1; info->bmiHeader.biSizeImage = width_bytes * bm.bmHeight; - if (!(mask_bits = HeapAlloc( GetProcessHeap(), 0, info->bmiHeader.biSizeImage ))) goto failed; + if (!(mask_bits = malloc( info->bmiHeader.biSizeImage ))) goto failed; if (!NtGdiGetDIBitsInternal( hdc, mask, 0, bm.bmHeight, mask_bits, info, DIB_RGB_COLORS, 0, 0 )) goto failed; ptr = bits; for (i = 0; i < bm.bmHeight; i++) for (j = 0; j < bm.bmWidth; j++, ptr++) if (!((mask_bits[i * width_bytes + j / 8] << (j % 8)) & 0x80)) *ptr |= 0xff000000; - HeapFree( GetProcessHeap(), 0, mask_bits ); + free( mask_bits ); }
return bits;
failed: - HeapFree( GetProcessHeap(), 0, bits ); - HeapFree( GetProcessHeap(), 0, mask_bits ); + free( bits ); + free( mask_bits ); *width = *height = 0; return NULL; } @@ -1477,7 +1476,7 @@ void ANDROID_SetCursor( HCURSOR handle ) } } ioctl_set_cursor( id, width, height, info.xHotspot, info.yHotspot, bits ); - HeapFree( GetProcessHeap(), 0, bits ); + free( bits ); NtGdiDeleteObjectApp( info.hbmColor ); NtGdiDeleteObjectApp( info.hbmMask ); }
From: Jacek Caban jacek@codeweavers.com
Signed-off-by: Jacek Caban jacek@codeweavers.com --- dlls/wineandroid.drv/device.c | 60 ++++++++++++++++++++++++----------- dlls/wineandroid.drv/window.c | 12 +++---- 2 files changed, 47 insertions(+), 25 deletions(-)
diff --git a/dlls/wineandroid.drv/device.c b/dlls/wineandroid.drv/device.c index b54eabbcc75..b4f332d2cef 100644 --- a/dlls/wineandroid.drv/device.c +++ b/dlls/wineandroid.drv/device.c @@ -331,8 +331,8 @@ static int duplicate_fd( HANDLE client, int fd ) HANDLE handle, ret = 0;
if (!wine_server_fd_to_handle( dup(fd), GENERIC_READ | SYNCHRONIZE, 0, &handle )) - DuplicateHandle( GetCurrentProcess(), handle, client, &ret, - 0, FALSE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE ); + NtDuplicateObject( GetCurrentProcess(), handle, client, &ret, + 0, 0, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE );
if (!ret) return -1; return HandleToLong( ret ); @@ -347,8 +347,8 @@ static int map_native_handle( union native_handle_buffer *dest, const native_han if (mapping) /* only duplicate the mapping handle */ { HANDLE ret = 0; - if (!DuplicateHandle( GetCurrentProcess(), mapping, client, &ret, - 0, FALSE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE )) + if (!NtDuplicateObject( GetCurrentProcess(), mapping, client, &ret, + 0, 0, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE )) return -ENOSPC; dest->handle.numFds = 0; dest->handle.numInts = 1; @@ -434,7 +434,7 @@ static int register_buffer( struct native_win_data *win, struct ANativeWindowBuf TRACE( "%p %p evicting buffer %p id %d from cache\n", win->hwnd, win->parent, win->buffers[i], i ); win->buffers[i]->common.decRef( &win->buffers[i]->common ); - if (win->mappings[i]) UnmapViewOfFile( win->mappings[i] ); + if (win->mappings[i]) NtUnmapViewOfSection( GetCurrentProcess(), win->mappings[i] ); }
win->buffers[i] = buffer; @@ -442,9 +442,16 @@ static int register_buffer( struct native_win_data *win, struct ANativeWindowBuf
if (mapping) { - *mapping = CreateFileMappingW( INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, - buffer->stride * buffer->height * 4, NULL ); - win->mappings[i] = MapViewOfFile( *mapping, FILE_MAP_READ, 0, 0, 0 ); + OBJECT_ATTRIBUTES attr; + LARGE_INTEGER size; + SIZE_T count = 0; + size.QuadPart = buffer->stride * buffer->height * 4; + InitializeObjectAttributes( &attr, NULL, OBJ_OPENIF, NULL, NULL ); + NtCreateSection( mapping, + STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_WRITE, + &attr, &size, PAGE_READWRITE, 0, INVALID_HANDLE_VALUE ); + NtMapViewOfSection( *mapping, GetCurrentProcess(), &win->mappings[i], 0, 0, + NULL, &count, ViewShare, 0, PAGE_READONLY ); } buffer->common.incRef( &buffer->common ); *is_new = 1; @@ -473,7 +480,7 @@ static void release_native_window( struct native_win_data *data ) for (i = 0; i < NB_CACHED_BUFFERS; i++) { if (data->buffers[i]) data->buffers[i]->common.decRef( &data->buffers[i]->common ); - if (data->mappings[i]) UnmapViewOfFile( data->mappings[i] ); + if (data->mappings[i]) NtUnmapViewOfSection( GetCurrentProcess(), data->mappings[i] ); data->buffer_lru[i] = -1; } memset( data->buffers, 0, sizeof(data->buffers) ); @@ -823,9 +830,12 @@ static NTSTATUS dequeueBuffer_ioctl( void *data, DWORD in_size, DWORD out_size, res->generation = win_data->generation; if (is_new) { - HANDLE process = OpenProcess( PROCESS_DUP_HANDLE, FALSE, current_client_id() ); + OBJECT_ATTRIBUTES attr = { .Length = sizeof(attr) }; + CLIENT_ID cid = { .UniqueProcess = UlongToHandle( current_client_id() ) }; + HANDLE process; + NtOpenProcess( &process, PROCESS_DUP_HANDLE, &attr, &cid ); map_native_handle( &res->native_handle, buffer->handle, mapping, process ); - CloseHandle( process ); + NtClose( process ); *ret_size = sizeof( *res ); } wait_fence_and_close( fence ); @@ -1212,10 +1222,19 @@ static int android_ioctl( enum android_ioctl code, void *in, DWORD in_size, void
if (!device) { - HANDLE file = CreateFileW( deviceW, GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 ); - if (file == INVALID_HANDLE_VALUE) return -ENOENT; - if (InterlockedCompareExchangePointer( &device, file, NULL )) CloseHandle( file ); + OBJECT_ATTRIBUTES attr; + UNICODE_STRING name; + IO_STATUS_BLOCK io; + NTSTATUS status; + HANDLE file; + + RtlInitUnicodeString( &name, deviceW ); + InitializeObjectAttributes( &attr, &name, OBJ_CASE_INSENSITIVE, NULL, NULL ); + status = NtCreateFile( &file, GENERIC_READ | SYNCHRONIZE, &attr, &io, NULL, 0, + FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OPEN, + FILE_NON_DIRECTORY_FILE, NULL, 0 ); + if (status) return -ENOENT; + if (InterlockedCompareExchangePointer( &device, file, NULL )) NtClose( file ); }
status = NtDeviceIoControlFile( device, NULL, NULL, NULL, &iosb, ANDROID_IOCTL(code), @@ -1223,7 +1242,7 @@ static int android_ioctl( enum android_ioctl code, void *in, DWORD in_size, void if (status == STATUS_FILE_DELETED) { WARN( "parent process is gone\n" ); - ExitProcess( 1 ); + NtTerminateProcess( 0, 1 ); } if (out_size) *out_size = iosb.Information; return status_to_android_error( status ); @@ -1254,7 +1273,7 @@ static void buffer_decRef( struct android_native_base_t *base ) if (!InterlockedDecrement( &buffer->ref )) { if (!is_in_desktop_process()) gralloc_release_buffer( &buffer->buffer ); - if (buffer->bits) UnmapViewOfFile( buffer->bits ); + if (buffer->bits) NtUnmapViewOfSection( GetCurrentProcess(), buffer->bits ); free( buffer ); } } @@ -1299,9 +1318,12 @@ static int dequeueBuffer( struct ANativeWindow *window, struct ANativeWindowBuff
if (use_win32) { + LARGE_INTEGER zero = { .QuadPart = 0 }; + SIZE_T count = 0; HANDLE mapping = LongToHandle( res.native_handle.handle.data[0] ); - buf->bits = MapViewOfFile( mapping, FILE_MAP_WRITE, 0, 0, 0 ); - CloseHandle( mapping ); + NtMapViewOfSection( mapping, GetCurrentProcess(), &buf->bits, 0, 0, &zero, &count, + ViewShare, 0, PAGE_READWRITE ); + NtClose( mapping ); } else if (!is_in_desktop_process()) { diff --git a/dlls/wineandroid.drv/window.c b/dlls/wineandroid.drv/window.c index a5d6a98cd3f..3860e0a2772 100644 --- a/dlls/wineandroid.drv/window.c +++ b/dlls/wineandroid.drv/window.c @@ -367,12 +367,12 @@ static void init_event_queue(void) if (pipe2( event_pipe, O_CLOEXEC | O_NONBLOCK ) == -1) { ERR( "could not create data\n" ); - ExitProcess(1); + NtTerminateProcess( 0, 1 ); } if (wine_server_fd_to_handle( event_pipe[0], GENERIC_READ | SYNCHRONIZE, 0, &handle )) { ERR( "Can't allocate handle for event fd\n" ); - ExitProcess(1); + NtTerminateProcess( 0, 1 ); } SERVER_START_REQ( set_queue_fd ) { @@ -383,9 +383,9 @@ static void init_event_queue(void) if (ret) { ERR( "Can't store handle for event fd %x\n", ret ); - ExitProcess(1); + NtTerminateProcess( 0, 1 ); } - CloseHandle( handle ); + NtClose( handle ); desktop_tid = GetCurrentThreadId(); }
@@ -1450,9 +1450,9 @@ void ANDROID_SetCursor( HCURSOR handle ) static DWORD last_cursor_change;
if (InterlockedExchangePointer( (void **)&last_cursor, handle ) != handle || - GetTickCount() - last_cursor_change > 100) + NtGetTickCount() - last_cursor_change > 100) { - last_cursor_change = GetTickCount(); + last_cursor_change = NtGetTickCount();
if (handle) {
From: Jacek Caban jacek@codeweavers.com
Signed-off-by: Jacek Caban jacek@codeweavers.com --- dlls/wineandroid.drv/android.h | 3 ++ dlls/wineandroid.drv/device.c | 71 ++++++++------------------- dlls/wineandroid.drv/dllmain.c | 89 +++++++++++++++++++++++++++++++++- dlls/wineandroid.drv/init.c | 3 ++ dlls/wineandroid.drv/unixlib.h | 16 ++++++ 5 files changed, 130 insertions(+), 52 deletions(-)
diff --git a/dlls/wineandroid.drv/android.h b/dlls/wineandroid.drv/android.h index 2a09d4195ef..c73ab6bc765 100644 --- a/dlls/wineandroid.drv/android.h +++ b/dlls/wineandroid.drv/android.h @@ -115,6 +115,9 @@ extern void ANDROID_WindowPosChanged( HWND hwnd, HWND insert_after, UINT swp_fla /* unixlib interface */
extern NTSTATUS android_create_desktop( void *arg ) DECLSPEC_HIDDEN; +extern NTSTATUS android_dispatch_ioctl( void *arg ) DECLSPEC_HIDDEN; +extern NTSTATUS android_java_init( void *arg ) DECLSPEC_HIDDEN; +extern NTSTATUS android_java_uninit( void *arg ) DECLSPEC_HIDDEN;
extern unsigned int screen_width DECLSPEC_HIDDEN; extern unsigned int screen_height DECLSPEC_HIDDEN; diff --git a/dlls/wineandroid.drv/device.c b/dlls/wineandroid.drv/device.c index b4f332d2cef..b49b691b27a 100644 --- a/dlls/wineandroid.drv/device.c +++ b/dlls/wineandroid.drv/device.c @@ -47,8 +47,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(android); #define SYNC_IOC_WAIT _IOW('>', 0, __s32) #endif
-extern NTSTATUS CDECL wine_ntoskrnl_main_loop( HANDLE stop_event ); -static HANDLE stop_event; static HANDLE thread; static JNIEnv *jni_env; static HWND capture_window; @@ -243,7 +241,8 @@ static inline BOOL is_in_desktop_process(void)
static inline DWORD current_client_id(void) { - return HandleToUlong( PsGetCurrentProcessId() ); + DWORD client_id = PtrToUlong( NtUserGetThreadInfo()->driver_data ); + return client_id ? client_id : GetCurrentProcessId(); }
static inline BOOL is_client_in_process(void) @@ -1116,8 +1115,10 @@ static const ioctl_func ioctl_funcs[] = setCursor_ioctl, /* IOCTL_SET_CURSOR */ };
-static NTSTATUS WINAPI ioctl_callback( DEVICE_OBJECT *device, IRP *irp ) +NTSTATUS android_dispatch_ioctl( void *arg ) { + struct ioctl_params *params = arg; + IRP *irp = params->irp; IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation( irp ); DWORD code = (irpsp->Parameters.DeviceIoControl.IoControlCode - ANDROID_IOCTL(0)) >> 2;
@@ -1130,9 +1131,11 @@ static NTSTATUS WINAPI ioctl_callback( DEVICE_OBJECT *device, IRP *irp ) if (in_size >= sizeof(*header)) { irp->IoStatus.Information = 0; + NtUserGetThreadInfo()->driver_data = UlongToHandle( params->client_id ); irp->IoStatus.u.Status = func( irp->AssociatedIrp.SystemBuffer, in_size, irpsp->Parameters.DeviceIoControl.OutputBufferLength, &irp->IoStatus.Information ); + NtUserGetThreadInfo()->driver_data = 0; } else irp->IoStatus.u.Status = STATUS_INVALID_PARAMETER; } @@ -1141,72 +1144,38 @@ static NTSTATUS WINAPI ioctl_callback( DEVICE_OBJECT *device, IRP *irp ) FIXME( "ioctl %x not supported\n", irpsp->Parameters.DeviceIoControl.IoControlCode ); irp->IoStatus.u.Status = STATUS_NOT_SUPPORTED; } - IoCompleteRequest( irp, IO_NO_INCREMENT ); return STATUS_SUCCESS; }
-static NTSTATUS CALLBACK init_android_driver( DRIVER_OBJECT *driver, UNICODE_STRING *name ) +NTSTATUS android_java_init( void *arg ) { - static const WCHAR device_nameW[] = {'\','D','e','v','i','c','e','\','W','i','n','e','A','n','d','r','o','i','d',0 }; - static const WCHAR device_linkW[] = {'\','?','?','\','W','i','n','e','A','n','d','r','o','i','d',0 }; - - UNICODE_STRING nameW, linkW; - DEVICE_OBJECT *device; - NTSTATUS status; - - driver->MajorFunction[IRP_MJ_DEVICE_CONTROL] = ioctl_callback; - - RtlInitUnicodeString( &nameW, device_nameW ); - RtlInitUnicodeString( &linkW, device_linkW ); - - if ((status = IoCreateDevice( driver, 0, &nameW, 0, 0, FALSE, &device ))) return status; - return IoCreateSymbolicLink( &linkW, &nameW ); -} - -static DWORD CALLBACK device_thread( void *arg ) -{ - static const WCHAR driver_nameW[] = {'\','D','r','i','v','e','r','\','W','i','n','e','A','n','d','r','o','i','d',0 }; - - HANDLE start_event = arg; - UNICODE_STRING nameW; - NTSTATUS status; JavaVM *java_vm; - DWORD ret; - - TRACE( "starting process %x\n", GetCurrentProcessId() );
- if (!(java_vm = *p_java_vm)) return 0; /* not running under Java */ + if (!(java_vm = *p_java_vm)) return STATUS_UNSUCCESSFUL; /* not running under Java */
init_java_thread( java_vm ); - create_desktop_window( NtUserGetDesktopWindow() ); + return STATUS_SUCCESS; +}
- RtlInitUnicodeString( &nameW, driver_nameW ); - if ((status = IoCreateDriver( &nameW, init_android_driver ))) - { - FIXME( "failed to create driver error %x\n", status ); - return status; - } - - stop_event = CreateEventW( NULL, TRUE, FALSE, NULL ); - SetEvent( start_event ); +NTSTATUS android_java_uninit( void *arg ) +{ + JavaVM *java_vm;
- ret = wine_ntoskrnl_main_loop( stop_event ); + if (!(java_vm = *p_java_vm)) return STATUS_UNSUCCESSFUL; /* not running under Java */
wrap_java_call(); (*java_vm)->DetachCurrentThread( java_vm ); unwrap_java_call(); - return ret; + return STATUS_SUCCESS; }
void start_android_device(void) { - HANDLE handles[2]; - - handles[0] = CreateEventW( NULL, TRUE, FALSE, NULL ); - handles[1] = thread = CreateThread( NULL, 0, device_thread, handles[0], 0, NULL ); - WaitForMultipleObjects( 2, handles, FALSE, INFINITE ); - CloseHandle( handles[0] ); + /* FIXME: use KeUserModeCallback instead */ + NTSTATUS (WINAPI *func)(void *, ULONG) = + ((void **)NtCurrentTeb()->Peb->KernelCallbackTable)[client_start_device]; + func( NULL, 0 ); }
diff --git a/dlls/wineandroid.drv/dllmain.c b/dlls/wineandroid.drv/dllmain.c index 42719798f33..37539fa5756 100644 --- a/dlls/wineandroid.drv/dllmain.c +++ b/dlls/wineandroid.drv/dllmain.c @@ -19,9 +19,89 @@ */
#include <stdarg.h> +#include "ntstatus.h" +#define WIN32_NO_STATUS #include "windef.h" #include "winbase.h" +#include "winternl.h" +#include "winioctl.h" +#include "ddk/wdm.h" #include "unixlib.h" +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(android); + + +extern NTSTATUS CDECL wine_ntoskrnl_main_loop( HANDLE stop_event ); +static HANDLE stop_event; +static HANDLE thread; + + +static NTSTATUS WINAPI ioctl_callback( DEVICE_OBJECT *device, IRP *irp ) +{ + struct ioctl_params params = { .irp = irp, .client_id = HandleToUlong(PsGetCurrentProcessId()) }; + NTSTATUS status = ANDROID_CALL( dispatch_ioctl, ¶ms ); + IoCompleteRequest( irp, IO_NO_INCREMENT ); + return status; +} + +static NTSTATUS CALLBACK init_android_driver( DRIVER_OBJECT *driver, UNICODE_STRING *name ) +{ + static const WCHAR device_nameW[] = {'\','D','e','v','i','c','e','\','W','i','n','e','A','n','d','r','o','i','d',0 }; + static const WCHAR device_linkW[] = {'\','?','?','\','W','i','n','e','A','n','d','r','o','i','d',0 }; + + UNICODE_STRING nameW, linkW; + DEVICE_OBJECT *device; + NTSTATUS status; + + driver->MajorFunction[IRP_MJ_DEVICE_CONTROL] = ioctl_callback; + + RtlInitUnicodeString( &nameW, device_nameW ); + RtlInitUnicodeString( &linkW, device_linkW ); + + if ((status = IoCreateDevice( driver, 0, &nameW, 0, 0, FALSE, &device ))) return status; + return IoCreateSymbolicLink( &linkW, &nameW ); +} + +static DWORD CALLBACK device_thread( void *arg ) +{ + static const WCHAR driver_nameW[] = {'\','D','r','i','v','e','r','\','W','i','n','e','A','n','d','r','o','i','d',0 }; + + HANDLE start_event = arg; + UNICODE_STRING nameW; + NTSTATUS status; + DWORD ret; + + TRACE( "starting process %x\n", GetCurrentProcessId() ); + + if (ANDROID_CALL( java_init, NULL )) return 0; /* not running under Java */ + + RtlInitUnicodeString( &nameW, driver_nameW ); + if ((status = IoCreateDriver( &nameW, init_android_driver ))) + { + FIXME( "failed to create driver error %x\n", status ); + return status; + } + + stop_event = CreateEventW( NULL, TRUE, FALSE, NULL ); + SetEvent( start_event ); + + ret = wine_ntoskrnl_main_loop( stop_event ); + + ANDROID_CALL( java_uninit, NULL ); + return ret; +} + +static NTSTATUS WINAPI android_start_device(void *param, ULONG size) +{ + HANDLE handles[2]; + + handles[0] = CreateEventW( NULL, TRUE, FALSE, NULL ); + handles[1] = thread = CreateThread( NULL, 0, device_thread, handles[0], 0, NULL ); + WaitForMultipleObjects( 2, handles, FALSE, INFINITE ); + CloseHandle( handles[0] ); + return HandleToULong( thread ); +}
/*********************************************************************** @@ -29,10 +109,17 @@ */ BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved ) { + void **callback_table; + if (reason == DLL_PROCESS_ATTACH) return TRUE;
DisableThreadLibraryCalls( inst ); - return !ANDROID_CALL(init, NULL); + if (ANDROID_CALL( init, NULL )) return FALSE; + + callback_table = NtCurrentTeb()->Peb->KernelCallbackTable; + callback_table[client_start_device] = android_start_device; + + return TRUE; }
diff --git a/dlls/wineandroid.drv/init.c b/dlls/wineandroid.drv/init.c index 3739d4e4cb4..b5f0b69fcec 100644 --- a/dlls/wineandroid.drv/init.c +++ b/dlls/wineandroid.drv/init.c @@ -604,7 +604,10 @@ static HRESULT android_init( void *arg ) const unixlib_entry_t __wine_unix_call_funcs[] = { android_create_desktop, + android_dispatch_ioctl, android_init, + android_java_init, + android_java_uninit, };
diff --git a/dlls/wineandroid.drv/unixlib.h b/dlls/wineandroid.drv/unixlib.h index 10fe401dea0..2838047f4fe 100644 --- a/dlls/wineandroid.drv/unixlib.h +++ b/dlls/wineandroid.drv/unixlib.h @@ -22,10 +22,26 @@ enum android_funcs { unix_create_desktop, + unix_dispatch_ioctl, unix_init, + unix_java_init, + unix_java_uninit, unix_funcs_count };
/* FIXME: Use __wine_unix_call when the rest of the stack is ready */ extern NTSTATUS unix_call( enum android_funcs func, void *arg ) DECLSPEC_HIDDEN; #define ANDROID_CALL(func, params) unix_call( unix_ ## func, params ) + +/* android_ioctl params */ +struct ioctl_params +{ + struct _IRP *irp; + DWORD client_id; +}; + + +enum +{ + client_start_device = NtUserDriverCallbackFirst, +};
From: Jacek Caban jacek@codeweavers.com
Signed-off-by: Jacek Caban jacek@codeweavers.com --- dlls/wineandroid.drv/android.h | 2 ++ dlls/wineandroid.drv/device.c | 16 +++++++++------- dlls/wineandroid.drv/dllmain.c | 12 +++++++++++- dlls/wineandroid.drv/init.c | 6 ++++++ dlls/wineandroid.drv/unixlib.h | 17 +++++++++++++++++ 5 files changed, 45 insertions(+), 8 deletions(-)
diff --git a/dlls/wineandroid.drv/android.h b/dlls/wineandroid.drv/android.h index c73ab6bc765..22652f11d27 100644 --- a/dlls/wineandroid.drv/android.h +++ b/dlls/wineandroid.drv/android.h @@ -118,6 +118,8 @@ extern NTSTATUS android_create_desktop( void *arg ) DECLSPEC_HIDDEN; extern NTSTATUS android_dispatch_ioctl( void *arg ) DECLSPEC_HIDDEN; extern NTSTATUS android_java_init( void *arg ) DECLSPEC_HIDDEN; extern NTSTATUS android_java_uninit( void *arg ) DECLSPEC_HIDDEN; +extern NTSTATUS android_register_window( void *arg ) DECLSPEC_HIDDEN; +extern PNTAPCFUNC register_window_callback;
extern unsigned int screen_width DECLSPEC_HIDDEN; extern unsigned int screen_height DECLSPEC_HIDDEN; diff --git a/dlls/wineandroid.drv/device.c b/dlls/wineandroid.drv/device.c index b49b691b27a..fa11e0d071e 100644 --- a/dlls/wineandroid.drv/device.c +++ b/dlls/wineandroid.drv/device.c @@ -516,21 +516,22 @@ static struct native_win_data *create_native_win_data( HWND hwnd, BOOL opengl ) return data; }
-static void CALLBACK register_native_window_callback( ULONG_PTR arg1, ULONG_PTR arg2, ULONG_PTR arg3 ) +NTSTATUS android_register_window( void *arg ) { - HWND hwnd = (HWND)arg1; - struct ANativeWindow *win = (struct ANativeWindow *)arg2; - BOOL opengl = arg3; + struct register_window_params *params = arg; + HWND hwnd = (HWND)params->arg1; + struct ANativeWindow *win = (struct ANativeWindow *)params->arg2; + BOOL opengl = params->arg3; struct native_win_data *data = get_native_win_data( hwnd, opengl );
- if (!win) return; /* do nothing and hold on to the window until we get a new surface */ + if (!win) return 0; /* do nothing and hold on to the window until we get a new surface */
if (!data || data->parent == win) { pANativeWindow_release( win ); if (data) NtUserPostMessage( hwnd, WM_ANDROID_REFRESH, opengl, 0 ); TRACE( "%p -> %p win %p (unchanged)\n", hwnd, data, win ); - return; + return 0; }
release_native_window( data ); @@ -543,12 +544,13 @@ static void CALLBACK register_native_window_callback( ULONG_PTR arg1, ULONG_PTR unwrap_java_call(); NtUserPostMessage( hwnd, WM_ANDROID_REFRESH, opengl, 0 ); TRACE( "%p -> %p win %p\n", hwnd, data, win ); + return 0; }
/* register a native window received from the Java side for use in ioctls */ void register_native_window( HWND hwnd, struct ANativeWindow *win, BOOL opengl ) { - NtQueueApcThread( thread, register_native_window_callback, (ULONG_PTR)hwnd, (ULONG_PTR)win, opengl ); + NtQueueApcThread( thread, register_window_callback, (ULONG_PTR)hwnd, (ULONG_PTR)win, opengl ); }
void init_gralloc( const struct hw_module_t *module ) diff --git a/dlls/wineandroid.drv/dllmain.c b/dlls/wineandroid.drv/dllmain.c index 37539fa5756..79b3c2c62a4 100644 --- a/dlls/wineandroid.drv/dllmain.c +++ b/dlls/wineandroid.drv/dllmain.c @@ -104,17 +104,27 @@ static NTSTATUS WINAPI android_start_device(void *param, ULONG size) }
+static void CALLBACK register_window_callback( ULONG_PTR arg1, ULONG_PTR arg2, ULONG_PTR arg3 ) +{ + struct register_window_params params = { .arg1 = arg1, .arg2 = arg2, .arg3 = arg3 }; + ANDROID_CALL( register_window, ¶ms ); +} + + /*********************************************************************** * dll initialisation routine */ BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved ) { + struct init_params params; void **callback_table;
if (reason == DLL_PROCESS_ATTACH) return TRUE;
DisableThreadLibraryCalls( inst ); - if (ANDROID_CALL( init, NULL )) return FALSE; + + params.register_window_callback = register_window_callback; + if (ANDROID_CALL( init, ¶ms )) return FALSE;
callback_table = NtCurrentTeb()->Peb->KernelCallbackTable; callback_table[client_start_device] = android_start_device; diff --git a/dlls/wineandroid.drv/init.c b/dlls/wineandroid.drv/init.c index b5f0b69fcec..527eda7a241 100644 --- a/dlls/wineandroid.drv/init.c +++ b/dlls/wineandroid.drv/init.c @@ -48,6 +48,8 @@ static RECT monitor_rc_work; static int device_init_done; static BOOL force_display_devices_refresh;
+PNTAPCFUNC register_window_callback; + typedef struct { struct gdi_physdev dev; @@ -558,6 +560,7 @@ unsigned short *p_java_gdt_sel = NULL;
static HRESULT android_init( void *arg ) { + struct init_params *params = arg; pthread_mutexattr_t attr; jclass class; jobject object; @@ -581,6 +584,8 @@ static HRESULT android_init( void *arg ) pthread_mutex_init( &win_data_mutex, &attr ); pthread_mutexattr_destroy( &attr );
+ register_window_callback = params->register_window_callback; + if ((java_vm = *p_java_vm)) /* running under Java */ { #ifdef __i386__ @@ -608,6 +613,7 @@ const unixlib_entry_t __wine_unix_call_funcs[] = android_init, android_java_init, android_java_uninit, + android_register_window, };
diff --git a/dlls/wineandroid.drv/unixlib.h b/dlls/wineandroid.drv/unixlib.h index 2838047f4fe..8a94bb1253a 100644 --- a/dlls/wineandroid.drv/unixlib.h +++ b/dlls/wineandroid.drv/unixlib.h @@ -26,6 +26,7 @@ enum android_funcs unix_init, unix_java_init, unix_java_uninit, + unix_register_window, unix_funcs_count };
@@ -33,6 +34,13 @@ enum android_funcs extern NTSTATUS unix_call( enum android_funcs func, void *arg ) DECLSPEC_HIDDEN; #define ANDROID_CALL(func, params) unix_call( unix_ ## func, params )
+/* android_init params */ +struct init_params +{ + PNTAPCFUNC register_window_callback; +}; + + /* android_ioctl params */ struct ioctl_params { @@ -41,6 +49,15 @@ struct ioctl_params };
+/* android_register_window params */ +struct register_window_params +{ + UINT_PTR arg1; + UINT_PTR arg2; + UINT_PTR arg3; +}; + + enum { client_start_device = NtUserDriverCallbackFirst,
From: Jacek Caban jacek@codeweavers.com
To allow using it in drivers.
Signed-off-by: Jacek Caban jacek@codeweavers.com --- dlls/win32u/dce.c | 16 ++++++++-------- dlls/win32u/message.c | 6 +++--- dlls/win32u/sysparams.c | 6 ++++-- dlls/win32u/win32u_private.h | 1 - dlls/win32u/window.c | 28 ++++++++++++++-------------- 5 files changed, 29 insertions(+), 28 deletions(-)
diff --git a/dlls/win32u/dce.c b/dlls/win32u/dce.c index fbde3f3d0ec..62d84d7e77b 100644 --- a/dlls/win32u/dce.c +++ b/dlls/win32u/dce.c @@ -810,7 +810,7 @@ void invalidate_dce( WND *win, const RECT *extra_rect )
if (!win->parent) return;
- context = set_thread_dpi_awareness_context( get_window_dpi_awareness_context( win->obj.handle )); + context = SetThreadDpiAwarenessContext( get_window_dpi_awareness_context( win->obj.handle )); get_window_rect( win->obj.handle, &window_rect, get_thread_dpi() );
TRACE("%p parent %p %s (%s)\n", @@ -845,7 +845,7 @@ void invalidate_dce( WND *win, const RECT *extra_rect ) make_dc_dirty( dce ); } } - set_thread_dpi_awareness_context( context ); + SetThreadDpiAwarenessContext( context ); }
/*********************************************************************** @@ -1160,7 +1160,7 @@ static HRGN send_ncpaint( HWND hwnd, HWND *child, UINT *flags ) RECT client, window, update; INT type;
- context = set_thread_dpi_awareness_context( get_window_dpi_awareness_context( hwnd )); + context = SetThreadDpiAwarenessContext( get_window_dpi_awareness_context( hwnd ));
/* check if update rgn overlaps with nonclient area */ type = NtGdiGetRgnBox( whole_rgn, &update ); @@ -1201,7 +1201,7 @@ static HRGN send_ncpaint( HWND hwnd, HWND *child, UINT *flags ) } if (whole_rgn > (HRGN)1) NtGdiDeleteObjectApp( whole_rgn ); } - set_thread_dpi_awareness_context( context ); + SetThreadDpiAwarenessContext( context ); } return client_rgn; } @@ -1500,7 +1500,7 @@ INT WINAPI NtUserGetUpdateRgn( HWND hwnd, HRGN hrgn, BOOL erase ) UINT flags = UPDATE_NOCHILDREN; HRGN update_rgn;
- context = set_thread_dpi_awareness_context( get_window_dpi_awareness_context( hwnd )); + context = SetThreadDpiAwarenessContext( get_window_dpi_awareness_context( hwnd ));
if (erase) flags |= UPDATE_NONCLIENT | UPDATE_ERASE;
@@ -1515,7 +1515,7 @@ INT WINAPI NtUserGetUpdateRgn( HWND hwnd, HRGN hrgn, BOOL erase ) /* map region to client coordinates */ map_window_region( 0, hwnd, hrgn ); } - set_thread_dpi_awareness_context( context ); + SetThreadDpiAwarenessContext( context ); return retval; }
@@ -1564,12 +1564,12 @@ INT WINAPI NtUserExcludeUpdateRgn( HDC hdc, HWND hwnd ) DPI_AWARENESS_CONTEXT context; POINT pt;
- context = set_thread_dpi_awareness_context( get_window_dpi_awareness_context( hwnd )); + context = SetThreadDpiAwarenessContext( get_window_dpi_awareness_context( hwnd )); NtGdiGetDCPoint( hdc, NtGdiGetDCOrg, &pt ); map_window_points( 0, hwnd, &pt, 1, get_thread_dpi() ); NtGdiOffsetRgn( update_rgn, -pt.x, -pt.y ); ret = NtGdiExtSelectClipRgn( hdc, update_rgn, RGN_DIFF ); - set_thread_dpi_awareness_context( context ); + SetThreadDpiAwarenessContext( context ); } NtGdiDeleteObjectApp( update_rgn ); return ret; diff --git a/dlls/win32u/message.c b/dlls/win32u/message.c index bc6db20d164..b41d252457d 100644 --- a/dlls/win32u/message.c +++ b/dlls/win32u/message.c @@ -1420,7 +1420,7 @@ static BOOL process_mouse_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, H }
msg->pt = point_phys_to_win_dpi( msg->hwnd, msg->pt ); - set_thread_dpi_awareness_context( get_window_dpi_awareness_context( msg->hwnd )); + SetThreadDpiAwarenessContext( get_window_dpi_awareness_context( msg->hwnd ));
/* FIXME: is this really the right place for this hook? */ event.message = msg->message; @@ -1599,7 +1599,7 @@ static BOOL process_hardware_message( MSG *msg, UINT hw_id, const struct hardwar get_user_thread_info()->msg_source.originId = msg_data->source.origin;
/* hardware messages are always in physical coords */ - context = set_thread_dpi_awareness_context( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE ); + context = SetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE );
if (msg->message == WM_INPUT || msg->message == WM_INPUT_DEVICE_CHANGE) ret = user_callbacks && user_callbacks->process_rawinput_message( msg, hw_id, msg_data ); @@ -1609,7 +1609,7 @@ static BOOL process_hardware_message( MSG *msg, UINT hw_id, const struct hardwar ret = process_mouse_message( msg, hw_id, msg_data->info, hwnd_filter, first, last, remove ); else ERR( "unknown message type %x\n", msg->message ); - set_thread_dpi_awareness_context( context ); + SetThreadDpiAwarenessContext( context ); return ret; }
diff --git a/dlls/win32u/sysparams.c b/dlls/win32u/sysparams.c index b68bfa3a7ce..902cd7ddb0c 100644 --- a/dlls/win32u/sysparams.c +++ b/dlls/win32u/sysparams.c @@ -1459,8 +1459,10 @@ static DPI_AWARENESS get_awareness_from_dpi_awareness_context( DPI_AWARENESS_CON } }
-/* see SetThreadDpiAwarenessContext */ -DPI_AWARENESS_CONTEXT set_thread_dpi_awareness_context( DPI_AWARENESS_CONTEXT context ) +/********************************************************************** + * SetThreadDpiAwarenessContext (win32u.so) + */ +DPI_AWARENESS_CONTEXT WINAPI SetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT context ) { struct user_thread_info *info = get_user_thread_info(); DPI_AWARENESS prev, val = get_awareness_from_dpi_awareness_context( context ); diff --git a/dlls/win32u/win32u_private.h b/dlls/win32u/win32u_private.h index 053fb25fe36..fd6dba82da2 100644 --- a/dlls/win32u/win32u_private.h +++ b/dlls/win32u/win32u_private.h @@ -427,7 +427,6 @@ extern RECT rect_thread_to_win_dpi( HWND hwnd, RECT rect ) DECLSPEC_HIDDEN; extern HMONITOR monitor_from_point( POINT pt, DWORD flags, UINT dpi ) DECLSPEC_HIDDEN; extern HMONITOR monitor_from_rect( const RECT *rect, DWORD flags, UINT dpi ) DECLSPEC_HIDDEN; extern HMONITOR monitor_from_window( HWND hwnd, DWORD flags, UINT dpi ) DECLSPEC_HIDDEN; -extern DPI_AWARENESS_CONTEXT set_thread_dpi_awareness_context( DPI_AWARENESS_CONTEXT context ) DECLSPEC_HIDDEN; extern void user_lock(void) DECLSPEC_HIDDEN; extern void user_unlock(void) DECLSPEC_HIDDEN; extern void user_check_not_lock(void) DECLSPEC_HIDDEN; diff --git a/dlls/win32u/window.c b/dlls/win32u/window.c index 338063f5fb5..319f47712e6 100644 --- a/dlls/win32u/window.c +++ b/dlls/win32u/window.c @@ -461,7 +461,7 @@ HWND WINAPI NtUserSetParent( HWND hwnd, HWND parent ) if (!ret) return 0;
get_window_rects( hwnd, COORDS_SCREEN, &new_screen_rect, NULL, 0 ); - context = set_thread_dpi_awareness_context( get_window_dpi_awareness_context( hwnd )); + context = SetThreadDpiAwarenessContext( get_window_dpi_awareness_context( hwnd ));
user_driver->pSetParent( full_handle, parent, old_parent );
@@ -478,7 +478,7 @@ HWND WINAPI NtUserSetParent( HWND hwnd, HWND parent )
if (was_visible) NtUserShowWindow( hwnd, SW_SHOW );
- set_thread_dpi_awareness_context( context ); + SetThreadDpiAwarenessContext( context ); return old_parent; }
@@ -3405,7 +3405,7 @@ BOOL set_window_pos( WINDOWPOS *winpos, int parent_x, int parent_y ) else if (winpos->cy > 32767) winpos->cy = 32767; }
- context = set_thread_dpi_awareness_context( get_window_dpi_awareness_context( winpos->hwnd )); + context = SetThreadDpiAwarenessContext( get_window_dpi_awareness_context( winpos->hwnd ));
if (!calc_winpos( winpos, &old_window_rect, &old_client_rect, &new_window_rect, &new_client_rect )) goto done; @@ -3480,7 +3480,7 @@ BOOL set_window_pos( WINDOWPOS *winpos, int parent_x, int parent_y ) } ret = TRUE; done: - set_thread_dpi_awareness_context( context ); + SetThreadDpiAwarenessContext( context ); return ret; }
@@ -3816,7 +3816,7 @@ MINMAXINFO get_min_max_info( HWND hwnd ) RECT rc; WND *win;
- context = set_thread_dpi_awareness_context( get_window_dpi_awareness_context( hwnd )); + context = SetThreadDpiAwarenessContext( get_window_dpi_awareness_context( hwnd ));
/* Compute default values */
@@ -3887,7 +3887,7 @@ MINMAXINFO get_min_max_info( HWND hwnd ) minmax.ptMaxTrackSize.x = max( minmax.ptMaxTrackSize.x, minmax.ptMinTrackSize.x ); minmax.ptMaxTrackSize.y = max( minmax.ptMaxTrackSize.y, minmax.ptMinTrackSize.y );
- set_thread_dpi_awareness_context( context ); + SetThreadDpiAwarenessContext( context ); return minmax; }
@@ -4198,13 +4198,13 @@ void update_window_state( HWND hwnd ) return; }
- context = set_thread_dpi_awareness_context( get_window_dpi_awareness_context( hwnd )); + context = SetThreadDpiAwarenessContext( get_window_dpi_awareness_context( hwnd )); get_window_rects( hwnd, COORDS_PARENT, &window_rect, &client_rect, get_thread_dpi() ); valid_rects[0] = valid_rects[1] = client_rect; apply_window_pos( hwnd, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW, &window_rect, &client_rect, valid_rects ); - set_thread_dpi_awareness_context( context ); + SetThreadDpiAwarenessContext( context ); }
/*********************************************************************** @@ -4225,7 +4225,7 @@ static BOOL show_window( HWND hwnd, INT cmd )
TRACE( "hwnd=%p, cmd=%d, was_visible %d\n", hwnd, cmd, was_visible );
- context = set_thread_dpi_awareness_context( get_window_dpi_awareness_context( hwnd )); + context = SetThreadDpiAwarenessContext( get_window_dpi_awareness_context( hwnd ));
switch(cmd) { @@ -4377,7 +4377,7 @@ static BOOL show_window( HWND hwnd, INT cmd ) }
done: - set_thread_dpi_awareness_context( context ); + SetThreadDpiAwarenessContext( context ); return was_visible; }
@@ -5163,7 +5163,7 @@ HWND WINAPI NtUserCreateWindowEx( DWORD ex_style, UNICODE_STRING *class_name,
if (parent) map_dpi_create_struct( &cs, thread_dpi, win_dpi );
- context = set_thread_dpi_awareness_context( get_window_dpi_awareness_context( hwnd )); + context = SetThreadDpiAwarenessContext( get_window_dpi_awareness_context( hwnd ));
/* send the WM_GETMINMAXINFO message and fix the size if needed */
@@ -5261,7 +5261,7 @@ HWND WINAPI NtUserCreateWindowEx( DWORD ex_style, UNICODE_STRING *class_name, send_parent_notify( hwnd, WM_CREATE ); if (!is_window( hwnd )) { - set_thread_dpi_awareness_context( context ); + SetThreadDpiAwarenessContext( context ); return 0; }
@@ -5290,12 +5290,12 @@ HWND WINAPI NtUserCreateWindowEx( DWORD ex_style, UNICODE_STRING *class_name, call_hooks( WH_SHELL, HSHELL_WINDOWCREATED, (WPARAM)hwnd, 0, TRUE );
TRACE( "created window %p\n", hwnd ); - set_thread_dpi_awareness_context( context ); + SetThreadDpiAwarenessContext( context ); return hwnd;
failed: destroy_window( hwnd ); - set_thread_dpi_awareness_context( context ); + SetThreadDpiAwarenessContext( context ); return 0; }
From: Jacek Caban jacek@codeweavers.com
Signed-off-by: Jacek Caban jacek@codeweavers.com --- dlls/wineandroid.drv/Makefile.in | 7 +++---- dlls/wineandroid.drv/android.h | 2 ++ dlls/wineandroid.drv/device.c | 11 +++++++---- dlls/wineandroid.drv/dllmain.c | 10 +++++++++- dlls/wineandroid.drv/init.c | 12 +++++++++++- dlls/wineandroid.drv/keyboard.c | 4 ++++ dlls/wineandroid.drv/opengl.c | 4 ++++ dlls/wineandroid.drv/unixlib.h | 3 ++- dlls/wineandroid.drv/window.c | 15 ++++++++++----- 9 files changed, 52 insertions(+), 16 deletions(-)
diff --git a/dlls/wineandroid.drv/Makefile.in b/dlls/wineandroid.drv/Makefile.in index 4c4b63d2e78..a56ef3dc290 100644 --- a/dlls/wineandroid.drv/Makefile.in +++ b/dlls/wineandroid.drv/Makefile.in @@ -1,9 +1,8 @@ EXTRADEFS = -DWINE_NO_LONG_TYPES MODULE = wineandroid.drv -IMPORTS = user32 ntoskrnl win32u -EXTRALIBS = $(PTHREAD_LIBS) - -EXTRADLLFLAGS = -mcygwin +UNIXLIB = wineandroid.so +IMPORTS = ntoskrnl +EXTRALIBS = -lwin32u $(PTHREAD_LIBS)
C_SRCS = \ device.c \ diff --git a/dlls/wineandroid.drv/android.h b/dlls/wineandroid.drv/android.h index 22652f11d27..57f566b3cfd 100644 --- a/dlls/wineandroid.drv/android.h +++ b/dlls/wineandroid.drv/android.h @@ -120,6 +120,8 @@ extern NTSTATUS android_java_init( void *arg ) DECLSPEC_HIDDEN; extern NTSTATUS android_java_uninit( void *arg ) DECLSPEC_HIDDEN; extern NTSTATUS android_register_window( void *arg ) DECLSPEC_HIDDEN; extern PNTAPCFUNC register_window_callback; +extern NTSTATUS (WINAPI *pNtWaitForMultipleObjects)( ULONG,const HANDLE*,BOOLEAN, + BOOLEAN,const LARGE_INTEGER* ) DECLSPEC_HIDDEN;
extern unsigned int screen_width DECLSPEC_HIDDEN; extern unsigned int screen_height DECLSPEC_HIDDEN; diff --git a/dlls/wineandroid.drv/device.c b/dlls/wineandroid.drv/device.c index fa11e0d071e..62bcbae72f3 100644 --- a/dlls/wineandroid.drv/device.c +++ b/dlls/wineandroid.drv/device.c @@ -18,6 +18,10 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
+#if 0 +#pragma makedep unix +#endif + #include "config.h"
#include <assert.h> @@ -1174,10 +1178,9 @@ NTSTATUS android_java_uninit( void *arg )
void start_android_device(void) { - /* FIXME: use KeUserModeCallback instead */ - NTSTATUS (WINAPI *func)(void *, ULONG) = - ((void **)NtCurrentTeb()->Peb->KernelCallbackTable)[client_start_device]; - func( NULL, 0 ); + void *ret_ptr; + ULONG ret_len; + thread = ULongToHandle( KeUserModeCallback( client_start_device, NULL, 0, &ret_ptr, &ret_len )); }
diff --git a/dlls/wineandroid.drv/dllmain.c b/dlls/wineandroid.drv/dllmain.c index 79b3c2c62a4..81581591770 100644 --- a/dlls/wineandroid.drv/dllmain.c +++ b/dlls/wineandroid.drv/dllmain.c @@ -32,6 +32,9 @@ WINE_DEFAULT_DEBUG_CHANNEL(android);
+static unixlib_handle_t unix_handle; +static NTSTATUS (CDECL *unix_call)( enum android_funcs code, void *params ); + extern NTSTATUS CDECL wine_ntoskrnl_main_loop( HANDLE stop_event ); static HANDLE stop_event; static HANDLE thread; @@ -122,13 +125,18 @@ BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved ) if (reason == DLL_PROCESS_ATTACH) return TRUE;
DisableThreadLibraryCalls( inst ); + if (NtQueryVirtualMemory( GetCurrentProcess(), inst, MemoryWineUnixFuncs, + &unix_handle, sizeof(unix_handle), NULL )) + return FALSE;
params.register_window_callback = register_window_callback; - if (ANDROID_CALL( init, ¶ms )) return FALSE; + params.pNtWaitForMultipleObjects = NtWaitForMultipleObjects; + if (__wine_unix_call( unix_handle, unix_init, ¶ms )) return FALSE;
callback_table = NtCurrentTeb()->Peb->KernelCallbackTable; callback_table[client_start_device] = android_start_device;
+ unix_call = params.unix_call; return TRUE; }
diff --git a/dlls/wineandroid.drv/init.c b/dlls/wineandroid.drv/init.c index 527eda7a241..170ccb064a7 100644 --- a/dlls/wineandroid.drv/init.c +++ b/dlls/wineandroid.drv/init.c @@ -18,6 +18,10 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
+#if 0 +#pragma makedep unix +#endif + #define NONAMELESSSTRUCT #define NONAMELESSUNION #include "config.h" @@ -558,6 +562,10 @@ JavaVM **p_java_vm = NULL; jobject *p_java_object = NULL; unsigned short *p_java_gdt_sel = NULL;
+static NTSTATUS CDECL unix_call( enum android_funcs code, void *params ); +NTSTATUS (WINAPI *pNtWaitForMultipleObjects)( ULONG,const HANDLE*,BOOLEAN, + BOOLEAN,const LARGE_INTEGER* ); + static HRESULT android_init( void *arg ) { struct init_params *params = arg; @@ -603,6 +611,8 @@ static HRESULT android_init( void *arg ) #endif } __wine_set_user_driver( &android_drv_funcs, WINE_GDI_DRIVER_VERSION ); + pNtWaitForMultipleObjects = params->pNtWaitForMultipleObjects; + params->unix_call = unix_call; return STATUS_SUCCESS; }
@@ -621,7 +631,7 @@ C_ASSERT( ARRAYSIZE(__wine_unix_call_funcs) == unix_funcs_count );
/* FIXME: Use __wine_unix_call instead */ -NTSTATUS unix_call( enum android_funcs code, void *params ) +static NTSTATUS CDECL unix_call( enum android_funcs code, void *params ) { return __wine_unix_call_funcs[code]( params ); } diff --git a/dlls/wineandroid.drv/keyboard.c b/dlls/wineandroid.drv/keyboard.c index e92079c0f59..82035cc14dd 100644 --- a/dlls/wineandroid.drv/keyboard.c +++ b/dlls/wineandroid.drv/keyboard.c @@ -26,6 +26,10 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
+#if 0 +#pragma makedep unix +#endif + #define NONAMELESSUNION #define NONAMELESSSTRUCT
diff --git a/dlls/wineandroid.drv/opengl.c b/dlls/wineandroid.drv/opengl.c index d7026be6599..911f6e3f3d1 100644 --- a/dlls/wineandroid.drv/opengl.c +++ b/dlls/wineandroid.drv/opengl.c @@ -24,6 +24,10 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
+#if 0 +#pragma makedep unix +#endif + #include "config.h"
#include <assert.h> diff --git a/dlls/wineandroid.drv/unixlib.h b/dlls/wineandroid.drv/unixlib.h index 8a94bb1253a..92d28176ee7 100644 --- a/dlls/wineandroid.drv/unixlib.h +++ b/dlls/wineandroid.drv/unixlib.h @@ -31,13 +31,14 @@ enum android_funcs };
/* FIXME: Use __wine_unix_call when the rest of the stack is ready */ -extern NTSTATUS unix_call( enum android_funcs func, void *arg ) DECLSPEC_HIDDEN; #define ANDROID_CALL(func, params) unix_call( unix_ ## func, params )
/* android_init params */ struct init_params { PNTAPCFUNC register_window_callback; + NTSTATUS (WINAPI *pNtWaitForMultipleObjects)( ULONG,const HANDLE*,BOOLEAN,BOOLEAN,const LARGE_INTEGER* ); + NTSTATUS (CDECL *unix_call)( enum android_funcs code, void *params ); };
diff --git a/dlls/wineandroid.drv/window.c b/dlls/wineandroid.drv/window.c index 3860e0a2772..c580a36c828 100644 --- a/dlls/wineandroid.drv/window.c +++ b/dlls/wineandroid.drv/window.c @@ -20,6 +20,10 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
+#if 0 +#pragma makedep unix +#endif + #define NONAMELESSUNION #define NONAMELESSSTRUCT
@@ -1164,14 +1168,15 @@ static const struct static int get_cursor_system_id( const ICONINFOEXW *info ) { const struct system_cursors *cursors; + const WCHAR *module; unsigned int i; - HMODULE module;
if (info->szResName[0]) return 0; /* only integer resources are supported here */ - if (!(module = GetModuleHandleW( info->szModName ))) return 0;
+ if ((module = wcsrchr( info->szModName, '\' ))) module++; + else module = info->szModName; for (i = 0; i < ARRAY_SIZE( module_cursors ); i++) - if (GetModuleHandleW( module_cursors[i].name ) == module) break; + if (!wcsicmp( module, module_cursors[i].name )) break; if (i == ARRAY_SIZE( module_cursors )) return 0;
cursors = module_cursors[i].cursors; @@ -1207,8 +1212,8 @@ NTSTATUS ANDROID_MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *handles if (current_event) mask = 0; if (process_events( mask )) return count - 1; } - return NtWaitForMultipleObjects( count, handles, !(flags & MWMO_WAITALL), - !!(flags & MWMO_ALERTABLE), timeout ); + return pNtWaitForMultipleObjects( count, handles, !(flags & MWMO_WAITALL), + !!(flags & MWMO_ALERTABLE), timeout ); }
/**********************************************************************
This merge request was approved by Huw Davies.