From: Rémi Bernon rbernon@codeweavers.com
--- dlls/win32u/dce.c | 32 ++++++++++++------------ dlls/wineandroid.drv/window.c | 19 ++++++--------- dlls/winemac.drv/surface.c | 35 ++++++++++++--------------- dlls/winewayland.drv/window_surface.c | 13 +--------- dlls/winex11.drv/bitblt.c | 30 +++++++++-------------- include/wine/gdi_driver.h | 4 +-- 6 files changed, 55 insertions(+), 78 deletions(-)
diff --git a/dlls/win32u/dce.c b/dlls/win32u/dce.c index 5faea17a6a2..6749e2b1725 100644 --- a/dlls/win32u/dce.c +++ b/dlls/win32u/dce.c @@ -106,7 +106,6 @@ static BOOL offscreen_window_surface_flush( struct window_surface *surface, cons
static void offscreen_window_surface_destroy( struct window_surface *surface ) { - free( surface ); }
static const struct window_surface_funcs offscreen_window_surface_funcs = @@ -119,8 +118,8 @@ static const struct window_surface_funcs offscreen_window_surface_funcs = void create_offscreen_window_surface( HWND hwnd, const RECT *surface_rect, struct window_surface **window_surface ) { char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )]; - BITMAPINFO *info = (BITMAPINFO *)buffer; struct window_surface *surface, *previous; + BITMAPINFO *info = (BITMAPINFO *)buffer;
TRACE( "hwnd %p, surface_rect %s, window_surface %p.\n", hwnd, wine_dbgstr_rect( surface_rect ), window_surface );
@@ -136,14 +135,7 @@ void create_offscreen_window_surface( HWND hwnd, const RECT *surface_rect, struc info->bmiHeader.biSizeImage = get_dib_image_size( info ); info->bmiHeader.biCompression = BI_RGB;
- /* create a new window surface */ - if (!(surface = calloc(1, sizeof(*surface)))) return; - window_surface_init( surface, &offscreen_window_surface_funcs, hwnd, surface_rect, info, 0 ); - - TRACE( "created window surface %p\n", surface ); - *window_surface = surface; - - if (previous) window_surface_release( previous ); + *window_surface = window_surface_create( sizeof(*surface), &offscreen_window_surface_funcs, hwnd, surface_rect, info, 0 ); }
/* window surface common helpers */ @@ -344,9 +336,12 @@ static BOOL update_surface_shape( struct window_surface *surface, const RECT *re return clear_surface_shape( surface ); }
-W32KAPI BOOL window_surface_init( struct window_surface *surface, const struct window_surface_funcs *funcs, - HWND hwnd, const RECT *rect, BITMAPINFO *info, HBITMAP bitmap ) +W32KAPI struct window_surface *window_surface_create( UINT size, const struct window_surface_funcs *funcs, HWND hwnd, + const RECT *rect, BITMAPINFO *info, HBITMAP bitmap ) { + struct window_surface *surface; + + if (!(surface = calloc( 1, size ))) return NULL; surface->funcs = funcs; surface->ref = 1; surface->hwnd = hwnd; @@ -354,13 +349,19 @@ W32KAPI BOOL window_surface_init( struct window_surface *surface, const struct w surface->color_key = CLR_INVALID; surface->alpha_bits = -1; surface->alpha_mask = 0; - pthread_mutex_init( &surface->mutex, NULL ); reset_bounds( &surface->bounds );
if (!bitmap) bitmap = NtGdiCreateDIBSection( 0, NULL, 0, info, DIB_RGB_COLORS, 0, 0, 0, NULL ); - if (!(surface->color_bitmap = bitmap)) return FALSE; + if (!(surface->color_bitmap = bitmap)) + { + free( surface ); + return NULL; + }
- return TRUE; + pthread_mutex_init( &surface->mutex, NULL ); + + TRACE( "created surface %p for hwnd %p rect %s\n", surface, hwnd, wine_dbgstr_rect( &surface->rect ) ); + return surface; }
W32KAPI void window_surface_add_ref( struct window_surface *surface ) @@ -378,6 +379,7 @@ W32KAPI void window_surface_release( struct window_surface *surface ) if (surface->color_bitmap) NtGdiDeleteObjectApp( surface->color_bitmap ); if (surface->shape_bitmap) NtGdiDeleteObjectApp( surface->shape_bitmap ); surface->funcs->destroy( surface ); + if (surface != &dummy_surface) free( surface ); } }
diff --git a/dlls/wineandroid.drv/window.c b/dlls/wineandroid.drv/window.c index bb7a8985f3c..bb169054370 100644 --- a/dlls/wineandroid.drv/window.c +++ b/dlls/wineandroid.drv/window.c @@ -679,7 +679,6 @@ static void android_surface_destroy( struct window_surface *window_surface )
free( surface->clip_rects ); release_ioctl_window( surface->window ); - free( surface ); }
static const struct window_surface_funcs android_surface_funcs = @@ -699,6 +698,7 @@ static struct window_surface *create_surface( HWND hwnd, const RECT *rect ) int width = rect->right - rect->left, height = rect->bottom - rect->top; char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )]; BITMAPINFO *info = (BITMAPINFO *)buffer; + struct window_surface *window_surface;
memset( info, 0, sizeof(*info) ); info->bmiHeader.biSize = sizeof(info->bmiHeader); @@ -709,18 +709,13 @@ static struct window_surface *create_surface( HWND hwnd, const RECT *rect ) info->bmiHeader.biSizeImage = get_dib_image_size(info); info->bmiHeader.biCompression = BI_RGB;
- if (!(surface = calloc( 1, sizeof(*surface) ))) return NULL; - if (!window_surface_init( &surface->header, &android_surface_funcs, hwnd, rect, info, 0 )) goto failed; - - surface->window = get_ioctl_window( hwnd ); - - TRACE( "created %p hwnd %p %s\n", surface, hwnd, wine_dbgstr_rect(rect) ); - - return &surface->header; + if ((window_surface = window_surface_create( sizeof(*surface), &android_surface_funcs, hwnd, rect, info, 0 ))) + { + surface = get_android_surface( window_surface ); + surface->window = get_ioctl_window( hwnd ); + }
-failed: - window_surface_release( &surface->header ); - return NULL; + return window_surface; }
/*********************************************************************** diff --git a/dlls/winemac.drv/surface.c b/dlls/winemac.drv/surface.c index 5e7f94f47ed..a849918dfa7 100644 --- a/dlls/winemac.drv/surface.c +++ b/dlls/winemac.drv/surface.c @@ -132,7 +132,6 @@ static void macdrv_surface_destroy(struct window_surface *window_surface)
TRACE("freeing %p\n", surface); CGDataProviderRelease(surface->provider); - free(surface); }
static const struct window_surface_funcs macdrv_surface_funcs = @@ -153,12 +152,13 @@ static struct macdrv_window_surface *get_mac_surface(struct window_surface *surf */ static struct window_surface *create_surface(HWND hwnd, macdrv_window window, const RECT *rect) { - struct macdrv_window_surface *surface = NULL; + struct macdrv_window_surface *surface; int width = rect->right - rect->left, height = rect->bottom - rect->top; DWORD window_background; D3DKMT_CREATEDCFROMMEMORY desc = {.Format = D3DDDIFMT_A8R8G8B8}; char buffer[FIELD_OFFSET(BITMAPINFO, bmiColors[256])]; BITMAPINFO *info = (BITMAPINFO *)buffer; + struct window_surface *window_surface; CGDataProviderRef provider; HBITMAP bitmap = 0; UINT status; @@ -174,6 +174,8 @@ static struct window_surface *create_surface(HWND hwnd, macdrv_window window, co info->bmiHeader.biCompression = BI_RGB;
if (!(provider = data_provider_create(info->bmiHeader.biSizeImage, &bits))) return NULL; + window_background = macdrv_window_background_color(); + memset_pattern4(bits, &window_background, info->bmiHeader.biSizeImage);
/* wrap the data in a HBITMAP so we can write to the surface pixels directly */ desc.Width = info->bmiHeader.biWidth; @@ -190,24 +192,19 @@ static struct window_surface *create_surface(HWND hwnd, macdrv_window window, co } if (desc.hDeviceDc) NtUserReleaseDC(hwnd, desc.hDeviceDc);
- if (!(surface = calloc(1, sizeof(*surface)))) return NULL; - if (!window_surface_init(&surface->header, &macdrv_surface_funcs, hwnd, rect, info, bitmap)) goto failed; - - surface->window = window; - surface->provider = provider; - - window_background = macdrv_window_background_color(); - memset_pattern4(bits, &window_background, info->bmiHeader.biSizeImage); - - TRACE("created %p for %p %s\n", surface, window, wine_dbgstr_rect(rect)); - - return &surface->header; + if (!(window_surface = window_surface_create(sizeof(*surface), &macdrv_surface_funcs, hwnd, rect, info, bitmap))) + { + if (bitmap) NtGdiDeleteObjectApp(bitmap); + CGDataProviderRelease(provider); + } + else + { + surface = get_mac_surface(window_surface); + surface->window = window; + surface->provider = provider; + }
-failed: - if (surface) window_surface_release(&surface->header); - if (bitmap) NtGdiDeleteObjectApp(bitmap); - CGDataProviderRelease(provider); - return NULL; + return window_surface; }
diff --git a/dlls/winewayland.drv/window_surface.c b/dlls/winewayland.drv/window_surface.c index e0c00dfb28f..570c186861b 100644 --- a/dlls/winewayland.drv/window_surface.c +++ b/dlls/winewayland.drv/window_surface.c @@ -425,7 +425,6 @@ static void wayland_window_surface_destroy(struct window_surface *window_surface
if (wws->wayland_buffer_queue) wayland_buffer_queue_destroy(wws->wayland_buffer_queue); - free(wws); }
static const struct window_surface_funcs wayland_window_surface_funcs = @@ -457,17 +456,7 @@ static struct window_surface *wayland_window_surface_create(HWND hwnd, const REC info->bmiHeader.biSizeImage = width * height * 4; info->bmiHeader.biCompression = BI_RGB;
- wws = calloc(1, sizeof(*wws)); - if (!wws) return NULL; - if (!window_surface_init(&wws->header, &wayland_window_surface_funcs, hwnd, rect, info, 0)) goto failed; - - TRACE("created %p hwnd %p %s\n", wws, hwnd, wine_dbgstr_rect(rect)); - - return &wws->header; - -failed: - window_surface_release(&wws->header); - return NULL; + return window_surface_create(sizeof(*wws), &wayland_window_surface_funcs, hwnd, rect, info, 0); }
/*********************************************************************** diff --git a/dlls/winex11.drv/bitblt.c b/dlls/winex11.drv/bitblt.c index c0ffa1531a0..757386595f0 100644 --- a/dlls/winex11.drv/bitblt.c +++ b/dlls/winex11.drv/bitblt.c @@ -1868,7 +1868,6 @@ static void x11drv_surface_destroy( struct window_surface *window_surface ) TRACE( "freeing %p\n", surface ); if (surface->gc) XFreeGC( gdi_display, surface->gc ); if (surface->image) x11drv_image_destroy( surface->image ); - free( surface ); }
static const struct window_surface_funcs x11drv_surface_funcs = @@ -1889,6 +1888,7 @@ static struct window_surface *create_surface( HWND hwnd, Window window, const XV BITMAPINFO *info = (BITMAPINFO *)buffer; struct x11drv_window_surface *surface; int width = rect->right - rect->left, height = rect->bottom - rect->top; + struct window_surface *window_surface; struct x11drv_image *image; D3DDDIFORMAT d3d_format; HBITMAP bitmap = 0; @@ -1932,28 +1932,22 @@ static struct window_surface *create_surface( HWND hwnd, Window window, const XV if (desc.hDeviceDc) NtUserReleaseDC( hwnd, desc.hDeviceDc ); }
- if (!(surface = calloc( 1, sizeof(*surface) ))) + if (!(window_surface = window_surface_create( sizeof(*surface), &x11drv_surface_funcs, hwnd, rect, info, bitmap ))) { if (bitmap) NtGdiDeleteObjectApp( bitmap ); x11drv_image_destroy( image ); - return NULL; } - surface->image = image; - surface->byteswap = byteswap; - - if (!window_surface_init( &surface->header, &x11drv_surface_funcs, hwnd, rect, info, bitmap )) goto failed; - - surface->window = window; - surface->gc = XCreateGC( gdi_display, window, 0, NULL ); - XSetSubwindowMode( gdi_display, surface->gc, IncludeInferiors ); - - TRACE( "created %p for %lx %s image %p\n", surface, window, wine_dbgstr_rect(rect), surface->image->ximage->data ); - - return &surface->header; + else + { + surface = get_x11_surface( window_surface ); + surface->image = image; + surface->byteswap = byteswap; + surface->window = window; + surface->gc = XCreateGC( gdi_display, window, 0, NULL ); + XSetSubwindowMode( gdi_display, surface->gc, IncludeInferiors ); + }
-failed: - window_surface_release( &surface->header ); - return NULL; + return window_surface; }
diff --git a/include/wine/gdi_driver.h b/include/wine/gdi_driver.h index 69bd096a1a5..feda5594234 100644 --- a/include/wine/gdi_driver.h +++ b/include/wine/gdi_driver.h @@ -253,8 +253,8 @@ struct window_surface /* driver-specific fields here */ };
-W32KAPI BOOL window_surface_init( struct window_surface *surface, const struct window_surface_funcs *funcs, - HWND hwnd, const RECT *rect, BITMAPINFO *info, HBITMAP bitmap ); +W32KAPI struct window_surface *window_surface_create( UINT size, const struct window_surface_funcs *funcs, HWND hwnd, + const RECT *rect, BITMAPINFO *info, HBITMAP bitmap ); 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 );