Incorrect canvas render size when rendering with framebuffers on a HiDPI screen #109
Description
I'm working on porting a C++ program that uses SDL2 to Emscripten. I have gotten most things to work, but I'm having trouble making HiDPI support work. This is what the program looks like on desktop with HiDPI:
This is the exact same code running in an Emscripten environment using this SDL2 port, on the same HiDPI screen:
Notice how the entire screen is rendered only in the top left corner of the screen, and that everything is 2x smaller. If I change the code to render the screen at 2x resolution, it looks like this:
The text is at the correct size, but only a quarter of the screen is showing up. If I make the created window 2x larger, it makes the canvas much larger than the border:
For reference, here's what it looks like without HiDPI enabled:
I looked at the source a bit and found that:
- The size of the image data is 4x smaller than it would be with the full size (in this case, it's 620x350 pixels long instead of 1240x700 pixels long). This could be fixed by applying
data->pixel_ratio
to the width and height, but I don't believe this is a portable solution since the normal SDL behavior doesn't require the application to do 2x rendering itself. (?) - The actual image data is not scaled up to 2x size anywhere in
Emscripten_UpdateWindowFramebuffer
, which under normal circumstances I would expect, but due to the way SDL2 seems to handle HiDPI (at least from my experience) the image should be integer scaled up to the correct resolution.
Note that I don't really understand how HiDPI works with normal SDL (I just messed with code until I got a result), so I may be wrong on how to handle this; but I know for sure that more than just a quarter of the canvas should be accessible with HiDPI.