From 2497ac45841803590fec20a64339381abeea91bf Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 8 Mar 2020 18:36:07 +0100 Subject: [PATCH] (video_crt_switch.c) Move static global variables to struct --- gfx/video_crt_switch.c | 130 +++++++++++++++++++++++------------------ 1 file changed, 72 insertions(+), 58 deletions(-) diff --git a/gfx/video_crt_switch.c b/gfx/video_crt_switch.c index af3a9e78d0..a253c710c2 100644 --- a/gfx/video_crt_switch.c +++ b/gfx/video_crt_switch.c @@ -33,22 +33,28 @@ static void crt_rpi_switch(int width, int height, float hz, int xoffset); #endif -static unsigned ra_core_width = 0; -static unsigned ra_core_height = 0; -static unsigned ra_tmp_width = 0; -static unsigned ra_tmp_height = 0; -static unsigned ra_set_core_hz = 0; -static int crt_center_adjust = 0; -static int crt_tmp_center_adjust = 0; -static double p_clock = 0; +typedef struct videocrt_switch +{ + int center_adjust; + int tmp_center_adjust; + unsigned ra_core_width; + unsigned ra_core_height; + unsigned ra_tmp_width; + unsigned ra_tmp_height; + unsigned ra_set_core_hz; + unsigned index; + + float ra_core_hz; + float ra_tmp_core_hz; + float fly_aspect; + + double p_clock; +} videocrt_switch_t; + +static videocrt_switch_t crt_switch_st; static bool first_run = true; -static float ra_tmp_core_hz = 0.0f; -static float fly_aspect = 0.0f; -static float ra_core_hz = 0.0f; -static unsigned crt_index = 0; - static void crt_check_first_run(void) { if (!first_run) @@ -59,48 +65,56 @@ static void crt_check_first_run(void) static void switch_crt_hz(void) { - if (ra_core_hz == ra_tmp_core_hz) + float ra_core_hz = crt_switch_st.ra_core_hz; + + if (ra_core_hz == crt_switch_st.ra_tmp_core_hz) return; + /* set hz float to an int for windows switching */ if (ra_core_hz < 100) { if (ra_core_hz < 53) - ra_set_core_hz = 50; + crt_switch_st.ra_set_core_hz = 50; if (ra_core_hz >= 53 && ra_core_hz < 57) - ra_set_core_hz = 55; + crt_switch_st.ra_set_core_hz = 55; if (ra_core_hz >= 57) - ra_set_core_hz = 60; + crt_switch_st.ra_set_core_hz = 60; } if (ra_core_hz > 100) { if (ra_core_hz < 106) - ra_set_core_hz = 120; + crt_switch_st.ra_set_core_hz = 120; if (ra_core_hz >= 106 && ra_core_hz < 114) - ra_set_core_hz = 110; + crt_switch_st.ra_set_core_hz = 110; if (ra_core_hz >= 114) - ra_set_core_hz = 120; + crt_switch_st.ra_set_core_hz = 120; } - video_monitor_set_refresh_rate(ra_set_core_hz); + video_monitor_set_refresh_rate(crt_switch_st.ra_set_core_hz); - ra_tmp_core_hz = ra_core_hz; + crt_switch_st.ra_tmp_core_hz = ra_core_hz; } void crt_aspect_ratio_switch(unsigned width, unsigned height) { /* send aspect float to videeo_driver */ - fly_aspect = (float)width / height; - video_driver_set_aspect_ratio_value((float)fly_aspect); + crt_switch_st.fly_aspect = (float)width / height; + video_driver_set_aspect_ratio_value((float)crt_switch_st.fly_aspect); } static void switch_res_crt(unsigned width, unsigned height) { video_display_server_set_resolution(width, height, - ra_set_core_hz, ra_core_hz, crt_center_adjust, crt_index, crt_center_adjust); + crt_switch_st.ra_set_core_hz, + crt_switch_st.ra_core_hz, + crt_switch_st.center_adjust, + crt_switch_st.index, + crt_switch_st.center_adjust); #if defined(HAVE_VIDEOCORE) - crt_rpi_switch(width, height, ra_core_hz, crt_center_adjust); - video_monitor_set_refresh_rate(ra_core_hz); + crt_rpi_switch(width, height, crt_switch_st.ra_core_hz, + crt_switch_st.center_adjust); + video_monitor_set_refresh_rate(crt_switch_st.ra_core_hz); crt_switch_driver_reinit(); #endif video_driver_apply_state_changes(); @@ -136,7 +150,7 @@ static void crt_screen_setup_aspect(unsigned width, unsigned height) if (height > 200) crt_aspect_ratio_switch(width, height); - if (height == 144 && ra_set_core_hz == 50) + if (height == 144 && crt_switch_st.ra_set_core_hz == 50) { height = 288; crt_aspect_ratio_switch(width, height); @@ -160,13 +174,13 @@ static void crt_screen_setup_aspect(unsigned width, unsigned height) height = 254; } - if (height == 528 && ra_set_core_hz == 60) + if (height == 528 && crt_switch_st.ra_set_core_hz == 60) { crt_aspect_ratio_switch(width, height); height = 480; } - if (height >= 240 && height < 255 && ra_set_core_hz == 55) + if (height >= 240 && height < 255 && crt_switch_st.ra_set_core_hz == 55) { crt_aspect_ratio_switch(width, height); height = 254; @@ -183,47 +197,49 @@ void crt_switch_res_core(unsigned width, unsigned height, * video_driver_monitor_adjust_system_rates() */ if (width == 4) { - width = 320; + width = 320; height = 240; } - ra_core_height = height; - ra_core_hz = hz; + crt_switch_st.ra_core_height = height; + crt_switch_st.ra_core_hz = hz; if (dynamic) - ra_core_width = crt_compute_dynamic_width(width); + crt_switch_st.ra_core_width = crt_compute_dynamic_width(width); else - ra_core_width = width; + crt_switch_st.ra_core_width = width; - crt_center_adjust = crt_switch_center_adjust; - crt_index = monitor_index; + crt_switch_st.center_adjust = crt_switch_center_adjust; + crt_switch_st.index = monitor_index; if (crt_mode == 2) { if (hz > 53) - ra_core_hz = hz * 2; + crt_switch_st.ra_core_hz = hz * 2; if (hz <= 53) - ra_core_hz = 120.0f; + crt_switch_st.ra_core_hz = 120.0f; } crt_check_first_run(); /* Detect resolution change and switch */ if ( - (ra_tmp_height != ra_core_height) || - (ra_core_width != ra_tmp_width) || (crt_center_adjust != crt_tmp_center_adjust) + (crt_switch_st.ra_tmp_height != crt_switch_st.ra_core_height) || + (crt_switch_st.ra_core_width != crt_switch_st.ra_tmp_width) || + (crt_switch_st.center_adjust != crt_switch_st.tmp_center_adjust) ) - crt_screen_setup_aspect(ra_core_width, ra_core_height); + crt_screen_setup_aspect(crt_switch_st.ra_core_width, + crt_switch_st.ra_core_height); - ra_tmp_height = ra_core_height; - ra_tmp_width = ra_core_width; - crt_tmp_center_adjust = crt_center_adjust; + crt_switch_st.ra_tmp_height = crt_switch_st.ra_core_height; + crt_switch_st.ra_tmp_width = crt_switch_st.ra_core_width; + crt_switch_st.tmp_center_adjust = crt_switch_st.center_adjust; /* Check if aspect is correct, if not change */ - if (video_driver_get_aspect_ratio() != fly_aspect) + if (video_driver_get_aspect_ratio() != crt_switch_st.fly_aspect) { - video_driver_set_aspect_ratio_value((float)fly_aspect); + video_driver_set_aspect_ratio_value((float)crt_switch_st.fly_aspect); video_driver_apply_state_changes(); } } @@ -239,21 +255,21 @@ void crt_video_restore(void) int crt_compute_dynamic_width(int width) { unsigned i; - int dynamic_width = 0; - unsigned min_height = 261; + int dynamic_width = 0; + unsigned min_height = 261; #if defined(HAVE_VIDEOCORE) - p_clock = 32000000; + crt_switch_st.p_clock = 32000000; #else - p_clock = 21000000; + crt_switch_st.p_clock = 21000000; #endif for (i = 0; i < 10; i++) { - dynamic_width = width*i; - if ((dynamic_width * min_height * ra_core_hz) > p_clock) + dynamic_width = width * i; + if ((dynamic_width * min_height * crt_switch_st.ra_core_hz) + > crt_switch_st.p_clock) break; - } return dynamic_width; } @@ -336,10 +352,8 @@ static void crt_rpi_switch(int width, int height, float hz, int xoffset) if (height > 300) vsp = vfp + 6; /* needs to be 6 for interlaced */ - vsp = 3; - - vbp = (vmax-height)-vsp-vfp; - + vsp = 3; + vbp = (vmax-height)-vsp-vfp; hmax = width+hfp+hsp+hbp; if (height < 300)