From d7963e6fa124db367a4fd906353f5ec898f784f9 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 26 Jan 2023 22:11:20 +0100 Subject: [PATCH] [Linux][FlView] fix rendering on startup when shown after plugin registration (flutter/engine#38982) * [FlView] fix rendering on startup when shown after plugin registration * Add clarifying comment --- .../src/flutter/shell/platform/linux/fl_view.cc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/shell/platform/linux/fl_view.cc b/engine/src/flutter/shell/platform/linux/fl_view.cc index 69fea7ccafe..5229d4d9f39 100644 --- a/engine/src/flutter/shell/platform/linux/fl_view.cc +++ b/engine/src/flutter/shell/platform/linux/fl_view.cc @@ -200,8 +200,17 @@ static void handle_geometry_changed(FlView* self) { self->engine, allocation.width * scale_factor, allocation.height * scale_factor, scale_factor); - fl_renderer_wait_for_frame(self->renderer, allocation.width * scale_factor, - allocation.height * scale_factor); + // Make sure the view has been realized and its size has been allocated before + // waiting for a frame. `fl_view_realize()` and `fl_view_size_allocate()` may + // be called in either order depending on the order in which the window is + // shown and the view is added to a container in the app runner. + // + // Note: `gtk_widget_init()` initializes the size allocation to 1x1. + if (allocation.width > 1 && allocation.height > 1 && + gtk_widget_get_realized(GTK_WIDGET(self))) { + fl_renderer_wait_for_frame(self->renderer, allocation.width * scale_factor, + allocation.height * scale_factor); + } } // Adds a widget to render in this view. @@ -661,6 +670,8 @@ static void fl_view_realize(GtkWidget* widget) { g_warning("Failed to start Flutter engine: %s", error->message); return; } + + handle_geometry_changed(self); } // Implements GtkWidget::get-preferred-width