Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
glwindow: fix racy resize updates
Take locks around resize handling and marshall all resizes to the
windowing thread by default.
  • Loading branch information
ystreet authored and GStreamer Merge Bot committed Nov 6, 2019
1 parent b29d61b commit b887db1
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions gst-libs/gst/gl/gstglwindow.c
Expand Up @@ -147,12 +147,15 @@ gst_gl_window_error_quark (void)
static gboolean
gst_gl_window_default_open (GstGLWindow * window, GError ** error)
{
g_main_context_push_thread_default (window->main_context);

return TRUE;
}

static void
gst_gl_window_default_close (GstGLWindow * window)
{
g_main_context_pop_thread_default (window->main_context);
}

static void
Expand Down Expand Up @@ -511,11 +514,7 @@ gst_gl_window_default_run (GstGLWindow * window)
{
GstGLWindowPrivate *priv = window->priv;

g_main_context_push_thread_default (window->main_context);

g_main_loop_run (priv->loop);

g_main_context_pop_thread_default (window->main_context);
}

/**
Expand Down Expand Up @@ -890,10 +889,12 @@ void
gst_gl_window_get_surface_dimensions (GstGLWindow * window, guint * width,
guint * height)
{
GST_GL_WINDOW_LOCK (window);
if (width)
*width = window->priv->surface_width;
if (height)
*height = window->priv->surface_height;
GST_GL_WINDOW_UNLOCK (window);
}

void
Expand Down Expand Up @@ -958,19 +959,24 @@ gst_gl_window_set_render_rectangle (GstGLWindow * window, gint x, gint y,
g_return_val_if_fail (GST_IS_GL_WINDOW (window), FALSE);
window_class = GST_GL_WINDOW_GET_CLASS (window);

GST_GL_WINDOW_LOCK (window);
/* When x/y is smaller then reset the render rectangle */
if (x < 0 || y < 0) {
x = y = 0;
width = window->priv->surface_width;
height = window->priv->surface_height;
}

if (x < 0 || y < 0 || width <= 0 || height <= 0)
if (x < 0 || y < 0 || width <= 0 || height <= 0) {
GST_GL_WINDOW_UNLOCK (window);
return FALSE;
}

if (window_class->set_render_rectangle)
ret = window_class->set_render_rectangle (window, x, y, width, height);

GST_GL_WINDOW_UNLOCK (window);

return ret;
}

Expand Down Expand Up @@ -1004,8 +1010,18 @@ _on_resize (gpointer data)
{
struct resize_data *resize = data;

resize->window->resize (resize->window->resize_data, resize->width,
resize->height);
GST_GL_WINDOW_LOCK (resize->window);

if (resize->window->resize)
resize->window->resize (resize->window->resize_data, resize->width,
resize->height);

resize->window->priv->surface_width = resize->width;
resize->window->priv->surface_height = resize->height;

GST_GL_WINDOW_UNLOCK (resize->window);

resize->window->queue_resize = FALSE;
}

/**
Expand All @@ -1019,22 +1035,15 @@ _on_resize (gpointer data)
void
gst_gl_window_resize (GstGLWindow * window, guint width, guint height)
{
g_return_if_fail (GST_IS_GL_WINDOW (window));

if (window->resize) {
struct resize_data resize = { 0, };

resize.window = window;
resize.width = width;
resize.height = height;
struct resize_data resize = { 0, };

gst_gl_window_send_message (window, (GstGLWindowCB) _on_resize, &resize);
}
g_return_if_fail (GST_IS_GL_WINDOW (window));

window->priv->surface_width = width;
window->priv->surface_height = height;
resize.window = window;
resize.width = width;
resize.height = height;

window->queue_resize = FALSE;
gst_gl_window_send_message (window, (GstGLWindowCB) _on_resize, &resize);
}

/**
Expand Down

0 comments on commit b887db1

Please sign in to comment.