dix: add CreateScreenResources callback mechanism
Right now, extensions that need to be called after the CreateScreenResources proc had been run, must wrap the screen proc vector directly (all of them forming kind of daisy chain), and so - when called - temporarily restore the previous one, call it, wrap again, and if the call was successful finally doing it's own stuff. (same is done for many 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. Instead introducing a simple approach for letting extension hook into a post-CreateScreenResources callback list safely, w/o having to care much about side effects with the call chain. Extensions now can simply register their business logic and get called back - w/o ever having to mess with the ScreenRec's internal structures. Note that these hooks are executed *AFTER* the original CreateScreenResources() proc had been called SUCCESSFULLY (returned TRUE), so callees can rely on the DDX/driver had already done it's job. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
parent
cece84fa93
commit
b0f94e1c5c
|
@ -323,6 +323,18 @@ void dixScreenRaiseClose(ScreenPtr pScreen);
|
||||||
*/
|
*/
|
||||||
void dixScreenRaisePixmapDestroy(PixmapPtr pPixmap);
|
void dixScreenRaisePixmapDestroy(PixmapPtr pPixmap);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @brief call screen's CreateScreenResources chain
|
||||||
|
* @see dixScreenHookPostCreateResources
|
||||||
|
* @param pScreen the screen to run on
|
||||||
|
*
|
||||||
|
* Call the screen's CreateScreenResources() proc, and if it returns TRUE,
|
||||||
|
* run the installed hooks afterwards.
|
||||||
|
*
|
||||||
|
* Should only be called by DIX itself.
|
||||||
|
*/
|
||||||
|
Bool dixScreenRaiseCreateResources(ScreenPtr pScreen);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @brief mark event ID as critical
|
* @brief mark event ID as critical
|
||||||
* @param event the event to add to the critical events bitmap
|
* @param event the event to add to the critical events bitmap
|
||||||
|
|
|
@ -210,8 +210,7 @@ dix_main(int argc, char *argv[], char *envp[])
|
||||||
ScreenPtr pScreen = screenInfo.gpuscreens[i];
|
ScreenPtr pScreen = screenInfo.gpuscreens[i];
|
||||||
if (!PixmapScreenInit(pScreen))
|
if (!PixmapScreenInit(pScreen))
|
||||||
FatalError("failed to create screen pixmap properties");
|
FatalError("failed to create screen pixmap properties");
|
||||||
if (pScreen->CreateScreenResources &&
|
if (!dixScreenRaiseCreateResources(pScreen))
|
||||||
!(*pScreen->CreateScreenResources) (pScreen))
|
|
||||||
FatalError("failed to create screen resources");
|
FatalError("failed to create screen resources");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,8 +219,7 @@ dix_main(int argc, char *argv[], char *envp[])
|
||||||
|
|
||||||
if (!PixmapScreenInit(pScreen))
|
if (!PixmapScreenInit(pScreen))
|
||||||
FatalError("failed to create screen pixmap properties");
|
FatalError("failed to create screen pixmap properties");
|
||||||
if (pScreen->CreateScreenResources &&
|
if (!dixScreenRaiseCreateResources(pScreen))
|
||||||
!(*pScreen->CreateScreenResources) (pScreen))
|
|
||||||
FatalError("failed to create screen resources");
|
FatalError("failed to create screen resources");
|
||||||
if (!CreateGCperDepth(i))
|
if (!CreateGCperDepth(i))
|
||||||
FatalError("failed to create scratch GCs");
|
FatalError("failed to create scratch GCs");
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
#include <dix-config.h>
|
#include <dix-config.h>
|
||||||
|
|
||||||
|
#include <X11/Xdefs.h>
|
||||||
|
|
||||||
#include "dix/dix_priv.h"
|
#include "dix/dix_priv.h"
|
||||||
#include "dix/screen_hooks_priv.h"
|
#include "dix/screen_hooks_priv.h"
|
||||||
#include "include/dix.h"
|
#include "include/dix.h"
|
||||||
|
@ -27,6 +29,8 @@ DECLARE_HOOK_PROC(WindowDestroy, hookWindowDestroy, XorgScreenWindowDestroyProcP
|
||||||
DECLARE_HOOK_PROC(WindowPosition, hookWindowPosition, XorgScreenWindowPositionProcPtr);
|
DECLARE_HOOK_PROC(WindowPosition, hookWindowPosition, XorgScreenWindowPositionProcPtr);
|
||||||
DECLARE_HOOK_PROC(Close, hookClose, XorgScreenCloseProcPtr);
|
DECLARE_HOOK_PROC(Close, hookClose, XorgScreenCloseProcPtr);
|
||||||
DECLARE_HOOK_PROC(PixmapDestroy, hookPixmapDestroy, XorgScreenPixmapDestroyProcPtr);
|
DECLARE_HOOK_PROC(PixmapDestroy, hookPixmapDestroy, XorgScreenPixmapDestroyProcPtr);
|
||||||
|
DECLARE_HOOK_PROC(PostCreateResources, hookPostCreateResources,
|
||||||
|
XorgScreenPostCreateResourcesProcPtr);
|
||||||
|
|
||||||
int dixScreenRaiseWindowDestroy(WindowPtr pWin)
|
int dixScreenRaiseWindowDestroy(WindowPtr pWin)
|
||||||
{
|
{
|
||||||
|
@ -78,3 +82,18 @@ void dixScreenRaisePixmapDestroy(PixmapPtr pPixmap)
|
||||||
CallCallbacks(&pScreen->hookPixmapDestroy, pPixmap);
|
CallCallbacks(&pScreen->hookPixmapDestroy, pPixmap);
|
||||||
/* we must not call the original ScreenRec->DestroyPixmap() here */
|
/* we must not call the original ScreenRec->DestroyPixmap() here */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Bool dixScreenRaiseCreateResources(ScreenPtr pScreen)
|
||||||
|
{
|
||||||
|
if (!pScreen)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (pScreen->CreateScreenResources) {
|
||||||
|
if (!pScreen->CreateScreenResources(pScreen))
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Bool ret = TRUE;
|
||||||
|
CallCallbacks(&pScreen->hookPostCreateResources, &ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#ifndef XORG_DIX_SCREEN_HOOKS_H
|
#ifndef XORG_DIX_SCREEN_HOOKS_H
|
||||||
#define XORG_DIX_SCREEN_HOOKS_H
|
#define XORG_DIX_SCREEN_HOOKS_H
|
||||||
|
|
||||||
|
#include <X11/Xdefs.h>
|
||||||
#include <X11/Xfuncproto.h>
|
#include <X11/Xfuncproto.h>
|
||||||
|
|
||||||
#include "include/callback.h" /* CallbackListPtr */
|
#include "include/callback.h" /* CallbackListPtr */
|
||||||
|
@ -185,4 +186,36 @@ _X_EXPORT
|
||||||
void dixScreenUnhookPixmapDestroy(ScreenPtr pScreen,
|
void dixScreenUnhookPixmapDestroy(ScreenPtr pScreen,
|
||||||
XorgScreenPixmapDestroyProcPtr func);
|
XorgScreenPixmapDestroyProcPtr func);
|
||||||
|
|
||||||
|
/* prototype of screen close notification handler */
|
||||||
|
typedef void (*XorgScreenPostCreateResourcesProcPtr)(CallbackListPtr *pcbl,
|
||||||
|
ScreenPtr pScreen,
|
||||||
|
Bool *ret);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief register post-CreateScreenResources hook on the given screen
|
||||||
|
*
|
||||||
|
* @param pScreen pointer to the screen to register the notify hook into
|
||||||
|
* @param func pointer to the hook function
|
||||||
|
* @param arg opaque pointer passed to the hook
|
||||||
|
*
|
||||||
|
* This hook is called when CreateScreenResources() had been called
|
||||||
|
* and returned TRUE.
|
||||||
|
**/
|
||||||
|
_X_EXPORT
|
||||||
|
void dixScreenHookPostCreateResources(ScreenPtr pScreen,
|
||||||
|
XorgScreenPostCreateResourcesProcPtr func);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief unregister a post-CreateScreenResources hook on the given screen
|
||||||
|
*
|
||||||
|
* @param pScreen pointer to the screen to unregister the hook from
|
||||||
|
* @param func pointer to the hook function
|
||||||
|
* @param arg opaque pointer passed to the destructor
|
||||||
|
*
|
||||||
|
* @see dixScreenHookPostCreateResources
|
||||||
|
**/
|
||||||
|
_X_EXPORT
|
||||||
|
void dixScreenUnhookPostCreateResources(ScreenPtr pScreen,
|
||||||
|
XorgScreenPostCreateResourcesProcPtr func);
|
||||||
|
|
||||||
#endif /* DIX_SCREEN_HOOKS_H */
|
#endif /* DIX_SCREEN_HOOKS_H */
|
||||||
|
|
|
@ -725,8 +725,7 @@ xf86platformAddDevice(const char *driver_name, int index)
|
||||||
|
|
||||||
PixmapScreenInit(xf86GPUScreens[i]->pScreen);
|
PixmapScreenInit(xf86GPUScreens[i]->pScreen);
|
||||||
|
|
||||||
if (xf86GPUScreens[i]->pScreen->CreateScreenResources &&
|
if (dixScreenRaiseCreateResources(xf86GPUScreens[i]->pScreen)) {
|
||||||
!(*xf86GPUScreens[i]->pScreen->CreateScreenResources) (xf86GPUScreens[i]->pScreen)) {
|
|
||||||
RemoveGPUScreen(xf86GPUScreens[i]->pScreen);
|
RemoveGPUScreen(xf86GPUScreens[i]->pScreen);
|
||||||
xf86DeleteScreen(xf86GPUScreens[i]);
|
xf86DeleteScreen(xf86GPUScreens[i]);
|
||||||
xf86UnclaimPlatformSlot(&xf86_platform_devices[index], NULL);
|
xf86UnclaimPlatformSlot(&xf86_platform_devices[index], NULL);
|
||||||
|
|
|
@ -683,6 +683,10 @@ typedef struct _Screen {
|
||||||
/* additional pixmap destroy notify hooks (replaces wrapping DestroyPixmap)
|
/* additional pixmap destroy notify hooks (replaces wrapping DestroyPixmap)
|
||||||
should NOT be touched outside of DIX core */
|
should NOT be touched outside of DIX core */
|
||||||
CallbackListPtr hookPixmapDestroy;
|
CallbackListPtr hookPixmapDestroy;
|
||||||
|
|
||||||
|
/* hooks run right after SUCCESSFUL CreateScreenResources
|
||||||
|
should NOT be touched outside of DIX core */
|
||||||
|
CallbackListPtr hookPostCreateResources;
|
||||||
} ScreenRec;
|
} ScreenRec;
|
||||||
|
|
||||||
static inline RegionPtr
|
static inline RegionPtr
|
||||||
|
|
Loading…
Reference in New Issue