@@ -29,6 +29,8 @@ class Display::Impl {
29
29
uint32_t disp_wnd_id = 0 ;
30
30
SDL_Window* display_wnd = 0 ;
31
31
SDL_Renderer* renderer = 0 ;
32
+ double renderer_scale_x; // scaling factor from guest OS to host OS
33
+ double renderer_scale_y;
32
34
SDL_Texture* disp_texture = 0 ;
33
35
SDL_Texture* cursor_texture = 0 ;
34
36
SDL_Rect cursor_rect; // destination rectangle for cursor drawing
@@ -61,7 +63,7 @@ bool Display::configure(int width, int height) {
61
63
SDL_WINDOWPOS_UNDEFINED,
62
64
SDL_WINDOWPOS_UNDEFINED,
63
65
width, height,
64
- SDL_WINDOW_OPENGL
66
+ SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI
65
67
);
66
68
67
69
impl->disp_wnd_id = SDL_GetWindowID (impl->display_wnd );
@@ -72,6 +74,11 @@ bool Display::configure(int width, int height) {
72
74
if (impl->renderer == NULL )
73
75
ABORT_F (" Display: SDL_CreateRenderer failed with %s" , SDL_GetError ());
74
76
77
+ int drawable_width, drawable_height;
78
+ SDL_GetRendererOutputSize (impl->renderer , &drawable_width, &drawable_height);
79
+ impl->renderer_scale_x = static_cast <double >(drawable_width) / width;
80
+ impl->renderer_scale_y = static_cast <float >(drawable_height) / height;
81
+
75
82
is_initialization = true ;
76
83
} else { // resize display window
77
84
SDL_SetWindowSize (impl->display_wnd , width, height);
@@ -133,8 +140,8 @@ void Display::update(std::function<void(uint8_t *dst_buf, int dst_pitch)> conver
133
140
134
141
// draw HW cursor if enabled
135
142
if (draw_hw_cursor) {
136
- impl->cursor_rect .x = cursor_x;
137
- impl->cursor_rect .y = cursor_y;
143
+ impl->cursor_rect .x = cursor_x * impl-> renderer_scale_x ;
144
+ impl->cursor_rect .y = cursor_y * impl-> renderer_scale_y ;
138
145
SDL_RenderCopy (impl->renderer , impl->cursor_texture , NULL , &impl->cursor_rect );
139
146
}
140
147
@@ -170,6 +177,6 @@ void Display::setup_hw_cursor(std::function<void(uint8_t *dst_buf, int dst_pitch
170
177
171
178
impl->cursor_rect .x = 0 ;
172
179
impl->cursor_rect .y = 0 ;
173
- impl->cursor_rect .w = cursor_width;
174
- impl->cursor_rect .h = cursor_height;
180
+ impl->cursor_rect .w = cursor_width * impl-> renderer_scale_x ;
181
+ impl->cursor_rect .h = cursor_height * impl-> renderer_scale_y ;
175
182
}
0 commit comments