Bug 476102 - [Wayland] Downscaled X11 Windows Look Blocky/Blurry
Summary: [Wayland] Downscaled X11 Windows Look Blocky/Blurry
Status: RESOLVED INTENTIONAL
Alias: None
Product: kwin
Classification: Plasma
Component: multi-screen (other bugs)
Version First Reported In: 5.27.8
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-10-26 02:15 UTC by Eamonn Rea
Modified: 2023-11-01 21:58 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eamonn Rea 2023-10-26 02:15:48 UTC
SUMMARY
On KDE Plasma Wayland, with one fractionally scaled display and any number of displays without any scaling, the text in downscaled(?) X11 applications look blocky when using the "Apply scaling themselves" option under Legacy (X11) Application settings once they are moved from the scaled display to a display which is not scaled. Images look more on the blurry side. The larger the font in the application, the more it moves from the "blocky" to the "blurry" end of the spectrum. The content of X11 windows with this option does not look as smooth as one would expect.

The thinner the font as well, the more apparent this effect becomes. Here is an example of the effect on some text on the Steam:
- Games in library: https://i.postimg.cc/0j0YWsQm/image.png
- Some general library text: https://i.postimg.cc/xTgGLnBV/image.png
- Image content on the Store Page looks noticeably blurrier in the client (X11) than it does on Firefox on the same display.
  - Steam Client: https://i.postimg.cc/sXF53XG7/image.png
  - Firefox: https://i.postimg.cc/zDFT1qzH/image.png

The issue is not exclusive to Steam, here are other examples:
- ProtonUp-Qt Flatpak, running with QT_QPA_PLATFORM=xcb to enforce X11: https://i.postimg.cc/90L4wF0x/image.png
  - Here's how it looks under Wayland on the same display: https://postimg.cc/xqH2DtwK/487bfd88
- Cookie Clicker, an Electron game running under Proton (Wine X11) with the "--force-device-scale-factor=1.5" launch option: https://i.postimg.cc/6qkk0C8T/image.png
  - Using the Wine integer scaling option does not really alleviate the issue either

This applies to all X11 applications:
- X11 applications that can apply scaling themselves, such as modern Qt/GTK applications, including some Electron applications such as the Heroic Games Launcher.
- X11 applications that cannot apply scaling themselves but which can have a scale factor set, such as the Steam Client (STEAM_FORCE_DESKTOPUI_SCALING=1.5) or older Electron applications including games (both native and running under Wine) such as Cookie Clicker or Melvor Idle (--force-device-scale-factor=1.5). Wine applications with a DPI scale factor set also exhibit similar behaviour, to varying degrees depending on how high you set the scale factor (it's not as easy to get right as it is for the other two, since you can't provide a decimal value)
- X11 applications unscaled, which look noticeably blockier and not just smaller when not on the scaled display.

I understand that when running with this "Apply scaling themselves" option that a single XWayland server is used, which is why applications are downscaled in the first place. I did test this quickly with a non-fractional scale factor and applications looked better, but still not perfect.

In spite of this, I'm wondering if perhaps this is related to KWin in Plasma 5 not using the pretty new Wayland fractional scaling protocol? Since to my understanding for the scaled display, KWin is downscaling from the nearest integer value in order to achieve fractional scaling, as for a long time there was no protocol for fraction scaling on Wayland. Since when moving from the scaled display over to another display we're essentially downscaling *again*, maybe this effect is a side-effect of that? It still happens with integer scaling values I think though, but I only tested briefly.

If this is true, then could this potentially be fixed when Plasma implements the Wayland fractional scaling protocol in KWin in Plasma 6? I have read on other bug reports that implementing this protocol is planned for Plasma 6, but I'm not sure if it's still on the roadmap or if I perhaps misunderstood.

I also understand that this cannot be backported so I am not jabbing anyone who has worked tirelessly on making Plasma Wayland as rock-solid as it is (a visual oddity is very minor in the grand scheme and shows how far Wayland has come!).

Of course, the *real* solution here is for applications to port to Wayland. If the Steam Client ports to Wayland, if Electron Wayland support continues at the brisk pace it's going at, and once Wine (and derivatives like Proton) lands Wayland support with support for fractional scaling, this issue will disappear for a huge amount of use-cases. Since many Qt and GTK apps all support Wayland already, the main way I am impacted by this is with games and Wine applications (particularly tools like ModOrganizer 2).

STEPS TO REPRODUCE
1.  Use two displays, one with fractional scaling and one without (though it may be reproduceable without a fractional scale value, the scaled+no scale display is the main factor here)
2. Set the Legacy (X11) application setting in Display Settings to "Apply scaling themselves"
3. Launch an X11 application which can apply scaling itself, such as:
  - The Steam Client, with the STEAM_FORCE_DESKTOPUI_SCALING value set to the decimal equivalent of your scale factor, ex: 1.5 for 150% scaling, is an accessible example.

OBSERVED RESULT
On Wayland with at least one display with scaling, X11 applications is blurry/blocky on displays without scaling. This is always present but is more noticeable when scaled up.


EXPECTED RESULT
The rendering content of X11 applications should match that of Wayland applications on displays without scaling, and/or the way they look when the "Scaled by the system" option is used in Display settings.


SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Linux Zen Kernel 5.6.7 64bit
KDE Plasma Version: 5.27.8
KDE Frameworks Version: 5.110.0
Qt Version: 5.15.11

ADDITIONAL INFORMATION
- Similar behaviour happens with some parts of KDE, such as notification text very occasionally being blocky until highlighted, and the same issue with text on some settings menu options (though this problem has gradually lessened with updates!)
  - A similar issue is also present on text in the Overview effect, on displays with no scaling, text always appears pixelated.
- Even though I have a suspicion this is a technical limitation with no real immediate solution, I have provided so much background and context not just in the hope of helping get an answer, but in the interest of documenting what behaviour I'm seeing so if others stumble upon this ticket, they can see if they're having the exact same problem and then see what the answer is. I didn't see another issue reporting this problem, so I am hoping if this cannot be resolved, this ticket could help document the problem a little better.
Comment 1 David Edmundson 2023-11-01 12:47:22 UTC
 It's unrelated to being fractional. With apply scaling themselves, we pick one display and use that scale for both screens. If that matches you get native rendering. The other screen will be upscaled or downscaled. 

Mixed DPI on X11 was not ever supported and can't be added.

You can override which scale we use for X11, there's also the workraround of running apps in gamescope to fix the scaling issues.
There's not much else we can do unfortunately. Sorry

>  - A similar issue is also present on text in the Overview effect, on displays with no scaling, text always appears pixelated.

That sounds unrelated, and fixable.
Comment 2 Nate Graham 2023-11-01 18:00:01 UTC
Could we run one XWayland server per screen, in the case where the screens have different scale factors?

Maybe not worth the overhead, though.
Comment 3 Eamonn Rea 2023-11-01 21:46:30 UTC
Sorry if I wasn't clear, I understand that X11 doesn't support mixed DPI. I wasn't referring to applications not scaling, I was referring to how they look visually when downscaled, is there no way to make these applications which are scaled up and then scaled down on non-scaled displays look any better visually?

I am fine with applications which don't support scaling looking too small on unscaled displays, but applications which can be scaled up and moved to non-scaled displays should be filtered better in some way, no? The impact varies from application to application, for example with Steam it's generally ok, but with some other cases like Qt applications, text can be borderline-illegible when not on the display with the given scale factor.

Many applications are now using Wayland, but two massive use-cases are not filled yet: The Steam Client, and games. Games running through Proton are fine because once Wine and then Proton gets Wayland support, this will be fine, but legacy games which may never get this kind of support, will consistently look blocky when downscaled.

My post was not about adding mixed-scale support for X11, which is not feasible and not relevant to KDE specifically. What I was asking for is a way to make the apps which can be scaled up, look better when moved to displays which are not scaled. They match the scale factor just fine but their contents do not look visually appealing.
Comment 4 Eamonn Rea 2023-11-01 21:58:45 UTC
In case I am still not being clear enough, as I am having some trouble knowing if I'm articulating the problem correctly, here's a visual representation of the issue. I hope it serves to show that while the window *sizing* is correct, the window contents look significantly worse when an X11 application is downscaled when the "Apply scaling themselves" option is used.

https://i.postimg.cc/MZLqg6Fk/Screenshot-20231101-215050.png

The example here is with a Qt6 application called ProtonUp-Qt. On the left is the program running using Wayland, running from source. On the right is the Flatpak version of the tool, running with the Wayland socket disabled so it's forced to use X11. The text looks significantly worse when downscaled, more blocky and sometimes even blurry in some programs.

The issue is not specific to ProtonUp-Qt, it happens with any application I can apply scaling to. Heck, even without a scale factor applied, the applications do not simply look like they're running too small on unscaled displays, they are smaller when they can't apply scaling themselves, but they also still look a little bit blocky/blurry.

When both the Wayland and X11 versions of the application are running on the scaled display, aside from some font differences as a result of one running from source and one running on Flatpak, they look virtually indistinguishable even when zooming in: https://i.postimg.cc/4xgdF4Yf/Screenshot-20231101-215645.png

What I'm really hoping to illustrate here is that the window sizing isn't an issue, because applications can scale themselves just fine or have a flag I can set, but that when this flag is set, application *contents* is what looks off. Hope that makes sense!