Skip to content

Commit cd9f09a

Browse files
committed
use platform display
required if mutiple platforms are available, otherwise egl may call into x11 and crash even if gbm is desired. tested on rk3588
1 parent 1653fa6 commit cd9f09a

File tree

6 files changed

+38
-9
lines changed

6 files changed

+38
-9
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ Sebastian Urban <[email protected]>
1818
Athaariq Ardhiansyah <[email protected]>
1919
Anton Sakhon <[email protected]>
2020
21+

src/flutter/shell/platform/linux_embedded/surface/environment_egl.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_ENVIRONMENT_EGL_H_
77

88
#include <EGL/egl.h>
9+
#include <EGL/eglext.h>
910

1011
#include "flutter/shell/platform/linux_embedded/logger.h"
1112
#include "flutter/shell/platform/linux_embedded/surface/egl_utils.h"
@@ -14,10 +15,17 @@ namespace flutter {
1415

1516
class EnvironmentEgl {
1617
public:
17-
EnvironmentEgl(EGLNativeDisplayType platform_display,
18+
EnvironmentEgl(EGLenum platform,
19+
EGLNativeDisplayType platform_display,
1820
bool sub_environment = false)
1921
: display_(EGL_NO_DISPLAY), sub_environment_(sub_environment) {
20-
display_ = eglGetDisplay(platform_display);
22+
InitPlatformFuns();
23+
if (platform && eglGetPlatformDisplay_) {
24+
display_ = eglGetPlatformDisplay_(platform, platform_display, nullptr);
25+
}
26+
if (display_ == EGL_NO_DISPLAY) {
27+
display_ = eglGetDisplay(platform_display);
28+
}
2129
if (display_ == EGL_NO_DISPLAY) {
2230
ELINUX_LOG(ERROR) << "Failed to get the EGL display: "
2331
<< get_egl_error_cause();
@@ -66,7 +74,20 @@ class EnvironmentEgl {
6674

6775
EGLDisplay Display() const { return display_; }
6876

77+
private:
78+
void InitPlatformFuns() {
79+
static const char* client_exts =
80+
eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
81+
if (client_exts &&
82+
has_egl_extension(client_exts, "EGL_EXT_platform_base")) {
83+
eglGetPlatformDisplay_ =
84+
reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC>(
85+
eglGetProcAddress("eglGetPlatformDisplayEXT"));
86+
}
87+
}
88+
6989
protected:
90+
PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplay_ = nullptr;
7091
EGLDisplay display_;
7192
bool valid_ = false;
7293
bool sub_environment_;

src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,8 @@ bool ELinuxWindowWayland::CreateRenderSurface(int32_t width_px,
14431443
wl_surface_commit(native_window_->Surface());
14441444

14451445
render_surface_ = std::make_unique<SurfaceGl>(std::make_unique<ContextEgl>(
1446-
std::make_unique<EnvironmentEgl>(wl_display_), enable_impeller));
1446+
std::make_unique<EnvironmentEgl>(EGL_PLATFORM_WAYLAND_KHR, wl_display_),
1447+
enable_impeller));
14471448
render_surface_->SetNativeWindow(native_window_.get());
14481449

14491450
if (view_properties_.use_window_decoration) {

src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ bool ELinuxWindowX11::CreateRenderSurface(int32_t width,
125125
int32_t height,
126126
bool enable_impeller) {
127127
auto context_egl = std::make_unique<ContextEgl>(
128-
std::make_unique<EnvironmentEgl>(display_), enable_impeller);
128+
std::make_unique<EnvironmentEgl>(EGL_PLATFORM_X11_KHR, display_),
129+
enable_impeller);
129130

130131
if (current_rotation_ == 90 || current_rotation_ == 270) {
131132
std::swap(width, height);

src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ bool NativeWindowDrmGbm::DismissCursor() {
134134
std::unique_ptr<SurfaceGl> NativeWindowDrmGbm::CreateRenderSurface(
135135
bool enable_impeller) {
136136
return std::make_unique<SurfaceGl>(std::make_unique<ContextEgl>(
137-
std::make_unique<EnvironmentEgl>(gbm_device_), enable_impeller));
137+
std::make_unique<EnvironmentEgl>(EGL_PLATFORM_GBM_KHR, gbm_device_),
138+
enable_impeller));
138139
}
139140

140141
bool NativeWindowDrmGbm::IsNeedRecreateSurfaceAfterResize() const {

src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ WindowDecorationsWayland::WindowDecorationsWayland(
3535
compositor, subcompositor, root_surface, width_dip * pixel_ratio,
3636
kTitleBarHeightDIP * pixel_ratio, enable_vsync),
3737
std::make_unique<SurfaceDecoration>(std::make_unique<ContextEgl>(
38-
std::make_unique<EnvironmentEgl>(display, sub_egl_display),
38+
std::make_unique<EnvironmentEgl>(EGL_PLATFORM_WAYLAND_KHR, display,
39+
sub_egl_display),
3940
enable_impeller)));
4041
titlebar_->SetPosition(0, -kTitleBarHeightDIP);
4142

@@ -48,7 +49,8 @@ WindowDecorationsWayland::WindowDecorationsWayland(
4849
kButtonWidthDIP * pixel_ratio, kButtonHeightDIP * pixel_ratio,
4950
enable_vsync),
5051
std::make_unique<SurfaceDecoration>(std::make_unique<ContextEgl>(
51-
std::make_unique<EnvironmentEgl>(display, sub_egl_display),
52+
std::make_unique<EnvironmentEgl>(EGL_PLATFORM_WAYLAND_KHR, display,
53+
sub_egl_display),
5254
enable_impeller))));
5355
buttons_[type]->SetPosition(
5456
width_dip * pixel_ratio - kButtonWidthDIP - kButtonMarginDIP,
@@ -63,7 +65,8 @@ WindowDecorationsWayland::WindowDecorationsWayland(
6365
kButtonWidthDIP * pixel_ratio, kButtonHeightDIP * pixel_ratio,
6466
enable_vsync),
6567
std::make_unique<SurfaceDecoration>(std::make_unique<ContextEgl>(
66-
std::make_unique<EnvironmentEgl>(display, sub_egl_display),
68+
std::make_unique<EnvironmentEgl>(EGL_PLATFORM_WAYLAND_KHR, display,
69+
sub_egl_display),
6770
enable_impeller))));
6871
buttons_[type]->SetPosition(
6972
width_dip * pixel_ratio - kButtonWidthDIP * 2 - kButtonMarginDIP * 2,
@@ -78,7 +81,8 @@ WindowDecorationsWayland::WindowDecorationsWayland(
7881
kButtonWidthDIP * pixel_ratio, kButtonHeightDIP * pixel_ratio,
7982
enable_vsync),
8083
std::make_unique<SurfaceDecoration>(std::make_unique<ContextEgl>(
81-
std::make_unique<EnvironmentEgl>(display, sub_egl_display),
84+
std::make_unique<EnvironmentEgl>(EGL_PLATFORM_WAYLAND_KHR, display,
85+
sub_egl_display),
8286
enable_impeller))));
8387
buttons_[type]->SetPosition(
8488
width_dip * pixel_ratio - kButtonWidthDIP * 3 - kButtonMarginDIP * 3,

0 commit comments

Comments
 (0)