Skip to content

Commit cbf31c8

Browse files
Add a platform OpenGL context. (flutter#183715)
Switch the compositor from using the engine OpenGL context to a new context for the platform thread. When creating windows with the new multi-window API (calls come from Dart code) the FlView would try and make shaders but fail since the engine context was already current. This would show when running the multiple_windows example as: ** (com.example.multiple_windows:1244082): WARNING **: 14:09:30.400: Failed to setup compositor shaders, unable to make OpenGL context current
1 parent a76a276 commit cbf31c8

3 files changed

Lines changed: 37 additions & 4 deletions

File tree

engine/src/flutter/shell/platform/linux/fl_compositor_opengl.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static gchar* get_program_log(GLuint program) {
110110
}
111111

112112
static void setup_shader(FlCompositorOpenGL* self) {
113-
if (!fl_opengl_manager_make_current(self->opengl_manager)) {
113+
if (!fl_opengl_manager_make_platform_current(self->opengl_manager)) {
114114
g_warning(
115115
"Failed to setup compositor shaders, unable to make OpenGL context "
116116
"current");
@@ -169,7 +169,7 @@ static void setup_shader(FlCompositorOpenGL* self) {
169169
}
170170

171171
static void cleanup_shader(FlCompositorOpenGL* self) {
172-
if (!fl_opengl_manager_make_current(self->opengl_manager)) {
172+
if (!fl_opengl_manager_make_platform_current(self->opengl_manager)) {
173173
g_warning(
174174
"Failed to cleanup compositor shaders, unable to make OpenGL context "
175175
"current");

engine/src/flutter/shell/platform/linux/fl_opengl_manager.cc

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ struct _FlOpenGLManager {
1616
// Display being rendered to.
1717
EGLDisplay display;
1818

19-
// Context used by Flutter to render.
19+
// Context used by the Flutter engine for rendering.
2020
EGLContext render_context;
2121

22-
// Context used by Flutter to share resources.
22+
// Context used by the Flutter engine to share resources.
2323
EGLContext resource_context;
24+
25+
// Context used by platform thread.
26+
EGLContext platform_context;
2427
};
2528

2629
G_DEFINE_TYPE(FlOpenGLManager, fl_opengl_manager, G_TYPE_OBJECT)
@@ -30,6 +33,7 @@ static void fl_opengl_manager_dispose(GObject* object) {
3033

3134
eglDestroyContext(self->display, self->render_context);
3235
eglDestroyContext(self->display, self->resource_context);
36+
eglDestroyContext(self->display, self->platform_context);
3337
eglTerminate(self->display);
3438

3539
G_OBJECT_CLASS(fl_opengl_manager_parent_class)->dispose(object);
@@ -65,10 +69,24 @@ static void fl_opengl_manager_init(FlOpenGLManager* self) {
6569
eglChooseConfig(self->display, config_attributes, &config, 1, &num_config);
6670

6771
const EGLint context_attributes[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
72+
6873
self->render_context = eglCreateContext(self->display, config, EGL_NO_CONTEXT,
6974
context_attributes);
75+
if (self->render_context == EGL_NO_CONTEXT) {
76+
g_warning("Failed to create EGL context for rendering");
77+
}
78+
7079
self->resource_context = eglCreateContext(
7180
self->display, config, self->render_context, context_attributes);
81+
if (self->resource_context == EGL_NO_CONTEXT) {
82+
g_warning("Failed to create EGL context for resource sharing");
83+
}
84+
85+
self->platform_context = eglCreateContext(
86+
self->display, config, self->render_context, context_attributes);
87+
if (self->platform_context == EGL_NO_CONTEXT) {
88+
g_warning("Failed to create EGL context for platform thread");
89+
}
7290
}
7391

7492
FlOpenGLManager* fl_opengl_manager_new() {
@@ -87,6 +105,11 @@ gboolean fl_opengl_manager_make_resource_current(FlOpenGLManager* self) {
87105
self->resource_context) == EGL_TRUE;
88106
}
89107

108+
gboolean fl_opengl_manager_make_platform_current(FlOpenGLManager* self) {
109+
return eglMakeCurrent(self->display, EGL_NO_SURFACE, EGL_NO_SURFACE,
110+
self->platform_context) == EGL_TRUE;
111+
}
112+
90113
gboolean fl_opengl_manager_clear_current(FlOpenGLManager* self) {
91114
return eglMakeCurrent(self->display, EGL_NO_SURFACE, EGL_NO_SURFACE,
92115
EGL_NO_CONTEXT) == EGL_TRUE;

engine/src/flutter/shell/platform/linux/fl_opengl_manager.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ gboolean fl_opengl_manager_make_current(FlOpenGLManager* manager);
4444
*/
4545
gboolean fl_opengl_manager_make_resource_current(FlOpenGLManager* manager);
4646

47+
/**
48+
* fl_opengl_manager_make_platform_current:
49+
* @manager: an #FlOpenGLManager.
50+
*
51+
* Makes the platform rendering context current.
52+
*
53+
* Returns: %TRUE if the context made current.
54+
*/
55+
gboolean fl_opengl_manager_make_platform_current(FlOpenGLManager* manager);
56+
4757
/**
4858
* fl_opengl_manager_clear_current:
4959
* @manager: an #FlOpenGLManager.

0 commit comments

Comments
 (0)