Skip to content

Commit 00f6aab

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 00f6aab

File tree

6 files changed

+27
-9
lines changed

6 files changed

+27
-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: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_ENVIRONMENT_EGL_H_
77

88
#include <EGL/egl.h>
9+
#include <EGL/eglext.h>
10+
#include <cstdio>
911

1012
#include "flutter/shell/platform/linux_embedded/logger.h"
1113
#include "flutter/shell/platform/linux_embedded/surface/egl_utils.h"
@@ -14,10 +16,16 @@ namespace flutter {
1416

1517
class EnvironmentEgl {
1618
public:
17-
EnvironmentEgl(EGLNativeDisplayType platform_display,
19+
EnvironmentEgl(EGLenum platform, 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,16 @@ class EnvironmentEgl {
6674

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

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ 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_), enable_impeller));
14471447
render_surface_->SetNativeWindow(native_window_.get());
14481448

14491449
if (view_properties_.use_window_decoration) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ 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_), enable_impeller);
129129

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ 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_), enable_impeller));
138138
}
139139

140140
bool NativeWindowDrmGbm::IsNeedRecreateSurfaceAfterResize() const {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ 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, sub_egl_display),
3939
enable_impeller)));
4040
titlebar_->SetPosition(0, -kTitleBarHeightDIP);
4141

@@ -48,7 +48,7 @@ WindowDecorationsWayland::WindowDecorationsWayland(
4848
kButtonWidthDIP * pixel_ratio, kButtonHeightDIP * pixel_ratio,
4949
enable_vsync),
5050
std::make_unique<SurfaceDecoration>(std::make_unique<ContextEgl>(
51-
std::make_unique<EnvironmentEgl>(display, sub_egl_display),
51+
std::make_unique<EnvironmentEgl>(EGL_PLATFORM_WAYLAND_KHR, display, sub_egl_display),
5252
enable_impeller))));
5353
buttons_[type]->SetPosition(
5454
width_dip * pixel_ratio - kButtonWidthDIP - kButtonMarginDIP,
@@ -63,7 +63,7 @@ WindowDecorationsWayland::WindowDecorationsWayland(
6363
kButtonWidthDIP * pixel_ratio, kButtonHeightDIP * pixel_ratio,
6464
enable_vsync),
6565
std::make_unique<SurfaceDecoration>(std::make_unique<ContextEgl>(
66-
std::make_unique<EnvironmentEgl>(display, sub_egl_display),
66+
std::make_unique<EnvironmentEgl>(EGL_PLATFORM_WAYLAND_KHR, display, sub_egl_display),
6767
enable_impeller))));
6868
buttons_[type]->SetPosition(
6969
width_dip * pixel_ratio - kButtonWidthDIP * 2 - kButtonMarginDIP * 2,
@@ -78,7 +78,7 @@ WindowDecorationsWayland::WindowDecorationsWayland(
7878
kButtonWidthDIP * pixel_ratio, kButtonHeightDIP * pixel_ratio,
7979
enable_vsync),
8080
std::make_unique<SurfaceDecoration>(std::make_unique<ContextEgl>(
81-
std::make_unique<EnvironmentEgl>(display, sub_egl_display),
81+
std::make_unique<EnvironmentEgl>(EGL_PLATFORM_WAYLAND_KHR, display, sub_egl_display),
8282
enable_impeller))));
8383
buttons_[type]->SetPosition(
8484
width_dip * pixel_ratio - kButtonWidthDIP * 3 - kButtonMarginDIP * 3,

0 commit comments

Comments
 (0)