-
Notifications
You must be signed in to change notification settings - Fork 3.1k
vo/opengl,vo/vulkan: fix Android surface tearing on resize #16540
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
base: master
Are you sure you want to change the base?
Conversation
Download the artifacts for this pull request: Windows |
How does it look now? I've switched to using the swapchain abstraction |
ra_gl_ctx_resize(ctx->swapchain, w, h, 0); | ||
|
||
// Force a buffer swap to sync the new geometry | ||
// This ensures the surface is updated even when paused |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks better but I'm still wondering about the paused case.
In my mental model the VO should be redrawing anyway, since the old frame will mismatch the new dimensions.
I'll try to give the code changes some testing later.
Works where it works but results in black screen on some ancient opengl versions like such, breaks rendering entirely
|
Test case: opening a picture in mpv-android (paused) and switching the orientation Setting I tested removing the part of the code that seemed weird to me and it still works perfectly fine: diff --git a/video/out/opengl/context_android.c b/video/out/opengl/context_android.c
--- a/video/out/opengl/context_android.c
+++ b/video/out/opengl/context_android.c
@@ -111,25 +111,12 @@ static bool android_reconfig(struct ra_ctx *ctx)
// Update native window buffer geometry to prevent screen tearing
ANativeWindow *native_window = vo_android_native_window(ctx->vo);
- if (native_window) {
+ if (native_window)
ANativeWindow_setBuffersGeometry(native_window, w, h, 0);
- }
ctx->vo->dwidth = w;
ctx->vo->dheight = h;
ra_gl_ctx_resize(ctx->swapchain, w, h, 0);
-
- // Force a buffer swap to sync the new geometry
- // This ensures the surface is updated even when paused
- struct priv *p = ctx->priv;
- if (p->egl_display && p->egl_surface) {
- struct ra_fbo fbo;
- if (ctx->swapchain->fns->start_frame(ctx->swapchain, &fbo)) {
- // Submit an empty frame to force buffer synchronization
- ctx->swapchain->fns->submit_frame(ctx->swapchain, NULL);
- ctx->swapchain->fns->swap_buffers(ctx->swapchain);
- }
- }
return true;
} |
Thanks, but I remember this didn't work on my device before. I'll retest and confirm later. |
Simple fix is enough but it's also enough to cause breakage on older versions. Format being null may be why but idk |
For all we know this is a driver issue affecting a very small subset of old devices. Safe to assume not many of them are in use today. I'm okay with this being merged as is and seeing if anyone else complains. Helps more devices actively being used and beats having to do client sided hacks to workaround the bug. |
Actually no, there's something seriously wrong with the approach of calling |
It's possible that calling mpv/video/out/opengl/context_android.c Lines 74 to 75 in 440f35a
|
@chachako any time to look at this again? |
Sorry I've been a bit busy lately, I'll take a look again in the next day or two 🥹 |
@sfan5 Sorry for the wait! I tried the simplified approach you suggested, but unfortunately it doesn't work on my device. I think I may have missed mentioning the most important detail earlier: this issue specifically occurs when the activity has Also, Some alternative workarounds:
|
mpv-android has that (and more): Are you testing the changes with your own app or with mpv-android? |
I only tested the changes in this PR on my own app. mpv-android certainly has its problems, but I haven't replaced and tested the mpv native it uses Screenrecorder-2025-10-01-15-13-23-481.mp4 |
This PR fixes screen tearing that occurs when resizing or rotating the display on Android, particularly noticeable when video is paused.
Problem
When the device orientation changes, the surface size updates but the native window buffer geometry is not synchronized, causing visual artifacts and screen tearing.
This issue was reported in mpv-android/mpv-android#991.
Testing
Tested on Android devices by:
Before:
Screenrecorder-2025-07-13-21-20-25-249.mp4
After:
Screenrecorder-2025-07-14-01-21-47-889.mp4