mirror of
https://github.com/X11Libre/xserver.git
synced 2026-03-24 12:25:07 +00:00
Right now, extension specific pixmap destruction procedures are implemented by wrapping the ScreenRec's DestroyPixmap() proc pointer: the extensions are storing the original pointer in their private data and putting in their own one. On each call, their proc restores the original one, calls it, and switches back again. When multiple extensions doing so, they're forming a kind of daisy chain. (the same is done for lots of other procs) While that approach is looking nice and elegant on the drawing board, it's complicated, dangerous like a chainsaw and makes debugging hard, leading to pretty blurred API borders. It's even getting worse: the proc also has to do ref counting, and only destroy the pixmap if refconter reaching zero - that's all done in the individual screen drivers. Therefore, all extensions must check for refcnt == 1, in order to know when to really act. This commit introduces a simple approach for letting extension hook into the pixmap destruction safely, w/o having to care much about side effects with the call chain. Extensions now can simply register their destructor proc (and an opaque pointer) and get called back - w/o ever having to mess with the ScreenRec's internal structures. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
106 lines
3.0 KiB
C
106 lines
3.0 KiB
C
/* SPDX-License-Identifier: MIT OR X11
|
|
*
|
|
* Copyright © 2024 Enrico Weigelt, metux IT consult <info@metux.net>
|
|
*/
|
|
|
|
#include <dix-config.h>
|
|
|
|
#include "dix/dix_priv.h"
|
|
#include "include/dix.h"
|
|
#include "include/os.h"
|
|
#include "include/scrnintstr.h"
|
|
#include "include/windowstr.h"
|
|
|
|
#define ARRAY_LENGTH(x) (sizeof(x) / sizeof((x)[0]))
|
|
|
|
#define ARRAY_FOR_EACH(_ARRAY, _WALK) \
|
|
for (struct { int idx; typeof(_ARRAY[0])*ptr; } _WALK = { 0, _ARRAY }; _WALK.idx < ARRAY_LENGTH(_ARRAY); _WALK.idx++, _WALK.ptr++)
|
|
|
|
#define DECLARE_HOOK_LIST(NAME, FIELD) \
|
|
void dixScreenHook##NAME(ScreenPtr pScreen, typeof(((ScreenRec){0}).FIELD[0].func) func, void *arg) \
|
|
{ \
|
|
for (int i=0; i<ARRAY_LENGTH(pScreen->FIELD); i++) { \
|
|
if (!(pScreen->FIELD[i].func)) { \
|
|
pScreen->FIELD[i].func = func; \
|
|
pScreen->FIELD[i].arg = arg; \
|
|
return; \
|
|
} \
|
|
} \
|
|
FatalError("%s: out of slots", __FUNCTION__); \
|
|
} \
|
|
\
|
|
void dixScreenUnhook##NAME(ScreenPtr pScreen, typeof(((ScreenRec){0}).FIELD[0].func) func, void *arg) \
|
|
{ \
|
|
for (int i=0; i<ARRAY_LENGTH(pScreen->FIELD); i++) { \
|
|
if ((pScreen->FIELD[i].func == func) && (pScreen->FIELD[i].arg == arg)) { \
|
|
pScreen->FIELD[i].func = NULL; \
|
|
pScreen->FIELD[i].arg = NULL; \
|
|
return; \
|
|
} \
|
|
} \
|
|
}
|
|
|
|
DECLARE_HOOK_LIST(WindowDestroy, _notify_window_destroy)
|
|
DECLARE_HOOK_LIST(WindowPosition, _notify_window_position)
|
|
DECLARE_HOOK_LIST(Close, _notify_screen_close)
|
|
DECLARE_HOOK_LIST(PixmapDestroy, _notify_pixmap_destroy)
|
|
|
|
int dixScreenRaiseWindowDestroy(WindowPtr pWin)
|
|
{
|
|
if (!pWin)
|
|
return Success;
|
|
|
|
ScreenPtr pScreen = pWin->drawable.pScreen;
|
|
|
|
ARRAY_FOR_EACH(pScreen->_notify_window_destroy, walk) {
|
|
if (walk.ptr->func)
|
|
walk.ptr->func(pScreen, pWin, walk.ptr->arg);
|
|
}
|
|
return (pScreen->DestroyWindow ? (*pScreen->DestroyWindow) (pWin) : Success);
|
|
}
|
|
|
|
void dixScreenRaiseWindowPosition(WindowPtr pWin, uint32_t x, uint32_t y)
|
|
{
|
|
if (!pWin)
|
|
return;
|
|
|
|
ScreenPtr pScreen = pWin->drawable.pScreen;
|
|
|
|
ARRAY_FOR_EACH(pScreen->_notify_window_position, walk) {
|
|
if (walk.ptr->func)
|
|
walk.ptr->func(pScreen, pWin, walk.ptr->arg, x, y);
|
|
}
|
|
|
|
if (pScreen->PositionWindow)
|
|
(*pScreen->PositionWindow) (pWin, x, y);
|
|
}
|
|
|
|
void dixScreenRaiseClose(ScreenPtr pScreen)
|
|
{
|
|
if (!pScreen)
|
|
return;
|
|
|
|
ARRAY_FOR_EACH(pScreen->_notify_screen_close, walk) {
|
|
if (walk.ptr->func)
|
|
walk.ptr->func(pScreen, walk.ptr->arg);
|
|
}
|
|
|
|
if (pScreen->CloseScreen)
|
|
(*pScreen->CloseScreen) (pScreen);
|
|
}
|
|
|
|
void dixScreenRaisePixmapDestroy(PixmapPtr pPixmap)
|
|
{
|
|
if (!pPixmap)
|
|
return;
|
|
|
|
ScreenPtr pScreen = pPixmap->drawable.pScreen;
|
|
|
|
ARRAY_FOR_EACH(pScreen->_notify_pixmap_destroy, walk) {
|
|
if (walk.ptr->func)
|
|
walk.ptr->func(pScreen, pPixmap, walk.ptr->arg);
|
|
}
|
|
|
|
/* we must not call the original ScreenRec->DestroyPixmap() here */
|
|
}
|