PageRenderTime 46ms CodeModel.GetById 1ms RepoModel.GetById 1ms app.codeStats 0ms

/include/misc.h

https://github.com/dmitriy103/androix-xserver
C Header | 292 lines | 131 code | 44 blank | 117 comment | 4 complexity | 8059e0addb10923d06d71d0ec19a1cb0 MD5 | raw file
  1. /***********************************************************
  2. Copyright 1987, 1998 The Open Group
  3. Permission to use, copy, modify, distribute, and sell this software and its
  4. documentation for any purpose is hereby granted without fee, provided that
  5. the above copyright notice appear in all copies and that both that
  6. copyright notice and this permission notice appear in supporting
  7. documentation.
  8. The above copyright notice and this permission notice shall be included in
  9. all copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  14. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. Except as contained in this notice, the name of The Open Group shall not be
  17. used in advertising or otherwise to promote the sale, use or other dealings
  18. in this Software without prior written authorization from The Open Group.
  19. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
  20. All Rights Reserved
  21. Permission to use, copy, modify, and distribute this software and its
  22. documentation for any purpose and without fee is hereby granted,
  23. provided that the above copyright notice appear in all copies and that
  24. both that copyright notice and this permission notice appear in
  25. supporting documentation, and that the name of Digital not be
  26. used in advertising or publicity pertaining to distribution of the
  27. software without specific, written prior permission.
  28. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  29. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  30. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  31. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  32. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  33. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  34. SOFTWARE.
  35. Copyright 1992, 1993 Data General Corporation;
  36. Copyright 1992, 1993 OMRON Corporation
  37. Permission to use, copy, modify, distribute, and sell this software and its
  38. documentation for any purpose is hereby granted without fee, provided that the
  39. above copyright notice appear in all copies and that both that copyright
  40. notice and this permission notice appear in supporting documentation, and that
  41. neither the name OMRON or DATA GENERAL be used in advertising or publicity
  42. pertaining to distribution of the software without specific, written prior
  43. permission of the party whose name is to be used. Neither OMRON or
  44. DATA GENERAL make any representation about the suitability of this software
  45. for any purpose. It is provided "as is" without express or implied warranty.
  46. OMRON AND DATA GENERAL EACH DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  47. SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  48. IN NO EVENT SHALL OMRON OR DATA GENERAL BE LIABLE FOR ANY SPECIAL, INDIRECT
  49. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  50. DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  51. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  52. OF THIS SOFTWARE.
  53. ******************************************************************/
  54. #ifndef MISC_H
  55. #define MISC_H 1
  56. /*
  57. * X internal definitions
  58. *
  59. */
  60. #include <X11/Xosdefs.h>
  61. #include <X11/Xfuncproto.h>
  62. #include <X11/Xmd.h>
  63. #include <X11/X.h>
  64. #include <X11/Xdefs.h>
  65. #include <stddef.h>
  66. #ifndef MAXSCREENS
  67. #define MAXSCREENS 16
  68. #endif
  69. #define MAXCLIENTS 256
  70. #define MAXEXTENSIONS 128
  71. #define MAXFORMATS 8
  72. #define MAXDEVICES 40 /* input devices */
  73. #define EXTENSION_EVENT_BASE 64
  74. #define EXTENSION_BASE 128
  75. typedef unsigned long PIXEL;
  76. typedef unsigned long ATOM;
  77. #ifndef TRUE
  78. #define TRUE 1
  79. #define FALSE 0
  80. #endif
  81. #ifndef _XTYPEDEF_CALLBACKLISTPTR
  82. typedef struct _CallbackList *CallbackListPtr; /* also in dix.h */
  83. #define _XTYPEDEF_CALLBACKLISTPTR
  84. #endif
  85. typedef struct _xReq *xReqPtr;
  86. #include "os.h" /* for ALLOCATE_LOCAL and DEALLOCATE_LOCAL */
  87. #include <X11/Xfuncs.h> /* for bcopy, bzero, and bcmp */
  88. #define NullBox ((BoxPtr)0)
  89. #define MILLI_PER_MIN (1000 * 60)
  90. #define MILLI_PER_SECOND (1000)
  91. /* this next is used with None and ParentRelative to tell
  92. PaintWin() what to use to paint the background. Also used
  93. in the macro IS_VALID_PIXMAP */
  94. #define USE_BACKGROUND_PIXEL 3
  95. #define USE_BORDER_PIXEL 3
  96. /* byte swap a 32-bit literal */
  97. #define lswapl(x) ((((x) & 0xff) << 24) |\
  98. (((x) & 0xff00) << 8) |\
  99. (((x) & 0xff0000) >> 8) |\
  100. (((x) >> 24) & 0xff))
  101. /* byte swap a short literal */
  102. #define lswaps(x) ((((x) & 0xff) << 8) | (((x) >> 8) & 0xff))
  103. #undef min
  104. #undef max
  105. #define min(a, b) (((a) < (b)) ? (a) : (b))
  106. #define max(a, b) (((a) > (b)) ? (a) : (b))
  107. /* abs() is a function, not a macro; include the file declaring
  108. * it in case we haven't done that yet.
  109. */
  110. #include <stdlib.h>
  111. #ifndef Fabs
  112. #define Fabs(a) ((a) > 0.0 ? (a) : -(a)) /* floating absolute value */
  113. #endif
  114. #define sign(x) ((x) < 0 ? -1 : ((x) > 0 ? 1 : 0))
  115. /* this assumes b > 0 */
  116. #define modulus(a, b, d) if (((d) = (a) % (b)) < 0) (d) += (b)
  117. /*
  118. * return the least significant bit in x which is set
  119. *
  120. * This works on 1's complement and 2's complement machines.
  121. * If you care about the extra instruction on 2's complement
  122. * machines, change to ((x) & (-(x)))
  123. */
  124. #define lowbit(x) ((x) & (~(x) + 1))
  125. /* XXX Not for modules */
  126. #include <limits.h>
  127. #if !defined(MAXSHORT) || !defined(MINSHORT) || \
  128. !defined(MAXINT) || !defined(MININT)
  129. /*
  130. * Some implementations #define these through <math.h>, so preclude
  131. * #include'ing it later.
  132. */
  133. #include <math.h>
  134. #undef MAXSHORT
  135. #define MAXSHORT SHRT_MAX
  136. #undef MINSHORT
  137. #define MINSHORT SHRT_MIN
  138. #undef MAXINT
  139. #define MAXINT INT_MAX
  140. #undef MININT
  141. #define MININT INT_MIN
  142. #include <assert.h>
  143. #include <ctype.h>
  144. #include <stdio.h> /* for fopen, etc... */
  145. #endif
  146. /**
  147. * Calculate the number of bytes needed to hold bits.
  148. * @param bits The minimum number of bits needed.
  149. * @return The number of bytes needed to hold bits.
  150. */
  151. static inline int
  152. bits_to_bytes(const int bits) {
  153. return ((bits + 7) >> 3);
  154. }
  155. /**
  156. * Calculate the number of 4-byte units needed to hold the given number of
  157. * bytes.
  158. * @param bytes The minimum number of bytes needed.
  159. * @return The number of 4-byte units needed to hold bytes.
  160. */
  161. static inline int
  162. bytes_to_int32(const int bytes) {
  163. return (((bytes) + 3) >> 2);
  164. }
  165. /**
  166. * Calculate the number of bytes (in multiples of 4) needed to hold bytes.
  167. * @param bytes The minimum number of bytes needed.
  168. * @return The closest multiple of 4 that is equal or higher than bytes.
  169. */
  170. static inline int
  171. pad_to_int32(const int bytes) {
  172. return (((bytes) + 3) & ~3);
  173. }
  174. extern char**
  175. xstrtokenize(const char *str, const char* separators);
  176. /* some macros to help swap requests, replies, and events */
  177. #define LengthRestB(stuff) \
  178. ((client->req_len << 2) - sizeof(*stuff))
  179. #define LengthRestS(stuff) \
  180. ((client->req_len << 1) - (sizeof(*stuff) >> 1))
  181. #define LengthRestL(stuff) \
  182. (client->req_len - (sizeof(*stuff) >> 2))
  183. #define SwapRestS(stuff) \
  184. SwapShorts((short *)(stuff + 1), LengthRestS(stuff))
  185. #define SwapRestL(stuff) \
  186. SwapLongs((CARD32 *)(stuff + 1), LengthRestL(stuff))
  187. /* byte swap a 32-bit value */
  188. #define swapl(x, n) { \
  189. n = ((char *) (x))[0];\
  190. ((char *) (x))[0] = ((char *) (x))[3];\
  191. ((char *) (x))[3] = n;\
  192. n = ((char *) (x))[1];\
  193. ((char *) (x))[1] = ((char *) (x))[2];\
  194. ((char *) (x))[2] = n; }
  195. /* byte swap a short */
  196. #define swaps(x, n) { \
  197. n = ((char *) (x))[0];\
  198. ((char *) (x))[0] = ((char *) (x))[1];\
  199. ((char *) (x))[1] = n; }
  200. /* copy 32-bit value from src to dst byteswapping on the way */
  201. #define cpswapl(src, dst) { \
  202. ((char *)&(dst))[0] = ((char *) &(src))[3];\
  203. ((char *)&(dst))[1] = ((char *) &(src))[2];\
  204. ((char *)&(dst))[2] = ((char *) &(src))[1];\
  205. ((char *)&(dst))[3] = ((char *) &(src))[0]; }
  206. /* copy short from src to dst byteswapping on the way */
  207. #define cpswaps(src, dst) { \
  208. ((char *) &(dst))[0] = ((char *) &(src))[1];\
  209. ((char *) &(dst))[1] = ((char *) &(src))[0]; }
  210. extern _X_EXPORT void SwapLongs(
  211. CARD32 *list,
  212. unsigned long count);
  213. extern _X_EXPORT void SwapShorts(
  214. short *list,
  215. unsigned long count);
  216. extern _X_EXPORT void MakePredeclaredAtoms(void);
  217. extern _X_EXPORT int Ones(
  218. unsigned long /*mask*/);
  219. typedef struct _xPoint *DDXPointPtr;
  220. typedef struct pixman_box16 *BoxPtr;
  221. typedef struct _xEvent *xEventPtr;
  222. typedef struct _xRectangle *xRectanglePtr;
  223. typedef struct _GrabRec *GrabPtr;
  224. /* typedefs from other places - duplicated here to minimize the amount
  225. * of unnecessary junk that one would normally have to include to get
  226. * these symbols defined
  227. */
  228. #ifndef _XTYPEDEF_CHARINFOPTR
  229. typedef struct _CharInfo *CharInfoPtr; /* also in fonts/include/font.h */
  230. #define _XTYPEDEF_CHARINFOPTR
  231. #endif
  232. extern _X_EXPORT unsigned long globalSerialNumber;
  233. extern _X_EXPORT unsigned long serverGeneration;
  234. #endif /* MISC_H */