/** * Free all the data hanging off the given gl_framebuffer, but don't free * the gl_framebuffer object itself. */ void _mesa_free_framebuffer_data(struct gl_framebuffer *fb) { GLuint i; assert(fb); assert(fb->RefCount == 0); _glthread_DESTROY_MUTEX(fb->Mutex); for (i = 0; i < BUFFER_COUNT; i++) { struct gl_renderbuffer_attachment *att = &fb->Attachment[i]; if (att->Renderbuffer) { _mesa_reference_renderbuffer(&att->Renderbuffer, NULL); } if (att->Texture) { _mesa_reference_texobj(&att->Texture, NULL); } ASSERT(!att->Renderbuffer); ASSERT(!att->Texture); att->Type = GL_NONE; } /* unbind _Depth/_StencilBuffer to decr ref counts */ _mesa_reference_renderbuffer(&fb->_DepthBuffer, NULL); _mesa_reference_renderbuffer(&fb->_StencilBuffer, NULL); }
/** * Deallocate a texture object struct. It should have already been * removed from the texture object pool. * Called via ctx->Driver.DeleteTexture() if not overriden by a driver. * * \param shared the shared GL state to which the object belongs. * \param texObj the texture object to delete. */ void _mesa_delete_texture_object(struct gl_context *ctx, struct gl_texture_object *texObj) { GLuint i, face; /* Set Target to an invalid value. With some assertions elsewhere * we can try to detect possible use of deleted textures. */ texObj->Target = 0x99; /* free the texture images */ for (face = 0; face < 6; face++) { for (i = 0; i < MAX_TEXTURE_LEVELS; i++) { if (texObj->Image[face][i]) { ctx->Driver.DeleteTextureImage(ctx, texObj->Image[face][i]); } } } _mesa_reference_buffer_object(ctx, &texObj->BufferObject, NULL); /* destroy the mutex -- it may have allocated memory (eg on bsd) */ _glthread_DESTROY_MUTEX(texObj->Mutex); /* free this object */ free(texObj); }
/** * Delete an array object. * * This function is intended to be called via * \c dd_function_table::DeleteArrayObject. */ void _mesa_delete_array_object( struct gl_context *ctx, struct gl_array_object *obj ) { (void) ctx; unbind_array_object_vbos(ctx, obj); _glthread_DESTROY_MUTEX(obj->Mutex); free(obj); }
/** * Delete an array object. * * This function is intended to be called via * \c dd_function_table::DeleteArrayObject. */ void _mesa_delete_array_object( struct gl_context *ctx, struct gl_array_object *obj ) { (void) ctx; unbind_array_object_vbos(ctx, obj); _mesa_reference_buffer_object(ctx, &obj->ElementArrayBufferObj, NULL); _glthread_DESTROY_MUTEX(obj->Mutex); free(obj); }
/** * Delete a hash table. * Frees each entry on the hash table and then the hash table structure itself. * Note that the caller should have already traversed the table and deleted * the objects in the table (i.e. We don't free the entries' data pointer). * * \param table the hash table to delete. */ void _mesa_DeleteHashTable(struct _mesa_HashTable *table) { GLuint pos; assert(table); for (pos = 0; pos < TABLE_SIZE; pos++) { struct HashEntry *entry = table->Table[pos]; while (entry) { struct HashEntry *next = entry->Next; if (entry->Data) { _mesa_problem(NULL, "In _mesa_DeleteHashTable, found non-freed data"); } free(entry); entry = next; } } _glthread_DESTROY_MUTEX(table->Mutex); _glthread_DESTROY_MUTEX(table->WalkMutex); free(table); }
/** * Delete a hash table. * \param table - the hash table to delete */ void _mesa_DeleteHashTable(struct _mesa_HashTable *table) { GLuint i; assert(table); for (i=0;i<TABLE_SIZE;i++) { struct HashEntry *entry = table->Table[i]; while (entry) { struct HashEntry *next = entry->Next; FREE(entry); entry = next; } } _glthread_DESTROY_MUTEX(table->Mutex); FREE(table); }
/** * Delete a buffer object. * * Default callback for the \c dd_function_table::DeleteBuffer() hook. */ static void _mesa_delete_buffer_object(struct gl_context *ctx, struct gl_buffer_object *bufObj) { (void) ctx; if (bufObj->Data) free(bufObj->Data); /* assign strange values here to help w/ debugging */ bufObj->RefCount = -1000; bufObj->Name = ~0; _glthread_DESTROY_MUTEX(bufObj->Mutex); free(bufObj); }
void stw_cleanup(void) { unsigned i; debug_printf("%s\n", __FUNCTION__); if (!stw_dev) return; pipe_mutex_lock( stw_dev->ctx_mutex ); { /* Ensure all contexts are destroyed */ i = handle_table_get_first_handle(stw_dev->ctx_table); while (i) { stw_delete_context(i); i = handle_table_get_next_handle(stw_dev->ctx_table, i); } handle_table_destroy(stw_dev->ctx_table); } pipe_mutex_unlock( stw_dev->ctx_mutex ); stw_framebuffer_cleanup(); pipe_mutex_destroy( stw_dev->fb_mutex ); pipe_mutex_destroy( stw_dev->ctx_mutex ); stw_dev->screen->destroy(stw_dev->screen); #ifdef WIN32_THREADS _glthread_DESTROY_MUTEX(OneTimeLock); FreeAllTSD(); #endif #ifdef DEBUG debug_memory_end(stw_dev->memdbg_no); #endif stw_tls_cleanup(); stw_dev = NULL; }
/** * Deallocate a texture object struct. It should have already been * removed from the texture object pool. * * \param shared the shared GL state to which the object belongs. * \param texOjb the texture object to delete. */ void _mesa_delete_texture_object( GLcontext *ctx, struct gl_texture_object *texObj ) { GLuint i, face; (void) ctx; _mesa_free_colortable_data(&texObj->Palette); /* free the texture images */ for (face = 0; face < 6; face++) { for (i = 0; i < MAX_TEXTURE_LEVELS; i++) { if (texObj->Image[face][i]) { _mesa_delete_texture_image( ctx, texObj->Image[face][i] ); } } } /* destroy the mutex -- it may have allocated memory (eg on bsd) */ _glthread_DESTROY_MUTEX(texObj->Mutex); /* free this object */ _mesa_free(texObj); }
/** * Deallocate a shared state object and all children structures. * * \param ctx GL context. * \param shared shared state pointer. * * Frees the display lists, the texture objects (calling the driver texture * deletion callback to free its private data) and the vertex programs, as well * as their hash tables. * * \sa alloc_shared_state(). */ void _mesa_free_shared_state(GLcontext *ctx, struct gl_shared_state *shared) { GLuint i; /* * Free display lists */ _mesa_HashDeleteAll(shared->DisplayList, delete_displaylist_cb, ctx); _mesa_DeleteHashTable(shared->DisplayList); #if FEATURE_ARB_shader_objects _mesa_HashWalk(shared->ShaderObjects, free_shader_program_data_cb, ctx); _mesa_HashDeleteAll(shared->ShaderObjects, delete_shader_cb, ctx); _mesa_DeleteHashTable(shared->ShaderObjects); #endif _mesa_HashDeleteAll(shared->Programs, delete_program_cb, ctx); _mesa_DeleteHashTable(shared->Programs); _mesa_HashDeleteAll(shared->ArrayObjects, delete_arrayobj_cb, ctx); _mesa_DeleteHashTable(shared->ArrayObjects); #if FEATURE_ARB_vertex_program _mesa_reference_vertprog(ctx, &shared->DefaultVertexProgram, NULL); #endif #if FEATURE_ARB_fragment_program _mesa_reference_fragprog(ctx, &shared->DefaultFragmentProgram, NULL); #endif #if FEATURE_ATI_fragment_shader _mesa_HashDeleteAll(shared->ATIShaders, delete_fragshader_cb, ctx); _mesa_DeleteHashTable(shared->ATIShaders); _mesa_delete_ati_fragment_shader(ctx, shared->DefaultFragmentShader); #endif #if FEATURE_ARB_vertex_buffer_object || FEATURE_ARB_pixel_buffer_object _mesa_HashDeleteAll(shared->BufferObjects, delete_bufferobj_cb, ctx); _mesa_DeleteHashTable(shared->BufferObjects); #endif #if FEATURE_EXT_framebuffer_object _mesa_HashDeleteAll(shared->FrameBuffers, delete_framebuffer_cb, ctx); _mesa_DeleteHashTable(shared->FrameBuffers); _mesa_HashDeleteAll(shared->RenderBuffers, delete_renderbuffer_cb, ctx); _mesa_DeleteHashTable(shared->RenderBuffers); #endif /* * Free texture objects (after FBOs since some textures might have * been bound to FBOs). */ ASSERT(ctx->Driver.DeleteTexture); /* the default textures */ for (i = 0; i < NUM_TEXTURE_TARGETS; i++) { ctx->Driver.DeleteTexture(ctx, shared->DefaultTex[i]); } /* all other textures */ _mesa_HashDeleteAll(shared->TexObjects, delete_texture_cb, ctx); _mesa_DeleteHashTable(shared->TexObjects); _glthread_DESTROY_MUTEX(shared->Mutex); _glthread_DESTROY_MUTEX(shared->TexMutex); _mesa_free(shared); }
/** * Delete a gl_framebuffer. * This is the default function for renderbuffer->Delete(). * Drivers which subclass gl_renderbuffer should probably implement their * own delete function. But the driver might also call this function to * free the object in the end. */ void _mesa_delete_renderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb) { _glthread_DESTROY_MUTEX(rb->Mutex); free(rb); }