Skip to content

Commit 53676f0

Browse files
Fix GTK redraw call being called from non-GTK thread. (flutter#173602)
gtk_widget_queue_draw is not thread-safe, call it from an idle callback. Fixes flutter#173447
1 parent a07fc6b commit 53676f0

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

engine/src/flutter/shell/platform/linux/fl_view.cc

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,16 @@ G_DEFINE_TYPE_WITH_CODE(
9999
G_IMPLEMENT_INTERFACE(fl_plugin_registry_get_type(),
100100
fl_view_plugin_registry_iface_init))
101101

102-
// Emit the first frame signal in the main thread.
103-
static gboolean first_frame_idle_cb(gpointer user_data) {
102+
// Redraw the view from the GTK thread.
103+
static gboolean redraw_cb(gpointer user_data) {
104104
FlView* self = FL_VIEW(user_data);
105105

106-
g_signal_emit(self, fl_view_signals[SIGNAL_FIRST_FRAME], 0);
106+
gtk_widget_queue_draw(GTK_WIDGET(self->render_area));
107+
108+
if (!self->have_first_frame) {
109+
self->have_first_frame = TRUE;
110+
g_signal_emit(self, fl_view_signals[SIGNAL_FIRST_FRAME], 0);
111+
}
107112

108113
return FALSE;
109114
}
@@ -247,14 +252,8 @@ static void fl_view_present_layers(FlRenderable* renderable,
247252

248253
fl_compositor_present_layers(self->compositor, layers, layers_count);
249254

250-
gtk_widget_queue_draw(GTK_WIDGET(self->render_area));
251-
252-
if (!self->have_first_frame) {
253-
self->have_first_frame = TRUE;
254-
// This is not the main thread, so the signal needs to be done via an idle
255-
// callback.
256-
g_idle_add(first_frame_idle_cb, self);
257-
}
255+
// Perform the redraw in the GTK thead.
256+
g_idle_add(redraw_cb, self);
258257
}
259258

260259
// Implements FlPluginRegistry::get_registrar_for_plugin.

0 commit comments

Comments
 (0)