From 18a285a5e244b7405b85feb7315a30d99920ec5d Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sat, 16 Mar 2002 00:53:15 +0000 Subject: Lots of changes related to framebuffer/window buffer resizing. Basically, instead of passing a GLcontext* to ResizeBuffers(), pass a GLframebuffer*. The idea is that a window can be resized without it being bound to a rendering context. This makes for a nice clean-up in the XFree86 server-side GLX code. Renamed ctx->Driver.ResizeBuffersMESA() to ctx->Driver.ResizeBuffers(). --- src/mesa/drivers/dos/dmesa.c | 9 +++- src/mesa/drivers/glide/fxdd.c | 25 +++++---- src/mesa/drivers/osmesa/osmesa.c | 16 +++--- src/mesa/drivers/svga/svgamesa.c | 5 +- src/mesa/drivers/windows/wmesa.c | 9 ++-- src/mesa/drivers/x11/xm_api.c | 17 ++++-- src/mesa/drivers/x11/xm_dd.c | 113 ++++++++++++++++++++------------------- src/mesa/drivers/x11/xmesaP.h | 6 ++- 8 files changed, 114 insertions(+), 86 deletions(-) (limited to 'src/mesa/drivers') diff --git a/src/mesa/drivers/dos/dmesa.c b/src/mesa/drivers/dos/dmesa.c index 454b891c08..d150cdca5a 100644 --- a/src/mesa/drivers/dos/dmesa.c +++ b/src/mesa/drivers/dos/dmesa.c @@ -540,8 +540,13 @@ static GLboolean set_draw_buffer (GLcontext *ctx, GLenum mode) * If anything special has to been done when the buffer/window is * resized, do it now. */ -static void get_buffer_size (GLcontext *ctx, GLuint *width, GLuint *height) +static void get_buffer_size (GLframebuffer *buffer, GLuint *width, GLuint *height) { + /* XXX this may not be right. We should query the size of the DOS window + * associated with . This function should work whether or + * not there is a current context. + */ + GET_CURRENT_CONTEXT(ctx); DMesaContext c = (DMesaContext)ctx->DriverCtx; *width = c->Buffer->width; @@ -636,7 +641,7 @@ void dmesa_init_pointers (GLcontext *ctx) ctx->Driver.Accum = _swrast_Accum; ctx->Driver.Bitmap = _swrast_Bitmap; ctx->Driver.Clear = clear; - ctx->Driver.ResizeBuffersMESA = _swrast_alloc_buffers; + ctx->Driver.ResizeBuffers = _swrast_alloc_buffers; ctx->Driver.CopyPixels = _swrast_CopyPixels; ctx->Driver.DrawPixels = _swrast_DrawPixels; ctx->Driver.ReadPixels = _swrast_ReadPixels; diff --git a/src/mesa/drivers/glide/fxdd.c b/src/mesa/drivers/glide/fxdd.c index 720ef41d3f..8cdbe35382 100644 --- a/src/mesa/drivers/glide/fxdd.c +++ b/src/mesa/drivers/glide/fxdd.c @@ -1,4 +1,4 @@ -/* $Id: fxdd.c,v 1.84 2001/09/23 16:50:01 brianp Exp $ */ +/* $Id: fxdd.c,v 1.85 2002/03/16 00:53:15 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -103,19 +103,22 @@ fxInitPixelTables(fxMesaContext fxMesa, GLboolean bgrOrder) /* Return buffer size information */ static void -fxDDBufferSize(GLcontext * ctx, GLuint * width, GLuint * height) +fxDDBufferSize(GLframebuffer *buffer, GLuint * width, GLuint * height) { - fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GET_CURRENT_CONTEXT(ctx); + if (ctx && ctx->DriverCtx) { + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; - if (MESA_VERBOSE & VERBOSE_DRIVER) { - fprintf(stderr, "fxmesa: fxDDBufferSize(...) Start\n"); - } + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxDDBufferSize(...) Start\n"); + } - *width = fxMesa->width; - *height = fxMesa->height; + *width = fxMesa->width; + *height = fxMesa->height; - if (MESA_VERBOSE & VERBOSE_DRIVER) { - fprintf(stderr, "fxmesa: fxDDBufferSize(...) End\n"); + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxDDBufferSize(...) End\n"); + } } } @@ -1002,7 +1005,7 @@ fxSetupDDPointers(GLcontext * ctx) ctx->Driver.CopyPixels = _swrast_CopyPixels; ctx->Driver.DrawPixels = _swrast_DrawPixels; ctx->Driver.ReadPixels = fxDDReadPixels; - ctx->Driver.ResizeBuffersMESA = _swrast_alloc_buffers; + ctx->Driver.ResizeBuffers = _swrast_alloc_buffers; ctx->Driver.Finish = fxDDFinish; ctx->Driver.Flush = NULL; ctx->Driver.ChooseTextureFormat = fxDDChooseTextureFormat; diff --git a/src/mesa/drivers/osmesa/osmesa.c b/src/mesa/drivers/osmesa/osmesa.c index 842ad6652b..1cc7439afd 100644 --- a/src/mesa/drivers/osmesa/osmesa.c +++ b/src/mesa/drivers/osmesa/osmesa.c @@ -1,4 +1,4 @@ -/* $Id: osmesa.c,v 1.74 2002/03/01 04:23:36 brianp Exp $ */ +/* $Id: osmesa.c,v 1.75 2002/03/16 00:53:15 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -875,11 +875,15 @@ static void clear( GLcontext *ctx, GLbitfield mask, GLboolean all, -static void buffer_size( GLcontext *ctx, GLuint *width, GLuint *height ) +static void buffer_size( GLframebuffer *buffer, GLuint *width, GLuint *height ) { - OSMesaContext osmesa = OSMESA_CONTEXT(ctx); - *width = osmesa->width; - *height = osmesa->height; + GET_CURRENT_CONTEXT(ctx); + (void) buffer; + if (ctx) { + OSMesaContext osmesa = OSMESA_CONTEXT(ctx); + *width = osmesa->width; + *height = osmesa->height; + } } @@ -2023,7 +2027,7 @@ static void osmesa_update_state( GLcontext *ctx, GLuint new_state ) ctx->Driver.GetString = get_string; ctx->Driver.UpdateState = osmesa_update_state; ctx->Driver.SetDrawBuffer = set_draw_buffer; - ctx->Driver.ResizeBuffersMESA = _swrast_alloc_buffers; + ctx->Driver.ResizeBuffers = _swrast_alloc_buffers; ctx->Driver.GetBufferSize = buffer_size; ctx->Driver.Accum = _swrast_Accum; diff --git a/src/mesa/drivers/svga/svgamesa.c b/src/mesa/drivers/svga/svgamesa.c index db97d20194..c841f46f01 100644 --- a/src/mesa/drivers/svga/svgamesa.c +++ b/src/mesa/drivers/svga/svgamesa.c @@ -1,4 +1,4 @@ -/* $Id: svgamesa.c,v 1.16 2001/09/23 16:11:27 brianp Exp $ */ +/* $Id: svgamesa.c,v 1.17 2002/03/16 00:53:15 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -210,7 +210,7 @@ static void copy_buffer( const GLubyte * buffer) { } } -static void get_buffer_size( GLcontext *ctx, GLuint *width, GLuint *height ) +static void get_buffer_size( GLframebuffer *buffer, GLuint *width, GLuint *height ) { *width = SVGAMesa->width = vga_getxdim(); *height = SVGAMesa->height = vga_getydim(); @@ -286,6 +286,7 @@ static void svgamesa_update_state( GLcontext *ctx, GLuint new_state ) ctx->Driver.GetBufferSize = get_buffer_size; ctx->Driver.SetDrawBuffer = set_draw_buffer; + ctx->Driver.ResizeBuffers = _swrast_alloc_buffers; /* Software rasterizer pixel paths: */ diff --git a/src/mesa/drivers/windows/wmesa.c b/src/mesa/drivers/windows/wmesa.c index 47edef993e..4f057bfad7 100644 --- a/src/mesa/drivers/windows/wmesa.c +++ b/src/mesa/drivers/windows/wmesa.c @@ -1,4 +1,4 @@ -/* $Id: wmesa.c,v 1.25 2002/01/16 15:42:17 kschultz Exp $ */ +/* $Id: wmesa.c,v 1.26 2002/03/16 00:53:15 brianp Exp $ */ /* * Windows (Win32) device driver for Mesa 3.4 @@ -583,8 +583,9 @@ static void set_read_buffer(GLcontext *ctx, GLframebuffer *colorBuffer, /* Return characteristics of the output buffer. */ -static void buffer_size( GLcontext* ctx, GLuint *width, GLuint *height ) +static void buffer_size( GLframebuffer *buffer, GLuint *width, GLuint *height ) { + GET_CURRENT_CONTEXT(ctx); int New_Size; RECT CR; @@ -1021,7 +1022,7 @@ static void SetFunctionPointers(GLcontext *ctx) ctx->Driver.GetString = get_string; ctx->Driver.UpdateState = wmesa_update_state; ctx->Driver.SetDrawBuffer = set_draw_buffer; - ctx->Driver.ResizeBuffersMESA = _swrast_alloc_buffers; + ctx->Driver.ResizeBuffers = _swrast_alloc_buffers; ctx->Driver.GetBufferSize = buffer_size; ctx->Driver.Accum = _swrast_Accum; @@ -1100,7 +1101,7 @@ static void wmesa_update_state( GLcontext *ctx, GLuint new_state ) ctx->Driver.GetString = get_string; ctx->Driver.UpdateState = wmesa_update_state; ctx->Driver.SetDrawBuffer = set_draw_buffer; - ctx->Driver.ResizeBuffersMESA = _swrast_alloc_buffers; + ctx->Driver.ResizeBuffers = _swrast_alloc_buffers; ctx->Driver.GetBufferSize = buffer_size; ctx->Driver.Accum = _swrast_Accum; diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c index ce5576d68d..9ee36a45ca 100644 --- a/src/mesa/drivers/x11/xm_api.c +++ b/src/mesa/drivers/x11/xm_api.c @@ -1,8 +1,8 @@ -/* $Id: xm_api.c,v 1.34 2002/03/12 21:55:50 brianp Exp $ */ +/* $Id: xm_api.c,v 1.35 2002/03/16 00:53:15 brianp Exp $ */ /* * Mesa 3-D graphics library - * Version: 4.1 + * Version: 4.0.2 * * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. * @@ -2329,9 +2329,8 @@ void XMesaSwapBuffers( XMesaBuffer b ) /* If we're swapping the buffer associated with the current context * we have to flush any pending rendering commands first. */ - if (ctx && ctx->DrawBuffer == &(b->mesa_buffer)) { + if (ctx && ctx->DrawBuffer == &(b->mesa_buffer)) _mesa_swapbuffers(ctx); - } if (b->db_state) { #ifdef FX @@ -2630,3 +2629,13 @@ unsigned long XMesaDitherColor( XMesaContext xmesa, GLint x, GLint y, } +/* + * This is typically called when the window size changes and we need + * to reallocate the buffer's back/depth/stencil/accum buffers. + */ +void XMesaResizeBuffers( XMesaBuffer b ) +{ + xmesa_resize_buffers( &(b->mesa_buffer) ); + +} + diff --git a/src/mesa/drivers/x11/xm_dd.c b/src/mesa/drivers/x11/xm_dd.c index ec79f3c514..642aee8a22 100644 --- a/src/mesa/drivers/x11/xm_dd.c +++ b/src/mesa/drivers/x11/xm_dd.c @@ -1,8 +1,8 @@ -/* $Id: xm_dd.c,v 1.29 2002/03/01 04:28:32 brianp Exp $ */ +/* $Id: xm_dd.c,v 1.30 2002/03/16 00:53:15 brianp Exp $ */ /* * Mesa 3-D graphics library - * Version: 4.1 + * Version: 4.0.2 * * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. * @@ -48,17 +48,18 @@ /* - * Return the size (width,height of the current color buffer. - * This function should be called by the glViewport function because - * glViewport is often called when the window gets resized. We need to - * update some X/Mesa stuff when that happens. + * Return the size (width, height) of the X window for the given GLframebuffer. * Output: width - width of buffer in pixels. * height - height of buffer in pixels. */ static void -get_buffer_size( GLcontext *ctx, GLuint *width, GLuint *height ) +get_buffer_size( GLframebuffer *buffer, GLuint *width, GLuint *height ) { - const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; + /* We can do this cast because the first field in the XMesaBuffer + * struct is a GLframebuffer struct. If this weren't true, we'd + * need a pointer from the GLframebuffer to the XMesaBuffer. + */ + const XMesaBuffer xmBuffer = (XMesaBuffer) buffer; unsigned int winwidth, winheight; #ifndef XFree86Server Window root; @@ -66,58 +67,19 @@ get_buffer_size( GLcontext *ctx, GLuint *width, GLuint *height ) unsigned int bw, d; _glthread_LOCK_MUTEX(_xmesa_lock); - XGetGeometry( xmesa->display, xmesa->xm_buffer->frontbuffer, &root, + XGetGeometry( xmBuffer->xm_visual->display, xmBuffer->frontbuffer, &root, &winx, &winy, &winwidth, &winheight, &bw, &d ); _glthread_UNLOCK_MUTEX(_xmesa_lock); #else - - winwidth = xmesa->xm_buffer->frontbuffer->width; - winheight = xmesa->xm_buffer->frontbuffer->height; + /* XFree86 GLX renderer */ + winwidth = xmBuffer->frontbuffer->width; + winheight = xmBuffer->frontbuffer->height; #endif (void)kernel8; /* Muffle compiler */ *width = winwidth; *height = winheight; - - if ( winwidth!=xmesa->xm_buffer->width - || winheight!=xmesa->xm_buffer->height) { - xmesa->xm_buffer->width = winwidth; - xmesa->xm_buffer->height = winheight; - xmesa_alloc_back_buffer( xmesa->xm_buffer ); - } - - /* Needed by FLIP macro */ - xmesa->xm_buffer->bottom = (int) winheight - 1; - - if (xmesa->xm_buffer->backimage) { - /* Needed by PIXELADDR1 macro */ - xmesa->xm_buffer->ximage_width1 - = xmesa->xm_buffer->backimage->bytes_per_line; - xmesa->xm_buffer->ximage_origin1 - = (GLubyte *) xmesa->xm_buffer->backimage->data - + xmesa->xm_buffer->ximage_width1 * (winheight-1); - - /* Needed by PIXELADDR2 macro */ - xmesa->xm_buffer->ximage_width2 - = xmesa->xm_buffer->backimage->bytes_per_line / 2; - xmesa->xm_buffer->ximage_origin2 - = (GLushort *) xmesa->xm_buffer->backimage->data - + xmesa->xm_buffer->ximage_width2 * (winheight-1); - - /* Needed by PIXELADDR3 macro */ - xmesa->xm_buffer->ximage_width3 - = xmesa->xm_buffer->backimage->bytes_per_line; - xmesa->xm_buffer->ximage_origin3 - = (GLubyte *) xmesa->xm_buffer->backimage->data - + xmesa->xm_buffer->ximage_width3 * (winheight-1); - - /* Needed by PIXELADDR4 macro */ - xmesa->xm_buffer->ximage_width4 = xmesa->xm_buffer->backimage->width; - xmesa->xm_buffer->ximage_origin4 - = (GLuint *) xmesa->xm_buffer->backimage->data - + xmesa->xm_buffer->ximage_width4 * (winheight-1); - } } @@ -780,10 +742,51 @@ clear_buffers( GLcontext *ctx, GLbitfield mask, } -static void -resize_buffers( GLcontext *ctx ) +/* + * When we detect that the user has resized the window this function will + * get called. Here we'll reallocate the back buffer, depth buffer, + * stencil buffer etc. to match the new window size. + */ +void +xmesa_resize_buffers( GLframebuffer *buffer ) { - _swrast_alloc_buffers( ctx ); + int height = (int) buffer->Height; + /* We can do this cast because the first field in the XMesaBuffer + * struct is a GLframebuffer struct. If this weren't true, we'd + * need a pointer from the GLframebuffer to the XMesaBuffer. + */ + XMesaBuffer xmBuffer = (XMesaBuffer) buffer; + + xmBuffer->width = buffer->Width; + xmBuffer->height = buffer->Height; + xmesa_alloc_back_buffer( xmBuffer ); + + /* Needed by FLIP macro */ + xmBuffer->bottom = height - 1; + + if (xmBuffer->backimage) { + /* Needed by PIXELADDR1 macro */ + xmBuffer->ximage_width1 = xmBuffer->backimage->bytes_per_line; + xmBuffer->ximage_origin1 = (GLubyte *) xmBuffer->backimage->data + + xmBuffer->ximage_width1 * (height-1); + + /* Needed by PIXELADDR2 macro */ + xmBuffer->ximage_width2 = xmBuffer->backimage->bytes_per_line / 2; + xmBuffer->ximage_origin2 = (GLushort *) xmBuffer->backimage->data + + xmBuffer->ximage_width2 * (height-1); + + /* Needed by PIXELADDR3 macro */ + xmBuffer->ximage_width3 = xmBuffer->backimage->bytes_per_line; + xmBuffer->ximage_origin3 = (GLubyte *) xmBuffer->backimage->data + + xmBuffer->ximage_width3 * (height-1); + + /* Needed by PIXELADDR4 macro */ + xmBuffer->ximage_width4 = xmBuffer->backimage->width; + xmBuffer->ximage_origin4 = (GLuint *) xmBuffer->backimage->data + + xmBuffer->ximage_width4 * (height-1); + } + + _swrast_alloc_buffers( buffer ); } #if 0 @@ -951,7 +954,7 @@ void xmesa_init_pointers( GLcontext *ctx ) ctx->Driver.Accum = _swrast_Accum; ctx->Driver.Bitmap = _swrast_Bitmap; ctx->Driver.Clear = clear_buffers; - ctx->Driver.ResizeBuffersMESA = resize_buffers; + ctx->Driver.ResizeBuffers = xmesa_resize_buffers; ctx->Driver.CopyPixels = _swrast_CopyPixels; ctx->Driver.DrawPixels = _swrast_DrawPixels; ctx->Driver.ReadPixels = _swrast_ReadPixels; diff --git a/src/mesa/drivers/x11/xmesaP.h b/src/mesa/drivers/x11/xmesaP.h index 409ea22567..d61ee88e55 100644 --- a/src/mesa/drivers/x11/xmesaP.h +++ b/src/mesa/drivers/x11/xmesaP.h @@ -1,8 +1,8 @@ -/* $Id: xmesaP.h,v 1.26 2002/03/12 21:55:50 brianp Exp $ */ +/* $Id: xmesaP.h,v 1.27 2002/03/16 00:53:15 brianp Exp $ */ /* * Mesa 3-D graphics library - * Version: 4.2 + * Version: 4.0.2 * * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. * @@ -532,4 +532,6 @@ extern void XMesaReset( void ); extern void xmesa_set_read_buffer( GLcontext *ctx, GLframebuffer *buffer, GLenum mode ); +extern void xmesa_resize_buffers( GLframebuffer *buffer ); + #endif -- cgit v1.2.3