Skip to content

Commit

Permalink
Merge pull request #17671 from hrydgard/android-message-cleanup
Browse files Browse the repository at this point in the history
Android string message cleanup
  • Loading branch information
hrydgard committed Jul 6, 2023
2 parents 30f470a + b15b283 commit e1060c8
Show file tree
Hide file tree
Showing 30 changed files with 174 additions and 134 deletions.
3 changes: 0 additions & 3 deletions Common/System/NativeApp.h
Expand Up @@ -20,9 +20,6 @@ class GraphicsContext;
// This might get called multiple times in some implementations, you must be able to handle that.
void NativeGetAppInfo(std::string *app_dir_name, std::string *app_nice_name, bool *landscape, std::string *version);

// Generic host->C++ messaging, used for functionality like system-native popup input boxes.
void NativeMessageReceived(const char *message, const char *value);

// Easy way for the Java side to ask the C++ side for configuration options, such as
// the rotation lock which must be controlled from Java on Android.
// It is currently not called on non-Android platforms.
Expand Down
2 changes: 1 addition & 1 deletion Common/System/System.h
Expand Up @@ -211,7 +211,7 @@ std::vector<std::string> System_GetCameraDeviceList();
bool System_AudioRecordingIsAvailable();
bool System_AudioRecordingState();

// This will be changed to take an enum. Currently simply implemented by forwarding to NativeMessageReceived.
// This will be changed to take an enum. Replacement for the old NativeMessageReceived.
void System_PostUIMessage(const std::string &message, const std::string &param);

// For these functions, most platforms will use the implementation provided in UI/AudioCommon.cpp,
Expand Down
3 changes: 3 additions & 0 deletions Core/KeyMap.cpp
Expand Up @@ -780,6 +780,7 @@ bool HasBuiltinController(const std::string &name) {
}

void NotifyPadConnected(InputDeviceID deviceId, const std::string &name) {
std::lock_guard<std::recursive_mutex> guard(g_controllerMapLock);
g_seenPads.insert(name);
g_padNames[deviceId] = name;
}
Expand Down Expand Up @@ -812,10 +813,12 @@ void AutoConfForPad(const std::string &name) {
}

const std::set<std::string> &GetSeenPads() {
std::lock_guard<std::recursive_mutex> guard(g_controllerMapLock);
return g_seenPads;
}

std::string PadName(InputDeviceID deviceId) {
std::lock_guard<std::recursive_mutex> guard(g_controllerMapLock);
auto it = g_padNames.find(deviceId);
if (it != g_padNames.end())
return it->second;
Expand Down
2 changes: 1 addition & 1 deletion Qt/QtMain.cpp
Expand Up @@ -537,7 +537,7 @@ QString MainUI::InputBoxGetQString(QString title, QString defaultValue) {

void MainUI::resizeGL(int w, int h) {
if (UpdateScreenScale(w, h)) {
NativeMessageReceived("gpu_displayResized", "");
System_PostUIMessage("gpu_displayResized", "");
}
xscale = w / this->width();
yscale = h / this->height();
Expand Down
12 changes: 6 additions & 6 deletions Qt/mainwindow.cpp
Expand Up @@ -130,15 +130,15 @@ void MainWindow::loadAct()
{
QFileInfo info(filename);
g_Config.currentDirectory = Path(info.absolutePath().toStdString());
NativeMessageReceived("boot", filename.toStdString().c_str());
System_PostUIMessage("boot", filename.toStdString().c_str());
}
}

void MainWindow::closeAct()
{
updateMenus();

NativeMessageReceived("stop", "");
System_PostUIMessage("stop", "");
SetGameTitle("");
}

Expand Down Expand Up @@ -232,25 +232,25 @@ void MainWindow::exitAct()

void MainWindow::runAct()
{
NativeMessageReceived("run", "");
System_PostUIMessage("run", "");
}

void MainWindow::pauseAct()
{
NativeMessageReceived("pause", "");
System_PostUIMessage("pause", "");
}

void MainWindow::stopAct()
{
Core_Stop();
NativeMessageReceived("stop", "");
System_PostUIMessage("stop", "");
}

void MainWindow::resetAct()
{
updateMenus();

NativeMessageReceived("reset", "");
System_PostUIMessage("reset", "");
}

void MainWindow::switchUMDAct()
Expand Down
28 changes: 14 additions & 14 deletions Qt/mainwindow.h
Expand Up @@ -113,28 +113,28 @@ private slots:
void consoleAct();

// Game settings
void languageAct() { NativeMessageReceived("language screen", ""); }
void controlMappingAct() { NativeMessageReceived("control mapping", ""); }
void displayLayoutEditorAct() { NativeMessageReceived("display layout editor", ""); }
void moreSettingsAct() { NativeMessageReceived("settings", ""); }
void languageAct() { System_PostUIMessage("language screen", ""); }
void controlMappingAct() { System_PostUIMessage("control mapping", ""); }
void displayLayoutEditorAct() { System_PostUIMessage("display layout editor", ""); }
void moreSettingsAct() { System_PostUIMessage("settings", ""); }

void bufferRenderAct() {
NativeMessageReceived("gpu_renderResized", "");
NativeMessageReceived("gpu_configChanged", "");
System_PostUIMessage("gpu_renderResized", "");
System_PostUIMessage("gpu_configChanged", "");
}
void linearAct() { g_Config.iTexFiltering = (g_Config.iTexFiltering != 0) ? 0 : 3; }

void renderingResolutionGroup_triggered(QAction *action) {
g_Config.iInternalResolution = action->data().toInt();
NativeMessageReceived("gpu_renderResized", "");
System_PostUIMessage("gpu_renderResized", "");
}
void windowGroup_triggered(QAction *action) { SetWindowScale(action->data().toInt()); }

void autoframeskipAct() {
g_Config.bAutoFrameSkip = !g_Config.bAutoFrameSkip;
if (g_Config.bSkipBufferEffects) {
g_Config.bSkipBufferEffects = false;
NativeMessageReceived("gpu_configChanged", "");
System_PostUIMessage("gpu_configChanged", "");
}
}
void frameSkippingGroup_triggered(QAction *action) { g_Config.iFrameSkip = action->data().toInt(); }
Expand All @@ -143,19 +143,19 @@ private slots:
void screenScalingFilterGroup_triggered(QAction *action) { g_Config.iDisplayFilter = action->data().toInt(); }
void textureScalingLevelGroup_triggered(QAction *action) {
g_Config.iTexScalingLevel = action->data().toInt();
NativeMessageReceived("gpu_configChanged", "");
System_PostUIMessage("gpu_configChanged", "");
}
void textureScalingTypeGroup_triggered(QAction *action) {
g_Config.iTexScalingType = action->data().toInt();
NativeMessageReceived("gpu_configChanged", "");
System_PostUIMessage("gpu_configChanged", "");
}
void deposterizeAct() {
g_Config.bTexDeposterize = !g_Config.bTexDeposterize;
NativeMessageReceived("gpu_configChanged", "");
System_PostUIMessage("gpu_configChanged", "");
}
void transformAct() {
g_Config.bHardwareTransform = !g_Config.bHardwareTransform;
NativeMessageReceived("gpu_configChanged", "");
System_PostUIMessage("gpu_configChanged", "");
}
void vertexCacheAct() { g_Config.bVertexCache = !g_Config.bVertexCache; }
void frameskipAct() { g_Config.iFrameSkip = !g_Config.iFrameSkip; }
Expand All @@ -172,15 +172,15 @@ private slots:
// Chat
void chatAct() {
if (GetUIState() == UISTATE_INGAME) {
NativeMessageReceived("chat screen", "");
System_PostUIMessage("chat screen", "");
}
}

void fullscrAct();
void raiseTopMost();
void statsAct() {
g_Config.bShowDebugStats = !g_Config.bShowDebugStats;
NativeMessageReceived("clear jit", "");
System_PostUIMessage("clear jit", "");
}

// Help
Expand Down
12 changes: 6 additions & 6 deletions SDL/CocoaBarItems.mm
Expand Up @@ -442,17 +442,17 @@ -(void)breakAction: (NSMenuItem *)item {
}

-(void)pauseAction: (NSMenuItem *)item {
NativeMessageReceived("pause", "");
System_PostUIMessage("pause", "");
}

-(void)resetAction: (NSMenuItem *)item {
NativeMessageReceived("reset", "");
System_PostUIMessage("reset", "");
Core_EnableStepping(false);
}

-(void)chatAction: (NSMenuItem *)item {
if (GetUIState() == UISTATE_INGAME) {
NativeMessageReceived("chat screen", "");
System_PostUIMessage("chat screen", "");
}
}

Expand Down Expand Up @@ -541,7 +541,7 @@ -(void)toggle##name: (NSMenuItem *)item { \
TOGGLE_METHOD(SoftwareRendering, g_Config.bSoftwareRendering)
TOGGLE_METHOD(FullScreen, g_Config.bFullScreen, System_MakeRequest(SystemRequestType::TOGGLE_FULLSCREEN_STATE, 0, g_Config.UseFullScreen() ? "1" : "0", "", 3))
// TOGGLE_METHOD(VSync, g_Config.bVSync)
TOGGLE_METHOD(ShowDebugStats, g_Config.bShowDebugStats, NativeMessageReceived("clear jit", ""))
TOGGLE_METHOD(ShowDebugStats, g_Config.bShowDebugStats, System_PostUIMessage("clear jit", ""))
#undef TOGGLE_METHOD

-(void)setToggleShowCounterItem: (NSMenuItem *)item {
Expand Down Expand Up @@ -622,14 +622,14 @@ -(void)addOpenRecentlyItem {
}

-(void)openRecentItem: (NSMenuItem *)item {
NativeMessageReceived("boot", g_Config.RecentIsos()[item.tag].c_str());
System_PostUIMessage("boot", g_Config.RecentIsos()[item.tag].c_str());
}

-(void)openSystemFileBrowser {
int g = 0;
DarwinDirectoryPanelCallback callback = [g] (bool succ, Path thePathChosen) {
if (succ)
NativeMessageReceived("boot", thePathChosen.c_str());
System_PostUIMessage("boot", thePathChosen.c_str());
};

DarwinFileSystemServices services;
Expand Down
16 changes: 8 additions & 8 deletions UI/DisplayLayoutScreen.cpp
Expand Up @@ -155,9 +155,9 @@ UI::EventReturn DisplayLayoutScreen::OnPostProcShaderChange(UI::EventParams &e)
g_Config.vPostShaderNames.erase(std::remove(g_Config.vPostShaderNames.begin(), g_Config.vPostShaderNames.end(), "Off"), g_Config.vPostShaderNames.end());
FixPostShaderOrder(&g_Config.vPostShaderNames);

NativeMessageReceived("gpu_configChanged", "");
NativeMessageReceived("gpu_renderResized", ""); // To deal with shaders that can change render resolution like upscaling.
NativeMessageReceived("postshader_updated", "");
System_PostUIMessage("gpu_configChanged", "");
System_PostUIMessage("gpu_renderResized", ""); // To deal with shaders that can change render resolution like upscaling.
System_PostUIMessage("postshader_updated", "");

if (gpu) {
gpu->NotifyConfigChanged();
Expand Down Expand Up @@ -381,7 +381,7 @@ void DisplayLayoutScreen::CreateViews() {
auto removeButton = shaderRow->Add(new Choice(ImageID("I_TRASHCAN"), new LinearLayoutParams(0.0f)));
removeButton->OnClick.Add([=](EventParams &e) -> UI::EventReturn {
g_Config.vPostShaderNames.erase(g_Config.vPostShaderNames.begin() + i);
NativeMessageReceived("gpu_configChanged", "");
System_PostUIMessage("gpu_configChanged", "");
RecreateViews();
return UI::EVENT_DONE;
});
Expand Down Expand Up @@ -409,7 +409,7 @@ void DisplayLayoutScreen::CreateViews() {
return UI::EVENT_DONE;
}
FixPostShaderOrder(&g_Config.vPostShaderNames);
NativeMessageReceived("gpu_configChanged", "");
System_PostUIMessage("gpu_configChanged", "");
RecreateViews();
return UI::EVENT_DONE;
});
Expand Down Expand Up @@ -493,18 +493,18 @@ void PostProcScreen::OnCompleted(DialogResult result) {
if (showStereoShaders_) {
if (g_Config.sStereoToMonoShader != value) {
g_Config.sStereoToMonoShader = value;
NativeMessageReceived("gpu_configChanged", "");
System_PostUIMessage("gpu_configChanged", "");
}
} else {
if (id_ < (int)g_Config.vPostShaderNames.size()) {
if (g_Config.vPostShaderNames[id_] != value) {
g_Config.vPostShaderNames[id_] = value;
NativeMessageReceived("gpu_configChanged", "");
System_PostUIMessage("gpu_configChanged", "");
}
}
else {
g_Config.vPostShaderNames.push_back(value);
NativeMessageReceived("gpu_configChanged", "");
System_PostUIMessage("gpu_configChanged", "");
}
}
}
12 changes: 6 additions & 6 deletions UI/EmuScreen.cpp
Expand Up @@ -428,7 +428,7 @@ EmuScreen::~EmuScreen() {
void EmuScreen::dialogFinished(const Screen *dialog, DialogResult result) {
// TODO: improve the way with which we got commands from PauseMenu.
// DR_CANCEL/DR_BACK means clicked on "continue", DR_OK means clicked on "back to menu",
// DR_YES means a message sent to PauseMenu by NativeMessageReceived.
// DR_YES means a message sent to PauseMenu by System_PostUIMessage.
if (result == DR_OK || quit_) {
screenManager()->switchScreen(new MainScreen());
quit_ = false;
Expand Down Expand Up @@ -709,13 +709,13 @@ void EmuScreen::onVKey(int virtualKeyCode, bool down) {
case VIRTKEY_PREVIOUS_SLOT:
if (down) {
SaveState::PrevSlot();
NativeMessageReceived("savestate_displayslot", "");
System_PostUIMessage("savestate_displayslot", "");
}
break;
case VIRTKEY_NEXT_SLOT:
if (down) {
SaveState::NextSlot();
NativeMessageReceived("savestate_displayslot", "");
System_PostUIMessage("savestate_displayslot", "");
}
break;
case VIRTKEY_TOGGLE_FULLSCREEN:
Expand All @@ -733,7 +733,7 @@ void EmuScreen::onVKey(int virtualKeyCode, bool down) {
g_Config.bSaveNewTextures = !g_Config.bSaveNewTextures;
if (g_Config.bSaveNewTextures) {
g_OSD.Show(OSDType::MESSAGE_INFO, sc->T("saveNewTextures_true", "Textures will now be saved to your storage"), 2.0);
NativeMessageReceived("gpu_configChanged", "");
System_PostUIMessage("gpu_configChanged", "");
} else {
g_OSD.Show(OSDType::MESSAGE_INFO, sc->T("saveNewTextures_false", "Texture saving was disabled"), 2.0);
}
Expand All @@ -746,7 +746,7 @@ void EmuScreen::onVKey(int virtualKeyCode, bool down) {
g_OSD.Show(OSDType::MESSAGE_INFO, sc->T("replaceTextures_true", "Texture replacement enabled"), 2.0);
else
g_OSD.Show(OSDType::MESSAGE_INFO, sc->T("replaceTextures_false", "Textures no longer are being replaced"), 2.0);
NativeMessageReceived("gpu_configChanged", "");
System_PostUIMessage("gpu_configChanged", "");
}
break;
case VIRTKEY_RAPID_FIRE:
Expand Down Expand Up @@ -1037,7 +1037,7 @@ UI::EventReturn EmuScreen::OnResume(UI::EventParams &params) {

UI::EventReturn EmuScreen::OnReset(UI::EventParams &params) {
if (coreState == CoreState::CORE_RUNTIME_ERROR) {
NativeMessageReceived("reset", "");
System_PostUIMessage("reset", "");
}
return UI::EVENT_DONE;
}
Expand Down
16 changes: 8 additions & 8 deletions UI/GameSettingsScreen.cpp
Expand Up @@ -297,7 +297,7 @@ void GameSettingsScreen::CreateGraphicsSettings(UI::ViewGroup *graphicsSettings)
static const char *msaaModes[] = { "Off", "2x", "4x", "8x", "16x" };
auto msaaChoice = graphicsSettings->Add(new PopupMultiChoice(&g_Config.iMultiSampleLevel, gr->T("Antialiasing (MSAA)"), msaaModes, 0, ARRAY_SIZE(msaaModes), I18NCat::GRAPHICS, screenManager()));
msaaChoice->OnChoice.Add([&](UI::EventParams &) -> UI::EventReturn {
NativeMessageReceived("gpu_renderResized", "");
System_PostUIMessage("gpu_renderResized", "");
return UI::EVENT_DONE;
});
msaaChoice->SetDisabledPtr(&g_Config.bSoftwareRendering);
Expand Down Expand Up @@ -388,7 +388,7 @@ void GameSettingsScreen::CreateGraphicsSettings(UI::ViewGroup *graphicsSettings)
settingInfo_->Show(gr->T("RenderingMode NonBuffered Tip", "Faster, but graphics may be missing in some games"), e.v);
g_Config.bAutoFrameSkip = false;
}
NativeMessageReceived("gpu_renderResized", "");
System_PostUIMessage("gpu_renderResized", "");
return UI::EVENT_DONE;
});
skipBufferEffects->SetDisabledPtr(&g_Config.bSoftwareRendering);
Expand Down Expand Up @@ -1147,7 +1147,7 @@ UI::EventReturn GameSettingsScreen::OnSustainedPerformanceModeChange(UI::EventPa
}

UI::EventReturn GameSettingsScreen::OnJitAffectingSetting(UI::EventParams &e) {
NativeMessageReceived("clear jit", "");
System_PostUIMessage("clear jit", "");
return UI::EVENT_DONE;
}

Expand Down Expand Up @@ -1263,7 +1263,7 @@ UI::EventReturn GameSettingsScreen::OnResolutionChange(UI::EventParams &e) {
System_RecreateActivity();
}
Reporting::UpdateConfig();
NativeMessageReceived("gpu_renderResized", "");
System_PostUIMessage("gpu_renderResized", "");
return UI::EVENT_DONE;
}

Expand Down Expand Up @@ -1292,7 +1292,7 @@ void GameSettingsScreen::onFinish(DialogResult result) {

// Wipe some caches after potentially changing settings.
// Let's not send resize messages here, handled elsewhere.
NativeMessageReceived("gpu_configChanged", "");
System_PostUIMessage("gpu_configChanged", "");
}

void GameSettingsScreen::dialogFinished(const Screen *dialog, DialogResult result) {
Expand Down Expand Up @@ -1538,7 +1538,7 @@ UI::EventReturn GameSettingsScreen::OnTextureShader(UI::EventParams &e) {
}

UI::EventReturn GameSettingsScreen::OnTextureShaderChange(UI::EventParams &e) {
NativeMessageReceived("gpu_configChanged", "");
System_PostUIMessage("gpu_configChanged", "");
RecreateViews(); // Update setting name
g_Config.bTexHardwareScaling = g_Config.sTextureShaderName != "Off";
return UI::EVENT_DONE;
Expand Down Expand Up @@ -1727,7 +1727,7 @@ void DeveloperToolsScreen::CreateViews() {

void DeveloperToolsScreen::onFinish(DialogResult result) {
g_Config.Save("DeveloperToolsScreen::onFinish");
NativeMessageReceived("gpu_configChanged", "");
System_PostUIMessage("gpu_configChanged", "");
}

void GameSettingsScreen::CallbackRestoreDefaults(bool yes) {
Expand Down Expand Up @@ -1808,7 +1808,7 @@ UI::EventReturn DeveloperToolsScreen::OnTouchscreenTest(UI::EventParams &e) {
}

UI::EventReturn DeveloperToolsScreen::OnJitAffectingSetting(UI::EventParams &e) {
NativeMessageReceived("clear jit", "");
System_PostUIMessage("clear jit", "");
return UI::EVENT_DONE;
}

Expand Down

0 comments on commit e1060c8

Please sign in to comment.