diff --git a/Source/Core/Core/HW/DVD/DVDInterface.cpp b/Source/Core/Core/HW/DVD/DVDInterface.cpp index c5db7b09d6..853026a92e 100644 --- a/Source/Core/Core/HW/DVD/DVDInterface.cpp +++ b/Source/Core/Core/HW/DVD/DVDInterface.cpp @@ -19,7 +19,6 @@ #include "Common/Logging/Log.h" #include "Core/ConfigManager.h" -#include "Core/Core.h" #include "Core/CoreTiming.h" #include "Core/HW/AudioInterface.h" #include "Core/HW/DVD/DVDMath.h" @@ -451,10 +450,6 @@ bool IsDiscInside() return DVDThread::HasDisc(); } -// Take care of all logic of "swapping discs" -// We want this in the "backend", NOT the gui -// any !empty string will be deleted to ensure -// that the userdata string exists when called static void EjectDiscCallback(u64 userdata, s64 cyclesLate) { SetDisc(nullptr); @@ -473,14 +468,14 @@ static void InsertDiscCallback(u64 userdata, s64 cyclesLate) s_disc_path_to_insert.clear(); } -// Can only be called by the host thread -void ChangeDiscAsHost(const std::string& new_path) +// Must only be called on the CPU thread +void EjectDisc() { - Core::RunAsCPUThread([&] { ChangeDiscAsCPU(new_path); }); + CoreTiming::ScheduleEvent(0, s_eject_disc); } -// Can only be called by the CPU thread -void ChangeDiscAsCPU(const std::string& new_path) +// Must only be called on the CPU thread +void ChangeDisc(const std::string& new_path) { if (!s_disc_path_to_insert.empty()) { @@ -488,10 +483,10 @@ void ChangeDiscAsCPU(const std::string& new_path) return; } - s_disc_path_to_insert = new_path; - CoreTiming::ScheduleEvent(0, s_eject_disc); - CoreTiming::ScheduleEvent(SystemTimers::GetTicksPerSecond(), s_insert_disc); + EjectDisc(); + s_disc_path_to_insert = new_path; + CoreTiming::ScheduleEvent(SystemTimers::GetTicksPerSecond(), s_insert_disc); Movie::SignalDiscChange(new_path); } diff --git a/Source/Core/Core/HW/DVD/DVDInterface.h b/Source/Core/Core/HW/DVD/DVDInterface.h index cc29e76c25..fc23fb8bbd 100644 --- a/Source/Core/Core/HW/DVD/DVDInterface.h +++ b/Source/Core/Core/HW/DVD/DVDInterface.h @@ -113,8 +113,8 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base); void SetDisc(std::unique_ptr disc); bool IsDiscInside(); -void ChangeDiscAsHost(const std::string& new_path); // Can only be called by the host thread -void ChangeDiscAsCPU(const std::string& new_path); // Can only be called by the CPU thread +void EjectDisc(); // Must only be called on the CPU thread +void ChangeDisc(const std::string& new_path); // Must only be called on the CPU thread // This function returns true and calls SConfig::SetRunningGameMetadata(Volume&, Partition&) // if both of the following conditions are true: diff --git a/Source/Core/Core/HotkeyManager.cpp b/Source/Core/Core/HotkeyManager.cpp index 89c394deb7..0edd84bdf3 100644 --- a/Source/Core/Core/HotkeyManager.cpp +++ b/Source/Core/Core/HotkeyManager.cpp @@ -23,6 +23,7 @@ const std::string hotkey_labels[] = { _trans("Open"), _trans("Change Disc"), + _trans("Eject Disc"), _trans("Refresh List"), _trans("Toggle Pause"), _trans("Stop"), diff --git a/Source/Core/Core/HotkeyManager.h b/Source/Core/Core/HotkeyManager.h index 10dbb9ccf4..f9b4dabaf5 100644 --- a/Source/Core/Core/HotkeyManager.h +++ b/Source/Core/Core/HotkeyManager.h @@ -21,6 +21,7 @@ enum Hotkey { HK_OPEN, HK_CHANGE_DISC, + HK_EJECT_DISC, HK_REFRESH_LIST, HK_PLAY_PAUSE, HK_STOP, diff --git a/Source/Core/Core/Movie.cpp b/Source/Core/Core/Movie.cpp index b9c6f9867d..16ffdb7584 100644 --- a/Source/Core/Core/Movie.cpp +++ b/Source/Core/Core/Movie.cpp @@ -1180,7 +1180,7 @@ void PlayController(GCPadStatus* PadStatus, int controllerID) } if (found) { - DVDInterface::ChangeDiscAsCPU(path); + Core::RunAsCPUThread([&path] { DVDInterface::ChangeDisc(path); }); } else { diff --git a/Source/Core/DolphinQt2/GameList/GameList.cpp b/Source/Core/DolphinQt2/GameList/GameList.cpp index df4e9d161c..90510c5b04 100644 --- a/Source/Core/DolphinQt2/GameList/GameList.cpp +++ b/Source/Core/DolphinQt2/GameList/GameList.cpp @@ -417,7 +417,8 @@ void GameList::DeleteFile() void GameList::ChangeDisc() { - DVDInterface::ChangeDiscAsHost(GetSelectedGame()->GetFilePath().toStdString()); + Core::RunAsCPUThread( + [this] { DVDInterface::ChangeDisc(GetSelectedGame()->GetFilePath().toStdString()); }); } QSharedPointer GameList::GetSelectedGame() const diff --git a/Source/Core/DolphinWX/Frame.cpp b/Source/Core/DolphinWX/Frame.cpp index 7bc9daab15..c4f9cd7dd1 100644 --- a/Source/Core/DolphinWX/Frame.cpp +++ b/Source/Core/DolphinWX/Frame.cpp @@ -143,7 +143,7 @@ void CRenderFrame::OnDropFiles(wxDropFilesEvent& event) } else { - DVDInterface::ChangeDiscAsHost(filepath); + Core::RunAsCPUThread([&filepath] { DVDInterface::ChangeDisc(filepath); }); } } @@ -961,6 +961,8 @@ static int GetMenuIDFromHotkey(unsigned int key) return wxID_OPEN; case HK_CHANGE_DISC: return IDM_CHANGE_DISC; + case HK_EJECT_DISC: + return IDM_EJECT_DISC; case HK_REFRESH_LIST: return wxID_REFRESH; case HK_PLAY_PAUSE: @@ -1305,6 +1307,7 @@ void CFrame::ParseHotkeys() { case HK_OPEN: case HK_CHANGE_DISC: + case HK_EJECT_DISC: case HK_REFRESH_LIST: case HK_RESET: case HK_START_RECORDING: diff --git a/Source/Core/DolphinWX/Frame.h b/Source/Core/DolphinWX/Frame.h index cb5364155d..a7005841ef 100644 --- a/Source/Core/DolphinWX/Frame.h +++ b/Source/Core/DolphinWX/Frame.h @@ -299,6 +299,7 @@ private: void OnShowInputDisplay(wxCommandEvent& event); void OnShowRTCDisplay(wxCommandEvent& event); void OnChangeDisc(wxCommandEvent& event); + void OnEjectDisc(wxCommandEvent& event); void OnScreenshot(wxCommandEvent& event); void OnActive(wxActivateEvent& event); void OnClose(wxCloseEvent& event); diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp index 89726223dc..0db98e74ea 100644 --- a/Source/Core/DolphinWX/FrameTools.cpp +++ b/Source/Core/DolphinWX/FrameTools.cpp @@ -127,6 +127,7 @@ void CFrame::BindMenuBarEvents() // File menu Bind(wxEVT_MENU, &CFrame::OnOpen, this, wxID_OPEN); Bind(wxEVT_MENU, &CFrame::OnChangeDisc, this, IDM_CHANGE_DISC); + Bind(wxEVT_MENU, &CFrame::OnEjectDisc, this, IDM_EJECT_DISC); Bind(wxEVT_MENU, &CFrame::OnBootDrive, this, IDM_DRIVE1, IDM_DRIVE24); Bind(wxEVT_MENU, &CFrame::OnRefresh, this, wxID_REFRESH); Bind(wxEVT_MENU, &CFrame::OnQuit, this, wxID_EXIT); @@ -369,7 +370,7 @@ void CFrame::DoOpen(bool Boot) } else { - DVDInterface::ChangeDiscAsHost(WxStrToStr(path)); + Core::RunAsCPUThread([&path] { DVDInterface::ChangeDisc(WxStrToStr(path)); }); } } @@ -459,6 +460,11 @@ void CFrame::OnChangeDisc(wxCommandEvent& WXUNUSED(event)) DoOpen(false); } +void CFrame::OnEjectDisc(wxCommandEvent& WXUNUSED(event)) +{ + Core::RunAsCPUThread(DVDInterface::EjectDisc); +} + void CFrame::OnRecord(wxCommandEvent& WXUNUSED(event)) { if ((!Core::IsRunningAndStarted() && Core::IsRunning()) || Movie::IsRecordingInput() || diff --git a/Source/Core/DolphinWX/GameListCtrl.cpp b/Source/Core/DolphinWX/GameListCtrl.cpp index 5d91ca7193..ceb6894776 100644 --- a/Source/Core/DolphinWX/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/GameListCtrl.cpp @@ -1557,7 +1557,7 @@ void GameListCtrl::OnChangeDisc(wxCommandEvent& WXUNUSED(event)) const GameListItem* iso = GetSelectedISO(); if (!iso || !Core::IsRunning()) return; - DVDInterface::ChangeDiscAsHost(WxStrToStr(iso->GetFileName())); + Core::RunAsCPUThread([&iso] { DVDInterface::ChangeDisc(WxStrToStr(iso->GetFileName())); }); } void GameListCtrl::OnSize(wxSizeEvent& event) diff --git a/Source/Core/DolphinWX/Globals.h b/Source/Core/DolphinWX/Globals.h index b72cf2686b..dad9550cd7 100644 --- a/Source/Core/DolphinWX/Globals.h +++ b/Source/Core/DolphinWX/Globals.h @@ -94,6 +94,7 @@ enum IDM_CHEATS, IDM_NETPLAY, IDM_RESTART, + IDM_EJECT_DISC, IDM_CHANGE_DISC, IDM_LIST_CHANGE_DISC, IDM_PROPERTIES, diff --git a/Source/Core/DolphinWX/MainMenuBar.cpp b/Source/Core/DolphinWX/MainMenuBar.cpp index 71504bf5be..c9b505e891 100644 --- a/Source/Core/DolphinWX/MainMenuBar.cpp +++ b/Source/Core/DolphinWX/MainMenuBar.cpp @@ -79,6 +79,7 @@ wxMenu* MainMenuBar::CreateFileMenu() const auto* const file_menu = new wxMenu; file_menu->Append(wxID_OPEN, _("&Open...")); file_menu->Append(IDM_CHANGE_DISC, _("Change &Disc...")); + file_menu->Append(IDM_EJECT_DISC, _("Eject Disc")); file_menu->Append(IDM_DRIVES, _("&Boot from DVD Backup"), external_drive_menu); file_menu->AppendSeparator(); file_menu->Append(wxID_REFRESH, _("&Refresh Game List"));