Flutter Linux Embedder
fl_wayland_display.cc File Reference
#include "flutter/shell/platform/linux/fl_wayland_display.h"
#include <gdk/gdkwayland.h>
#include <wayland-client.h>

Go to the source code of this file.

Classes

struct  _FlWaylandDisplay
 

Functions

static void registry_global (void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version)
 
static void registry_global_remove (void *data, struct wl_registry *registry, uint32_t name)
 
static gboolean bind_globals (FlWaylandDisplay *self, struct wl_display *display)
 
static void fl_wayland_display_dispose (GObject *object)
 
static void fl_wayland_display_class_init (FlWaylandDisplayClass *klass)
 
static void fl_wayland_display_init (FlWaylandDisplay *self)
 
FlWaylandDisplay * fl_wayland_display_open (struct wl_display *wl_display)
 
FlWaylandDisplay * fl_wayland_display_get_for_display (GdkDisplay *gdk_display)
 
FlSubsurface * fl_wayland_display_create_subsurface (FlWaylandDisplay *self, struct wl_surface *parent_surface)
 

Variables

static const char * kWaylandDisplayKey = "fl-wayland-display"
 
static const struct wl_registry_listener kRegistryListener
 

Function Documentation

◆ bind_globals()

static gboolean bind_globals ( FlWaylandDisplay *  self,
struct wl_display *  display 
)
static

Definition at line 51 of file fl_wayland_display.cc.

52  {
53  struct wl_registry* registry = wl_display_get_registry(display);
54  wl_registry_add_listener(registry, &kRegistryListener, self);
55  wl_display_roundtrip(display);
56  wl_registry_destroy(registry);
57 
58  return self->compositor != nullptr && self->subcompositor != nullptr;
59 }
static const struct wl_registry_listener kRegistryListener

References kRegistryListener.

Referenced by fl_wayland_display_open().

◆ fl_wayland_display_class_init()

static void fl_wayland_display_class_init ( FlWaylandDisplayClass *  klass)
static

Definition at line 70 of file fl_wayland_display.cc.

70  {
71  G_OBJECT_CLASS(klass)->dispose = fl_wayland_display_dispose;
72 }
static void fl_wayland_display_dispose(GObject *object)

References fl_wayland_display_dispose().

◆ fl_wayland_display_create_subsurface()

FlSubsurface* fl_wayland_display_create_subsurface ( FlWaylandDisplay *  display,
struct wl_surface *  parent_surface 
)

fl_wayland_display_create_subsurface: @display: an #FlWaylandDisplay. @parent_surface: the Wayland surface to attach the subsurface to.

Creates a new Wayland subsurface on @parent_surface. @parent_surface must be on the display @display was created for, it is a programmer error to call this otherwise.

Returns: (transfer full): a new #FlSubsurface.

Definition at line 112 of file fl_wayland_display.cc.

114  {
115  g_return_val_if_fail(FL_IS_WAYLAND_DISPLAY(self), nullptr);
116 
117  return fl_subsurface_new(self->compositor, self->subcompositor,
118  parent_surface);
119 }
FlSubsurface * fl_subsurface_new(struct wl_compositor *compositor, struct wl_subcompositor *subcompositor, struct wl_surface *parent_surface)

References fl_subsurface_new().

Referenced by FlSubsurfaceTest::CreateSubsurface(), FlSubsurfaceEGLTest::SetUp(), and TEST_F().

◆ fl_wayland_display_dispose()

static void fl_wayland_display_dispose ( GObject *  object)
static

Definition at line 61 of file fl_wayland_display.cc.

61  {
62  FlWaylandDisplay* self = FL_WAYLAND_DISPLAY(object);
63 
64  g_clear_pointer(&self->subcompositor, wl_subcompositor_destroy);
65  g_clear_pointer(&self->compositor, wl_compositor_destroy);
66 
67  G_OBJECT_CLASS(fl_wayland_display_parent_class)->dispose(object);
68 }

Referenced by fl_wayland_display_class_init().

◆ fl_wayland_display_get_for_display()

FlWaylandDisplay* fl_wayland_display_get_for_display ( GdkDisplay *  display)

fl_wayland_display_get_for_display: @display: a Wayland #GdkDisplay.

Gets the #FlWaylandDisplay for @display, creating it if required. The Wayland registry is only queried the first time this is called for a given display. @display must be a Wayland display, it is a programmer error to call this otherwise.

Returns: (transfer none): an #FlWaylandDisplay, or NULL if the required Wayland globals are not available.

Definition at line 89 of file fl_wayland_display.cc.

89  {
90  g_return_val_if_fail(GDK_IS_WAYLAND_DISPLAY(gdk_display), nullptr);
91 
92  FlWaylandDisplay* self = FL_WAYLAND_DISPLAY(
93  g_object_get_data(G_OBJECT(gdk_display), kWaylandDisplayKey));
94  if (self != nullptr) {
95  return self;
96  }
97 
98  self =
99  fl_wayland_display_open(gdk_wayland_display_get_wl_display(gdk_display));
100  if (self == nullptr) {
101  return nullptr;
102  }
103 
104  // Owned by the #GdkDisplay, so the globals are shared by everything using
105  // that display and released with it.
106  g_object_set_data_full(G_OBJECT(gdk_display), kWaylandDisplayKey, self,
107  g_object_unref);
108 
109  return self;
110 }
static const char * kWaylandDisplayKey
FlWaylandDisplay * fl_wayland_display_open(struct wl_display *wl_display)

References fl_wayland_display_open(), and kWaylandDisplayKey.

Referenced by TEST_F().

◆ fl_wayland_display_init()

static void fl_wayland_display_init ( FlWaylandDisplay *  self)
static

Definition at line 74 of file fl_wayland_display.cc.

74 {}

◆ fl_wayland_display_open()

FlWaylandDisplay* fl_wayland_display_open ( struct wl_display *  wl_display)

Definition at line 76 of file fl_wayland_display.cc.

76  {
77  FlWaylandDisplay* self =
78  FL_WAYLAND_DISPLAY(g_object_new(fl_wayland_display_get_type(), nullptr));
79 
80  if (!bind_globals(self, wl_display)) {
81  g_warning("Required Wayland globals not available");
82  g_object_unref(self);
83  return nullptr;
84  }
85 
86  return self;
87 }
static gboolean bind_globals(FlWaylandDisplay *self, struct wl_display *display)

References bind_globals().

Referenced by fl_wayland_display_get_for_display(), FlSubsurfaceEGLTest::SetUp(), FlSubsurfaceTest::SetUp(), and TEST_F().

◆ registry_global()

static void registry_global ( void *  data,
struct wl_registry *  registry,
uint32_t  name,
const char *  interface,
uint32_t  version 
)
static

Definition at line 25 of file fl_wayland_display.cc.

29  {
30  FlWaylandDisplay* self = FL_WAYLAND_DISPLAY(data);
31  if (g_strcmp0(interface, wl_compositor_interface.name) == 0) {
32  self->compositor = static_cast<struct wl_compositor*>(wl_registry_bind(
33  registry, name, &wl_compositor_interface, MIN(version, 4)));
34  } else if (g_strcmp0(interface, wl_subcompositor_interface.name) == 0) {
35  self->subcompositor = static_cast<struct wl_subcompositor*>(
36  wl_registry_bind(registry, name, &wl_subcompositor_interface, 1));
37  }
38 }

◆ registry_global_remove()

static void registry_global_remove ( void *  data,
struct wl_registry *  registry,
uint32_t  name 
)
static

Definition at line 40 of file fl_wayland_display.cc.

42  {}

Variable Documentation

◆ kRegistryListener

const struct wl_registry_listener kRegistryListener
static
Initial value:
= {
.global = registry_global,
.global_remove = registry_global_remove,
}
static void registry_global_remove(void *data, struct wl_registry *registry, uint32_t name)
static void registry_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version)

Definition at line 40 of file fl_wayland_display.cc.

Referenced by bind_globals().

◆ kWaylandDisplayKey

const char* kWaylandDisplayKey = "fl-wayland-display"
static

Definition at line 12 of file fl_wayland_display.cc.

Referenced by fl_wayland_display_get_for_display().