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) memmove(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, &__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), answer)
121 #define __GLX_SEND_SHORT_ARRAY(len) \
122 WriteToClient(client, __GLX_PAD((len)*__GLX_SIZE_INT16), answer)
124 #define __GLX_SEND_INT_ARRAY(len) \
125 WriteToClient(client, (len)*__GLX_SIZE_INT32, answer)
127 #define __GLX_SEND_FLOAT_ARRAY(len) \
128 WriteToClient(client, (len)*__GLX_SIZE_FLOAT32, answer)
130 #define __GLX_SEND_DOUBLE_ARRAY(len) \
131 WriteToClient(client, (len)*__GLX_SIZE_FLOAT64, answer)
133 #define __GLX_SEND_VOID_ARRAY(len) __GLX_SEND_BYTE_ARRAY(len)
134 #define __GLX_SEND_UBYTE_ARRAY(len) __GLX_SEND_BYTE_ARRAY(len)
135 #define __GLX_SEND_USHORT_ARRAY(len) __GLX_SEND_SHORT_ARRAY(len)
136 #define __GLX_SEND_UINT_ARRAY(len) __GLX_SEND_INT_ARRAY(len)
140 ** Machine dependent optimizations abound here; these swapping macros can
141 ** conceivably be replaced with routines that do the job faster.
143 #define __GLX_DECLARE_SWAP_VARIABLES \
146 #define __GLX_DECLARE_SWAP_ARRAY_VARIABLES \
150 #define __GLX_SWAP_INT(pc) \
151 sw = ((GLbyte *)(pc))[0]; \
152 ((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[3]; \
153 ((GLbyte *)(pc))[3] = sw; \
154 sw = ((GLbyte *)(pc))[1]; \
155 ((GLbyte *)(pc))[1] = ((GLbyte *)(pc))[2]; \
156 ((GLbyte *)(pc))[2] = sw;
158 #define __GLX_SWAP_SHORT(pc) \
159 sw = ((GLbyte *)(pc))[0]; \
160 ((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[1]; \
161 ((GLbyte *)(pc))[1] = sw;
163 #define __GLX_SWAP_DOUBLE(pc) \
164 sw = ((GLbyte *)(pc))[0]; \
165 ((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[7]; \
166 ((GLbyte *)(pc))[7] = sw; \
167 sw = ((GLbyte *)(pc))[1]; \
168 ((GLbyte *)(pc))[1] = ((GLbyte *)(pc))[6]; \
169 ((GLbyte *)(pc))[6] = sw; \
170 sw = ((GLbyte *)(pc))[2]; \
171 ((GLbyte *)(pc))[2] = ((GLbyte *)(pc))[5]; \
172 ((GLbyte *)(pc))[5] = sw; \
173 sw = ((GLbyte *)(pc))[3]; \
174 ((GLbyte *)(pc))[3] = ((GLbyte *)(pc))[4]; \
175 ((GLbyte *)(pc))[4] = sw;
177 #define __GLX_SWAP_FLOAT(pc) \
178 sw = ((GLbyte *)(pc))[0]; \
179 ((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[3]; \
180 ((GLbyte *)(pc))[3] = sw; \
181 sw = ((GLbyte *)(pc))[1]; \
182 ((GLbyte *)(pc))[1] = ((GLbyte *)(pc))[2]; \
183 ((GLbyte *)(pc))[2] = sw;
185 #define __GLX_SWAP_INT_ARRAY(pc, count) \
186 swapPC = ((GLbyte *)(pc)); \
187 swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_INT32;\
188 while (swapPC < swapEnd) { \
189 __GLX_SWAP_INT(swapPC); \
190 swapPC += __GLX_SIZE_INT32; \
193 #define __GLX_SWAP_SHORT_ARRAY(pc, count) \
194 swapPC = ((GLbyte *)(pc)); \
195 swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_INT16;\
196 while (swapPC < swapEnd) { \
197 __GLX_SWAP_SHORT(swapPC); \
198 swapPC += __GLX_SIZE_INT16; \
201 #define __GLX_SWAP_DOUBLE_ARRAY(pc, count) \
202 swapPC = ((GLbyte *)(pc)); \
203 swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_FLOAT64;\
204 while (swapPC < swapEnd) { \
205 __GLX_SWAP_DOUBLE(swapPC); \
206 swapPC += __GLX_SIZE_FLOAT64; \
209 #define __GLX_SWAP_FLOAT_ARRAY(pc, count) \
210 swapPC = ((GLbyte *)(pc)); \
211 swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_FLOAT32;\
212 while (swapPC < swapEnd) { \
213 __GLX_SWAP_FLOAT(swapPC); \
214 swapPC += __GLX_SIZE_FLOAT32; \
217 #define __GLX_SWAP_REPLY_HEADER() \
218 __GLX_SWAP_SHORT(&__glXReply.sequenceNumber); \
219 __GLX_SWAP_INT(&__glXReply.length);
221 #define __GLX_SWAP_REPLY_RETVAL() \
222 __GLX_SWAP_INT(&__glXReply.retval)
224 #define __GLX_SWAP_REPLY_SIZE() \
225 __GLX_SWAP_INT(&__glXReply.size)
227 #endif /* !__GLX_unpack_h__ */