X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fshared.c;h=ce9fc4de327474b61e8f5f0b8d5e41b02532670f;hb=1d1eb9578716913f4133786b30c6e6edc69a8a0c;hp=643ad3354e7e617a6778ac9268443de3955b0108;hpb=16b393d05990b6e917e144f9de87d0103b4c3e6d;p=mesa.git diff --git a/src/mesa/main/shared.c b/src/mesa/main/shared.c index 643ad3354e7..ce9fc4de327 100644 --- a/src/mesa/main/shared.c +++ b/src/mesa/main/shared.c @@ -30,22 +30,18 @@ #include "imports.h" +#include "mfeatures.h" #include "mtypes.h" #include "hash.h" -#include "arrayobj.h" +#if FEATURE_ATI_fragment_shader +#include "atifragshader.h" +#endif #include "bufferobj.h" #include "shared.h" -#include "shader/program.h" -#include "shader/shader_api.h" -#if FEATURE_dlist +#include "program/program.h" #include "dlist.h" -#endif -#if FEATURE_ATI_fragment_shader -#include "shader/atifragshader.h" -#endif -#if FEATURE_ARB_sync +#include "shaderobj.h" #include "syncobj.h" -#endif /** * Allocate and initialize a shared context state structure. @@ -57,7 +53,7 @@ * failure. */ struct gl_shared_state * -_mesa_alloc_shared_state(GLcontext *ctx) +_mesa_alloc_shared_state(struct gl_context *ctx) { struct gl_shared_state *shared; GLuint i; @@ -95,12 +91,8 @@ _mesa_alloc_shared_state(GLcontext *ctx) shared->BufferObjects = _mesa_NewHashTable(); #endif - /* Allocate the default buffer object and set refcount so high that - * it never gets deleted. - * XXX with recent/improved refcounting this may not longer be needed. - */ + /* Allocate the default buffer object */ shared->NullBufferObj = ctx->Driver.NewBufferObject(ctx, 0, 0); - shared->NullBufferObj->RefCount = 1000 * 1000 * 1000; /* Create default texture objects */ for (i = 0; i < NUM_TEXTURE_TARGETS; i++) { @@ -129,9 +121,7 @@ _mesa_alloc_shared_state(GLcontext *ctx) shared->RenderBuffers = _mesa_NewHashTable(); #endif -#if FEATURE_ARB_sync make_empty_list(& shared->SyncObjects); -#endif return shared; } @@ -143,11 +133,9 @@ _mesa_alloc_shared_state(GLcontext *ctx) static void delete_displaylist_cb(GLuint id, void *data, void *userData) { -#if FEATURE_dlist struct gl_display_list *list = (struct gl_display_list *) data; - GLcontext *ctx = (GLcontext *) userData; + struct gl_context *ctx = (struct gl_context *) userData; _mesa_delete_list(ctx, list); -#endif } @@ -158,7 +146,7 @@ static void delete_texture_cb(GLuint id, void *data, void *userData) { struct gl_texture_object *texObj = (struct gl_texture_object *) data; - GLcontext *ctx = (GLcontext *) userData; + struct gl_context *ctx = (struct gl_context *) userData; ctx->Driver.DeleteTexture(ctx, texObj); } @@ -170,7 +158,7 @@ static void delete_program_cb(GLuint id, void *data, void *userData) { struct gl_program *prog = (struct gl_program *) data; - GLcontext *ctx = (GLcontext *) userData; + struct gl_context *ctx = (struct gl_context *) userData; if(prog != &_mesa_DummyProgram) { ASSERT(prog->RefCount == 1); /* should only be referenced by hash table */ prog->RefCount = 0; /* now going away */ @@ -188,7 +176,7 @@ static void delete_fragshader_cb(GLuint id, void *data, void *userData) { struct ati_fragment_shader *shader = (struct ati_fragment_shader *) data; - GLcontext *ctx = (GLcontext *) userData; + struct gl_context *ctx = (struct gl_context *) userData; _mesa_delete_ati_fragment_shader(ctx, shader); } #endif @@ -201,12 +189,12 @@ static void delete_bufferobj_cb(GLuint id, void *data, void *userData) { struct gl_buffer_object *bufObj = (struct gl_buffer_object *) data; - GLcontext *ctx = (GLcontext *) userData; + struct gl_context *ctx = (struct gl_context *) userData; if (_mesa_bufferobj_mapped(bufObj)) { ctx->Driver.UnmapBuffer(ctx, 0, bufObj); bufObj->Pointer = NULL; } - ctx->Driver.DeleteBuffer(ctx, bufObj); + _mesa_reference_buffer_object(ctx, &bufObj, NULL); } @@ -217,7 +205,7 @@ delete_bufferobj_cb(GLuint id, void *data, void *userData) static void free_shader_program_data_cb(GLuint id, void *data, void *userData) { - GLcontext *ctx = (GLcontext *) userData; + struct gl_context *ctx = (struct gl_context *) userData; struct gl_shader_program *shProg = (struct gl_shader_program *) data; if (shProg->Type == GL_SHADER_PROGRAM_MESA) { @@ -233,15 +221,15 @@ free_shader_program_data_cb(GLuint id, void *data, void *userData) static void delete_shader_cb(GLuint id, void *data, void *userData) { - GLcontext *ctx = (GLcontext *) userData; + struct gl_context *ctx = (struct gl_context *) userData; struct gl_shader *sh = (struct gl_shader *) data; if (sh->Type == GL_FRAGMENT_SHADER || sh->Type == GL_VERTEX_SHADER) { - _mesa_free_shader(ctx, sh); + ctx->Driver.DeleteShader(ctx, sh); } else { struct gl_shader_program *shProg = (struct gl_shader_program *) data; ASSERT(shProg->Type == GL_SHADER_PROGRAM_MESA); - _mesa_free_shader_program(ctx, shProg); + ctx->Driver.DeleteShaderProgram(ctx, shProg); } } @@ -292,11 +280,15 @@ delete_renderbuffer_cb(GLuint id, void *data, void *userData) * * \sa alloc_shared_state(). */ -void -_mesa_free_shared_state(GLcontext *ctx, struct gl_shared_state *shared) +static void +free_shared_state(struct gl_context *ctx, struct gl_shared_state *shared) { GLuint i; + /* Free the dummy/fallback texture object */ + if (shared->FallbackTex) + ctx->Driver.DeleteTexture(ctx, shared->FallbackTex); + /* * Free display lists */ @@ -339,10 +331,9 @@ _mesa_free_shared_state(GLcontext *ctx, struct gl_shared_state *shared) #endif #if FEATURE_ARB_vertex_buffer_object - ctx->Driver.DeleteBuffer(ctx, shared->NullBufferObj); + _mesa_reference_buffer_object(ctx, &shared->NullBufferObj, NULL); #endif -#if FEATURE_ARB_sync { struct simple_node *node; struct simple_node *temp; @@ -351,7 +342,6 @@ _mesa_free_shared_state(GLcontext *ctx, struct gl_shared_state *shared) _mesa_unref_sync_object(ctx, (struct gl_sync_object *) node); } } -#endif /* * Free texture objects (after FBOs since some textures might have @@ -370,5 +360,32 @@ _mesa_free_shared_state(GLcontext *ctx, struct gl_shared_state *shared) _glthread_DESTROY_MUTEX(shared->Mutex); _glthread_DESTROY_MUTEX(shared->TexMutex); - _mesa_free(shared); + free(shared); +} + + +/** + * Decrement shared state object reference count and potentially free it + * and all children structures. + * + * \param ctx GL context. + * \param shared shared state pointer. + * + * \sa free_shared_state(). + */ +void +_mesa_release_shared_state(struct gl_context *ctx, struct gl_shared_state *shared) +{ + GLint RefCount; + + _glthread_LOCK_MUTEX(shared->Mutex); + RefCount = --shared->RefCount; + _glthread_UNLOCK_MUTEX(shared->Mutex); + + assert(RefCount >= 0); + + if (RefCount == 0) { + /* free shared state */ + free_shared_state( ctx, shared ); + } }