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