From 7c7eeff0fbccd9d7d7b10f386d144d83f9b40435 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 8 Mar 2020 18:47:52 +0100 Subject: [PATCH] Move display_server code into retroarch.c --- Makefile.common | 1 - gfx/video_crt_switch.c | 109 +++++++++++++---------- gfx/video_display_server.c | 178 ------------------------------------- griffin/griffin.c | 1 - retroarch.c | 158 ++++++++++++++++++++++++++++++++ 5 files changed, 218 insertions(+), 229 deletions(-) delete mode 100644 gfx/video_display_server.c diff --git a/Makefile.common b/Makefile.common index d6694f5445..aff67b3485 100644 --- a/Makefile.common +++ b/Makefile.common @@ -222,7 +222,6 @@ OBJ += \ input/input_mapper.o \ led/led_driver.o \ gfx/video_coord_array.o \ - gfx/video_display_server.o \ gfx/video_crt_switch.o \ gfx/gfx_display.o \ gfx/gfx_animation.o \ diff --git a/gfx/video_crt_switch.c b/gfx/video_crt_switch.c index a253c710c2..5e1352b424 100644 --- a/gfx/video_crt_switch.c +++ b/gfx/video_crt_switch.c @@ -65,56 +65,63 @@ static void crt_check_first_run(void) static void switch_crt_hz(void) { - float ra_core_hz = crt_switch_st.ra_core_hz; + videocrt_switch_t *p_switch = &crt_switch_st; - if (ra_core_hz == crt_switch_st.ra_tmp_core_hz) + float ra_core_hz = p_switch->ra_core_hz; + + if (ra_core_hz == p_switch->ra_tmp_core_hz) return; /* set hz float to an int for windows switching */ if (ra_core_hz < 100) { if (ra_core_hz < 53) - crt_switch_st.ra_set_core_hz = 50; + p_switch->ra_set_core_hz = 50; if (ra_core_hz >= 53 && ra_core_hz < 57) - crt_switch_st.ra_set_core_hz = 55; + p_switch->ra_set_core_hz = 55; if (ra_core_hz >= 57) - crt_switch_st.ra_set_core_hz = 60; + p_switch->ra_set_core_hz = 60; } if (ra_core_hz > 100) { if (ra_core_hz < 106) - crt_switch_st.ra_set_core_hz = 120; + p_switch->ra_set_core_hz = 120; if (ra_core_hz >= 106 && ra_core_hz < 114) - crt_switch_st.ra_set_core_hz = 110; + p_switch->ra_set_core_hz = 110; if (ra_core_hz >= 114) - crt_switch_st.ra_set_core_hz = 120; + p_switch->ra_set_core_hz = 120; } - video_monitor_set_refresh_rate(crt_switch_st.ra_set_core_hz); + video_monitor_set_refresh_rate(p_switch->ra_set_core_hz); - crt_switch_st.ra_tmp_core_hz = ra_core_hz; + p_switch->ra_tmp_core_hz = ra_core_hz; } void crt_aspect_ratio_switch(unsigned width, unsigned height) { - /* send aspect float to videeo_driver */ - crt_switch_st.fly_aspect = (float)width / height; - video_driver_set_aspect_ratio_value((float)crt_switch_st.fly_aspect); + videocrt_switch_t *p_switch = &crt_switch_st; + /* send aspect float to video_driver */ + p_switch->fly_aspect = (float)width / height; + video_driver_set_aspect_ratio_value((float)p_switch->fly_aspect); } static void switch_res_crt(unsigned width, unsigned height) { + videocrt_switch_t *p_switch = &crt_switch_st; + video_display_server_set_resolution(width, height, - 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); + p_switch->ra_set_core_hz, + p_switch->ra_core_hz, + p_switch->center_adjust, + p_switch->index, + p_switch->center_adjust); + #if defined(HAVE_VIDEOCORE) - 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_rpi_switch(width, height, + p_switch->ra_core_hz, + p_switch->center_adjust); + video_monitor_set_refresh_rate(p_switch->ra_core_hz); crt_switch_driver_reinit(); #endif video_driver_apply_state_changes(); @@ -123,6 +130,7 @@ static void switch_res_crt(unsigned width, unsigned height) /* Create correct aspect to fit video if resolution does not exist */ static void crt_screen_setup_aspect(unsigned width, unsigned height) { + videocrt_switch_t *p_switch = &crt_switch_st; #if defined(HAVE_VIDEOCORE) if (height > 300) height = height/2; @@ -150,7 +158,7 @@ static void crt_screen_setup_aspect(unsigned width, unsigned height) if (height > 200) crt_aspect_ratio_switch(width, height); - if (height == 144 && crt_switch_st.ra_set_core_hz == 50) + if (height == 144 && p_switch->ra_set_core_hz == 50) { height = 288; crt_aspect_ratio_switch(width, height); @@ -174,13 +182,13 @@ static void crt_screen_setup_aspect(unsigned width, unsigned height) height = 254; } - if (height == 528 && crt_switch_st.ra_set_core_hz == 60) + if (height == 528 && p_switch->ra_set_core_hz == 60) { crt_aspect_ratio_switch(width, height); height = 480; } - if (height >= 240 && height < 255 && crt_switch_st.ra_set_core_hz == 55) + if (height >= 240 && height < 255 && p_switch->ra_set_core_hz == 55) { crt_aspect_ratio_switch(width, height); height = 254; @@ -193,6 +201,8 @@ void crt_switch_res_core(unsigned width, unsigned height, float hz, unsigned crt_mode, int crt_switch_center_adjust, int monitor_index, bool dynamic) { + videocrt_switch_t *p_switch = &crt_switch_st; + /* ra_core_hz float passed from within * video_driver_monitor_adjust_system_rates() */ if (width == 4) @@ -201,45 +211,45 @@ void crt_switch_res_core(unsigned width, unsigned height, height = 240; } - crt_switch_st.ra_core_height = height; - crt_switch_st.ra_core_hz = hz; + p_switch->ra_core_height = height; + p_switch->ra_core_hz = hz; if (dynamic) - crt_switch_st.ra_core_width = crt_compute_dynamic_width(width); + p_switch->ra_core_width = crt_compute_dynamic_width(width); else - crt_switch_st.ra_core_width = width; + p_switch->ra_core_width = width; - crt_switch_st.center_adjust = crt_switch_center_adjust; - crt_switch_st.index = monitor_index; + p_switch->center_adjust = crt_switch_center_adjust; + p_switch->index = monitor_index; if (crt_mode == 2) { if (hz > 53) - crt_switch_st.ra_core_hz = hz * 2; - + p_switch->ra_core_hz = hz * 2; if (hz <= 53) - crt_switch_st.ra_core_hz = 120.0f; + p_switch->ra_core_hz = 120.0f; } crt_check_first_run(); /* Detect resolution change and switch */ if ( - (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) + (p_switch->ra_tmp_height != p_switch->ra_core_height) || + (p_switch->ra_core_width != p_switch->ra_tmp_width) || + (p_switch->center_adjust != p_switch->tmp_center_adjust) ) - crt_screen_setup_aspect(crt_switch_st.ra_core_width, - crt_switch_st.ra_core_height); + crt_screen_setup_aspect( + p_switch->ra_core_width, + p_switch->ra_core_height); - 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; + p_switch->ra_tmp_height = p_switch->ra_core_height; + p_switch->ra_tmp_width = p_switch->ra_core_width; + p_switch->tmp_center_adjust = p_switch->center_adjust; /* Check if aspect is correct, if not change */ - if (video_driver_get_aspect_ratio() != crt_switch_st.fly_aspect) + if (video_driver_get_aspect_ratio() != p_switch->fly_aspect) { - video_driver_set_aspect_ratio_value((float)crt_switch_st.fly_aspect); + video_driver_set_aspect_ratio_value((float)p_switch->fly_aspect); video_driver_apply_state_changes(); } } @@ -255,20 +265,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; + videocrt_switch_t *p_switch = &crt_switch_st; #if defined(HAVE_VIDEOCORE) - crt_switch_st.p_clock = 32000000; + p_switch->p_clock = 32000000; #else - crt_switch_st.p_clock = 21000000; + p_switch->p_clock = 21000000; #endif for (i = 0; i < 10; i++) { dynamic_width = width * i; - if ((dynamic_width * min_height * crt_switch_st.ra_core_hz) - > crt_switch_st.p_clock) + if ((dynamic_width * min_height * p_switch->ra_core_hz) + > p_switch->p_clock) break; } return dynamic_width; diff --git a/gfx/video_display_server.c b/gfx/video_display_server.c deleted file mode 100644 index 040b1c7a9b..0000000000 --- a/gfx/video_display_server.c +++ /dev/null @@ -1,178 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2010-2014 - Hans-Kristian Arntzen - * Copyright (C) 2011-2017 - Daniel De Matteis - * Copyright (C) 2016-2019 - Brad Parker - * - * RetroArch is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with RetroArch. - * If not, see . - */ - -#include "video_display_server.h" -#include "../verbosity.h" - -static const video_display_server_t dispserv_null = { - NULL, /* init */ - NULL, /* destroy */ - NULL, /* set_window_opacity */ - NULL, /* set_window_progress */ - NULL, /* set_window_decorations */ - NULL, /* set_resolution */ - NULL, /* get_resolution_list */ - NULL, /* get_output_options */ - NULL, /* set_screen_orientation */ - NULL, /* get_screen_orientation */ - NULL, /* get_flags */ - "null" -}; - -static const video_display_server_t *current_display_server = &dispserv_null; -static void *current_display_server_data = NULL; -static enum rotation initial_screen_orientation = ORIENTATION_NORMAL; -static enum rotation current_screen_orientation = ORIENTATION_NORMAL; - -const char *video_display_server_get_ident(void) -{ - if (!current_display_server) - return "null"; - return current_display_server->ident; -} - -void* video_display_server_init(enum rarch_display_type type) -{ - video_display_server_destroy(); - - switch (type) - { - case RARCH_DISPLAY_WIN32: -#if defined(_WIN32) && !defined(_XBOX) && !defined(__WINRT__) - current_display_server = &dispserv_win32; -#endif - break; - case RARCH_DISPLAY_X11: -#if defined(HAVE_X11) - current_display_server = &dispserv_x11; -#endif - break; - default: -#if defined(ANDROID) - current_display_server = &dispserv_android; -#else - current_display_server = &dispserv_null; -#endif - break; - } - - if (current_display_server && current_display_server->init) - current_display_server_data = current_display_server->init(); - - RARCH_LOG("[Video]: Found display server: %s\n", - current_display_server->ident); - - initial_screen_orientation = video_display_server_get_screen_orientation(); - current_screen_orientation = initial_screen_orientation; - - return current_display_server_data; -} - -void video_display_server_destroy(void) -{ - if (initial_screen_orientation != current_screen_orientation) - video_display_server_set_screen_orientation(initial_screen_orientation); - - if (current_display_server) - if (current_display_server_data) - current_display_server->destroy(current_display_server_data); -} - -bool video_display_server_set_window_opacity(unsigned opacity) -{ - if (current_display_server && current_display_server->set_window_opacity) - return current_display_server->set_window_opacity(current_display_server_data, opacity); - return false; -} - -bool video_display_server_set_window_progress(int progress, bool finished) -{ - if (current_display_server && current_display_server->set_window_progress) - return current_display_server->set_window_progress(current_display_server_data, progress, finished); - return false; -} - -bool video_display_server_set_window_decorations(bool on) -{ - if (current_display_server && current_display_server->set_window_decorations) - return current_display_server->set_window_decorations(current_display_server_data, on); - return false; -} - -bool video_display_server_set_resolution(unsigned width, unsigned height, - int int_hz, float hz, int center, int monitor_index, int xoffset) -{ - if (current_display_server && current_display_server->set_resolution) - return current_display_server->set_resolution(current_display_server_data, width, height, int_hz, hz, center, monitor_index, xoffset); - return false; -} - -bool video_display_server_has_resolution_list(void) -{ - return (current_display_server - && current_display_server->get_resolution_list); -} - -void *video_display_server_get_resolution_list(unsigned *size) -{ - if (video_display_server_has_resolution_list()) - return current_display_server->get_resolution_list(current_display_server_data, size); - return NULL; -} - -const char *video_display_server_get_output_options(void) -{ - if (current_display_server && current_display_server->get_output_options) - return current_display_server->get_output_options(current_display_server_data); - return NULL; -} - -void video_display_server_set_screen_orientation(enum rotation rotation) -{ - if (current_display_server && current_display_server->set_screen_orientation) - { - RARCH_LOG("[Video]: Setting screen orientation to %d.\n", rotation); - current_screen_orientation = rotation; - current_display_server->set_screen_orientation(rotation); - } -} - -bool video_display_server_can_set_screen_orientation(void) -{ - if (current_display_server && current_display_server->set_screen_orientation) - return true; - return false; -} - -enum rotation video_display_server_get_screen_orientation(void) -{ - if (current_display_server && current_display_server->get_screen_orientation) - return current_display_server->get_screen_orientation(); - return ORIENTATION_NORMAL; -} - -bool video_display_server_get_flags(gfx_ctx_flags_t *flags) -{ - if (!current_display_server || !current_display_server->get_flags) - return false; - if (!flags) - return false; - - flags->flags = current_display_server->get_flags( - current_display_server_data); - return true; -} diff --git a/griffin/griffin.c b/griffin/griffin.c index 0dd806bf4e..0617ae19cd 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -920,7 +920,6 @@ DRIVERS #include "../gfx/gfx_display.c" #include "../gfx/gfx_thumbnail_path.c" #include "../gfx/gfx_thumbnail.c" -#include "../gfx/video_display_server.c" #include "../gfx/video_coord_array.c" #ifdef HAVE_AUDIOMIXER #include "../libretro-common/audio/audio_mixer.c" diff --git a/retroarch.c b/retroarch.c index 0c6b0b0041..469678a60e 100644 --- a/retroarch.c +++ b/retroarch.c @@ -367,6 +367,21 @@ static const audio_driver_t *audio_drivers[] = { NULL, }; +static const video_display_server_t dispserv_null = { + NULL, /* init */ + NULL, /* destroy */ + NULL, /* set_window_opacity */ + NULL, /* set_window_progress */ + NULL, /* set_window_decorations */ + NULL, /* set_resolution */ + NULL, /* get_resolution_list */ + NULL, /* get_output_options */ + NULL, /* set_screen_orientation */ + NULL, /* get_screen_orientation */ + NULL, /* get_flags */ + "null" +}; + static void video_null_free(void *data) { } static void *video_null_init(const video_info_t *video, @@ -2943,6 +2958,11 @@ static bool wifi_driver_active = false; /* VIDEO GLOBAL VARIABLES */ +static const video_display_server_t *current_display_server = &dispserv_null; +static void *current_display_server_data = NULL; +static enum rotation initial_screen_orientation = ORIENTATION_NORMAL; +static enum rotation current_screen_orientation = ORIENTATION_NORMAL; + #if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL) static void retroarch_set_runtime_shader_preset(const char *arg) { @@ -21764,6 +21784,144 @@ bool *audio_get_bool_ptr(enum audio_action action) } /* VIDEO */ +const char *video_display_server_get_ident(void) +{ + if (!current_display_server) + return "null"; + return current_display_server->ident; +} + +void* video_display_server_init(enum rarch_display_type type) +{ + video_display_server_destroy(); + + switch (type) + { + case RARCH_DISPLAY_WIN32: +#if defined(_WIN32) && !defined(_XBOX) && !defined(__WINRT__) + current_display_server = &dispserv_win32; +#endif + break; + case RARCH_DISPLAY_X11: +#if defined(HAVE_X11) + current_display_server = &dispserv_x11; +#endif + break; + default: +#if defined(ANDROID) + current_display_server = &dispserv_android; +#else + current_display_server = &dispserv_null; +#endif + break; + } + + if (current_display_server && current_display_server->init) + current_display_server_data = current_display_server->init(); + + RARCH_LOG("[Video]: Found display server: %s\n", + current_display_server->ident); + + initial_screen_orientation = video_display_server_get_screen_orientation(); + current_screen_orientation = initial_screen_orientation; + + return current_display_server_data; +} + +void video_display_server_destroy(void) +{ + if (initial_screen_orientation != current_screen_orientation) + video_display_server_set_screen_orientation(initial_screen_orientation); + + if (current_display_server) + if (current_display_server_data) + current_display_server->destroy(current_display_server_data); +} + +bool video_display_server_set_window_opacity(unsigned opacity) +{ + if (current_display_server && current_display_server->set_window_opacity) + return current_display_server->set_window_opacity(current_display_server_data, opacity); + return false; +} + +bool video_display_server_set_window_progress(int progress, bool finished) +{ + if (current_display_server && current_display_server->set_window_progress) + return current_display_server->set_window_progress(current_display_server_data, progress, finished); + return false; +} + +bool video_display_server_set_window_decorations(bool on) +{ + if (current_display_server && current_display_server->set_window_decorations) + return current_display_server->set_window_decorations(current_display_server_data, on); + return false; +} + +bool video_display_server_set_resolution(unsigned width, unsigned height, + int int_hz, float hz, int center, int monitor_index, int xoffset) +{ + if (current_display_server && current_display_server->set_resolution) + return current_display_server->set_resolution(current_display_server_data, width, height, int_hz, hz, center, monitor_index, xoffset); + return false; +} + +bool video_display_server_has_resolution_list(void) +{ + return (current_display_server + && current_display_server->get_resolution_list); +} + +void *video_display_server_get_resolution_list(unsigned *size) +{ + if (video_display_server_has_resolution_list()) + return current_display_server->get_resolution_list(current_display_server_data, size); + return NULL; +} + +const char *video_display_server_get_output_options(void) +{ + if (current_display_server && current_display_server->get_output_options) + return current_display_server->get_output_options(current_display_server_data); + return NULL; +} + +void video_display_server_set_screen_orientation(enum rotation rotation) +{ + if (current_display_server && current_display_server->set_screen_orientation) + { + RARCH_LOG("[Video]: Setting screen orientation to %d.\n", rotation); + current_screen_orientation = rotation; + current_display_server->set_screen_orientation(rotation); + } +} + +bool video_display_server_can_set_screen_orientation(void) +{ + if (current_display_server && current_display_server->set_screen_orientation) + return true; + return false; +} + +enum rotation video_display_server_get_screen_orientation(void) +{ + if (current_display_server && current_display_server->get_screen_orientation) + return current_display_server->get_screen_orientation(); + return ORIENTATION_NORMAL; +} + +bool video_display_server_get_flags(gfx_ctx_flags_t *flags) +{ + if (!current_display_server || !current_display_server->get_flags) + return false; + if (!flags) + return false; + + flags->flags = current_display_server->get_flags( + current_display_server_data); + return true; +} bool video_driver_started_fullscreen(void) {