]> git.sesse.net Git - mlt/commitdiff
Add back automatic cleanup of OpenGL fences.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 12 Jan 2014 22:51:21 +0000 (23:51 +0100)
committerDan Dennedy <dan@dennedy.org>
Sun, 12 Jan 2014 23:40:50 +0000 (15:40 -0800)
Instead of having the client do deletion of fences, work around the problem
with missing contexts by adding them to a list in the GlslManager, which then
it garbage-collected before creating more fences.

src/modules/opengl/filter_glsl_manager.cpp
src/modules/opengl/filter_glsl_manager.h

index 72ca55af0c1ff9cd66acea934b2ad87fb7c2c339..9cb0855cb5da0ea530df2e7c02cbdfbfbff14290 100644 (file)
@@ -80,6 +80,10 @@ GlslManager::~GlslManager()
        if (prev_sync != NULL) {
                glDeleteSync( prev_sync );
        }
+       while (syncs_to_delete.count() > 0) {
+               GLsync sync = (GLsync) syncs_to_delete.pop_front();
+               glDeleteSync( sync );
+       }
 }
 
 GlslManager* GlslManager::get_instance()
@@ -198,6 +202,17 @@ void GlslManager::release_texture(glsl_texture texture)
        texture->used = 0;
 }
 
+void GlslManager::delete_sync(GLsync sync)
+{
+       // We do not know which thread we are called from, and we can only
+       // delete this if we are in one with a valid OpenGL context.
+       // Thus, store it for later deletion in render_frame_texture().
+       GlslManager* g = GlslManager::get_instance();
+       g->lock();
+       g->syncs_to_delete.push_back(sync);
+       g->unlock();
+}
+
 glsl_pbo GlslManager::get_pbo(int size)
 {
        lock();
@@ -412,6 +427,13 @@ int GlslManager::render_frame_texture(mlt_service service, mlt_frame frame, int
        glBindFramebuffer( GL_FRAMEBUFFER, 0 );
        check_error();
 
+       lock();
+       while (syncs_to_delete.count() > 0) {
+               GLsync sync = (GLsync) syncs_to_delete.pop_front();
+               glDeleteSync( sync );
+       }
+       unlock();
+
        // Make sure we never have more than one frame pending at any time.
        // This ensures we do not swamp the GPU with so much work
        // that we cannot actually display the frames we generate.
@@ -433,7 +455,8 @@ int GlslManager::render_frame_texture(mlt_service service, mlt_frame frame, int
        mlt_frame_set_image( frame, *image, 0, NULL );
        mlt_properties_set_data( MLT_FRAME_PROPERTIES(frame), "movit.convert.texture", texture, 0,
                (mlt_destructor) GlslManager::release_texture, NULL );
-       mlt_properties_set_data( MLT_FRAME_PROPERTIES(frame), "movit.convert.fence", sync, 0, NULL, NULL );
+       mlt_properties_set_data( MLT_FRAME_PROPERTIES(frame), "movit.convert.fence", sync, 0,
+               (mlt_destructor) GlslManager::delete_sync, NULL );
 
        return 0;
 }
index 5263e5cb51cf3ea52334a820d96a14d3ca0fee6a..4bc3836b1e0a341277a06b16b04825221e3fdceb 100644 (file)
@@ -104,6 +104,7 @@ private:
        static void onPropertyChanged( mlt_properties owner, mlt_service service, const char* property );
        Mlt::Deque fbo_list;
        Mlt::Deque texture_list;
+       Mlt::Deque syncs_to_delete;
        glsl_pbo  pbo;
        Mlt::Event* initEvent;
        Mlt::Event* closeEvent;