glamor: use CloseScreen hook

Wrapping ScreenRec's function pointers is problematic for many reasons,
so use the new screen close notify hook instead.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2025-04-25 19:41:48 +02:00
parent feee189a02
commit f315b2b07d
4 changed files with 25 additions and 21 deletions

View File

@ -30,10 +30,13 @@
* This file covers the initialization and teardown of glamor, and has various
* functions not responsible for performing rendering.
*/
#include <dix-config.h>
#include <stdlib.h>
#include <unistd.h>
#include "dix/screen_hooks_priv.h"
#include "glamor_priv.h"
#include "mipict.h"
@ -604,6 +607,17 @@ glamor_setup_formats(ScreenPtr screen)
glamor_priv->cbcr_format.texture_only = FALSE;
}
/* This function is used to free the glamor private screen's
* resources. If the DDX driver is not set GLAMOR_USE_SCREEN,
* then, DDX need to call this function at proper stage, if
* it is the xorg DDX driver,then it should be called at free
* screen stage not the close screen stage. The reason is after
* call to this function, the xorg DDX may need to destroy the
* screen pixmap which must be a glamor pixmap and requires
* the internal data structure still exist at that time.
* Otherwise, the glamor internal structure will not be freed.*/
static void glamor_close_screen(CallbackListPtr *pcbl, ScreenPtr screen, void *unused);
/** Set up glamor for an already-configured GL context. */
Bool
glamor_init(ScreenPtr screen, unsigned int flags)
@ -649,9 +663,6 @@ glamor_init(ScreenPtr screen, unsigned int flags)
goto free_glamor_private;
}
glamor_priv->saved_procs.close_screen = screen->CloseScreen;
screen->CloseScreen = glamor_close_screen;
glamor_priv->saved_procs.destroy_pixmap = screen->DestroyPixmap;
screen->DestroyPixmap = glamor_destroy_pixmap;
@ -874,11 +885,12 @@ glamor_init(ScreenPtr screen, unsigned int flags)
glamor_priv->screen = screen;
dixScreenHookClose(screen, glamor_close_screen);
return TRUE;
fail:
/* Restore default CloseScreen and DestroyPixmap handlers */
screen->CloseScreen = glamor_priv->saved_procs.close_screen;
/* Restore default DestroyPixmap handler */
screen->DestroyPixmap = glamor_priv->saved_procs.destroy_pixmap;
free_glamor_private:
@ -900,8 +912,7 @@ glamor_release_screen_priv(ScreenPtr screen)
glamor_set_screen_private(screen, NULL);
}
Bool
glamor_close_screen(ScreenPtr screen)
static void glamor_close_screen(CallbackListPtr *pcbl, ScreenPtr screen, void *unused)
{
glamor_screen_private *glamor_priv;
PixmapPtr screen_pixmap;
@ -911,7 +922,8 @@ glamor_close_screen(ScreenPtr screen)
glamor_sync_close(screen);
glamor_composite_glyphs_fini(screen);
glamor_set_glvnd_vendor(screen, NULL);
screen->CloseScreen = glamor_priv->saved_procs.close_screen;
dixScreenUnhookClose(screen, glamor_close_screen);
screen->CreateGC = glamor_priv->saved_procs.create_gc;
screen->CreatePixmap = glamor_priv->saved_procs.create_pixmap;
@ -933,8 +945,6 @@ glamor_close_screen(ScreenPtr screen)
glamor_pixmap_destroy_fbo(screen_pixmap);
glamor_release_screen_priv(screen);
return screen->CloseScreen(screen);
}
void

View File

@ -106,7 +106,6 @@ extern _X_EXPORT void glamor_fini(ScreenPtr screen);
* screen pixmap which must be a glamor pixmap and requires
* the internal data structure still exist at that time.
* Otherwise, the glamor internal structure will not be freed.*/
extern _X_EXPORT Bool glamor_close_screen(ScreenPtr screen);
extern _X_EXPORT uint32_t glamor_get_pixmap_texture(PixmapPtr pixmap);

View File

@ -42,6 +42,8 @@
#include <gbm.h>
#include <drm_fourcc.h>
#include "dix/screen_hooks_priv.h"
#include "glamor_egl.h"
#include "glamor.h"
@ -54,13 +56,11 @@ struct glamor_egl_screen_private {
EGLContext context;
char *device_path;
CloseScreenProcPtr CloseScreen;
int fd;
struct gbm_device *gbm;
int dmabuf_capable;
Bool force_vendor; /* if GLVND vendor is forced from options */
CloseScreenProcPtr saved_close_screen;
DestroyPixmapProcPtr saved_destroy_pixmap;
xf86FreeScreenProc *saved_free_screen;
};
@ -805,8 +805,7 @@ glamor_egl_exchange_buffers(PixmapPtr front, PixmapPtr back)
glamor_set_pixmap_type(back, GLAMOR_TEXTURE_DRM);
}
static Bool
glamor_egl_close_screen(ScreenPtr screen)
static void glamor_egl_close_screen(CallbackListPtr *pcbl, ScreenPtr screen, void *unused)
{
ScrnInfoPtr scrn;
struct glamor_egl_screen_private *glamor_egl;
@ -821,9 +820,7 @@ glamor_egl_close_screen(ScreenPtr screen)
eglDestroyImageKHR(glamor_egl->display, pixmap_priv->image);
pixmap_priv->image = NULL;
screen->CloseScreen = glamor_egl->saved_close_screen;
return screen->CloseScreen(screen);
dixScreenUnhookClose(screen, glamor_egl_close_screen);
}
#ifdef DRI3
@ -903,8 +900,7 @@ glamor_egl_screen_init(ScreenPtr screen, struct glamor_context *glamor_ctx)
#endif
const char *gbm_backend_name;
glamor_egl->saved_close_screen = screen->CloseScreen;
screen->CloseScreen = glamor_egl_close_screen;
dixScreenHookClose(screen, glamor_egl_close_screen);
glamor_egl->saved_destroy_pixmap = screen->DestroyPixmap;
screen->DestroyPixmap = glamor_egl_destroy_pixmap;

View File

@ -206,7 +206,6 @@ struct glamor_format {
};
struct glamor_saved_procs {
CloseScreenProcPtr close_screen;
CreateGCProcPtr create_gc;
CreatePixmapProcPtr create_pixmap;
DestroyPixmapProcPtr destroy_pixmap;