From: Steinar H. Gunderson Date: Tue, 28 Jan 2014 20:22:57 +0000 (+0100) Subject: Remove the FBO freelist. X-Git-Url: https://git.sesse.net/?p=mlt;a=commitdiff_plain;h=1efe96041e015b55eb70f300cac5a1083decc868 Remove the FBO freelist. FBOs are cheap to construct and delete (they carry almost no state), so it is less complex just to do it on the fly. It also gives less leakage, as we use new contexts all the time. --- diff --git a/src/modules/opengl/filter_glsl_manager.cpp b/src/modules/opengl/filter_glsl_manager.cpp index a276f08b..9b013373 100644 --- a/src/modules/opengl/filter_glsl_manager.cpp +++ b/src/modules/opengl/filter_glsl_manager.cpp @@ -102,53 +102,6 @@ GlslManager* GlslManager::get_instance() return (GlslManager*) mlt_properties_get_data(mlt_global_properties(), "glslManager", 0); } -glsl_fbo GlslManager::get_fbo(int width, int height) -{ -#if defined(__DARWIN__) - CGLContextObj context = CGLGetCurrentContext(); -#elif defined(WIN32) - HGLRC context = wglGetCurrentContext(); -#else - GLXContext context = glXGetCurrentContext(); -#endif - - lock(); - for (int i = 0; i < fbo_list.count(); ++i) { - glsl_fbo fbo = (glsl_fbo) fbo_list.peek(i); - if (!fbo->used && (fbo->width == width) && (fbo->height == height) && (fbo->context == context)) { - fbo->used = 1; - unlock(); - return fbo; - } - } - unlock(); - - GLuint fb = 0; - glGenFramebuffers(1, &fb); - if (!fb) - return NULL; - - glsl_fbo fbo = new glsl_fbo_s; - if (!fbo) { - glDeleteFramebuffers(1, &fb); - return NULL; - } - fbo->fbo = fb; - fbo->width = width; - fbo->height = height; - fbo->used = 1; - fbo->context = context; - lock(); - fbo_list.push_back(fbo); - unlock(); - return fbo; -} - -void GlslManager::release_fbo(glsl_fbo fbo) -{ - fbo->used = 0; -} - glsl_texture GlslManager::get_texture(int width, int height, GLint internal_format) { lock(); @@ -257,11 +210,6 @@ glsl_pbo GlslManager::get_pbo(int size) void GlslManager::cleanupContext() { lock(); - while (fbo_list.peek_back()) { - glsl_fbo fbo = (glsl_fbo) fbo_list.pop_back(); - glDeleteFramebuffers(1, &fbo->fbo); - delete fbo; - } for (int i = 0; i < texture_list.count(); ++i) { glsl_texture texture = (glsl_texture) texture_list.peek(i); glDeleteTextures(1, &texture->texture); @@ -420,15 +368,15 @@ void GlslManager::set_effect_secondary_input( mlt_service service, mlt_frame fra int GlslManager::render_frame_texture(EffectChain *chain, mlt_frame frame, int width, int height, uint8_t **image) { - glsl_fbo fbo = get_fbo( width, height ); - if (!fbo) return 1; glsl_texture texture = get_texture( width, height, GL_RGBA8 ); if (!texture) { - release_fbo( fbo ); return 1; } - glBindFramebuffer( GL_FRAMEBUFFER, fbo->fbo ); + GLuint fbo; + glGenFramebuffers( 1, &fbo ); + check_error(); + glBindFramebuffer( GL_FRAMEBUFFER, fbo ); check_error(); glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture->texture, 0 ); check_error(); @@ -450,14 +398,15 @@ int GlslManager::render_frame_texture(EffectChain *chain, mlt_frame frame, int w glClientWaitSync( prev_sync, 0, GL_TIMEOUT_IGNORED ); glDeleteSync( prev_sync ); } - chain->render_to_fbo( fbo->fbo, width, height ); + chain->render_to_fbo( fbo, width, height ); prev_sync = glFenceSync( GL_SYNC_GPU_COMMANDS_COMPLETE, 0 ); GLsync sync = glFenceSync( GL_SYNC_GPU_COMMANDS_COMPLETE, 0 ); check_error(); glBindFramebuffer( GL_FRAMEBUFFER, 0 ); check_error(); - release_fbo( fbo ); + glDeleteFramebuffers( 1, &fbo ); + check_error(); *image = (uint8_t*) &texture->texture; mlt_frame_set_image( frame, *image, 0, NULL ); @@ -471,11 +420,8 @@ int GlslManager::render_frame_texture(EffectChain *chain, mlt_frame frame, int w int GlslManager::render_frame_rgba(EffectChain *chain, mlt_frame frame, int width, int height, uint8_t **image) { - glsl_fbo fbo = get_fbo( width, height ); - if (!fbo) return 1; glsl_texture texture = get_texture( width, height, GL_RGBA8 ); if (!texture) { - release_fbo( fbo ); return 1; } @@ -484,24 +430,25 @@ int GlslManager::render_frame_rgba(EffectChain *chain, mlt_frame frame, int widt int img_size = width * height * 4; glsl_pbo pbo = get_pbo( img_size ); if (!pbo) { - release_fbo( fbo ); release_texture(texture); return 1; } // Set the FBO + GLuint fbo; + glGenFramebuffers( 1, &fbo ); check_error(); - glBindFramebuffer( GL_FRAMEBUFFER, fbo->fbo ); + glBindFramebuffer( GL_FRAMEBUFFER, fbo ); check_error(); glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture->texture, 0 ); check_error(); glBindFramebuffer( GL_FRAMEBUFFER, 0 ); check_error(); - chain->render_to_fbo( fbo->fbo, width, height ); + chain->render_to_fbo( fbo, width, height ); // Read FBO into PBO - glBindFramebuffer( GL_FRAMEBUFFER, fbo->fbo ); + glBindFramebuffer( GL_FRAMEBUFFER, fbo ); check_error(); glBindBuffer( GL_PIXEL_PACK_BUFFER_ARB, pbo->pbo ); check_error(); @@ -537,7 +484,8 @@ int GlslManager::render_frame_rgba(EffectChain *chain, mlt_frame frame, int widt check_error(); mlt_properties_set_data( MLT_FRAME_PROPERTIES(frame), "movit.convert.texture", texture, 0, (mlt_destructor) GlslManager::release_texture, NULL); - release_fbo( fbo ); + glDeleteFramebuffers( 1, &fbo ); + check_error(); return 0; } diff --git a/src/modules/opengl/filter_glsl_manager.h b/src/modules/opengl/filter_glsl_manager.h index dff1b0c7..28810506 100644 --- a/src/modules/opengl/filter_glsl_manager.h +++ b/src/modules/opengl/filter_glsl_manager.h @@ -49,16 +49,6 @@ struct glsl_texture_s }; typedef struct glsl_texture_s *glsl_texture; -struct glsl_fbo_s -{ - int used; - int width; - int height; - GLuint fbo; - void* context; -}; -typedef struct glsl_fbo_s *glsl_fbo; - struct glsl_pbo_s { int size; @@ -96,8 +86,6 @@ public: void add_ref(mlt_properties properties); static GlslManager* get_instance(); - glsl_fbo get_fbo(int width, int height); - static void release_fbo(glsl_fbo); glsl_texture get_texture(int width, int height, GLint internal_format); static void release_texture(glsl_texture); static void delete_sync(GLsync sync); @@ -135,7 +123,6 @@ private: static void onServiceChanged( mlt_properties owner, mlt_service service ); static void onPropertyChanged( mlt_properties owner, mlt_service service, const char* property ); ResourcePool* resource_pool; - Mlt::Deque fbo_list; Mlt::Deque texture_list; Mlt::Deque syncs_to_delete; glsl_pbo pbo;