1 #ifdef HAVE_DIX_CONFIG_H
2 #include <dix-config.h>
5 #ifndef __GLX_unpack_h__
6 #define __GLX_unpack_h__
9 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
10 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
19 * The above copyright notice including the dates of first publication and
20 * either this permission notice or a reference to
21 * http://oss.sgi.com/projects/FreeB/
22 * shall be included in all copies or substantial portions of the Software.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
29 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * Except as contained in this notice, the name of Silicon Graphics, Inc.
33 * shall not be used in advertising or otherwise to promote the sale, use or
34 * other dealings in this Software without prior written authorization from
35 * Silicon Graphics, Inc.
38 #define __GLX_PAD(s) (((s)+3) & (GLuint)~3)
41 ** Fetch the context-id out of a SingleReq request pointed to by pc.
43 #define __GLX_GET_SINGLE_CONTEXT_TAG(pc) (((xGLXSingleReq*)pc)->contextTag)
44 #define __GLX_GET_VENDPRIV_CONTEXT_TAG(pc) (((xGLXVendorPrivateReq*)pc)->contextTag)
47 ** Fetch a double from potentially unaligned memory.
50 #define __GLX_MEM_COPY(dst,src,n) if (src != NULL && dst != NULL) memcpy(dst,src,n)
51 #define __GLX_GET_DOUBLE(dst,src) __GLX_MEM_COPY(&dst,src,8)
53 #define __GLX_GET_DOUBLE(dst,src) (dst) = *((GLdouble*)(src))
56 extern void __glXMemInit(void);
58 extern xGLXSingleReply __glXReply;
60 #define __GLX_BEGIN_REPLY(size) \
61 __glXReply.length = __GLX_PAD(size) >> 2; \
62 __glXReply.type = X_Reply; \
63 __glXReply.sequenceNumber = client->sequence;
65 #define __GLX_SEND_HEADER() \
66 WriteToClient( client, sz_xGLXSingleReply, (char *)&__glXReply);
68 #define __GLX_PUT_RETVAL(a) \
69 __glXReply.retval = (a);
71 #define __GLX_PUT_SIZE(a) \
72 __glXReply.size = (a);
74 #define __GLX_PUT_RENDERMODE(m) \
78 ** Get a buffer to hold returned data, with the given alignment. If we have
79 ** to realloc, allocate size+align, in case the pointer has to be bumped for
80 ** alignment. The answerBuffer should already be aligned.
82 ** NOTE: the cast (long)res below assumes a long is large enough to hold a
85 #define __GLX_GET_ANSWER_BUFFER(res,cl,size,align) \
86 if ((size) > sizeof(answerBuffer)) { \
88 if ((cl)->returnBufSize < (size)+(align)) { \
89 (cl)->returnBuf = (GLbyte*)realloc((cl)->returnBuf, \
91 if (!(cl)->returnBuf) { \
94 (cl)->returnBufSize = (size)+(align); \
96 res = (char*)cl->returnBuf; \
97 bump = (long)(res) % (align); \
98 if (bump) res += (align) - (bump); \
100 res = (char *)answerBuffer; \
103 #define __GLX_PUT_BYTE() \
104 *(GLbyte *)&__glXReply.pad3 = *(GLbyte *)answer
106 #define __GLX_PUT_SHORT() \
107 *(GLshort *)&__glXReply.pad3 = *(GLshort *)answer
109 #define __GLX_PUT_INT() \
110 *(GLint *)&__glXReply.pad3 = *(GLint *)answer
112 #define __GLX_PUT_FLOAT() \
113 *(GLfloat *)&__glXReply.pad3 = *(GLfloat *)answer
115 #define __GLX_PUT_DOUBLE() \
116 *(GLdouble *)&__glXReply.pad3 = *(GLdouble *)answer
118 #define __GLX_SEND_BYTE_ARRAY(len) \
119 WriteToClient(client, __GLX_PAD((len)*__GLX_SIZE_INT8), (char *)answer)
121 #define __GLX_SEND_SHORT_ARRAY(len) \
122 WriteToClient(client, __GLX_PAD((len)*__GLX_SIZE_INT16), (char *)answer)
124 #define __GLX_SEND_INT_ARRAY(len) \
125 WriteToClient(client, (len)*__GLX_SIZE_INT32, (char *)answer)
127 #define __GLX_SEND_FLOAT_ARRAY(len) \
128 WriteToClient(client, (len)*__GLX_SIZE_FLOAT32, (char *)answer)
130 #define __GLX_SEND_DOUBLE_ARRAY(len) \
131 WriteToClient(client, (len)*__GLX_SIZE_FLOAT64, (char *)answer)
134 #define __GLX_SEND_VOID_ARRAY(len) __GLX_SEND_BYTE_ARRAY(len)
135 #define __GLX_SEND_UBYTE_ARRAY(len) __GLX_SEND_BYTE_ARRAY(len)
136 #define __GLX_SEND_USHORT_ARRAY(len) __GLX_SEND_SHORT_ARRAY(len)
137 #define __GLX_SEND_UINT_ARRAY(len) __GLX_SEND_INT_ARRAY(len)
141 ** Machine dependent optimizations abound here; these swapping macros can
142 ** conceivably be replaced with routines that do the job faster.
144 #define __GLX_DECLARE_SWAP_VARIABLES \
147 #define __GLX_DECLARE_SWAP_ARRAY_VARIABLES \
152 #define __GLX_SWAP_INT(pc) \
153 sw = ((GLbyte *)(pc))[0]; \
154 ((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[3]; \
155 ((GLbyte *)(pc))[3] = sw; \
156 sw = ((GLbyte *)(pc))[1]; \
157 ((GLbyte *)(pc))[1] = ((GLbyte *)(pc))[2]; \
158 ((GLbyte *)(pc))[2] = sw;
160 #define __GLX_SWAP_SHORT(pc) \
161 sw = ((GLbyte *)(pc))[0]; \
162 ((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[1]; \
163 ((GLbyte *)(pc))[1] = sw;
165 #define __GLX_SWAP_DOUBLE(pc) \
166 sw = ((GLbyte *)(pc))[0]; \
167 ((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[7]; \
168 ((GLbyte *)(pc))[7] = sw; \
169 sw = ((GLbyte *)(pc))[1]; \
170 ((GLbyte *)(pc))[1] = ((GLbyte *)(pc))[6]; \
171 ((GLbyte *)(pc))[6] = sw; \
172 sw = ((GLbyte *)(pc))[2]; \
173 ((GLbyte *)(pc))[2] = ((GLbyte *)(pc))[5]; \
174 ((GLbyte *)(pc))[5] = sw; \
175 sw = ((GLbyte *)(pc))[3]; \
176 ((GLbyte *)(pc))[3] = ((GLbyte *)(pc))[4]; \
177 ((GLbyte *)(pc))[4] = sw;
179 #define __GLX_SWAP_FLOAT(pc) \
180 sw = ((GLbyte *)(pc))[0]; \
181 ((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[3]; \
182 ((GLbyte *)(pc))[3] = sw; \
183 sw = ((GLbyte *)(pc))[1]; \
184 ((GLbyte *)(pc))[1] = ((GLbyte *)(pc))[2]; \
185 ((GLbyte *)(pc))[2] = sw;
187 #define __GLX_SWAP_INT_ARRAY(pc, count) \
188 swapPC = ((GLbyte *)(pc)); \
189 swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_INT32;\
190 while (swapPC < swapEnd) { \
191 __GLX_SWAP_INT(swapPC); \
192 swapPC += __GLX_SIZE_INT32; \
195 #define __GLX_SWAP_SHORT_ARRAY(pc, count) \
196 swapPC = ((GLbyte *)(pc)); \
197 swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_INT16;\
198 while (swapPC < swapEnd) { \
199 __GLX_SWAP_SHORT(swapPC); \
200 swapPC += __GLX_SIZE_INT16; \
203 #define __GLX_SWAP_DOUBLE_ARRAY(pc, count) \
204 swapPC = ((GLbyte *)(pc)); \
205 swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_FLOAT64;\
206 while (swapPC < swapEnd) { \
207 __GLX_SWAP_DOUBLE(swapPC); \
208 swapPC += __GLX_SIZE_FLOAT64; \
211 #define __GLX_SWAP_FLOAT_ARRAY(pc, count) \
212 swapPC = ((GLbyte *)(pc)); \
213 swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_FLOAT32;\
214 while (swapPC < swapEnd) { \
215 __GLX_SWAP_FLOAT(swapPC); \
216 swapPC += __GLX_SIZE_FLOAT32; \
219 #define __GLX_SWAP_REPLY_HEADER() \
220 __GLX_SWAP_SHORT(&__glXReply.sequenceNumber); \
221 __GLX_SWAP_INT(&__glXReply.length);
223 #define __GLX_SWAP_REPLY_RETVAL() \
224 __GLX_SWAP_INT(&__glXReply.retval)
226 #define __GLX_SWAP_REPLY_SIZE() \
227 __GLX_SWAP_INT(&__glXReply.size)
229 #endif /* !__GLX_unpack_h__ */