From: Rémi Bernon rbernon@codeweavers.com
--- dlls/win32u/dce.c | 23 +++++++++++------------ dlls/wineandroid.drv/window.c | 14 +++----------- dlls/winemac.drv/surface.c | 21 ++++----------------- dlls/winewayland.drv/window_surface.c | 12 +++--------- dlls/winex11.drv/bitblt.c | 14 +++----------- include/wine/gdi_driver.h | 9 +++++++++ 6 files changed, 33 insertions(+), 60 deletions(-)
diff --git a/dlls/win32u/dce.c b/dlls/win32u/dce.c index f8e9b0bbe6e..f62cddd2116 100644 --- a/dlls/win32u/dce.c +++ b/dlls/win32u/dce.c @@ -116,7 +116,7 @@ static const struct window_surface_funcs dummy_surface_funcs = dummy_surface_destroy };
-struct window_surface dummy_surface = { &dummy_surface_funcs, { NULL, NULL }, 1, { 0, 0, 1, 1 } }; +struct window_surface dummy_surface = { &dummy_surface_funcs, { NULL, NULL }, 1, { 0, 0, 1, 1 }, PTHREAD_MUTEX_INITIALIZER };
/******************************************************************* * Off-screen window surface. @@ -125,7 +125,6 @@ struct window_surface dummy_surface = { &dummy_surface_funcs, { NULL, NULL }, 1, struct offscreen_window_surface { struct window_surface header; - pthread_mutex_t mutex; RECT bounds; char *bits; BITMAPINFO info; @@ -139,16 +138,14 @@ static struct offscreen_window_surface *impl_from_window_surface( struct window_ return CONTAINING_RECORD( base, struct offscreen_window_surface, header ); }
-static void offscreen_window_surface_lock( struct window_surface *base ) +static void offscreen_window_surface_lock( struct window_surface *surface ) { - struct offscreen_window_surface *impl = impl_from_window_surface( base ); - pthread_mutex_lock( &impl->mutex ); + pthread_mutex_lock( &surface->mutex ); }
-static void offscreen_window_surface_unlock( struct window_surface *base ) +static void offscreen_window_surface_unlock( struct window_surface *surface ) { - struct offscreen_window_surface *impl = impl_from_window_surface( base ); - pthread_mutex_unlock( &impl->mutex ); + pthread_mutex_unlock( &surface->mutex ); }
static RECT *offscreen_window_surface_get_bounds( struct window_surface *base ) @@ -179,7 +176,6 @@ static void offscreen_window_surface_flush( struct window_surface *base ) static void offscreen_window_surface_destroy( struct window_surface *base ) { struct offscreen_window_surface *impl = impl_from_window_surface( base ); - pthread_mutex_destroy( &impl->mutex ); free( impl ); }
@@ -221,8 +217,6 @@ void create_offscreen_window_surface( const RECT *visible_rect, struct window_su if (!(impl = calloc(1, offsetof( struct offscreen_window_surface, info.bmiColors[0] ) + size))) return; window_surface_init( &impl->header, &offscreen_window_surface_funcs, &surface_rect );
- pthread_mutex_init( &impl->mutex, NULL ); - reset_bounds( &impl->bounds );
impl->bits = (char *)&impl->info.bmiColors[0]; @@ -246,6 +240,7 @@ W32KAPI void window_surface_init( struct window_surface *surface, const struct w surface->funcs = funcs; surface->ref = 1; surface->rect = *rect; + pthread_mutex_init( &surface->mutex, NULL ); }
W32KAPI void window_surface_add_ref( struct window_surface *surface ) @@ -256,7 +251,11 @@ W32KAPI void window_surface_add_ref( struct window_surface *surface ) W32KAPI void window_surface_release( struct window_surface *surface ) { ULONG ret = InterlockedDecrement( &surface->ref ); - if (!ret) surface->funcs->destroy( surface ); + if (!ret) + { + if (surface != &dummy_surface) pthread_mutex_destroy( &surface->mutex ); + surface->funcs->destroy( surface ); + } }
/******************************************************************* diff --git a/dlls/wineandroid.drv/window.c b/dlls/wineandroid.drv/window.c index 7397e1758f4..ac6b211a34c 100644 --- a/dlls/wineandroid.drv/window.c +++ b/dlls/wineandroid.drv/window.c @@ -580,7 +580,6 @@ struct android_window_surface BYTE alpha; COLORREF color_key; void *bits; - pthread_mutex_t mutex; BITMAPINFO info; /* variable size, must be last */ };
@@ -651,9 +650,7 @@ static void apply_line_region( DWORD *dst, int width, int x, int y, const RECT * */ static void android_surface_lock( struct window_surface *window_surface ) { - struct android_window_surface *surface = get_android_surface( window_surface ); - - pthread_mutex_lock( &surface->mutex ); + pthread_mutex_lock( &window_surface->mutex ); }
/*********************************************************************** @@ -661,9 +658,7 @@ static void android_surface_lock( struct window_surface *window_surface ) */ static void android_surface_unlock( struct window_surface *window_surface ) { - struct android_window_surface *surface = get_android_surface( window_surface ); - - pthread_mutex_unlock( &surface->mutex ); + pthread_mutex_unlock( &window_surface->mutex ); }
/*********************************************************************** @@ -807,7 +802,6 @@ static void android_surface_destroy( struct window_surface *window_surface ) if (surface->region) NtGdiDeleteObjectApp( surface->region ); release_ioctl_window( surface->window ); free( surface->bits ); - pthread_mutex_destroy( &surface->mutex ); free( surface ); }
@@ -913,8 +907,6 @@ 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 );
- pthread_mutex_init( &surface->mutex, NULL ); - surface->hwnd = hwnd; surface->window = get_ioctl_window( hwnd ); surface->alpha = alpha; @@ -931,7 +923,7 @@ static struct window_surface *create_surface( HWND hwnd, const RECT *rect, return &surface->header;
failed: - android_surface_destroy( &surface->header ); + window_surface_release( &surface->header ); return NULL; }
diff --git a/dlls/winemac.drv/surface.c b/dlls/winemac.drv/surface.c index 2ad17c625d9..aa4bc4a9cc9 100644 --- a/dlls/winemac.drv/surface.c +++ b/dlls/winemac.drv/surface.c @@ -70,7 +70,6 @@ struct macdrv_window_surface BOOL use_alpha; RGNDATA *blit_data; BYTE *bits; - pthread_mutex_t mutex; BITMAPINFO info; /* variable size, must be last */ };
@@ -102,9 +101,7 @@ static void update_blit_data(struct macdrv_window_surface *surface) */ static void macdrv_surface_lock(struct window_surface *window_surface) { - struct macdrv_window_surface *surface = get_mac_surface(window_surface); - - pthread_mutex_lock(&surface->mutex); + pthread_mutex_lock(&window_surface->mutex); }
/*********************************************************************** @@ -112,9 +109,7 @@ static void macdrv_surface_lock(struct window_surface *window_surface) */ static void macdrv_surface_unlock(struct window_surface *window_surface) { - struct macdrv_window_surface *surface = get_mac_surface(window_surface); - - pthread_mutex_unlock(&surface->mutex); + pthread_mutex_unlock(&window_surface->mutex); }
/*********************************************************************** @@ -215,7 +210,6 @@ static void macdrv_surface_destroy(struct window_surface *window_surface) if (surface->drawn) NtGdiDeleteObjectApp(surface->drawn); free(surface->blit_data); free(surface->bits); - pthread_mutex_destroy(&surface->mutex); free(surface); }
@@ -246,19 +240,12 @@ struct window_surface *create_surface(macdrv_window window, const RECT *rect, struct macdrv_window_surface *old_mac_surface = get_mac_surface(old_surface); int width = rect->right - rect->left, height = rect->bottom - rect->top; DWORD *colors; - int err; DWORD window_background;
surface = calloc(1, FIELD_OFFSET(struct macdrv_window_surface, info.bmiColors[3])); if (!surface) return NULL; window_surface_init( &surface->header, &macdrv_surface_funcs, rect );
- if ((err = pthread_mutex_init(&surface->mutex, NULL))) - { - free(surface); - return NULL; - } - surface->info.bmiHeader.biSize = sizeof(surface->info.bmiHeader); surface->info.bmiHeader.biWidth = width; surface->info.bmiHeader.biHeight = -height; /* top-down */ @@ -298,7 +285,7 @@ struct window_surface *create_surface(macdrv_window window, const RECT *rect, return &surface->header;
failed: - macdrv_surface_destroy(&surface->header); + window_surface_release(&surface->header); return NULL; }
@@ -317,7 +304,7 @@ void set_surface_use_alpha(struct window_surface *window_surface, BOOL use_alpha void set_window_surface(macdrv_window window, struct window_surface *window_surface) { struct macdrv_window_surface *surface = get_mac_surface(window_surface); - macdrv_set_window_surface(window, window_surface, surface ? &surface->mutex : NULL); + macdrv_set_window_surface(window, window_surface, surface ? &window_surface->mutex : NULL); }
/*********************************************************************** diff --git a/dlls/winewayland.drv/window_surface.c b/dlls/winewayland.drv/window_surface.c index 36388585faa..4844ea29b99 100644 --- a/dlls/winewayland.drv/window_surface.c +++ b/dlls/winewayland.drv/window_surface.c @@ -48,7 +48,6 @@ struct wayland_window_surface struct wayland_buffer_queue *wayland_buffer_queue; RECT bounds; void *bits; - pthread_mutex_t mutex; BITMAPINFO info; };
@@ -224,8 +223,7 @@ static void wayland_buffer_queue_add_damage(struct wayland_buffer_queue *queue, */ static void wayland_window_surface_lock(struct window_surface *window_surface) { - struct wayland_window_surface *wws = wayland_window_surface_cast(window_surface); - pthread_mutex_lock(&wws->mutex); + pthread_mutex_lock(&window_surface->mutex); }
/*********************************************************************** @@ -233,8 +231,7 @@ static void wayland_window_surface_lock(struct window_surface *window_surface) */ static void wayland_window_surface_unlock(struct window_surface *window_surface) { - struct wayland_window_surface *wws = wayland_window_surface_cast(window_surface); - pthread_mutex_unlock(&wws->mutex); + pthread_mutex_unlock(&window_surface->mutex); }
/*********************************************************************** @@ -481,7 +478,6 @@ static void wayland_window_surface_destroy(struct window_surface *window_surface
TRACE("surface=%p\n", wws);
- pthread_mutex_destroy(&wws->mutex); if (wws->wayland_buffer_queue) wayland_buffer_queue_destroy(wws->wayland_buffer_queue); free(wws->bits); @@ -523,8 +519,6 @@ struct window_surface *wayland_window_surface_create(HWND hwnd, const RECT *rect wws->info.bmiHeader.biPlanes = 1; wws->info.bmiHeader.biSizeImage = width * height * 4;
- pthread_mutex_init(&wws->mutex, NULL); - wws->hwnd = hwnd; reset_bounds(&wws->bounds);
@@ -537,7 +531,7 @@ struct window_surface *wayland_window_surface_create(HWND hwnd, const RECT *rect return &wws->header;
failed: - wayland_window_surface_destroy(&wws->header); + window_surface_release(&wws->header); return NULL; }
diff --git a/dlls/winex11.drv/bitblt.c b/dlls/winex11.drv/bitblt.c index a814fdb94b0..bb4b11be866 100644 --- a/dlls/winex11.drv/bitblt.c +++ b/dlls/winex11.drv/bitblt.c @@ -1587,7 +1587,6 @@ struct x11drv_window_surface #ifdef HAVE_LIBXXSHM XShmSegmentInfo shminfo; #endif - pthread_mutex_t mutex; BITMAPINFO info; /* variable size, must be last */ };
@@ -1833,9 +1832,7 @@ failed: */ static void x11drv_surface_lock( struct window_surface *window_surface ) { - struct x11drv_window_surface *surface = get_x11_surface( window_surface ); - - pthread_mutex_lock( &surface->mutex ); + pthread_mutex_lock( &window_surface->mutex ); }
/*********************************************************************** @@ -1843,9 +1840,7 @@ static void x11drv_surface_lock( struct window_surface *window_surface ) */ static void x11drv_surface_unlock( struct window_surface *window_surface ) { - struct x11drv_window_surface *surface = get_x11_surface( window_surface ); - - pthread_mutex_unlock( &surface->mutex ); + pthread_mutex_unlock( &window_surface->mutex ); }
/*********************************************************************** @@ -1993,7 +1988,6 @@ static void x11drv_surface_destroy( struct window_surface *window_surface ) } if (surface->region) NtGdiDeleteObjectApp( surface->region );
- pthread_mutex_destroy( &surface->mutex ); free( surface ); }
@@ -2031,8 +2025,6 @@ struct window_surface *create_surface( Window window, const XVisualInfo *vis, co surface->info.bmiHeader.biSizeImage = get_dib_image_size( &surface->info ); if (format->bits_per_pixel > 8) set_color_info( vis, &surface->info, use_alpha );
- pthread_mutex_init( &surface->mutex, NULL ); - surface->window = window; surface->is_argb = (use_alpha && vis->depth == 32 && surface->info.bmiHeader.biCompression == BI_RGB); set_color_key( surface, color_key ); @@ -2072,7 +2064,7 @@ struct window_surface *create_surface( Window window, const XVisualInfo *vis, co return &surface->header;
failed: - x11drv_surface_destroy( &surface->header ); + window_surface_release( &surface->header ); return NULL; }
diff --git a/include/wine/gdi_driver.h b/include/wine/gdi_driver.h index e1a7f2bbffc..53555db972b 100644 --- a/include/wine/gdi_driver.h +++ b/include/wine/gdi_driver.h @@ -25,6 +25,13 @@ #error The GDI driver can only be used on the Unix side #endif
+#include <stdarg.h> +#include <stddef.h> + +#include <pthread.h> + +#include "windef.h" +#include "winbase.h" #include "winternl.h" #include "ntuser.h" #include "immdev.h" @@ -219,6 +226,8 @@ struct window_surface struct list entry; /* entry in global list managed by user32 */ LONG ref; /* reference count */ RECT rect; /* constant, no locking needed */ + + pthread_mutex_t mutex; DWORD draw_start_ticks; /* start ticks of fresh draw */ /* driver-specific fields here */ };