xrt: Introduce xrt_comp_fd_destroy to avoid some error prone casting

This commit is contained in:
Jakob Bornecrantz 2020-06-04 17:36:00 +01:00 committed by Jakob Bornecrantz
parent b60219445a
commit 077087bb15
4 changed files with 24 additions and 3 deletions

View file

@ -31,7 +31,7 @@ client_egl_compositor_destroy(struct xrt_compositor *xc)
{
struct client_gl_compositor *c = client_gl_compositor(xc);
// Pipe down call into fd compositor.
xrt_comp_destroy((struct xrt_compositor **)c->xcfd);
xrt_comp_fd_destroy(&c->xcfd);
free(c);
}

View file

@ -33,7 +33,7 @@ client_gl_xlib_compositor_destroy(struct xrt_compositor *xc)
{
struct client_gl_xlib_compositor *c = client_gl_xlib_compositor(xc);
// Pipe down call into fd compositor.
xrt_comp_destroy((struct xrt_compositor **)c->base.xcfd);
xrt_comp_fd_destroy(&c->base.xcfd);
free(c);
}

View file

@ -116,7 +116,7 @@ client_vk_compositor_destroy(struct xrt_compositor *xc)
}
// Pipe down call into fd compositor.
xrt_comp_destroy((struct xrt_compositor **)&c->xcfd);
xrt_comp_fd_destroy(&c->xcfd);
free(c);
}

View file

@ -777,6 +777,27 @@ xrt_comp_fd_create_swapchain(struct xrt_compositor_fd *xcfd,
return (struct xrt_swapchain_fd *)xsc;
}
/*!
* @copydoc xrt_compositor::destroy
*
* Helper for calling through the function pointer: does a null check and sets
* xcfd_ptr to null if freed.
*
* @public @memberof xrt_compositor_fd
*/
static inline void
xrt_comp_fd_destroy(struct xrt_compositor_fd **xcfd_ptr)
{
struct xrt_compositor_fd *xcfd = *xcfd_ptr;
if (xcfd == NULL) {
return;
}
xcfd->base.destroy(&xcfd->base);
*xcfd_ptr = NULL;
}
#ifdef __cplusplus
}
#endif