Merge pull request #17178 from hrydgard/more-host-cleanup

More Host cleanup
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2023-03-24 18:50:38 +01:00
commit 2f09d29698
20 files changed
+99 -169

No files matched your search

+4
View File
@@ -121,3 +121,7 @@ inline void System_ShareText(const std::string &text) {
inline void System_NotifyUIState(const std::string &state) {
g_requestManager.MakeSystemRequest(SystemRequestType::NOTIFY_UI_STATE, nullptr, state, "", 0);
}
inline void System_SetWindowTitle(const std::string &param) {
g_requestManager.MakeSystemRequest(SystemRequestType::SET_WINDOW_TITLE, nullptr, param, "", 0);
}
+6 -3
View File
@@ -64,16 +64,17 @@ enum class SystemRequestType {
EXIT_APP,
RESTART_APP, // For graphics backend changes
COPY_TO_CLIPBOARD,
SHARE_TEXT,
SET_WINDOW_TITLE,
TOGGLE_FULLSCREEN_STATE,
GRAPHICS_BACKEND_FAILED_ALERT,
NOTIFY_UI_STATE, // Used on Android only. Not a SystemNotification since it takes a parameter.
// High-level hardware control
CAMERA_COMMAND,
GPS_COMMAND,
MICROPHONE_COMMAND,
SHARE_TEXT,
NOTIFY_UI_STATE, // Used on Android only. Not a SystemNotification since it takes a parameter.
};
// Implementations are supposed to process the request, and post the response to the g_RequestManager (see Message.h).
@@ -162,6 +163,8 @@ enum SystemProperty {
SYSPROP_CAN_JIT,
SYSPROP_HAS_DEBUGGER,
SYSPROP_KEYBOARD_LAYOUT,
SYSPROP_SKIP_UI,
+4 -3
View File
@@ -206,12 +206,12 @@ bool SymbolMap::LoadSymbolMap(const Path &filename) {
return started;
}
void SymbolMap::SaveSymbolMap(const Path &filename) const {
bool SymbolMap::SaveSymbolMap(const Path &filename) const {
std::lock_guard<std::recursive_mutex> guard(lock_);
// Don't bother writing a blank file.
if (!File::Exists(filename) && functions.empty() && data.empty()) {
return;
return true;
}
// TODO(scoped): Use gzdopen
@@ -222,7 +222,7 @@ void SymbolMap::SaveSymbolMap(const Path &filename) const {
#endif
if (f == Z_NULL)
return;
return false;
gzprintf(f, ".text\n");
@@ -241,6 +241,7 @@ void SymbolMap::SaveSymbolMap(const Path &filename) const {
gzprintf(f, "%08x %08x %x %i %s\n", e.start, e.size, e.module, ST_DATA, GetLabelNameRel(e.start, e.module));
}
gzclose(f);
return true;
}
bool SymbolMap::LoadNocashSym(const Path &filename) {
+1 -1
View File
@@ -71,7 +71,7 @@ public:
void SortSymbols();
bool LoadSymbolMap(const Path &filename);
void SaveSymbolMap(const Path &filename) const;
bool SaveSymbolMap(const Path &filename) const;
bool LoadNocashSym(const Path &filename);
void SaveNocashSym(const Path &filename) const;
-8
View File
@@ -15,14 +15,6 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include <cstring>
#include "Core/Host.h"
#include "Core/Debugger/SymbolMap.h"
Host *host = nullptr;
bool Host::AttemptLoadSymbolMap() {
g_symbolMap->Clear();
return false;
}
-4
View File
@@ -31,10 +31,6 @@ public:
virtual void PollControllers() {}
virtual void ToggleDebugConsoleVisibility() {}
virtual bool AttemptLoadSymbolMap();
virtual void SaveSymbolMap() {}
virtual void SetWindowTitle(const char *message) {}
virtual bool CreateDesktopShortcut(std::string argumentPath, std::string title) {return false;}
virtual void NotifyUserMessage(const std::string &message, float duration = 1.0f, u32 color = 0x00FFFFFF, const char *id = nullptr) {}
+3 -2
View File
@@ -19,6 +19,7 @@
#include "Common/Data/Encoding/Utf8.h"
#include "Common/Thread/ThreadUtil.h"
#include "Common/System/Request.h"
#include "Common/File/FileUtil.h"
#include "Common/StringUtils.h"
@@ -248,7 +249,7 @@ bool Load_PSP_ISO(FileLoader *fileLoader, std::string *error_string) {
if (g_paramSFO.ReadSFO(paramsfo)) {
std::string title = StringFromFormat("%s : %s", g_paramSFO.GetValueString("DISC_ID").c_str(), g_paramSFO.GetValueString("TITLE").c_str());
INFO_LOG(LOADER, "%s", title.c_str());
host->SetWindowTitle(title.c_str());
System_SetWindowTitle(title);
}
}
@@ -430,7 +431,7 @@ bool Load_PSP_ELF_PBP(FileLoader *fileLoader, std::string *error_string) {
std::string title = StringFromFormat("%s : %s", discID.c_str(), homebrewTitle.c_str());
INFO_LOG(LOADER, "%s", title.c_str());
host->SetWindowTitle(title.c_str());
System_SetWindowTitle(title);
// Migrate old save states from old versions of fake game IDs.
const Path savestateDir = GetSysDirectory(DIRECTORY_SAVESTATE);
+40 -5
View File
@@ -35,13 +35,14 @@
#include "Common/System/System.h"
#include "Common/System/Request.h"
#include "Common/File/Path.h"
#include "Common/File/FileUtil.h"
#include "Common/File/DirListing.h"
#include "Common/Math/math_util.h"
#include "Common/Thread/ThreadUtil.h"
#include "Common/Data/Encoding/Utf8.h"
#include "Common/File/FileUtil.h"
#include "Common/TimeUtil.h"
#include "Common/GraphicsContext.h"
#include "Core/MemFault.h"
#include "Core/HDRemaster.h"
#include "Core/MIPS/MIPS.h"
@@ -173,6 +174,40 @@ bool CPU_HasPendingAction() {
void CPU_Shutdown();
static Path SymbolMapFilename(const Path &currentFilename, const char *ext) {
File::FileInfo info{};
// can't fail, definitely exists if it gets this far
File::GetFileInfo(currentFilename, &info);
if (info.isDirectory) {
return currentFilename / (std::string(".ppsspp-symbols") + ext);
}
return currentFilename.WithReplacedExtension(ext);
};
static bool LoadSymbolsIfSupported() {
if (System_GetPropertyBool(SYSPROP_HAS_DEBUGGER)) {
if (!g_symbolMap)
return false;
bool result1 = g_symbolMap->LoadSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart, ".ppmap"));
// Load the old-style map file.
if (!result1)
result1 = g_symbolMap->LoadSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart, ".map"));
bool result2 = g_symbolMap->LoadNocashSym(SymbolMapFilename(PSP_CoreParameter().fileToStart, ".sym"));
return result1 || result2;
} else {
g_symbolMap->Clear();
return true;
}
}
static bool SaveSymbolMapIfSupported() {
if (g_symbolMap) {
return g_symbolMap->SaveSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart, ".ppmap"));
}
return false;
}
bool DiscIDFromGEDumpPath(const Path &path, FileLoader *fileLoader, std::string *id) {
using namespace GPURecord;
@@ -283,7 +318,7 @@ bool CPU_Init(std::string *errorString) {
}
mipsr4k.Reset();
host->AttemptLoadSymbolMap();
LoadSymbolsIfSupported();
CoreTiming::Init();
@@ -324,7 +359,7 @@ void CPU_Shutdown() {
PSPLoaders_Shutdown();
if (g_Config.bAutoSaveSymbolMap) {
host->SaveSymbolMap();
SaveSymbolMapIfSupported();
}
Replacement_Shutdown();
@@ -522,7 +557,7 @@ void PSP_Shutdown() {
CPU_Shutdown();
GPU_Shutdown();
g_paramSFO.Clear();
host->SetWindowTitle(0);
System_SetWindowTitle("");
currentMIPS = 0;
pspIsInited = false;
pspIsIniting = false;
-4
View File
@@ -16,7 +16,3 @@
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "Qt/QtHost.h"
Path QtHost::SymbolMapFilename(Path currentFilename) {
return currentFilename.WithReplacedExtension(".map");
}
-15
View File
@@ -23,7 +23,6 @@
#include "Qt/mainwindow.h"
#include "Core/Debugger/SymbolMap.h"
class QtHost : public Host {
public:
QtHost(MainWindow *mainWindow_)
@@ -33,24 +32,10 @@ public:
void UpdateSound() override {}
bool AttemptLoadSymbolMap() override {
auto fn = SymbolMapFilename(PSP_CoreParameter().fileToStart);
return g_symbolMap->LoadSymbolMap(fn);
}
void PrepareShutdown() {
auto fn = SymbolMapFilename(PSP_CoreParameter().fileToStart);
g_symbolMap->SaveSymbolMap(fn);
}
void SetWindowTitle(const char *message) override {
std::string title = std::string("PPSSPP ") + PPSSPP_GIT_VERSION;
if (message)
title += std::string(" - ") + message;
#ifdef _DEBUG
title += " (debug)";
#endif
mainWindow->SetWindowTitleAsync(title);
}
void NotifyUserMessage(const std::string &message, float duration = 1.0f, u32 color = 0x00FFFFFF, const char *id = nullptr) override {
osm.Show(message, duration, color, -1, true, id);
+11
View File
@@ -355,6 +355,17 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
case SystemRequestType::COPY_TO_CLIPBOARD:
QApplication::clipboard()->setText(param1.c_str());
return true;
case SystemRequestType::SET_WINDOW_TITLE:
{
std::string title = std::string("PPSSPP ") + PPSSPP_GIT_VERSION;
if (!param1.empty())
title += std::string(" - ") + param1;
#ifdef _DEBUG
title += " (debug)";
#endif
g_mainWindow->SetWindowTitleAsync(title);
return true;
}
case SystemRequestType::INPUT_TEXT_MODAL:
{
g_requestId = requestId;
+1 -3
View File
@@ -18,6 +18,7 @@
#pragma once
#include "Core/Host.h"
#include "Common/System/NativeApp.h"
#include "UI/OnScreenDisplay.h"
class NativeHost : public Host {
@@ -26,9 +27,6 @@ public:
void UpdateSound() override {}
bool AttemptLoadSymbolMap() override {return false;}
void SetWindowTitle(const char *message) override {}
void NotifyUserMessage(const std::string &message, float duration = 1.0f, u32 color = 0x00FFFFFF, const char *id = nullptr) override {
osm.Show(message, duration, color, -1, true, id);
}
-32
View File
@@ -48,15 +48,6 @@ UWPHost::~UWPHost() {
}
void UWPHost::SetConsolePosition() {
}
void UWPHost::UpdateConsolePosition() {
}
void UWPHost::SetWindowTitle(const char *message) {
}
void UWPHost::UpdateSound() {
}
@@ -86,29 +77,6 @@ void UWPHost::PollControllers() {
*/
}
static Path SymbolMapFilename(const Path &currentFilename, const char *ext) {
File::FileInfo info;
// can't fail, definitely exists if it gets this far
File::GetFileInfo(currentFilename, &info);
if (info.isDirectory) {
return currentFilename / (std::string(".ppsspp-symbols") + ext);
}
return currentFilename.WithReplacedExtension(ext);
}
bool UWPHost::AttemptLoadSymbolMap() {
bool result1 = g_symbolMap->LoadSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart, ".ppmap"));
// Load the old-style map file.
if (!result1)
result1 = g_symbolMap->LoadSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart, ".map"));
bool result2 = g_symbolMap->LoadNocashSym(SymbolMapFilename(PSP_CoreParameter().fileToStart, ".sym"));
return result1 || result2;
}
void UWPHost::SaveSymbolMap() {
g_symbolMap->SaveSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart, ".ppmap"));
}
void UWPHost::ToggleDebugConsoleVisibility() {
// N/A
}
-9
View File
@@ -16,19 +16,10 @@ public:
void UpdateSound() override;
bool AttemptLoadSymbolMap() override;
void SaveSymbolMap() override;
void SetWindowTitle(const char *message) override;
void ToggleDebugConsoleVisibility() override;
void NotifyUserMessage(const std::string &message, float duration = 1.0f, u32 color = 0x00FFFFFF, const char *id = nullptr) override;
GraphicsContext *GetGraphicsContext() { return nullptr; }
private:
void SetConsolePosition();
void UpdateConsolePosition();
std::list<std::unique_ptr<InputDevice>> input;
};
+5 -9
View File
@@ -4,6 +4,7 @@
#include "Common/System/NativeApp.h"
#include "Common/System/System.h"
#include "Common/System/Request.h"
#include "Common/Data/Text/I18n.h"
#include "Common/Input/InputState.h"
#include "Common/Data/Encoding/Utf8.h"
@@ -151,16 +152,11 @@ bool CreateGraphicsBackend(std::string *error_message, GraphicsContext **ctx) {
}
void MainThreadFunc() {
if (useEmuThread) {
// We'll start up a separate thread we'll call Emu
SetCurrentThreadName("Render");
} else {
// This is both Emu and Render.
SetCurrentThreadName("Emu");
}
// We'll start up a separate thread we'll call Emu
SetCurrentThreadName(useEmuThread ? "Render" : "Emu");
host = new WindowsHost(MainWindow::GetHInstance(), MainWindow::GetHWND(), MainWindow::GetDisplayHWND());
host->SetWindowTitle(nullptr);
host = new WindowsHost();
System_SetWindowTitle("");
// We convert command line arguments to UTF-8 immediately.
std::vector<std::wstring> wideArgs = GetWideCmdLine();
+4 -57
View File
@@ -44,12 +44,14 @@
#include "Core/Config.h"
#include "Core/ConfigValues.h"
#include "Core/CoreParameter.h"
#include "Core/HLE/Plugins.h"
#include "Core/System.h"
#include "Core/Debugger/SymbolMap.h"
#include "Core/Instance.h"
#include "UI/OnScreenDisplay.h"
#include "Windows/EmuThread.h"
#include "Windows/WindowsAudio.h"
#include "Windows/WindowsHost.h"
#include "Windows/MainWindow.h"
@@ -63,8 +65,6 @@
#include "Windows/XinputDevice.h"
#include "Windows/main.h"
#include "UI/OnScreenDisplay.h"
#include <Core/HLE/Plugins.h>
float g_mouseDeltaX = 0;
float g_mouseDeltaY = 0;
@@ -73,11 +73,7 @@ static BOOL PostDialogMessage(Dialog *dialog, UINT message, WPARAM wParam = 0, L
return PostMessage(dialog->GetDlgHandle(), message, wParam, lParam);
}
WindowsHost::WindowsHost(HINSTANCE hInstance, HWND mainWindow, HWND displayWindow)
: hInstance_(hInstance),
displayWindow_(displayWindow),
mainWindow_(mainWindow)
{
WindowsHost::WindowsHost() {
g_mouseDeltaX = 0;
g_mouseDeltaY = 0;
@@ -109,29 +105,6 @@ void WindowsHost::UpdateConsolePosition() {
}
}
void WindowsHost::SetWindowTitle(const char *message) {
#ifdef GOLD
const char *name = "PPSSPP Gold ";
#else
const char *name = "PPSSPP ";
#endif
std::wstring winTitle = ConvertUTF8ToWString(std::string(name) + PPSSPP_GIT_VERSION);
if (message != nullptr) {
winTitle.append(ConvertUTF8ToWString(" - "));
winTitle.append(ConvertUTF8ToWString(message));
}
#ifdef _DEBUG
winTitle.append(L" (debug)");
#endif
lastTitle_ = winTitle;
MainWindow::SetWindowTitle(winTitle.c_str());
PostMessage(mainWindow_, MainWindow::WM_USER_WINDOW_TITLE_CHANGED, 0, 0);
}
// UGLY!
extern WindowsAudioBackend *winAudioBackend;
void WindowsHost::PollControllers() {
static int checkCounter = 0;
static const int CHECK_FREQUENCY = 71;
@@ -182,32 +155,6 @@ void WindowsHost::PollControllers() {
HLEPlugins::PluginDataAxis[JOYSTICK_AXIS_MOUSE_REL_Y] = g_mouseDeltaY;
}
static Path SymbolMapFilename(const Path &currentFilename, const char *ext) {
File::FileInfo info{};
// can't fail, definitely exists if it gets this far
File::GetFileInfo(currentFilename, &info);
if (info.isDirectory) {
return currentFilename / (std::string(".ppsspp-symbols") + ext);
}
return currentFilename.WithReplacedExtension(ext);
}
bool WindowsHost::AttemptLoadSymbolMap() {
if (!g_symbolMap)
return false;
bool result1 = g_symbolMap->LoadSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart, ".ppmap"));
// Load the old-style map file.
if (!result1)
result1 = g_symbolMap->LoadSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart, ".map"));
bool result2 = g_symbolMap->LoadNocashSym(SymbolMapFilename(PSP_CoreParameter().fileToStart, ".sym"));
return result1 || result2;
}
void WindowsHost::SaveSymbolMap() {
if (g_symbolMap)
g_symbolMap->SaveSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart, ".ppmap"));
}
// http://msdn.microsoft.com/en-us/library/aa969393.aspx
HRESULT CreateLink(LPCWSTR lpszPathObj, LPCWSTR lpszArguments, LPCWSTR lpszPathLink, LPCWSTR lpszDesc) {
HRESULT hres;
+1 -9
View File
@@ -26,7 +26,7 @@ extern float g_mouseDeltaY;
class WindowsHost : public Host {
public:
WindowsHost(HINSTANCE hInstance, HWND mainWindow, HWND displayWindow);
WindowsHost();
~WindowsHost() {
UpdateConsolePosition();
@@ -34,10 +34,6 @@ public:
void PollControllers() override;
bool AttemptLoadSymbolMap() override;
void SaveSymbolMap() override;
void SetWindowTitle(const char *message) override;
void ToggleDebugConsoleVisibility() override;
bool CreateDesktopShortcut(std::string argumentPath, std::string title) override;
@@ -49,11 +45,7 @@ private:
void SetConsolePosition();
void UpdateConsolePosition();
HINSTANCE hInstance_;
HWND displayWindow_;
HWND mainWindow_;
size_t numDinputDevices_ = 0;
std::wstring lastTitle_;
std::list<std::unique_ptr<InputDevice>> input;
};
+19
View File
@@ -351,6 +351,7 @@ float System_GetPropertyFloat(SystemProperty prop) {
bool System_GetPropertyBool(SystemProperty prop) {
switch (prop) {
case SYSPROP_HAS_DEBUGGER:
case SYSPROP_HAS_FILE_BROWSER:
case SYSPROP_HAS_FOLDER_BROWSER:
case SYSPROP_HAS_OPEN_DIRECTORY:
@@ -467,6 +468,24 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
W32Util::CopyTextToClipboard(MainWindow::GetDisplayHWND(), data);
return true;
}
case SystemRequestType::SET_WINDOW_TITLE:
{
#ifdef GOLD
const char *name = "PPSSPP Gold ";
#else
const char *name = "PPSSPP ";
#endif
std::wstring winTitle = ConvertUTF8ToWString(std::string(name) + PPSSPP_GIT_VERSION);
if (!param1.empty()) {
winTitle.append(ConvertUTF8ToWString(" - " + param1));
}
#ifdef _DEBUG
winTitle.append(L" (debug)");
#endif
MainWindow::SetWindowTitle(winTitle.c_str());
PostMessage(MainWindow::GetHWND(), MainWindow::WM_USER_WINDOW_TITLE_CHANGED, 0, 0);
return true;
}
case SystemRequestType::INPUT_TEXT_MODAL:
if (g_dialogRunning) {
g_dialogThread.join();
-4
View File
@@ -28,10 +28,6 @@ public:
virtual bool InitGraphics(std::string *error_message, GraphicsContext **ctx, GPUCore core) {return false;}
virtual void ShutdownGraphics() {}
void UpdateSound() override {}
bool AttemptLoadSymbolMap() override { g_symbolMap->Clear(); return false; }
void SendDebugOutput(const std::string &output) override {
if (output.find('\n') != output.npos) {
DoFlushDebugOutput();
-1
View File
@@ -396,7 +396,6 @@ class LibretroHost : public Host
int samples = __AudioMix(audio, hostAttemptBlockSize, SAMPLERATE);
AudioBufferWrite(audio, samples);
}
bool AttemptLoadSymbolMap() override { return false; }
};
class PrintfLogger : public LogListener