Gtk: Convert driver setting to a string.

This commit is contained in:
BearOso 2022-06-07 15:15:21 -05:00
parent 6433b8f689
commit 109fedf42c
6 changed files with 49 additions and 69 deletions

View File

@ -82,7 +82,7 @@ int Snes9xConfig::load_defaults()
rom_loaded = false;
multithreading = false;
splash_image = SPLASH_IMAGE_STARFIELD;
hw_accel = 0;
display_driver = "OpenGL";
allow_opengl = false;
allow_xv = false;
allow_xrandr = false;
@ -227,7 +227,7 @@ int Snes9xConfig::save_config_file()
outint("ScanlineFilterIntensity", scanline_filter_intensity, "0: 0%, 1: 12.5%, 2: 25%, 3: 50%, 4: 100%");
outint("HiresEffect", hires_effect, "0: Downscale to low-res, 1: Leave as-is, 2: Upscale low-res screens");
outint("NumberOfThreads", num_threads);
outint("HardwareAcceleration", hw_accel, "0: None, 1: OpenGL, 2: XVideo");
outstring("HardwareAcceleration", display_driver, "None, OpenGL, Xv, Vulkan");
outint("SplashBackground", splash_image, "0: Black, 1: Color bars, 2: Pattern, 3: Blue, 4: Default");
section = "NTSC";
@ -453,7 +453,7 @@ int Snes9xConfig::load_config_file()
inbool("ForceInvertedByteOrder", force_inverted_byte_order);
inbool("Multithreading", multithreading);
inint("NumberOfThreads", num_threads);
inint("HardwareAcceleration", hw_accel);
instr("HardwareAcceleration", display_driver);
inbool("BilinearFilter", Settings.BilinearFilter);
inint("SplashBackground", splash_image);

View File

@ -15,12 +15,6 @@
#include <string>
#include <array>
enum {
HWA_NONE = 0,
HWA_OPENGL = 1,
HWA_XV = 2
};
enum {
HIRES_MERGE = 0,
HIRES_NORMAL = 1,
@ -92,7 +86,7 @@ class Snes9xConfig
float ntsc_merge_fields;
int ntsc_scanline_intensity;
int scanline_filter_intensity;
int hw_accel;
std::string display_driver;
bool allow_opengl;
bool allow_xv;
bool allow_xrandr;
@ -125,6 +119,7 @@ class Snes9xConfig
/* Operational */
std::vector<std::string> sound_drivers;
std::vector<std::string> display_drivers;
int sound_driver;
bool mute_sound;
bool mute_sound_turbo;

View File

@ -798,6 +798,14 @@ void S9xQueryDrivers()
gui_config->xrr_screen_resources->crtcs[0]);
}
#endif
auto &dd = gui_config->display_drivers;
dd.clear();
dd.push_back("None");
if (gui_config->allow_opengl)
dd.push_back("OpenGL");
if (gui_config->allow_xv)
dd.push_back("Xv");
}
bool8 S9xDeinitUpdate(int width, int height)
@ -887,40 +895,30 @@ static void S9xInitDriver()
#ifdef GDK_WINDOWING_WAYLAND
if (GDK_IS_WAYLAND_DISPLAY(gdk_display_get_default()))
{
gui_config->hw_accel = HWA_OPENGL;
gui_config->display_driver = "OpenGL";
}
#endif
switch (gui_config->hw_accel)
if ("OpenGL" == gui_config->display_driver)
{
case HWA_OPENGL:
driver = new S9xOpenGLDisplayDriver(top_level, gui_config);
break;
}
#if defined(USE_XV) && defined(GDK_WINDOWING_X11)
case HWA_XV:
else if ("Xv" == gui_config->display_driver)
{
driver = new S9xXVDisplayDriver(top_level, gui_config);
break;
}
#endif
default:
else
{
driver = new S9xGTKDisplayDriver(top_level, gui_config);
}
if (driver->init())
{
if (gui_config->hw_accel > 0)
{
delete driver;
gui_config->hw_accel = HWA_NONE;
S9xInitDriver();
}
else
{
fprintf(stderr, "Error: Couldn't initialize any display output.\n");
exit(1);
}
delete driver;
gui_config->display_driver = "None";
driver->init();
}
pool = NULL;

View File

@ -589,9 +589,6 @@ int S9xOpenGLDisplayDriver::query_availability()
}
#endif
if (gui_config->hw_accel == HWA_OPENGL)
gui_config->hw_accel = HWA_NONE;
return 0;
}

View File

@ -138,15 +138,18 @@ Snes9xPreferences::Snes9xPreferences(Snes9xConfig *config)
combo_box_append("scale_method_combo", _("4xBRZ"));
#endif
combo_box_append("hw_accel", _("None - Use software scaler"));
for (const auto &driver : config->display_drivers)
{
std::string entry;
if (!strcasecmp(driver.c_str(), "opengl"))
entry = _("OpenGL - Use 3D graphics hardware");
else if (!strcasecmp(driver.c_str(), "Xv"))
entry = _("XVideo - Use hardware video blitter");
else
entry = _("None - Use software scaler");
if (config->allow_opengl)
combo_box_append("hw_accel",
_("OpenGL - Use 3D graphics hardware"));
if (config->allow_xv)
combo_box_append("hw_accel",
_("XVideo - Use hardware video blitter"));
combo_box_append("hw_accel", entry.c_str());
}
for (auto &name : config->sound_drivers)
{
@ -173,9 +176,9 @@ void Snes9xPreferences::connect_signals()
get_object<Gtk::ComboBox>("hw_accel")->signal_changed().connect([&] {
int id = get_combo("hw_accel");
show_widget("bilinear_filter", id != HWA_XV);
show_widget("opengl_frame", id == HWA_OPENGL);
show_widget("xv_frame", id == HWA_XV);
show_widget("bilinear_filter", config->display_drivers[id] != "Xv");
show_widget("opengl_frame", config->display_drivers[id] == "OpenGL");
show_widget("xv_frame", config->display_drivers[id] == "Xv");
});
get_object<Gtk::Button>("reset_current_joypad")->signal_pressed().connect(sigc::mem_fun(*this, &Snes9xPreferences::reset_current_joypad));
@ -425,7 +428,7 @@ void Snes9xPreferences::move_settings_to_dialog()
set_check("prevent_screensaver", config->prevent_screensaver);
set_check("force_inverted_byte_order", config->force_inverted_byte_order);
set_combo("playback_combo", 7 - config->sound_playback_rate);
set_combo("hw_accel", combo_value (config->hw_accel));
set_combo("hw_accel", combo_value (config->display_driver));
set_check("pause_emulation_on_switch", config->pause_emulation_on_switch);
set_spin ("num_threads", config->num_threads);
set_check("mute_sound_check", config->mute_sound);
@ -545,7 +548,7 @@ void Snes9xPreferences::get_settings_from_dialog()
if (config->multithreading != get_check("multithreading"))
gfx_needs_restart = true;
if (config->hw_accel != hw_accel_value (get_combo("hw_accel")))
if (config->display_driver != config->display_drivers[get_combo("hw_accel")])
gfx_needs_restart = true;
if (config->force_inverted_byte_order != get_check("force_inverted_byte_order"))
@ -586,7 +589,7 @@ void Snes9xPreferences::get_settings_from_dialog()
store_ntsc_settings();
config->ntsc_scanline_intensity = get_combo("ntsc_scanline_intensity");
config->scanline_filter_intensity = get_combo("scanline_filter_intensity");
config->hw_accel = hw_accel_value(get_combo("hw_accel"));
config->display_driver = config->display_drivers[get_combo("hw_accel")];
Settings.BilinearFilter = get_check("bilinear_filter");
config->num_threads = get_spin("num_threads");
config->default_esc_behavior = get_combo("default_esc_behavior");
@ -715,28 +718,15 @@ void Snes9xPreferences::get_settings_from_dialog()
top_level->leave_fullscreen_mode();
}
int Snes9xPreferences::hw_accel_value(int combo_value)
int Snes9xPreferences::combo_value(std::string driver_name)
{
if (config->allow_opengl && config->allow_xv)
return combo_value;
else if (!config->allow_opengl && !config->allow_xv)
return 0;
else if (!config->allow_opengl && config->allow_xv)
return combo_value ? 2 : 0;
else
return combo_value ? 1 : 0;
}
for (size_t i = 0; i < config->display_drivers.size(); i++)
{
if (config->display_drivers[i] == driver_name)
return i;
}
int Snes9xPreferences::combo_value(int hw_accel)
{
if (config->allow_opengl && config->allow_xv)
return hw_accel;
else if (!config->allow_opengl && !config->allow_xv)
return 0;
else if (!config->allow_opengl && config->allow_xv)
return hw_accel == HWA_XV ? 1 : 0;
else
return hw_accel == HWA_OPENGL ? 1 : 0;
return 0;
}
void Snes9xPreferences::show()

View File

@ -24,7 +24,7 @@ class Snes9xPreferences : public GtkBuilderWindow
int get_focused_binding();
void store_binding(const char *string, Binding binding);
int hw_accel_value(int combo_value);
int combo_value(int hw_accel);
int combo_value(std::string driver_name);
void focus_next();
void swap_with();
void clear_binding(const char *name);