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 | |
parent | 8f91fb630c3292c6294384783d02e2e7402fc778 (diff) |
further simplification of thread-related code, misc clean-up
Diffstat (limited to 'src/mesa')
-rw-r--r-- | src/mesa/main/context.c | 359 | ||||
-rw-r--r-- | src/mesa/main/context.h | 55 |
2 files changed, 200 insertions, 214 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) { diff --git a/src/mesa/main/context.h b/src/mesa/main/context.h index 76ac1bb327a..57c209aae9f 100644 --- a/src/mesa/main/context.h +++ b/src/mesa/main/context.h @@ -1,4 +1,4 @@ -/* $Id: context.h,v 1.6 1999/12/17 12:21:39 brianp Exp $ */ +/* $Id: context.h,v 1.7 1999/12/17 14:52:37 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -29,6 +29,7 @@ #define CONTEXT_H +#include "glapi.h" #include "types.h" @@ -73,6 +74,21 @@ extern void gl_destroy_visual( GLvisual *vis ); /* + * Create/destroy a GLframebuffer. A GLframebuffer is like a GLX drawable. + * It bundles up the depth buffer, stencil buffer and accum buffers into a + * single entity. + */ +extern GLframebuffer *gl_create_framebuffer( GLvisual *visual, + GLboolean softwareDepth, + GLboolean softwareStencil, + GLboolean softwareAccum, + GLboolean softwareAlpha ); + +extern void gl_destroy_framebuffer( GLframebuffer *buffer ); + + + +/* * Create/destroy a GLcontext. A GLcontext is like a GLX context. It * contains the rendering state. */ @@ -92,36 +108,24 @@ extern void gl_context_initialize( GLcontext *ctx ); extern void gl_copy_context(const GLcontext *src, GLcontext *dst, GLuint mask); -/* - * Create/destroy a GLframebuffer. A GLframebuffer is like a GLX drawable. - * It bundles up the depth buffer, stencil buffer and accum buffers into a - * single entity. - */ -extern GLframebuffer *gl_create_framebuffer( GLvisual *visual, - GLboolean softwareDepth, - GLboolean softwareStencil, - GLboolean softwareAccum, - GLboolean softwareAlpha ); - -extern void gl_destroy_framebuffer( GLframebuffer *buffer ); - - - extern void gl_make_current( GLcontext *ctx, GLframebuffer *buffer ); + extern void gl_make_current2( GLcontext *ctx, GLframebuffer *drawBuffer, GLframebuffer *readBuffer ); -extern GLcontext *gl_get_current_context(void); +extern GLcontext *gl_get_current_context(void); -#ifdef THREADS /* - * A seperate GLcontext for each thread + * Macros for fetching current context, input buffer, etc. */ -#define GET_CURRENT_CONTEXT(C) GLcontext *C = gl_get_current_context() -#define GET_IMMEDIATE struct immediate *IM = (gl_get_current_context())->input; +#ifdef THREADS + +#define GET_CURRENT_CONTEXT(C) GLcontext *C = (GLcontext *) (_glapi_ThreadSafe ? _glapi_get_current_context() : _glapi_CurrentContext) + +#define GET_IMMEDIATE struct immediate *IM = ((GLcontext *) _glapi_get_current_context())->input; #define SET_IMMEDIATE(ctx, im) \ do { \ ctx->input = im; \ @@ -129,12 +133,8 @@ do { \ #else -/* - * All threads use same pointer to current context. - */ -extern GLcontext *_mesa_current_context; extern struct immediate *CURRENT_INPUT; -#define GET_CURRENT_CONTEXT(C) GLcontext *C = _mesa_current_context +#define GET_CURRENT_CONTEXT(C) GLcontext *C = _glapi_CurrentContext #define GET_IMMEDIATE struct immediate *IM = CURRENT_INPUT #define SET_IMMEDIATE(ctx, im) \ do { \ @@ -149,6 +149,7 @@ do { \ extern void _mesa_swapbuffers(GLcontext *ctx); + extern struct _glapi_table * _mesa_get_dispatch(GLcontext *ctx); @@ -170,8 +171,8 @@ extern void gl_problem( const GLcontext *ctx, const char *s ); extern void gl_warning( const GLcontext *ctx, const char *s ); extern void gl_error( GLcontext *ctx, GLenum error, const char *s ); -extern void gl_compile_error( GLcontext *ctx, GLenum error, const char *s ); +extern void gl_compile_error( GLcontext *ctx, GLenum error, const char *s ); extern void gl_update_state( GLcontext *ctx ); |