VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/x11include/xorg-server-1.12.0/misc.h@ 78293

Last change on this file since 78293 was 40349, checked in by vboxsync, 13 years ago

Additions/xorg: support X.Org Server 1.12.

  • Property svn:eol-style set to native
File size: 11.2 KB
Line 
1/***********************************************************
2
3Copyright 1987, 1998 The Open Group
4
5Permission to use, copy, modify, distribute, and sell this software and its
6documentation for any purpose is hereby granted without fee, provided that
7the above copyright notice appear in all copies and that both that
8copyright notice and this permission notice appear in supporting
9documentation.
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21Except as contained in this notice, the name of The Open Group shall not be
22used in advertising or otherwise to promote the sale, use or other dealings
23in this Software without prior written authorization from The Open Group.
24
25
26Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
27
28 All Rights Reserved
29
30Permission to use, copy, modify, and distribute this software and its
31documentation for any purpose and without fee is hereby granted,
32provided that the above copyright notice appear in all copies and that
33both that copyright notice and this permission notice appear in
34supporting documentation, and that the name of Digital not be
35used in advertising or publicity pertaining to distribution of the
36software without specific, written prior permission.
37
38DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
44SOFTWARE.
45
46Copyright 1992, 1993 Data General Corporation;
47Copyright 1992, 1993 OMRON Corporation
48
49Permission to use, copy, modify, distribute, and sell this software and its
50documentation for any purpose is hereby granted without fee, provided that the
51above copyright notice appear in all copies and that both that copyright
52notice and this permission notice appear in supporting documentation, and that
53neither the name OMRON or DATA GENERAL be used in advertising or publicity
54pertaining to distribution of the software without specific, written prior
55permission of the party whose name is to be used. Neither OMRON or
56DATA GENERAL make any representation about the suitability of this software
57for any purpose. It is provided "as is" without express or implied warranty.
58
59OMRON AND DATA GENERAL EACH DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
60SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
61IN NO EVENT SHALL OMRON OR DATA GENERAL BE LIABLE FOR ANY SPECIAL, INDIRECT
62OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
63DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
64TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
65OF THIS SOFTWARE.
66
67******************************************************************/
68#ifndef MISC_H
69#define MISC_H 1
70/*
71 * X internal definitions
72 *
73 */
74
75#include <X11/Xosdefs.h>
76#include <X11/Xfuncproto.h>
77#include <X11/Xmd.h>
78#include <X11/X.h>
79#include <X11/Xdefs.h>
80
81#include <stddef.h>
82#include <stdint.h>
83
84#ifndef MAXSCREENS
85#define MAXSCREENS 16
86#endif
87#define MAXCLIENTS 256
88#define MAXEXTENSIONS 128
89#define MAXFORMATS 8
90#define MAXDEVICES 40 /* input devices */
91
92/* 128 event opcodes for core + extension events, excluding GE */
93#define MAXEVENTS 128
94#define EXTENSION_EVENT_BASE 64
95#define EXTENSION_BASE 128
96
97typedef uint32_t ATOM;
98
99#ifndef TRUE
100#define TRUE 1
101#define FALSE 0
102#endif
103
104#ifndef _XTYPEDEF_CALLBACKLISTPTR
105typedef struct _CallbackList *CallbackListPtr; /* also in dix.h */
106#define _XTYPEDEF_CALLBACKLISTPTR
107#endif
108
109typedef struct _xReq *xReqPtr;
110
111#include "os.h" /* for ALLOCATE_LOCAL and DEALLOCATE_LOCAL */
112#include <X11/Xfuncs.h> /* for bcopy, bzero, and bcmp */
113
114#define NullBox ((BoxPtr)0)
115#define MILLI_PER_MIN (1000 * 60)
116#define MILLI_PER_SECOND (1000)
117
118 /* this next is used with None and ParentRelative to tell
119 PaintWin() what to use to paint the background. Also used
120 in the macro IS_VALID_PIXMAP */
121
122#define USE_BACKGROUND_PIXEL 3
123#define USE_BORDER_PIXEL 3
124
125
126/* byte swap a 32-bit literal */
127static inline uint32_t lswapl(uint32_t x)
128{
129 return ((x & 0xff) << 24) |
130 ((x & 0xff00) << 8) |
131 ((x & 0xff0000) >> 8) |
132 ((x >> 24) & 0xff);
133}
134
135/* byte swap a 16-bit literal */
136static inline uint16_t lswaps(uint16_t x)
137{
138 return ((x & 0xff) << 8) | ((x >> 8) & 0xff);
139}
140
141#undef min
142#undef max
143
144#define min(a, b) (((a) < (b)) ? (a) : (b))
145#define max(a, b) (((a) > (b)) ? (a) : (b))
146/* abs() is a function, not a macro; include the file declaring
147 * it in case we haven't done that yet.
148 */
149#include <stdlib.h>
150#define sign(x) ((x) < 0 ? -1 : ((x) > 0 ? 1 : 0))
151/* this assumes b > 0 */
152#define modulus(a, b, d) if (((d) = (a) % (b)) < 0) (d) += (b)
153/*
154 * return the least significant bit in x which is set
155 *
156 * This works on 1's complement and 2's complement machines.
157 * If you care about the extra instruction on 2's complement
158 * machines, change to ((x) & (-(x)))
159 */
160#define lowbit(x) ((x) & (~(x) + 1))
161
162/* XXX Not for modules */
163#include <limits.h>
164#if !defined(MAXSHORT) || !defined(MINSHORT) || \
165 !defined(MAXINT) || !defined(MININT)
166/*
167 * Some implementations #define these through <math.h>, so preclude
168 * #include'ing it later.
169 */
170
171#include <math.h>
172#undef MAXSHORT
173#define MAXSHORT SHRT_MAX
174#undef MINSHORT
175#define MINSHORT SHRT_MIN
176#undef MAXINT
177#define MAXINT INT_MAX
178#undef MININT
179#define MININT INT_MIN
180
181#include <assert.h>
182#include <ctype.h>
183#include <stdio.h> /* for fopen, etc... */
184
185#endif
186
187#ifndef PATH_MAX
188#include <sys/param.h>
189#ifndef PATH_MAX
190#ifdef MAXPATHLEN
191#define PATH_MAX MAXPATHLEN
192#else
193#define PATH_MAX 1024
194#endif
195#endif
196#endif
197
198/**
199 * Calculate the number of bytes needed to hold bits.
200 * @param bits The minimum number of bits needed.
201 * @return The number of bytes needed to hold bits.
202 */
203static inline int
204bits_to_bytes(const int bits) {
205 return ((bits + 7) >> 3);
206}
207/**
208 * Calculate the number of 4-byte units needed to hold the given number of
209 * bytes.
210 * @param bytes The minimum number of bytes needed.
211 * @return The number of 4-byte units needed to hold bytes.
212 */
213static inline int
214bytes_to_int32(const int bytes) {
215 return (((bytes) + 3) >> 2);
216}
217
218/**
219 * Calculate the number of bytes (in multiples of 4) needed to hold bytes.
220 * @param bytes The minimum number of bytes needed.
221 * @return The closest multiple of 4 that is equal or higher than bytes.
222 */
223static inline int
224pad_to_int32(const int bytes) {
225 return (((bytes) + 3) & ~3);
226}
227
228extern char**
229xstrtokenize(const char *str, const char* separators);
230
231/**
232 * Compare the two version numbers comprising of major.minor.
233 *
234 * @return A value less than 0 if a is less than b, 0 if a is equal to b,
235 * or a value greater than 0
236 */
237static inline int
238version_compare(uint16_t a_major, uint16_t a_minor,
239 uint16_t b_major, uint16_t b_minor)
240{
241 int a, b;
242
243 a = a_major << 16 | a_minor;
244 b = b_major << 16 | b_minor;
245
246 return (a - b);
247}
248
249/* some macros to help swap requests, replies, and events */
250
251#define LengthRestB(stuff) \
252 ((client->req_len << 2) - sizeof(*stuff))
253
254#define LengthRestS(stuff) \
255 ((client->req_len << 1) - (sizeof(*stuff) >> 1))
256
257#define LengthRestL(stuff) \
258 (client->req_len - (sizeof(*stuff) >> 2))
259
260#define SwapRestS(stuff) \
261 SwapShorts((short *)(stuff + 1), LengthRestS(stuff))
262
263#define SwapRestL(stuff) \
264 SwapLongs((CARD32 *)(stuff + 1), LengthRestL(stuff))
265
266#if defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
267void __attribute__((error("wrong sized variable passed to swap"))) wrong_size(void);
268#else
269static inline void wrong_size(void)
270{
271}
272#endif
273
274#if !(defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)))
275static inline int __builtin_constant_p(int x)
276{
277 return 0;
278}
279#endif
280
281/* byte swap a 32-bit value */
282static inline void swap_uint32(uint32_t *x)
283{
284 char n = ((char *) x)[0];
285 ((char *) x)[0] = ((char *) x)[3];
286 ((char *) x)[3] = n;
287 n = ((char *) x)[1];
288 ((char *) x)[1] = ((char *) x)[2];
289 ((char *) x)[2] = n;
290}
291
292#define swapl(x) do { \
293 if (sizeof(*(x)) != 4) \
294 wrong_size(); \
295 if (__builtin_constant_p((uintptr_t)(x) & 3) && ((uintptr_t)(x) & 3) == 0) \
296 *(x) = lswapl(*(x)); \
297 else \
298 swap_uint32((uint32_t *)(x)); \
299 } while (0)
300
301/* byte swap a 16-bit value */
302static inline void swap_uint16(uint16_t *x)
303{
304 char n = ((char *) x)[0];
305 ((char *) x)[0] = ((char *) x)[1];
306 ((char *) x)[1] = n;
307}
308
309#define swaps(x) do { \
310 if (sizeof(*(x)) != 2) \
311 wrong_size(); \
312 if (__builtin_constant_p((uintptr_t)(x) & 1) && ((uintptr_t)(x) & 1) == 0) \
313 *(x) = lswaps(*(x)); \
314 else \
315 swap_uint16((uint16_t *)(x)); \
316 } while (0)
317
318/* copy 32-bit value from src to dst byteswapping on the way */
319#define cpswapl(src, dst) do { \
320 if (sizeof((src)) != 4 || sizeof((dst)) != 4) \
321 wrong_size(); \
322 (dst) = lswapl((src)); \
323 } while (0)
324
325/* copy short from src to dst byteswapping on the way */
326#define cpswaps(src, dst) do { \
327 if (sizeof((src)) != 2 || sizeof((dst)) != 2) \
328 wrong_size(); \
329 (dst) = lswaps((src)); \
330 } while (0)
331
332extern _X_EXPORT void SwapLongs(
333 CARD32 *list,
334 unsigned long count);
335
336extern _X_EXPORT void SwapShorts(
337 short *list,
338 unsigned long count);
339
340extern _X_EXPORT void MakePredeclaredAtoms(void);
341
342extern _X_EXPORT int Ones(
343 unsigned long /*mask*/);
344
345typedef struct _xPoint *DDXPointPtr;
346typedef struct pixman_box16 *BoxPtr;
347typedef struct _xEvent *xEventPtr;
348typedef struct _xRectangle *xRectanglePtr;
349typedef struct _GrabRec *GrabPtr;
350
351/* typedefs from other places - duplicated here to minimize the amount
352 * of unnecessary junk that one would normally have to include to get
353 * these symbols defined
354 */
355
356#ifndef _XTYPEDEF_CHARINFOPTR
357typedef struct _CharInfo *CharInfoPtr; /* also in fonts/include/font.h */
358#define _XTYPEDEF_CHARINFOPTR
359#endif
360
361extern _X_EXPORT unsigned long globalSerialNumber;
362extern _X_EXPORT unsigned long serverGeneration;
363
364/* Don't use this directly, use BUG_WARN or BUG_WARN_MSG instead */
365#define __BUG_WARN_MSG(cond, with_msg, ...) \
366 do { if (cond) { \
367 ErrorF("BUG: triggered 'if (" #cond ")'\n"); \
368 ErrorF("BUG: %s:%d in %s()\n", \
369 __FILE__, __LINE__, __func__); \
370 if (with_msg) ErrorF(__VA_ARGS__); \
371 xorg_backtrace(); \
372 } } while(0)
373
374#define BUG_WARN_MSG(cond, ...) \
375 __BUG_WARN_MSG(cond, 1, __VA_ARGS__)
376
377#define BUG_WARN(cond) __BUG_WARN_MSG(cond, 0, NULL)
378
379#endif /* MISC_H */
Note: See TracBrowser for help on using the repository browser.

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