Skip to content

Commit 8efc672

Browse files
Don't terminate the shared EGL display when an engine is disposed (flutter#194520)
The EGL display is shared across the process (by all engines and GDK), so calling eglTerminate() when one engine's FlOpenGLManager is disposed breaks rendering for any remaining engines. This doesn't occur in the standard case of a single engine, only when multiple engines are used. Regression introduced in flutter#172330. Fixes flutter#194399
1 parent 72f018b commit 8efc672

3 files changed

Lines changed: 57 additions & 1 deletion

File tree

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ static void fl_opengl_manager_dispose(GObject* object) {
3737
eglDestroyContext(self->display, self->render_context);
3838
eglDestroyContext(self->display, self->resource_context);
3939
eglDestroyContext(self->display, self->platform_context);
40-
eglTerminate(self->display);
4140

4241
G_OBJECT_CLASS(fl_opengl_manager_parent_class)->dispose(object);
4342
}

‎engine/src/flutter/shell/platform/linux/fl_view_test.cc‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
1010
#include "flutter/shell/platform/linux/fl_engine_private.h"
11+
#include "flutter/shell/platform/linux/fl_opengl_manager.h"
1112
#include "flutter/shell/platform/linux/fl_renderable.h"
1213
#include "flutter/shell/platform/linux/fl_text_input_handler.h"
1314
#include "flutter/shell/platform/linux/fl_view_private.h"
@@ -256,3 +257,47 @@ TEST_F(FlViewTest, SizedToContent) {
256257
fl_gtk_widget_destroy(GTK_WIDGET(secondary_view));
257258
fl_gtk_widget_destroy(GTK_WIDGET(implicit_view));
258259
}
260+
261+
// Check that destroying a view with its own engine doesn't break the OpenGL
262+
// state of another engine, as they share the same EGL display.
263+
// https://github.com/flutter/flutter/issues/194399
264+
TEST_F(FlViewTest, DestroyViewWithSeparateEngine) {
265+
FlView* view1 = fl_view_new(project);
266+
g_object_ref_sink(view1);
267+
FlView* view2 = fl_view_new(project);
268+
g_object_ref_sink(view2);
269+
270+
FlEngine* engine1 = fl_view_get_engine(view1);
271+
FlEngine* engine2 = fl_view_get_engine(view2);
272+
EXPECT_NE(engine1, engine2);
273+
274+
// Complete view removal so the engine is not held by the pending request.
275+
fl_engine_get_embedder_api(engine2)->RemoveView = MOCK_ENGINE_PROC(
276+
RemoveView, ([](auto engine, const FlutterRemoveViewInfo* info) {
277+
FlutterRemoveViewResult result = {
278+
.struct_size = sizeof(FlutterRemoveViewResult),
279+
.removed = true,
280+
.user_data = info->user_data};
281+
info->remove_view_callback(&result);
282+
return kSuccess;
283+
}));
284+
285+
// Destroy the second view, which disposes its engine.
286+
g_object_add_weak_pointer(G_OBJECT(engine2),
287+
reinterpret_cast<gpointer*>(&engine2));
288+
fl_gtk_widget_destroy(GTK_WIDGET(view2));
289+
g_object_unref(view2);
290+
while (g_main_context_iteration(nullptr, FALSE)) {
291+
}
292+
ASSERT_EQ(engine2, nullptr);
293+
294+
// The first engine can still use OpenGL.
295+
FlOpenGLManager* opengl_manager = fl_engine_get_opengl_manager(engine1);
296+
EXPECT_TRUE(fl_opengl_manager_make_current(opengl_manager));
297+
EXPECT_TRUE(fl_opengl_manager_make_resource_current(opengl_manager));
298+
EXPECT_TRUE(fl_opengl_manager_make_platform_current(opengl_manager));
299+
EXPECT_TRUE(fl_opengl_manager_clear_current(opengl_manager));
300+
301+
fl_gtk_widget_destroy(GTK_WIDGET(view1));
302+
g_object_unref(view1);
303+
}

‎engine/src/flutter/shell/platform/linux/testing/mock_epoxy.cc‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,16 @@ EGLBoolean _eglDestroyContext(EGLDisplay dpy, EGLContext ctx) {
423423
return bool_success();
424424
}
425425

426+
EGLBoolean _eglTerminate(EGLDisplay dpy) {
427+
if (!check_display(dpy)) {
428+
return EGL_FALSE;
429+
}
430+
431+
display_initialized = false;
432+
433+
return bool_success();
434+
}
435+
426436
EGLBoolean _eglSwapInterval(EGLDisplay dpy, EGLint interval) {
427437
if (!check_display(dpy) || !check_initialized(dpy)) {
428438
return EGL_FALSE;
@@ -852,6 +862,7 @@ EGLBoolean (*epoxy_eglQuerySurface)(EGLDisplay dpy,
852862
EGLint* value);
853863
EGLBoolean (*epoxy_eglDestroySurface)(EGLDisplay dpy, EGLSurface surface);
854864
EGLBoolean (*epoxy_eglDestroyContext)(EGLDisplay dpy, EGLContext ctx);
865+
EGLBoolean (*epoxy_eglTerminate)(EGLDisplay dpy);
855866
EGLBoolean (*epoxy_eglSwapInterval)(EGLDisplay dpy, EGLint interval);
856867
EGLSyncKHR (*epoxy_eglCreateSyncKHR)(EGLDisplay dpy,
857868
EGLenum type,
@@ -966,6 +977,7 @@ static void library_init() {
966977
epoxy_eglQuerySurface = _eglQuerySurface;
967978
epoxy_eglDestroySurface = _eglDestroySurface;
968979
epoxy_eglDestroyContext = _eglDestroyContext;
980+
epoxy_eglTerminate = _eglTerminate;
969981
epoxy_eglSwapInterval = _eglSwapInterval;
970982
epoxy_eglCreateSyncKHR = _eglCreateSyncKHR;
971983
epoxy_eglDestroySyncKHR = _eglDestroySyncKHR;

0 commit comments

Comments
 (0)