Skip to content

Commit

Permalink
Fix rendering corruption by Flutter and GDK sharing the same OpenGL c…
Browse files Browse the repository at this point in the history
…ontext (flutter#53103)

Fix rendering corruption by Flutter and GDK sharing the same OpenGL
context

Solved by having three contexts - one for GDK and two for Flutter.

Regression introduced in flutter#50754

Fixes flutter/flutter#148653
  • Loading branch information
robert-ancell authored and GitHub Actions Bot committed Jun 3, 2024
1 parent 1a948ed commit e0472d6
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions shell/platform/linux/fl_renderer_gdk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ struct _FlRendererGdk {
// Window being rendered on.
GdkWindow* window;

// Main OpenGL rendering context.
// OpenGL rendering context used by GDK.
GdkGLContext* gdk_context;

// Main OpenGL rendering context used by Flutter.
GdkGLContext* main_context;

// Secondary OpenGL rendering context.
// Secondary OpenGL rendering context used by Flutter.
GdkGLContext* resource_context;
};

Expand All @@ -39,6 +42,7 @@ static void fl_renderer_gdk_clear_current(FlRenderer* renderer) {
static void fl_renderer_gdk_dispose(GObject* object) {
FlRendererGdk* self = FL_RENDERER_GDK(object);

g_clear_object(&self->gdk_context);
g_clear_object(&self->main_context);
g_clear_object(&self->resource_context);

Expand All @@ -64,6 +68,14 @@ FlRendererGdk* fl_renderer_gdk_new(GdkWindow* window) {
}

gboolean fl_renderer_gdk_create_contexts(FlRendererGdk* self, GError** error) {
self->gdk_context = gdk_window_create_gl_context(self->window, error);
if (self->gdk_context == nullptr) {
return FALSE;
}
if (!gdk_gl_context_realize(self->gdk_context, error)) {
return FALSE;
}

self->main_context = gdk_window_create_gl_context(self->window, error);
if (self->main_context == nullptr) {
return FALSE;
Expand All @@ -85,5 +97,5 @@ gboolean fl_renderer_gdk_create_contexts(FlRendererGdk* self, GError** error) {

GdkGLContext* fl_renderer_gdk_get_context(FlRendererGdk* self) {
g_return_val_if_fail(FL_IS_RENDERER_GDK(self), nullptr);
return self->main_context;
return self->gdk_context;
}

0 comments on commit e0472d6

Please sign in to comment.