Moved from http://www.freedesktop.org/wiki/Software/WrappingFunctions
XXX: Add some information about prologues/epilogues
Sometimes you want to override or hook into a certain function and have it do something else. For example, you might want to use an accelerated function for drawing triangles. This is done by replacing the function pointers in the data structures
/* Don't forget to save the original function */
pMyScreenData->CreatePixmap = pSCreen->CreatePixmap;
/* Replace the function */
pScreen->CreatePixmap = MyCreatePixmap;
Now the function MyCreatePixmap
will be called instead of the regular CreatePixmap
function. This is good if we're superstitious:
static PixmapPtr
MyCreatePixmap (ScreenPtr pScreen, int w, int h, int depth)
{
MyScreenDataPtr pMyScreenData = GET''MY''SCREEN_DATA (pScreen);
if (w == 13 && h == 13)
{
/* Refuse to create pixmaps with size 13x13 */
return NULL;
}
/* Call the original function */
return (* pMyScreenData->CreatePixmap) (pScreen, w, h, depth);
}
(See Development/Documentation/DevPrivates for information on where the MyScreenDataPtr
comes from)
-- AndersCarlsson - 23 Sep 2003