diff options
author | Brian Paul <[email protected]> | 1999-12-17 14:52:35 +0000 |
---|---|---|
committer | Brian Paul <[email protected]> | 1999-12-17 14:52:35 +0000 |
commit | 0003778847df6adb792f453df83808fefa560f18 (patch) | |
tree | 2647b24bb9fa898f5c7e90def027cfcc8a8bf98b /src/mesa/main/context.c | |
parent | 8f91fb630c3292c6294384783d02e2e7402fc778 (diff) |
further simplification of thread-related code, misc clean-up
Diffstat (limited to 'src/mesa/main/context.c')
-rw-r--r-- | src/mesa/main/context.c | 359 |
1 files changed, 172 insertions, 187 deletions
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index 1e192f589fc..66d319494a5 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -1,4 +1,4 @@ -/* $Id: context.c,v 1.28 1999/12/17 12:21:38 brianp Exp $ */ +/* $Id: context.c,v 1.29 1999/12/17 14:52:35 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -83,24 +83,11 @@ /**********************************************************************/ -#ifdef THREADS +#if !defined(THREADS) -#include "glthread.h" - -static _glthread_TSD ContextTSD; - -static void ctx_thread_init() -{ - _glthread_InitTSD(&ContextTSD); -} - -#else - -/* One Current Context pointer for all threads in the address space */ -GLcontext *_mesa_current_context = NULL; struct immediate *CURRENT_INPUT = NULL; -#endif /*THREADS*/ +#endif @@ -1102,6 +1089,93 @@ void gl_destroy_visual( GLvisual *vis ) + +/* + * Create a new framebuffer. A GLframebuffer is a struct which + * encapsulates the depth, stencil and accum buffers and related + * parameters. + * Input: visual - a GLvisual pointer + * softwareDepth - create/use a software depth buffer? + * softwareStencil - create/use a software stencil buffer? + * softwareAccum - create/use a software accum buffer? + * softwareAlpha - create/use a software alpha buffer? + + * Return: pointer to new GLframebuffer struct or NULL if error. + */ +GLframebuffer *gl_create_framebuffer( GLvisual *visual, + GLboolean softwareDepth, + GLboolean softwareStencil, + GLboolean softwareAccum, + GLboolean softwareAlpha ) +{ + GLframebuffer *buffer; + + buffer = CALLOC_STRUCT(gl_frame_buffer); + if (!buffer) { + return NULL; + } + + /* sanity checks */ + if (softwareDepth ) { + assert(visual->DepthBits > 0); + } + if (softwareStencil) { + assert(visual->StencilBits > 0); + } + if (softwareAccum) { + assert(visual->RGBAflag); + assert(visual->AccumBits > 0); + } + if (softwareAlpha) { + assert(visual->RGBAflag); + assert(visual->AlphaBits > 0); + } + + buffer->Visual = visual; + buffer->UseSoftwareDepthBuffer = softwareDepth; + buffer->UseSoftwareStencilBuffer = softwareStencil; + buffer->UseSoftwareAccumBuffer = softwareAccum; + buffer->UseSoftwareAlphaBuffers = softwareAlpha; + + return buffer; +} + + + +/* + * Free a framebuffer struct and its buffers. + */ +void gl_destroy_framebuffer( GLframebuffer *buffer ) +{ + if (buffer) { + if (buffer->Depth) { + FREE( buffer->Depth ); + } + if (buffer->Accum) { + FREE( buffer->Accum ); + } + if (buffer->Stencil) { + FREE( buffer->Stencil ); + } + if (buffer->FrontLeftAlpha) { + FREE( buffer->FrontLeftAlpha ); + } + if (buffer->BackLeftAlpha) { + FREE( buffer->BackLeftAlpha ); + } + if (buffer->FrontRightAlpha) { + FREE( buffer->FrontRightAlpha ); + } + if (buffer->BackRightAlpha) { + FREE( buffer->BackRightAlpha ); + } + FREE(buffer); + } +} + + + + /* * Allocate the proxy textures. If we run out of memory part way through * the allocations clean up and return GL_FALSE. @@ -1289,14 +1363,6 @@ GLcontext *gl_create_context( GLvisual *visual, return ctx; } -/* Just reads the config files... - */ -void gl_context_initialize( GLcontext *ctx ) -{ - gl_read_config_file( ctx ); -} - - /* @@ -1407,90 +1473,93 @@ void gl_destroy_context( GLcontext *ctx ) /* - * Create a new framebuffer. A GLframebuffer is a struct which - * encapsulates the depth, stencil and accum buffers and related - * parameters. - * Input: visual - a GLvisual pointer - * softwareDepth - create/use a software depth buffer? - * softwareStencil - create/use a software stencil buffer? - * softwareAccum - create/use a software accum buffer? - * softwareAlpha - create/use a software alpha buffer? - - * Return: pointer to new GLframebuffer struct or NULL if error. + * Just reads the config files... */ -GLframebuffer *gl_create_framebuffer( GLvisual *visual, - GLboolean softwareDepth, - GLboolean softwareStencil, - GLboolean softwareAccum, - GLboolean softwareAlpha ) +void gl_context_initialize( GLcontext *ctx ) { - GLframebuffer *buffer; - - buffer = CALLOC_STRUCT(gl_frame_buffer); - if (!buffer) { - return NULL; - } - - /* sanity checks */ - if (softwareDepth ) { - assert(visual->DepthBits > 0); - } - if (softwareStencil) { - assert(visual->StencilBits > 0); - } - if (softwareAccum) { - assert(visual->RGBAflag); - assert(visual->AccumBits > 0); - } - if (softwareAlpha) { - assert(visual->RGBAflag); - assert(visual->AlphaBits > 0); - } - - buffer->Visual = visual; - buffer->UseSoftwareDepthBuffer = softwareDepth; - buffer->UseSoftwareStencilBuffer = softwareStencil; - buffer->UseSoftwareAccumBuffer = softwareAccum; - buffer->UseSoftwareAlphaBuffers = softwareAlpha; - - return buffer; + gl_read_config_file( ctx ); } /* - * Free a framebuffer struct and its buffers. + * Copy attribute groups from one context to another. + * Input: src - source context + * dst - destination context + * mask - bitwise OR of GL_*_BIT flags */ -void gl_destroy_framebuffer( GLframebuffer *buffer ) +void gl_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask ) { - if (buffer) { - if (buffer->Depth) { - FREE( buffer->Depth ); - } - if (buffer->Accum) { - FREE( buffer->Accum ); - } - if (buffer->Stencil) { - FREE( buffer->Stencil ); - } - if (buffer->FrontLeftAlpha) { - FREE( buffer->FrontLeftAlpha ); - } - if (buffer->BackLeftAlpha) { - FREE( buffer->BackLeftAlpha ); - } - if (buffer->FrontRightAlpha) { - FREE( buffer->FrontRightAlpha ); - } - if (buffer->BackRightAlpha) { - FREE( buffer->BackRightAlpha ); + if (mask & GL_ACCUM_BUFFER_BIT) { + MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) ); + } + if (mask & GL_COLOR_BUFFER_BIT) { + MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) ); + } + if (mask & GL_CURRENT_BIT) { + MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) ); + } + if (mask & GL_DEPTH_BUFFER_BIT) { + MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) ); + } + if (mask & GL_ENABLE_BIT) { + /* no op */ + } + if (mask & GL_EVAL_BIT) { + MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) ); + } + if (mask & GL_FOG_BIT) { + MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) ); + } + if (mask & GL_HINT_BIT) { + MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) ); + } + if (mask & GL_LIGHTING_BIT) { + MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) ); + /* gl_reinit_light_attrib( &dst->Light ); */ + } + if (mask & GL_LINE_BIT) { + MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) ); + } + if (mask & GL_LIST_BIT) { + MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) ); + } + if (mask & GL_PIXEL_MODE_BIT) { + MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) ); + } + if (mask & GL_POINT_BIT) { + MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) ); + } + if (mask & GL_POLYGON_BIT) { + MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) ); + } + if (mask & GL_POLYGON_STIPPLE_BIT) { + /* Use loop instead of MEMCPY due to problem with Portland Group's + * C compiler. Reported by John Stone. + */ + int i; + for (i=0;i<32;i++) { + dst->PolygonStipple[i] = src->PolygonStipple[i]; } - FREE(buffer); + } + if (mask & GL_SCISSOR_BIT) { + MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) ); + } + if (mask & GL_STENCIL_BUFFER_BIT) { + MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) ); + } + if (mask & GL_TEXTURE_BIT) { + MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) ); + } + if (mask & GL_TRANSFORM_BIT) { + MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) ); + } + if (mask & GL_VIEWPORT_BIT) { + MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) ); } } - /* * Set the current context, binding the given frame buffer to the context. */ @@ -1525,14 +1594,13 @@ void gl_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer, } #endif + /* We call this function periodically (just here for now) in + * order to detect when multithreading has begun. + */ _glapi_check_multithread(); -#ifdef THREADS - _glthread_SetTSD(&ContextTSD, (void *) newCtx, ctx_thread_init); + _glapi_set_current_context((void *) newCtx); ASSERT(gl_get_current_context() == newCtx); -#else - _mesa_current_context = newCtx; -#endif if (newCtx) { SET_IMMEDIATE(newCtx, newCtx->input); _glapi_set_dispatch(newCtx->CurrentDispatch); @@ -1571,98 +1639,17 @@ void gl_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer, /* * Return current context handle for the calling thread. + * This isn't the fastest way to get the current context. + * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h */ GLcontext *gl_get_current_context( void ) { -#ifdef THREADS - GLcontext *c = (GLcontext *) _glthread_GetTSD(&ContextTSD); - return c; -#else - return _mesa_current_context; -#endif + return (GLcontext *) _glapi_get_current_context(); } /* - * Copy attribute groups from one context to another. - * Input: src - source context - * dst - destination context - * mask - bitwise OR of GL_*_BIT flags - */ -void gl_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask ) -{ - if (mask & GL_ACCUM_BUFFER_BIT) { - MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) ); - } - if (mask & GL_COLOR_BUFFER_BIT) { - MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) ); - } - if (mask & GL_CURRENT_BIT) { - MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) ); - } - if (mask & GL_DEPTH_BUFFER_BIT) { - MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) ); - } - if (mask & GL_ENABLE_BIT) { - /* no op */ - } - if (mask & GL_EVAL_BIT) { - MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) ); - } - if (mask & GL_FOG_BIT) { - MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) ); - } - if (mask & GL_HINT_BIT) { - MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) ); - } - if (mask & GL_LIGHTING_BIT) { - MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) ); -/* gl_reinit_light_attrib( &dst->Light ); */ - } - if (mask & GL_LINE_BIT) { - MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) ); - } - if (mask & GL_LIST_BIT) { - MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) ); - } - if (mask & GL_PIXEL_MODE_BIT) { - MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) ); - } - if (mask & GL_POINT_BIT) { - MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) ); - } - if (mask & GL_POLYGON_BIT) { - MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) ); - } - if (mask & GL_POLYGON_STIPPLE_BIT) { - /* Use loop instead of MEMCPY due to problem with Portland Group's - * C compiler. Reported by John Stone. - */ - int i; - for (i=0;i<32;i++) { - dst->PolygonStipple[i] = src->PolygonStipple[i]; - } - } - if (mask & GL_SCISSOR_BIT) { - MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) ); - } - if (mask & GL_STENCIL_BUFFER_BIT) { - MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) ); - } - if (mask & GL_TEXTURE_BIT) { - MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) ); - } - if (mask & GL_TRANSFORM_BIT) { - MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) ); - } - if (mask & GL_VIEWPORT_BIT) { - MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) ); - } -} - - -/* * This should be called by device drivers just before they do a * swapbuffers. Any pending rendering commands will be executed. */ @@ -1673,6 +1660,7 @@ _mesa_swapbuffers(GLcontext *ctx) } + /* * Return pointer to this context's current API dispatch table. * It'll either be the immediate-mode execute dispatcher or the @@ -1689,7 +1677,7 @@ _mesa_get_dispatch(GLcontext *ctx) void _mesa_ResizeBuffersMESA( void ) { - GET_CURRENT_CONTEXT(ctx); + GLcontext *ctx = gl_get_current_context(); GLuint buf_width, buf_height; @@ -1712,15 +1700,12 @@ _mesa_ResizeBuffersMESA( void ) /* Reallocate other buffers if needed. */ if (ctx->DrawBuffer->UseSoftwareDepthBuffer) { - /* reallocate depth buffer */ gl_alloc_depth_buffer( ctx ); } if (ctx->DrawBuffer->UseSoftwareStencilBuffer) { - /* reallocate stencil buffer */ gl_alloc_stencil_buffer( ctx ); } if (ctx->DrawBuffer->UseSoftwareAccumBuffer) { - /* reallocate accum buffer */ gl_alloc_accum_buffer( ctx ); } if (ctx->Visual->SoftwareAlpha) { |