diff --git a/src/osdep/amiberry.cpp b/src/osdep/amiberry.cpp index e39d6bbe7..73c33455d 100644 --- a/src/osdep/amiberry.cpp +++ b/src/osdep/amiberry.cpp @@ -2508,6 +2508,17 @@ void set_logfile_enabled(bool enabled) amiberry_options.write_logfile = enabled; } +bool get_sdl2_thread_enabled() +{ + return amiberry_options.use_sdl2_render_thread; +} + +void set_sdl2_thread_enabled(bool enabled) +{ + amiberry_options.use_sdl2_render_thread = enabled; + sdl2_thread_changed = true; +} + // Returns 1 if savedatapath is overridden // if force_internal == true, the non-overridden whdbootpath based save-data path will be returned int get_savedatapath(char* out, int size, const int force_internal) diff --git a/src/osdep/amiberry_gfx.cpp b/src/osdep/amiberry_gfx.cpp index 6feddb113..72494d6be 100644 --- a/src/osdep/amiberry_gfx.cpp +++ b/src/osdep/amiberry_gfx.cpp @@ -96,6 +96,7 @@ static int deskhz; #ifdef AMIBERRY bool vsync_changed = false; +bool sdl2_thread_changed = false; #endif // Check if the requested Amiga resolution can be displayed with the current Screen mode as a direct multiple @@ -1003,7 +1004,7 @@ int check_prefs_changed_gfx() c |= currprefs.multithreaded_drawing != changed_prefs.multithreaded_drawing ? (512) : 0; #endif - if (display_change_requested || c) + if (display_change_requested || c || sdl2_thread_changed) { bool setpause = false; bool dontcapture = false; @@ -1128,7 +1129,13 @@ int check_prefs_changed_gfx() currprefs.rtgallowscaling = changed_prefs.rtgallowscaling; currprefs.rtgscaleaspectratio = changed_prefs.rtgscaleaspectratio; currprefs.rtgvblankrate = changed_prefs.rtgvblankrate; - + + if (sdl2_thread_changed) + { + graphics_leave(); + graphics_init(true); + sdl2_thread_changed = false; + } bool unacquired = false; for (int monid = MAX_AMIGAMONITORS - 1; monid >= 0; monid--) { if (!monitors[monid]) diff --git a/src/osdep/amiberry_gfx.h b/src/osdep/amiberry_gfx.h index a4675f2fc..0ba5cfc97 100644 --- a/src/osdep/amiberry_gfx.h +++ b/src/osdep/amiberry_gfx.h @@ -147,3 +147,4 @@ void SDL2_toggle_vsync(bool vsync); extern void auto_crop_image(); extern SDL_GameControllerButton vkbd_button; +extern bool sdl2_thread_changed; \ No newline at end of file diff --git a/src/osdep/gui/Navigation.cpp b/src/osdep/gui/Navigation.cpp index f8da66599..dd23ac39a 100644 --- a/src/osdep/gui/Navigation.cpp +++ b/src/osdep/gui/Navigation.cpp @@ -268,7 +268,7 @@ static NavigationMap navMap[] = // active move left move right move up move down // PanelDisplay - { "cboFullscreen", "Display", "chkHorizontal", "sldBrightness", "cboScreenmode" }, + { "cboFullscreen", "Display", "chkHorizontal", "chkSdl2Thread", "cboScreenmode" }, { "cboScreenmode", "Display", "chkVertical", "cboFullscreen", "sldWidth" }, { "sldWidth", "", "", "cboScreenmode", "sldHeight" }, { "sldHeight", "", "", "sldWidth", "chkAutoCrop" }, @@ -285,7 +285,8 @@ static NavigationMap navMap[] = { "chkFlickerFixer", "Display", "optIDouble", "chkAspect", "chkFrameskip" }, { "chkFrameskip", "Display", "optIDouble2", "chkFlickerFixer", "sldBrightness" }, { "sldRefresh", "", "", "chkFlickerFixer", "sldBrightness" }, - { "sldBrightness", "", "", "chkFrameskip", "cboFullscreen" }, + { "sldBrightness", "", "", "chkFrameskip", "chkSdl2Thread" }, + { "chkSdl2Thread", "Display", "optIDouble2", "sldBrightness", "cboFullscreen" }, { "chkHorizontal", "cboScreenmode", "", "optIDouble3", "chkVertical" }, { "chkVertical", "cboScreenmode", "", "chkHorizontal", "optSingle" }, diff --git a/src/osdep/gui/PanelDisplay.cpp b/src/osdep/gui/PanelDisplay.cpp index 17a47fe2c..68380e30b 100644 --- a/src/osdep/gui/PanelDisplay.cpp +++ b/src/osdep/gui/PanelDisplay.cpp @@ -124,6 +124,8 @@ static gcn::Label* lblBrightness; static gcn::Slider* sldBrightness; static gcn::Label* lblBrightnessValue; +static gcn::CheckBox* chkSdl2Thread; + class AmigaScreenActionListener : public gcn::ActionListener { public: @@ -237,7 +239,10 @@ class AmigaScreenActionListener : public gcn::ActionListener else if (actionEvent.getSource() == chkFilterLowRes) changed_prefs.gfx_lores_mode = chkFilterLowRes->isSelected() ? 1 : 0; - + + else if (actionEvent.getSource() == chkSdl2Thread) + set_sdl2_thread_enabled(chkSdl2Thread->isSelected()); + RefreshPanelDisplay(); } }; @@ -470,6 +475,10 @@ void InitPanelDisplay(const config_category& category) lblBrightnessValue = new gcn::Label("0.0"); lblBrightnessValue->setAlignment(gcn::Graphics::LEFT); + chkSdl2Thread = new gcn::CheckBox("Use SDL2 multi-threaded rendering"); + chkSdl2Thread->setId("chkSdl2Thread"); + chkSdl2Thread->addActionListener(amigaScreenActionListener); + lblScreenmode = new gcn::Label("Screen mode:"); lblScreenmode->setAlignment(gcn::Graphics::RIGHT); cboScreenmode = new gcn::DropDown(&fullscreen_modes_list); @@ -634,6 +643,9 @@ void InitPanelDisplay(const config_category& category) category.panel->add(lblBrightness, DISTANCE_BORDER, posY); category.panel->add(sldBrightness, lblBrightness->getX() + lblBrightness->getWidth() + DISTANCE_NEXT_X, posY); category.panel->add(lblBrightnessValue, sldBrightness->getX() + sldBrightness->getWidth() + 8, posY); + posY += lblBrightness->getHeight() + DISTANCE_NEXT_Y; + + category.panel->add(chkSdl2Thread, DISTANCE_BORDER, posY); RefreshPanelDisplay(); } @@ -696,6 +708,7 @@ void ExitPanelDisplay() delete lblResolution; delete cboResolution; delete chkFilterLowRes; + delete chkSdl2Thread; } void RefreshPanelDisplay() @@ -773,6 +786,8 @@ void RefreshPanelDisplay() chkAspect->setSelected(changed_prefs.gfx_correct_aspect); chkFilterLowRes->setSelected(changed_prefs.gfx_lores_mode); + chkSdl2Thread->setSelected(get_sdl2_thread_enabled()); + if (changed_prefs.gfx_apmode[0].gfx_fullscreen == GFX_WINDOW) { cboScreenmode->setSelected(0); @@ -941,6 +956,9 @@ bool HelpPanelDisplay(std::vector& helptext) helptext.emplace_back(" "); helptext.emplace_back("\"Brightness\" - Allows adjustment of the output image brightness, from -200 to 200."); helptext.emplace_back(" "); + helptext.emplace_back("\"Use SDL2 multi-threaded rendering\" - Enables multi-threaded drawing using SDL2."); + helptext.emplace_back("Provides a performance benefit, however not all systems support it."); + helptext.emplace_back("Disable this if you notice problems, like a black screen when starting emulation."); helptext.emplace_back(" "); helptext.emplace_back("\"Line Mode\" - These options define how the Amiga screen is drawn."); helptext.emplace_back(" "); diff --git a/src/osdep/target.h b/src/osdep/target.h index c831803cb..9fe052b17 100644 --- a/src/osdep/target.h +++ b/src/osdep/target.h @@ -106,6 +106,8 @@ extern int get_savedatapath(char* out, int size, const int force_internal); extern void get_whdbootpath(char* out, int size); extern void set_whdbootpath(char* newpath); +extern bool get_sdl2_thread_enabled(); +extern void set_sdl2_thread_enabled(bool enabled); extern bool get_logfile_enabled(); extern void set_logfile_enabled(bool enabled); extern void get_logfile_path(char* out, int size);