Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit d2ea378

Browse files
authored
Revert "Explicitly make the X connection for EGL. (#21831)" (#21851)
This reverts commit 516cbae.
1 parent 516cbae commit d2ea378

File tree

3 files changed

+9
-32
lines changed

3 files changed

+9
-32
lines changed

shell/platform/linux/BUILD.gn

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ source_set("flutter_linux") {
129129
"//flutter/shell/platform/linux/config:gtk",
130130
"//flutter/shell/platform/linux/config:egl",
131131
"//flutter/shell/platform/linux/config:wayland-egl",
132-
"//flutter/shell/platform/linux/config:x11",
133132
"//third_party/khronos:khronos_headers",
134133
]
135134

@@ -173,7 +172,6 @@ executable("flutter_linux_unittests") {
173172
configs += [
174173
"//flutter/shell/platform/linux/config:gtk",
175174
"//flutter/shell/platform/linux/config:wayland-egl",
176-
"//flutter/shell/platform/linux/config:x11",
177175
]
178176

179177
# Set flag to allow public headers to be directly included (library users should not do this)

shell/platform/linux/config/BUILD.gn

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import("//build/config/linux/pkg_config.gni")
66
import("//flutter/shell/platform/glfw/config.gni")
77

8-
pkg_config("x11") {
9-
packages = [ "x11" ]
8+
if (build_glfw_shell) {
9+
pkg_config("x11") {
10+
packages = [ "x11" ]
11+
}
1012
}
1113

1214
pkg_config("gtk") {

shell/platform/linux/fl_renderer_x11.cc

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,14 @@
55
#include "fl_renderer_x11.h"
66
#ifdef GDK_WINDOWING_X11
77

8-
#include <X11/X.h>
9-
108
#include "flutter/shell/platform/linux/egl_utils.h"
119

1210
struct _FlRendererX11 {
1311
FlRenderer parent_instance;
14-
15-
// Connection to the X server.
16-
Display* display;
1712
};
1813

1914
G_DEFINE_TYPE(FlRendererX11, fl_renderer_x11, fl_renderer_get_type())
2015

21-
static void fl_renderer_x11_dispose(GObject* object) {
22-
FlRendererX11* self = FL_RENDERER_X11(object);
23-
24-
if (self->display != nullptr) {
25-
XCloseDisplay(self->display);
26-
self->display = nullptr;
27-
}
28-
29-
G_OBJECT_CLASS(fl_renderer_x11_parent_class)->dispose(object);
30-
}
31-
3216
// Implements FlRenderer::setup_window_attr.
3317
static gboolean fl_renderer_x11_setup_window_attr(
3418
FlRenderer* renderer,
@@ -66,17 +50,11 @@ static gboolean fl_renderer_x11_setup_window_attr(
6650

6751
// Implements FlRenderer::create_display.
6852
static EGLDisplay fl_renderer_x11_create_display(FlRenderer* renderer) {
69-
FlRendererX11* self = FL_RENDERER_X11(renderer);
70-
71-
// Create a dedicated connection to the X server because the EGL calls are
72-
// made from Flutter on a different thread to GTK. Re-using the existing
73-
// GTK X11 connection would crash as Xlib is not thread safe.
74-
if (self->display == nullptr) {
75-
Display* display = gdk_x11_get_default_xdisplay();
76-
self->display = XOpenDisplay(DisplayString(display));
77-
}
78-
79-
return eglGetDisplay(self->display);
53+
// Note the use of EGL_DEFAULT_DISPLAY rather than sharing the existing
54+
// display connection from GTK. This is because this EGL display is going to
55+
// be accessed by a thread from Flutter. The GTK/X11 display connection is not
56+
// thread safe and would cause a crash.
57+
return eglGetDisplay(EGL_DEFAULT_DISPLAY);
8058
}
8159

8260
// Implements FlRenderer::create_surfaces.
@@ -121,7 +99,6 @@ static gboolean fl_renderer_x11_create_surfaces(FlRenderer* renderer,
12199
}
122100

123101
static void fl_renderer_x11_class_init(FlRendererX11Class* klass) {
124-
G_OBJECT_CLASS(klass)->dispose = fl_renderer_x11_dispose;
125102
FL_RENDERER_CLASS(klass)->setup_window_attr =
126103
fl_renderer_x11_setup_window_attr;
127104
FL_RENDERER_CLASS(klass)->create_display = fl_renderer_x11_create_display;

0 commit comments

Comments
 (0)