xm_dd.c revision b1d0ac64ab2e8285fd8a1f6b52f86a967162ae35
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
26#include "glxheader.h"
27#include "bufferobj.h"
28#include "buffers.h"
29#include "context.h"
30#include "colormac.h"
31#include "depth.h"
32#include "drawpix.h"
33#include "extensions.h"
34#include "framebuffer.h"
35#include "macros.h"
36#include "image.h"
37#include "imports.h"
38#include "mtypes.h"
39#include "state.h"
40#include "texobj.h"
41#include "teximage.h"
42#include "texstore.h"
43#include "texformat.h"
44#include "xmesaP.h"
45#include "array_cache/acache.h"
46#include "swrast/swrast.h"
47#include "swrast/s_context.h"
48#include "swrast_setup/swrast_setup.h"
49#include "tnl/tnl.h"
50#include "tnl/t_context.h"
51
52#ifdef XFree86Server
53#include <GL/glxtokens.h>
54#endif
55
56
57
58/*
59 * Dithering kernels and lookup tables.
60 */
61
62const int xmesa_kernel8[DITH_DY * DITH_DX] = {
63    0 * MAXC,  8 * MAXC,  2 * MAXC, 10 * MAXC,
64   12 * MAXC,  4 * MAXC, 14 * MAXC,  6 * MAXC,
65    3 * MAXC, 11 * MAXC,  1 * MAXC,  9 * MAXC,
66   15 * MAXC,  7 * MAXC, 13 * MAXC,  5 * MAXC,
67};
68
69const short xmesa_HPCR_DRGB[3][2][16] = {
70   {
71      { 16, -4,  1,-11, 14, -6,  3, -9, 15, -5,  2,-10, 13, -7,  4, -8},
72      {-15,  5,  0, 12,-13,  7, -2, 10,-14,  6, -1, 11,-12,  8, -3,  9}
73   },
74   {
75      {-11, 15, -7,  3, -8, 14, -4,  2,-10, 16, -6,  4, -9, 13, -5,  1},
76      { 12,-14,  8, -2,  9,-13,  5, -1, 11,-15,  7, -3, 10,-12,  6,  0}
77   },
78   {
79      {  6,-18, 26,-14,  2,-22, 30,-10,  8,-16, 28,-12,  4,-20, 32, -8},
80      { -4, 20,-24, 16,  0, 24,-28, 12, -6, 18,-26, 14, -2, 22,-30, 10}
81   }
82};
83
84const int xmesa_kernel1[16] = {
85   0*47,  9*47,  4*47, 12*47,     /* 47 = (255*3)/16 */
86   6*47,  2*47, 14*47,  8*47,
87  10*47,  1*47,  5*47, 11*47,
88   7*47, 13*47,  3*47, 15*47
89};
90
91
92/*
93 * Return the size (width, height) of the X window for the given GLframebuffer.
94 * Output:  width - width of buffer in pixels.
95 *          height - height of buffer in pixels.
96 */
97static void
98get_buffer_size( GLframebuffer *buffer, GLuint *width, GLuint *height )
99{
100   /* We can do this cast because the first field in the XMesaBuffer
101    * struct is a GLframebuffer struct.  If this weren't true, we'd
102    * need a pointer from the GLframebuffer to the XMesaBuffer.
103    */
104   const XMesaBuffer xmBuffer = (XMesaBuffer) buffer;
105   unsigned int winwidth, winheight;
106#ifdef XFree86Server
107   /* XFree86 GLX renderer */
108   winwidth = MIN2(xmBuffer->frontxrb->pixmap->width, MAX_WIDTH);
109   winheight = MIN2(xmBuffer->frontxrb->pixmap->height, MAX_HEIGHT);
110#else
111   Window root;
112   int winx, winy;
113   unsigned int bw, d;
114
115   _glthread_LOCK_MUTEX(_xmesa_lock);
116   XSync(xmBuffer->xm_visual->display, 0); /* added for Chromium */
117   XGetGeometry( xmBuffer->xm_visual->display, xmBuffer->frontxrb->pixmap, &root,
118		 &winx, &winy, &winwidth, &winheight, &bw, &d );
119   _glthread_UNLOCK_MUTEX(_xmesa_lock);
120#endif
121
122   *width = winwidth;
123   *height = winheight;
124}
125
126
127static void
128finish_or_flush( GLcontext *ctx )
129{
130#ifdef XFree86Server
131      /* NOT_NEEDED */
132#else
133   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
134   if (xmesa) {
135      _glthread_LOCK_MUTEX(_xmesa_lock);
136      XSync( xmesa->display, False );
137      _glthread_UNLOCK_MUTEX(_xmesa_lock);
138   }
139#endif
140}
141
142
143
144/**
145 * This chooses the color buffer for reading and writing spans, points,
146 * lines, and triangles.
147 * Remember that a GLframebuffer has several distinct color buffers:
148 * front/left, front/right, back/left, back/right and aux buffers.
149 * The bufferBit specifies which one to use.
150 */
151void
152xmesa_set_buffer( GLcontext *ctx, GLframebuffer *buffer, GLuint bufferBit )
153{
154#if 000
155   /* We can make this cast since the XMesaBuffer wraps GLframebuffer.
156    * GLframebuffer is the first member in a XMesaBuffer struct.
157    */
158   XMesaBuffer target = (XMesaBuffer) buffer;
159   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
160
161#if NEW_RENDERBUFFER
162   if (buffer->Name != 0)
163      return;
164#endif
165
166   /* This assignment tells the span/point/line/triangle functions
167    * which XMesaBuffer to use.
168    */
169   /*   xmesa->xm_buffer = target;*/
170
171   /*
172    * Now determine front vs back color buffer.
173    */
174   if (bufferBit == BUFFER_BIT_FRONT_LEFT) {
175      target->buffer = target->frontxrb->pixmap;
176      printf("set get/put!\n");
177      xmesa_update_span_funcs(ctx);
178   }
179   else if (bufferBit == BUFFER_BIT_BACK_LEFT) {
180      ASSERT(target->db_state);
181      if (target->backxrb->pixmap) {
182         /* back buffer is a pixmap */
183         target->buffer = (XMesaDrawable) target->backxrb->pixmap;
184      }
185      else if (target->backimage) {
186         /* back buffer is an XImage */
187         target->buffer = None;
188      }
189      else {
190         /* No back buffer!!!!  Must be out of memory, use front buffer */
191         target->buffer = target->frontxrb->pixmap;
192      }
193      printf("set get/put!\n");
194      xmesa_update_span_funcs(ctx);
195   }
196   else if (bufferBit & (BUFFER_BIT_AUX0 | BUFFER_BIT_AUX1 | BUFFER_BIT_AUX2 | BUFFER_BIT_AUX3)) {
197      /*_swrast_use_aux_buffer(ctx, buffer, bufferBit);*/
198   }
199   else {
200      _mesa_problem(ctx, "invalid buffer 0x%x in set_buffer() in xm_dd.c");
201      return;
202   }
203#endif
204}
205
206
207
208static void
209clear_index( GLcontext *ctx, GLuint index )
210{
211   if (ctx->DrawBuffer->Name == 0) {
212      const XMesaContext xmesa = XMESA_CONTEXT(ctx);
213      XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer);
214      xmesa->clearpixel = (unsigned long) index;
215      XMesaSetForeground( xmesa->display, xmbuf->cleargc, (unsigned long) index );
216   }
217}
218
219
220static void
221clear_color( GLcontext *ctx, const GLfloat color[4] )
222{
223   if (ctx->DrawBuffer->Name == 0) {
224      const XMesaContext xmesa = XMESA_CONTEXT(ctx);
225      XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer);
226
227      CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[0], color[0]);
228      CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[1], color[1]);
229      CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[2], color[2]);
230      CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[3], color[3]);
231      xmesa->clearpixel = xmesa_color_to_pixel( ctx,
232                                                xmesa->clearcolor[0],
233                                                xmesa->clearcolor[1],
234                                                xmesa->clearcolor[2],
235                                                xmesa->clearcolor[3],
236                                                xmesa->xm_visual->undithered_pf );
237      _glthread_LOCK_MUTEX(_xmesa_lock);
238      XMesaSetForeground( xmesa->display, xmbuf->cleargc,
239                          xmesa->clearpixel );
240      _glthread_UNLOCK_MUTEX(_xmesa_lock);
241   }
242}
243
244
245
246/* Set index mask ala glIndexMask */
247static void
248index_mask( GLcontext *ctx, GLuint mask )
249{
250   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
251   XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer);
252   /* not sure this conditional is really needed */
253   if (xmbuf->backxrb && xmbuf->backxrb->pixmap) {
254      unsigned long m;
255      if (mask==0xffffffff) {
256	 m = ((unsigned long)~0L);
257      }
258      else {
259         m = (unsigned long) mask;
260      }
261      XMesaSetPlaneMask( xmesa->display, xmbuf->cleargc, m );
262      XMesaSetPlaneMask( xmesa->display, xmbuf->gc, m );
263   }
264}
265
266
267/* Implements glColorMask() */
268static void
269color_mask(GLcontext *ctx,
270           GLboolean rmask, GLboolean gmask, GLboolean bmask, GLboolean amask)
271{
272   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
273   XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer);
274   const int xclass = xmesa->xm_visual->mesa_visual.visualType;
275   (void) amask;
276
277   if (xclass == GLX_TRUE_COLOR || xclass == GLX_DIRECT_COLOR) {
278      unsigned long m;
279      if (rmask && gmask && bmask) {
280         m = ((unsigned long)~0L);
281      }
282      else {
283         m = 0;
284         if (rmask)   m |= GET_REDMASK(xmesa->xm_visual);
285         if (gmask)   m |= GET_GREENMASK(xmesa->xm_visual);
286         if (bmask)   m |= GET_BLUEMASK(xmesa->xm_visual);
287      }
288      XMesaSetPlaneMask( xmesa->display, xmbuf->cleargc, m );
289      XMesaSetPlaneMask( xmesa->display, xmbuf->gc, m );
290   }
291}
292
293
294
295/**********************************************************************/
296/*** glClear implementations                                        ***/
297/**********************************************************************/
298
299
300/**
301 * Clear the front or back color buffer, if it's implemented with a pixmap.
302 */
303static void
304clear_pixmap(GLcontext *ctx, struct xmesa_renderbuffer *xrb, GLboolean all,
305             GLint x, GLint y, GLint width, GLint height)
306{
307   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
308   XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer);
309
310   assert(xmbuf);
311   assert(xrb->pixmap);
312   assert(xmesa);
313   assert(xmesa->display);
314   assert(xrb->pixmap);
315   assert(xmbuf->cleargc);
316
317   if (all) {
318      XMesaFillRectangle( xmesa->display, xrb->pixmap, xmbuf->cleargc,
319                          0, 0, xrb->Base.Width + 1, xrb->Base.Height + 1 );
320   }
321   else {
322      XMesaFillRectangle( xmesa->display, xrb->pixmap, xmbuf->cleargc,
323                          x, xrb->Base.Height - y - height,
324                          width, height );
325   }
326}
327
328
329static void
330clear_8bit_ximage( GLcontext *ctx, struct xmesa_renderbuffer *xrb,
331                   GLboolean all, GLint x, GLint y, GLint width, GLint height )
332{
333   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
334
335   if (all) {
336      const size_t n = xrb->ximage->bytes_per_line * xrb->Base.Height;
337      MEMSET( xrb->ximage->data, xmesa->clearpixel, n );
338   }
339   else {
340      GLint i;
341      for (i=0;i<height;i++) {
342         GLubyte *ptr = PIXEL_ADDR1(xrb, x, y + i);
343         MEMSET( ptr, xmesa->clearpixel, width );
344      }
345   }
346}
347
348
349static void
350clear_HPCR_ximage( GLcontext *ctx, struct xmesa_renderbuffer *xrb,
351                   GLboolean all, GLint x, GLint y, GLint width, GLint height )
352{
353   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
354
355   if (all) {
356      GLint i, c16 = (xrb->ximage->bytes_per_line>>4)<<4;
357      GLubyte *ptr  = (GLubyte *) xrb->ximage->data;
358      for (i = 0; i < xrb->Base.Height; i++) {
359         GLint j;
360         GLubyte *sptr = xmesa->xm_visual->hpcr_clear_ximage_pattern[0];
361         if (i&1) {
362            sptr += 16;
363         }
364         for (j=0; j<c16; j+=16) {
365            ptr[0] = sptr[0];
366            ptr[1] = sptr[1];
367            ptr[2] = sptr[2];
368            ptr[3] = sptr[3];
369            ptr[4] = sptr[4];
370            ptr[5] = sptr[5];
371            ptr[6] = sptr[6];
372            ptr[7] = sptr[7];
373            ptr[8] = sptr[8];
374            ptr[9] = sptr[9];
375            ptr[10] = sptr[10];
376            ptr[11] = sptr[11];
377            ptr[12] = sptr[12];
378            ptr[13] = sptr[13];
379            ptr[14] = sptr[14];
380            ptr[15] = sptr[15];
381            ptr += 16;
382         }
383         for (; j < xrb->ximage->bytes_per_line; j++) {
384            *ptr = sptr[j&15];
385            ptr++;
386         }
387      }
388   }
389   else {
390      GLint i;
391      for (i=y; i<y+height; i++) {
392         GLubyte *ptr = PIXEL_ADDR1( xrb, x, i );
393         int j;
394         const GLubyte *sptr = xmesa->xm_visual->hpcr_clear_ximage_pattern[0];
395         if (i&1) {
396            sptr += 16;
397         }
398         for (j=x; j<x+width; j++) {
399            *ptr = sptr[j&15];
400            ptr++;
401         }
402      }
403   }
404}
405
406
407static void
408clear_16bit_ximage( GLcontext *ctx, struct xmesa_renderbuffer *xrb,
409                    GLboolean all, GLint x, GLint y, GLint width, GLint height)
410{
411   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
412   register GLuint pixel = (GLuint) xmesa->clearpixel;
413
414   if (xmesa->swapbytes) {
415      pixel = ((pixel >> 8) & 0x00ff) | ((pixel << 8) & 0xff00);
416   }
417
418   if (all) {
419      GLuint *ptr4 = (GLuint *) xrb->ximage->data;
420      if ((pixel & 0xff) == ((pixel >> 8) & 0xff)) {
421         /* low and high bytes are equal so use memset() */
422         const GLuint n = xrb->ximage->bytes_per_line * xrb->Base.Height;
423         MEMSET( ptr4, pixel & 0xff, n );
424      }
425      else {
426         const GLuint n = xrb->ximage->bytes_per_line * xrb->Base.Height / 4;
427         GLuint i;
428         pixel = pixel | (pixel<<16);
429         for (i = 0; i < n; i++) {
430            ptr4[i] = pixel;
431         }
432         ptr4 += n;
433         /* might be one last GLushort to set */
434         if ((xrb->ximage->bytes_per_line * xrb->Base.Height) & 0x2)
435            *(GLushort *)ptr4 = pixel & 0xffff;
436      }
437   }
438   else {
439      GLint i, j;
440      for (j=0;j<height;j++) {
441         GLushort *ptr2 = PIXEL_ADDR2(xrb, x, y + j);
442         for (i=0;i<width;i++) {
443            *ptr2++ = pixel;
444         }
445      }
446   }
447}
448
449
450/* Optimized code provided by Nozomi Ytow <noz@xfree86.org> */
451static void
452clear_24bit_ximage(GLcontext *ctx, struct xmesa_renderbuffer *xrb,
453                   GLboolean all, GLint x, GLint y, GLint width, GLint height)
454{
455   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
456   const GLubyte r = xmesa->clearcolor[0];
457   const GLubyte g = xmesa->clearcolor[1];
458   const GLubyte b = xmesa->clearcolor[2];
459
460   if (all) {
461      if (r == g && g == b) {
462         /* same value for all three components (gray) */
463         const GLint w3 = xrb->Base.Width * 3;
464         const GLint h = xrb->Base.Height;
465         GLint i;
466         for (i = 0; i < h; i++) {
467            bgr_t *ptr3 = PIXEL_ADDR3(xrb, 0, i);
468            MEMSET(ptr3, r, w3);
469         }
470      }
471      else {
472         /* the usual case */
473         const GLint w = xrb->Base.Width;
474         const GLint h = xrb->Base.Height;
475         GLint i, j;
476         for (i = 0; i < h; i++) {
477            bgr_t *ptr3 = PIXEL_ADDR3(xrb, 0, i);
478            for (j = 0; j < w; j++) {
479               ptr3->r = r;
480               ptr3->g = g;
481               ptr3->b = b;
482               ptr3++;
483            }
484         }
485      }
486   }
487   else {
488      /* only clear subrect of color buffer */
489      if (r == g && g == b) {
490         /* same value for all three components (gray) */
491         GLint j;
492         for (j=0;j<height;j++) {
493            bgr_t *ptr3 = PIXEL_ADDR3(xrb, x, y + j);
494            MEMSET(ptr3, r, 3 * width);
495         }
496      }
497      else {
498         /* non-gray clear color */
499         GLint i, j;
500         for (j = 0; j < height; j++) {
501            bgr_t *ptr3 = PIXEL_ADDR3(xrb, x, y + j);
502            for (i = 0; i < width; i++) {
503               ptr3->r = r;
504               ptr3->g = g;
505               ptr3->b = b;
506               ptr3++;
507            }
508         }
509      }
510   }
511}
512
513
514static void
515clear_32bit_ximage(GLcontext *ctx, struct xmesa_renderbuffer *xrb,
516                   GLboolean all, GLint x, GLint y, GLint width, GLint height)
517{
518   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
519   register GLuint pixel = (GLuint) xmesa->clearpixel;
520
521   if (xmesa->swapbytes) {
522      pixel = ((pixel >> 24) & 0x000000ff)
523            | ((pixel >> 8)  & 0x0000ff00)
524            | ((pixel << 8)  & 0x00ff0000)
525            | ((pixel << 24) & 0xff000000);
526   }
527
528   if (all) {
529      const GLuint n = xrb->Base.Width * xrb->Base.Height;
530      GLuint *ptr4 = (GLuint *) xrb->ximage->data;
531      if (pixel == 0) {
532         _mesa_memset(ptr4, pixel, 4 * n);
533      }
534      else {
535         GLuint i;
536         for (i = 0; i < n; i++)
537            ptr4[i] = pixel;
538      }
539   }
540   else {
541      GLint i, j;
542      for (j = 0; j < height; j++) {
543         GLuint *ptr4 = PIXEL_ADDR4(xrb, x, y + j);
544         for (i = 0; i < width; i++) {
545            ptr4[i] = pixel;
546         }
547      }
548   }
549}
550
551
552static void
553clear_nbit_ximage(GLcontext *ctx, struct xmesa_renderbuffer *xrb,
554                  GLboolean all, GLint x, GLint y, GLint width, GLint height)
555{
556   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
557   XMesaImage *img = xrb->ximage;
558   GLint i, j;
559
560   /* We can ignore 'all' here - x, y, width, height are always right */
561   (void) all;
562
563   /* TODO: optimize this */
564   y = YFLIP(xrb, y);
565   for (j = 0; j < height; j++) {
566      for (i = 0; i < width; i++) {
567         XMesaPutPixel(img, x+i, y-j, xmesa->clearpixel);
568      }
569   }
570}
571
572
573
574static void
575clear_buffers( GLcontext *ctx, GLbitfield mask,
576               GLboolean all, GLint x, GLint y, GLint width, GLint height )
577{
578   if (ctx->DrawBuffer->Name == 0) {
579      /* this is a window system framebuffer */
580      const GLuint *colorMask = (GLuint *) &ctx->Color.ColorMask;
581      XMesaBuffer b = (XMesaBuffer) ctx->DrawBuffer;
582
583      /* we can't handle color or index masking */
584      if (*colorMask == 0xffffffff && ctx->Color.IndexMask == 0xffffffff) {
585         if (mask & BUFFER_BIT_FRONT_LEFT) {
586            /* clear front color buffer */
587            if (b->frontxrb == (struct xmesa_renderbuffer *)
588                ctx->DrawBuffer->Attachment[BUFFER_FRONT_LEFT].Renderbuffer) {
589               /* renderbuffer is not wrapped - great! */
590               b->frontxrb->clearFunc(ctx, b->frontxrb, all, x, y,
591                                      width, height);
592               mask &= ~BUFFER_BIT_FRONT_LEFT;
593            }
594            else {
595               /* we can't directly clear an alpha-wrapped color buffer */
596            }
597         }
598         if (mask & BUFFER_BIT_BACK_LEFT) {
599            /* clear back color buffer */
600            if (b->backxrb == (struct xmesa_renderbuffer *)
601                ctx->DrawBuffer->Attachment[BUFFER_BACK_LEFT].Renderbuffer) {
602               /* renderbuffer is not wrapped - great! */
603               b->backxrb->clearFunc(ctx, b->backxrb, all, x, y,
604                                     width, height);
605               mask &= ~BUFFER_BIT_BACK_LEFT;
606            }
607         }
608      }
609   }
610   if (mask)
611      _swrast_Clear( ctx, mask, all, x, y, width, height );
612}
613
614
615/**
616 * Called by ctx->Driver.ResizeBuffers()
617 * Resize the front/back colorbuffers to match the latest window size.
618 */
619void
620xmesa_resize_buffers(GLcontext *ctx, GLframebuffer *buffer,
621                     GLuint width, GLuint height)
622{
623   /* We can do this cast because the first field in the XMesaBuffer
624    * struct is a GLframebuffer struct.  If this weren't true, we'd
625    * need a pointer from the GLframebuffer to the XMesaBuffer.
626    */
627   XMesaBuffer xmBuffer = (XMesaBuffer) buffer;
628
629   xmesa_alloc_back_buffer(xmBuffer, width, height);
630
631#if NEW_RENDERBUFFER
632   _mesa_resize_framebuffer(ctx, buffer, width, height);
633#endif
634}
635
636
637#ifndef XFree86Server
638/* XXX this was never tested in the Xserver environment */
639
640/**
641 * This function implements glDrawPixels() with an XPutImage call when
642 * drawing to the front buffer (X Window drawable).
643 * The image format must be GL_BGRA to match the PF_8R8G8B pixel format.
644 */
645static void
646xmesa_DrawPixels_8R8G8B( GLcontext *ctx,
647                         GLint x, GLint y, GLsizei width, GLsizei height,
648                         GLenum format, GLenum type,
649                         const struct gl_pixelstore_attrib *unpack,
650                         const GLvoid *pixels )
651{
652   struct xmesa_renderbuffer *xrb
653      = (struct xmesa_renderbuffer *) ctx->DrawBuffer->_ColorDrawBuffers[0][0];
654
655   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
656   const SWcontext *swrast = SWRAST_CONTEXT( ctx );
657   XMesaDisplay *dpy = xmesa->xm_visual->display;
658   XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer);
659   const XMesaGC gc = xmbuf->gc;
660
661   ASSERT(dpy);
662   ASSERT(gc);
663   ASSERT(xmesa->xm_visual->dithered_pf == PF_8R8G8B);
664   ASSERT(xmesa->xm_visual->undithered_pf == PF_8R8G8B);
665
666   if (swrast->NewState)
667      _swrast_validate_derived( ctx );
668
669   if (xrb->pixmap &&
670       format == GL_BGRA &&
671       type == GL_UNSIGNED_BYTE &&
672       (swrast->_RasterMask & ~CLIP_BIT) == 0 && /* no blend, z-test, etc */
673       ctx->_ImageTransferState == 0 &&  /* no color tables, scale/bias, etc */
674       ctx->Pixel.ZoomX == 1.0 &&        /* no zooming */
675       ctx->Pixel.ZoomY == 1.0) {
676      int dstX = x;
677      int dstY = y;
678      int w = width;
679      int h = height;
680      int srcX = unpack->SkipPixels;
681      int srcY = unpack->SkipRows;
682      int rowLength = unpack->RowLength ? unpack->RowLength : width;
683
684      if (unpack->BufferObj->Name) {
685         /* unpack from PBO */
686         GLubyte *buf;
687         if (!_mesa_validate_pbo_access(2, unpack, width, height, 1,
688                                        format, type, pixels)) {
689            _mesa_error(ctx, GL_INVALID_OPERATION,
690                        "glDrawPixels(invalid PBO access)");
691            return;
692         }
693         buf = (GLubyte *) ctx->Driver.MapBuffer(ctx,
694                                                 GL_PIXEL_UNPACK_BUFFER_EXT,
695                                                 GL_READ_ONLY_ARB,
696                                                 unpack->BufferObj);
697         if (!buf) {
698            /* buffer is already mapped - that's an error */
699            _mesa_error(ctx, GL_INVALID_OPERATION,
700                        "glDrawPixels(PBO is mapped)");
701            return;
702         }
703         pixels = ADD_POINTERS(buf, pixels);
704      }
705
706      if (_mesa_clip_drawpixels(ctx, &dstX, &dstY, &w, &h, &srcX, &srcY)) {
707         /* This is a little tricky since all coordinates up to now have
708          * been in the OpenGL bottom-to-top orientation.  X is top-to-bottom
709          * so we have to carefully compute the Y coordinates/addresses here.
710          */
711         XMesaImage ximage;
712         MEMSET(&ximage, 0, sizeof(XMesaImage));
713         ximage.width = width;
714         ximage.height = height;
715         ximage.format = ZPixmap;
716         ximage.data = (char *) pixels
717            + ((srcY + h - 1) * rowLength + srcX) * 4;
718         ximage.byte_order = LSBFirst;
719         ximage.bitmap_unit = 32;
720         ximage.bitmap_bit_order = LSBFirst;
721         ximage.bitmap_pad = 32;
722         ximage.depth = 24;
723         ximage.bytes_per_line = -rowLength * 4; /* negative to flip image */
724         ximage.bits_per_pixel = 32;
725         /* it seems we don't need to set the ximage.red/green/blue_mask fields */
726         /* flip Y axis for dest position */
727         dstY = YFLIP(xrb, dstY) - h + 1;
728         XPutImage(dpy, xrb->pixmap, gc, &ximage, 0, 0, dstX, dstY, w, h);
729      }
730
731      if (unpack->BufferObj->Name) {
732         ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
733                                 unpack->BufferObj);
734      }
735   }
736   else {
737      /* software fallback */
738      _swrast_DrawPixels(ctx, x, y, width, height,
739                         format, type, unpack, pixels);
740   }
741}
742
743
744
745/**
746 * This function implements glDrawPixels() with an XPutImage call when
747 * drawing to the front buffer (X Window drawable).  The image format
748 * must be GL_RGB and image type must be GL_UNSIGNED_SHORT_5_6_5 to
749 * match the PF_5R6G5B pixel format.
750 */
751static void
752xmesa_DrawPixels_5R6G5B( GLcontext *ctx,
753                         GLint x, GLint y, GLsizei width, GLsizei height,
754                         GLenum format, GLenum type,
755                         const struct gl_pixelstore_attrib *unpack,
756                         const GLvoid *pixels )
757{
758   struct xmesa_renderbuffer *xrb
759      = (struct xmesa_renderbuffer *) ctx->DrawBuffer->_ColorDrawBuffers[0][0];
760   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
761   const SWcontext *swrast = SWRAST_CONTEXT( ctx );
762   XMesaDisplay *dpy = xmesa->xm_visual->display;
763   XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer);
764   const XMesaGC gc = xmbuf->gc;
765
766   ASSERT(dpy);
767   ASSERT(gc);
768   ASSERT(xmesa->xm_visual->undithered_pf == PF_5R6G5B);
769
770   if (swrast->NewState)
771      _swrast_validate_derived( ctx );
772
773   if (xrb->pixmap &&
774       format == GL_RGB &&
775       type == GL_UNSIGNED_SHORT_5_6_5 &&
776       !ctx->Color.DitherFlag &&  /* no dithering */
777       (swrast->_RasterMask & ~CLIP_BIT) == 0 && /* no blend, z-test, etc */
778       ctx->_ImageTransferState == 0 &&  /* no color tables, scale/bias, etc */
779       ctx->Pixel.ZoomX == 1.0 &&        /* no zooming */
780       ctx->Pixel.ZoomY == 1.0) {
781      int dstX = x;
782      int dstY = y;
783      int w = width;
784      int h = height;
785      int srcX = unpack->SkipPixels;
786      int srcY = unpack->SkipRows;
787      int rowLength = unpack->RowLength ? unpack->RowLength : width;
788
789      if (unpack->BufferObj->Name) {
790         /* unpack from PBO */
791         GLubyte *buf;
792         if (!_mesa_validate_pbo_access(2, unpack, width, height, 1,
793                                        format, type, pixels)) {
794            _mesa_error(ctx, GL_INVALID_OPERATION,
795                        "glDrawPixels(invalid PBO access)");
796            return;
797         }
798         buf = (GLubyte *) ctx->Driver.MapBuffer(ctx,
799                                                 GL_PIXEL_UNPACK_BUFFER_EXT,
800                                                 GL_READ_ONLY_ARB,
801                                                 unpack->BufferObj);
802         if (!buf) {
803            /* buffer is already mapped - that's an error */
804            _mesa_error(ctx, GL_INVALID_OPERATION,
805                        "glDrawPixels(PBO is mapped)");
806            return;
807         }
808         pixels = ADD_POINTERS(buf, pixels);
809      }
810
811      if (_mesa_clip_drawpixels(ctx, &dstX, &dstY, &w, &h, &srcX, &srcY)) {
812         /* This is a little tricky since all coordinates up to now have
813          * been in the OpenGL bottom-to-top orientation.  X is top-to-bottom
814          * so we have to carefully compute the Y coordinates/addresses here.
815          */
816         XMesaImage ximage;
817         MEMSET(&ximage, 0, sizeof(XMesaImage));
818         ximage.width = width;
819         ximage.height = height;
820         ximage.format = ZPixmap;
821         ximage.data = (char *) pixels
822            + ((srcY + h - 1) * rowLength + srcX) * 2;
823         ximage.byte_order = LSBFirst;
824         ximage.bitmap_unit = 16;
825         ximage.bitmap_bit_order = LSBFirst;
826         ximage.bitmap_pad = 16;
827         ximage.depth = 16;
828         ximage.bytes_per_line = -rowLength * 2; /* negative to flip image */
829         ximage.bits_per_pixel = 16;
830         /* it seems we don't need to set the ximage.red/green/blue_mask fields */
831         /* flip Y axis for dest position */
832         dstY = YFLIP(xrb, dstY) - h + 1;
833         XPutImage(dpy, xrb->pixmap, gc, &ximage, 0, 0, dstX, dstY, w, h);
834      }
835
836      if (unpack->BufferObj->Name) {
837         ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
838                                 unpack->BufferObj);
839      }
840   }
841   else {
842      /* software fallback */
843      _swrast_DrawPixels(ctx, x, y, width, height,
844                         format, type, unpack, pixels);
845   }
846}
847
848
849
850/**
851 * Implement glCopyPixels for the front color buffer (or back buffer Pixmap)
852 * for the color buffer.  Don't support zooming, pixel transfer, etc.
853 * We do support copying from one window to another, ala glXMakeCurrentRead.
854 */
855static void
856xmesa_CopyPixels( GLcontext *ctx,
857                  GLint srcx, GLint srcy, GLsizei width, GLsizei height,
858                  GLint destx, GLint desty, GLenum type )
859{
860   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
861   const SWcontext *swrast = SWRAST_CONTEXT( ctx );
862   XMesaDisplay *dpy = xmesa->xm_visual->display;
863   const XMesaGC gc = ((XMesaBuffer) ctx->DrawBuffer)->gc;
864   struct xmesa_renderbuffer *srcXrb = (struct xmesa_renderbuffer *)
865      ctx->ReadBuffer->_ColorReadBuffer;
866   struct xmesa_renderbuffer *dstXrb = (struct xmesa_renderbuffer *)
867      ctx->DrawBuffer->_ColorDrawBuffers[0][0];
868
869   ASSERT(dpy);
870   ASSERT(gc);
871
872   if (swrast->NewState)
873      _swrast_validate_derived( ctx );
874
875   if (ctx->Color.DrawBuffer[0] == GL_FRONT &&
876       ctx->Pixel.ReadBuffer == GL_FRONT &&
877       srcXrb->pixmap &&
878       dstXrb->pixmap &&
879       type == GL_COLOR &&
880       (swrast->_RasterMask & ~CLIP_BIT) == 0 && /* no blend, z-test, etc */
881       ctx->_ImageTransferState == 0 &&  /* no color tables, scale/bias, etc */
882       ctx->Pixel.ZoomX == 1.0 &&        /* no zooming */
883       ctx->Pixel.ZoomY == 1.0) {
884      /* Note: we don't do any special clipping work here.  We could,
885       * but X will do it for us.
886       */
887      srcy = YFLIP(srcXrb, srcy) - height + 1;
888      desty = YFLIP(dstXrb, desty) - height + 1;
889      XCopyArea(dpy, srcXrb->pixmap, dstXrb->pixmap, gc,
890                srcx, srcy, width, height, destx, desty);
891   }
892   else {
893      _swrast_CopyPixels(ctx, srcx, srcy, width, height, destx, desty, type );
894   }
895}
896#endif /* XFree86Server */
897
898
899
900/*
901 * Every driver should implement a GetString function in order to
902 * return a meaningful GL_RENDERER string.
903 */
904static const GLubyte *
905get_string( GLcontext *ctx, GLenum name )
906{
907   (void) ctx;
908   switch (name) {
909      case GL_RENDERER:
910#ifdef XFree86Server
911         return (const GLubyte *) "Mesa GLX Indirect";
912#else
913         return (const GLubyte *) "Mesa X11";
914#endif
915      case GL_VENDOR:
916#ifdef XFree86Server
917         return (const GLubyte *) "Mesa project: www.mesa3d.org";
918#else
919         return NULL;
920#endif
921      default:
922         return NULL;
923   }
924}
925
926
927/*
928 * We implement the glEnable function only because we care about
929 * dither enable/disable.
930 */
931static void
932enable( GLcontext *ctx, GLenum pname, GLboolean state )
933{
934   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
935
936   switch (pname) {
937      case GL_DITHER:
938         if (state)
939            xmesa->pixelformat = xmesa->xm_visual->dithered_pf;
940         else
941            xmesa->pixelformat = xmesa->xm_visual->undithered_pf;
942         break;
943      default:
944         ;  /* silence compiler warning */
945   }
946}
947
948
949static void
950clear_color_HPCR_ximage( GLcontext *ctx, const GLfloat color[4] )
951{
952   int i;
953   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
954
955   CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[0], color[0]);
956   CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[1], color[1]);
957   CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[2], color[2]);
958   CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[3], color[3]);
959
960   if (color[0] == 0.0 && color[1] == 0.0 && color[2] == 0.0) {
961      /* black is black */
962      MEMSET( xmesa->xm_visual->hpcr_clear_ximage_pattern, 0x0 ,
963              sizeof(xmesa->xm_visual->hpcr_clear_ximage_pattern));
964   }
965   else {
966      /* build clear pattern */
967      for (i=0; i<16; i++) {
968         xmesa->xm_visual->hpcr_clear_ximage_pattern[0][i] =
969            DITHER_HPCR(i, 0,
970                        xmesa->clearcolor[0],
971                        xmesa->clearcolor[1],
972                        xmesa->clearcolor[2]);
973         xmesa->xm_visual->hpcr_clear_ximage_pattern[1][i]    =
974            DITHER_HPCR(i, 1,
975                        xmesa->clearcolor[0],
976                        xmesa->clearcolor[1],
977                        xmesa->clearcolor[2]);
978      }
979   }
980}
981
982
983static void
984clear_color_HPCR_pixmap( GLcontext *ctx, const GLfloat color[4] )
985{
986   int i;
987   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
988
989   CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[0], color[0]);
990   CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[1], color[1]);
991   CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[2], color[2]);
992   CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[3], color[3]);
993
994   if (color[0] == 0.0 && color[1] == 0.0 && color[2] == 0.0) {
995      /* black is black */
996      for (i=0; i<16; i++) {
997         XMesaPutPixel(xmesa->xm_visual->hpcr_clear_ximage, i, 0, 0);
998         XMesaPutPixel(xmesa->xm_visual->hpcr_clear_ximage, i, 1, 0);
999      }
1000   }
1001   else {
1002      for (i=0; i<16; i++) {
1003         XMesaPutPixel(xmesa->xm_visual->hpcr_clear_ximage, i, 0,
1004                       DITHER_HPCR(i, 0,
1005                                   xmesa->clearcolor[0],
1006                                   xmesa->clearcolor[1],
1007                                   xmesa->clearcolor[2]));
1008         XMesaPutPixel(xmesa->xm_visual->hpcr_clear_ximage, i, 1,
1009                       DITHER_HPCR(i, 1,
1010                                   xmesa->clearcolor[0],
1011                                   xmesa->clearcolor[1],
1012                                   xmesa->clearcolor[2]));
1013      }
1014   }
1015   /* change tile pixmap content */
1016   XMesaPutImage(xmesa->display,
1017		 (XMesaDrawable)xmesa->xm_visual->hpcr_clear_pixmap,
1018		 XMESA_BUFFER(ctx->DrawBuffer)->cleargc,
1019		 xmesa->xm_visual->hpcr_clear_ximage, 0, 0, 0, 0, 16, 2);
1020}
1021
1022
1023/**
1024 * Called when the driver should update it's state, based on the new_state
1025 * flags.
1026 */
1027void
1028xmesa_update_state( GLcontext *ctx, GLuint new_state )
1029{
1030   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1031   struct xmesa_renderbuffer *front_xrb, *back_xrb;
1032
1033   /* Propagate statechange information to swrast and swrast_setup
1034    * modules.  The X11 driver has no internal GL-dependent state.
1035    */
1036   _swrast_InvalidateState( ctx, new_state );
1037   _ac_InvalidateState( ctx, new_state );
1038   _tnl_InvalidateState( ctx, new_state );
1039   _swsetup_InvalidateState( ctx, new_state );
1040
1041   if (ctx->DrawBuffer->Name != 0)
1042      return;
1043
1044   front_xrb = XMESA_BUFFER(ctx->DrawBuffer)->frontxrb;
1045   if (front_xrb) {
1046      /* XXX check for relevant new_state flags */
1047      xmesa_set_renderbuffer_funcs(front_xrb, xmesa->pixelformat,
1048                                   xmesa->xm_visual->BitsPerPixel);
1049      /* setup pointers to front and back buffer clear functions */
1050      front_xrb->clearFunc = clear_pixmap;
1051   }
1052
1053   back_xrb = XMESA_BUFFER(ctx->DrawBuffer)->backxrb;
1054   if (back_xrb) {
1055      XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer);
1056
1057      /* XXX check for relevant new_state flags */
1058      xmesa_set_renderbuffer_funcs(back_xrb, xmesa->pixelformat,
1059                                   xmesa->xm_visual->BitsPerPixel);
1060
1061      if (xmbuf->backxrb->pixmap) {
1062         back_xrb->clearFunc = clear_pixmap;
1063      }
1064      else {
1065         switch (xmesa->xm_visual->BitsPerPixel) {
1066         case 8:
1067            if (xmesa->xm_visual->hpcr_clear_flag) {
1068               back_xrb->clearFunc = clear_HPCR_ximage;
1069            }
1070            else {
1071               back_xrb->clearFunc = clear_8bit_ximage;
1072            }
1073            break;
1074         case 16:
1075            back_xrb->clearFunc = clear_16bit_ximage;
1076            break;
1077         case 24:
1078            back_xrb->clearFunc = clear_24bit_ximage;
1079            break;
1080         case 32:
1081            back_xrb->clearFunc = clear_32bit_ximage;
1082            break;
1083         default:
1084            back_xrb->clearFunc = clear_nbit_ximage;
1085            break;
1086         }
1087      }
1088   }
1089
1090#if OLD_RENDERBUFFER && 0
1091   if (ctx->DrawBuffer->_ColorDrawBufferMask[0] & (BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT)) {
1092      xmesa_update_span_funcs(ctx);
1093   }
1094#endif
1095
1096   if (xmesa->xm_visual->hpcr_clear_flag) {
1097      /* this depends on whether we're drawing to the front or back buffer */
1098      /* XXX FIX THIS! */
1099#if 0
1100      if (pixmap) {
1101         ctx->Driver.ClearColor = clear_color_HPCR_pixmap;
1102      }
1103      else {
1104         ctx->Driver.ClearColor = clear_color_HPCR_ximage;
1105      }
1106#else
1107      (void) clear_color_HPCR_pixmap;
1108      (void) clear_color_HPCR_ximage;
1109#endif
1110   }
1111}
1112
1113
1114
1115/**
1116 * Called via ctx->Driver.TestProxyTeximage().  Normally, we'd just use
1117 * the _mesa_test_proxy_teximage() fallback function, but we're going to
1118 * special-case the 3D texture case to allow textures up to 512x512x32
1119 * texels.
1120 */
1121static GLboolean
1122test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level,
1123                    GLint internalFormat, GLenum format, GLenum type,
1124                    GLint width, GLint height, GLint depth, GLint border)
1125{
1126   if (target == GL_PROXY_TEXTURE_3D) {
1127      /* special case for 3D textures */
1128      if (width * height * depth > 512 * 512 * 64 ||
1129          width  < 2 * border ||
1130          (!ctx->Extensions.ARB_texture_non_power_of_two &&
1131           _mesa_bitcount(width  - 2 * border) != 1) ||
1132          height < 2 * border ||
1133          (!ctx->Extensions.ARB_texture_non_power_of_two &&
1134           _mesa_bitcount(height - 2 * border) != 1) ||
1135          depth  < 2 * border ||
1136          (!ctx->Extensions.ARB_texture_non_power_of_two &&
1137           _mesa_bitcount(depth  - 2 * border) != 1)) {
1138         /* Bad size, or too many texels */
1139         return GL_FALSE;
1140      }
1141      return GL_TRUE;
1142   }
1143   else {
1144      /* use the fallback routine for 1D, 2D, cube and rect targets */
1145      return _mesa_test_proxy_teximage(ctx, target, level, internalFormat,
1146                                       format, type, width, height, depth,
1147                                       border);
1148   }
1149}
1150
1151
1152/**
1153 * In SW, we don't really compress GL_COMPRESSED_RGB[A] textures!
1154 */
1155static const struct gl_texture_format *
1156choose_tex_format( GLcontext *ctx, GLint internalFormat,
1157                   GLenum format, GLenum type )
1158{
1159   switch (internalFormat) {
1160      case GL_COMPRESSED_RGB_ARB:
1161         return &_mesa_texformat_rgb;
1162      case GL_COMPRESSED_RGBA_ARB:
1163         return &_mesa_texformat_rgba;
1164      default:
1165         return _mesa_choose_tex_format(ctx, internalFormat, format, type);
1166   }
1167}
1168
1169
1170/**
1171 * Called by glViewport.
1172 * This is a good time for us to poll the current X window size and adjust
1173 * our renderbuffers to match the current window size.
1174 * Remember, we have no opportunity to respond to conventional
1175 * X Resize/StructureNotify events since the X driver has no event loop.
1176 * Thus, we poll.
1177 * Note that this trick isn't fool-proof.  If the application never calls
1178 * glViewport, our notion of the current window size may be incorrect.
1179 */
1180static void
1181xmesa_viewport(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h)
1182{
1183#if 1
1184   struct gl_framebuffer *fb = ctx->WinSysDrawBuffer;
1185   GLuint newWidth, newHeight;
1186
1187   /*
1188   printf("%s before %d x %d\n", __FUNCTION__, fb->Width, fb->Height);
1189   */
1190
1191   get_buffer_size(fb, &newWidth, &newHeight);
1192   if (newWidth != fb->Width || newHeight != fb->Height) {
1193      xmesa_resize_buffers(ctx, fb, newWidth, newHeight);
1194      ctx->NewState |= _NEW_BUFFERS;  /* to update scissor / window bounds */
1195   }
1196   /*
1197   printf("%s after %d x %d\n", __FUNCTION__, fb->Width, fb->Height);
1198   */
1199#else
1200   /* This also works: */
1201   _mesa_ResizeBuffersMESA();
1202#endif
1203}
1204
1205
1206/**
1207 * Initialize the device driver function table with the functions
1208 * we implement in this driver.
1209 */
1210void
1211xmesa_init_driver_functions( XMesaVisual xmvisual,
1212                             struct dd_function_table *driver )
1213{
1214   driver->GetString = get_string;
1215   driver->UpdateState = xmesa_update_state;
1216   driver->GetBufferSize = get_buffer_size;
1217   driver->Flush = finish_or_flush;
1218   driver->Finish = finish_or_flush;
1219   driver->ClearIndex = clear_index;
1220   driver->ClearColor = clear_color;
1221   driver->IndexMask = index_mask;
1222   driver->ColorMask = color_mask;
1223   driver->Enable = enable;
1224   driver->Clear = clear_buffers;
1225   driver->ResizeBuffers = xmesa_resize_buffers;
1226   driver->Viewport = xmesa_viewport;
1227#ifndef XFree86Server
1228   driver->CopyPixels = xmesa_CopyPixels;
1229   if (xmvisual->undithered_pf == PF_8R8G8B &&
1230       xmvisual->dithered_pf == PF_8R8G8B) {
1231      driver->DrawPixels = xmesa_DrawPixels_8R8G8B;
1232   }
1233   else if (xmvisual->undithered_pf == PF_5R6G5B) {
1234      driver->DrawPixels = xmesa_DrawPixels_5R6G5B;
1235   }
1236#endif
1237   driver->TestProxyTexImage = test_proxy_teximage;
1238#if SWTC
1239   driver->ChooseTextureFormat = choose_tex_format;
1240#else
1241   (void) choose_tex_format;
1242#endif
1243}
1244
1245
1246#define XMESA_NEW_POINT  (_NEW_POINT | \
1247                          _NEW_RENDERMODE | \
1248                          _SWRAST_NEW_RASTERMASK)
1249
1250#define XMESA_NEW_LINE   (_NEW_LINE | \
1251                          _NEW_TEXTURE | \
1252                          _NEW_LIGHT | \
1253                          _NEW_DEPTH | \
1254                          _NEW_RENDERMODE | \
1255                          _SWRAST_NEW_RASTERMASK)
1256
1257#define XMESA_NEW_TRIANGLE (_NEW_POLYGON | \
1258                            _NEW_TEXTURE | \
1259                            _NEW_LIGHT | \
1260                            _NEW_DEPTH | \
1261                            _NEW_RENDERMODE | \
1262                            _SWRAST_NEW_RASTERMASK)
1263
1264
1265/* Extend the software rasterizer with our line/point/triangle
1266 * functions.
1267 */
1268void xmesa_register_swrast_functions( GLcontext *ctx )
1269{
1270   SWcontext *swrast = SWRAST_CONTEXT( ctx );
1271   struct swrast_device_driver *dd = _swrast_GetDeviceDriverReference(ctx);
1272
1273   dd->SetBuffer = xmesa_set_buffer;
1274
1275   swrast->choose_point = xmesa_choose_point;
1276   swrast->choose_line = xmesa_choose_line;
1277   swrast->choose_triangle = xmesa_choose_triangle;
1278
1279   swrast->invalidate_point |= XMESA_NEW_POINT;
1280   swrast->invalidate_line |= XMESA_NEW_LINE;
1281   swrast->invalidate_triangle |= XMESA_NEW_TRIANGLE;
1282}
1283