remove the XFree86 ID line
[mesa.git] / src / mesa / drivers / dri / common / spantmp.h
1 /*
2 * Copyright 2000-2001 VA Linux Systems, Inc.
3 * (C) Copyright IBM Corporation 2002, 2003
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * on the rights to use, copy, modify, merge, publish, distribute, sub
10 * license, and/or sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 * Authors:
26 * Keith Whitwell <keithw@tungstengraphics.com>
27 * Gareth Hughes <gareth@nvidia.com>
28 */
29
30 #ifndef DBG
31 #define DBG 0
32 #endif
33
34 #ifndef HW_WRITE_LOCK
35 #define HW_WRITE_LOCK() HW_LOCK()
36 #endif
37
38 #ifndef HW_WRITE_UNLOCK
39 #define HW_WRITE_UNLOCK() HW_UNLOCK()
40 #endif
41
42 #ifndef HW_READ_LOCK
43 #define HW_READ_LOCK() HW_LOCK()
44 #endif
45
46 #ifndef HW_READ_UNLOCK
47 #define HW_READ_UNLOCK() HW_UNLOCK()
48 #endif
49
50 #ifndef HW_READ_CLIPLOOP
51 #define HW_READ_CLIPLOOP() HW_CLIPLOOP()
52 #endif
53
54 #ifndef HW_WRITE_CLIPLOOP
55 #define HW_WRITE_CLIPLOOP() HW_CLIPLOOP()
56 #endif
57
58
59 static void TAG(WriteRGBASpan)( GLcontext *ctx,
60 struct gl_renderbuffer *rb,
61 GLuint n, GLint x, GLint y,
62 const void *values, const GLubyte mask[] )
63 {
64 HW_WRITE_LOCK()
65 {
66 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
67 GLint x1;
68 GLint n1;
69 LOCAL_VARS;
70
71 y = Y_FLIP(y);
72
73 HW_WRITE_CLIPLOOP()
74 {
75 GLint i = 0;
76 CLIPSPAN(x,y,n,x1,n1,i);
77
78 if (DBG) fprintf(stderr, "WriteRGBASpan %d..%d (x1 %d)\n",
79 (int)i, (int)n1, (int)x1);
80
81 if (mask)
82 {
83 for (;n1>0;i++,x1++,n1--)
84 if (mask[i])
85 WRITE_RGBA( x1, y,
86 rgba[i][0], rgba[i][1],
87 rgba[i][2], rgba[i][3] );
88 }
89 else
90 {
91 for (;n1>0;i++,x1++,n1--)
92 WRITE_RGBA( x1, y,
93 rgba[i][0], rgba[i][1],
94 rgba[i][2], rgba[i][3] );
95 }
96 }
97 HW_ENDCLIPLOOP();
98 }
99 HW_WRITE_UNLOCK();
100 }
101
102 static void TAG(WriteRGBSpan)( GLcontext *ctx,
103 struct gl_renderbuffer *rb,
104 GLuint n, GLint x, GLint y,
105 const void *values, const GLubyte mask[] )
106 {
107 HW_WRITE_LOCK()
108 {
109 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
110 GLint x1;
111 GLint n1;
112 LOCAL_VARS;
113
114 y = Y_FLIP(y);
115
116 HW_WRITE_CLIPLOOP()
117 {
118 GLint i = 0;
119 CLIPSPAN(x,y,n,x1,n1,i);
120
121 if (DBG) fprintf(stderr, "WriteRGBSpan %d..%d (x1 %d)\n",
122 (int)i, (int)n1, (int)x1);
123
124 if (mask)
125 {
126 for (;n1>0;i++,x1++,n1--)
127 if (mask[i])
128 WRITE_RGBA( x1, y, rgb[i][0], rgb[i][1], rgb[i][2], 255 );
129 }
130 else
131 {
132 for (;n1>0;i++,x1++,n1--)
133 WRITE_RGBA( x1, y, rgb[i][0], rgb[i][1], rgb[i][2], 255 );
134 }
135 }
136 HW_ENDCLIPLOOP();
137 }
138 HW_WRITE_UNLOCK();
139 }
140
141 static void TAG(WriteRGBAPixels)( GLcontext *ctx,
142 struct gl_renderbuffer *rb,
143 GLuint n, const GLint x[], const GLint y[],
144 const void *values, const GLubyte mask[] )
145 {
146 HW_WRITE_LOCK()
147 {
148 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
149 GLuint i;
150 LOCAL_VARS;
151
152 if (DBG) fprintf(stderr, "WriteRGBAPixels\n");
153
154 HW_WRITE_CLIPLOOP()
155 {
156 if (mask)
157 {
158 for (i=0;i<n;i++)
159 {
160 if (mask[i]) {
161 const int fy = Y_FLIP(y[i]);
162 if (CLIPPIXEL(x[i],fy))
163 WRITE_RGBA( x[i], fy,
164 rgba[i][0], rgba[i][1],
165 rgba[i][2], rgba[i][3] );
166 }
167 }
168 }
169 else
170 {
171 for (i=0;i<n;i++)
172 {
173 const int fy = Y_FLIP(y[i]);
174 if (CLIPPIXEL(x[i],fy))
175 WRITE_RGBA( x[i], fy,
176 rgba[i][0], rgba[i][1],
177 rgba[i][2], rgba[i][3] );
178 }
179 }
180 }
181 HW_ENDCLIPLOOP();
182 }
183 HW_WRITE_UNLOCK();
184 }
185
186
187 static void TAG(WriteMonoRGBASpan)( GLcontext *ctx,
188 struct gl_renderbuffer *rb,
189 GLuint n, GLint x, GLint y,
190 const void *value,
191 const GLubyte mask[] )
192 {
193 HW_WRITE_LOCK()
194 {
195 const GLubyte *color = (const GLubyte *) value;
196 GLint x1;
197 GLint n1;
198 LOCAL_VARS;
199 INIT_MONO_PIXEL(p, color);
200
201 y = Y_FLIP( y );
202
203 if (DBG) fprintf(stderr, "WriteMonoRGBASpan\n");
204
205 HW_WRITE_CLIPLOOP()
206 {
207 GLint i = 0;
208 CLIPSPAN(x,y,n,x1,n1,i);
209 if (mask)
210 {
211 for (;n1>0;i++,x1++,n1--)
212 if (mask[i])
213 WRITE_PIXEL( x1, y, p );
214 }
215 else
216 {
217 for (;n1>0;i++,x1++,n1--)
218 WRITE_PIXEL( x1, y, p );
219 }
220 }
221 HW_ENDCLIPLOOP();
222 }
223 HW_WRITE_UNLOCK();
224 }
225
226
227 static void TAG(WriteMonoRGBAPixels)( GLcontext *ctx,
228 struct gl_renderbuffer *rb,
229 GLuint n,
230 const GLint x[], const GLint y[],
231 const void *value,
232 const GLubyte mask[] )
233 {
234 HW_WRITE_LOCK()
235 {
236 const GLubyte *color = (const GLubyte *) value;
237 GLuint i;
238 LOCAL_VARS;
239 INIT_MONO_PIXEL(p, color);
240
241 if (DBG) fprintf(stderr, "WriteMonoRGBAPixels\n");
242
243 HW_WRITE_CLIPLOOP()
244 {
245 if (mask)
246 {
247 for (i=0;i<n;i++)
248 if (mask[i]) {
249 int fy = Y_FLIP(y[i]);
250 if (CLIPPIXEL( x[i], fy ))
251 WRITE_PIXEL( x[i], fy, p );
252 }
253 }
254 else
255 {
256 for (i=0;i<n;i++) {
257 int fy = Y_FLIP(y[i]);
258 if (CLIPPIXEL( x[i], fy ))
259 WRITE_PIXEL( x[i], fy, p );
260 }
261 }
262 }
263 HW_ENDCLIPLOOP();
264 }
265 HW_WRITE_UNLOCK();
266 }
267
268
269 static void TAG(ReadRGBASpan)( GLcontext *ctx,
270 struct gl_renderbuffer *rb,
271 GLuint n, GLint x, GLint y,
272 void *values)
273 {
274 HW_READ_LOCK()
275 {
276 GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
277 GLint x1,n1;
278 LOCAL_VARS;
279
280 y = Y_FLIP(y);
281
282 if (DBG) fprintf(stderr, "ReadRGBASpan\n");
283
284 HW_READ_CLIPLOOP()
285 {
286 GLint i = 0;
287 CLIPSPAN(x,y,n,x1,n1,i);
288 for (;n1>0;i++,x1++,n1--)
289 READ_RGBA( rgba[i], x1, y );
290 }
291 HW_ENDCLIPLOOP();
292 }
293 HW_READ_UNLOCK();
294 }
295
296
297 static void TAG(ReadRGBAPixels)( GLcontext *ctx,
298 struct gl_renderbuffer *rb,
299 GLuint n, const GLint x[], const GLint y[],
300 void *values )
301 {
302 HW_READ_LOCK()
303 {
304 GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
305 const GLubyte *mask = NULL; /* remove someday */
306 GLuint i;
307 LOCAL_VARS;
308
309 if (DBG) fprintf(stderr, "ReadRGBAPixels\n");
310
311 HW_READ_CLIPLOOP()
312 {
313 if (mask)
314 {
315 for (i=0;i<n;i++)
316 if (mask[i]) {
317 int fy = Y_FLIP( y[i] );
318 if (CLIPPIXEL( x[i], fy ))
319 READ_RGBA( rgba[i], x[i], fy );
320 }
321 }
322 else
323 {
324 for (i=0;i<n;i++) {
325 int fy = Y_FLIP( y[i] );
326 if (CLIPPIXEL( x[i], fy ))
327 READ_RGBA( rgba[i], x[i], fy );
328 }
329 }
330 }
331 HW_ENDCLIPLOOP();
332 }
333 HW_READ_UNLOCK();
334 }
335
336
337
338
339 #undef WRITE_PIXEL
340 #undef WRITE_RGBA
341 #undef READ_RGBA
342 #undef TAG