Skip to content
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

Preserve game UI scale on small screen sizes #31083

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

frenzibyte
Copy link
Member

@frenzibyte frenzibyte commented Dec 11, 2024

As it turns out, SDL provides sane window size dimensions for iPhones, e.g. 852x393 on iPhone 16. We can use that information to construct an algorithm at a ScalingContainer level which ensures the game does not descale on small window sizes (inspired by previous discussions on the matter, mainly #21335 (comment)).

Preview on mobile:

CleanShot 2024-12-11 at 09 12 01

Copy link

@HOWZ1T HOWZ1T left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A easy to digest PR 🙂
The fix to scaling would be great for small mobile devices! 🚀

The tests failing should be addressed and the hard-coded base_target_draw_size would ideally be configurable and not hard-coded at this level. However, depending on why this is, it may be more or less feasible.

osu.Game/Graphics/Containers/ScalingContainer.cs Outdated Show resolved Hide resolved
osu.Game/Graphics/Containers/ScalingContainer.cs Outdated Show resolved Hide resolved
@Joehuu Joehuu self-requested a review December 11, 2024 20:08
Copy link
Member

@Joehuu Joehuu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Android seems to be giving resolutions scaled by DPI (also tested/seen on emulator):
On Pixel 6a:
Screenshot 2024-12-11 at 12 43 27 PMScreenshot 2024-12-11 at 12 45 26 PM

@frenzibyte
Copy link
Member Author

Well that shows that this cannot fix the Android issue without SDL providing a pre-scaled window resolution for host.Window.Size. According to Android, they define this as density-independent pixels (dp) and pixels are converted to dp by the inverse of the factor of dpi / 160. The Pixel 6a above has a scaling factor of ~2.68125 (429 / 160), converting the screen resolution mentioned above to dp form yields 895x403, roughly equal to the window size on an iPhone 16. cc @Susko3 in case interested, host.Window.Size is expected to return screen size in density-independent pixels but it returns it post-scale (i.e. host.Window.Scale is incorrectly equal to 1 probably).

@Susko3
Copy link
Member

Susko3 commented Dec 12, 2024

Window.Scale is using (the equivalent of) https://wiki.libsdl.org/SDL3/SDL_GetWindowPixelDensity, this is always 1.0f on android and windows, while differing on apple platforms. The pixel size is just an internal scaling factor when converting from physical pixels to "desktop coordinate space" positions.

This PR should actually be using https://wiki.libsdl.org/SDL3/SDL_GetWindowDisplayScale, which reports correct values on windows (haven't yet tested android): 200% display scale will yield 2.0f.

Could you update your code to use Window.ClientSize, scaling it by Window.Scale? This way, it can be easily updated to use SDL display scale once we implement this in framework (probably as IWindow.DisplayScale).

@frenzibyte
Copy link
Member Author

I would hope we use the seemingly new API you mentioned directly on the Scale property inside the window class, and Size would reflect on that. Is that incorrect approach? Does SDL not include the pixel density in that API?

@Susko3
Copy link
Member

Susko3 commented Dec 12, 2024

I would hope we use the seemingly new API you mentioned directly on the Scale property inside the window class, and Size would reflect on that. Is that incorrect approach?

That would break most existing usages of Scale.

Does SDL not include the pixel density in that API?

Display scale and pixel density are orthogonal concepts. Depending on the context, it makes sense to apply one or the other.

@frenzibyte
Copy link
Member Author

Looks like Android does indeed return the pixel density through the API you suggested: https://github.com/libsdl-org/SDL/blob/6cc9ce183d904489bf8e33e26b91d6012667e1b0/src/video/android/SDL_androidvideo.c#L181

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UI scale on iOS is too small by default
5 participants