win32u: Use helpers to lock/unlock window surfaces.

This commit is contained in:
Rémi Bernon 2024-05-26 14:21:54 +02:00 committed by Alexandre Julliard
parent 00aec714dd
commit 1565d529ba
9 changed files with 58 additions and 142 deletions

View file

@ -56,16 +56,6 @@ static pthread_mutex_t surfaces_lock = PTHREAD_MUTEX_INITIALIZER;
* Dummy window surface for windows that shouldn't get painted.
*/
static void dummy_surface_lock( struct window_surface *window_surface )
{
/* nothing to do */
}
static void dummy_surface_unlock( struct window_surface *window_surface )
{
/* nothing to do */
}
static void *dummy_surface_get_bitmap_info( struct window_surface *window_surface, BITMAPINFO *info )
{
static DWORD dummy_data;
@ -107,8 +97,6 @@ static void dummy_surface_destroy( struct window_surface *window_surface )
static const struct window_surface_funcs dummy_surface_funcs =
{
dummy_surface_lock,
dummy_surface_unlock,
dummy_surface_get_bitmap_info,
dummy_surface_get_bounds,
dummy_surface_set_region,
@ -138,16 +126,6 @@ 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 *surface )
{
pthread_mutex_lock( &surface->mutex );
}
static void offscreen_window_surface_unlock( struct window_surface *surface )
{
pthread_mutex_unlock( &surface->mutex );
}
static RECT *offscreen_window_surface_get_bounds( struct window_surface *base )
{
struct offscreen_window_surface *impl = impl_from_window_surface( base );
@ -168,9 +146,9 @@ static void offscreen_window_surface_set_region( struct window_surface *base, HR
static void offscreen_window_surface_flush( struct window_surface *base )
{
struct offscreen_window_surface *impl = impl_from_window_surface( base );
base->funcs->lock( base );
window_surface_lock( base );
reset_bounds( &impl->bounds );
base->funcs->unlock( base );
window_surface_unlock( base );
}
static void offscreen_window_surface_destroy( struct window_surface *base )
@ -181,8 +159,6 @@ static void offscreen_window_surface_destroy( struct window_surface *base )
static const struct window_surface_funcs offscreen_window_surface_funcs =
{
offscreen_window_surface_lock,
offscreen_window_surface_unlock,
offscreen_window_surface_get_bitmap_info,
offscreen_window_surface_get_bounds,
offscreen_window_surface_set_region,
@ -258,6 +234,18 @@ W32KAPI void window_surface_release( struct window_surface *surface )
}
}
W32KAPI void window_surface_lock( struct window_surface *surface )
{
if (surface == &dummy_surface) return;
pthread_mutex_lock( &surface->mutex );
}
W32KAPI void window_surface_unlock( struct window_surface *surface )
{
if (surface == &dummy_surface) return;
pthread_mutex_unlock( &surface->mutex );
}
/*******************************************************************
* register_window_surface
*
@ -1171,12 +1159,12 @@ static void copy_bits_from_surface( HWND hwnd, struct window_surface *surface,
else
{
bits = surface->funcs->get_info( surface, info );
surface->funcs->lock( surface );
window_surface_lock( surface );
NtGdiSetDIBitsToDeviceInternal( hdc, dst->left, dst->top, dst->right - dst->left, dst->bottom - dst->top,
src->left - surface->rect.left, surface->rect.bottom - src->bottom,
0, surface->rect.bottom - surface->rect.top,
bits, info, DIB_RGB_COLORS, 0, 0, FALSE, NULL );
surface->funcs->unlock( surface );
window_surface_unlock( surface );
}
NtUserReleaseDC( hwnd, hdc );

View file

@ -751,7 +751,7 @@ static inline void lock_surface( struct windrv_physdev *dev )
if (!dev->lock_count++)
{
surface->funcs->lock( surface );
window_surface_lock( surface );
if (IsRectEmpty( dev->dibdrv->bounds ) || !surface->draw_start_ticks)
surface->draw_start_ticks = NtGetTickCount();
}
@ -764,7 +764,7 @@ static inline void unlock_surface( struct windrv_physdev *dev )
if (!--dev->lock_count)
{
DWORD ticks = NtGetTickCount() - surface->draw_start_ticks;
surface->funcs->unlock( surface );
window_surface_unlock( surface );
if (ticks > FLUSH_PERIOD) surface->funcs->flush( dev->surface );
}
}

View file

@ -645,22 +645,6 @@ static void apply_line_region( DWORD *dst, int width, int x, int y, const RECT *
if (width > 0) memset( dst, 0, width * sizeof(*dst) );
}
/***********************************************************************
* android_surface_lock
*/
static void android_surface_lock( struct window_surface *window_surface )
{
pthread_mutex_lock( &window_surface->mutex );
}
/***********************************************************************
* android_surface_unlock
*/
static void android_surface_unlock( struct window_surface *window_surface )
{
pthread_mutex_unlock( &window_surface->mutex );
}
/***********************************************************************
* android_surface_get_bitmap_info
*/
@ -691,7 +675,7 @@ static void android_surface_set_region( struct window_surface *window_surface, H
TRACE( "updating surface %p hwnd %p with %p\n", surface, surface->hwnd, region );
window_surface->funcs->lock( window_surface );
window_surface_lock( window_surface );
if (!region)
{
if (surface->region) NtGdiDeleteObjectApp( surface->region );
@ -702,7 +686,7 @@ static void android_surface_set_region( struct window_surface *window_surface, H
if (!surface->region) surface->region = NtGdiCreateRectRgn( 0, 0, 0, 0 );
NtGdiCombineRgn( surface->region, region, 0, RGN_COPY );
}
window_surface->funcs->unlock( window_surface );
window_surface_unlock( window_surface );
set_surface_region( &surface->header, (HRGN)1 );
}
@ -717,12 +701,12 @@ static void android_surface_flush( struct window_surface *window_surface )
RECT rect;
BOOL needs_flush;
window_surface->funcs->lock( window_surface );
window_surface_lock( window_surface );
SetRect( &rect, 0, 0, surface->header.rect.right - surface->header.rect.left,
surface->header.rect.bottom - surface->header.rect.top );
needs_flush = intersect_rect( &rect, &rect, &surface->bounds );
reset_bounds( &surface->bounds );
window_surface->funcs->unlock( window_surface );
window_surface_unlock( window_surface );
if (!needs_flush) return;
TRACE( "flushing %p hwnd %p surface %s rect %s bits %p alpha %02x key %08x region %u rects\n",
@ -807,8 +791,6 @@ static void android_surface_destroy( struct window_surface *window_surface )
static const struct window_surface_funcs android_surface_funcs =
{
android_surface_lock,
android_surface_unlock,
android_surface_get_bitmap_info,
android_surface_get_bounds,
android_surface_set_region,
@ -880,11 +862,11 @@ static void set_surface_region( struct window_surface *window_surface, HRGN win_
}
done:
window_surface->funcs->lock( window_surface );
window_surface_lock( window_surface );
free( surface->region_data );
surface->region_data = data;
*window_surface->funcs->get_bounds( window_surface ) = surface->header.rect;
window_surface->funcs->unlock( window_surface );
window_surface_unlock( window_surface );
if (region != win_region) NtGdiDeleteObjectApp( region );
}
@ -938,14 +920,14 @@ static void set_surface_layered( struct window_surface *window_surface, BYTE alp
if (window_surface->funcs != &android_surface_funcs) return; /* we may get the null surface */
window_surface->funcs->lock( window_surface );
window_surface_lock( window_surface );
prev_key = surface->color_key;
prev_alpha = surface->alpha;
surface->alpha = alpha;
set_color_key( surface, color_key );
if (alpha != prev_alpha || surface->color_key != prev_key) /* refresh */
*window_surface->funcs->get_bounds( window_surface ) = surface->header.rect;
window_surface->funcs->unlock( window_surface );
window_surface_unlock( window_surface );
}
/***********************************************************************
@ -1577,7 +1559,7 @@ BOOL ANDROID_UpdateLayeredWindow( HWND hwnd, const UPDATELAYEREDWINDOWINFO *info
NtGdiSelectBitmap( hdc, dib );
surface->funcs->lock( surface );
window_surface_lock( surface );
if (info->prcDirty)
{
@ -1600,7 +1582,7 @@ BOOL ANDROID_UpdateLayeredWindow( HWND hwnd, const UPDATELAYEREDWINDOWINFO *info
add_bounds_rect( surface->funcs->get_bounds( surface ), &rect );
}
surface->funcs->unlock( surface );
window_surface_unlock( surface );
surface->funcs->flush( surface );
done:
@ -1630,9 +1612,9 @@ LRESULT ANDROID_WindowMessage( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
struct window_surface *surface = data->surface;
if (surface)
{
surface->funcs->lock( surface );
window_surface_lock( surface );
*surface->funcs->get_bounds( surface ) = surface->rect;
surface->funcs->unlock( surface );
window_surface_unlock( surface );
if (is_argb_surface( surface )) surface->funcs->flush( surface );
}
release_win_data( data );

View file

@ -96,22 +96,6 @@ static void update_blit_data(struct macdrv_window_surface *surface)
}
}
/***********************************************************************
* macdrv_surface_lock
*/
static void macdrv_surface_lock(struct window_surface *window_surface)
{
pthread_mutex_lock(&window_surface->mutex);
}
/***********************************************************************
* macdrv_surface_unlock
*/
static void macdrv_surface_unlock(struct window_surface *window_surface)
{
pthread_mutex_unlock(&window_surface->mutex);
}
/***********************************************************************
* macdrv_surface_get_bitmap_info
*/
@ -143,7 +127,7 @@ static void macdrv_surface_set_region(struct window_surface *window_surface, HRG
TRACE("updating surface %p with %p\n", surface, region);
window_surface->funcs->lock(window_surface);
window_surface_lock(window_surface);
if (region)
{
@ -157,7 +141,7 @@ static void macdrv_surface_set_region(struct window_surface *window_surface, HRG
}
update_blit_data(surface);
window_surface->funcs->unlock(window_surface);
window_surface_unlock(window_surface);
}
/***********************************************************************
@ -169,7 +153,7 @@ static void macdrv_surface_flush(struct window_surface *window_surface)
CGRect rect;
HRGN region;
window_surface->funcs->lock(window_surface);
window_surface_lock(window_surface);
TRACE("flushing %p %s bounds %s bits %p\n", surface, wine_dbgstr_rect(&surface->header.rect),
wine_dbgstr_rect(&surface->bounds), surface->bits);
@ -192,7 +176,7 @@ static void macdrv_surface_flush(struct window_surface *window_surface)
update_blit_data(surface);
reset_bounds(&surface->bounds);
window_surface->funcs->unlock(window_surface);
window_surface_unlock(window_surface);
if (!CGRectIsEmpty(rect))
macdrv_window_needs_display(surface->window, rect);
@ -215,8 +199,6 @@ static void macdrv_surface_destroy(struct window_surface *window_surface)
static const struct window_surface_funcs macdrv_surface_funcs =
{
macdrv_surface_lock,
macdrv_surface_unlock,
macdrv_surface_get_bitmap_info,
macdrv_surface_get_bounds,
macdrv_surface_set_region,
@ -427,7 +409,7 @@ void surface_clip_to_visible_rect(struct window_surface *window_surface, const R
struct macdrv_window_surface *surface = get_mac_surface(window_surface);
if (!surface) return;
window_surface->funcs->lock(window_surface);
window_surface_lock(window_surface);
if (surface->drawn)
{
@ -446,5 +428,5 @@ void surface_clip_to_visible_rect(struct window_surface *window_surface, const R
}
}
window_surface->funcs->unlock(window_surface);
window_surface_unlock(window_surface);
}

View file

@ -509,10 +509,10 @@ static void sync_window_opacity(struct macdrv_win_data *data, COLORREF key, BYTE
rect = data->whole_rect;
OffsetRect(&rect, -data->whole_rect.left, -data->whole_rect.top);
data->surface->funcs->lock(data->surface);
window_surface_lock(data->surface);
bounds = data->surface->funcs->get_bounds(data->surface);
add_bounds_rect(bounds, &rect);
data->surface->funcs->unlock(data->surface);
window_surface_unlock(data->surface);
}
}
@ -1964,9 +1964,9 @@ BOOL macdrv_UpdateLayeredWindow(HWND hwnd, const UPDATELAYEREDWINDOWINFO *info,
if (info->prcDirty)
{
intersect_rect(&rect, &rect, info->prcDirty);
surface->funcs->lock(surface);
window_surface_lock(surface);
memcpy(src_bits, dst_bits, bmi->bmiHeader.biSizeImage);
surface->funcs->unlock(surface);
window_surface_unlock(surface);
NtGdiPatBlt(hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, BLACKNESS);
}
src_rect = rect;
@ -1983,10 +1983,10 @@ BOOL macdrv_UpdateLayeredWindow(HWND hwnd, const UPDATELAYEREDWINDOWINFO *info,
{
if (surface == data->surface)
{
surface->funcs->lock(surface);
window_surface_lock(surface);
memcpy(dst_bits, src_bits, bmi->bmiHeader.biSizeImage);
add_bounds_rect(surface->funcs->get_bounds(surface), &rect);
surface->funcs->unlock(surface);
window_surface_unlock(surface);
surface->funcs->flush(surface);
}

View file

@ -218,22 +218,6 @@ static void wayland_buffer_queue_add_damage(struct wayland_buffer_queue *queue,
}
}
/***********************************************************************
* wayland_window_surface_lock
*/
static void wayland_window_surface_lock(struct window_surface *window_surface)
{
pthread_mutex_lock(&window_surface->mutex);
}
/***********************************************************************
* wayland_window_surface_unlock
*/
static void wayland_window_surface_unlock(struct window_surface *window_surface)
{
pthread_mutex_unlock(&window_surface->mutex);
}
/***********************************************************************
* wayland_window_surface_get_bitmap_info
*/
@ -376,7 +360,7 @@ static void wayland_window_surface_flush(struct window_surface *window_surface)
HRGN surface_damage_region = NULL;
HRGN copy_from_window_region;
wayland_window_surface_lock(window_surface);
window_surface_lock(window_surface);
if (!intersect_rect(&damage_rect, &wws->header.rect, &wws->bounds)) goto done;
@ -466,7 +450,7 @@ static void wayland_window_surface_flush(struct window_surface *window_surface)
done:
if (flushed) reset_bounds(&wws->bounds);
if (surface_damage_region) NtGdiDeleteObjectApp(surface_damage_region);
wayland_window_surface_unlock(window_surface);
window_surface_unlock(window_surface);
}
/***********************************************************************
@ -486,8 +470,6 @@ static void wayland_window_surface_destroy(struct window_surface *window_surface
static const struct window_surface_funcs wayland_window_surface_funcs =
{
wayland_window_surface_lock,
wayland_window_surface_unlock,
wayland_window_surface_get_bitmap_info,
wayland_window_surface_get_bounds,
wayland_window_surface_set_region,
@ -543,7 +525,7 @@ void wayland_window_surface_update_wayland_surface(struct window_surface *window
{
struct wayland_window_surface *wws = wayland_window_surface_cast(window_surface);
wayland_window_surface_lock(window_surface);
window_surface_lock(window_surface);
TRACE("surface=%p hwnd=%p wayland_surface=%p\n", wws, wws->hwnd, wayland_surface);
@ -562,5 +544,5 @@ void wayland_window_surface_update_wayland_surface(struct window_surface *window
wws->wayland_buffer_queue = NULL;
}
wayland_window_surface_unlock(window_surface);
window_surface_unlock(window_surface);
}

View file

@ -1827,22 +1827,6 @@ failed:
}
#endif /* HAVE_LIBXXSHM */
/***********************************************************************
* x11drv_surface_lock
*/
static void x11drv_surface_lock( struct window_surface *window_surface )
{
pthread_mutex_lock( &window_surface->mutex );
}
/***********************************************************************
* x11drv_surface_unlock
*/
static void x11drv_surface_unlock( struct window_surface *window_surface )
{
pthread_mutex_unlock( &window_surface->mutex );
}
/***********************************************************************
* x11drv_surface_get_bitmap_info
*/
@ -1874,7 +1858,7 @@ static void x11drv_surface_set_region( struct window_surface *window_surface, HR
TRACE( "updating surface %p with %p\n", surface, region );
window_surface->funcs->lock( window_surface );
window_surface_lock( window_surface );
if (!region)
{
if (surface->region) NtGdiDeleteObjectApp( surface->region );
@ -1892,7 +1876,7 @@ static void x11drv_surface_set_region( struct window_surface *window_surface, HR
free( data );
}
}
window_surface->funcs->unlock( window_surface );
window_surface_unlock( window_surface );
}
/***********************************************************************
@ -1905,7 +1889,7 @@ static void x11drv_surface_flush( struct window_surface *window_surface )
unsigned char *dst = (unsigned char *)surface->image->data;
struct bitblt_coords coords;
window_surface->funcs->lock( window_surface );
window_surface_lock( window_surface );
coords.x = 0;
coords.y = 0;
coords.width = surface->header.rect.right - surface->header.rect.left;
@ -1959,7 +1943,7 @@ static void x11drv_surface_flush( struct window_surface *window_surface )
XFlush( gdi_display );
}
reset_bounds( &surface->bounds );
window_surface->funcs->unlock( window_surface );
window_surface_unlock( window_surface );
}
/***********************************************************************
@ -1993,8 +1977,6 @@ static void x11drv_surface_destroy( struct window_surface *window_surface )
static const struct window_surface_funcs x11drv_surface_funcs =
{
x11drv_surface_lock,
x11drv_surface_unlock,
x11drv_surface_get_bitmap_info,
x11drv_surface_get_bounds,
x11drv_surface_set_region,
@ -2078,11 +2060,11 @@ void set_surface_color_key( struct window_surface *window_surface, COLORREF colo
if (window_surface->funcs != &x11drv_surface_funcs) return; /* we may get the null surface */
window_surface->funcs->lock( window_surface );
window_surface_lock( window_surface );
prev = surface->color_key;
set_color_key( surface, color_key );
if (surface->color_key != prev) update_surface_region( surface );
window_surface->funcs->unlock( window_surface );
window_surface_unlock( window_surface );
}
/***********************************************************************
@ -2096,7 +2078,7 @@ HRGN expose_surface( struct window_surface *window_surface, const RECT *rect )
if (window_surface->funcs != &x11drv_surface_funcs) return 0; /* we may get the null surface */
window_surface->funcs->lock( window_surface );
window_surface_lock( window_surface );
OffsetRect( &rc, -window_surface->rect.left, -window_surface->rect.top );
add_bounds_rect( &surface->bounds, &rc );
if (surface->region)
@ -2108,6 +2090,6 @@ HRGN expose_surface( struct window_surface *window_surface, const RECT *rect )
region = 0;
}
}
window_surface->funcs->unlock( window_surface );
window_surface_unlock( window_surface );
return region;
}

View file

@ -3026,7 +3026,7 @@ BOOL X11DRV_UpdateLayeredWindow( HWND hwnd, const UPDATELAYEREDWINDOWINFO *info,
NtGdiSelectBitmap( hdc, dib );
surface->funcs->lock( surface );
window_surface_lock( surface );
if (info->prcDirty)
{
@ -3049,7 +3049,7 @@ BOOL X11DRV_UpdateLayeredWindow( HWND hwnd, const UPDATELAYEREDWINDOWINFO *info,
add_bounds_rect( surface->funcs->get_bounds( surface ), &rect );
}
surface->funcs->unlock( surface );
window_surface_unlock( surface );
surface->funcs->flush( surface );
done:

View file

@ -211,8 +211,6 @@ struct window_surface;
struct window_surface_funcs
{
void (*lock)( struct window_surface *surface );
void (*unlock)( struct window_surface *surface );
void* (*get_info)( struct window_surface *surface, BITMAPINFO *info );
RECT* (*get_bounds)( struct window_surface *surface );
void (*set_region)( struct window_surface *surface, HRGN region );
@ -235,6 +233,8 @@ struct window_surface
W32KAPI void window_surface_init( struct window_surface *surface, const struct window_surface_funcs *funcs, const RECT *rect );
W32KAPI void window_surface_add_ref( struct window_surface *surface );
W32KAPI void window_surface_release( struct window_surface *surface );
W32KAPI void window_surface_lock( struct window_surface *surface );
W32KAPI void window_surface_unlock( struct window_surface *surface );
/* display manager interface, used to initialize display device registry data */