Skip to content

Commit 6784ca7

Browse files
wang-binugurulupinar
authored andcommitted
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 7668680 commit 6784ca7

File tree

6 files changed

+26
-9
lines changed

6 files changed

+26
-9
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ Anton Sakhon <kofhein@gmail.com>
2020
Bari Rao <bari.rao@gmail.com>
2121
Frede Emil Hoey Braendstrup <frederikbraendstrup@gmail.com>
2222
Dominique Martinet <dominique.martinet@atmark-techno.com>
23+
Wang Bin <wbsecg1@gmail.com>

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

Lines changed: 18 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,16 @@ namespace flutter {
1415

1516
class EnvironmentEgl {
1617
public:
17-
EnvironmentEgl(EGLNativeDisplayType platform_display,
18+
EnvironmentEgl(EGLenum platform, EGLNativeDisplayType platform_display,
1819
bool sub_environment = false)
1920
: display_(EGL_NO_DISPLAY), sub_environment_(sub_environment) {
20-
display_ = eglGetDisplay(platform_display);
21+
InitPlatformFuns();
22+
if (platform && eglGetPlatformDisplay_) {
23+
display_ = eglGetPlatformDisplay_(platform, platform_display, nullptr);
24+
}
25+
if (display_ == EGL_NO_DISPLAY) {
26+
display_ = eglGetDisplay(platform_display);
27+
}
2128
if (display_ == EGL_NO_DISPLAY) {
2229
ELINUX_LOG(ERROR) << "Failed to get the EGL display: "
2330
<< get_egl_error_cause();
@@ -66,7 +73,16 @@ class EnvironmentEgl {
6673

6774
EGLDisplay Display() const { return display_; }
6875

76+
private:
77+
void InitPlatformFuns() {
78+
static const char* client_exts = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
79+
if (client_exts && has_egl_extension(client_exts, "EGL_EXT_platform_base")) {
80+
eglGetPlatformDisplay_ = reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC>(eglGetProcAddress("eglGetPlatformDisplayEXT"));
81+
}
82+
}
83+
6984
protected:
85+
PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplay_ = nullptr;
7086
EGLDisplay display_;
7187
bool valid_ = false;
7288
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)