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 3353

Summary: rpi video driver window mode isn't very useful
Product: SDL Reporter: Logan McNaughton <logan>
Component: videoAssignee: Sam Lantinga <slouken>
Status: ASSIGNED --- QA Contact: Sam Lantinga <slouken>
Severity: minor    
Priority: P2 CC: buzz, chli.hug, ioq3, philipp.wiesemann
Version: 2.0.4   
Hardware: ARM   
OS: Linux   
Attachments: Patch to fix problem
Patch to SDL_hints.h
New rpivideo.c patch with SDL hint
New rpivideo patch with SDL hint
Patch to SDL_hints.h
New rpivideo patch with SDL hint
Update patch

Description Logan McNaughton 2016-05-31 16:10:39 UTC
in RPI_CreateWindow (video/raspberry/SDL_rpivideo.c), it does this:

/* Windows have one size for now */
    window->w = display->desktop_mode.w;
    window->h = display->desktop_mode.h;

It overwrites the SDL window size with the size of the display. Basically window mode is disabled.

I'll give you an example of why this is not helpful:

My rpi runs at a resolution of 640x480. If I run mupen64plus (n64 emulator) with --windowed --resolution 320x240, it just uses 1/4 of the screen, because SDL is overwriting the resolution back to 640x480, and mupen64plus is rendering at 320x240.

I created this patch:

https://github.com/loganmc10/game_launcher/blob/master/sdl_patch.patch

This uses dispmanx to stretch the image. So if your display is 640x480, and you create an SDL Window that is 320x240, it will stretch that 320x240 image to fit 640x480. This is useful. Since the rpi doesn't really support windows, this is more useful than overwriting the window size like it does now.
Comment 1 Logan McNaughton 2016-05-31 16:13:53 UTC
Created attachment 2474 [details]
Patch to fix problem
Comment 2 Simon Hug 2016-06-01 14:23:12 UTC
Why settle for one option if we could have both? The SDL hint system offers a great way to solve this issue.

Shouldn't mupen64plus check if the window size isn't what was requested? SDL makes no guarantees here. The application should have options on how to scale its contents.
Comment 3 Logan McNaughton 2016-06-01 14:53:52 UTC
(In reply to Simon Hug from comment #2)
> Why settle for one option if we could have both? The SDL hint system offers
> a great way to solve this issue.
> 
> Shouldn't mupen64plus check if the window size isn't what was requested? SDL
> makes no guarantees here. The application should have options on how to
> scale its contents.

Even if mupen64plus realized that the window size is wrong, what is it going to do about it? I'm sure mupen64plus could scale the contents, but that requires work from the GPU, this patch accomplishes the scaling at basically no cost to the GPU.

Anyway, I don't know anything about SDL hints, but the way it works right now is not very useful. If someone requests a window, it just makes it full screen and sends it back to the user, at least with this patch they get the resolution they wanted.
Comment 4 Simon Hug 2016-06-01 18:43:26 UTC
Perhaps. But forcing a stretch to fullscreen with whatever filter dispmanx is using might not be useful to someone else. Especially if the aspect ratios don't match.

Have a look at the SDL_hints.h header. These hints can be used to change the behavior of SDL with a change of an environment variable. You can add another one for this case and use SDL_GetHint in the RPI_CreateWindow function to decide if SDL should do it the current or your way.
Comment 5 Logan McNaughton 2016-06-01 19:42:33 UTC
Created attachment 2477 [details]
Patch to SDL_hints.h
Comment 6 Logan McNaughton 2016-06-01 19:43:01 UTC
Created attachment 2478 [details]
New rpivideo.c patch with SDL hint
Comment 7 Logan McNaughton 2016-06-01 19:43:23 UTC
Created attachment 2479 [details]
New rpivideo patch with SDL hint
Comment 8 Logan McNaughton 2016-06-01 19:44:37 UTC
Fair enough, I've added patches for SDL_hints.h and SDL_rpivideo.c to use the hint SDL_RPI_STRETCH_WINDOW.

Tested and working on my Raspberry Pi 3 in both modes.
Comment 9 Simon Hug 2016-06-02 13:01:55 UTC
I tested it as well and noticed that the stretching breaks the position of the software cursor which the SDL Raspberry Pi driver puts on screen. It obviously doesn't know about the scaling.
Comment 10 Logan McNaughton 2016-06-02 14:16:04 UTC
hm ok I don't know about that, I don't use a cursor, I am using a fullscreen OpenGL application controlled by a joypad.
Comment 11 Philipp Wiesemann 2016-06-06 20:58:34 UTC
The hint name should start with "SDL_HINT_" (e.g. SDL_HINT_RPI_STRETCH_WINDOW).
Comment 12 Logan McNaughton 2016-06-06 21:32:45 UTC
Would this patch be accepted if I changed the hint name? I don't own a mouse to test the cursor functionality.
Comment 13 Logan McNaughton 2016-06-07 14:24:13 UTC
Created attachment 2482 [details]
Patch to SDL_hints.h
Comment 14 Logan McNaughton 2016-06-07 14:24:35 UTC
Created attachment 2483 [details]
New rpivideo patch with SDL hint
Comment 15 Philipp Wiesemann 2016-07-02 21:43:27 UTC
The value of the hint should not contain the "SDL_HINT_" (as documented at the top of SDL_hints.h :).

#define SDL_HINT_RPI_STRETCH_WINDOW    "SDL_RPI_STRETCH_WINDOW"
Comment 16 Logan McNaughton 2016-07-07 19:05:06 UTC
Created attachment 2528 [details]
Update patch

This is a more robust version of this patch written by gizmo98 on GitHub. I have attached the patch as pull from GitHub, you can see the discussion that went along with this here:

https://github.com/RetroPie/SDL-mirror/pull/1
Comment 17 Logan McNaughton 2017-02-20 21:33:27 UTC
Is there anything else that needs to be done for this patch to be merged?
Comment 18 Sam Lantinga 2017-02-21 05:30:33 UTC
Out of curiosity, why do you have an aspect ratio hint? It seems like you should always respect the resolution set by the window?
Comment 19 Logan McNaughton 2017-02-21 05:41:16 UTC
I believe it would be to take a 4:3 window and stretch it to 16:9 fullscreen (instead of having black bars on the side)
Comment 20 Sam Lantinga 2017-02-21 06:26:15 UTC
That's already handled by setting the scaling to 2 (stretch to fullscreen)
Comment 21 Jools Wills 2017-02-21 15:03:57 UTC
The aspect ratio hint is useful for fine tuning aspect ratio - eg for emulators  for systems where the original pixels were not quite square etc.

The referenced patch is out of date btw - we also now include

https://github.com/spurious/SDL-mirror/commit/9d9af1f5943bda8fccd4463b6085d45c8325d359

and a c89 fix

https://github.com/RetroPie/SDL-mirror/commit/6c42ad55b293893ac472106248148dc706acf10c
Comment 22 Jools Wills 2017-02-21 15:10:07 UTC
I can provide an updated patch including everything if needed - if not we will just continue to maintain it our own fork - which we need anyway as we need to have this revert https://github.com/spurious/SDL-mirror/commit/b02fe999cc9a04bf3b663327d1a82d0cbfa75817 as ps3 controllers are broken without it  in Emulation station and other sdl2 apps.

(This is mentioned in another ticket - https://bugzilla.libsdl.org/show_bug.cgi?id=3277)
Comment 23 q3dev 2019-08-19 19:55:35 UTC
Hello,

I've been using this patch in my game and it works well.  It's been included in RetroPie for 2+ years now.  Would it be possible to get an updated patch and include this in SDL?  Thanks everyone for working on this.