@@ -35,6 +35,9 @@ static Uint64 frame_time_end = 0;
3535static int monitor_refresh_rate = 60 ;
3636static int vsync_frames_per_emu_frame = 1 ;
3737static int vsync_frame_counter = 0 ;
38+ static int last_vsync_state = -1 ;
39+ static bool multi_monitor_mixed_refresh = false ;
40+ static bool pending_gl_context_recreate = false ;
3841
3942void display_begin_frame (void )
4043{
@@ -107,9 +110,11 @@ bool display_should_run_emu_frame(void)
107110
108111void display_set_vsync (bool enabled)
109112{
113+ bool effective = enabled && !display_is_vsync_forced_off ();
110114 SDL_GL_SetSwapInterval (0 );
111- if (enabled )
115+ if (effective )
112116 SDL_GL_SetSwapInterval (1 );
117+ last_vsync_state = effective ? 1 : 0 ;
113118 display_update_frame_pacing ();
114119}
115120
@@ -140,6 +145,69 @@ void display_update_frame_pacing(void)
140145 Debug (" Monitor refresh rate: %d Hz, vsync frames per emu frame: %d" , monitor_refresh_rate, vsync_frames_per_emu_frame);
141146}
142147
148+ void display_check_mixed_refresh_rates (void )
149+ {
150+ int count = 0 ;
151+ SDL_DisplayID* displays = SDL_GetDisplays (&count);
152+
153+ if (!displays || count <= 1 )
154+ {
155+ if (displays)
156+ SDL_free (displays);
157+ multi_monitor_mixed_refresh = false ;
158+ return ;
159+ }
160+
161+ int first_rate = 0 ;
162+ bool mixed = false ;
163+
164+ for (int i = 0 ; i < count; i++)
165+ {
166+ const SDL_DisplayMode* mode = SDL_GetCurrentDisplayMode (displays[i]);
167+ if (mode && mode->refresh_rate > 0 )
168+ {
169+ int rate = (int )mode->refresh_rate ;
170+ if (first_rate == 0 )
171+ first_rate = rate;
172+ else if (rate != first_rate)
173+ {
174+ mixed = true ;
175+ break ;
176+ }
177+ }
178+ }
179+
180+ SDL_free (displays);
181+
182+ if (mixed != multi_monitor_mixed_refresh)
183+ {
184+ multi_monitor_mixed_refresh = mixed;
185+ if (mixed)
186+ Log (" Multiple monitors with different refresh rates detected" );
187+
188+ if (display_is_vsync_forced_off ())
189+ {
190+ SDL_GL_SetSwapInterval (0 );
191+ last_vsync_state = 0 ;
192+ Debug (" Vsync forced off: multi-viewport with mixed refresh rate monitors" );
193+ }
194+ else if (config_video.sync )
195+ {
196+ display_set_vsync (true );
197+ }
198+ }
199+ }
200+
201+ bool display_is_vsync_forced_off (void )
202+ {
203+ return config_debug.debug && config_debug.multi_viewport && multi_monitor_mixed_refresh;
204+ }
205+
206+ void display_request_gl_context_recreate (void )
207+ {
208+ pending_gl_context_recreate = true ;
209+ }
210+
143211void display_recreate_gl_context (void )
144212{
145213 ogl_renderer_destroy ();
@@ -153,7 +221,7 @@ void display_recreate_gl_context(void)
153221 SDL_GL_MakeCurrent (application_sdl_window, display_gl_context);
154222 SDL_GL_DestroyContext (old_context);
155223
156- bool enable_vsync = config_video.sync ;
224+ bool enable_vsync = config_video.sync && ! display_is_vsync_forced_off () ;
157225 SDL_GL_SetSwapInterval (0 );
158226 if (enable_vsync)
159227 SDL_GL_SetSwapInterval (1 );
0 commit comments