We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1394

Summary: Fixes for SDL's handling of "Retina" display on iOS devices
Product: SDL Reporter: Tim Angus <tim>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2    
Version: HG 2.0   
Hardware: iPhone/iPod touch   
OS: iOS (All)   
Attachments: Convert usage of UIKit coordinates to pixel coordinates
Support retina display modes, but retain non-retina display modes
Fix for double free when quitting on iOS

Description Tim Angus 2012-01-23 08:22:46 UTC
Created attachment 799 [details]
Convert usage of UIKit coordinates to pixel coordinates

From the patch:

// When dealing with UIKit all coordinates are specified in terms of
// what Apple refers to as points. On earlier devices without the
// so called "Retina" display, there is a one to one mapping between
// points and pixels. In other cases [UIScreen scale] indicates the
// relationship between points and pixels. Since SDL has no notion
// of points, we must compensate in all cases where dealing with such
// units.
Comment 1 Tim Angus 2012-01-25 07:05:44 UTC
Created attachment 804 [details]
Support retina display modes, but retain non-retina display modes

Alright, this new version implements reporting of the "non-scaled" display on Retina devices, i.e. 320x480 as well as 640x960. If the former is selected (using SDL_SetWindowDisplayMode + SDL_SetWindowFullscreen) a scale of 1.0 is used instead of [UIScreen scale].

The only slight gotcha that I've come across is the fact that calling SDL_SetWindowFullscreen unavoidably disables the iOS status bar. I've tried to disconnect the two things but this implies that a window is both fullscreen and its dimensions are not the same as the display mode's. For example, the display mode might be 320x480, but with the status bar enabled the window size will be 320x460. In itself this is fine, but this breaks the wide spread assumption that the two sets of dimensions are identical and with it various other parts of SDL. So I've left that alone for now. It's not really a big deal though, since I imagine most users will want the status bar disabled anyway.
Comment 2 Sam Lantinga 2012-01-28 07:34:27 UTC
Looks good, thanks!
http://hg.libsdl.org/SDL/rev/ed2cf4669e55
Comment 3 Rodrigo Cardoso 2012-01-31 07:31:26 UTC
Thanks for the fix, Tim!
I was looking to try fix this, if nobody get their hands dirty first :)
Comment 4 Tim Angus 2012-01-31 07:33:13 UTC
You're welcome :).
Comment 5 Tim Angus 2012-02-20 09:40:35 UTC
Created attachment 826 [details]
Fix for double free when quitting on iOS

It seems I introduced a bug with the original fix for this bug. The new patch fixes it.

As alluded to in the email thread "SDL2 error on iOS (doublefree)", I believe the original cause of this bug is confusion over the purpose of SDL_VideoDisplay::current_mode. It looks as though it is a weak reference to another mode, albeit with value semantics. The iOS port treated it as a strong reference however and claimed ownership, which is why things blew up. All the patch really does it to stop treating current_mode as a strong reference.

To prevent this happening again it might be an idea to change current_mode to be a pointer type rather than a value. This would certainly make its semantics much more obvious. Failing that, a comment in the struct indicating its weak reference properties might be wise.
Comment 6 Tim Angus 2012-02-20 09:41:04 UTC
Reopening.
Comment 7 Sam Lantinga 2012-02-20 17:47:06 UTC
Patch applied, thanks!
http://hg.libsdl.org/SDL/rev/4c25a7b9e819