summaryrefslogtreecommitdiff
path: root/Development/Documentation/WrappingFunctions.mdwn
blob: 5991859a6fc978d40a0aa8c09ee425309545bbb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
*Moved from <http://www.freedesktop.org/wiki/Software/WrappingFunctions>*


## Wrapping Functions

_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 


[[!format txt """
/* 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: 
[[!format txt """
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|Development/Documentation/DevPrivates]] for information on where the `MyScreenDataPtr` comes from) 

-- [[AndersCarlsson|AndersCarlsson]] - 23 Sep 2003 

---
[[CategoryServerInternals]]