From 3b81bc4b78dcff4876b64e3c5802741b3e086c8c Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Wed, 8 Feb 2023 11:28:24 +1300 Subject: [PATCH 01/14] Fix transfer notation for fl_view_add_gl_area argument --- shell/platform/linux/fl_view_private.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/linux/fl_view_private.h b/shell/platform/linux/fl_view_private.h index 693c937231528..b29d27c18c936 100644 --- a/shell/platform/linux/fl_view_private.h +++ b/shell/platform/linux/fl_view_private.h @@ -21,7 +21,7 @@ void fl_view_begin_frame(FlView* view); /** * fl_view_add_gl_area: * @view: an #FlView. - * @context: (transfer full): a #GdkGLContext, for #FlGLArea to render. + * @context: a #GdkGLContext, for #FlGLArea to render. * @texture: (transfer full): texture for OpenGL area to render. * * Append an #FlGLArea at top of stacked children of #FlView. From f064be5443e31baf0dde2b58d2b0e3ed0c867d92 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Tue, 7 Feb 2023 15:37:03 +1300 Subject: [PATCH 02/14] Remove unused private fl_view_add_widget --- shell/platform/linux/fl_view.cc | 7 ------- shell/platform/linux/fl_view_private.h | 12 ------------ 2 files changed, 19 deletions(-) diff --git a/shell/platform/linux/fl_view.cc b/shell/platform/linux/fl_view.cc index 5229d4d9f391f..8d13416d0b2d3 100644 --- a/shell/platform/linux/fl_view.cc +++ b/shell/platform/linux/fl_view.cc @@ -970,13 +970,6 @@ void fl_view_add_gl_area(FlView* view, fl_gl_area_queue_render(area, texture); } -void fl_view_add_widget(FlView* view, - GtkWidget* widget, - GdkRectangle* geometry) { - gtk_widget_show(widget); - add_pending_child(view, widget, geometry); -} - void fl_view_end_frame(FlView* view) { for (GList* pending_child = view->pending_children_list; pending_child; pending_child = pending_child->next) { diff --git a/shell/platform/linux/fl_view_private.h b/shell/platform/linux/fl_view_private.h index b29d27c18c936..5265420de0711 100644 --- a/shell/platform/linux/fl_view_private.h +++ b/shell/platform/linux/fl_view_private.h @@ -32,18 +32,6 @@ void fl_view_add_gl_area(FlView* view, GdkGLContext* context, FlBackingStoreProvider* texture); -/** - * fl_view_add_widget: - * @view: an #FlView. - * @widget: a #GtkWidget. - * @geometry: geometry of the widget. - * - * Append a #GtkWidget at top of stacked children of #FlView. - */ -void fl_view_add_widget(FlView* view, - GtkWidget* widget, - GdkRectangle* geometry); - /** * fl_view_end_frame: * @view: an #FlView. From bc19c170d4ae7d1395efba3d3f04bfa1c5b19fd8 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Wed, 8 Feb 2023 11:51:58 +1300 Subject: [PATCH 03/14] Combine fl_view_begin_frame/fl_view_add_gl_area/fl_view_end_frame into one method. --- shell/platform/linux/fl_renderer_gl.cc | 10 +++---- shell/platform/linux/fl_view.cc | 37 +++++++++++++------------- shell/platform/linux/fl_view_private.h | 32 +++++----------------- 3 files changed, 30 insertions(+), 49 deletions(-) diff --git a/shell/platform/linux/fl_renderer_gl.cc b/shell/platform/linux/fl_renderer_gl.cc index ec44b9b2dc5b8..7210e95954950 100644 --- a/shell/platform/linux/fl_renderer_gl.cc +++ b/shell/platform/linux/fl_renderer_gl.cc @@ -98,17 +98,16 @@ static gboolean fl_renderer_gl_present_layers(FlRenderer* renderer, if (!view || !context) { return FALSE; } - fl_view_begin_frame(view); + g_autoptr(GPtrArray) textures = g_ptr_array_new(); for (size_t i = 0; i < layers_count; ++i) { const FlutterLayer* layer = layers[i]; switch (layer->type) { case kFlutterLayerContentTypeBackingStore: { const FlutterBackingStore* backing_store = layer->backing_store; auto framebuffer = &backing_store->open_gl.framebuffer; - fl_view_add_gl_area( - view, context, - reinterpret_cast(framebuffer->user_data)); + g_ptr_array_add(textures, reinterpret_cast( + framebuffer->user_data)); } break; case kFlutterLayerContentTypePlatformView: { // Currently unsupported. @@ -116,7 +115,8 @@ static gboolean fl_renderer_gl_present_layers(FlRenderer* renderer, } } - fl_view_end_frame(view); + fl_view_set_textures(view, context, textures); + return TRUE; } diff --git a/shell/platform/linux/fl_view.cc b/shell/platform/linux/fl_view.cc index 8d13416d0b2d3..73fce4f264a35 100644 --- a/shell/platform/linux/fl_view.cc +++ b/shell/platform/linux/fl_view.cc @@ -942,35 +942,34 @@ G_MODULE_EXPORT FlEngine* fl_view_get_engine(FlView* view) { return view->engine; } -void fl_view_begin_frame(FlView* view) { +void fl_view_set_textures(FlView* view, + GdkGLContext* context, + GPtrArray* textures) { g_return_if_fail(FL_IS_VIEW(view)); FlView* self = FL_VIEW(view); self->used_area_list = self->gl_area_list; g_list_free_full(self->pending_children_list, g_free); self->pending_children_list = nullptr; -} -void fl_view_add_gl_area(FlView* view, - GdkGLContext* context, - FlBackingStoreProvider* texture) { - g_return_if_fail(FL_IS_VIEW(view)); + for (size_t i = 0; i < textures->len; i++) { + FlBackingStoreProvider* texture = + FL_BACKING_STORE_PROVIDER(g_ptr_array_index(textures, i)); + FlGLArea* area; - FlGLArea* area; - if (view->used_area_list) { - area = reinterpret_cast(view->used_area_list->data); - view->used_area_list = view->used_area_list->next; - } else { - area = FL_GL_AREA(fl_gl_area_new(context)); - view->gl_area_list = g_list_append(view->gl_area_list, area); - } + if (view->used_area_list) { + area = reinterpret_cast(view->used_area_list->data); + view->used_area_list = view->used_area_list->next; + } else { + area = FL_GL_AREA(fl_gl_area_new(context)); + view->gl_area_list = g_list_append(view->gl_area_list, area); + } - gtk_widget_show(GTK_WIDGET(area)); - add_pending_child(view, GTK_WIDGET(area), nullptr); - fl_gl_area_queue_render(area, texture); -} + gtk_widget_show(GTK_WIDGET(area)); + add_pending_child(view, GTK_WIDGET(area), nullptr); + fl_gl_area_queue_render(area, texture); + } -void fl_view_end_frame(FlView* view) { for (GList* pending_child = view->pending_children_list; pending_child; pending_child = pending_child->next) { FlViewChild* pending_view_child = diff --git a/shell/platform/linux/fl_view_private.h b/shell/platform/linux/fl_view_private.h index 5265420de0711..f9650227a88e5 100644 --- a/shell/platform/linux/fl_view_private.h +++ b/shell/platform/linux/fl_view_private.h @@ -10,34 +10,16 @@ #include "flutter/shell/platform/linux/fl_gl_area.h" /** - * fl_view_begin_frame: - * @view: an #FlView. - * - * Reset children of #FlView a stacked #GtkContainer. - * This function is always paired with fl_view_end_frame. - */ -void fl_view_begin_frame(FlView* view); - -/** - * fl_view_add_gl_area: + * fl_view_set_textures: * @view: an #FlView. * @context: a #GdkGLContext, for #FlGLArea to render. - * @texture: (transfer full): texture for OpenGL area to render. - * - * Append an #FlGLArea at top of stacked children of #FlView. - * This function must be called after fl_view_begin_frame, and - * before fl_view_end_frame. - */ -void fl_view_add_gl_area(FlView* view, - GdkGLContext* context, - FlBackingStoreProvider* texture); - -/** - * fl_view_end_frame: - * @view: an #FlView. + * @textures: (transfer none) (element-type FlBackingStoreProvider): a list of + * #FlBackingStoreProvider. * - * Apply changes made by fl_view_add_gl_area and fl_view_add_widget. + * Set the textures for this view to render. */ -void fl_view_end_frame(FlView* view); +void fl_view_set_textures(FlView* view, + GdkGLContext* context, + GPtrArray* textures); #endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_VIEW_PRIVATE_H_ From e8fe69716d7bb2d013d693fdf02f0b7948880282 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Wed, 8 Feb 2023 11:57:40 +1300 Subject: [PATCH 04/14] Remove no longer required pending_children_list --- shell/platform/linux/fl_view.cc | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/shell/platform/linux/fl_view.cc b/shell/platform/linux/fl_view.cc index 73fce4f264a35..cc838d9f8d7a5 100644 --- a/shell/platform/linux/fl_view.cc +++ b/shell/platform/linux/fl_view.cc @@ -56,7 +56,6 @@ struct _FlView { GtkWidget* event_box; GList* children_list; - GList* pending_children_list; // Tracks whether mouse pointer is inside the view. gboolean pointer_inside; @@ -213,22 +212,6 @@ static void handle_geometry_changed(FlView* self) { } } -// Adds a widget to render in this view. -static void add_pending_child(FlView* self, - GtkWidget* widget, - GdkRectangle* geometry) { - FlViewChild* child = g_new(FlViewChild, 1); - child->widget = widget; - if (geometry) { - child->geometry = *geometry; - } else { - child->geometry = {0, 0, 0, 0}; - } - - self->pending_children_list = - g_list_append(self->pending_children_list, child); -} - // Finds the node with the specified widget in a list of FlViewChild. static GList* find_child(GList* list, GtkWidget* widget) { for (GList* i = list; i; i = i->next) { @@ -949,8 +932,7 @@ void fl_view_set_textures(FlView* view, FlView* self = FL_VIEW(view); self->used_area_list = self->gl_area_list; - g_list_free_full(self->pending_children_list, g_free); - self->pending_children_list = nullptr; + GList* pending_children_list = nullptr; for (size_t i = 0; i < textures->len; i++) { FlBackingStoreProvider* texture = @@ -966,11 +948,14 @@ void fl_view_set_textures(FlView* view, } gtk_widget_show(GTK_WIDGET(area)); - add_pending_child(view, GTK_WIDGET(area), nullptr); + FlViewChild* child = g_new(FlViewChild, 1); + child->widget = GTK_WIDGET(area); + child->geometry = {0, 0, 0, 0}; + pending_children_list = g_list_append(pending_children_list, child); fl_gl_area_queue_render(area, texture); } - for (GList* pending_child = view->pending_children_list; pending_child; + for (GList* pending_child = pending_children_list; pending_child; pending_child = pending_child->next) { FlViewChild* pending_view_child = reinterpret_cast(pending_child->data); @@ -998,8 +983,7 @@ void fl_view_set_textures(FlView* view, } g_list_free(view->children_list); - view->children_list = view->pending_children_list; - view->pending_children_list = nullptr; + view->children_list = pending_children_list; struct _ReorderData data = { .parent_window = gtk_widget_get_window(GTK_WIDGET(view)), From 940ec0f451d3c7a3db235813e744d4252ddabbb1 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Wed, 8 Feb 2023 12:02:08 +1300 Subject: [PATCH 05/14] Remove no longer required used_area_list --- shell/platform/linux/fl_view.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/shell/platform/linux/fl_view.cc b/shell/platform/linux/fl_view.cc index cc838d9f8d7a5..d7e8298219f83 100644 --- a/shell/platform/linux/fl_view.cc +++ b/shell/platform/linux/fl_view.cc @@ -51,7 +51,6 @@ struct _FlView { FlPlatformPlugin* platform_plugin; GList* gl_area_list; - GList* used_area_list; GtkWidget* event_box; @@ -931,7 +930,7 @@ void fl_view_set_textures(FlView* view, g_return_if_fail(FL_IS_VIEW(view)); FlView* self = FL_VIEW(view); - self->used_area_list = self->gl_area_list; + GList* used_area_list = self->gl_area_list; GList* pending_children_list = nullptr; for (size_t i = 0; i < textures->len; i++) { @@ -939,9 +938,9 @@ void fl_view_set_textures(FlView* view, FL_BACKING_STORE_PROVIDER(g_ptr_array_index(textures, i)); FlGLArea* area; - if (view->used_area_list) { - area = reinterpret_cast(view->used_area_list->data); - view->used_area_list = view->used_area_list->next; + if (used_area_list) { + area = reinterpret_cast(used_area_list->data); + used_area_list = used_area_list->next; } else { area = FL_GL_AREA(fl_gl_area_new(context)); view->gl_area_list = g_list_append(view->gl_area_list, area); From 90fee2d75734313ef8129825ec807e64cbeb7c08 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Wed, 8 Feb 2023 12:05:04 +1300 Subject: [PATCH 06/14] Remove unnecessary put_widget method --- shell/platform/linux/fl_view.cc | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/shell/platform/linux/fl_view.cc b/shell/platform/linux/fl_view.cc index d7e8298219f83..9a777034429ad 100644 --- a/shell/platform/linux/fl_view.cc +++ b/shell/platform/linux/fl_view.cc @@ -794,28 +794,18 @@ static gboolean fl_view_key_release_event(GtkWidget* widget, reinterpret_cast(event)))); } -static void put_widget(FlView* self, - GtkWidget* widget, - GdkRectangle* geometry) { +// Implements GtkContainer::add +static void fl_view_add(GtkContainer* container, GtkWidget* widget) { + FlView* self = FL_VIEW(container); + FlViewChild* child = g_new(FlViewChild, 1); child->widget = widget; - child->geometry = *geometry; + child->geometry = {0, 0, 0, 0}; gtk_widget_set_parent(widget, GTK_WIDGET(self)); self->children_list = g_list_append(self->children_list, child); } -// Implements GtkContainer::add -static void fl_view_add(GtkContainer* container, GtkWidget* widget) { - GdkRectangle geometry = { - .x = 0, - .y = 0, - .width = 0, - .height = 0, - }; - put_widget(FL_VIEW(container), widget, &geometry); -} - // Implements GtkContainer::remove static void fl_view_remove(GtkContainer* container, GtkWidget* widget) { FlView* self = FL_VIEW(container); From cf34e96cfc324ad52e7013a9eddfb24fcac86f3e Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Wed, 8 Feb 2023 12:14:37 +1300 Subject: [PATCH 07/14] Remove unused FlViewChild.geometry --- shell/platform/linux/fl_view.cc | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/shell/platform/linux/fl_view.cc b/shell/platform/linux/fl_view.cc index 9a777034429ad..954c054c7c2f9 100644 --- a/shell/platform/linux/fl_view.cc +++ b/shell/platform/linux/fl_view.cc @@ -67,7 +67,6 @@ struct _FlView { typedef struct _FlViewChild { GtkWidget* widget; - GdkRectangle geometry; } FlViewChild; enum { kPropFlutterProject = 1, kPropLast }; @@ -676,8 +675,8 @@ static void fl_view_get_preferred_width(GtkWidget* widget, gtk_widget_get_preferred_width(child->widget, &child_min, &child_nat); - *minimum = MAX(*minimum, child->geometry.x + child_min); - *natural = MAX(*natural, child->geometry.x + child_nat); + *minimum = MAX(*minimum, child_min); + *natural = MAX(*natural, child_nat); } } @@ -701,8 +700,8 @@ static void fl_view_get_preferred_height(GtkWidget* widget, gtk_widget_get_preferred_height(child->widget, &child_min, &child_nat); - *minimum = MAX(*minimum, child->geometry.y + child_min); - *natural = MAX(*natural, child->geometry.y + child_nat); + *minimum = MAX(*minimum, child_min); + *natural = MAX(*natural, child_nat); } } @@ -728,7 +727,7 @@ static void fl_view_size_allocate(GtkWidget* widget, continue; } - GtkAllocation child_allocation = child->geometry; + GtkAllocation child_allocation = {0, 0, 0, 0}; GtkRequisition child_requisition; gtk_widget_get_preferred_size(child->widget, &child_requisition, NULL); @@ -800,7 +799,6 @@ static void fl_view_add(GtkContainer* container, GtkWidget* widget) { FlViewChild* child = g_new(FlViewChild, 1); child->widget = widget; - child->geometry = {0, 0, 0, 0}; gtk_widget_set_parent(widget, GTK_WIDGET(self)); self->children_list = g_list_append(self->children_list, child); @@ -939,7 +937,6 @@ void fl_view_set_textures(FlView* view, gtk_widget_show(GTK_WIDGET(area)); FlViewChild* child = g_new(FlViewChild, 1); child->widget = GTK_WIDGET(area); - child->geometry = {0, 0, 0, 0}; pending_children_list = g_list_append(pending_children_list, child); fl_gl_area_queue_render(area, texture); } From cf751215c70d065a5a62dba276355c56a69ebe3e Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Wed, 8 Feb 2023 12:29:19 +1300 Subject: [PATCH 08/14] Remove unused FlViewChild --- shell/platform/linux/fl_view.cc | 76 ++++++++++++++------------------- 1 file changed, 31 insertions(+), 45 deletions(-) diff --git a/shell/platform/linux/fl_view.cc b/shell/platform/linux/fl_view.cc index 954c054c7c2f9..d8eb94ccfc909 100644 --- a/shell/platform/linux/fl_view.cc +++ b/shell/platform/linux/fl_view.cc @@ -65,10 +65,6 @@ struct _FlView { gulong keymap_keys_changed_cb_id; // Signal connection ID. }; -typedef struct _FlViewChild { - GtkWidget* widget; -} FlViewChild; - enum { kPropFlutterProject = 1, kPropLast }; static void fl_view_plugin_registry_iface_init( @@ -210,11 +206,11 @@ static void handle_geometry_changed(FlView* self) { } } -// Finds the node with the specified widget in a list of FlViewChild. +// Finds the node with the specified widget. static GList* find_child(GList* list, GtkWidget* widget) { for (GList* i = list; i; i = i->next) { - FlViewChild* child = reinterpret_cast(i->data); - if (child && child->widget == widget) { + GtkWidget* w = reinterpret_cast(i->data); + if (w == widget) { return i; } } @@ -667,13 +663,13 @@ static void fl_view_get_preferred_width(GtkWidget* widget, for (GList* iterator = self->children_list; iterator; iterator = iterator->next) { - FlViewChild* child = reinterpret_cast(iterator->data); + GtkWidget* w = reinterpret_cast(iterator->data); - if (!gtk_widget_get_visible(child->widget)) { + if (!gtk_widget_get_visible(w)) { continue; } - gtk_widget_get_preferred_width(child->widget, &child_min, &child_nat); + gtk_widget_get_preferred_width(w, &child_min, &child_nat); *minimum = MAX(*minimum, child_min); *natural = MAX(*natural, child_nat); @@ -692,13 +688,13 @@ static void fl_view_get_preferred_height(GtkWidget* widget, for (GList* iterator = self->children_list; iterator; iterator = iterator->next) { - FlViewChild* child = reinterpret_cast(iterator->data); + GtkWidget* w = reinterpret_cast(iterator->data); - if (!gtk_widget_get_visible(child->widget)) { + if (!gtk_widget_get_visible(w)) { continue; } - gtk_widget_get_preferred_height(child->widget, &child_min, &child_nat); + gtk_widget_get_preferred_height(w, &child_min, &child_nat); *minimum = MAX(*minimum, child_min); *natural = MAX(*natural, child_nat); @@ -722,14 +718,14 @@ static void fl_view_size_allocate(GtkWidget* widget, for (GList* iterator = self->children_list; iterator; iterator = iterator->next) { - FlViewChild* child = reinterpret_cast(iterator->data); - if (!gtk_widget_get_visible(child->widget)) { + GtkWidget* w = reinterpret_cast(iterator->data); + if (!gtk_widget_get_visible(w)) { continue; } GtkAllocation child_allocation = {0, 0, 0, 0}; GtkRequisition child_requisition; - gtk_widget_get_preferred_size(child->widget, &child_requisition, NULL); + gtk_widget_get_preferred_size(w, &child_requisition, NULL); if (!gtk_widget_get_has_window(widget)) { child_allocation.x += allocation->x; @@ -741,7 +737,7 @@ static void fl_view_size_allocate(GtkWidget* widget, child_allocation.height = allocation->height; } - gtk_widget_size_allocate(child->widget, &child_allocation); + gtk_widget_size_allocate(w, &child_allocation); } GtkAllocation event_box_allocation = { @@ -797,11 +793,8 @@ static gboolean fl_view_key_release_event(GtkWidget* widget, static void fl_view_add(GtkContainer* container, GtkWidget* widget) { FlView* self = FL_VIEW(container); - FlViewChild* child = g_new(FlViewChild, 1); - child->widget = widget; - gtk_widget_set_parent(widget, GTK_WIDGET(self)); - self->children_list = g_list_append(self->children_list, child); + self->children_list = g_list_append(self->children_list, widget); } // Implements GtkContainer::remove @@ -809,13 +802,12 @@ static void fl_view_remove(GtkContainer* container, GtkWidget* widget) { FlView* self = FL_VIEW(container); for (GList* iterator = self->children_list; iterator; iterator = iterator->next) { - FlViewChild* child = reinterpret_cast(iterator->data); - if (child->widget == widget) { + GtkWidget* w = reinterpret_cast(iterator->data); + if (w == widget) { g_object_ref(widget); gtk_widget_unparent(widget); self->children_list = g_list_remove_link(self->children_list, iterator); g_list_free(iterator); - g_free(child); break; } @@ -834,8 +826,8 @@ static void fl_view_forall(GtkContainer* container, FlView* self = FL_VIEW(container); for (GList* iterator = self->children_list; iterator; iterator = iterator->next) { - FlViewChild* child = reinterpret_cast(iterator->data); - (*callback)(child->widget, callback_data); + GtkWidget* w = reinterpret_cast(iterator->data); + (*callback)(w, callback_data); } if (include_internals) { @@ -935,36 +927,30 @@ void fl_view_set_textures(FlView* view, } gtk_widget_show(GTK_WIDGET(area)); - FlViewChild* child = g_new(FlViewChild, 1); - child->widget = GTK_WIDGET(area); - pending_children_list = g_list_append(pending_children_list, child); + pending_children_list = + g_list_append(pending_children_list, GTK_WIDGET(area)); fl_gl_area_queue_render(area, texture); } for (GList* pending_child = pending_children_list; pending_child; pending_child = pending_child->next) { - FlViewChild* pending_view_child = - reinterpret_cast(pending_child->data); - GList* child = find_child(view->children_list, pending_view_child->widget); - - if (child) { - // existing child - g_free(child->data); - child->data = nullptr; - } else { + GtkWidget* w = reinterpret_cast(pending_child->data); + GList* child = find_child(view->children_list, w); + + if (!child) { // newly added child - gtk_widget_set_parent(pending_view_child->widget, GTK_WIDGET(view)); + gtk_widget_set_parent(w, GTK_WIDGET(view)); } } for (GList* child = view->children_list; child; child = child->next) { - FlViewChild* view_child = reinterpret_cast(child->data); - if (view_child) { + GtkWidget* w = reinterpret_cast(child->data); + GList* pending_child = find_child(pending_children_list, w); + + if (!pending_child) { // removed child - g_object_ref(view_child->widget); - gtk_widget_unparent(view_child->widget); - g_free(view_child); - child->data = nullptr; + g_object_ref(w); + gtk_widget_unparent(w); } } From e8c5e00c96782e37dc08ad25619f37771f46c2e5 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Wed, 8 Feb 2023 12:34:36 +1300 Subject: [PATCH 09/14] Only need to show glareas when they are created --- shell/platform/linux/fl_view.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/linux/fl_view.cc b/shell/platform/linux/fl_view.cc index d8eb94ccfc909..7de296c88ff09 100644 --- a/shell/platform/linux/fl_view.cc +++ b/shell/platform/linux/fl_view.cc @@ -923,10 +923,10 @@ void fl_view_set_textures(FlView* view, used_area_list = used_area_list->next; } else { area = FL_GL_AREA(fl_gl_area_new(context)); + gtk_widget_show(GTK_WIDGET(area)); view->gl_area_list = g_list_append(view->gl_area_list, area); } - gtk_widget_show(GTK_WIDGET(area)); pending_children_list = g_list_append(pending_children_list, GTK_WIDGET(area)); fl_gl_area_queue_render(area, texture); From 22790b4a904f6aedc321d0c23ad20ee0db9873e4 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Wed, 8 Feb 2023 12:40:15 +1300 Subject: [PATCH 10/14] Set the glarea parent at the time we create it --- shell/platform/linux/fl_view.cc | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/shell/platform/linux/fl_view.cc b/shell/platform/linux/fl_view.cc index 7de296c88ff09..f33e97515ed2a 100644 --- a/shell/platform/linux/fl_view.cc +++ b/shell/platform/linux/fl_view.cc @@ -923,6 +923,7 @@ void fl_view_set_textures(FlView* view, used_area_list = used_area_list->next; } else { area = FL_GL_AREA(fl_gl_area_new(context)); + gtk_widget_set_parent(GTK_WIDGET(area), GTK_WIDGET(view)); gtk_widget_show(GTK_WIDGET(area)); view->gl_area_list = g_list_append(view->gl_area_list, area); } @@ -932,17 +933,6 @@ void fl_view_set_textures(FlView* view, fl_gl_area_queue_render(area, texture); } - for (GList* pending_child = pending_children_list; pending_child; - pending_child = pending_child->next) { - GtkWidget* w = reinterpret_cast(pending_child->data); - GList* child = find_child(view->children_list, w); - - if (!child) { - // newly added child - gtk_widget_set_parent(w, GTK_WIDGET(view)); - } - } - for (GList* child = view->children_list; child; child = child->next) { GtkWidget* w = reinterpret_cast(child->data); GList* pending_child = find_child(pending_children_list, w); From 9b75996e6cefa05c80280b90a4535956ae2c49ba Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Wed, 8 Feb 2023 12:56:49 +1300 Subject: [PATCH 11/14] Rename view variable to self to match convention --- shell/platform/linux/fl_view.cc | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/shell/platform/linux/fl_view.cc b/shell/platform/linux/fl_view.cc index f33e97515ed2a..162a0218d23fa 100644 --- a/shell/platform/linux/fl_view.cc +++ b/shell/platform/linux/fl_view.cc @@ -904,11 +904,10 @@ G_MODULE_EXPORT FlEngine* fl_view_get_engine(FlView* view) { return view->engine; } -void fl_view_set_textures(FlView* view, +void fl_view_set_textures(FlView* self, GdkGLContext* context, GPtrArray* textures) { - g_return_if_fail(FL_IS_VIEW(view)); - FlView* self = FL_VIEW(view); + g_return_if_fail(FL_IS_VIEW(self)); GList* used_area_list = self->gl_area_list; GList* pending_children_list = nullptr; @@ -923,9 +922,9 @@ void fl_view_set_textures(FlView* view, used_area_list = used_area_list->next; } else { area = FL_GL_AREA(fl_gl_area_new(context)); - gtk_widget_set_parent(GTK_WIDGET(area), GTK_WIDGET(view)); + gtk_widget_set_parent(GTK_WIDGET(area), GTK_WIDGET(self)); gtk_widget_show(GTK_WIDGET(area)); - view->gl_area_list = g_list_append(view->gl_area_list, area); + self->gl_area_list = g_list_append(self->gl_area_list, area); } pending_children_list = @@ -933,7 +932,7 @@ void fl_view_set_textures(FlView* view, fl_gl_area_queue_render(area, texture); } - for (GList* child = view->children_list; child; child = child->next) { + for (GList* child = self->children_list; child; child = child->next) { GtkWidget* w = reinterpret_cast(child->data); GList* pending_child = find_child(pending_children_list, w); @@ -944,15 +943,15 @@ void fl_view_set_textures(FlView* view, } } - g_list_free(view->children_list); - view->children_list = pending_children_list; + g_list_free(self->children_list); + self->children_list = pending_children_list; struct _ReorderData data = { - .parent_window = gtk_widget_get_window(GTK_WIDGET(view)), + .parent_window = gtk_widget_get_window(GTK_WIDGET(self)), .last_window = nullptr, }; - gtk_container_forall(GTK_CONTAINER(view), fl_view_reorder_forall, &data); + gtk_container_forall(GTK_CONTAINER(self), fl_view_reorder_forall, &data); - gtk_widget_queue_draw(GTK_WIDGET(view)); + gtk_widget_queue_draw(GTK_WIDGET(self)); } From bffc92bf532a5ab7d20b51980ce4a60ce0f6de43 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Wed, 8 Feb 2023 12:57:13 +1300 Subject: [PATCH 12/14] Simplify matching the number of glarea to textures --- shell/platform/linux/fl_view.cc | 74 +++++++++++---------------------- 1 file changed, 25 insertions(+), 49 deletions(-) diff --git a/shell/platform/linux/fl_view.cc b/shell/platform/linux/fl_view.cc index 162a0218d23fa..7629b10fd1b94 100644 --- a/shell/platform/linux/fl_view.cc +++ b/shell/platform/linux/fl_view.cc @@ -50,8 +50,6 @@ struct _FlView { FlMouseCursorPlugin* mouse_cursor_plugin; FlPlatformPlugin* platform_plugin; - GList* gl_area_list; - GtkWidget* event_box; GList* children_list; @@ -206,17 +204,6 @@ static void handle_geometry_changed(FlView* self) { } } -// Finds the node with the specified widget. -static GList* find_child(GList* list, GtkWidget* widget) { - for (GList* i = list; i; i = i->next) { - GtkWidget* w = reinterpret_cast(i->data); - if (w == widget) { - return i; - } - } - return nullptr; -} - // Called when the engine updates accessibility nodes. static void update_semantics_node_cb(FlEngine* engine, const FlutterSemanticsNode* node, @@ -604,8 +591,8 @@ static void fl_view_dispose(GObject* object) { } g_clear_object(&self->mouse_cursor_plugin); g_clear_object(&self->platform_plugin); - g_list_free_full(self->gl_area_list, g_object_unref); - self->gl_area_list = nullptr; + g_list_free_full(self->children_list, g_object_unref); + self->children_list = nullptr; G_OBJECT_CLASS(fl_view_parent_class)->dispose(object); } @@ -899,9 +886,9 @@ G_MODULE_EXPORT FlView* fl_view_new(FlDartProject* project) { g_object_new(fl_view_get_type(), "flutter-project", project, nullptr)); } -G_MODULE_EXPORT FlEngine* fl_view_get_engine(FlView* view) { - g_return_val_if_fail(FL_IS_VIEW(view), nullptr); - return view->engine; +G_MODULE_EXPORT FlEngine* fl_view_get_engine(FlView* self) { + g_return_val_if_fail(FL_IS_VIEW(self), nullptr); + return self->engine; } void fl_view_set_textures(FlView* self, @@ -909,42 +896,31 @@ void fl_view_set_textures(FlView* self, GPtrArray* textures) { g_return_if_fail(FL_IS_VIEW(self)); - GList* used_area_list = self->gl_area_list; - GList* pending_children_list = nullptr; + guint children_length = g_list_length(self->children_list); - for (size_t i = 0; i < textures->len; i++) { - FlBackingStoreProvider* texture = - FL_BACKING_STORE_PROVIDER(g_ptr_array_index(textures, i)); - FlGLArea* area; - - if (used_area_list) { - area = reinterpret_cast(used_area_list->data); - used_area_list = used_area_list->next; - } else { - area = FL_GL_AREA(fl_gl_area_new(context)); - gtk_widget_set_parent(GTK_WIDGET(area), GTK_WIDGET(self)); - gtk_widget_show(GTK_WIDGET(area)); - self->gl_area_list = g_list_append(self->gl_area_list, area); - } - - pending_children_list = - g_list_append(pending_children_list, GTK_WIDGET(area)); - fl_gl_area_queue_render(area, texture); + // Add more GL areas if we need them. + for (guint i = children_length; i < textures->len; i++) { + FlGLArea* area = FL_GL_AREA(fl_gl_area_new(context)); + gtk_widget_set_parent(GTK_WIDGET(area), GTK_WIDGET(self)); + gtk_widget_show(GTK_WIDGET(area)); + self->children_list = g_list_append(self->children_list, area); } - for (GList* child = self->children_list; child; child = child->next) { - GtkWidget* w = reinterpret_cast(child->data); - GList* pending_child = find_child(pending_children_list, w); - - if (!pending_child) { - // removed child - g_object_ref(w); - gtk_widget_unparent(w); - } + // Remove unused GL areas. + for (guint i = textures->len; i < children_length; i++) { + FlGLArea* area = FL_GL_AREA(g_list_first(self->children_list)->data); + gtk_widget_unparent(GTK_WIDGET(area)); + g_object_unref(area); + self->children_list = + g_list_remove_link(self->children_list, self->children_list); } - g_list_free(self->children_list); - self->children_list = pending_children_list; + GList* area_link = self->children_list; + for (guint i = 0; i < textures->len; i++, area_link = area_link->next) { + FlBackingStoreProvider* texture = + FL_BACKING_STORE_PROVIDER(g_ptr_array_index(textures, i)); + fl_gl_area_queue_render(FL_GL_AREA(area_link->data), texture); + } struct _ReorderData data = { .parent_window = gtk_widget_get_window(GTK_WIDGET(self)), From c5cdc070818fb419d6eb28e8126053165875b9a4 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Wed, 8 Feb 2023 13:13:00 +1300 Subject: [PATCH 13/14] Place glareas in correct order, so don't need to reorder them --- shell/platform/linux/fl_view.cc | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/shell/platform/linux/fl_view.cc b/shell/platform/linux/fl_view.cc index 7629b10fd1b94..f40e863622265 100644 --- a/shell/platform/linux/fl_view.cc +++ b/shell/platform/linux/fl_view.cc @@ -742,22 +742,6 @@ static void fl_view_size_allocate(GtkWidget* widget, handle_geometry_changed(self); } -struct _ReorderData { - GdkWindow* parent_window; - GdkWindow* last_window; -}; - -static void fl_view_reorder_forall(GtkWidget* widget, gpointer user_data) { - _ReorderData* data = reinterpret_cast<_ReorderData*>(user_data); - GdkWindow* window = gtk_widget_get_window(widget); - if (window && window != data->parent_window) { - if (data->last_window) { - gdk_window_restack(window, data->last_window, TRUE); - } - data->last_window = window; - } -} - // Implements GtkWidget::key_press_event. static gboolean fl_view_key_press_event(GtkWidget* widget, GdkEventKey* event) { FlView* self = FL_VIEW(widget); @@ -901,8 +885,14 @@ void fl_view_set_textures(FlView* self, // Add more GL areas if we need them. for (guint i = children_length; i < textures->len; i++) { FlGLArea* area = FL_GL_AREA(fl_gl_area_new(context)); + gtk_widget_set_parent(GTK_WIDGET(area), GTK_WIDGET(self)); gtk_widget_show(GTK_WIDGET(area)); + + // Stack above previous areas but below the event box. + gdk_window_restack(gtk_widget_get_window(GTK_WIDGET(area)), + gtk_widget_get_window(self->event_box), FALSE); + self->children_list = g_list_append(self->children_list, area); } @@ -922,12 +912,5 @@ void fl_view_set_textures(FlView* self, fl_gl_area_queue_render(FL_GL_AREA(area_link->data), texture); } - struct _ReorderData data = { - .parent_window = gtk_widget_get_window(GTK_WIDGET(self)), - .last_window = nullptr, - }; - - gtk_container_forall(GTK_CONTAINER(self), fl_view_reorder_forall, &data); - gtk_widget_queue_draw(GTK_WIDGET(self)); } From 5e3a45159824ce1684c819d92dec7c6b81a168a6 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Wed, 1 Mar 2023 11:50:02 -0800 Subject: [PATCH 14/14] NULL -> nullptr --- shell/platform/linux/fl_view.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/linux/fl_view.cc b/shell/platform/linux/fl_view.cc index f40e863622265..5cd4714e77fda 100644 --- a/shell/platform/linux/fl_view.cc +++ b/shell/platform/linux/fl_view.cc @@ -712,7 +712,7 @@ static void fl_view_size_allocate(GtkWidget* widget, GtkAllocation child_allocation = {0, 0, 0, 0}; GtkRequisition child_requisition; - gtk_widget_get_preferred_size(w, &child_requisition, NULL); + gtk_widget_get_preferred_size(w, &child_requisition, nullptr); if (!gtk_widget_get_has_window(widget)) { child_allocation.x += allocation->x;