Skip to content

Commit

Permalink
wl: Do not rely on CogShell to track viewports
Browse files Browse the repository at this point in the history
Use the new CogPlatform.viewport_{created,disposed} vfuncs to track live
CogViewport instances, instead of relying on CogShell. This removes all
the usage of the shell instance in the Wayland platform, paving the way
to uncouple CogShell from CogPlatform.
  • Loading branch information
aperezdc committed Dec 18, 2023
1 parent 597d641 commit 6af7c01
Showing 1 changed file with 33 additions and 18 deletions.
51 changes: 33 additions & 18 deletions platform/wayland/cog-platform-wl.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* cog-wl-platform.c
* Copyright (C) 2019-2023 Igalia S.L.
* Copyright (C) 2018 Eduardo Lima <[email protected]>
* Copyright (C) 2018 Adrian Perez de Castro <[email protected]>
*
Expand Down Expand Up @@ -1321,18 +1322,8 @@ cog_wl_platform_on_notify_visible_view(CogWlPlatform *self, GParamSpec *pspec G_
cog_wl_view_update_surface_contents(view);
}

static void
cog_wl_platform_on_create_viewport(CogWlPlatform *platform, CogViewport *viewport, CogShell *shell)
{
g_assert(COG_IS_VIEWPORT(viewport));
cog_wl_viewport_create_window(COG_WL_VIEWPORT(viewport), NULL);

g_signal_connect_object(viewport, "notify::visible-view", G_CALLBACK(cog_wl_platform_on_notify_visible_view),
platform, G_CONNECT_AFTER | G_CONNECT_SWAPPED);
}

static gboolean
cog_wl_platform_setup(CogPlatform *platform, CogShell *shell, const char *params, GError **error)
cog_wl_platform_setup(CogPlatform *platform, CogShell *shell G_GNUC_UNUSED, const char *params, GError **error)
{
g_return_val_if_fail(COG_IS_SHELL(shell), FALSE);

Expand All @@ -1356,12 +1347,7 @@ cog_wl_platform_setup(CogPlatform *platform, CogShell *shell, const char *params
}

/* init WPE host data */
wpe_fdo_initialize_for_egl_display(display->egl_display);

/* get a reference to the hashmap with viewports added to the shell */
self->viewports = cog_shell_get_viewports(shell);

g_signal_connect_swapped(shell, "create-viewport", G_CALLBACK(cog_wl_platform_on_create_viewport), self);
wpe_fdo_initialize_for_egl_display(self->display->egl_display);

#if COG_ENABLE_WESTON_DIRECT_DISPLAY
wpe_video_plane_display_dmabuf_register_receiver(&video_plane_display_dmabuf_receiver, platform);
Expand All @@ -1382,6 +1368,8 @@ cog_wl_platform_finalize(GObject *object)
clear_egl(platform->display);
clear_wayland(platform);

g_clear_pointer(&platform->viewports, g_ptr_array_unref);

G_OBJECT_CLASS(cog_wl_platform_parent_class)->finalize(object);
}

Expand Down Expand Up @@ -1432,6 +1420,30 @@ cog_wl_platform_popup_update(void)
cog_wl_popup_update(platform->popup);
}

static void
cog_wl_platform_viewport_created(CogPlatform *platform, CogViewport *viewport)
{
CogWlPlatform *self = COG_WL_PLATFORM(platform);

g_assert(!g_ptr_array_find(self->viewports, viewport, NULL));
g_ptr_array_add(self->viewports, viewport);

// TODO: Move into CogWlViewport.constructed or somewhere more suitable.
cog_wl_viewport_create_window(COG_WL_VIEWPORT(viewport), NULL);

g_signal_connect_object(viewport, "notify::visible-view", G_CALLBACK(cog_wl_platform_on_notify_visible_view),
platform, G_CONNECT_AFTER | G_CONNECT_SWAPPED);
}

static void
cog_wl_platform_viewport_disposed(CogPlatform *platform, CogViewport *viewport)
{
CogWlPlatform *self = COG_WL_PLATFORM(platform);

gboolean removed G_GNUC_UNUSED = g_ptr_array_remove_fast(self->viewports, viewport);
g_assert(removed);
}

static void
cog_wl_platform_class_init(CogWlPlatformClass *klass)
{
Expand All @@ -1444,6 +1456,8 @@ cog_wl_platform_class_init(CogWlPlatformClass *klass)
platform_class->get_viewport_type = cog_wl_viewport_get_type;
platform_class->setup = cog_wl_platform_setup;
platform_class->create_im_context = cog_wl_platform_create_im_context;
platform_class->viewport_created = cog_wl_platform_viewport_created;
platform_class->viewport_disposed = cog_wl_platform_viewport_disposed;
}

static void
Expand All @@ -1452,8 +1466,9 @@ cog_wl_platform_class_finalize(CogWlPlatformClass *klass)
}

static void
cog_wl_platform_init(CogWlPlatform *platform)
cog_wl_platform_init(CogWlPlatform *self)
{
self->viewports = g_ptr_array_sized_new(3);
}

G_MODULE_EXPORT void
Expand Down

0 comments on commit 6af7c01

Please sign in to comment.