From a3194fa99bc5cb775bd601126766b0abc4fa8ef6 Mon Sep 17 00:00:00 2001 From: flutteractionsbot <154381524+flutteractionsbot@users.noreply.github.com> Date: Tue, 2 Jul 2024 08:56:06 -0700 Subject: [PATCH] [CP-stable]Fix rendering corruption by Flutter and GDK sharing the same OpenGL context (#53183) This pull request is created by [automatic cherry pick workflow](https://github.com/flutter/flutter/wiki/Flutter-Cherrypick-Process#automatically-creates-a-cherry-pick-request) Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request. ### Issue Link: What is the link to the issue this cherry-pick is addressing? https://github.com/flutter/flutter/issues/148653 ### Changelog Description: Explain this cherry pick in one line that is accessible to most Flutter developers. See [best practices](https://github.com/flutter/flutter/wiki/Hotfix-Documentation-Best-Practices) for examples Linux applications showing visual corruption on some frames ### Impact Description: What is the impact (ex. visual jank on Samsung phones, app crash, cannot ship an iOS app)? Does it impact development (ex. flutter doctor crashes when Android Studio is installed), or the shipping production app (the app crashes on launch) Visual corruption seen on Linux Flutter apps, affects production apps. ### Workaround: Is there a workaround for this issue? No workaround. ### Risk: What is the risk level of this cherry-pick? ### Test Coverage: Are you confident that your fix is well-tested by automated tests? (rendering corruption not currently testable, may not be possible to test). ### Validation Steps: What are the steps to validate that this fix works? Run app in https://github.com/flutter/flutter/issues/148653 and observe popup not rendering correctly or corruption during window resize. --- shell/platform/linux/fl_renderer_gdk.cc | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/shell/platform/linux/fl_renderer_gdk.cc b/shell/platform/linux/fl_renderer_gdk.cc index f5d4990efcd82..5ddc058064bc8 100644 --- a/shell/platform/linux/fl_renderer_gdk.cc +++ b/shell/platform/linux/fl_renderer_gdk.cc @@ -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; }; @@ -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); @@ -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; @@ -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; }