From b899a178bfed63bdaafdfb00dba8065fa35fa4f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 18 Jan 2024 17:57:14 +0100 Subject: [PATCH] Change approach (call from NativeFrame instead). Add Mac support --- Common/System/System.h | 1 + Core/Core.cpp | 15 --------------- Core/Core.h | 1 - SDL/CocoaBarItems.mm | 9 +++++++++ UI/NativeApp.cpp | 13 ++++++++++++- Windows/MainWindowMenu.cpp | 2 +- 6 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Common/System/System.h b/Common/System/System.h index 74ade8dece2c..70cc763db853 100644 --- a/Common/System/System.h +++ b/Common/System/System.h @@ -246,6 +246,7 @@ enum class UIMessage { SAVESTATE_DISPLAY_SLOT, GAMESETTINGS_SEARCH, SAVEDATA_SEARCH, + RESTART_GRAPHICS, }; std::string System_GetProperty(SystemProperty prop); diff --git a/Core/Core.cpp b/Core/Core.cpp index 3ec1df186df9..8add9989c863 100644 --- a/Core/Core.cpp +++ b/Core/Core.cpp @@ -61,7 +61,6 @@ static std::set lifecycleFuncs; static std::set stopFuncs; static bool windowHidden = false; static bool powerSaving = false; -static bool g_restartGraphics = false; static MIPSExceptionInfo g_exceptionInfo; @@ -212,10 +211,6 @@ void UpdateRunLoop(GraphicsContext *ctx) { } } -void Core_DebugRestartGraphics() { - g_restartGraphics = true; -} - // Note: not used on Android. void Core_RunLoop(GraphicsContext *ctx) { if (windowHidden && g_Config.bPauseWhenMinimized) { @@ -223,16 +218,6 @@ void Core_RunLoop(GraphicsContext *ctx) { return; } -#if PPSSPP_PLATFORM(WINDOWS) - // This can only be accessed from Windows currently, and causes linking errors with headless etc. - if (g_restartGraphics) { - // Used for debugging only. - NativeShutdownGraphics(); - NativeInitGraphics(ctx); - g_restartGraphics = false; - } -#endif - NativeFrame(ctx); } diff --git a/Core/Core.h b/Core/Core.h index cbab7ce5972c..b2166cee7b09 100644 --- a/Core/Core.h +++ b/Core/Core.h @@ -44,7 +44,6 @@ bool Core_NextFrame(); void Core_DoSingleStep(); void Core_UpdateSingleStep(); void Core_ProcessStepping(); -void Core_DebugRestartGraphics(); // Changes every time we enter stepping. int Core_GetSteppingCounter(); diff --git a/SDL/CocoaBarItems.mm b/SDL/CocoaBarItems.mm index e518c2ab1242..fc6ca65355f5 100644 --- a/SDL/CocoaBarItems.mm +++ b/SDL/CocoaBarItems.mm @@ -405,6 +405,10 @@ -(NSMenu *)makeDebugMenu { copyBaseAddr.target = self; copyBaseAddr.tag = 11; + NSMenuItem *restartGraphicsAction = [[NSMenuItem alloc] initWithTitle:DESKTOPUI_LOCALIZED("Restart Graphics") action:@selector(restartGraphics) keyEquivalent:@""]; + restartGraphicsAction.target = self; + restartGraphicsAction.tag = 12; + MENU_ITEM(showDebugStatsAction, DESKTOPUI_LOCALIZED("Show Debug Statistics"), @selector(toggleShowDebugStats:), ((DebugOverlay)g_Config.iDebugOverlay == DebugOverlay::DEBUG_STATS), 12) [parent addItem:loadSymbolMapAction]; @@ -421,6 +425,7 @@ -(NSMenu *)makeDebugMenu { [parent addItem:takeScreenshotAction]; [parent addItem:dumpNextFrameToLogAction]; [parent addItem:showDebugStatsAction]; + [parent addItem:restartGraphicsAction]; [parent addItem:[NSMenuItem separatorItem]]; [parent addItem:copyBaseAddr]; @@ -462,6 +467,10 @@ -(void)copyAddr { [NSPasteboard.generalPasteboard setString:stringToCopy forType:NSPasteboardTypeString]; } +-(void)restartGraphics { + System_PostUIMessage(UIMessage::RESTART_GRAPHICS); +} + -(NSURL *)presentOpenPanelWithAllowedFileTypes: (NSArray *)allowedFileTypes { NSOpenPanel *openPanel = [[NSOpenPanel alloc] init]; openPanel.allowedFileTypes = allowedFileTypes; diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index e418b690224c..5e123f0256c1 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -183,6 +183,7 @@ static Draw::DrawContext *g_draw; static Draw::Pipeline *colorPipeline; static Draw::Pipeline *texColorPipeline; static UIContext *uiContext; +static bool g_restartGraphics; #ifdef _WIN32 WindowsAudioBackend *winAudioBackend; @@ -1035,6 +1036,14 @@ static void SendMouseDeltaAxis(); void NativeFrame(GraphicsContext *graphicsContext) { PROFILE_END_FRAME(); + // This can only be accessed from Windows currently, and causes linking errors with headless etc. + if (g_restartGraphics) { + // Used for debugging only. + NativeShutdownGraphics(); + NativeInitGraphics(graphicsContext); + g_restartGraphics = false; + } + double startTime = time_now_d(); ProcessWheelRelease(NKCODE_EXT_MOUSEWHEEL_UP, startTime, false); @@ -1173,7 +1182,9 @@ void NativeFrame(GraphicsContext *graphicsContext) { } bool HandleGlobalMessage(UIMessage message, const std::string &value) { - if (message == UIMessage::SAVESTATE_DISPLAY_SLOT) { + if (message == UIMessage::RESTART_GRAPHICS) { + g_restartGraphics = true; + } else if (message == UIMessage::SAVESTATE_DISPLAY_SLOT) { auto sy = GetI18NCategory(I18NCat::SYSTEM); std::string msg = StringFromFormat("%s: %d", sy->T("Savestate Slot"), SaveState::GetCurrentSlot() + 1); // Show for the same duration as the preview. diff --git a/Windows/MainWindowMenu.cpp b/Windows/MainWindowMenu.cpp index 88b436e7229a..65538da423b5 100644 --- a/Windows/MainWindowMenu.cpp +++ b/Windows/MainWindowMenu.cpp @@ -926,7 +926,7 @@ namespace MainWindow { break; case ID_DEBUG_RESTARTGRAPHICS: - Core_DebugRestartGraphics(); + System_PostUIMessage(UIMessage::RESTART_GRAPHICS); break; case ID_FILE_DUMPFRAMES: