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
56extern void __glXMemInit(void);
57
58extern 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, (char *)&__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 < 0) return BadLength;                                      \
87    else if ((size) > sizeof(answerBuffer)) {				 \
88	int bump;							 \
89	if ((cl)->returnBufSize < (size)+(align)) {			 \
90	    (cl)->returnBuf = (GLbyte*)realloc((cl)->returnBuf,	 	 \
91						(size)+(align));         \
92	    if (!(cl)->returnBuf) {					 \
93		return BadAlloc;					 \
94	    }								 \
95	    (cl)->returnBufSize = (size)+(align);			 \
96	}								 \
97	res = (char*)cl->returnBuf;					 \
98	bump = (long)(res) % (align);					 \
99	if (bump) res += (align) - (bump);				 \
100    } else {								 \
101	res = (char *)answerBuffer;					 \
102    }
103
104#define __GLX_PUT_BYTE() \
105  	*(GLbyte *)&__glXReply.pad3 = *(GLbyte *)answer
106
107#define __GLX_PUT_SHORT() \
108  	*(GLshort *)&__glXReply.pad3 = *(GLshort *)answer
109
110#define __GLX_PUT_INT() \
111  	*(GLint *)&__glXReply.pad3 = *(GLint *)answer
112
113#define __GLX_PUT_FLOAT() \
114  	*(GLfloat *)&__glXReply.pad3 = *(GLfloat *)answer
115
116#define __GLX_PUT_DOUBLE() \
117  	*(GLdouble *)&__glXReply.pad3 = *(GLdouble *)answer
118
119#define __GLX_SEND_BYTE_ARRAY(len) \
120	WriteToClient(client, __GLX_PAD((len)*__GLX_SIZE_INT8), (char *)answer)
121
122#define __GLX_SEND_SHORT_ARRAY(len) \
123	WriteToClient(client, __GLX_PAD((len)*__GLX_SIZE_INT16), (char *)answer)
124
125#define __GLX_SEND_INT_ARRAY(len) \
126	WriteToClient(client, (len)*__GLX_SIZE_INT32, (char *)answer)
127
128#define __GLX_SEND_FLOAT_ARRAY(len) \
129	WriteToClient(client, (len)*__GLX_SIZE_FLOAT32, (char *)answer)
130
131#define __GLX_SEND_DOUBLE_ARRAY(len) \
132	WriteToClient(client, (len)*__GLX_SIZE_FLOAT64, (char *)answer)
133
134
135#define __GLX_SEND_VOID_ARRAY(len)  __GLX_SEND_BYTE_ARRAY(len)
136#define __GLX_SEND_UBYTE_ARRAY(len)  __GLX_SEND_BYTE_ARRAY(len)
137#define __GLX_SEND_USHORT_ARRAY(len) __GLX_SEND_SHORT_ARRAY(len)
138#define __GLX_SEND_UINT_ARRAY(len)  __GLX_SEND_INT_ARRAY(len)
139
140/*
141** PERFORMANCE NOTE:
142** Machine dependent optimizations abound here; these swapping macros can
143** conceivably be replaced with routines that do the job faster.
144*/
145#define __GLX_DECLARE_SWAP_VARIABLES \
146	GLbyte sw
147
148#define __GLX_DECLARE_SWAP_ARRAY_VARIABLES \
149  	GLbyte *swapPC;		\
150  	GLbyte *swapEnd
151
152
153#define __GLX_SWAP_INT(pc) 			\
154  	sw = ((GLbyte *)(pc))[0]; 		\
155  	((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[3]; 	\
156  	((GLbyte *)(pc))[3] = sw; 		\
157  	sw = ((GLbyte *)(pc))[1]; 		\
158  	((GLbyte *)(pc))[1] = ((GLbyte *)(pc))[2]; 	\
159  	((GLbyte *)(pc))[2] = sw;
160
161#define __GLX_SWAP_SHORT(pc) \
162  	sw = ((GLbyte *)(pc))[0]; 		\
163  	((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[1]; 	\
164  	((GLbyte *)(pc))[1] = sw;
165
166#define __GLX_SWAP_DOUBLE(pc) \
167  	sw = ((GLbyte *)(pc))[0]; 		\
168  	((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[7]; 	\
169  	((GLbyte *)(pc))[7] = sw; 		\
170  	sw = ((GLbyte *)(pc))[1]; 		\
171  	((GLbyte *)(pc))[1] = ((GLbyte *)(pc))[6]; 	\
172  	((GLbyte *)(pc))[6] = sw;			\
173  	sw = ((GLbyte *)(pc))[2]; 		\
174  	((GLbyte *)(pc))[2] = ((GLbyte *)(pc))[5]; 	\
175  	((GLbyte *)(pc))[5] = sw;			\
176  	sw = ((GLbyte *)(pc))[3]; 		\
177  	((GLbyte *)(pc))[3] = ((GLbyte *)(pc))[4]; 	\
178  	((GLbyte *)(pc))[4] = sw;
179
180#define __GLX_SWAP_FLOAT(pc) \
181  	sw = ((GLbyte *)(pc))[0]; 		\
182  	((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[3]; 	\
183  	((GLbyte *)(pc))[3] = sw; 		\
184  	sw = ((GLbyte *)(pc))[1]; 		\
185  	((GLbyte *)(pc))[1] = ((GLbyte *)(pc))[2]; 	\
186  	((GLbyte *)(pc))[2] = sw;
187
188#define __GLX_SWAP_INT_ARRAY(pc, count) \
189  	swapPC = ((GLbyte *)(pc));		\
190  	swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_INT32;\
191  	while (swapPC < swapEnd) {		\
192	    __GLX_SWAP_INT(swapPC);		\
193	    swapPC += __GLX_SIZE_INT32;		\
194	}
195
196#define __GLX_SWAP_SHORT_ARRAY(pc, count) \
197  	swapPC = ((GLbyte *)(pc));		\
198  	swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_INT16;\
199  	while (swapPC < swapEnd) {		\
200	    __GLX_SWAP_SHORT(swapPC);		\
201	    swapPC += __GLX_SIZE_INT16;		\
202	}
203
204#define __GLX_SWAP_DOUBLE_ARRAY(pc, count) \
205  	swapPC = ((GLbyte *)(pc));		\
206  	swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_FLOAT64;\
207  	while (swapPC < swapEnd) {		\
208	    __GLX_SWAP_DOUBLE(swapPC);		\
209	    swapPC += __GLX_SIZE_FLOAT64;	\
210	}
211
212#define __GLX_SWAP_FLOAT_ARRAY(pc, count) \
213  	swapPC = ((GLbyte *)(pc));		\
214  	swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_FLOAT32;\
215  	while (swapPC < swapEnd) {		\
216	    __GLX_SWAP_FLOAT(swapPC);		\
217	    swapPC += __GLX_SIZE_FLOAT32;	\
218	}
219
220#define __GLX_SWAP_REPLY_HEADER() \
221  	__GLX_SWAP_SHORT(&__glXReply.sequenceNumber); \
222  	__GLX_SWAP_INT(&__glXReply.length);
223
224#define __GLX_SWAP_REPLY_RETVAL() \
225  	__GLX_SWAP_INT(&__glXReply.retval)
226
227#define __GLX_SWAP_REPLY_SIZE() \
228  	__GLX_SWAP_INT(&__glXReply.size)
229
230#endif /* !__GLX_unpack_h__ */
231
232
233
234
235
236