gallium: fix refcount bug introduced in eb20e2984
[mesa.git] / src / glx / x11 / packrender.h
1 #ifndef __GLX_packrender_h__
2 #define __GLX_packrender_h__
3
4 /*
5 ** License Applicability. Except to the extent portions of this file are
6 ** made subject to an alternative license as permitted in the SGI Free
7 ** Software License B, Version 1.1 (the "License"), the contents of this
8 ** file are subject only to the provisions of the License. You may not use
9 ** this file except in compliance with the License. You may obtain a copy
10 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
11 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
12 **
13 ** http://oss.sgi.com/projects/FreeB
14 **
15 ** Note that, as provided in the License, the Software is distributed on an
16 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
17 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
18 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
19 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
20 **
21 ** Original Code. The Original Code is: OpenGL Sample Implementation,
22 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
23 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
24 ** Copyright in any portions created by third parties is as indicated
25 ** elsewhere herein. All Rights Reserved.
26 **
27 ** Additional Notice Provisions: The application programming interfaces
28 ** established by SGI in conjunction with the Original Code are The
29 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
30 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
31 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
32 ** Window System(R) (Version 1.3), released October 19, 1998. This software
33 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
34 ** published by SGI, but has not been independently verified as being
35 ** compliant with the OpenGL(R) version 1.2.1 Specification.
36 **
37 */
38
39 #include "glxclient.h"
40
41 /*
42 ** The macros in this header convert the client machine's native data types to
43 ** wire protocol data types. The header is part of the porting layer of the
44 ** client library, and it is intended that hardware vendors will rewrite this
45 ** header to suit their own machines.
46 */
47
48 /*
49 ** Pad a count of bytes to the nearest multiple of 4. The X protocol
50 ** transfers data in 4 byte quantities, so this macro is used to
51 ** insure the right amount of data being sent.
52 */
53 #define __GLX_PAD(a) (((a)+3) & ~3)
54
55 /*
56 ** Network size parameters
57 */
58 #define sz_double 8
59
60 /* Setup for all commands */
61 #define __GLX_DECLARE_VARIABLES() \
62 __GLXcontext *gc; \
63 GLubyte *pc, *pixelHeaderPC; \
64 GLuint compsize, cmdlen
65
66 #define __GLX_LOAD_VARIABLES() \
67 gc = __glXGetCurrentContext(); \
68 pc = gc->pc; \
69 /* Muffle compilers */ \
70 cmdlen = 0; (void)cmdlen; \
71 compsize = 0; (void)compsize; \
72 pixelHeaderPC = 0; (void)pixelHeaderPC
73
74 /*
75 ** Variable sized command support macro. This macro is used by calls
76 ** that are potentially larger than __GLX_SMALL_RENDER_CMD_SIZE.
77 ** Because of their size, they may not automatically fit in the buffer.
78 ** If the buffer can't hold the command then it is flushed so that
79 ** the command will fit in the next buffer.
80 */
81 #define __GLX_BEGIN_VARIABLE(opcode,size) \
82 if (pc + (size) > gc->bufEnd) { \
83 pc = __glXFlushRenderBuffer(gc, pc); \
84 } \
85 __GLX_PUT_SHORT(0,size); \
86 __GLX_PUT_SHORT(2,opcode)
87
88 #define __GLX_BEGIN_VARIABLE_LARGE(opcode,size) \
89 pc = __glXFlushRenderBuffer(gc, pc); \
90 __GLX_PUT_LONG(0,size); \
91 __GLX_PUT_LONG(4,opcode)
92
93 #define __GLX_BEGIN_VARIABLE_WITH_PIXEL(opcode,size) \
94 if (pc + (size) > gc->bufEnd) { \
95 pc = __glXFlushRenderBuffer(gc, pc); \
96 } \
97 __GLX_PUT_SHORT(0,size); \
98 __GLX_PUT_SHORT(2,opcode); \
99 pc += __GLX_RENDER_HDR_SIZE; \
100 pixelHeaderPC = pc; \
101 pc += __GLX_PIXEL_HDR_SIZE
102
103 #define __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(opcode,size) \
104 pc = __glXFlushRenderBuffer(gc, pc); \
105 __GLX_PUT_LONG(0,size); \
106 __GLX_PUT_LONG(4,opcode); \
107 pc += __GLX_RENDER_LARGE_HDR_SIZE; \
108 pixelHeaderPC = pc; \
109 pc += __GLX_PIXEL_HDR_SIZE
110
111 #define __GLX_BEGIN_VARIABLE_WITH_PIXEL_3D(opcode,size) \
112 if (pc + (size) > gc->bufEnd) { \
113 pc = __glXFlushRenderBuffer(gc, pc); \
114 } \
115 __GLX_PUT_SHORT(0,size); \
116 __GLX_PUT_SHORT(2,opcode); \
117 pc += __GLX_RENDER_HDR_SIZE; \
118 pixelHeaderPC = pc; \
119 pc += __GLX_PIXEL_3D_HDR_SIZE
120
121 #define __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL_3D(opcode,size) \
122 pc = __glXFlushRenderBuffer(gc, pc); \
123 __GLX_PUT_LONG(0,size); \
124 __GLX_PUT_LONG(4,opcode); \
125 pc += __GLX_RENDER_LARGE_HDR_SIZE; \
126 pixelHeaderPC = pc; \
127 pc += __GLX_PIXEL_3D_HDR_SIZE
128
129 /*
130 ** Fixed size command support macro. This macro is used by calls that
131 ** are never larger than __GLX_SMALL_RENDER_CMD_SIZE. Because they
132 ** always fit in the buffer, and because the buffer promises to
133 ** maintain enough room for them, we don't need to check for space
134 ** before doing the storage work.
135 */
136 #define __GLX_BEGIN(opcode,size) \
137 __GLX_PUT_SHORT(0,size); \
138 __GLX_PUT_SHORT(2,opcode)
139
140 /*
141 ** Finish a rendering command by advancing the pc. If the pc is now past
142 ** the limit pointer then there is no longer room for a
143 ** __GLX_SMALL_RENDER_CMD_SIZE sized command, which will break the
144 ** assumptions present in the __GLX_BEGIN macro. In this case the
145 ** rendering buffer is flushed out into the X protocol stream (which may
146 ** or may not do I/O).
147 */
148 #define __GLX_END(size) \
149 pc += size; \
150 if (pc > gc->limit) { \
151 (void) __glXFlushRenderBuffer(gc, pc); \
152 } else { \
153 gc->pc = pc; \
154 }
155
156 /* Array copy macros */
157 #define __GLX_MEM_COPY(dest,src,bytes) \
158 if (src && dest) \
159 memcpy(dest, src, bytes)
160
161 /* Single item copy macros */
162 #define __GLX_PUT_CHAR(offset,a) \
163 *((INT8 *) (pc + offset)) = a
164
165 #ifndef _CRAY
166 #define __GLX_PUT_SHORT(offset,a) \
167 *((INT16 *) (pc + offset)) = a
168
169 #define __GLX_PUT_LONG(offset,a) \
170 *((INT32 *) (pc + offset)) = a
171
172 #define __GLX_PUT_FLOAT(offset,a) \
173 *((FLOAT32 *) (pc + offset)) = a
174
175 #else
176 #define __GLX_PUT_SHORT(offset,a) \
177 { GLubyte *cp = (pc+offset); \
178 int shift = (64-16) - ((int)(cp) >> (64-6)); \
179 *(int *)cp = (*(int *)cp & ~(0xffff << shift)) | ((a & 0xffff) << shift); }
180
181 #define __GLX_PUT_LONG(offset,a) \
182 { GLubyte *cp = (pc+offset); \
183 int shift = (64-32) - ((int)(cp) >> (64-6)); \
184 *(int *)cp = (*(int *)cp & ~(0xffffffff << shift)) | ((a & 0xffffffff) << shift); }
185
186 #define __GLX_PUT_FLOAT(offset,a) \
187 gl_put_float((pc + offset),a)
188
189 #define __GLX_PUT_DOUBLE(offset,a) \
190 gl_put_double(pc + offset, a)
191
192 extern void gl_put_float(/*GLubyte *, struct cray_single*/);
193 extern void gl_put_double(/*GLubyte *, struct cray_double*/);
194 #endif
195
196 #ifndef _CRAY
197
198 #ifdef __GLX_ALIGN64
199 /*
200 ** This can certainly be done better for a particular machine
201 ** architecture!
202 */
203 #define __GLX_PUT_DOUBLE(offset,a) \
204 __GLX_MEM_COPY(pc + offset, &a, 8)
205 #else
206 #define __GLX_PUT_DOUBLE(offset,a) \
207 *((FLOAT64 *) (pc + offset)) = a
208 #endif
209
210 #endif
211
212 #define __GLX_PUT_CHAR_ARRAY(offset,a,alen) \
213 __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_INT8)
214
215 #ifndef _CRAY
216 #define __GLX_PUT_SHORT_ARRAY(offset,a,alen) \
217 __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_INT16)
218
219 #define __GLX_PUT_LONG_ARRAY(offset,a,alen) \
220 __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_INT32)
221
222 #define __GLX_PUT_FLOAT_ARRAY(offset,a,alen) \
223 __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_FLOAT32)
224
225 #define __GLX_PUT_DOUBLE_ARRAY(offset,a,alen) \
226 __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_FLOAT64)
227
228 #else
229 #define __GLX_PUT_SHORT_ARRAY(offset,a,alen) \
230 gl_put_short_array((GLubyte *)(pc + offset), a, alen * __GLX_SIZE_INT16)
231
232 #define __GLX_PUT_LONG_ARRAY(offset,a,alen) \
233 gl_put_long_array((GLubyte *)(pc + offset), (long *)a, alen * __GLX_SIZE_INT32)
234
235 #define __GLX_PUT_FLOAT_ARRAY(offset,a,alen) \
236 gl_put_float_array((GLubyte *)(pc + offset), (float *)a, alen * __GLX_SIZE_FLOAT32)
237
238 #define __GLX_PUT_DOUBLE_ARRAY(offset,a,alen) \
239 gl_put_double_array((GLubyte *)(pc + offset), (double *)a, alen * __GLX_SIZE_FLOAT64)
240
241 extern gl_put_short_array (GLubyte *, short *, int);
242 extern gl_put_long_array (GLubyte *, long *, int);
243 extern gl_put_float_array (GLubyte *, float *, int);
244 extern gl_put_double_array (GLubyte *, double *, int);
245
246 #endif /* _CRAY */
247
248 #endif /* !__GLX_packrender_h__ */