-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
Graphics corruption on some frames after OpenGL rendering changes #148653
Comments
The commit in question is flutter/engine#50754, all other changes in that engine roll were impeller/macos/web related. |
I currently don't have Linux setup to verify this, but based on the report, I'll label for team's input / attention. I will request colleague to verify this further. Also, based on git bisect, the reported behavior seems to be broken, so I'll label this as regression. |
Confirmed reproduction here (first "Actual Results" case). Interestingly if you toggle performance overlay ('p' from command line) it renders correctly. Investigating in the engine with some hooks to see what is being rendered. |
I suspect this is a duplicate of #148607 |
Where the issue seems to be is the Linux embedder is rendering the textures generated by Flutter before they are complete. This seems to occur in more complex applications, as simpler ones are rendered before this is a problem. You can also see this occurring less when the window sizes are small. |
If I read the contents of the framebuffer before rendering then these show the correct contents. So it does seem to be ready from Flutter and the corruption is occurring at a later point. diff --git a/shell/platform/linux/fl_renderer.cc b/shell/platform/linux/fl_renderer.cc
index 595c315134..db2da8076e 100644
--- a/shell/platform/linux/fl_renderer.cc
+++ b/shell/platform/linux/fl_renderer.cc
@@ -333,6 +333,17 @@ void fl_renderer_render(FlRenderer* self, int width, int height) {
FlBackingStoreProvider* texture =
FL_BACKING_STORE_PROVIDER(g_ptr_array_index(priv->textures, i));
+ uint32_t framebuffer_id = fl_backing_store_provider_get_gl_framebuffer_id(texture);
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer_id);
+ GdkRectangle g =
+ fl_backing_store_provider_get_geometry(texture);
+ size_t image_data_length = 4 * g.width * g.height;
+ uint8_t *image_data = static_cast<uint8_t*>(malloc(image_data_length));
+ glReadPixels(0, 0, g.width, g.height, GL_RGBA, GL_UNSIGNED_BYTE, image_data);
+ g_printerr("%dx%d\n", g.width, g.height);
+ g_file_set_contents("texture.raw", reinterpret_cast<gchar *>(image_data), image_data_length, nullptr);
+ free(image_data);
+
uint32_t texture_id = fl_backing_store_provider_get_gl_texture_id(texture);
glBindTexture(GL_TEXTURE_2D, texture_id); The images can then be converted with:
|
I found if I replace the draw callback with just a glClear the bad frames still sometimes show up. It seems that Flutter is sometimes rendering into the framebuffer that GTK is using. I think we might be able to stop this by having Flutter and GTK use different contexts, which I will try tomorrow. |
…ontext Solved by having three contexts - one for GDK and two for Flutter. Regression introduced in flutter#50754 Fixes flutter/flutter#148653
Found the issue - it was due to Flutter and GDK sharing the same OpenGL context. This would cause Flutter to sometimes render into the framebuffer used inside GDK. Solution is to make three contexts - two for Flutter (main and resource) and one for GDK. |
…ontext (#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 #50754 Fixes flutter/flutter#148653
…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
Steps to reproduce
git clone https://github.com/xsahil03x/multi_trigger_autocomplete.git
cd multi_trigger_autocomplete/example
flutter config --enable-linux-desktop
flutter create .
flutter run -d linux
Expected results
The expected complete for emoji suggestions should look like:
Actual results
The actual results are this blog bar which has some width based on the content size but I can't tell what:
In my real app the bad rendering either shows up as a blank gray area over the whole window:
Or, after a time usually, this weird black area with mangled red lines in the bottom left corner:
Code sample
No code is necessary beyond the example app for the multi_trigger_autocomplete. To arrive at the broken commit I used
git bisect
and discovered that the last working version is commit #fe56a35602f7360850aca41b8af5bdde7fafda97 and the next commit, commit #8e418d18185697e56024ef3d5784afba4ac96370. Commit #8e418d18185697e56024ef3d5784afba4ac96370 was a Roll Flutter Engine commit that had work being done on GTK4 and some other work that may be related to this problem.Screenshots or Video
Screenshots embedded above.
Logs
No information in the logs indicating exceptions/warnings being thrown were shown.
Flutter Doctor output
Below is the output from the primary machine, which is running Linux Mint 21 in a VirtualBox VM with Software 3D Acceleration with the first bad commit. But I've testing this with Ubuntu 24.04 in a VirtualBox VM with Software 3D Acceleration using Flutter 3.22.0, and a Linux Mint 20 bare metal machine with a GeForce GTX 950 running Flutter 3.22.0:
The text was updated successfully, but these errors were encountered: