ui/sdl2: Allow high-dpi
PATCH 1/1 ui/sdl2: Allow high-dpi
Add the SDL_WINDOW_ALLOW_HIGHDPI flag when creating a window and get the drawable size instead of the window size when setting up the framebuffer and the viewport.
--- ui/sdl2-gl.c | 4 ++-- ui/sdl2.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
ui/sdl2-gl.c +2 -2
@@ -53,7 +53,7 @@ static void sdl2_gl_render_surface(struct sdl2_console *scon)SDL_GL_MakeCurrent (scon->real_window, scon->winctx);sdl2_set_scanout_mode (scon, false); -SDL_GetWindowSize (scon->real_window, &ww, &wh); +SDL_GL_GetDrawableSize (scon->real_window, &ww, &wh);surface_gl_setup_viewport (scon->gls, scon->surface, ww, wh);surface_gl_render_texture (scon->gls, scon->surface);
@@ -239,7 +239,7 @@ void sdl2_gl_scanout_flush(DisplayChangeListener *dcl,SDL_GL_MakeCurrent (scon->real_window, scon->winctx); -SDL_GetWindowSize (scon->real_window, &ww, &wh); +SDL_GL_GetDrawableSize (scon->real_window, &ww, &wh);egl_fb_setup_default (&scon->win_fb, ww, wh);egl_fb_blit (&scon->win_fb, &scon->guest_fb, !scon->y0_top);
ui/sdl2.c +1 -1
@@ -95,7 +95,7 @@ void sdl2_window_create(struct sdl2_console *scon) }#ifdef CONFIG_OPENGL if (scon->opengl) { - flags |=SDL_WINDOW_OPENGL ; + flags |=SDL_WINDOW_OPENGL |SDL_WINDOW_ALLOW_HIGHDPI ; }#endif
Signature · 1 line
2.40.0
Hi Antonio
Quoted 5 lines · Antonio Caggiano
Add the
SDL_WINDOW_ALLOW_HIGHDPIflag when creating a window and get the drawable size instead of the window size when setting up the framebuffer and the viewport.
What does this actually change?
What about non-gl display, Mouse motion, and display resize?
thanks
Quoted 45 lines
--- ui/sdl2-gl.c | 4 ++-- ui/sdl2.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)ui/sdl2-gl.c +1
-1@@ -53,7 +53,7 @@ static void sdl2_gl_render_surface(struct sdl2_console *scon)SDL_GL_MakeCurrent (scon->real_window, scon->winctx);sdl2_set_scanout_mode (scon, false); -SDL_GetWindowSize (scon->real_window, &ww, &wh); +SDL_GL_GetDrawableSize (scon->real_window, &ww, &wh);surface_gl_setup_viewport (scon->gls, scon->surface, ww, wh);surface_gl_render_texture(scon->gls, scon->surface);ui/sdl2-gl.c +1
-1@@ -239,7 +239,7 @@ void sdl2_gl_scanout_flush(DisplayChangeListener *dcl,SDL_GL_MakeCurrent (scon->real_window, scon->winctx); -SDL_GetWindowSize (scon->real_window, &ww, &wh); +SDL_GL_GetDrawableSize (scon->real_window, &ww, &wh);egl_fb_setup_default (&scon->win_fb, ww, wh);egl_fb_blit (&scon->win_fb, &scon->guest_fb, !scon->y0_top);ui/sdl2.c +1
-2@@ -95,7 +95,7 @@ void sdl2_window_create(struct sdl2_console *scon) }#ifdef CONFIG_OPENGL if (scon->opengl) { - flags |=SDL_WINDOW_OPENGL ; + flags |=SDL_WINDOW_OPENGL |SDL_WINDOW_ALLOW_HIGHDPI ; }#endif --2.40.0
Hi Marc-André,
Quoted 11 lines · Marc-André Lureau
Hi Antonio
Quoted 5 lines · Antonio Caggiano
Add the
SDL_WINDOW_ALLOW_HIGHDPIflag when creating a window and get the drawable size instead of the window size when setting up the framebuffer and the viewport.What does this actually change?
The sdl2-gl backend does not work properly on high-DPI windows. [0]
My understanding is that by allowing high-DPI, SDL creates a framebuffer with the right size in pixels which might be different than the size of the window. [1] I believe we just need to use the framebuffer size for GL viewport and texture, by retrieving it with SDL_GL_GetDrawableSize.
Quoted 1 line
What about non-gl display, Mouse motion, and display resize?
From what I can see by testing the SDL2 renderer, it seems to handle all of this transparently, so there is nothing we need to do in sdl2-2d.
Same for mouse motion, which I believe is using window "screen coordinates".
Display resize is a bit weird for a bunch of frames, but then it fixes itself.
[0] https://user-images.githubusercontent.com/6058008/244368628-329241dc-267d-452f-b8ce-816ae1623131.png
[1] https://wiki.libsdl.org/SDL2/SDL_GetWindowSize#remarks
Quoted 45 lines
thanks
Signed-off-by Antonio Caggiano <[email protected]>Quoted 41 lines
--- ui/sdl2-gl.c | 4 ++-- ui/sdl2.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)ui/sdl2-gl.c +1
-1@@ -53,7 +53,7 @@ static void sdl2_gl_render_surface(struct sdl2_console *scon)SDL_GL_MakeCurrent (scon->real_window, scon->winctx);sdl2_set_scanout_mode (scon, false); -SDL_GetWindowSize (scon->real_window, &ww, &wh); +SDL_GL_GetDrawableSize (scon->real_window, &ww, &wh);surface_gl_setup_viewport (scon->gls, scon->surface, ww, wh);surface_gl_render_texture(scon->gls, scon->surface);ui/sdl2-gl.c +1
-1@@ -239,7 +239,7 @@ void sdl2_gl_scanout_flush(DisplayChangeListener *dcl,SDL_GL_MakeCurrent (scon->real_window, scon->winctx); -SDL_GetWindowSize (scon->real_window, &ww, &wh); +SDL_GL_GetDrawableSize (scon->real_window, &ww, &wh);egl_fb_setup_default (&scon->win_fb, ww, wh);egl_fb_blit (&scon->win_fb, &scon->guest_fb, !scon->y0_top);ui/sdl2.c +1
-1@@ -95,7 +95,7 @@ void sdl2_window_create(struct sdl2_console *scon) }#ifdef CONFIG_OPENGL if (scon->opengl) { - flags |=SDL_WINDOW_OPENGL ; + flags |=SDL_WINDOW_OPENGL |SDL_WINDOW_ALLOW_HIGHDPI ; }#endif
Quoted 5 lines
Quoted 4 lines
--
2.40.0
Cheers,
Antonio
Hi Antonio
Quoted 31 lines · Antonio Caggiano
Hi Marc-André,
Quoted 3 lines · Marc-André Lureau
Hi Antonio
On Wed, Jun 7, 2023 at 1:05 PM Antonio Caggiano <
Quoted 8 lines
Quoted 5 lines · wrote:
Add the
SDL_WINDOW_ALLOW_HIGHDPIflag when creating a window and get the drawable size instead of the window size when setting up the framebuffer and the viewport.What does this actually change?
The sdl2-gl backend does not work properly on high-DPI windows. [0] My understanding is that by allowing high-DPI, SDL creates a framebuffer with the right size in pixels which might be different than the size of the window. [1]
I believe we just need to use the framebuffer size for GL viewport and texture, by retrieving it withSDL_GL_GetDrawableSize.Quoted 1 line
What about non-gl display, Mouse motion, and display resize?
From what I can see by testing the SDL2 renderer, it seems to handle
all of this transparently, so there is nothing we need to do in sdl2-2d.Same for mouse motion, which I believe is using window "screen coordinates".
Quoted 6 lines
Display resize is a bit weird for a bunch of frames, but then it fixes itself.
[0]
https://user-images.githubusercontent.com/6058008/244368628-329241dc-267d-452f-b8ce-816ae1623131.png
I am using SDL2-2.26.3-1.fc38.x86_64 on wayland, and it doesn't have this issue.
Your patch doesn't seem to change the behaviour.
Maybe there is something to investigate at SDL level instead.
btw, "allow hi-dpi" isn't a good description imho, since the guest still doesn't receive real physical hi-dpi details of the client, and remains scaled-up.
Quoted 59 lines
[1] https://wiki.libsdl.org/SDL2/SDL_GetWindowSize#remarks
Quoted 18 lines
thanks
Signed-off-by Antonio Caggiano <[email protected]>Quoted 14 lines
--- ui/sdl2-gl.c | 4 ++-- ui/sdl2.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)ui/sdl2-gl.c +0
-0@@ -53,7 +53,7 @@ static void sdl2_gl_render_surface(struct sdl2_console *scon)SDL_GL_MakeCurrent (scon->real_window, scon->winctx);sdl2_set_scanout_mode (scon, false);Quoted 6 lines
ui/sdl2-gl.c void sdl2_gl_scanout_flush(DisplayChangeListener
Quoted 6 lines
ui/sdl2-gl.c +1
-1-SDL_GetWindowSize (scon->real_window, &ww, &wh); +SDL_GL_GetDrawableSize (scon->real_window, &ww, &wh);surface_gl_setup_viewport (scon->gls, scon->surface, ww, wh);surface_gl_render_texture(scon->gls, scon->surface);ui/sdl2-gl.c +0
-0@@ -239,7 +239,7 @@ void sdl2_gl_scanout_flush(DisplayChangeListener*dcl,
Quoted 21 lines
Quoted 21 lines
ui/sdl2-gl.c +1
-1SDL_GL_MakeCurrent (scon->real_window, scon->winctx); -SDL_GetWindowSize (scon->real_window, &ww, &wh); +SDL_GL_GetDrawableSize (scon->real_window, &ww, &wh);egl_fb_setup_default (&scon->win_fb, ww, wh);egl_fb_blit (&scon->win_fb, &scon->guest_fb, !scon->y0_top);ui/sdl2.c +1
-1@@ -95,7 +95,7 @@ void sdl2_window_create(struct sdl2_console *scon) }#ifdef CONFIG_OPENGL if (scon->opengl) { - flags |=SDL_WINDOW_OPENGL ; + flags |=SDL_WINDOW_OPENGL |SDL_WINDOW_ALLOW_HIGHDPI ; }#endif Quoted 5 lines
Quoted 4 lines
--
2.40.0Cheers,
Antonio
Signature · 1 line
Marc-André Lureau