Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CP-stable]Fix rendering corruption by Flutter and GDK sharing the same OpenGL context #53183

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}