qmlgloverlay: don't leak resources freed on a different GL thread

deleting a QOpenGLFrameBufferObject needs to occur on the same thread it
was created on in order to actually free the relevant resources
immediately.  Otherwise, they will be queued for deletion and not freed
until the associated QOpenGLContext is destroyed.
This commit is contained in:
Matthew Waters 2020-03-23 14:02:22 +11:00
parent 818dde2e02
commit 6397d2f910

View file

@ -170,11 +170,26 @@ GstQuickRenderer::activateContext ()
{ {
} }
static void struct FBOUserData
delete_cxx (QOpenGLFramebufferObject * cxx)
{ {
GST_TRACE ("freeing Qfbo %p", cxx); GstGLContext * context;
delete cxx; QOpenGLFramebufferObject * fbo;
};
static void
delete_cxx_gl_context (GstGLContext * context, struct FBOUserData * data)
{
GST_TRACE ("freeing Qfbo %p", data->fbo);
delete data->fbo;
}
static void
notify_fbo_delete (struct FBOUserData * data)
{
gst_gl_context_thread_add (data->context,
(GstGLContextThreadFunc) delete_cxx_gl_context, data);
gst_object_unref (data->context);
g_free (data);
} }
GstQuickRenderer::GstQuickRenderer() GstQuickRenderer::GstQuickRenderer()
@ -294,7 +309,7 @@ bool GstQuickRenderer::init (GstGLContext * context, GError ** error)
gl_params = (GstGLAllocationParams *) gl_params = (GstGLAllocationParams *)
gst_gl_video_allocation_params_new_wrapped_texture (gl_context, gst_gl_video_allocation_params_new_wrapped_texture (gl_context,
NULL, &this->v_info, 0, NULL, GST_GL_TEXTURE_TARGET_2D, GST_GL_RGBA8, NULL, &this->v_info, 0, NULL, GST_GL_TEXTURE_TARGET_2D, GST_GL_RGBA8,
0, NULL, (GDestroyNotify) delete_cxx); 0, NULL, (GDestroyNotify) notify_fbo_delete);
/* This is a gross hack relying on the internals of Qt and GStreamer /* This is a gross hack relying on the internals of Qt and GStreamer
* however it's the only way to remove this warning on shutdown of all * however it's the only way to remove this warning on shutdown of all
@ -435,7 +450,10 @@ GstQuickRenderer::renderGstGL ()
m_renderControl->render(); m_renderControl->render();
GST_DEBUG ("wrapping Qfbo %p with texture %u", m_fbo, m_fbo->texture()); GST_DEBUG ("wrapping Qfbo %p with texture %u", m_fbo, m_fbo->texture());
gl_params->user_data = static_cast<gpointer> (m_fbo); struct FBOUserData *data = g_new0 (struct FBOUserData, 1);
data->context = (GstGLContext *) gst_object_ref (gl_context);
data->fbo = m_fbo;
gl_params->user_data = static_cast<gpointer> (data);
gl_params->gl_handle = GINT_TO_POINTER (m_fbo->texture()); gl_params->gl_handle = GINT_TO_POINTER (m_fbo->texture());
gl_mem = (GstGLMemory *) gst_gl_base_memory_alloc (gl_allocator, gl_params); gl_mem = (GstGLMemory *) gst_gl_base_memory_alloc (gl_allocator, gl_params);