Skip to content

Commit

Permalink
[CP-stable]Fix rendering corruption by Flutter and GDK sharing the sa…
Browse files Browse the repository at this point in the history
…me 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?

flutter/flutter#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 flutter/flutter#148653 and observe popup not rendering correctly or corruption during window resize.
  • Loading branch information
flutteractionsbot authored Jul 2, 2024
1 parent a43ee36 commit a3194fa
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 a3194fa

Please sign in to comment.