Imported Upstream version 1.15.1
[deb_xorg-server.git] / glx / unpack.h
1 #ifdef HAVE_DIX_CONFIG_H
2 #include <dix-config.h>
3 #endif
4
5 #ifndef __GLX_unpack_h__
6 #define __GLX_unpack_h__
7
8 /*
9 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
10 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
11 *
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:
18 *
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.
23 *
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
30 * SOFTWARE.
31 *
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.
36 */
37
38 #define __GLX_PAD(s) (((s)+3) & (GLuint)~3)
39
40 /*
41 ** Fetch the context-id out of a SingleReq request pointed to by pc.
42 */
43 #define __GLX_GET_SINGLE_CONTEXT_TAG(pc) (((xGLXSingleReq*)pc)->contextTag)
44 #define __GLX_GET_VENDPRIV_CONTEXT_TAG(pc) (((xGLXVendorPrivateReq*)pc)->contextTag)
45
46 /*
47 ** Fetch a double from potentially unaligned memory.
48 */
49 #ifdef __GLX_ALIGN64
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)
52 #else
53 #define __GLX_GET_DOUBLE(dst,src) (dst) = *((GLdouble*)(src))
54 #endif
55
56 extern void __glXMemInit(void);
57
58 extern xGLXSingleReply __glXReply;
59
60 #define __GLX_BEGIN_REPLY(size) \
61 __glXReply.length = __GLX_PAD(size) >> 2; \
62 __glXReply.type = X_Reply; \
63 __glXReply.sequenceNumber = client->sequence;
64
65 #define __GLX_SEND_HEADER() \
66 WriteToClient (client, sz_xGLXSingleReply, &__glXReply);
67
68 #define __GLX_PUT_RETVAL(a) \
69 __glXReply.retval = (a);
70
71 #define __GLX_PUT_SIZE(a) \
72 __glXReply.size = (a);
73
74 #define __GLX_PUT_RENDERMODE(m) \
75 __glXReply.pad3 = (m)
76
77 /*
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.
81 **
82 ** NOTE: the cast (long)res below assumes a long is large enough to hold a
83 ** pointer.
84 */
85 #define __GLX_GET_ANSWER_BUFFER(res,cl,size,align) \
86 if ((size) > sizeof(answerBuffer)) { \
87 int bump; \
88 if ((cl)->returnBufSize < (size)+(align)) { \
89 (cl)->returnBuf = (GLbyte*)realloc((cl)->returnBuf, \
90 (size)+(align)); \
91 if (!(cl)->returnBuf) { \
92 return BadAlloc; \
93 } \
94 (cl)->returnBufSize = (size)+(align); \
95 } \
96 res = (char*)cl->returnBuf; \
97 bump = (long)(res) % (align); \
98 if (bump) res += (align) - (bump); \
99 } else { \
100 res = (char *)answerBuffer; \
101 }
102
103 #define __GLX_PUT_BYTE() \
104 *(GLbyte *)&__glXReply.pad3 = *(GLbyte *)answer
105
106 #define __GLX_PUT_SHORT() \
107 *(GLshort *)&__glXReply.pad3 = *(GLshort *)answer
108
109 #define __GLX_PUT_INT() \
110 *(GLint *)&__glXReply.pad3 = *(GLint *)answer
111
112 #define __GLX_PUT_FLOAT() \
113 *(GLfloat *)&__glXReply.pad3 = *(GLfloat *)answer
114
115 #define __GLX_PUT_DOUBLE() \
116 *(GLdouble *)&__glXReply.pad3 = *(GLdouble *)answer
117
118 #define __GLX_SEND_BYTE_ARRAY(len) \
119 WriteToClient(client, __GLX_PAD((len)*__GLX_SIZE_INT8), answer)
120
121 #define __GLX_SEND_SHORT_ARRAY(len) \
122 WriteToClient(client, __GLX_PAD((len)*__GLX_SIZE_INT16), answer)
123
124 #define __GLX_SEND_INT_ARRAY(len) \
125 WriteToClient(client, (len)*__GLX_SIZE_INT32, answer)
126
127 #define __GLX_SEND_FLOAT_ARRAY(len) \
128 WriteToClient(client, (len)*__GLX_SIZE_FLOAT32, answer)
129
130 #define __GLX_SEND_DOUBLE_ARRAY(len) \
131 WriteToClient(client, (len)*__GLX_SIZE_FLOAT64, answer)
132
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)
137
138 /*
139 ** PERFORMANCE NOTE:
140 ** Machine dependent optimizations abound here; these swapping macros can
141 ** conceivably be replaced with routines that do the job faster.
142 */
143 #define __GLX_DECLARE_SWAP_VARIABLES \
144 GLbyte sw
145
146 #define __GLX_DECLARE_SWAP_ARRAY_VARIABLES \
147 GLbyte *swapPC; \
148 GLbyte *swapEnd
149
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;
157
158 #define __GLX_SWAP_SHORT(pc) \
159 sw = ((GLbyte *)(pc))[0]; \
160 ((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[1]; \
161 ((GLbyte *)(pc))[1] = sw;
162
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;
176
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;
184
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; \
191 }
192
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; \
199 }
200
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; \
207 }
208
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; \
215 }
216
217 #define __GLX_SWAP_REPLY_HEADER() \
218 __GLX_SWAP_SHORT(&__glXReply.sequenceNumber); \
219 __GLX_SWAP_INT(&__glXReply.length);
220
221 #define __GLX_SWAP_REPLY_RETVAL() \
222 __GLX_SWAP_INT(&__glXReply.retval)
223
224 #define __GLX_SWAP_REPLY_SIZE() \
225 __GLX_SWAP_INT(&__glXReply.size)
226
227 #endif /* !__GLX_unpack_h__ */