From: Rémi Bernon rbernon@codeweavers.com
--- dlls/win32u/opengl.c | 17 +++++++++++++++++ dlls/wineandroid.drv/opengl.c | 9 +-------- dlls/winemac.drv/opengl.c | 10 ++-------- dlls/winewayland.drv/opengl.c | 10 +--------- dlls/winex11.drv/opengl.c | 17 ++--------------- include/wine/opengl_driver.h | 1 + 6 files changed, 24 insertions(+), 40 deletions(-)
diff --git a/dlls/win32u/opengl.c b/dlls/win32u/opengl.c index 8d20ff05fce..c165f9588c7 100644 --- a/dlls/win32u/opengl.c +++ b/dlls/win32u/opengl.c @@ -163,6 +163,22 @@ static void register_extension( char *list, size_t size, const char *name ) } }
+void *opengl_drawable_create( UINT size, const struct opengl_drawable_funcs *funcs, int format, HWND hwnd, HDC hdc ) +{ + struct opengl_drawable *drawable; + + if (!(drawable = calloc( 1, size ))) return NULL; + drawable->funcs = funcs; + drawable->ref = 1; + + drawable->format = format; + drawable->hwnd = hwnd; + drawable->hdc = hdc; + + TRACE( "created %s\n", debugstr_opengl_drawable( drawable ) ); + return drawable; +} + void opengl_drawable_add_ref( struct opengl_drawable *drawable ) { ULONG ref = InterlockedIncrement( &drawable->ref ); @@ -177,6 +193,7 @@ void opengl_drawable_release( struct opengl_drawable *drawable ) if (!ref) { drawable->funcs->destroy( drawable ); + free( drawable ); } }
diff --git a/dlls/wineandroid.drv/opengl.c b/dlls/wineandroid.drv/opengl.c index f0b3f76e64e..593b5e448aa 100644 --- a/dlls/wineandroid.drv/opengl.c +++ b/dlls/wineandroid.drv/opengl.c @@ -105,13 +105,7 @@ 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;
- if (!(gl = calloc( 1, sizeof(*gl) ))) return NULL; - gl->base.funcs = &android_drawable_funcs; - gl->base.ref = 1; - gl->base.hwnd = hwnd; - gl->base.hdc = hdc; - gl->base.format = format; - + if (!(gl = opengl_drawable_create( sizeof(*gl), &android_drawable_funcs, format, hwnd, hdc ))) return NULL; gl->window = create_ioctl_window( hwnd, TRUE, 1.0f ); gl->surface = 0; gl->pbuffer = funcs->p_eglCreatePbufferSurface( egl->display, egl_config_for_format(gl->base.format), attribs ); @@ -143,7 +137,6 @@ static void android_drawable_destroy( struct opengl_drawable *base ) if (gl->surface) funcs->p_eglDestroySurface( egl->display, gl->surface ); if (gl->pbuffer) funcs->p_eglDestroySurface( egl->display, gl->pbuffer ); release_ioctl_window( gl->window ); - free( gl ); }
static void release_gl_drawable( struct gl_drawable *gl ) diff --git a/dlls/winemac.drv/opengl.c b/dlls/winemac.drv/opengl.c index 1facd278726..bddd6f531f4 100644 --- a/dlls/winemac.drv/opengl.c +++ b/dlls/winemac.drv/opengl.c @@ -2383,18 +2383,13 @@ static BOOL macdrv_pbuffer_create(HDC hdc, int format, BOOL largest, GLenum text texture_format = GL_RGB; }
- if (!(gl = calloc(1, sizeof(*gl)))) return FALSE; - gl->base.funcs = &macdrv_pbuffer_funcs; - gl->base.ref = 1; - gl->base.hwnd = 0; - gl->base.hdc = hdc; - gl->base.format = format; + if (!(gl = opengl_drawable_create(sizeof(*gl), &macdrv_pbuffer_funcs, format, 0, hdc))) return FALSE;
err = CGLCreatePBuffer(*width, *height, texture_target, texture_format, max_level, &gl->pbuffer); if (err != kCGLNoError) { WARN("CGLCreatePBuffer failed; err %d %s\n", err, CGLErrorString(err)); - free(gl); + opengl_drawable_release(&gl->base); return FALSE; }
@@ -2418,7 +2413,6 @@ static void macdrv_pbuffer_destroy(struct opengl_drawable *base) pthread_mutex_unlock(&dc_pbuffers_mutex);
CGLReleasePBuffer(gl->pbuffer); - free(gl); }
diff --git a/dlls/winewayland.drv/opengl.c b/dlls/winewayland.drv/opengl.c index 0dc3f16b9f9..a9f0e2d259e 100644 --- a/dlls/winewayland.drv/opengl.c +++ b/dlls/winewayland.drv/opengl.c @@ -143,8 +143,6 @@ static void wayland_drawable_destroy(struct opengl_drawable *base)
if (data) wayland_win_data_release(data); } - - free(gl); }
static inline BOOL is_onscreen_format(int format) @@ -175,13 +173,7 @@ static struct wayland_gl_drawable *wayland_gl_drawable_create(HWND hwnd, HDC hdc } *attrib++ = EGL_NONE;
- if (!(gl = calloc(1, sizeof(*gl)))) return NULL; - gl->base.funcs = &wayland_drawable_funcs; - gl->base.ref = 1; - gl->base.hwnd = hwnd; - gl->base.hdc = hdc; - gl->base.format = format; - + if (!(gl = opengl_drawable_create(sizeof(*gl), &wayland_drawable_funcs, format, hwnd, hdc))) return NULL; gl->swap_interval = 1;
/* Get the client surface for the HWND. If don't have a wayland surface diff --git a/dlls/winex11.drv/opengl.c b/dlls/winex11.drv/opengl.c index eae594d630d..ad82c8d8f7a 100644 --- a/dlls/winex11.drv/opengl.c +++ b/dlls/winex11.drv/opengl.c @@ -839,7 +839,6 @@ static void x11drv_surface_destroy( struct opengl_drawable *base ) XFreeColormap( gdi_display, gl->colormap ); if (gl->hdc_src) NtGdiDeleteObjectApp( gl->hdc_src ); if (gl->hdc_dst) NtGdiDeleteObjectApp( gl->hdc_dst ); - free( gl ); }
static BOOL set_swap_interval( struct gl_drawable *gl, int interval ) @@ -920,13 +919,7 @@ static struct gl_drawable *create_gl_drawable( HWND hwnd, int format )
NtUserGetClientRect( hwnd, &rect, NtUserGetDpiForWindow( hwnd ) );
- if (!(gl = calloc( 1, sizeof(*gl) ))) return NULL; - gl->base.funcs = &x11drv_surface_funcs; - gl->base.ref = 1; - gl->base.hwnd = hwnd; - gl->base.hdc = 0; - gl->base.format = format; - + if (!(gl = opengl_drawable_create( sizeof(*gl), &x11drv_surface_funcs, format, hwnd, 0 ))) return NULL; /* Default GLX and WGL swap interval is 1, but in case of glXSwapIntervalSGI there is no way to query it. */ gl->swap_interval = INT_MIN; gl->rect = rect; @@ -1515,12 +1508,7 @@ static BOOL x11drv_pbuffer_create( HDC hdc, int format, BOOL largest, GLenum tex } glx_attribs[count++] = 0;
- if (!(gl = calloc( 1, sizeof(*gl) ))) return FALSE; - gl->base.funcs = &x11drv_pbuffer_funcs; - gl->base.ref = 1; - gl->base.hwnd = 0; - gl->base.hdc = hdc; - gl->base.format = format; + if (!(gl = opengl_drawable_create( sizeof(*gl), &x11drv_pbuffer_funcs, format, 0, hdc ))) return FALSE;
gl->drawable = pglXCreatePbuffer( gdi_display, fmt->fbconfig, glx_attribs ); TRACE( "new Pbuffer drawable as %p (%lx)\n", gl, gl->drawable ); @@ -1554,7 +1542,6 @@ static void x11drv_pbuffer_destroy( struct opengl_drawable *base ) pthread_mutex_unlock( &context_mutex );
pglXDestroyPbuffer( gdi_display, gl->drawable ); - free( gl ); }
static BOOL x11drv_pbuffer_updated( HDC hdc, struct opengl_drawable *base, GLenum cube_face, GLint mipmap_level ) diff --git a/include/wine/opengl_driver.h b/include/wine/opengl_driver.h index b4f3d13eca3..15f9b26e5cf 100644 --- a/include/wine/opengl_driver.h +++ b/include/wine/opengl_driver.h @@ -149,6 +149,7 @@ static inline const char *debugstr_opengl_drawable( struct opengl_drawable *draw return wine_dbg_sprintf( "%p (format %u, hwnd %p, hdc %p)", drawable, drawable->format, drawable->hwnd, drawable->hdc ); }
+W32KAPI void *opengl_drawable_create( UINT size, const struct opengl_drawable_funcs *funcs, int format, HWND hwnd, HDC hdc ); W32KAPI void opengl_drawable_add_ref( struct opengl_drawable *drawable ); W32KAPI void opengl_drawable_release( struct opengl_drawable *drawable );