Skip to content

Commit d17004d

Browse files
authored
[Linux][FlView] fix rendering on startup when shown after plugin registration (flutter#38982)
* [FlView] fix rendering on startup when shown after plugin registration * Add clarifying comment
1 parent 8ca3b2b commit d17004d

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

shell/platform/linux/fl_view.cc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,17 @@ static void handle_geometry_changed(FlView* self) {
200200
self->engine, allocation.width * scale_factor,
201201
allocation.height * scale_factor, scale_factor);
202202

203-
fl_renderer_wait_for_frame(self->renderer, allocation.width * scale_factor,
204-
allocation.height * scale_factor);
203+
// Make sure the view has been realized and its size has been allocated before
204+
// waiting for a frame. `fl_view_realize()` and `fl_view_size_allocate()` may
205+
// be called in either order depending on the order in which the window is
206+
// shown and the view is added to a container in the app runner.
207+
//
208+
// Note: `gtk_widget_init()` initializes the size allocation to 1x1.
209+
if (allocation.width > 1 && allocation.height > 1 &&
210+
gtk_widget_get_realized(GTK_WIDGET(self))) {
211+
fl_renderer_wait_for_frame(self->renderer, allocation.width * scale_factor,
212+
allocation.height * scale_factor);
213+
}
205214
}
206215

207216
// Adds a widget to render in this view.
@@ -661,6 +670,8 @@ static void fl_view_realize(GtkWidget* widget) {
661670
g_warning("Failed to start Flutter engine: %s", error->message);
662671
return;
663672
}
673+
674+
handle_geometry_changed(self);
664675
}
665676

666677
// Implements GtkWidget::get-preferred-width

0 commit comments

Comments
 (0)