xlib: remove a ton of old xlib driver cruft
[mesa.git] / src / mesa / drivers / x11 / xm_span.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.3
4 *
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 #include "glxheader.h"
26 #include "main/context.h"
27 #include "main/macros.h"
28 #include "main/imports.h"
29 #include "main/mtypes.h"
30 #include "xmesaP.h"
31
32 #include "swrast/swrast.h"
33
34
35 /*
36 * The following functions are used to trap XGetImage() calls which
37 * generate BadMatch errors if the drawable isn't mapped.
38 */
39
40 static int caught_xgetimage_error = 0;
41 static int (*old_xerror_handler)( XMesaDisplay *dpy, XErrorEvent *ev );
42 static unsigned long xgetimage_serial;
43
44 /*
45 * This is the error handler which will be called if XGetImage fails.
46 */
47 static int xgetimage_error_handler( XMesaDisplay *dpy, XErrorEvent *ev )
48 {
49 if (ev->serial==xgetimage_serial && ev->error_code==BadMatch) {
50 /* caught the expected error */
51 caught_xgetimage_error = 0;
52 }
53 else {
54 /* call the original X error handler, if any. otherwise ignore */
55 if (old_xerror_handler) {
56 (*old_xerror_handler)( dpy, ev );
57 }
58 }
59 return 0;
60 }
61
62
63 /*
64 * Call this right before XGetImage to setup error trap.
65 */
66 static void catch_xgetimage_errors( XMesaDisplay *dpy )
67 {
68 xgetimage_serial = NextRequest( dpy );
69 old_xerror_handler = XSetErrorHandler( xgetimage_error_handler );
70 caught_xgetimage_error = 0;
71 }
72
73
74 /*
75 * Call this right after XGetImage to check if an error occured.
76 */
77 static int check_xgetimage_errors( void )
78 {
79 /* restore old handler */
80 (void) XSetErrorHandler( old_xerror_handler );
81 /* return 0=no error, 1=error caught */
82 return caught_xgetimage_error;
83 }
84
85
86 /*
87 * Read a pixel from an X drawable.
88 */
89 static unsigned long read_pixel( XMesaDisplay *dpy,
90 XMesaDrawable d, int x, int y )
91 {
92 unsigned long p;
93 XMesaImage *pixel = NULL;
94 int error;
95
96 catch_xgetimage_errors( dpy );
97 pixel = XGetImage( dpy, d, x, y, 1, 1, AllPlanes, ZPixmap );
98 error = check_xgetimage_errors();
99 if (pixel && !error) {
100 p = XMesaGetPixel( pixel, 0, 0 );
101 }
102 else {
103 p = 0;
104 }
105 if (pixel) {
106 XMesaDestroyImage( pixel );
107 }
108 return p;
109 }
110
111
112
113 /*
114 * The Mesa library needs to be able to draw pixels in a number of ways:
115 * 1. RGB vs Color Index
116 * 2. as horizontal spans (polygons, images) vs random locations (points,
117 * lines)
118 * 3. different color per-pixel or same color for all pixels
119 *
120 * Furthermore, the X driver needs to support rendering to 3 possible
121 * "buffers", usually one, but sometimes two at a time:
122 * 1. The front buffer as an X window
123 * 2. The back buffer as a Pixmap
124 * 3. The back buffer as an XImage
125 *
126 * Finally, if the back buffer is an XImage, we can avoid using XPutPixel and
127 * optimize common cases such as 24-bit and 8-bit modes.
128 *
129 * By multiplication, there's at least 48 possible combinations of the above.
130 *
131 * Below are implementations of the most commonly used combinations. They are
132 * accessed through function pointers which get initialized here and are used
133 * directly from the Mesa library. The 8 function pointers directly correspond
134 * to the first 3 cases listed above.
135 *
136 *
137 * The function naming convention is:
138 *
139 * [put|get]_[mono]_[row|values]_[format]_[pixmap|ximage]
140 *
141 * New functions optimized for specific cases can be added without too much
142 * trouble. An example might be the 24-bit TrueColor mode 8A8R8G8B which is
143 * found on IBM RS/6000 X servers.
144 */
145
146
147
148
149 /**********************************************************************/
150 /*** Write COLOR SPAN functions ***/
151 /**********************************************************************/
152
153
154 #define PUT_ROW_ARGS \
155 struct gl_context *ctx, \
156 struct gl_renderbuffer *rb, \
157 GLuint n, GLint x, GLint y, \
158 const void *values, const GLubyte mask[]
159
160 #define RGB_SPAN_ARGS \
161 struct gl_context *ctx, \
162 struct gl_renderbuffer *rb, \
163 GLuint n, GLint x, GLint y, \
164 const void *values, const GLubyte mask[]
165
166
167 #define GET_XRB(XRB) \
168 struct xmesa_renderbuffer *XRB = xmesa_renderbuffer(rb)
169
170
171 /*
172 * Write a span of PF_TRUECOLOR pixels to a pixmap.
173 */
174 static void put_row_TRUECOLOR_pixmap( PUT_ROW_ARGS )
175 {
176 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
177 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
178 GET_XRB(xrb);
179 XMesaDisplay *dpy = XMESA_BUFFER(ctx->DrawBuffer)->display;
180 XMesaDrawable buffer = xrb->drawable;
181 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
182 register GLuint i;
183
184 y = YFLIP(xrb, y);
185 if (mask) {
186 for (i=0;i<n;i++,x++) {
187 if (mask[i]) {
188 unsigned long p;
189 PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
190 XMesaSetForeground( dpy, gc, p );
191 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
192 }
193 }
194 }
195 else {
196 /* draw all pixels */
197 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
198 for (i=0;i<n;i++) {
199 unsigned long p;
200 PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
201 XMesaPutPixel( rowimg, i, 0, p );
202 }
203 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
204 }
205 }
206
207
208 /*
209 * Write a span of PF_TRUECOLOR pixels to a pixmap.
210 */
211 static void put_row_rgb_TRUECOLOR_pixmap( RGB_SPAN_ARGS )
212 {
213 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
214 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
215 GET_XRB(xrb);
216 XMesaDisplay *dpy = xmesa->xm_visual->display;
217 XMesaDrawable buffer = xrb->drawable;
218 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
219 register GLuint i;
220 y = YFLIP(xrb, y);
221 if (mask) {
222 for (i=0;i<n;i++,x++) {
223 if (mask[i]) {
224 unsigned long p;
225 PACK_TRUECOLOR( p, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
226 XMesaSetForeground( dpy, gc, p );
227 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
228 }
229 }
230 }
231 else {
232 /* draw all pixels */
233 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
234 for (i=0;i<n;i++) {
235 unsigned long p;
236 PACK_TRUECOLOR( p, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
237 XMesaPutPixel( rowimg, i, 0, p );
238 }
239 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
240 }
241 }
242
243 /*
244 * Write a span of PF_TRUEDITHER pixels to a pixmap.
245 */
246 static void put_row_TRUEDITHER_pixmap( PUT_ROW_ARGS )
247 {
248 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
249 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
250 GET_XRB(xrb);
251 XMesaDisplay *dpy = xmesa->xm_visual->display;
252 XMesaDrawable buffer = xrb->drawable;
253 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
254 register GLuint i;
255 y = YFLIP(xrb, y);
256 if (mask) {
257 for (i=0;i<n;i++,x++) {
258 if (mask[i]) {
259 unsigned long p;
260 PACK_TRUEDITHER(p, x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
261 XMesaSetForeground( dpy, gc, p );
262 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
263 }
264 }
265 }
266 else {
267 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
268 for (i=0;i<n;i++) {
269 unsigned long p;
270 PACK_TRUEDITHER(p, x+i, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
271 XMesaPutPixel( rowimg, i, 0, p );
272 }
273 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
274 }
275 }
276
277
278 /*
279 * Write a span of PF_TRUEDITHER pixels to a pixmap (no alpha).
280 */
281 static void put_row_rgb_TRUEDITHER_pixmap( RGB_SPAN_ARGS )
282 {
283 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
284 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
285 GET_XRB(xrb);
286 XMesaDisplay *dpy = xmesa->xm_visual->display;
287 XMesaDrawable buffer = xrb->drawable;
288 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
289 register GLuint i;
290 y = YFLIP(xrb, y);
291 if (mask) {
292 for (i=0;i<n;i++,x++) {
293 if (mask[i]) {
294 unsigned long p;
295 PACK_TRUEDITHER(p, x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
296 XMesaSetForeground( dpy, gc, p );
297 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
298 }
299 }
300 }
301 else {
302 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
303 for (i=0;i<n;i++) {
304 unsigned long p;
305 PACK_TRUEDITHER(p, x+i, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
306 XMesaPutPixel( rowimg, i, 0, p );
307 }
308 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
309 }
310 }
311
312
313 /*
314 * Write a span of PF_8A8B8G8R pixels to a pixmap.
315 */
316 static void put_row_8A8B8G8R_pixmap( PUT_ROW_ARGS )
317 {
318 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
319 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
320 GET_XRB(xrb);
321 XMesaDisplay *dpy = xmesa->xm_visual->display;
322 XMesaDrawable buffer = xrb->drawable;
323 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
324 register GLuint i;
325 y = YFLIP(xrb, y);
326 if (mask) {
327 for (i=0;i<n;i++,x++) {
328 if (mask[i]) {
329 XMesaSetForeground( dpy, gc,
330 PACK_8A8B8G8R(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP]) );
331 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
332 }
333 }
334 }
335 else {
336 /* draw all pixels */
337 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
338 register GLuint *ptr4 = (GLuint *) rowimg->data;
339 for (i=0;i<n;i++) {
340 *ptr4++ = PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
341 }
342 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
343 }
344 }
345
346
347 /*
348 * Write a span of PF_8A8B8G8R pixels to a pixmap (no alpha).
349 */
350 static void put_row_rgb_8A8B8G8R_pixmap( RGB_SPAN_ARGS )
351 {
352 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
353 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
354 GET_XRB(xrb);
355 XMesaDisplay *dpy = xmesa->xm_visual->display;
356 XMesaDrawable buffer = xrb->drawable;
357 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
358 register GLuint i;
359 y = YFLIP(xrb, y);
360 if (mask) {
361 for (i=0;i<n;i++,x++) {
362 if (mask[i]) {
363 XMesaSetForeground( dpy, gc,
364 PACK_8B8G8R(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]) );
365 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
366 }
367 }
368 }
369 else {
370 /* draw all pixels */
371 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
372 register GLuint *ptr4 = (GLuint *) rowimg->data;
373 for (i=0;i<n;i++) {
374 *ptr4++ = PACK_8B8G8R(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
375 }
376 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
377 }
378 }
379
380 /*
381 * Write a span of PF_8A8R8G8B pixels to a pixmap.
382 */
383 static void put_row_8A8R8G8B_pixmap( PUT_ROW_ARGS )
384 {
385 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
386 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
387 GET_XRB(xrb);
388 XMesaDisplay *dpy = xmesa->xm_visual->display;
389 XMesaDrawable buffer = xrb->drawable;
390 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
391 register GLuint i;
392 y = YFLIP(xrb, y);
393 if (mask) {
394 for (i=0;i<n;i++,x++) {
395 if (mask[i]) {
396 XMesaSetForeground( dpy, gc,
397 PACK_8A8R8G8B(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP]) );
398 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
399 }
400 }
401 }
402 else {
403 /* draw all pixels */
404 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
405 register GLuint *ptr4 = (GLuint *) rowimg->data;
406 for (i=0;i<n;i++) {
407 *ptr4++ = PACK_8A8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
408 }
409 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
410 }
411 }
412
413
414 /*
415 * Write a span of PF_8A8R8G8B pixels to a pixmap (no alpha).
416 */
417 static void put_row_rgb_8A8R8G8B_pixmap( RGB_SPAN_ARGS )
418 {
419 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
420 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
421 GET_XRB(xrb);
422 XMesaDisplay *dpy = xmesa->xm_visual->display;
423 XMesaDrawable buffer = xrb->drawable;
424 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
425 register GLuint i;
426 y = YFLIP(xrb, y);
427 if (mask) {
428 for (i=0;i<n;i++,x++) {
429 if (mask[i]) {
430 XMesaSetForeground( dpy, gc,
431 PACK_8R8G8B(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]) );
432 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
433 }
434 }
435 }
436 else {
437 /* draw all pixels */
438 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
439 register GLuint *ptr4 = (GLuint *) rowimg->data;
440 for (i=0;i<n;i++) {
441 *ptr4++ = PACK_8R8G8B(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
442 }
443 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
444 }
445 }
446
447 /*
448 * Write a span of PF_8R8G8B pixels to a pixmap.
449 */
450 static void put_row_8R8G8B_pixmap( PUT_ROW_ARGS )
451 {
452 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
453 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
454 GET_XRB(xrb);
455 XMesaDisplay *dpy = xmesa->xm_visual->display;
456 XMesaDrawable buffer = xrb->drawable;
457 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
458 register GLuint i;
459 y = YFLIP(xrb, y);
460 if (mask) {
461 for (i=0;i<n;i++,x++) {
462 if (mask[i]) {
463 #if 1
464 /*
465 * XXX Something funny is going on here.
466 * If we're drawing into a window that uses a depth 32 TrueColor
467 * visual, we see the right pixels on screen, but when we read
468 * them back with XGetImage() we get random colors.
469 * The alternative code below which uses XPutImage() instead
470 * seems to mostly fix the problem, but not always.
471 * We don't normally create windows with this visual, but glean
472 * does and we're seeing some failures there.
473 */
474 XMesaSetForeground( dpy, gc, PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ));
475 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
476 #else
477 /* This code works more often, but not always */
478 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
479 GLuint *ptr4 = (GLuint *) rowimg->data;
480 *ptr4 = PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
481 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, 1, 1 );
482 #endif
483 }
484 }
485 }
486 else {
487 /* draw all pixels */
488 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
489 register GLuint *ptr4 = (GLuint *) rowimg->data;
490 for (i=0;i<n;i++) {
491 *ptr4++ = PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
492 }
493 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
494 }
495 }
496
497
498 /*
499 * Write a span of PF_8R8G8B24 pixels to a pixmap.
500 */
501 static void put_row_8R8G8B24_pixmap( PUT_ROW_ARGS )
502 {
503 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
504 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
505 GET_XRB(xrb);
506 XMesaDisplay *dpy = xmesa->xm_visual->display;
507 XMesaDrawable buffer = xrb->drawable;
508 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
509 y = YFLIP(xrb, y);
510 if (mask) {
511 register GLuint i;
512 for (i=0;i<n;i++,x++) {
513 if (mask[i]) {
514 XMesaSetForeground( dpy, gc,
515 PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ));
516 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
517 }
518 }
519 }
520 else {
521 /* draw all pixels */
522 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
523 register GLuint *ptr4 = (GLuint *) rowimg->data;
524 register GLuint pixel;
525 static const GLuint shift[4] = {0, 8, 16, 24};
526 register GLuint i = 0;
527 int w = n;
528 while (w > 3) {
529 pixel = rgba[i][BCOMP] /* << shift[0]*/;
530 pixel |= rgba[i][GCOMP] << shift[1];
531 pixel |= rgba[i++][RCOMP] << shift[2];
532 pixel |= rgba[i][BCOMP] << shift[3];
533 *ptr4++ = pixel;
534
535 pixel = rgba[i][GCOMP] /* << shift[0]*/;
536 pixel |= rgba[i++][RCOMP] << shift[1];
537 pixel |= rgba[i][BCOMP] << shift[2];
538 pixel |= rgba[i][GCOMP] << shift[3];
539 *ptr4++ = pixel;
540
541 pixel = rgba[i++][RCOMP]/* << shift[0]*/;
542 pixel |= rgba[i][BCOMP] << shift[1];
543 pixel |= rgba[i][GCOMP] << shift[2];
544 pixel |= rgba[i++][RCOMP] << shift[3];
545 *ptr4++ = pixel;
546
547 w -= 4;
548 }
549 switch (w) {
550 case 3:
551 pixel = 0;
552 pixel |= rgba[i][BCOMP] /*<< shift[0]*/;
553 pixel |= rgba[i][GCOMP] << shift[1];
554 pixel |= rgba[i++][RCOMP] << shift[2];
555 pixel |= rgba[i][BCOMP] << shift[3];
556 *ptr4++ = pixel;
557 pixel = 0;
558 pixel |= rgba[i][GCOMP] /*<< shift[0]*/;
559 pixel |= rgba[i++][RCOMP] << shift[1];
560 pixel |= rgba[i][BCOMP] << shift[2];
561 pixel |= rgba[i][GCOMP] << shift[3];
562 *ptr4++ = pixel;
563 pixel = 0xffffff00 & *ptr4;
564 pixel |= rgba[i][RCOMP] /*<< shift[0]*/;
565 *ptr4 = pixel;
566 break;
567 case 2:
568 pixel = 0;
569 pixel |= rgba[i][BCOMP] /*<< shift[0]*/;
570 pixel |= rgba[i][GCOMP] << shift[1];
571 pixel |= rgba[i++][RCOMP] << shift[2];
572 pixel |= rgba[i][BCOMP] << shift[3];
573 *ptr4++ = pixel;
574 pixel = 0xffff0000 & *ptr4;
575 pixel |= rgba[i][GCOMP] /*<< shift[0]*/;
576 pixel |= rgba[i][RCOMP] << shift[1];
577 *ptr4 = pixel;
578 break;
579 case 1:
580 pixel = 0xff000000 & *ptr4;
581 pixel |= rgba[i][BCOMP] /*<< shift[0]*/;
582 pixel |= rgba[i][GCOMP] << shift[1];
583 pixel |= rgba[i][RCOMP] << shift[2];
584 *ptr4 = pixel;
585 break;
586 case 0:
587 break;
588 }
589 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
590 }
591 }
592
593
594 /*
595 * Write a span of PF_8R8G8B pixels to a pixmap (no alpha).
596 */
597 static void put_row_rgb_8R8G8B_pixmap( RGB_SPAN_ARGS )
598 {
599 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
600 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
601 GET_XRB(xrb);
602 XMesaDisplay *dpy = xmesa->xm_visual->display;
603 XMesaDrawable buffer = xrb->drawable;
604 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
605 register GLuint i;
606 y = YFLIP(xrb, y);
607 if (mask) {
608 for (i=0;i<n;i++,x++) {
609 if (mask[i]) {
610 XMesaSetForeground( dpy, gc, PACK_8R8G8B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ));
611 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
612 }
613 }
614 }
615 else {
616 /* draw all pixels */
617 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
618 register GLuint *ptr4 = (GLuint *) rowimg->data;
619 for (i=0;i<n;i++) {
620 *ptr4++ = PACK_8R8G8B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
621 }
622 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
623 }
624 }
625
626 /*
627 * Write a span of PF_8R8G8B24 pixels to a pixmap (no alpha).
628 */
629 static void put_row_rgb_8R8G8B24_pixmap( RGB_SPAN_ARGS )
630 {
631 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
632 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
633 GET_XRB(xrb);
634 XMesaDisplay *dpy = xmesa->xm_visual->display;
635 XMesaDrawable buffer = xrb->drawable;
636 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
637 y = YFLIP(xrb, y);
638 if (mask) {
639 register GLuint i;
640 for (i=0;i<n;i++,x++) {
641 if (mask[i]) {
642 XMesaSetForeground( dpy, gc,
643 PACK_8R8G8B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ));
644 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
645 }
646 }
647 }
648 else {
649 /* draw all pixels */
650 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
651 register GLuint *ptr4 = (GLuint *) rowimg->data;
652 register GLuint pixel;
653 static const GLuint shift[4] = {0, 8, 16, 24};
654 unsigned w = n;
655 register GLuint i = 0;
656 while (w > 3) {
657 pixel = 0;
658 pixel |= rgb[i][BCOMP]/* << shift[0]*/;
659 pixel |= rgb[i][GCOMP] << shift[1];
660 pixel |= rgb[i++][RCOMP] << shift[2];
661 pixel |= rgb[i][BCOMP] <<shift[3];
662 *ptr4++ = pixel;
663
664 pixel = 0;
665 pixel |= rgb[i][GCOMP]/* << shift[0]*/;
666 pixel |= rgb[i++][RCOMP] << shift[1];
667 pixel |= rgb[i][BCOMP] << shift[2];
668 pixel |= rgb[i][GCOMP] << shift[3];
669 *ptr4++ = pixel;
670
671 pixel = 0;
672 pixel |= rgb[i++][RCOMP]/* << shift[0]*/;
673 pixel |= rgb[i][BCOMP] << shift[1];
674 pixel |= rgb[i][GCOMP] << shift[2];
675 pixel |= rgb[i++][RCOMP] << shift[3];
676 *ptr4++ = pixel;
677 w -= 4;
678 }
679 switch (w) {
680 case 3:
681 pixel = 0;
682 pixel |= rgb[i][BCOMP]/* << shift[0]*/;
683 pixel |= rgb[i][GCOMP] << shift[1];
684 pixel |= rgb[i++][RCOMP] << shift[2];
685 pixel |= rgb[i][BCOMP] << shift[3];
686 *ptr4++ = pixel;
687 pixel = 0;
688 pixel |= rgb[i][GCOMP]/* << shift[0]*/;
689 pixel |= rgb[i++][RCOMP] << shift[1];
690 pixel |= rgb[i][BCOMP] << shift[2];
691 pixel |= rgb[i][GCOMP] << shift[3];
692 *ptr4++ = pixel;
693 pixel = *ptr4;
694 pixel &= 0xffffff00;
695 pixel |= rgb[i++][RCOMP]/* << shift[0]*/;
696 *ptr4++ = pixel;
697 break;
698 case 2:
699 pixel = 0;
700 pixel |= rgb[i][BCOMP]/* << shift[0]*/;
701 pixel |= rgb[i][GCOMP] << shift[1];
702 pixel |= rgb[i++][RCOMP] << shift[2];
703 pixel |= rgb[i][BCOMP] << shift[3];
704 *ptr4++ = pixel;
705 pixel = *ptr4;
706 pixel &= 0xffff0000;
707 pixel |= rgb[i][GCOMP]/* << shift[0]*/;
708 pixel |= rgb[i++][RCOMP] << shift[1];
709 *ptr4++ = pixel;
710 break;
711 case 1:
712 pixel = *ptr4;
713 pixel &= 0xff000000;
714 pixel |= rgb[i][BCOMP]/* << shift[0]*/;
715 pixel |= rgb[i][GCOMP] << shift[1];
716 pixel |= rgb[i++][RCOMP] << shift[2];
717 *ptr4++ = pixel;
718 break;
719 case 0:
720 break;
721 }
722 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
723 }
724 }
725
726
727 /*
728 * Write a span of PF_5R6G5B pixels to a pixmap.
729 */
730 static void put_row_5R6G5B_pixmap( PUT_ROW_ARGS )
731 {
732 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
733 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
734 GET_XRB(xrb);
735 XMesaDisplay *dpy = xmesa->xm_visual->display;
736 XMesaDrawable buffer = xrb->drawable;
737 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
738 register GLuint i;
739 y = YFLIP(xrb, y);
740 if (mask) {
741 for (i=0;i<n;i++,x++) {
742 if (mask[i]) {
743 XMesaSetForeground( dpy, gc, PACK_5R6G5B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ));
744 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
745 }
746 }
747 }
748 else {
749 /* draw all pixels */
750 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
751 register GLushort *ptr2 = (GLushort *) rowimg->data;
752 for (i=0;i<n;i++) {
753 ptr2[i] = PACK_5R6G5B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
754 }
755 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
756 }
757 }
758
759
760 /*
761 * Write a span of PF_DITHER_5R6G5B pixels to a pixmap.
762 */
763 static void put_row_DITHER_5R6G5B_pixmap( PUT_ROW_ARGS )
764 {
765 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
766 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
767 GET_XRB(xrb);
768 XMesaDisplay *dpy = xmesa->xm_visual->display;
769 XMesaDrawable buffer = xrb->drawable;
770 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
771 register GLuint i;
772 y = YFLIP(xrb, y);
773 if (mask) {
774 for (i=0;i<n;i++,x++) {
775 if (mask[i]) {
776 unsigned long p;
777 PACK_TRUEDITHER(p, x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
778 XMesaSetForeground( dpy, gc, p );
779 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
780 }
781 }
782 }
783 else {
784 /* draw all pixels */
785 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
786 register GLushort *ptr2 = (GLushort *) rowimg->data;
787 for (i=0;i<n;i++) {
788 PACK_TRUEDITHER( ptr2[i], x+i, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
789 }
790 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
791 }
792 }
793
794
795 /*
796 * Write a span of PF_5R6G5B pixels to a pixmap (no alpha).
797 */
798 static void put_row_rgb_5R6G5B_pixmap( RGB_SPAN_ARGS )
799 {
800 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
801 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
802 GET_XRB(xrb);
803 XMesaDisplay *dpy = xmesa->xm_visual->display;
804 XMesaDrawable buffer = xrb->drawable;
805 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
806 register GLuint i;
807 y = YFLIP(xrb, y);
808 if (mask) {
809 for (i=0;i<n;i++,x++) {
810 if (mask[i]) {
811 XMesaSetForeground( dpy, gc, PACK_5R6G5B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ));
812 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
813 }
814 }
815 }
816 else {
817 /* draw all pixels */
818 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
819 register GLushort *ptr2 = (GLushort *) rowimg->data;
820 for (i=0;i<n;i++) {
821 ptr2[i] = PACK_5R6G5B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
822 }
823 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
824 }
825 }
826
827
828 /*
829 * Write a span of PF_DITHER_5R6G5B pixels to a pixmap (no alpha).
830 */
831 static void put_row_rgb_DITHER_5R6G5B_pixmap( RGB_SPAN_ARGS )
832 {
833 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
834 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
835 GET_XRB(xrb);
836 XMesaDisplay *dpy = xmesa->xm_visual->display;
837 XMesaDrawable buffer = xrb->drawable;
838 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
839 register GLuint i;
840 y = YFLIP(xrb, y);
841 if (mask) {
842 for (i=0;i<n;i++,x++) {
843 if (mask[i]) {
844 unsigned long p;
845 PACK_TRUEDITHER(p, x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
846 XMesaSetForeground( dpy, gc, p );
847 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
848 }
849 }
850 }
851 else {
852 /* draw all pixels */
853 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
854 register GLushort *ptr2 = (GLushort *) rowimg->data;
855 for (i=0;i<n;i++) {
856 PACK_TRUEDITHER( ptr2[i], x+i, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
857 }
858 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
859 }
860 }
861
862
863 /*
864 * Write a span of PF_TRUECOLOR pixels to an XImage.
865 */
866 static void put_row_TRUECOLOR_ximage( PUT_ROW_ARGS )
867 {
868 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
869 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
870 GET_XRB(xrb);
871 XMesaImage *img = xrb->ximage;
872 register GLuint i;
873 y = YFLIP(xrb, y);
874 if (mask) {
875 for (i=0;i<n;i++,x++) {
876 if (mask[i]) {
877 unsigned long p;
878 PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
879 XMesaPutPixel( img, x, y, p );
880 }
881 }
882 }
883 else {
884 /* draw all pixels */
885 for (i=0;i<n;i++,x++) {
886 unsigned long p;
887 PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
888 XMesaPutPixel( img, x, y, p );
889 }
890 }
891 }
892
893
894 /*
895 * Write a span of PF_TRUECOLOR pixels to an XImage (no alpha).
896 */
897 static void put_row_rgb_TRUECOLOR_ximage( RGB_SPAN_ARGS )
898 {
899 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
900 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
901 GET_XRB(xrb);
902 XMesaImage *img = xrb->ximage;
903 register GLuint i;
904 y = YFLIP(xrb, y);
905 if (mask) {
906 for (i=0;i<n;i++,x++) {
907 if (mask[i]) {
908 unsigned long p;
909 PACK_TRUECOLOR( p, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
910 XMesaPutPixel( img, x, y, p );
911 }
912 }
913 }
914 else {
915 /* draw all pixels */
916 for (i=0;i<n;i++,x++) {
917 unsigned long p;
918 PACK_TRUECOLOR( p, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
919 XMesaPutPixel( img, x, y, p );
920 }
921 }
922 }
923
924
925 /*
926 * Write a span of PF_TRUEDITHER pixels to an XImage.
927 */
928 static void put_row_TRUEDITHER_ximage( PUT_ROW_ARGS )
929 {
930 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
931 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
932 GET_XRB(xrb);
933 XMesaImage *img = xrb->ximage;
934 register GLuint i;
935 y = YFLIP(xrb, y);
936 if (mask) {
937 for (i=0;i<n;i++,x++) {
938 if (mask[i]) {
939 unsigned long p;
940 PACK_TRUEDITHER(p, x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
941 XMesaPutPixel( img, x, y, p );
942 }
943 }
944 }
945 else {
946 /* draw all pixels */
947 for (i=0;i<n;i++,x++) {
948 unsigned long p;
949 PACK_TRUEDITHER(p, x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
950 XMesaPutPixel( img, x, y, p );
951 }
952 }
953 }
954
955
956 /*
957 * Write a span of PF_TRUEDITHER pixels to an XImage (no alpha).
958 */
959 static void put_row_rgb_TRUEDITHER_ximage( RGB_SPAN_ARGS )
960 {
961 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
962 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
963 GET_XRB(xrb);
964 XMesaImage *img = xrb->ximage;
965 register GLuint i;
966 y = YFLIP(xrb, y);
967 if (mask) {
968 for (i=0;i<n;i++,x++) {
969 if (mask[i]) {
970 unsigned long p;
971 PACK_TRUEDITHER(p, x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
972 XMesaPutPixel( img, x, y, p );
973 }
974 }
975 }
976 else {
977 /* draw all pixels */
978 for (i=0;i<n;i++,x++) {
979 unsigned long p;
980 PACK_TRUEDITHER(p, x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
981 XMesaPutPixel( img, x, y, p );
982 }
983 }
984 }
985
986
987 /*
988 * Write a span of PF_8A8B8G8R-format pixels to an ximage.
989 */
990 static void put_row_8A8B8G8R_ximage( PUT_ROW_ARGS )
991 {
992 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
993 GET_XRB(xrb);
994 register GLuint i;
995 register GLuint *ptr = PIXEL_ADDR4(xrb, x, y);
996 (void) ctx;
997 if (mask) {
998 for (i=0;i<n;i++) {
999 if (mask[i]) {
1000 ptr[i] = PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
1001 }
1002 }
1003 }
1004 else {
1005 /* draw all pixels */
1006 for (i=0;i<n;i++) {
1007 ptr[i] = PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
1008 }
1009 }
1010 }
1011
1012
1013 /*
1014 * Write a span of PF_8A8B8G8R-format pixels to an ximage (no alpha).
1015 */
1016 static void put_row_rgb_8A8B8G8R_ximage( RGB_SPAN_ARGS )
1017 {
1018 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1019 GET_XRB(xrb);
1020 register GLuint i;
1021 register GLuint *ptr = PIXEL_ADDR4(xrb, x, y);
1022 if (mask) {
1023 for (i=0;i<n;i++) {
1024 if (mask[i]) {
1025 ptr[i] = PACK_8A8B8G8R( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP], 255 );
1026 }
1027 }
1028 }
1029 else {
1030 /* draw all pixels */
1031 for (i=0;i<n;i++) {
1032 ptr[i] = PACK_8A8B8G8R( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP], 255 );
1033 }
1034 }
1035 }
1036
1037 /*
1038 * Write a span of PF_8A8R8G8B-format pixels to an ximage.
1039 */
1040 static void put_row_8A8R8G8B_ximage( PUT_ROW_ARGS )
1041 {
1042 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1043 GET_XRB(xrb);
1044 register GLuint i;
1045 register GLuint *ptr = PIXEL_ADDR4(xrb, x, y);
1046 if (mask) {
1047 for (i=0;i<n;i++) {
1048 if (mask[i]) {
1049 ptr[i] = PACK_8A8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
1050 }
1051 }
1052 }
1053 else {
1054 /* draw all pixels */
1055 for (i=0;i<n;i++) {
1056 ptr[i] = PACK_8A8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
1057 }
1058 }
1059 }
1060
1061
1062 /*
1063 * Write a span of PF_8A8R8G8B-format pixels to an ximage (no alpha).
1064 */
1065 static void put_row_rgb_8A8R8G8B_ximage( RGB_SPAN_ARGS )
1066 {
1067 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1068 GET_XRB(xrb);
1069 register GLuint i;
1070 register GLuint *ptr = PIXEL_ADDR4(xrb, x, y);
1071 if (mask) {
1072 for (i=0;i<n;i++) {
1073 if (mask[i]) {
1074 ptr[i] = PACK_8A8R8G8B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP], 255 );
1075 }
1076 }
1077 }
1078 else {
1079 /* draw all pixels */
1080 for (i=0;i<n;i++) {
1081 ptr[i] = PACK_8A8R8G8B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP], 255 );
1082 }
1083 }
1084 }
1085
1086
1087 /*
1088 * Write a span of PF_8R8G8B-format pixels to an ximage.
1089 */
1090 static void put_row_8R8G8B_ximage( PUT_ROW_ARGS )
1091 {
1092 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1093 GET_XRB(xrb);
1094 register GLuint i;
1095 register GLuint *ptr = PIXEL_ADDR4(xrb, x, y);
1096 if (mask) {
1097 for (i=0;i<n;i++) {
1098 if (mask[i]) {
1099 ptr[i] = PACK_8R8G8B(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
1100 }
1101 }
1102 }
1103 else {
1104 for (i=0;i<n;i++) {
1105 ptr[i] = PACK_8R8G8B(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
1106 }
1107 }
1108 }
1109
1110
1111 /*
1112 * Write a span of PF_8R8G8B24-format pixels to an ximage.
1113 */
1114 static void put_row_8R8G8B24_ximage( PUT_ROW_ARGS )
1115 {
1116 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1117 GET_XRB(xrb);
1118 register GLuint i;
1119 register GLubyte *ptr = (GLubyte *) PIXEL_ADDR3(xrb, x, y );
1120 if (mask) {
1121 for (i=0;i<n;i++) {
1122 if (mask[i]) {
1123 GLuint *ptr4 = (GLuint *) ptr;
1124 register GLuint pixel = *ptr4;
1125 switch (3 & (int)(ptr - (GLubyte*)ptr4)) {
1126 case 0:
1127 pixel &= 0xff000000;
1128 pixel |= rgba[i][BCOMP];
1129 pixel |= rgba[i][GCOMP] << 8;
1130 pixel |= rgba[i][RCOMP] << 16;
1131 *ptr4 = pixel;
1132 break;
1133 case 3:
1134 pixel &= 0x00ffffff;
1135 pixel |= rgba[i][BCOMP] << 24;
1136 *ptr4++ = pixel;
1137 pixel = *ptr4 & 0xffff0000;
1138 pixel |= rgba[i][GCOMP];
1139 pixel |= rgba[i][RCOMP] << 8;
1140 *ptr4 = pixel;
1141 break;
1142 case 2:
1143 pixel &= 0x0000ffff;
1144 pixel |= rgba[i][BCOMP] << 16;
1145 pixel |= rgba[i][GCOMP] << 24;
1146 *ptr4++ = pixel;
1147 pixel = *ptr4 & 0xffffff00;
1148 pixel |= rgba[i][RCOMP];
1149 *ptr4 = pixel;
1150 break;
1151 case 1:
1152 pixel &= 0x000000ff;
1153 pixel |= rgba[i][BCOMP] << 8;
1154 pixel |= rgba[i][GCOMP] << 16;
1155 pixel |= rgba[i][RCOMP] << 24;
1156 *ptr4 = pixel;
1157 break;
1158 }
1159 }
1160 ptr += 3;
1161 }
1162 }
1163 else {
1164 /* write all pixels */
1165 int w = n;
1166 GLuint *ptr4 = (GLuint *) ptr;
1167 register GLuint pixel = *ptr4;
1168 int index = (int)(ptr - (GLubyte *)ptr4);
1169 register GLuint i = 0;
1170 switch (index) {
1171 case 0:
1172 break;
1173 case 1:
1174 pixel &= 0x00ffffff;
1175 pixel |= rgba[i][BCOMP] << 24;
1176 *ptr4++ = pixel;
1177 pixel = *ptr4 & 0xffff0000;
1178 pixel |= rgba[i][GCOMP];
1179 pixel |= rgba[i++][RCOMP] << 8;
1180 *ptr4 = pixel;
1181 if (0 == --w)
1182 break;
1183 case 2:
1184 pixel &= 0x0000ffff;
1185 pixel |= rgba[i][BCOMP] << 16;
1186 pixel |= rgba[i][GCOMP] << 24;
1187 *ptr4++ = pixel;
1188 pixel = *ptr4 & 0xffffff00;
1189 pixel |= rgba[i++][RCOMP];
1190 *ptr4 = pixel;
1191 if (0 == --w)
1192 break;
1193 case 3:
1194 pixel &= 0x000000ff;
1195 pixel |= rgba[i][BCOMP] << 8;
1196 pixel |= rgba[i][GCOMP] << 16;
1197 pixel |= rgba[i++][RCOMP] << 24;
1198 *ptr4++ = pixel;
1199 if (0 == --w)
1200 break;
1201 break;
1202 }
1203 while (w > 3) {
1204 pixel = rgba[i][BCOMP];
1205 pixel |= rgba[i][GCOMP] << 8;
1206 pixel |= rgba[i++][RCOMP] << 16;
1207 pixel |= rgba[i][BCOMP] << 24;
1208 *ptr4++ = pixel;
1209 pixel = rgba[i][GCOMP];
1210 pixel |= rgba[i++][RCOMP] << 8;
1211 pixel |= rgba[i][BCOMP] << 16;
1212 pixel |= rgba[i][GCOMP] << 24;
1213 *ptr4++ = pixel;
1214 pixel = rgba[i++][RCOMP];
1215 pixel |= rgba[i][BCOMP] << 8;
1216 pixel |= rgba[i][GCOMP] << 16;
1217 pixel |= rgba[i++][RCOMP] << 24;
1218 *ptr4++ = pixel;
1219 w -= 4;
1220 }
1221 switch (w) {
1222 case 0:
1223 break;
1224 case 1:
1225 pixel = *ptr4 & 0xff000000;
1226 pixel |= rgba[i][BCOMP];
1227 pixel |= rgba[i][GCOMP] << 8;
1228 pixel |= rgba[i][RCOMP] << 16;
1229 *ptr4 = pixel;
1230 break;
1231 case 2:
1232 pixel = rgba[i][BCOMP];
1233 pixel |= rgba[i][GCOMP] << 8;
1234 pixel |= rgba[i++][RCOMP] << 16;
1235 pixel |= rgba[i][BCOMP] << 24;
1236 *ptr4++ = pixel;
1237 pixel = *ptr4 & 0xffff0000;
1238 pixel |= rgba[i][GCOMP];
1239 pixel |= rgba[i][RCOMP] << 8;
1240 *ptr4 = pixel;
1241 break;
1242 case 3:
1243 pixel = rgba[i][BCOMP];
1244 pixel |= rgba[i][GCOMP] << 8;
1245 pixel |= rgba[i++][RCOMP] << 16;
1246 pixel |= rgba[i][BCOMP] << 24;
1247 *ptr4++ = pixel;
1248 pixel = rgba[i][GCOMP];
1249 pixel |= rgba[i++][RCOMP] << 8;
1250 pixel |= rgba[i][BCOMP] << 16;
1251 pixel |= rgba[i][GCOMP] << 24;
1252 *ptr4++ = pixel;
1253 pixel = *ptr4 & 0xffffff00;
1254 pixel |= rgba[i][RCOMP];
1255 *ptr4 = pixel;
1256 break;
1257 }
1258 }
1259 }
1260
1261
1262 /*
1263 * Write a span of PF_8R8G8B-format pixels to an ximage (no alpha).
1264 */
1265 static void put_row_rgb_8R8G8B_ximage( RGB_SPAN_ARGS )
1266 {
1267 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1268 GET_XRB(xrb);
1269 register GLuint i;
1270 register GLuint *ptr = PIXEL_ADDR4(xrb, x, y);
1271 if (mask) {
1272 for (i=0;i<n;i++) {
1273 if (mask[i]) {
1274 ptr[i] = PACK_8R8G8B(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
1275 }
1276 }
1277 }
1278 else {
1279 /* draw all pixels */
1280 for (i=0;i<n;i++) {
1281 ptr[i] = PACK_8R8G8B(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
1282 }
1283 }
1284 }
1285
1286
1287 /*
1288 * Write a span of PF_8R8G8B24-format pixels to an ximage (no alpha).
1289 */
1290 static void put_row_rgb_8R8G8B24_ximage( RGB_SPAN_ARGS )
1291 {
1292 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1293 GET_XRB(xrb);
1294 register GLuint i;
1295 register GLubyte *ptr = (GLubyte *) PIXEL_ADDR3(xrb, x, y);
1296 if (mask) {
1297 for (i=0;i<n;i++) {
1298 if (mask[i]) {
1299 *ptr++ = rgb[i][BCOMP];
1300 *ptr++ = rgb[i][GCOMP];
1301 *ptr++ = rgb[i][RCOMP];
1302 }
1303 else {
1304 ptr += 3;
1305 }
1306 }
1307 }
1308 else {
1309 /* draw all pixels */
1310 for (i=0;i<n;i++) {
1311 *ptr++ = rgb[i][BCOMP];
1312 *ptr++ = rgb[i][GCOMP];
1313 *ptr++ = rgb[i][RCOMP];
1314 }
1315 }
1316 }
1317
1318
1319 /*
1320 * Write a span of PF_5R6G5B-format pixels to an ximage.
1321 */
1322 static void put_row_5R6G5B_ximage( PUT_ROW_ARGS )
1323 {
1324 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1325 GET_XRB(xrb);
1326 register GLuint i;
1327 register GLushort *ptr = PIXEL_ADDR2(xrb, x, y);
1328 if (mask) {
1329 for (i=0;i<n;i++) {
1330 if (mask[i]) {
1331 ptr[i] = PACK_5R6G5B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1332 }
1333 }
1334 }
1335 else {
1336 /* draw all pixels */
1337 #if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
1338 GLuint *ptr32 = (GLuint *) ptr;
1339 GLuint extraPixel = (n & 1);
1340 n -= extraPixel;
1341 for (i = 0; i < n; i += 2) {
1342 GLuint p0, p1;
1343 p0 = PACK_5R6G5B(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
1344 p1 = PACK_5R6G5B(rgba[i+1][RCOMP], rgba[i+1][GCOMP], rgba[i+1][BCOMP]);
1345 *ptr32++ = (p1 << 16) | p0;
1346 }
1347 if (extraPixel) {
1348 ptr[n] = PACK_5R6G5B(rgba[n][RCOMP], rgba[n][GCOMP], rgba[n][BCOMP]);
1349 }
1350 #else
1351 for (i = 0; i < n; i++) {
1352 ptr[i] = PACK_5R6G5B(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
1353 }
1354 #endif
1355 }
1356 }
1357
1358
1359 /*
1360 * Write a span of PF_DITHER_5R6G5B-format pixels to an ximage.
1361 */
1362 static void put_row_DITHER_5R6G5B_ximage( PUT_ROW_ARGS )
1363 {
1364 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1365 GET_XRB(xrb);
1366 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1367 register GLuint i;
1368 register GLushort *ptr = PIXEL_ADDR2(xrb, x, y);
1369 const GLint y2 = YFLIP(xrb, y);
1370 if (mask) {
1371 for (i=0;i<n;i++,x++) {
1372 if (mask[i]) {
1373 PACK_TRUEDITHER( ptr[i], x, y2, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1374 }
1375 }
1376 }
1377 else {
1378 /* draw all pixels */
1379 #if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
1380 GLuint *ptr32 = (GLuint *) ptr;
1381 GLuint extraPixel = (n & 1);
1382 n -= extraPixel;
1383 for (i = 0; i < n; i += 2, x += 2) {
1384 GLuint p0, p1;
1385 PACK_TRUEDITHER( p0, x, y2, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1386 PACK_TRUEDITHER( p1, x+1, y2, rgba[i+1][RCOMP], rgba[i+1][GCOMP], rgba[i+1][BCOMP] );
1387 *ptr32++ = (p1 << 16) | p0;
1388 }
1389 if (extraPixel) {
1390 PACK_TRUEDITHER( ptr[n], x+n, y2, rgba[n][RCOMP], rgba[n][GCOMP], rgba[n][BCOMP]);
1391 }
1392 #else
1393 for (i = 0; i < n; i++, x++) {
1394 PACK_TRUEDITHER( ptr[i], x, y2, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
1395 }
1396 #endif
1397 }
1398 }
1399
1400
1401 /*
1402 * Write a span of PF_5R6G5B-format pixels to an ximage (no alpha).
1403 */
1404 static void put_row_rgb_5R6G5B_ximage( RGB_SPAN_ARGS )
1405 {
1406 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1407 GET_XRB(xrb);
1408 register GLuint i;
1409 register GLushort *ptr = PIXEL_ADDR2(xrb, x, y);
1410 if (mask) {
1411 for (i=0;i<n;i++) {
1412 if (mask[i]) {
1413 ptr[i] = PACK_5R6G5B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1414 }
1415 }
1416 }
1417 else {
1418 /* draw all pixels */
1419 #if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
1420 GLuint *ptr32 = (GLuint *) ptr;
1421 GLuint extraPixel = (n & 1);
1422 n -= extraPixel;
1423 for (i = 0; i < n; i += 2) {
1424 GLuint p0, p1;
1425 p0 = PACK_5R6G5B(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
1426 p1 = PACK_5R6G5B(rgb[i+1][RCOMP], rgb[i+1][GCOMP], rgb[i+1][BCOMP]);
1427 *ptr32++ = (p1 << 16) | p0;
1428 }
1429 if (extraPixel) {
1430 ptr[n] = PACK_5R6G5B(rgb[n][RCOMP], rgb[n][GCOMP], rgb[n][BCOMP]);
1431 }
1432 #else
1433 for (i=0;i<n;i++) {
1434 ptr[i] = PACK_5R6G5B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1435 }
1436 #endif
1437 }
1438 }
1439
1440
1441 /*
1442 * Write a span of PF_DITHER_5R6G5B-format pixels to an ximage (no alpha).
1443 */
1444 static void put_row_rgb_DITHER_5R6G5B_ximage( RGB_SPAN_ARGS )
1445 {
1446 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1447 GET_XRB(xrb);
1448 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1449 register GLuint i;
1450 register GLushort *ptr = PIXEL_ADDR2(xrb, x, y );
1451 if (mask) {
1452 for (i=0;i<n;i++,x++) {
1453 if (mask[i]) {
1454 PACK_TRUEDITHER( ptr[i], x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1455 }
1456 }
1457 }
1458 else {
1459 /* draw all pixels */
1460 #if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
1461 GLuint *ptr32 = (GLuint *) ptr;
1462 GLuint extraPixel = (n & 1);
1463 n -= extraPixel;
1464 for (i = 0; i < n; i += 2, x += 2) {
1465 GLuint p0, p1;
1466 PACK_TRUEDITHER( p0, x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1467 PACK_TRUEDITHER( p1, x+1, y, rgb[i+1][RCOMP], rgb[i+1][GCOMP], rgb[i+1][BCOMP] );
1468 *ptr32++ = (p1 << 16) | p0;
1469 }
1470 if (extraPixel) {
1471 PACK_TRUEDITHER( ptr[n], x+n, y, rgb[n][RCOMP], rgb[n][GCOMP], rgb[n][BCOMP]);
1472 }
1473 #else
1474 for (i=0;i<n;i++,x++) {
1475 PACK_TRUEDITHER( ptr[i], x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1476 }
1477 #endif
1478 }
1479 }
1480
1481
1482
1483 /**********************************************************************/
1484 /*** Write COLOR PIXEL functions ***/
1485 /**********************************************************************/
1486
1487
1488 #define PUT_VALUES_ARGS \
1489 struct gl_context *ctx, struct gl_renderbuffer *rb, \
1490 GLuint n, const GLint x[], const GLint y[], \
1491 const void *values, const GLubyte mask[]
1492
1493
1494 /*
1495 * Write an array of PF_TRUECOLOR pixels to a pixmap.
1496 */
1497 static void put_values_TRUECOLOR_pixmap( PUT_VALUES_ARGS )
1498 {
1499 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1500 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1501 GET_XRB(xrb);
1502 XMesaDisplay *dpy = xmesa->xm_visual->display;
1503 XMesaDrawable buffer = xrb->drawable;
1504 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
1505 register GLuint i;
1506 for (i=0;i<n;i++) {
1507 if (mask[i]) {
1508 unsigned long p;
1509 PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1510 XMesaSetForeground( dpy, gc, p );
1511 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
1512 }
1513 }
1514 }
1515
1516
1517 /*
1518 * Write an array of PF_TRUEDITHER pixels to a pixmap.
1519 */
1520 static void put_values_TRUEDITHER_pixmap( PUT_VALUES_ARGS )
1521 {
1522 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1523 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1524 GET_XRB(xrb);
1525 XMesaDisplay *dpy = xmesa->xm_visual->display;
1526 XMesaDrawable buffer = xrb->drawable;
1527 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
1528 register GLuint i;
1529 for (i=0;i<n;i++) {
1530 if (mask[i]) {
1531 unsigned long p;
1532 PACK_TRUEDITHER(p, x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
1533 XMesaSetForeground( dpy, gc, p );
1534 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
1535 }
1536 }
1537 }
1538
1539
1540 /*
1541 * Write an array of PF_8A8B8G8R pixels to a pixmap.
1542 */
1543 static void put_values_8A8B8G8R_pixmap( PUT_VALUES_ARGS )
1544 {
1545 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1546 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1547 GET_XRB(xrb);
1548 XMesaDisplay *dpy = xmesa->xm_visual->display;
1549 XMesaDrawable buffer = xrb->drawable;
1550 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
1551 register GLuint i;
1552 for (i=0;i<n;i++) {
1553 if (mask[i]) {
1554 XMesaSetForeground( dpy, gc,
1555 PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] ));
1556 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
1557 }
1558 }
1559 }
1560
1561 /*
1562 * Write an array of PF_8A8R8G8B pixels to a pixmap.
1563 */
1564 static void put_values_8A8R8G8B_pixmap( PUT_VALUES_ARGS )
1565 {
1566 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1567 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1568 GET_XRB(xrb);
1569 XMesaDisplay *dpy = xmesa->xm_visual->display;
1570 XMesaDrawable buffer = xrb->drawable;
1571 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
1572 register GLuint i;
1573 for (i=0;i<n;i++) {
1574 if (mask[i]) {
1575 XMesaSetForeground( dpy, gc,
1576 PACK_8A8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] ));
1577 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
1578 }
1579 }
1580 }
1581
1582 /*
1583 * Write an array of PF_8R8G8B pixels to a pixmap.
1584 */
1585 static void put_values_8R8G8B_pixmap( PUT_VALUES_ARGS )
1586 {
1587 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1588 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1589 GET_XRB(xrb);
1590 XMesaDisplay *dpy = xmesa->xm_visual->display;
1591 XMesaDrawable buffer = xrb->drawable;
1592 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
1593 register GLuint i;
1594 for (i=0;i<n;i++) {
1595 if (mask[i]) {
1596 XMesaSetForeground( dpy, gc, PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
1597 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
1598 }
1599 }
1600 }
1601
1602
1603 /*
1604 * Write an array of PF_8R8G8B24 pixels to a pixmap.
1605 */
1606 static void put_values_8R8G8B24_pixmap( PUT_VALUES_ARGS )
1607 {
1608 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1609 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1610 GET_XRB(xrb);
1611 XMesaDisplay *dpy = xmesa->xm_visual->display;
1612 XMesaDrawable buffer = xrb->drawable;
1613 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
1614 register GLuint i;
1615 for (i=0;i<n;i++) {
1616 if (mask[i]) {
1617 XMesaSetForeground( dpy, gc, PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
1618 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
1619 }
1620 }
1621 }
1622
1623
1624 /*
1625 * Write an array of PF_5R6G5B pixels to a pixmap.
1626 */
1627 static void put_values_5R6G5B_pixmap( PUT_VALUES_ARGS )
1628 {
1629 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1630 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1631 GET_XRB(xrb);
1632 XMesaDisplay *dpy = xmesa->xm_visual->display;
1633 XMesaDrawable buffer = xrb->drawable;
1634 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
1635 register GLuint i;
1636 for (i=0;i<n;i++) {
1637 if (mask[i]) {
1638 XMesaSetForeground( dpy, gc, PACK_5R6G5B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
1639 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
1640 }
1641 }
1642 }
1643
1644
1645 /*
1646 * Write an array of PF_DITHER_5R6G5B pixels to a pixmap.
1647 */
1648 static void put_values_DITHER_5R6G5B_pixmap( PUT_VALUES_ARGS )
1649 {
1650 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1651 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1652 GET_XRB(xrb);
1653 XMesaDisplay *dpy = xmesa->xm_visual->display;
1654 XMesaDrawable buffer = xrb->drawable;
1655 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
1656 register GLuint i;
1657 for (i=0;i<n;i++) {
1658 if (mask[i]) {
1659 unsigned long p;
1660 PACK_TRUEDITHER(p, x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1661 XMesaSetForeground( dpy, gc, p );
1662 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
1663 }
1664 }
1665 }
1666
1667
1668 /*
1669 * Write an array of PF_TRUECOLOR pixels to an ximage.
1670 */
1671 static void put_values_TRUECOLOR_ximage( PUT_VALUES_ARGS )
1672 {
1673 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1674 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1675 GET_XRB(xrb);
1676 XMesaImage *img = xrb->ximage;
1677 register GLuint i;
1678 for (i=0;i<n;i++) {
1679 if (mask[i]) {
1680 unsigned long p;
1681 PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1682 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]), p );
1683 }
1684 }
1685 }
1686
1687
1688 /*
1689 * Write an array of PF_TRUEDITHER pixels to an XImage.
1690 */
1691 static void put_values_TRUEDITHER_ximage( PUT_VALUES_ARGS )
1692 {
1693 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1694 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1695 GET_XRB(xrb);
1696 XMesaImage *img = xrb->ximage;
1697 register GLuint i;
1698 for (i=0;i<n;i++) {
1699 if (mask[i]) {
1700 unsigned long p;
1701 PACK_TRUEDITHER(p, x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
1702 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]), p );
1703 }
1704 }
1705 }
1706
1707
1708 /*
1709 * Write an array of PF_8A8B8G8R pixels to an ximage.
1710 */
1711 static void put_values_8A8B8G8R_ximage( PUT_VALUES_ARGS )
1712 {
1713 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1714 GET_XRB(xrb);
1715 register GLuint i;
1716 for (i=0;i<n;i++) {
1717 if (mask[i]) {
1718 GLuint *ptr = PIXEL_ADDR4(xrb, x[i], y[i] );
1719 *ptr = PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
1720 }
1721 }
1722 }
1723
1724 /*
1725 * Write an array of PF_8A8R8G8B pixels to an ximage.
1726 */
1727 static void put_values_8A8R8G8B_ximage( PUT_VALUES_ARGS )
1728 {
1729 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1730 GET_XRB(xrb);
1731 register GLuint i;
1732 for (i=0;i<n;i++) {
1733 if (mask[i]) {
1734 GLuint *ptr = PIXEL_ADDR4(xrb, x[i], y[i]);
1735 *ptr = PACK_8A8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
1736 }
1737 }
1738 }
1739
1740
1741 /*
1742 * Write an array of PF_8R8G8B pixels to an ximage.
1743 */
1744 static void put_values_8R8G8B_ximage( PUT_VALUES_ARGS )
1745 {
1746 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1747 GET_XRB(xrb);
1748 register GLuint i;
1749 for (i=0;i<n;i++) {
1750 if (mask[i]) {
1751 GLuint *ptr = PIXEL_ADDR4(xrb, x[i], y[i]);
1752 *ptr = PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1753 }
1754 }
1755 }
1756
1757
1758 /*
1759 * Write an array of PF_8R8G8B24 pixels to an ximage.
1760 */
1761 static void put_values_8R8G8B24_ximage( PUT_VALUES_ARGS )
1762 {
1763 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1764 GET_XRB(xrb);
1765 register GLuint i;
1766 for (i=0;i<n;i++) {
1767 if (mask[i]) {
1768 bgr_t *ptr = PIXEL_ADDR3(xrb, x[i], y[i] );
1769 ptr->r = rgba[i][RCOMP];
1770 ptr->g = rgba[i][GCOMP];
1771 ptr->b = rgba[i][BCOMP];
1772 }
1773 }
1774 }
1775
1776
1777 /*
1778 * Write an array of PF_5R6G5B pixels to an ximage.
1779 */
1780 static void put_values_5R6G5B_ximage( PUT_VALUES_ARGS )
1781 {
1782 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1783 GET_XRB(xrb);
1784 register GLuint i;
1785 for (i=0;i<n;i++) {
1786 if (mask[i]) {
1787 GLushort *ptr = PIXEL_ADDR2(xrb, x[i], y[i] );
1788 *ptr = PACK_5R6G5B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1789 }
1790 }
1791 }
1792
1793
1794 /*
1795 * Write an array of PF_DITHER_5R6G5B pixels to an ximage.
1796 */
1797 static void put_values_DITHER_5R6G5B_ximage( PUT_VALUES_ARGS )
1798 {
1799 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1800 GET_XRB(xrb);
1801 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1802 register GLuint i;
1803 for (i=0;i<n;i++) {
1804 if (mask[i]) {
1805 GLushort *ptr = PIXEL_ADDR2(xrb, x[i], y[i] );
1806 PACK_TRUEDITHER( *ptr, x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1807 }
1808 }
1809 }
1810
1811
1812
1813 /**********************************************************************/
1814 /*** Write MONO COLOR SPAN functions ***/
1815 /**********************************************************************/
1816
1817 #define PUT_MONO_ROW_ARGS \
1818 struct gl_context *ctx, struct gl_renderbuffer *rb, \
1819 GLuint n, GLint x, GLint y, const void *value, \
1820 const GLubyte mask[]
1821
1822
1823
1824 /*
1825 * Write a span of identical pixels to a pixmap.
1826 */
1827 static void put_mono_row_pixmap( PUT_MONO_ROW_ARGS )
1828 {
1829 const GLubyte *color = (const GLubyte *) value;
1830 GET_XRB(xrb);
1831 XMesaContext xmesa = XMESA_CONTEXT(ctx);
1832 XMesaDisplay *dpy = xmesa->xm_visual->display;
1833 XMesaDrawable buffer = xrb->drawable;
1834 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
1835 const unsigned long pixel = xmesa_color_to_pixel(ctx, color[RCOMP],
1836 color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
1837 register GLuint i;
1838 XMesaSetForeground( xmesa->display, gc, pixel );
1839 y = YFLIP(xrb, y);
1840
1841 /* New code contributed by Jeff Epler and cleaned up by Keith
1842 * Whitwell.
1843 */
1844 for (i = 0; i < n; ) {
1845 GLuint start = i;
1846
1847 /* Identify and emit contiguous rendered pixels
1848 */
1849 while (i < n && (!mask || mask[i]))
1850 i++;
1851
1852 if (start < i)
1853 XMesaFillRectangle( dpy, buffer, gc,
1854 (int)(x+start), (int) y,
1855 (int)(i-start), 1);
1856
1857 /* Eat up non-rendered pixels
1858 */
1859 while (i < n && !mask[i])
1860 i++;
1861 }
1862 }
1863
1864
1865
1866 /*
1867 * Write a span of PF_TRUEDITHER pixels to a pixmap.
1868 */
1869 static void put_mono_row_TRUEDITHER_pixmap( PUT_MONO_ROW_ARGS )
1870 {
1871 const GLubyte *color = (const GLubyte *) value;
1872 GET_XRB(xrb);
1873 XMesaContext xmesa = XMESA_CONTEXT(ctx);
1874 XMesaDisplay *dpy = xmesa->xm_visual->display;
1875 XMesaDrawable buffer = xrb->drawable;
1876 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
1877 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
1878 register GLuint i;
1879 int yy = YFLIP(xrb, y);
1880 for (i=0;i<n;i++,x++) {
1881 if (!mask || mask[i]) {
1882 unsigned long p;
1883 PACK_TRUEDITHER(p, x, yy, r, g, b);
1884 XMesaSetForeground( dpy, gc, p );
1885 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) yy );
1886 }
1887 }
1888 }
1889
1890
1891 /*
1892 * Write a span of identical pixels to an XImage.
1893 */
1894 static void put_mono_row_ximage( PUT_MONO_ROW_ARGS )
1895 {
1896 const GLubyte *color = (const GLubyte *) value;
1897 GET_XRB(xrb);
1898 XMesaContext xmesa = XMESA_CONTEXT(ctx);
1899 XMesaImage *img = xrb->ximage;
1900 register GLuint i;
1901 const unsigned long pixel = xmesa_color_to_pixel(ctx, color[RCOMP],
1902 color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
1903 y = YFLIP(xrb, y);
1904 for (i=0;i<n;i++,x++) {
1905 if (!mask || mask[i]) {
1906 XMesaPutPixel( img, x, y, pixel );
1907 }
1908 }
1909 }
1910
1911
1912 /*
1913 * Write a span of identical PF_TRUEDITHER pixels to an XImage.
1914 */
1915 static void put_mono_row_TRUEDITHER_ximage( PUT_MONO_ROW_ARGS )
1916 {
1917 const GLubyte *color = (const GLubyte *) value;
1918 GET_XRB(xrb);
1919 XMesaContext xmesa = XMESA_CONTEXT(ctx);
1920 XMesaImage *img = xrb->ximage;
1921 const GLint r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
1922 GLuint i;
1923 y = YFLIP(xrb, y);
1924 for (i=0;i<n;i++) {
1925 if (!mask || mask[i]) {
1926 unsigned long p;
1927 PACK_TRUEDITHER( p, x+i, y, r, g, b);
1928 XMesaPutPixel( img, x+i, y, p );
1929 }
1930 }
1931 }
1932
1933
1934 /*
1935 * Write a span of identical 8A8B8G8R pixels to an XImage.
1936 */
1937 static void put_mono_row_8A8B8G8R_ximage( PUT_MONO_ROW_ARGS )
1938 {
1939 const GLubyte *color = (const GLubyte *) value;
1940 GET_XRB(xrb);
1941 XMesaContext xmesa = XMESA_CONTEXT(ctx);
1942 GLuint i, *ptr;
1943 const unsigned long pixel = xmesa_color_to_pixel(ctx, color[RCOMP],
1944 color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
1945 ptr = PIXEL_ADDR4(xrb, x, y );
1946 for (i=0;i<n;i++) {
1947 if (!mask || mask[i]) {
1948 ptr[i] = pixel;
1949 }
1950 }
1951 }
1952
1953 /*
1954 * Write a span of identical 8A8R8G8B pixels to an XImage.
1955 */
1956 static void put_mono_row_8A8R8G8B_ximage( PUT_MONO_ROW_ARGS )
1957 {
1958 const GLubyte *color = (const GLubyte *) value;
1959 GET_XRB(xrb);
1960 GLuint i, *ptr;
1961 XMesaContext xmesa = XMESA_CONTEXT(ctx);
1962 const unsigned long pixel = xmesa_color_to_pixel(ctx, color[RCOMP],
1963 color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
1964 ptr = PIXEL_ADDR4(xrb, x, y );
1965 for (i=0;i<n;i++) {
1966 if (!mask || mask[i]) {
1967 ptr[i] = pixel;
1968 }
1969 }
1970 }
1971
1972
1973 /*
1974 * Write a span of identical 8R8G8B pixels to an XImage.
1975 */
1976 static void put_mono_row_8R8G8B_ximage( PUT_MONO_ROW_ARGS )
1977 {
1978 const GLubyte *color = (const GLubyte *) value;
1979 GET_XRB(xrb);
1980 const GLuint pixel = PACK_8R8G8B(color[RCOMP], color[GCOMP], color[BCOMP]);
1981 GLuint *ptr = PIXEL_ADDR4(xrb, x, y );
1982 GLuint i;
1983 for (i=0;i<n;i++) {
1984 if (!mask || mask[i]) {
1985 ptr[i] = pixel;
1986 }
1987 }
1988 }
1989
1990
1991 /*
1992 * Write a span of identical 8R8G8B pixels to an XImage.
1993 */
1994 static void put_mono_row_8R8G8B24_ximage( PUT_MONO_ROW_ARGS )
1995 {
1996 const GLubyte *color = (const GLubyte *) value;
1997 GET_XRB(xrb);
1998 const GLubyte r = color[RCOMP];
1999 const GLubyte g = color[GCOMP];
2000 const GLubyte b = color[BCOMP];
2001 GLuint i;
2002 bgr_t *ptr = PIXEL_ADDR3(xrb, x, y );
2003 for (i=0;i<n;i++) {
2004 if (!mask || mask[i]) {
2005 ptr[i].r = r;
2006 ptr[i].g = g;
2007 ptr[i].b = b;
2008 }
2009 }
2010 }
2011
2012
2013 /*
2014 * Write a span of identical PF_DITHER_5R6G5B pixels to an XImage.
2015 */
2016 static void put_mono_row_DITHER_5R6G5B_ximage( PUT_MONO_ROW_ARGS )
2017 {
2018 const GLubyte *color = (const GLubyte *) value;
2019 GET_XRB(xrb);
2020 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2021 register GLushort *ptr = PIXEL_ADDR2(xrb, x, y );
2022 const GLint r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
2023 GLuint i;
2024 y = YFLIP(xrb, y);
2025 for (i=0;i<n;i++) {
2026 if (!mask || mask[i]) {
2027 PACK_TRUEDITHER(ptr[i], x+i, y, r, g, b);
2028 }
2029 }
2030 }
2031
2032
2033
2034 /**********************************************************************/
2035 /*** Write MONO COLOR PIXELS functions ***/
2036 /**********************************************************************/
2037
2038 #define PUT_MONO_VALUES_ARGS \
2039 struct gl_context *ctx, struct gl_renderbuffer *rb, \
2040 GLuint n, const GLint x[], const GLint y[], \
2041 const void *value, const GLubyte mask[]
2042
2043
2044
2045 /*
2046 * Write an array of identical pixels to a pixmap.
2047 */
2048 static void put_mono_values_pixmap( PUT_MONO_VALUES_ARGS )
2049 {
2050 const GLubyte *color = (const GLubyte *) value;
2051 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2052 GET_XRB(xrb);
2053 XMesaDisplay *dpy = xmesa->xm_visual->display;
2054 XMesaDrawable buffer = xrb->drawable;
2055 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2056 register GLuint i;
2057 const unsigned long pixel = xmesa_color_to_pixel(ctx, color[RCOMP],
2058 color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
2059 XMesaSetForeground( xmesa->display, gc, pixel );
2060 for (i=0;i<n;i++) {
2061 if (mask[i]) {
2062 XMesaDrawPoint( dpy, buffer, gc,
2063 (int) x[i], (int) YFLIP(xrb, y[i]) );
2064 }
2065 }
2066 }
2067
2068
2069 /*
2070 * Write an array of PF_TRUEDITHER pixels to a pixmap.
2071 */
2072 static void put_mono_values_TRUEDITHER_pixmap( PUT_MONO_VALUES_ARGS )
2073 {
2074 const GLubyte *color = (const GLubyte *) value;
2075 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2076 GET_XRB(xrb);
2077 XMesaDisplay *dpy = xmesa->xm_visual->display;
2078 XMesaDrawable buffer = xrb->drawable;
2079 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2080 register GLuint i;
2081 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
2082 for (i=0;i<n;i++) {
2083 if (mask[i]) {
2084 unsigned long p;
2085 PACK_TRUEDITHER(p, x[i], y[i], r, g, b);
2086 XMesaSetForeground( dpy, gc, p );
2087 XMesaDrawPoint( dpy, buffer, gc,
2088 (int) x[i], (int) YFLIP(xrb, y[i]) );
2089 }
2090 }
2091 }
2092
2093
2094 /*
2095 * Write an array of identical pixels to an XImage.
2096 */
2097 static void put_mono_values_ximage( PUT_MONO_VALUES_ARGS )
2098 {
2099 const GLubyte *color = (const GLubyte *) value;
2100 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2101 GET_XRB(xrb);
2102 XMesaImage *img = xrb->ximage;
2103 register GLuint i;
2104 const unsigned long pixel = xmesa_color_to_pixel(ctx, color[RCOMP],
2105 color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
2106 for (i=0;i<n;i++) {
2107 if (mask[i]) {
2108 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]), pixel );
2109 }
2110 }
2111 }
2112
2113
2114 /*
2115 * Write an array of identical TRUEDITHER pixels to an XImage.
2116 */
2117 static void put_mono_values_TRUEDITHER_ximage( PUT_MONO_VALUES_ARGS )
2118 {
2119 const GLubyte *color = (const GLubyte *) value;
2120 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2121 GET_XRB(xrb);
2122 XMesaImage *img = xrb->ximage;
2123 register GLuint i;
2124 const int r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
2125 for (i=0;i<n;i++) {
2126 if (mask[i]) {
2127 unsigned long p;
2128 PACK_TRUEDITHER(p, x[i], YFLIP(xrb, y[i]), r, g, b);
2129 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]), p );
2130 }
2131 }
2132 }
2133
2134
2135
2136 /*
2137 * Write an array of identical 8A8B8G8R pixels to an XImage
2138 */
2139 static void put_mono_values_8A8B8G8R_ximage( PUT_MONO_VALUES_ARGS )
2140 {
2141 const GLubyte *color = (const GLubyte *) value;
2142 GET_XRB(xrb);
2143 const GLuint p = PACK_8A8B8G8R(color[RCOMP], color[GCOMP],
2144 color[BCOMP], color[ACOMP]);
2145 register GLuint i;
2146 for (i=0;i<n;i++) {
2147 if (mask[i]) {
2148 GLuint *ptr = PIXEL_ADDR4(xrb, x[i], y[i] );
2149 *ptr = p;
2150 }
2151 }
2152 }
2153
2154 /*
2155 * Write an array of identical 8A8R8G8B pixels to an XImage
2156 */
2157 static void put_mono_values_8A8R8G8B_ximage( PUT_MONO_VALUES_ARGS )
2158 {
2159 const GLubyte *color = (const GLubyte *) value;
2160 GET_XRB(xrb);
2161 const GLuint p = PACK_8A8R8G8B(color[RCOMP], color[GCOMP],
2162 color[BCOMP], color[ACOMP]);
2163 register GLuint i;
2164 for (i=0;i<n;i++) {
2165 if (mask[i]) {
2166 GLuint *ptr = PIXEL_ADDR4(xrb, x[i], y[i] );
2167 *ptr = p;
2168 }
2169 }
2170 }
2171
2172 /*
2173 * Write an array of identical 8R8G8B pixels to an XImage.
2174 */
2175 static void put_mono_values_8R8G8B_ximage( PUT_MONO_VALUES_ARGS )
2176 {
2177 const GLubyte *color = (const GLubyte *) value;
2178 GET_XRB(xrb);
2179 register GLuint i;
2180 const GLuint p = PACK_8R8G8B(color[RCOMP], color[GCOMP], color[BCOMP]);
2181 for (i=0;i<n;i++) {
2182 if (mask[i]) {
2183 GLuint *ptr = PIXEL_ADDR4(xrb, x[i], y[i] );
2184 *ptr = p;
2185 }
2186 }
2187 }
2188
2189
2190 /*
2191 * Write an array of identical 8R8G8B pixels to an XImage.
2192 */
2193 static void put_mono_values_8R8G8B24_ximage( PUT_MONO_VALUES_ARGS )
2194 {
2195 const GLubyte *color = (const GLubyte *) value;
2196 GET_XRB(xrb);
2197 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
2198 register GLuint i;
2199 for (i=0;i<n;i++) {
2200 if (mask[i]) {
2201 bgr_t *ptr = PIXEL_ADDR3(xrb, x[i], y[i] );
2202 ptr->r = r;
2203 ptr->g = g;
2204 ptr->b = b;
2205 }
2206 }
2207 }
2208
2209
2210 /*
2211 * Write an array of identical PF_DITHER_5R6G5B pixels to an XImage.
2212 */
2213 static void put_mono_values_DITHER_5R6G5B_ximage( PUT_MONO_VALUES_ARGS )
2214 {
2215 const GLubyte *color = (const GLubyte *) value;
2216 GET_XRB(xrb);
2217 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2218 const int r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
2219 register GLuint i;
2220 for (i=0;i<n;i++) {
2221 if (mask[i]) {
2222 GLushort *ptr = PIXEL_ADDR2(xrb, x[i], y[i] );
2223 PACK_TRUEDITHER(*ptr, x[i], y[i], r, g, b);
2224 }
2225 }
2226 }
2227
2228
2229
2230 /**********************************************************************/
2231 /***** Pixel reading *****/
2232 /**********************************************************************/
2233
2234 /**
2235 * Do clip testing prior to calling XGetImage. If any of the region lies
2236 * outside the screen's bounds, XGetImage will return NULL.
2237 * We use XTranslateCoordinates() to check if that's the case and
2238 * adjust the x, y and length parameters accordingly.
2239 * \return -1 if span is totally clipped away,
2240 * else return number of pixels to skip in the destination array.
2241 */
2242 static int
2243 clip_for_xgetimage(struct gl_context *ctx, XMesaPixmap pixmap, GLuint *n, GLint *x, GLint *y)
2244 {
2245 XMesaContext xmesa = XMESA_CONTEXT(ctx);
2246 XMesaBuffer source = XMESA_BUFFER(ctx->DrawBuffer);
2247 Window rootWin = RootWindow(xmesa->display, 0);
2248 Window child;
2249 GLint screenWidth = WidthOfScreen(DefaultScreenOfDisplay(xmesa->display));
2250 GLint dx, dy;
2251 if (source->type == PBUFFER || source->type == PIXMAP)
2252 return 0;
2253 XTranslateCoordinates(xmesa->display, pixmap, rootWin,
2254 *x, *y, &dx, &dy, &child);
2255 if (dx >= screenWidth) {
2256 /* totally clipped on right */
2257 return -1;
2258 }
2259 if (dx < 0) {
2260 /* clipped on left */
2261 GLint clip = -dx;
2262 if (clip >= (GLint) *n)
2263 return -1; /* totally clipped on left */
2264 *x += clip;
2265 *n -= clip;
2266 dx = 0;
2267 return clip;
2268 }
2269 if ((GLint) (dx + *n) > screenWidth) {
2270 /* clipped on right */
2271 GLint clip = dx + *n - screenWidth;
2272 *n -= clip;
2273 }
2274 return 0;
2275 }
2276
2277
2278 /*
2279 * Read a horizontal span of color pixels.
2280 */
2281 static void
2282 get_row_rgba(struct gl_context *ctx, struct gl_renderbuffer *rb,
2283 GLuint n, GLint x, GLint y, void *values)
2284 {
2285 GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
2286 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2287 GET_XRB(xrb);
2288
2289 if (xrb->pixmap) {
2290 /* Read from Pixmap or Window */
2291 XMesaImage *span = NULL;
2292 int error;
2293 int k;
2294 y = YFLIP(xrb, y);
2295 k = clip_for_xgetimage(ctx, xrb->pixmap, &n, &x, &y);
2296 if (k < 0)
2297 return;
2298 rgba += k;
2299 catch_xgetimage_errors( xmesa->display );
2300 span = XGetImage( xmesa->display, xrb->pixmap,
2301 x, y, n, 1, AllPlanes, ZPixmap );
2302 error = check_xgetimage_errors();
2303 if (span && !error) {
2304 switch (xmesa->pixelformat) {
2305 case PF_Truecolor:
2306 case PF_Dither_True:
2307 {
2308 const GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
2309 const GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
2310 const GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
2311 unsigned long rMask = GET_REDMASK(xmesa->xm_visual);
2312 unsigned long gMask = GET_GREENMASK(xmesa->xm_visual);
2313 unsigned long bMask = GET_BLUEMASK(xmesa->xm_visual);
2314 GLint rShift = xmesa->xm_visual->rshift;
2315 GLint gShift = xmesa->xm_visual->gshift;
2316 GLint bShift = xmesa->xm_visual->bshift;
2317 GLuint i;
2318 for (i=0;i<n;i++) {
2319 unsigned long p;
2320 p = XMesaGetPixel( span, i, 0 );
2321 rgba[i][RCOMP] = pixelToR[(p & rMask) >> rShift];
2322 rgba[i][GCOMP] = pixelToG[(p & gMask) >> gShift];
2323 rgba[i][BCOMP] = pixelToB[(p & bMask) >> bShift];
2324 rgba[i][ACOMP] = 255;
2325 }
2326 }
2327 break;
2328 case PF_5R6G5B:
2329 case PF_Dither_5R6G5B:
2330 {
2331 const GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
2332 const GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
2333 const GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
2334 GLuint i;
2335 for (i=0;i<n;i++) {
2336 unsigned long p = XMesaGetPixel( span, i, 0 );
2337 /* fast, but not quite accurate
2338 rgba[i][RCOMP] = ((p >> 8) & 0xf8);
2339 rgba[i][GCOMP] = ((p >> 3) & 0xfc);
2340 rgba[i][BCOMP] = ((p << 3) & 0xff);
2341 */
2342 rgba[i][RCOMP] = pixelToR[p >> 11];
2343 rgba[i][GCOMP] = pixelToG[(p >> 5) & 0x3f];
2344 rgba[i][BCOMP] = pixelToB[p & 0x1f];
2345 rgba[i][ACOMP] = 255;
2346 }
2347 }
2348 break;
2349 case PF_8A8B8G8R:
2350 {
2351 const GLuint *ptr4 = (GLuint *) span->data;
2352 GLuint i;
2353 for (i=0;i<n;i++) {
2354 GLuint p4 = *ptr4++;
2355 rgba[i][RCOMP] = (GLubyte) ( p4 & 0xff);
2356 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
2357 rgba[i][BCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
2358 rgba[i][ACOMP] = (GLubyte) ((p4 >> 24) & 0xff);
2359 }
2360 }
2361 break;
2362 case PF_8A8R8G8B:
2363 {
2364 const GLuint *ptr4 = (GLuint *) span->data;
2365 GLuint i;
2366 for (i=0;i<n;i++) {
2367 GLuint p4 = *ptr4++;
2368 rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
2369 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
2370 rgba[i][BCOMP] = (GLubyte) ( p4 & 0xff);
2371 rgba[i][ACOMP] = (GLubyte) ((p4 >> 24) & 0xff);
2372 }
2373 }
2374 break;
2375 case PF_8R8G8B:
2376 {
2377 const GLuint *ptr4 = (GLuint *) span->data;
2378 GLuint i;
2379 for (i=0;i<n;i++) {
2380 GLuint p4 = *ptr4++;
2381 rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
2382 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
2383 rgba[i][BCOMP] = (GLubyte) ( p4 & 0xff);
2384 rgba[i][ACOMP] = 255;
2385 }
2386 }
2387 break;
2388 case PF_8R8G8B24:
2389 {
2390 const bgr_t *ptr3 = (bgr_t *) span->data;
2391 GLuint i;
2392 for (i=0;i<n;i++) {
2393 rgba[i][RCOMP] = ptr3[i].r;
2394 rgba[i][GCOMP] = ptr3[i].g;
2395 rgba[i][BCOMP] = ptr3[i].b;
2396 rgba[i][ACOMP] = 255;
2397 }
2398 }
2399 break;
2400 default:
2401 _mesa_problem(NULL,"Problem in DD.read_color_span (1)");
2402 return;
2403 }
2404 }
2405 else {
2406 /* return black pixels */
2407 GLuint i;
2408 for (i=0;i<n;i++) {
2409 rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = rgba[i][ACOMP] = 0;
2410 }
2411 }
2412 if (span) {
2413 XMesaDestroyImage( span );
2414 }
2415 }
2416 else if (xrb->ximage) {
2417 /* Read from XImage back buffer */
2418 switch (xmesa->pixelformat) {
2419 case PF_Truecolor:
2420 case PF_Dither_True:
2421 {
2422 const GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
2423 const GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
2424 const GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
2425 unsigned long rMask = GET_REDMASK(xmesa->xm_visual);
2426 unsigned long gMask = GET_GREENMASK(xmesa->xm_visual);
2427 unsigned long bMask = GET_BLUEMASK(xmesa->xm_visual);
2428 GLint rShift = xmesa->xm_visual->rshift;
2429 GLint gShift = xmesa->xm_visual->gshift;
2430 GLint bShift = xmesa->xm_visual->bshift;
2431 XMesaImage *img = xrb->ximage;
2432 GLuint i;
2433 y = YFLIP(xrb, y);
2434 for (i=0;i<n;i++) {
2435 unsigned long p;
2436 p = XMesaGetPixel( img, x+i, y );
2437 rgba[i][RCOMP] = pixelToR[(p & rMask) >> rShift];
2438 rgba[i][GCOMP] = pixelToG[(p & gMask) >> gShift];
2439 rgba[i][BCOMP] = pixelToB[(p & bMask) >> bShift];
2440 rgba[i][ACOMP] = 255;
2441 }
2442 }
2443 break;
2444 case PF_5R6G5B:
2445 case PF_Dither_5R6G5B:
2446 {
2447 const GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
2448 const GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
2449 const GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
2450 const GLushort *ptr2 = PIXEL_ADDR2(xrb, x, y);
2451 GLuint i;
2452 #if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
2453 const GLuint *ptr4 = (const GLuint *) ptr2;
2454 GLuint extraPixel = (n & 1);
2455 n -= extraPixel;
2456 for (i = 0; i < n; i += 2) {
2457 const GLuint p = *ptr4++;
2458 const GLuint p0 = p & 0xffff;
2459 const GLuint p1 = p >> 16;
2460 /* fast, but not quite accurate
2461 rgba[i][RCOMP] = ((p >> 8) & 0xf8);
2462 rgba[i][GCOMP] = ((p >> 3) & 0xfc);
2463 rgba[i][BCOMP] = ((p << 3) & 0xff);
2464 */
2465 rgba[i][RCOMP] = pixelToR[p0 >> 11];
2466 rgba[i][GCOMP] = pixelToG[(p0 >> 5) & 0x3f];
2467 rgba[i][BCOMP] = pixelToB[p0 & 0x1f];
2468 rgba[i][ACOMP] = 255;
2469 rgba[i+1][RCOMP] = pixelToR[p1 >> 11];
2470 rgba[i+1][GCOMP] = pixelToG[(p1 >> 5) & 0x3f];
2471 rgba[i+1][BCOMP] = pixelToB[p1 & 0x1f];
2472 rgba[i+1][ACOMP] = 255;
2473 }
2474 if (extraPixel) {
2475 GLushort p = ptr2[n];
2476 rgba[n][RCOMP] = pixelToR[p >> 11];
2477 rgba[n][GCOMP] = pixelToG[(p >> 5) & 0x3f];
2478 rgba[n][BCOMP] = pixelToB[p & 0x1f];
2479 rgba[n][ACOMP] = 255;
2480 }
2481 #else
2482 for (i = 0; i < n; i++) {
2483 const GLushort p = ptr2[i];
2484 rgba[i][RCOMP] = pixelToR[p >> 11];
2485 rgba[i][GCOMP] = pixelToG[(p >> 5) & 0x3f];
2486 rgba[i][BCOMP] = pixelToB[p & 0x1f];
2487 rgba[i][ACOMP] = 255;
2488 }
2489 #endif
2490 }
2491 break;
2492 case PF_8A8B8G8R:
2493 {
2494 const GLuint *ptr4 = PIXEL_ADDR4(xrb, x, y);
2495 GLuint i;
2496 for (i=0;i<n;i++) {
2497 GLuint p4 = *ptr4++;
2498 rgba[i][RCOMP] = (GLubyte) ( p4 & 0xff);
2499 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
2500 rgba[i][BCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
2501 rgba[i][ACOMP] = (GLint) ((p4 >> 24) & 0xff);
2502 }
2503 }
2504 break;
2505 case PF_8A8R8G8B:
2506 {
2507 const GLuint *ptr4 = PIXEL_ADDR4(xrb, x, y);
2508 GLuint i;
2509 for (i=0;i<n;i++) {
2510 GLuint p4 = *ptr4++;
2511 rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
2512 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
2513 rgba[i][BCOMP] = (GLubyte) ( p4 & 0xff);
2514 rgba[i][ACOMP] = (GLint) ((p4 >> 24) & 0xff);
2515 }
2516 }
2517 break;
2518 case PF_8R8G8B:
2519 {
2520 const GLuint *ptr4 = PIXEL_ADDR4(xrb, x, y);
2521 GLuint i;
2522 for (i=0;i<n;i++) {
2523 GLuint p4 = *ptr4++;
2524 rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
2525 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
2526 rgba[i][BCOMP] = (GLubyte) ( p4 & 0xff);
2527 rgba[i][ACOMP] = 255;
2528 }
2529 }
2530 break;
2531 case PF_8R8G8B24:
2532 {
2533 const bgr_t *ptr3 = PIXEL_ADDR3(xrb, x, y);
2534 GLuint i;
2535 for (i=0;i<n;i++) {
2536 rgba[i][RCOMP] = ptr3[i].r;
2537 rgba[i][GCOMP] = ptr3[i].g;
2538 rgba[i][BCOMP] = ptr3[i].b;
2539 rgba[i][ACOMP] = 255;
2540 }
2541 }
2542 break;
2543 default:
2544 _mesa_problem(NULL,"Problem in DD.read_color_span (2)");
2545 return;
2546 }
2547 }
2548 }
2549
2550
2551
2552 static void
2553 get_values_rgba(struct gl_context *ctx, struct gl_renderbuffer *rb,
2554 GLuint n, const GLint x[], const GLint y[], void *values)
2555 {
2556 GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
2557 GET_XRB(xrb);
2558 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2559 XMesaDisplay *dpy = xmesa->xm_visual->display;
2560 register GLuint i;
2561
2562 if (xrb->pixmap) {
2563 XMesaDrawable buffer = xrb->drawable;
2564 switch (xmesa->pixelformat) {
2565 case PF_Truecolor:
2566 case PF_Dither_True:
2567 case PF_5R6G5B:
2568 case PF_Dither_5R6G5B:
2569 {
2570 unsigned long rMask = GET_REDMASK(xmesa->xm_visual);
2571 unsigned long gMask = GET_GREENMASK(xmesa->xm_visual);
2572 unsigned long bMask = GET_BLUEMASK(xmesa->xm_visual);
2573 GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
2574 GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
2575 GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
2576 GLint rShift = xmesa->xm_visual->rshift;
2577 GLint gShift = xmesa->xm_visual->gshift;
2578 GLint bShift = xmesa->xm_visual->bshift;
2579 for (i=0;i<n;i++) {
2580 unsigned long p = read_pixel( dpy, buffer,
2581 x[i], YFLIP(xrb, y[i]) );
2582 rgba[i][RCOMP] = pixelToR[(p & rMask) >> rShift];
2583 rgba[i][GCOMP] = pixelToG[(p & gMask) >> gShift];
2584 rgba[i][BCOMP] = pixelToB[(p & bMask) >> bShift];
2585 rgba[i][ACOMP] = 255;
2586 }
2587 }
2588 break;
2589 case PF_8A8B8G8R:
2590 for (i=0;i<n;i++) {
2591 unsigned long p = read_pixel( dpy, buffer,
2592 x[i], YFLIP(xrb, y[i]) );
2593 rgba[i][RCOMP] = (GLubyte) ( p & 0xff);
2594 rgba[i][GCOMP] = (GLubyte) ((p >> 8) & 0xff);
2595 rgba[i][BCOMP] = (GLubyte) ((p >> 16) & 0xff);
2596 rgba[i][ACOMP] = (GLubyte) ((p >> 24) & 0xff);
2597 }
2598 break;
2599 case PF_8A8R8G8B:
2600 for (i=0;i<n;i++) {
2601 unsigned long p = read_pixel( dpy, buffer,
2602 x[i], YFLIP(xrb, y[i]) );
2603 rgba[i][RCOMP] = (GLubyte) ((p >> 16) & 0xff);
2604 rgba[i][GCOMP] = (GLubyte) ((p >> 8) & 0xff);
2605 rgba[i][BCOMP] = (GLubyte) ( p & 0xff);
2606 rgba[i][ACOMP] = (GLubyte) ((p >> 24) & 0xff);
2607 }
2608 break;
2609 case PF_8R8G8B:
2610 for (i=0;i<n;i++) {
2611 unsigned long p = read_pixel( dpy, buffer,
2612 x[i], YFLIP(xrb, y[i]) );
2613 rgba[i][RCOMP] = (GLubyte) ((p >> 16) & 0xff);
2614 rgba[i][GCOMP] = (GLubyte) ((p >> 8) & 0xff);
2615 rgba[i][BCOMP] = (GLubyte) ( p & 0xff);
2616 rgba[i][ACOMP] = 255;
2617 }
2618 break;
2619 case PF_8R8G8B24:
2620 for (i=0;i<n;i++) {
2621 unsigned long p = read_pixel( dpy, buffer,
2622 x[i], YFLIP(xrb, y[i]) );
2623 rgba[i][RCOMP] = (GLubyte) ((p >> 16) & 0xff);
2624 rgba[i][GCOMP] = (GLubyte) ((p >> 8) & 0xff);
2625 rgba[i][BCOMP] = (GLubyte) ( p & 0xff);
2626 rgba[i][ACOMP] = 255;
2627 }
2628 break;
2629 default:
2630 _mesa_problem(NULL,"Problem in DD.read_color_pixels (1)");
2631 return;
2632 }
2633 }
2634 else if (xrb->ximage) {
2635 /* Read from XImage back buffer */
2636 switch (xmesa->pixelformat) {
2637 case PF_Truecolor:
2638 case PF_Dither_True:
2639 case PF_5R6G5B:
2640 case PF_Dither_5R6G5B:
2641 {
2642 unsigned long rMask = GET_REDMASK(xmesa->xm_visual);
2643 unsigned long gMask = GET_GREENMASK(xmesa->xm_visual);
2644 unsigned long bMask = GET_BLUEMASK(xmesa->xm_visual);
2645 GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
2646 GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
2647 GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
2648 GLint rShift = xmesa->xm_visual->rshift;
2649 GLint gShift = xmesa->xm_visual->gshift;
2650 GLint bShift = xmesa->xm_visual->bshift;
2651 XMesaImage *img = xrb->ximage;
2652 for (i=0;i<n;i++) {
2653 unsigned long p;
2654 p = XMesaGetPixel( img, x[i], YFLIP(xrb, y[i]) );
2655 rgba[i][RCOMP] = pixelToR[(p & rMask) >> rShift];
2656 rgba[i][GCOMP] = pixelToG[(p & gMask) >> gShift];
2657 rgba[i][BCOMP] = pixelToB[(p & bMask) >> bShift];
2658 rgba[i][ACOMP] = 255;
2659 }
2660 }
2661 break;
2662 case PF_8A8B8G8R:
2663 for (i=0;i<n;i++) {
2664 GLuint *ptr4 = PIXEL_ADDR4(xrb, x[i], y[i]);
2665 GLuint p4 = *ptr4;
2666 rgba[i][RCOMP] = (GLubyte) ( p4 & 0xff);
2667 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
2668 rgba[i][BCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
2669 rgba[i][ACOMP] = (GLubyte) ((p4 >> 24) & 0xff);
2670 }
2671 break;
2672 case PF_8A8R8G8B:
2673 for (i=0;i<n;i++) {
2674 GLuint *ptr4 = PIXEL_ADDR4(xrb, x[i], y[i]);
2675 GLuint p4 = *ptr4;
2676 rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
2677 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
2678 rgba[i][BCOMP] = (GLubyte) ( p4 & 0xff);
2679 rgba[i][ACOMP] = (GLubyte) ((p4 >> 24) & 0xff);
2680 }
2681 break;
2682 case PF_8R8G8B:
2683 for (i=0;i<n;i++) {
2684 GLuint *ptr4 = PIXEL_ADDR4(xrb, x[i], y[i]);
2685 GLuint p4 = *ptr4;
2686 rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
2687 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
2688 rgba[i][BCOMP] = (GLubyte) ( p4 & 0xff);
2689 rgba[i][ACOMP] = 255;
2690 }
2691 break;
2692 case PF_8R8G8B24:
2693 for (i=0;i<n;i++) {
2694 bgr_t *ptr3 = PIXEL_ADDR3(xrb, x[i], y[i]);
2695 rgba[i][RCOMP] = ptr3->r;
2696 rgba[i][GCOMP] = ptr3->g;
2697 rgba[i][BCOMP] = ptr3->b;
2698 rgba[i][ACOMP] = 255;
2699 }
2700 break;
2701 default:
2702 _mesa_problem(NULL,"Problem in DD.read_color_pixels (1)");
2703 return;
2704 }
2705 }
2706 }
2707
2708
2709 /**
2710 * Initialize the renderbuffer's PutRow, GetRow, etc. functions.
2711 * This would generally only need to be called once when the renderbuffer
2712 * is created. However, we can change pixel formats on the fly if dithering
2713 * is enabled/disabled. Therefore, we may call this more often than that.
2714 */
2715 void
2716 xmesa_set_renderbuffer_funcs(struct xmesa_renderbuffer *xrb,
2717 enum pixel_format pixelformat, GLint depth)
2718 {
2719 const GLboolean pixmap = xrb->pixmap ? GL_TRUE : GL_FALSE;
2720
2721 switch (pixelformat) {
2722 case PF_Truecolor:
2723 if (pixmap) {
2724 xrb->Base.PutRow = put_row_TRUECOLOR_pixmap;
2725 xrb->Base.PutRowRGB = put_row_rgb_TRUECOLOR_pixmap;
2726 xrb->Base.PutMonoRow = put_mono_row_pixmap;
2727 xrb->Base.PutValues = put_values_TRUECOLOR_pixmap;
2728 xrb->Base.PutMonoValues = put_mono_values_pixmap;
2729 }
2730 else {
2731 xrb->Base.PutRow = put_row_TRUECOLOR_ximage;
2732 xrb->Base.PutRowRGB = put_row_rgb_TRUECOLOR_ximage;
2733 xrb->Base.PutMonoRow = put_mono_row_ximage;
2734 xrb->Base.PutValues = put_values_TRUECOLOR_ximage;
2735 xrb->Base.PutMonoValues = put_mono_values_ximage;
2736 }
2737 break;
2738 case PF_Dither_True:
2739 if (pixmap) {
2740 xrb->Base.PutRow = put_row_TRUEDITHER_pixmap;
2741 xrb->Base.PutRowRGB = put_row_rgb_TRUEDITHER_pixmap;
2742 xrb->Base.PutMonoRow = put_mono_row_TRUEDITHER_pixmap;
2743 xrb->Base.PutValues = put_values_TRUEDITHER_pixmap;
2744 xrb->Base.PutMonoValues = put_mono_values_TRUEDITHER_pixmap;
2745 }
2746 else {
2747 xrb->Base.PutRow = put_row_TRUEDITHER_ximage;
2748 xrb->Base.PutRowRGB = put_row_rgb_TRUEDITHER_ximage;
2749 xrb->Base.PutMonoRow = put_mono_row_TRUEDITHER_ximage;
2750 xrb->Base.PutValues = put_values_TRUEDITHER_ximage;
2751 xrb->Base.PutMonoValues = put_mono_values_TRUEDITHER_ximage;
2752 }
2753 break;
2754 case PF_8A8B8G8R:
2755 if (pixmap) {
2756 xrb->Base.PutRow = put_row_8A8B8G8R_pixmap;
2757 xrb->Base.PutRowRGB = put_row_rgb_8A8B8G8R_pixmap;
2758 xrb->Base.PutMonoRow = put_mono_row_pixmap;
2759 xrb->Base.PutValues = put_values_8A8B8G8R_pixmap;
2760 xrb->Base.PutMonoValues = put_mono_values_pixmap;
2761 }
2762 else {
2763 xrb->Base.PutRow = put_row_8A8B8G8R_ximage;
2764 xrb->Base.PutRowRGB = put_row_rgb_8A8B8G8R_ximage;
2765 xrb->Base.PutMonoRow = put_mono_row_8A8B8G8R_ximage;
2766 xrb->Base.PutValues = put_values_8A8B8G8R_ximage;
2767 xrb->Base.PutMonoValues = put_mono_values_8A8B8G8R_ximage;
2768 }
2769 break;
2770 case PF_8A8R8G8B:
2771 if (pixmap) {
2772 xrb->Base.PutRow = put_row_8A8R8G8B_pixmap;
2773 xrb->Base.PutRowRGB = put_row_rgb_8A8R8G8B_pixmap;
2774 xrb->Base.PutMonoRow = put_mono_row_pixmap;
2775 xrb->Base.PutValues = put_values_8A8R8G8B_pixmap;
2776 xrb->Base.PutMonoValues = put_mono_values_pixmap;
2777 }
2778 else {
2779 xrb->Base.PutRow = put_row_8A8R8G8B_ximage;
2780 xrb->Base.PutRowRGB = put_row_rgb_8A8R8G8B_ximage;
2781 xrb->Base.PutMonoRow = put_mono_row_8A8R8G8B_ximage;
2782 xrb->Base.PutValues = put_values_8A8R8G8B_ximage;
2783 xrb->Base.PutMonoValues = put_mono_values_8A8R8G8B_ximage;
2784 }
2785 break;
2786 case PF_8R8G8B:
2787 if (pixmap) {
2788 xrb->Base.PutRow = put_row_8R8G8B_pixmap;
2789 xrb->Base.PutRowRGB = put_row_rgb_8R8G8B_pixmap;
2790 xrb->Base.PutMonoRow = put_mono_row_pixmap;
2791 xrb->Base.PutValues = put_values_8R8G8B_pixmap;
2792 xrb->Base.PutMonoValues = put_mono_values_pixmap;
2793 }
2794 else {
2795 xrb->Base.PutRow = put_row_8R8G8B_ximage;
2796 xrb->Base.PutRowRGB = put_row_rgb_8R8G8B_ximage;
2797 xrb->Base.PutMonoRow = put_mono_row_8R8G8B_ximage;
2798 xrb->Base.PutValues = put_values_8R8G8B_ximage;
2799 xrb->Base.PutMonoValues = put_mono_values_8R8G8B_ximage;
2800 }
2801 break;
2802 case PF_8R8G8B24:
2803 if (pixmap) {
2804 xrb->Base.PutRow = put_row_8R8G8B24_pixmap;
2805 xrb->Base.PutRowRGB = put_row_rgb_8R8G8B24_pixmap;
2806 xrb->Base.PutMonoRow = put_mono_row_pixmap;
2807 xrb->Base.PutValues = put_values_8R8G8B24_pixmap;
2808 xrb->Base.PutMonoValues = put_mono_values_pixmap;
2809 }
2810 else {
2811 xrb->Base.PutRow = put_row_8R8G8B24_ximage;
2812 xrb->Base.PutRowRGB = put_row_rgb_8R8G8B24_ximage;
2813 xrb->Base.PutMonoRow = put_mono_row_8R8G8B24_ximage;
2814 xrb->Base.PutValues = put_values_8R8G8B24_ximage;
2815 xrb->Base.PutMonoValues = put_mono_values_8R8G8B24_ximage;
2816 }
2817 break;
2818 case PF_5R6G5B:
2819 if (pixmap) {
2820 xrb->Base.PutRow = put_row_5R6G5B_pixmap;
2821 xrb->Base.PutRowRGB = put_row_rgb_5R6G5B_pixmap;
2822 xrb->Base.PutMonoRow = put_mono_row_pixmap;
2823 xrb->Base.PutValues = put_values_5R6G5B_pixmap;
2824 xrb->Base.PutMonoValues = put_mono_values_pixmap;
2825 }
2826 else {
2827 xrb->Base.PutRow = put_row_5R6G5B_ximage;
2828 xrb->Base.PutRowRGB = put_row_rgb_5R6G5B_ximage;
2829 xrb->Base.PutMonoRow = put_mono_row_ximage;
2830 xrb->Base.PutValues = put_values_5R6G5B_ximage;
2831 xrb->Base.PutMonoValues = put_mono_values_ximage;
2832 }
2833 break;
2834 case PF_Dither_5R6G5B:
2835 if (pixmap) {
2836 xrb->Base.PutRow = put_row_DITHER_5R6G5B_pixmap;
2837 xrb->Base.PutRowRGB = put_row_rgb_DITHER_5R6G5B_pixmap;
2838 xrb->Base.PutMonoRow = put_mono_row_TRUEDITHER_pixmap;
2839 xrb->Base.PutValues = put_values_DITHER_5R6G5B_pixmap;
2840 xrb->Base.PutMonoValues = put_mono_values_TRUEDITHER_pixmap;
2841 }
2842 else {
2843 xrb->Base.PutRow = put_row_DITHER_5R6G5B_ximage;
2844 xrb->Base.PutRowRGB = put_row_rgb_DITHER_5R6G5B_ximage;
2845 xrb->Base.PutMonoRow = put_mono_row_DITHER_5R6G5B_ximage;
2846 xrb->Base.PutValues = put_values_DITHER_5R6G5B_ximage;
2847 xrb->Base.PutMonoValues = put_mono_values_DITHER_5R6G5B_ximage;
2848 }
2849 break;
2850 default:
2851 _mesa_problem(NULL, "Bad pixel format in xmesa_update_state (1)");
2852 return;
2853 }
2854
2855
2856 /* Get functions */
2857 xrb->Base.GetRow = get_row_rgba;
2858 xrb->Base.GetValues = get_values_rgba;
2859 }
2860