VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/x11include/xorg-server-1.14.0/privates.h@ 81245

最後變更 在這個檔案從81245是 45134,由 vboxsync 提交於 12 年 前

Additions/X11: build vboxvideo_drv.so for X.Org Server 1.14.

  • 屬性 svn:eol-style 設為 native
檔案大小: 10.8 KB
 
1/***********************************************************
2
3THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
5FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
6AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
7AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
8CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
10******************************************************************/
11
12#ifndef PRIVATES_H
13#define PRIVATES_H 1
14
15#include <X11/Xdefs.h>
16#include <X11/Xosdefs.h>
17#include <X11/Xfuncproto.h>
18#include "misc.h"
19
20/*****************************************************************
21 * STUFF FOR PRIVATES
22 *****************************************************************/
23
24typedef struct _Private PrivateRec, *PrivatePtr;
25
26typedef enum {
27 /* XSELinux uses the same private keys for numerous objects */
28 PRIVATE_XSELINUX,
29
30 /* Otherwise, you get a private in just the requested structure
31 */
32 /* These can have objects created before all of the keys are registered */
33 PRIVATE_SCREEN,
34 PRIVATE_EXTENSION,
35 PRIVATE_COLORMAP,
36 PRIVATE_DEVICE,
37
38 /* These cannot have any objects before all relevant keys are registered */
39 PRIVATE_CLIENT,
40 PRIVATE_PROPERTY,
41 PRIVATE_SELECTION,
42 PRIVATE_WINDOW,
43 PRIVATE_PIXMAP,
44 PRIVATE_GC,
45 PRIVATE_CURSOR,
46 PRIVATE_CURSOR_BITS,
47
48 /* extension privates */
49 PRIVATE_DBE_WINDOW,
50 PRIVATE_DAMAGE,
51 PRIVATE_GLYPH,
52 PRIVATE_GLYPHSET,
53 PRIVATE_PICTURE,
54 PRIVATE_SYNC_FENCE,
55
56 /* last private type */
57 PRIVATE_LAST,
58} DevPrivateType;
59
60typedef struct _DevPrivateKeyRec {
61 int offset;
62 int size;
63 Bool initialized;
64 Bool allocated;
65 DevPrivateType type;
66 struct _DevPrivateKeyRec *next;
67} DevPrivateKeyRec, *DevPrivateKey;
68
69typedef struct _DevPrivateSetRec {
70 DevPrivateKey key;
71 unsigned offset;
72 int created;
73 int allocated;
74} DevPrivateSetRec, *DevPrivateSetPtr;
75
76typedef struct _DevScreenPrivateKeyRec {
77 DevPrivateKeyRec screenKey;
78} DevScreenPrivateKeyRec, *DevScreenPrivateKey;
79
80/*
81 * Let drivers know how to initialize private keys
82 */
83
84#define HAS_DEVPRIVATEKEYREC 1
85#define HAS_DIXREGISTERPRIVATEKEY 1
86
87/*
88 * Register a new private index for the private type.
89 *
90 * This initializes the specified key and optionally requests pre-allocated
91 * private space for your driver/module. If you request no extra space, you
92 * may set and get a single pointer value using this private key. Otherwise,
93 * you can get the address of the extra space and store whatever data you like
94 * there.
95 *
96 * You may call dixRegisterPrivateKey more than once on the same key, but the
97 * size and type must match or the server will abort.
98 *
99 * dixRegisterPrivateKey returns FALSE if it fails to allocate memory
100 * during its operation.
101 */
102extern _X_EXPORT Bool
103 dixRegisterPrivateKey(DevPrivateKey key, DevPrivateType type, unsigned size);
104
105/*
106 * Check whether a private key has been registered
107 */
108static inline Bool
109dixPrivateKeyRegistered(DevPrivateKey key)
110{
111 return key->initialized;
112}
113
114/*
115 * Get the address of the private storage.
116 *
117 * For keys with pre-defined storage, this gets the base of that storage
118 * Otherwise, it returns the place where the private pointer is stored.
119 */
120static inline void *
121dixGetPrivateAddr(PrivatePtr *privates, const DevPrivateKey key)
122{
123 assert(key->initialized);
124 return (char *) (*privates) + key->offset;
125}
126
127/*
128 * Fetch a private pointer stored in the object
129 *
130 * Returns the pointer stored with dixSetPrivate.
131 * This must only be used with keys that have
132 * no pre-defined storage
133 */
134static inline void *
135dixGetPrivate(PrivatePtr *privates, const DevPrivateKey key)
136{
137 assert(key->size == 0);
138 return *(void **) dixGetPrivateAddr(privates, key);
139}
140
141/*
142 * Associate 'val' with 'key' in 'privates' so that later calls to
143 * dixLookupPrivate(privates, key) will return 'val'.
144 */
145static inline void
146dixSetPrivate(PrivatePtr *privates, const DevPrivateKey key, pointer val)
147{
148 assert(key->size == 0);
149 *(pointer *) dixGetPrivateAddr(privates, key) = val;
150}
151
152#include "dix.h"
153#include "resource.h"
154
155/*
156 * Lookup a pointer to the private record.
157 *
158 * For privates with defined storage, return the address of the
159 * storage. For privates without defined storage, return the pointer
160 * contents
161 */
162static inline pointer
163dixLookupPrivate(PrivatePtr *privates, const DevPrivateKey key)
164{
165 if (key->size)
166 return dixGetPrivateAddr(privates, key);
167 else
168 return dixGetPrivate(privates, key);
169}
170
171/*
172 * Look up the address of the pointer to the storage
173 *
174 * This returns the place where the private pointer is stored,
175 * which is only valid for privates without predefined storage.
176 */
177static inline pointer *
178dixLookupPrivateAddr(PrivatePtr *privates, const DevPrivateKey key)
179{
180 assert(key->size == 0);
181 return (pointer *) dixGetPrivateAddr(privates, key);
182}
183
184extern _X_EXPORT Bool
185
186dixRegisterScreenPrivateKey(DevScreenPrivateKey key, ScreenPtr pScreen,
187 DevPrivateType type, unsigned size);
188
189extern _X_EXPORT DevPrivateKey
190 _dixGetScreenPrivateKey(const DevScreenPrivateKey key, ScreenPtr pScreen);
191
192static inline void *
193dixGetScreenPrivateAddr(PrivatePtr *privates, const DevScreenPrivateKey key,
194 ScreenPtr pScreen)
195{
196 return dixGetPrivateAddr(privates, _dixGetScreenPrivateKey(key, pScreen));
197}
198
199static inline void *
200dixGetScreenPrivate(PrivatePtr *privates, const DevScreenPrivateKey key,
201 ScreenPtr pScreen)
202{
203 return dixGetPrivate(privates, _dixGetScreenPrivateKey(key, pScreen));
204}
205
206static inline void
207dixSetScreenPrivate(PrivatePtr *privates, const DevScreenPrivateKey key,
208 ScreenPtr pScreen, pointer val)
209{
210 dixSetPrivate(privates, _dixGetScreenPrivateKey(key, pScreen), val);
211}
212
213static inline pointer
214dixLookupScreenPrivate(PrivatePtr *privates, const DevScreenPrivateKey key,
215 ScreenPtr pScreen)
216{
217 return dixLookupPrivate(privates, _dixGetScreenPrivateKey(key, pScreen));
218}
219
220static inline pointer *
221dixLookupScreenPrivateAddr(PrivatePtr *privates, const DevScreenPrivateKey key,
222 ScreenPtr pScreen)
223{
224 return dixLookupPrivateAddr(privates,
225 _dixGetScreenPrivateKey(key, pScreen));
226}
227
228/*
229 * These functions relate to allocations related to a specific screen;
230 * space will only be available for objects allocated for use on that
231 * screen. As such, only objects which are related directly to a specific
232 * screen are candidates for allocation this way, this includes
233 * windows, pixmaps, gcs, pictures and colormaps. This key is
234 * used just like any other key using dixGetPrivate and friends.
235 *
236 * This is distinctly different from the ScreenPrivateKeys above which
237 * allocate space in global objects like cursor bits for a specific
238 * screen, allowing multiple screen-related chunks of storage in a
239 * single global object.
240 */
241
242#define HAVE_SCREEN_SPECIFIC_PRIVATE_KEYS 1
243
244extern _X_EXPORT Bool
245dixRegisterScreenSpecificPrivateKey(ScreenPtr pScreen, DevPrivateKey key,
246 DevPrivateType type, unsigned size);
247
248/* Clean up screen-specific privates before CloseScreen */
249extern void
250dixFreeScreenSpecificPrivates(ScreenPtr pScreen);
251
252/* Initialize screen-specific privates in AddScreen */
253extern void
254dixInitScreenSpecificPrivates(ScreenPtr pScreen);
255
256extern _X_EXPORT void *
257_dixAllocateScreenObjectWithPrivates(ScreenPtr pScreen,
258 unsigned size,
259 unsigned clear,
260 unsigned offset,
261 DevPrivateType type);
262
263#define dixAllocateScreenObjectWithPrivates(s, t, type) _dixAllocateScreenObjectWithPrivates(s, sizeof(t), sizeof(t), offsetof(t, devPrivates), type)
264
265extern _X_EXPORT int
266dixScreenSpecificPrivatesSize(ScreenPtr pScreen, DevPrivateType type);
267
268extern _X_EXPORT void
269_dixInitScreenPrivates(ScreenPtr pScreen, PrivatePtr *privates, void *addr, DevPrivateType type);
270
271#define dixInitScreenPrivates(s, o, v, type) _dixInitScreenPrivates(s, &(o)->devPrivates, (v), type);
272
273/*
274 * Allocates private data separately from main object.
275 *
276 * For objects created during server initialization, this allows those
277 * privates to be re-allocated as new private keys are registered.
278 *
279 * This includes screens, the serverClient, default colormaps and
280 * extensions entries.
281 */
282extern _X_EXPORT Bool
283 dixAllocatePrivates(PrivatePtr *privates, DevPrivateType type);
284
285/*
286 * Frees separately allocated private data
287 */
288extern _X_EXPORT void
289 dixFreePrivates(PrivatePtr privates, DevPrivateType type);
290
291/*
292 * Initialize privates by zeroing them
293 */
294extern _X_EXPORT void
295_dixInitPrivates(PrivatePtr *privates, void *addr, DevPrivateType type);
296
297#define dixInitPrivates(o, v, type) _dixInitPrivates(&(o)->devPrivates, (v), type);
298
299/*
300 * Clean up privates
301 */
302extern _X_EXPORT void
303 _dixFiniPrivates(PrivatePtr privates, DevPrivateType type);
304
305#define dixFiniPrivates(o,t) _dixFiniPrivates((o)->devPrivates,t)
306
307/*
308 * Allocates private data at object creation time. Required
309 * for almost all objects, except for the list described
310 * above for dixAllocatePrivates.
311 */
312extern _X_EXPORT void *_dixAllocateObjectWithPrivates(unsigned size,
313 unsigned clear,
314 unsigned offset,
315 DevPrivateType type);
316
317#define dixAllocateObjectWithPrivates(t, type) (t *) _dixAllocateObjectWithPrivates(sizeof(t), sizeof(t), offsetof(t, devPrivates), type)
318
319extern _X_EXPORT void
320
321_dixFreeObjectWithPrivates(void *object, PrivatePtr privates,
322 DevPrivateType type);
323
324#define dixFreeObjectWithPrivates(o,t) _dixFreeObjectWithPrivates(o, (o)->devPrivates, t)
325
326/*
327 * Return size of privates for the specified type
328 */
329extern _X_EXPORT int
330 dixPrivatesSize(DevPrivateType type);
331
332/*
333 * Dump out private stats to ErrorF
334 */
335extern void
336 dixPrivateUsage(void);
337
338/*
339 * Resets the privates subsystem. dixResetPrivates is called from the main loop
340 * before each server generation. This function must only be called by main().
341 */
342extern _X_EXPORT void
343 dixResetPrivates(void);
344
345/*
346 * Looks up the offset where the devPrivates field is located.
347 *
348 * Returns -1 if the specified resource has no dev privates.
349 * The position of the devPrivates field varies by structure
350 * and calling code might only know the resource type, not the
351 * structure definition.
352 */
353extern _X_EXPORT int
354 dixLookupPrivateOffset(RESTYPE type);
355
356/*
357 * Convenience macro for adding an offset to an object pointer
358 * when making a call to one of the devPrivates functions
359 */
360#define DEVPRIV_AT(ptr, offset) ((PrivatePtr *)((char *)(ptr) + offset))
361
362#endif /* PRIVATES_H */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette