Skip to content

Commit

Permalink
Support Wayland only (without X11 support in gdk) (#21218)
Browse files Browse the repository at this point in the history
Adds a support for compiling flutter engine when
gdk does not have X11 backend. In such a configuration
the generated gdkconfig.h header file looks like the following:

 /* gdkconfig.h
  *
  * This is a generated file.  Please modify `configure.ac'
  */

 #ifndef __GDKCONFIG_H__
 #define __GDKCONFIG_H__

 #if !defined (__GDK_H_INSIDE__) && !defined (GDK_COMPILATION)
 #error "Only <gdk/gdk.h> can be included directly."
 #endif

 #include <glib.h>

 G_BEGIN_DECLS

 #define GDK_WINDOWING_WAYLAND

 G_END_DECLS

 #endif  /* __GDKCONFIG_H__ */

Additionally headers like <gdk/gdkx.h> are not available at all.

Above configuration can be found on the most of the embedded systems.

This patch enables compilation of X11 specific code only when gdk
defines GDK_WINDOWING_X11.

Signed-off-by: Damian Wrobel <dwrobel@ertelnet.rybnik.pl>
  • Loading branch information
dwrobel committed Oct 13, 2020
1 parent d9a2481 commit 6634406
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
4 changes: 4 additions & 0 deletions shell/platform/linux/fl_renderer_x11.cc
Expand Up @@ -3,6 +3,8 @@
// found in the LICENSE file.

#include "fl_renderer_x11.h"
#ifdef GDK_WINDOWING_X11

#include "flutter/shell/platform/linux/egl_utils.h"

struct _FlRendererX11 {
Expand Down Expand Up @@ -108,3 +110,5 @@ static void fl_renderer_x11_init(FlRendererX11* self) {}
FlRendererX11* fl_renderer_x11_new() {
return FL_RENDERER_X11(g_object_new(fl_renderer_x11_get_type(), nullptr));
}

#endif // GDK_WINDOWING_X11
5 changes: 5 additions & 0 deletions shell/platform/linux/fl_renderer_x11.h
Expand Up @@ -5,6 +5,9 @@
#ifndef FLUTTER_SHELL_PLATFORM_LINUX_FL_RENDERER_X11_H_
#define FLUTTER_SHELL_PLATFORM_LINUX_FL_RENDERER_X11_H_

#include <gdk/gdk.h>

#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>

#include "flutter/shell/platform/linux/fl_renderer.h"
Expand Down Expand Up @@ -35,4 +38,6 @@ FlRendererX11* fl_renderer_x11_new();

G_END_DECLS

#endif // GDK_WINDOWING_X11

#endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_RENDERER_X11_H_
26 changes: 19 additions & 7 deletions shell/platform/linux/fl_view.cc
Expand Up @@ -5,7 +5,9 @@
#include "flutter/shell/platform/linux/public/flutter_linux/fl_view.h"

#include <gdk/gdkwayland.h>
#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
#endif
#include <cstring>

#include "flutter/shell/platform/linux/fl_engine_private.h"
Expand Down Expand Up @@ -131,17 +133,27 @@ static void fl_view_plugin_registry_iface_init(
iface->get_registrar_for_plugin = fl_view_get_registrar_for_plugin;
}

static FlRenderer* fl_view_get_renderer_for_display(GdkDisplay* display) {
#ifdef GDK_WINDOWING_X11
if (GDK_IS_X11_DISPLAY(display)) {
return FL_RENDERER(fl_renderer_x11_new());
}
#endif

if (GDK_IS_WAYLAND_DISPLAY(display)) {
return FL_RENDERER(fl_renderer_wayland_new());
}

g_error("Unsupported GDK backend");

return nullptr;
}

static void fl_view_constructed(GObject* object) {
FlView* self = FL_VIEW(object);

GdkDisplay* display = gtk_widget_get_display(GTK_WIDGET(self));
if (GDK_IS_X11_DISPLAY(display)) {
self->renderer = FL_RENDERER(fl_renderer_x11_new());
} else if (GDK_IS_WAYLAND_DISPLAY(display)) {
self->renderer = FL_RENDERER(fl_renderer_wayland_new());
} else {
g_error("Unsupported GDK backend");
}
self->renderer = fl_view_get_renderer_for_display(display);
self->engine = fl_engine_new(self->project, self->renderer);

// Create system channel handlers.
Expand Down

0 comments on commit 6634406

Please sign in to comment.