ios: report view pixel size + contentScaleFactor as dpi_scale#649
Merged
Conversation
draw_in_rect reported UIScreen.bounds * UIScreen.scale as the rendered size. On real iPhone / iPad that matches the view's framebuffer (the view fills the screen), but on iOS-on-Mac the view can be a window smaller than the Mac display — so screen_width / screen_height overstated the real rendering surface and apps drew at the wrong scale in windowed mode. Switch to the view's own bounds * contentScaleFactor, which is correct in both cases. Also populate native_display().dpi_scale with the view's contentScaleFactor — upstream left it at the 1.0 default on iOS, which breaks higher-level APIs (e.g. macroquad's screen_width() divides by dpi_scale to return density-independent units). With this change, iOS joins macOS in reporting a real content scale, and the same dp-positioned UI lands at matching screen positions across both platforms.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two related changes to make iOS's reported metrics match the actual rendering surface:
Populate
dpi_scalefromcontentScaleFactor. Upstream leftnative_display().dpi_scaleat1.0on iOS. macroquad'sscreen_width()/mouse_position()divide bydpi_scaleto return density-independent units — so without this, iOS callers got pixel values where macOS got points, and dp-positioned UI landed at the wrong place. Now iOS joins macOS in reporting a real content scale.Measure the view, not
UIScreen.draw_in_rectreportedUIScreen.bounds × UIScreen.scaleas the rendered size. Switched topayload.view.bounds × contentScaleFactor, which is more direct (the view IS the rendering surface) and avoids the globalUIScreen.mainScreencall that has gotchas with multi-window configurations.Both halves go together: the natural scale to multiply the view's
boundsby is the view's owncontentScaleFactor, and once we're reading it for that, exposing it asdpi_scaleis essentially free.The
high_dpitoggle is no longer consulted here — the view'scontentScaleFactoris already set toUIScreen.scalewhenhigh_dpi=trueand1.0whenhigh_dpi=false(seecreate_opengl_view), so the resultingscreen_size/dpi_scalematch upstream's high_dpi-aware branches on real iPhone / iPad.What this fixes
In a downstream macroquad app, iOS-on-Mac windowed mode was rendering at ~50 % of the window size. The fix is the
dpi_scalehalf — macroquad'sscreen_width()was returning physical-pixel counts where the macOS desktop returned points, so the rest of the app drew at half the expected scale.(Side note on the bounds half: iOS-on-Mac windowed reports the same
view.boundsas fullscreen — the window chrome clips a fixed-size view rather than shrinking it. So the change fromUIScreen.boundsis more about avoiding theUIScreen.mainScreenglobal and being more direct than about fixing the windowed-rendering bug per se.)Test plan
contentScaleFactor = 3):screen_width()reports 402 dp instead of 1206 px.