Commit | Line | Data |
---|---|---|
a09e091a JB |
1 | /* |
2 | *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. | |
3 | * | |
4 | *Permission is hereby granted, free of charge, to any person obtaining | |
5 | * a copy of this software and associated documentation files (the | |
6 | *"Software"), to deal in the Software without restriction, including | |
7 | *without limitation the rights to use, copy, modify, merge, publish, | |
8 | *distribute, sublicense, and/or sell copies of the Software, and to | |
9 | *permit persons to whom the Software is furnished to do so, subject to | |
10 | *the following conditions: | |
11 | * | |
12 | *The above copyright notice and this permission notice shall be | |
13 | *included in all copies or substantial portions of the Software. | |
14 | * | |
15 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
16 | *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
17 | *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
18 | *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR | |
19 | *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |
20 | *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
21 | *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | *Except as contained in this notice, the name of the XFree86 Project | |
24 | *shall not be used in advertising or otherwise to promote the sale, use | |
25 | *or other dealings in this Software without prior written authorization | |
26 | *from the XFree86 Project. | |
27 | * | |
28 | * Authors: Keith Packard, MIT X Consortium | |
29 | * Harold L Hunt II | |
30 | */ | |
31 | ||
32 | #ifdef HAVE_XWIN_CONFIG_H | |
33 | #include <xwin-config.h> | |
34 | #endif | |
35 | #include "win.h" | |
36 | ||
37 | /* See Porting Layer Definition - p. 58 */ | |
38 | /* | |
39 | * Allocate indexes for the privates that we use. | |
40 | * Allocate memory directly for the screen privates. | |
41 | * Reserve space in GCs and Pixmaps for our privates. | |
42 | * Colormap privates are handled in winAllocateCmapPrivates () | |
43 | */ | |
44 | ||
45 | Bool | |
46 | winAllocatePrivates(ScreenPtr pScreen) | |
47 | { | |
48 | winPrivScreenPtr pScreenPriv; | |
49 | ||
50 | #if CYGDEBUG | |
51 | winDebug("winAllocateScreenPrivates - g_ulServerGeneration: %d " | |
52 | "serverGeneration: %d\n", g_ulServerGeneration, serverGeneration); | |
53 | #endif | |
54 | ||
55 | /* We need a new slot for our privates if the screen gen has changed */ | |
56 | if (g_ulServerGeneration != serverGeneration) { | |
57 | g_ulServerGeneration = serverGeneration; | |
58 | } | |
59 | ||
60 | /* Allocate memory for the screen private structure */ | |
61 | pScreenPriv = (winPrivScreenPtr) malloc(sizeof(winPrivScreenRec)); | |
62 | if (!pScreenPriv) { | |
63 | ErrorF("winAllocateScreenPrivates - malloc () failed\n"); | |
64 | return FALSE; | |
65 | } | |
66 | ||
67 | /* Initialize the memory of the private structure */ | |
68 | ZeroMemory(pScreenPriv, sizeof(winPrivScreenRec)); | |
69 | ||
70 | /* Intialize private structure members */ | |
71 | pScreenPriv->fActive = TRUE; | |
72 | ||
73 | /* Register our screen private */ | |
74 | if (!dixRegisterPrivateKey(g_iScreenPrivateKey, PRIVATE_SCREEN, 0)) { | |
75 | ErrorF("winAllocatePrivates - AllocateScreenPrivate () failed\n"); | |
76 | return FALSE; | |
77 | } | |
78 | ||
79 | /* Save the screen private pointer */ | |
80 | winSetScreenPriv(pScreen, pScreenPriv); | |
81 | ||
82 | /* Reserve GC memory for our privates */ | |
83 | if (!dixRegisterPrivateKey | |
84 | (g_iGCPrivateKey, PRIVATE_GC, sizeof(winPrivGCRec))) { | |
85 | ErrorF("winAllocatePrivates - AllocateGCPrivate () failed\n"); | |
86 | return FALSE; | |
87 | } | |
88 | ||
89 | /* Reserve Pixmap memory for our privates */ | |
90 | if (!dixRegisterPrivateKey | |
91 | (g_iPixmapPrivateKey, PRIVATE_PIXMAP, sizeof(winPrivPixmapRec))) { | |
92 | ErrorF("winAllocatePrivates - AllocatePixmapPrivates () failed\n"); | |
93 | return FALSE; | |
94 | } | |
95 | ||
96 | /* Reserve Window memory for our privates */ | |
97 | if (!dixRegisterPrivateKey | |
98 | (g_iWindowPrivateKey, PRIVATE_WINDOW, sizeof(winPrivWinRec))) { | |
99 | ErrorF("winAllocatePrivates () - AllocateWindowPrivates () failed\n"); | |
100 | return FALSE; | |
101 | } | |
102 | ||
103 | return TRUE; | |
104 | } | |
105 | ||
106 | /* | |
107 | * Colormap privates may be allocated after the default colormap has | |
108 | * already been created for some screens. This initialization procedure | |
109 | * is called for each default colormap that is found. | |
110 | */ | |
111 | ||
112 | Bool | |
113 | winInitCmapPrivates(ColormapPtr pcmap, int i) | |
114 | { | |
115 | #if CYGDEBUG | |
116 | winDebug("winInitCmapPrivates\n"); | |
117 | #endif | |
118 | ||
119 | /* | |
120 | * I see no way that this function can do anything useful | |
121 | * with only a ColormapPtr. We don't have the index for | |
122 | * our dev privates yet, so we can't really initialize | |
123 | * anything. Perhaps I am misunderstanding the purpose | |
124 | * of this function. | |
125 | */ | |
126 | /* That's definitely true. | |
127 | * I therefore changed the API and added the index as argument. | |
128 | */ | |
129 | return TRUE; | |
130 | } | |
131 | ||
132 | /* | |
133 | * Allocate memory for our colormap privates | |
134 | */ | |
135 | ||
136 | Bool | |
137 | winAllocateCmapPrivates(ColormapPtr pCmap) | |
138 | { | |
139 | winPrivCmapPtr pCmapPriv; | |
140 | static unsigned long s_ulPrivateGeneration = 0; | |
141 | ||
142 | #if CYGDEBUG | |
143 | winDebug("winAllocateCmapPrivates\n"); | |
144 | #endif | |
145 | ||
146 | /* Get a new privates index when the server generation changes */ | |
147 | if (s_ulPrivateGeneration != serverGeneration) { | |
148 | /* Save the new server generation */ | |
149 | s_ulPrivateGeneration = serverGeneration; | |
150 | } | |
151 | ||
152 | /* Allocate memory for our private structure */ | |
153 | pCmapPriv = (winPrivCmapPtr) malloc(sizeof(winPrivCmapRec)); | |
154 | if (!pCmapPriv) { | |
155 | ErrorF("winAllocateCmapPrivates - malloc () failed\n"); | |
156 | return FALSE; | |
157 | } | |
158 | ||
159 | /* Initialize the memory of the private structure */ | |
160 | ZeroMemory(pCmapPriv, sizeof(winPrivCmapRec)); | |
161 | ||
162 | /* Register our colourmap private */ | |
163 | if (!dixRegisterPrivateKey(g_iCmapPrivateKey, PRIVATE_COLORMAP, 0)) { | |
164 | ErrorF("winAllocateCmapPrivates - AllocateCmapPrivate () failed\n"); | |
165 | return FALSE; | |
166 | } | |
167 | ||
168 | /* Save the cmap private pointer */ | |
169 | winSetCmapPriv(pCmap, pCmapPriv); | |
170 | ||
171 | #if CYGDEBUG | |
172 | winDebug("winAllocateCmapPrivates - Returning\n"); | |
173 | #endif | |
174 | ||
175 | return TRUE; | |
176 | } |