2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
29 * General device driver functions for Xlib driver.
32 #include "glxheader.h"
33 #include "main/bufferobj.h"
34 #include "main/context.h"
35 #include "main/colormac.h"
36 #include "main/fbobject.h"
37 #include "main/macros.h"
38 #include "main/mipmap.h"
39 #include "main/image.h"
40 #include "main/imports.h"
41 #include "main/mtypes.h"
43 #include "main/texformat.h"
44 #include "swrast/swrast.h"
45 #include "swrast/s_context.h"
46 #include "swrast_setup/swrast_setup.h"
48 #include "tnl/t_context.h"
49 #include "drivers/common/meta.h"
54 finish_or_flush( struct gl_context *ctx )
56 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
58 _glthread_LOCK_MUTEX(_xmesa_lock);
59 XSync( xmesa->display, False );
60 _glthread_UNLOCK_MUTEX(_xmesa_lock);
65 /* Implements glColorMask() */
67 color_mask(struct gl_context *ctx,
68 GLboolean rmask, GLboolean gmask, GLboolean bmask, GLboolean amask)
70 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
72 const int xclass = xmesa->xm_visual->visualType;
75 if (_mesa_is_user_fbo(ctx->DrawBuffer))
78 xmbuf = XMESA_BUFFER(ctx->DrawBuffer);
80 if (xclass == GLX_TRUE_COLOR || xclass == GLX_DIRECT_COLOR) {
82 if (rmask && gmask && bmask) {
83 m = ((unsigned long)~0L);
87 if (rmask) m |= GET_REDMASK(xmesa->xm_visual);
88 if (gmask) m |= GET_GREENMASK(xmesa->xm_visual);
89 if (bmask) m |= GET_BLUEMASK(xmesa->xm_visual);
91 XMesaSetPlaneMask( xmesa->display, xmbuf->cleargc, m );
97 /**********************************************************************/
98 /*** glClear implementations ***/
99 /**********************************************************************/
103 * Clear the front or back color buffer, if it's implemented with a pixmap.
106 clear_pixmap(struct gl_context *ctx, struct xmesa_renderbuffer *xrb,
107 GLint x, GLint y, GLint width, GLint height)
109 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
110 XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer);
115 assert(xmesa->display);
117 assert(xmbuf->cleargc);
119 XMesaFillRectangle( xmesa->display, xrb->pixmap, xmbuf->cleargc,
120 x, xrb->Base.Base.Height - y - height,
126 clear_16bit_ximage( struct gl_context *ctx, struct xmesa_renderbuffer *xrb,
127 GLint x, GLint y, GLint width, GLint height)
129 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
130 GLuint pixel = (GLuint) xmesa->clearpixel;
133 if (xmesa->swapbytes) {
134 pixel = ((pixel >> 8) & 0x00ff) | ((pixel << 8) & 0xff00);
137 for (j = 0; j < height; j++) {
138 GLushort *ptr2 = PIXEL_ADDR2(xrb, x, y + j);
139 for (i = 0; i < width; i++) {
146 /* Optimized code provided by Nozomi Ytow <noz@xfree86.org> */
148 clear_24bit_ximage(struct gl_context *ctx, struct xmesa_renderbuffer *xrb,
149 GLint x, GLint y, GLint width, GLint height)
151 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
152 const GLubyte r = xmesa->clearcolor[0];
153 const GLubyte g = xmesa->clearcolor[1];
154 const GLubyte b = xmesa->clearcolor[2];
156 if (r == g && g == b) {
157 /* same value for all three components (gray) */
159 for (j = 0; j < height; j++) {
160 bgr_t *ptr3 = PIXEL_ADDR3(xrb, x, y + j);
161 memset(ptr3, r, 3 * width);
165 /* non-gray clear color */
167 for (j = 0; j < height; j++) {
168 bgr_t *ptr3 = PIXEL_ADDR3(xrb, x, y + j);
169 for (i = 0; i < width; i++) {
181 clear_32bit_ximage(struct gl_context *ctx, struct xmesa_renderbuffer *xrb,
182 GLint x, GLint y, GLint width, GLint height)
184 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
185 register GLuint pixel = (GLuint) xmesa->clearpixel;
190 if (xmesa->swapbytes) {
191 pixel = ((pixel >> 24) & 0x000000ff)
192 | ((pixel >> 8) & 0x0000ff00)
193 | ((pixel << 8) & 0x00ff0000)
194 | ((pixel << 24) & 0xff000000);
197 if (width == xrb->Base.Base.Width && height == xrb->Base.Base.Height) {
198 /* clearing whole buffer */
199 const GLuint n = xrb->Base.Base.Width * xrb->Base.Base.Height;
200 GLuint *ptr4 = (GLuint *) xrb->ximage->data;
203 memset(ptr4, pixel, 4 * n);
207 for (i = 0; i < n; i++)
212 /* clearing scissored region */
214 for (j = 0; j < height; j++) {
215 GLuint *ptr4 = PIXEL_ADDR4(xrb, x, y + j);
216 for (i = 0; i < width; i++) {
225 clear_nbit_ximage(struct gl_context *ctx, struct xmesa_renderbuffer *xrb,
226 GLint x, GLint y, GLint width, GLint height)
228 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
229 XMesaImage *img = xrb->ximage;
232 /* TODO: optimize this */
234 for (j = 0; j < height; j++) {
235 for (i = 0; i < width; i++) {
236 XMesaPutPixel(img, x+i, y-j, xmesa->clearpixel);
244 clear_buffers(struct gl_context *ctx, GLbitfield buffers)
246 if (_mesa_is_winsys_fbo(ctx->DrawBuffer)) {
247 /* this is a window system framebuffer */
248 const GLuint *colorMask = (GLuint *) &ctx->Color.ColorMask[0];
249 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
250 XMesaBuffer b = XMESA_BUFFER(ctx->DrawBuffer);
251 const GLint x = ctx->DrawBuffer->_Xmin;
252 const GLint y = ctx->DrawBuffer->_Ymin;
253 const GLint width = ctx->DrawBuffer->_Xmax - x;
254 const GLint height = ctx->DrawBuffer->_Ymax - y;
256 _mesa_unclamped_float_rgba_to_ubyte(xmesa->clearcolor,
257 ctx->Color.ClearColor.f);
258 xmesa->clearpixel = xmesa_color_to_pixel(ctx,
259 xmesa->clearcolor[0],
260 xmesa->clearcolor[1],
261 xmesa->clearcolor[2],
262 xmesa->clearcolor[3],
263 xmesa->xm_visual->undithered_pf);
264 XMesaSetForeground(xmesa->display, b->cleargc, xmesa->clearpixel);
266 /* we can't handle color or index masking */
267 if (*colorMask == 0xffffffff && ctx->Color.IndexMask == 0xffffffff) {
268 if (buffers & BUFFER_BIT_FRONT_LEFT) {
269 /* clear front color buffer */
270 struct gl_renderbuffer *frontRb
271 = ctx->DrawBuffer->Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
272 if (b->frontxrb == xmesa_renderbuffer(frontRb)) {
273 /* renderbuffer is not wrapped - great! */
274 b->frontxrb->clearFunc(ctx, b->frontxrb, x, y, width, height);
275 buffers &= ~BUFFER_BIT_FRONT_LEFT;
278 /* we can't directly clear an alpha-wrapped color buffer */
281 if (buffers & BUFFER_BIT_BACK_LEFT) {
282 /* clear back color buffer */
283 struct gl_renderbuffer *backRb
284 = ctx->DrawBuffer->Attachment[BUFFER_BACK_LEFT].Renderbuffer;
285 if (b->backxrb == xmesa_renderbuffer(backRb)) {
286 /* renderbuffer is not wrapped - great! */
287 b->backxrb->clearFunc(ctx, b->backxrb, x, y, width, height);
288 buffers &= ~BUFFER_BIT_BACK_LEFT;
294 _swrast_Clear(ctx, buffers);
298 /* XXX these functions haven't been tested in the Xserver environment */
302 * Check if we can do an optimized glDrawPixels into an 8R8G8B visual.
305 can_do_DrawPixels_8R8G8B(struct gl_context *ctx, GLenum format, GLenum type)
307 if (format == GL_BGRA &&
308 type == GL_UNSIGNED_BYTE &&
310 _mesa_is_winsys_fbo(ctx->DrawBuffer) &&
311 ctx->Pixel.ZoomX == 1.0 && /* no zooming */
312 ctx->Pixel.ZoomY == 1.0 &&
313 ctx->_ImageTransferState == 0 /* no color tables, scale/bias, etc */) {
314 const SWcontext *swrast = SWRAST_CONTEXT(ctx);
316 if (swrast->NewState)
317 _swrast_validate_derived( ctx );
319 if ((swrast->_RasterMask & ~CLIP_BIT) == 0) /* no blend, z-test, etc */ {
320 struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0];
322 struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb);
324 xrb->pixmap && /* drawing to pixmap or window */
325 _mesa_get_format_bits(xrb->Base.Base.Format, GL_ALPHA_BITS) == 0) {
336 * This function implements glDrawPixels() with an XPutImage call when
337 * drawing to the front buffer (X Window drawable).
338 * The image format must be GL_BGRA to match the PF_8R8G8B pixel format.
341 xmesa_DrawPixels_8R8G8B( struct gl_context *ctx,
342 GLint x, GLint y, GLsizei width, GLsizei height,
343 GLenum format, GLenum type,
344 const struct gl_pixelstore_attrib *unpack,
345 const GLvoid *pixels )
347 if (can_do_DrawPixels_8R8G8B(ctx, format, type)) {
348 const SWcontext *swrast = SWRAST_CONTEXT( ctx );
349 struct gl_pixelstore_attrib clippedUnpack = *unpack;
355 if (swrast->NewState)
356 _swrast_validate_derived( ctx );
358 if (_mesa_is_bufferobj(unpack->BufferObj)) {
359 /* unpack from PBO */
361 if (!_mesa_validate_pbo_access(2, unpack, width, height, 1,
362 format, type, INT_MAX, pixels)) {
363 _mesa_error(ctx, GL_INVALID_OPERATION,
364 "glDrawPixels(invalid PBO access)");
367 buf = (GLubyte *) ctx->Driver.MapBufferRange(ctx, 0,
368 unpack->BufferObj->Size,
372 /* buffer is already mapped - that's an error */
373 _mesa_error(ctx, GL_INVALID_OPERATION,
374 "glDrawPixels(PBO is mapped)");
377 pixels = ADD_POINTERS(buf, pixels);
380 if (_mesa_clip_drawpixels(ctx, &dstX, &dstY, &w, &h, &clippedUnpack)) {
381 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
382 XMesaDisplay *dpy = xmesa->xm_visual->display;
383 XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer);
384 const XMesaGC gc = xmbuf->cleargc; /* effected by glColorMask */
385 struct xmesa_renderbuffer *xrb
386 = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]);
387 const int srcX = clippedUnpack.SkipPixels;
388 const int srcY = clippedUnpack.SkipRows;
389 const int rowLength = clippedUnpack.RowLength;
392 ASSERT(xmesa->xm_visual->dithered_pf == PF_8R8G8B);
393 ASSERT(xmesa->xm_visual->undithered_pf == PF_8R8G8B);
397 /* This is a little tricky since all coordinates up to now have
398 * been in the OpenGL bottom-to-top orientation. X is top-to-bottom
399 * so we have to carefully compute the Y coordinates/addresses here.
401 memset(&ximage, 0, sizeof(XMesaImage));
402 ximage.width = width;
403 ximage.height = height;
404 ximage.format = ZPixmap;
405 ximage.data = (char *) pixels
406 + ((srcY + h - 1) * rowLength + srcX) * 4;
407 ximage.byte_order = LSBFirst;
408 ximage.bitmap_unit = 32;
409 ximage.bitmap_bit_order = LSBFirst;
410 ximage.bitmap_pad = 32;
412 ximage.bits_per_pixel = 32;
413 ximage.bytes_per_line = -rowLength * 4; /* negative to flip image */
414 /* it seems we don't need to set the ximage.red/green/blue_mask fields */
415 /* flip Y axis for dest position */
416 dstY = YFLIP(xrb, dstY) - h + 1;
417 XPutImage(dpy, xrb->pixmap, gc, &ximage, 0, 0, dstX, dstY, w, h);
420 if (_mesa_is_bufferobj(unpack->BufferObj)) {
421 ctx->Driver.UnmapBuffer(ctx, unpack->BufferObj);
425 /* software fallback */
426 _swrast_DrawPixels(ctx, x, y, width, height,
427 format, type, unpack, pixels);
434 * Check if we can do an optimized glDrawPixels into an 5R6G5B visual.
437 can_do_DrawPixels_5R6G5B(struct gl_context *ctx, GLenum format, GLenum type)
439 if (format == GL_RGB &&
440 type == GL_UNSIGNED_SHORT_5_6_5 &&
441 !ctx->Color.DitherFlag && /* no dithering */
443 _mesa_is_winsys_fbo(ctx->DrawBuffer) &&
444 ctx->Pixel.ZoomX == 1.0 && /* no zooming */
445 ctx->Pixel.ZoomY == 1.0 &&
446 ctx->_ImageTransferState == 0 /* no color tables, scale/bias, etc */) {
447 const SWcontext *swrast = SWRAST_CONTEXT(ctx);
449 if (swrast->NewState)
450 _swrast_validate_derived( ctx );
452 if ((swrast->_RasterMask & ~CLIP_BIT) == 0) /* no blend, z-test, etc */ {
453 struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0];
455 struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb);
457 xrb->pixmap && /* drawing to pixmap or window */
458 _mesa_get_format_bits(xrb->Base.Base.Format, GL_ALPHA_BITS) == 0) {
469 * This function implements glDrawPixels() with an XPutImage call when
470 * drawing to the front buffer (X Window drawable). The image format
471 * must be GL_RGB and image type must be GL_UNSIGNED_SHORT_5_6_5 to
472 * match the PF_5R6G5B pixel format.
475 xmesa_DrawPixels_5R6G5B( struct gl_context *ctx,
476 GLint x, GLint y, GLsizei width, GLsizei height,
477 GLenum format, GLenum type,
478 const struct gl_pixelstore_attrib *unpack,
479 const GLvoid *pixels )
481 if (can_do_DrawPixels_5R6G5B(ctx, format, type)) {
482 const SWcontext *swrast = SWRAST_CONTEXT( ctx );
483 struct gl_pixelstore_attrib clippedUnpack = *unpack;
489 if (swrast->NewState)
490 _swrast_validate_derived( ctx );
492 if (_mesa_is_bufferobj(unpack->BufferObj)) {
493 /* unpack from PBO */
495 if (!_mesa_validate_pbo_access(2, unpack, width, height, 1,
496 format, type, INT_MAX, pixels)) {
497 _mesa_error(ctx, GL_INVALID_OPERATION,
498 "glDrawPixels(invalid PBO access)");
501 buf = (GLubyte *) ctx->Driver.MapBufferRange(ctx, 0,
502 unpack->BufferObj->Size,
506 /* buffer is already mapped - that's an error */
507 _mesa_error(ctx, GL_INVALID_OPERATION,
508 "glDrawPixels(PBO is mapped)");
511 pixels = ADD_POINTERS(buf, pixels);
514 if (_mesa_clip_drawpixels(ctx, &dstX, &dstY, &w, &h, &clippedUnpack)) {
515 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
516 XMesaDisplay *dpy = xmesa->xm_visual->display;
517 XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer);
518 const XMesaGC gc = xmbuf->cleargc; /* effected by glColorMask */
519 struct xmesa_renderbuffer *xrb
520 = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]);
521 const int srcX = clippedUnpack.SkipPixels;
522 const int srcY = clippedUnpack.SkipRows;
523 const int rowLength = clippedUnpack.RowLength;
526 ASSERT(xmesa->xm_visual->undithered_pf == PF_5R6G5B);
530 /* This is a little tricky since all coordinates up to now have
531 * been in the OpenGL bottom-to-top orientation. X is top-to-bottom
532 * so we have to carefully compute the Y coordinates/addresses here.
534 memset(&ximage, 0, sizeof(XMesaImage));
535 ximage.width = width;
536 ximage.height = height;
537 ximage.format = ZPixmap;
538 ximage.data = (char *) pixels
539 + ((srcY + h - 1) * rowLength + srcX) * 2;
540 ximage.byte_order = LSBFirst;
541 ximage.bitmap_unit = 16;
542 ximage.bitmap_bit_order = LSBFirst;
543 ximage.bitmap_pad = 16;
545 ximage.bits_per_pixel = 16;
546 ximage.bytes_per_line = -rowLength * 2; /* negative to flip image */
547 /* it seems we don't need to set the ximage.red/green/blue_mask fields */
548 /* flip Y axis for dest position */
549 dstY = YFLIP(xrb, dstY) - h + 1;
550 XPutImage(dpy, xrb->pixmap, gc, &ximage, 0, 0, dstX, dstY, w, h);
553 if (unpack->BufferObj->Name) {
554 ctx->Driver.UnmapBuffer(ctx, unpack->BufferObj);
558 /* software fallback */
559 _swrast_DrawPixels(ctx, x, y, width, height,
560 format, type, unpack, pixels);
566 * Determine if we can do an optimized glCopyPixels.
569 can_do_CopyPixels(struct gl_context *ctx, GLenum type)
571 if (type == GL_COLOR &&
572 ctx->_ImageTransferState == 0 && /* no color tables, scale/bias, etc */
573 ctx->Pixel.ZoomX == 1.0 && /* no zooming */
574 ctx->Pixel.ZoomY == 1.0 &&
575 ctx->Color.DrawBuffer[0] == GL_FRONT && /* copy to front buf */
576 ctx->Pixel.ReadBuffer == GL_FRONT && /* copy from front buf */
577 ctx->ReadBuffer->_ColorReadBuffer &&
578 ctx->DrawBuffer->_ColorDrawBuffers[0]) {
579 const SWcontext *swrast = SWRAST_CONTEXT( ctx );
581 if (swrast->NewState)
582 _swrast_validate_derived( ctx );
584 if ((swrast->_RasterMask & ~CLIP_BIT) == 0x0 &&
586 ctx->ReadBuffer->_ColorReadBuffer &&
588 ctx->DrawBuffer->_ColorDrawBuffers[0]) {
589 struct xmesa_renderbuffer *srcXrb
590 = xmesa_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer);
591 struct xmesa_renderbuffer *dstXrb
592 = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]);
593 if (srcXrb->pixmap && dstXrb->pixmap) {
603 * Implement glCopyPixels for the front color buffer (or back buffer Pixmap)
604 * for the color buffer. Don't support zooming, pixel transfer, etc.
605 * We do support copying from one window to another, ala glXMakeCurrentRead.
608 xmesa_CopyPixels( struct gl_context *ctx,
609 GLint srcx, GLint srcy, GLsizei width, GLsizei height,
610 GLint destx, GLint desty, GLenum type )
612 if (can_do_CopyPixels(ctx, type)) {
613 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
614 XMesaDisplay *dpy = xmesa->xm_visual->display;
615 XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer);
616 const XMesaGC gc = xmbuf->cleargc; /* effected by glColorMask */
617 struct xmesa_renderbuffer *srcXrb
618 = xmesa_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer);
619 struct xmesa_renderbuffer *dstXrb
620 = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]);
625 /* Note: we don't do any special clipping work here. We could,
626 * but X will do it for us.
628 srcy = YFLIP(srcXrb, srcy) - height + 1;
629 desty = YFLIP(dstXrb, desty) - height + 1;
630 XCopyArea(dpy, srcXrb->pixmap, dstXrb->pixmap, gc,
631 srcx, srcy, width, height, destx, desty);
634 _swrast_CopyPixels(ctx, srcx, srcy, width, height, destx, desty, type );
642 * Every driver should implement a GetString function in order to
643 * return a meaningful GL_RENDERER string.
645 static const GLubyte *
646 get_string( struct gl_context *ctx, GLenum name )
651 return (const GLubyte *) "Mesa X11";
661 * We implement the glEnable function only because we care about
662 * dither enable/disable.
665 enable( struct gl_context *ctx, GLenum pname, GLboolean state )
667 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
672 xmesa->pixelformat = xmesa->xm_visual->dithered_pf;
674 xmesa->pixelformat = xmesa->xm_visual->undithered_pf;
677 ; /* silence compiler warning */
683 * Called when the driver should update its state, based on the new_state
687 xmesa_update_state( struct gl_context *ctx, GLbitfield new_state )
689 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
691 /* Propagate statechange information to swrast and swrast_setup
692 * modules. The X11 driver has no internal GL-dependent state.
694 _swrast_InvalidateState( ctx, new_state );
695 _tnl_InvalidateState( ctx, new_state );
696 _vbo_InvalidateState( ctx, new_state );
697 _swsetup_InvalidateState( ctx, new_state );
699 if (_mesa_is_user_fbo(ctx->DrawBuffer))
703 * GL_DITHER, GL_READ/DRAW_BUFFER, buffer binding state, etc. effect
704 * renderbuffer span/clear funcs.
705 * Check _NEW_COLOR to detect dither enable/disable.
707 if (new_state & (_NEW_COLOR | _NEW_BUFFERS)) {
708 XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer);
709 struct xmesa_renderbuffer *front_xrb, *back_xrb;
711 front_xrb = xmbuf->frontxrb;
713 front_xrb->clearFunc = clear_pixmap;
716 back_xrb = xmbuf->backxrb;
718 if (xmbuf->backxrb->pixmap) {
719 back_xrb->clearFunc = clear_pixmap;
722 switch (xmesa->xm_visual->BitsPerPixel) {
724 back_xrb->clearFunc = clear_16bit_ximage;
727 back_xrb->clearFunc = clear_24bit_ximage;
730 back_xrb->clearFunc = clear_32bit_ximage;
733 back_xrb->clearFunc = clear_nbit_ximage;
743 * Called by glViewport.
744 * This is a good time for us to poll the current X window size and adjust
745 * our renderbuffers to match the current window size.
746 * Remember, we have no opportunity to respond to conventional
747 * X Resize/StructureNotify events since the X driver has no event loop.
749 * Note that this trick isn't fool-proof. If the application never calls
750 * glViewport, our notion of the current window size may be incorrect.
751 * That problem led to the GLX_MESA_resize_buffers extension.
754 xmesa_viewport(struct gl_context *ctx, GLint x, GLint y, GLsizei w, GLsizei h)
756 XMesaContext xmctx = XMESA_CONTEXT(ctx);
757 XMesaBuffer xmdrawbuf = XMESA_BUFFER(ctx->WinSysDrawBuffer);
758 XMesaBuffer xmreadbuf = XMESA_BUFFER(ctx->WinSysReadBuffer);
759 xmesa_check_and_update_buffer_size(xmctx, xmdrawbuf);
760 xmesa_check_and_update_buffer_size(xmctx, xmreadbuf);
768 #if ENABLE_EXT_timer_query
771 * The GL_EXT_timer_query extension is not enabled for the XServer
772 * indirect renderer. Not sure about how/if wrapping of gettimeofday()
776 struct xmesa_query_object
778 struct gl_query_object Base;
779 struct timeval StartTime;
783 static struct gl_query_object *
784 xmesa_new_query_object(struct gl_context *ctx, GLuint id)
786 struct xmesa_query_object *q = CALLOC_STRUCT(xmesa_query_object);
789 q->Base.Ready = GL_TRUE;
796 xmesa_begin_query(struct gl_context *ctx, struct gl_query_object *q)
798 if (q->Target == GL_TIME_ELAPSED_EXT) {
799 struct xmesa_query_object *xq = (struct xmesa_query_object *) q;
800 (void) gettimeofday(&xq->StartTime, NULL);
806 * Return the difference between the two given times in microseconds.
809 time_diff(const struct timeval *t0, const struct timeval *t1)
811 GLuint64EXT seconds0 = t0->tv_sec & 0xff; /* 0 .. 255 seconds */
812 GLuint64EXT seconds1 = t1->tv_sec & 0xff; /* 0 .. 255 seconds */
813 GLuint64EXT nanosec0 = (seconds0 * 1000000 + t0->tv_usec) * 1000;
814 GLuint64EXT nanosec1 = (seconds1 * 1000000 + t1->tv_usec) * 1000;
815 return nanosec1 - nanosec0;
820 xmesa_end_query(struct gl_context *ctx, struct gl_query_object *q)
822 if (q->Target == GL_TIME_ELAPSED_EXT) {
823 struct xmesa_query_object *xq = (struct xmesa_query_object *) q;
824 struct timeval endTime;
825 (void) gettimeofday(&endTime, NULL);
826 /* result is in nanoseconds! */
827 q->Result = time_diff(&xq->StartTime, &endTime);
832 #endif /* ENABLE_timer_query */
836 * Initialize the device driver function table with the functions
837 * we implement in this driver.
840 xmesa_init_driver_functions( XMesaVisual xmvisual,
841 struct dd_function_table *driver )
843 driver->GetString = get_string;
844 driver->UpdateState = xmesa_update_state;
845 driver->GetBufferSize = NULL; /* OBSOLETE */
846 driver->Flush = finish_or_flush;
847 driver->Finish = finish_or_flush;
848 driver->ColorMask = color_mask;
849 driver->Enable = enable;
850 driver->Viewport = xmesa_viewport;
851 if (TEST_META_FUNCS) {
852 driver->Clear = _mesa_meta_Clear;
853 driver->CopyPixels = _mesa_meta_CopyPixels;
854 driver->BlitFramebuffer = _mesa_meta_BlitFramebuffer;
855 driver->DrawPixels = _mesa_meta_DrawPixels;
856 driver->Bitmap = _mesa_meta_Bitmap;
859 driver->Clear = clear_buffers;
860 driver->CopyPixels = xmesa_CopyPixels;
861 if (xmvisual->undithered_pf == PF_8R8G8B &&
862 xmvisual->dithered_pf == PF_8R8G8B &&
863 xmvisual->BitsPerPixel == 32) {
864 driver->DrawPixels = xmesa_DrawPixels_8R8G8B;
866 else if (xmvisual->undithered_pf == PF_5R6G5B) {
867 driver->DrawPixels = xmesa_DrawPixels_5R6G5B;
871 driver->MapRenderbuffer = xmesa_MapRenderbuffer;
872 driver->UnmapRenderbuffer = xmesa_UnmapRenderbuffer;
874 driver->GenerateMipmap = _mesa_generate_mipmap;
876 #if ENABLE_EXT_timer_query
877 driver->NewQueryObject = xmesa_new_query_object;
878 driver->BeginQuery = xmesa_begin_query;
879 driver->EndQuery = xmesa_end_query;
884 #define XMESA_NEW_POINT (_NEW_POINT | \
886 _SWRAST_NEW_RASTERMASK)
888 #define XMESA_NEW_LINE (_NEW_LINE | \
893 _SWRAST_NEW_RASTERMASK)
895 #define XMESA_NEW_TRIANGLE (_NEW_POLYGON | \
900 _SWRAST_NEW_RASTERMASK)
904 * Extend the software rasterizer with our line/point/triangle
906 * Called during context creation only.
908 void xmesa_register_swrast_functions( struct gl_context *ctx )
910 SWcontext *swrast = SWRAST_CONTEXT( ctx );
912 swrast->choose_point = xmesa_choose_point;
913 swrast->choose_line = xmesa_choose_line;
914 swrast->choose_triangle = xmesa_choose_triangle;
916 /* XXX these lines have no net effect. Remove??? */
917 swrast->InvalidatePointMask |= XMESA_NEW_POINT;
918 swrast->InvalidateLineMask |= XMESA_NEW_LINE;
919 swrast->InvalidateTriangleMask |= XMESA_NEW_TRIANGLE;