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 e16a50281b
commit a6a17034f3
4 changed files with 22 additions and 21 deletions

View File

@ -36,6 +36,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include "dix/screen_hooks_priv.h"
#include "os/bug_priv.h" #include "os/bug_priv.h"
#include "glamor_priv.h" #include "glamor_priv.h"
@ -615,6 +616,17 @@ glamor_setup_formats(ScreenPtr screen)
glamor_priv->cbcr_format.texture_only = FALSE; 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. */ /** Set up glamor for an already-configured GL context. */
Bool Bool
glamor_init(ScreenPtr screen, unsigned int flags) glamor_init(ScreenPtr screen, unsigned int flags)
@ -660,9 +672,6 @@ glamor_init(ScreenPtr screen, unsigned int flags)
goto free_glamor_private; 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; glamor_priv->saved_procs.destroy_pixmap = screen->DestroyPixmap;
screen->DestroyPixmap = glamor_destroy_pixmap; screen->DestroyPixmap = glamor_destroy_pixmap;
@ -885,11 +894,12 @@ glamor_init(ScreenPtr screen, unsigned int flags)
glamor_priv->screen = screen; glamor_priv->screen = screen;
dixScreenHookClose(screen, glamor_close_screen);
return TRUE; return TRUE;
fail: fail:
/* Restore default CloseScreen and DestroyPixmap handlers */ /* Restore default DestroyPixmap handler */
screen->CloseScreen = glamor_priv->saved_procs.close_screen;
screen->DestroyPixmap = glamor_priv->saved_procs.destroy_pixmap; screen->DestroyPixmap = glamor_priv->saved_procs.destroy_pixmap;
free_glamor_private: free_glamor_private:
@ -911,8 +921,7 @@ glamor_release_screen_priv(ScreenPtr screen)
glamor_set_screen_private(screen, NULL); glamor_set_screen_private(screen, NULL);
} }
Bool static void glamor_close_screen(CallbackListPtr *pcbl, ScreenPtr screen, void *unused)
glamor_close_screen(ScreenPtr screen)
{ {
glamor_screen_private *glamor_priv; glamor_screen_private *glamor_priv;
PixmapPtr screen_pixmap; PixmapPtr screen_pixmap;
@ -921,7 +930,8 @@ glamor_close_screen(ScreenPtr screen)
glamor_sync_close(screen); glamor_sync_close(screen);
glamor_composite_glyphs_fini(screen); glamor_composite_glyphs_fini(screen);
glamor_set_glvnd_vendor(screen, NULL); 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->CreateGC = glamor_priv->saved_procs.create_gc;
screen->CreatePixmap = glamor_priv->saved_procs.create_pixmap; screen->CreatePixmap = glamor_priv->saved_procs.create_pixmap;
@ -946,8 +956,6 @@ glamor_close_screen(ScreenPtr screen)
glamor_pixmap_destroy_fbo(screen_pixmap); glamor_pixmap_destroy_fbo(screen_pixmap);
glamor_release_screen_priv(screen); glamor_release_screen_priv(screen);
return screen->CloseScreen(screen);
} }
void 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 * screen pixmap which must be a glamor pixmap and requires
* the internal data structure still exist at that time. * the internal data structure still exist at that time.
* Otherwise, the glamor internal structure will not be freed.*/ * 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); extern _X_EXPORT uint32_t glamor_get_pixmap_texture(PixmapPtr pixmap);

View File

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

View File

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