Skip to content

fix(window, input): enable HiDPI rendering and align Android density and coordinates - #247

Open
VIGO-VI wants to merge 1 commit into
komaruworld:mainfrom
VIGO-VI:vigo/hidpi-scaling
Open

VIGO-VI wants to merge 1 commit into
komaruworld:mainfrom
VIGO-VI:vigo/hidpi-scaling

Conversation

@VIGO-VI

@VIGO-VI VIGO-VI commented Dec 4, 2026 •

Copy link
Copy Markdown

Enables HiDPI rendering by default and aligns Android display density and input/text-overlay coordinate transforms with the physical surface resolution.

Summary

  • Enable HiDPI by default: Set window.high_dpi (RuntimeConfig, shipped example config, and WindowOptions::high_pixel_density) to true so SDL creates windows with SDL_WINDOW_HIGH_PIXEL_DENSITY. window.high_dpi: false remains available as an opt-out.
  • Derive density from surface pixel ratio: Compute dpi_scale / density_scale from pixel_width / logical_width in window.cc, sdl_event_converter.cc, and window_text_input_owner.cc. Wayland HiDPI surfaces report their actual pixel density (for example 2.0 at 2x), while X11 and high_dpi: false stay at 1.0.
  • Propagate density before engine init: Export MOCKTAIL_DISPLAY_SCALE_INTERNAL when the window initializes and use it to populate DisplayMetrics (density, scaledDensity, densityDpi, xdpi, ydpi), Configuration (densityDpi, screenWidthDp, screenHeightDp, smallestScreenWidthDp), NativeHelper, InitParams, PlatformParams (densityDpi, viewportWidthMm, viewportHeightMm, dpiScale), StartGameParams, and AConfiguration_getScreenWidthDp/AConfiguration_getScreenHeightDp.
  • Align pointer and TextBox coordinates: Update SurfaceCoordinateTransform and RobloxTextOverlayViewport to map between SDL logical window coordinates and Roblox's physical surface pixel space (pixel_width / logical_width) instead of dividing by density_scale.

Measured

Tested on Wayland (direct-vulkan) at both 3840x2160 scale 2 and a virtual kwin_wayland 2880x1620 output at fractional scale 1.5:

Surface Vulkan swapchain Reported density
Before (MOCKTAIL_WIN_HIGH_DPI=0, 4K 2x) 1920x1080 1920x1080 1.0
After (MOCKTAIL_WIN_HIGH_DPI=1, 4K 2x) 3840x2160 3840x2160 2.0 (1920x1080 dp)
After (MOCKTAIL_WIN_HIGH_DPI=1, 1620p 1.5x) 2880x1620 2880x1620 1.5 (1920x1080 dp)

1:1 crops of the Roblox logo:

Before (MOCKTAIL_WIN_HIGH_DPI=0, 3840x2160 output at scale 2):

before

After (MOCKTAIL_WIN_HIGH_DPI=1, 3840x2160 output at scale 2):

after

After (MOCKTAIL_WIN_HIGH_DPI=1, virtual kwin_wayland 2880x1620 output at fractional scale 1.5):

after-2880x1620-1.5x

  • UI proportions and the six-column home layout are unchanged at 2x scale.
  • Interactive pointer clicks, hovering, and text input land accurately on UI elements.

Testing

  • cmake --build build -j16 --target roblox_input_router_test mocktail
  • ctest --test-dir build --output-on-failure -R "RuntimeConfig|RobloxInputRouter|SurfaceCoordinateTransform|RobloxTextDisplayState|WindowCreationPolicy|WindowTextInputOwner" (131/131 passed)
  • git diff --check (clean)
  • Live Wayland direct-vulkan launch verified interactively at 3840x2160 scale 2.

…and coordinates

Wayland windows previously defaulted `window.high_dpi` to false, so the
compositor upscaled a logical-size framebuffer. Android `DisplayMetrics`,
`Configuration`, `InitParams`, `PlatformParams`, and `AConfiguration` also
hardcoded density 1.0 (160 dpi) and passed physical pixel sizes as dp,
while `SurfaceCoordinateTransform` and `RobloxTextOverlayViewport`
divided pointer and TextBox coordinates by `density_scale`.

- Default `window.high_dpi` and `WindowOptions::high_pixel_density` to true
  while keeping `window.high_dpi: false` as an opt-out.
- Derive `dpi_scale` / `density_scale` from `pixel_width / logical_width`
  so Wayland HiDPI uses the surface pixel density while X11 and
  `high_dpi: false` stay at 1.0.
- Propagate the measured surface scale into `DisplayMetrics`, `Configuration`,
  `NativeHelper`, `InitParams`, `PlatformParams`, `StartGameParams`, and
  `AConfiguration_getScreenWidthDp`/`HeightDp` before engine initialization.
- Map `SurfaceCoordinateTransform` and `RobloxTextOverlayViewport` between
  SDL logical coordinates and physical surface pixels without dividing by
  `density_scale`.

Verified on 3840x2160 scale 2 (Wayland, direct-vulkan): framebuffer and
Vulkan swapchain moved from 1920x1080 (density 1) to 3840x2160 (density 2)
with unchanged six-column UI layout, and 131/131 targeted unit tests pass.

Co-authored-by: theGreatGreenstar <145512144+thegreatGreenstar@users.noreply.github.com>
@thegreatGreenstar

thegreatGreenstar commented Dec 4, 2026 •

Copy link
Copy Markdown

While MAYBE HiDPI support off by default would make sense in say... 2021, it's 2026 and 1440p and even 4k are FAR more accessible and widely used, as well as more nonstandard DPI on laptops. Due to this, HiDPI should be the default and work out of the box. There is no excuse to not support it.
as Wayland docs say "It is intended that you pick the same buffer scale as the scale of the output that the surface is displayed on. This means the compositor can avoid scaling when rendering the surface on that output."
Rendering at 1x on a scaled output forces compositor upscaling and blurs every frame.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants