Qt: Use Qt 6.8 thread helpers

This commit is contained in:
Stenzek 2024-10-20 13:37:45 +10:00
parent 45f782962e
commit b277035734
No known key found for this signature in database
7 changed files with 72 additions and 73 deletions

View File

@ -9,7 +9,7 @@ endif()
set(THREADS_PREFER_PTHREAD_FLAG ON) set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
find_package(SDL2 2.30.7 REQUIRED) find_package(SDL2 2.30.8 REQUIRED)
find_package(Zstd 1.5.6 REQUIRED) find_package(Zstd 1.5.6 REQUIRED)
find_package(WebP REQUIRED) # v1.4.0, spews an error on Linux because no pkg-config. find_package(WebP REQUIRED) # v1.4.0, spews an error on Linux because no pkg-config.
find_package(ZLIB REQUIRED) # 1.3, but Mac currently doesn't use it. find_package(ZLIB REQUIRED) # 1.3, but Mac currently doesn't use it.
@ -38,6 +38,10 @@ if(ENABLE_WAYLAND)
find_package(Wayland REQUIRED Egl) find_package(Wayland REQUIRED Egl)
endif() endif()
if(BUILD_QT_FRONTEND)
find_package(Qt6 6.8.0 COMPONENTS Core Gui Widgets LinguistTools REQUIRED)
endif()
find_package(Shaderc REQUIRED) find_package(Shaderc REQUIRED)
find_package(spirv_cross_c_shared REQUIRED) find_package(spirv_cross_c_shared REQUIRED)

View File

@ -3,14 +3,14 @@
app-id: "org.duckstation.DuckStation" app-id: "org.duckstation.DuckStation"
runtime: "org.kde.Platform" runtime: "org.kde.Platform"
runtime-version: "6.7" runtime-version: "6.8"
sdk: "org.kde.Sdk" sdk: "org.kde.Sdk"
sdk-extensions: sdk-extensions:
- "org.freedesktop.Sdk.Extension.llvm17" - "org.freedesktop.Sdk.Extension.llvm17"
add-extensions: add-extensions:
"org.freedesktop.Platform.ffmpeg-full": "org.freedesktop.Platform.ffmpeg-full":
directory: "lib/ffmpeg" directory: "lib/ffmpeg"
version: "23.08" version: "24.08"
add-ld-path: "." add-ld-path: "."
autodownload: true autodownload: true

View File

@ -27,9 +27,9 @@ depends=('libjpeg.so' # libjpeg or libjpeg-turbo
'libwebp' 'libwebp'
'libx11' 'libx11'
'libxrandr' 'libxrandr'
'qt6-base' 'qt6-base>=6.8.0'
'qt6-imageformats' 'qt6-imageformats>=6.8.0'
'qt6-svg' 'qt6-svg>=6.8.0'
'wayland' 'wayland'
'zlib' 'zlib'
'zstd' 'zstd'
@ -45,7 +45,7 @@ makedepends=('base-devel'
'lld' 'lld'
'llvm' 'llvm'
'ninja' 'ninja'
'qt6-tools') 'qt6-tools>=6.8.0')
source=( source=(
"${pkgname}::git+file://${startdir}/../../.." "${pkgname}::git+file://${startdir}/../../.."

View File

@ -1,5 +1,3 @@
find_package(Qt6 6.7.2 COMPONENTS Core Gui Widgets LinguistTools REQUIRED)
include(CopyBaseTranslations) include(CopyBaseTranslations)
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)

View File

@ -294,7 +294,7 @@ void LogWindow::logCallback(void* pUserParam, const char* channelName, const cha
const QLatin1StringView qchannel((level <= Log::Level::Warning) ? functionName : channelName); const QLatin1StringView qchannel((level <= Log::Level::Warning) ? functionName : channelName);
if (g_emu_thread->isOnUIThread()) if (QThread::isMainThread())
{ {
this_ptr->appendMessage(qchannel, static_cast<u32>(level), qmessage); this_ptr->appendMessage(qchannel, static_cast<u32>(level), qmessage);
} }

View File

@ -655,7 +655,7 @@ void Host::CheckForSettingsChanges(const Settings& old_settings)
void EmuThread::setDefaultSettings(bool system /* = true */, bool controller /* = true */) void EmuThread::setDefaultSettings(bool system /* = true */, bool controller /* = true */)
{ {
if (isOnThread()) if (isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "setDefaultSettings", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "setDefaultSettings", Qt::QueuedConnection);
return; return;
@ -718,7 +718,7 @@ void Host::RequestResizeHostDisplay(s32 new_window_width, s32 new_window_height)
void EmuThread::applySettings(bool display_osd_messages /* = false */) void EmuThread::applySettings(bool display_osd_messages /* = false */)
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "applySettings", Qt::QueuedConnection, Q_ARG(bool, display_osd_messages)); QMetaObject::invokeMethod(this, "applySettings", Qt::QueuedConnection, Q_ARG(bool, display_osd_messages));
return; return;
@ -729,7 +729,7 @@ void EmuThread::applySettings(bool display_osd_messages /* = false */)
void EmuThread::reloadGameSettings(bool display_osd_messages /* = false */) void EmuThread::reloadGameSettings(bool display_osd_messages /* = false */)
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "reloadGameSettings", Qt::QueuedConnection, Q_ARG(bool, display_osd_messages)); QMetaObject::invokeMethod(this, "reloadGameSettings", Qt::QueuedConnection, Q_ARG(bool, display_osd_messages));
return; return;
@ -740,7 +740,7 @@ void EmuThread::reloadGameSettings(bool display_osd_messages /* = false */)
void EmuThread::updateEmuFolders() void EmuThread::updateEmuFolders()
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, &EmuThread::updateEmuFolders, Qt::QueuedConnection); QMetaObject::invokeMethod(this, &EmuThread::updateEmuFolders, Qt::QueuedConnection);
return; return;
@ -751,7 +751,7 @@ void EmuThread::updateEmuFolders()
void EmuThread::updateControllerSettings() void EmuThread::updateControllerSettings()
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, &EmuThread::updateControllerSettings, Qt::QueuedConnection); QMetaObject::invokeMethod(this, &EmuThread::updateControllerSettings, Qt::QueuedConnection);
return; return;
@ -765,7 +765,7 @@ void EmuThread::updateControllerSettings()
void EmuThread::startFullscreenUI() void EmuThread::startFullscreenUI()
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, &EmuThread::startFullscreenUI, Qt::QueuedConnection); QMetaObject::invokeMethod(this, &EmuThread::startFullscreenUI, Qt::QueuedConnection);
return; return;
@ -799,7 +799,7 @@ void EmuThread::startFullscreenUI()
void EmuThread::stopFullscreenUI() void EmuThread::stopFullscreenUI()
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, &EmuThread::stopFullscreenUI, Qt::QueuedConnection); QMetaObject::invokeMethod(this, &EmuThread::stopFullscreenUI, Qt::QueuedConnection);
@ -825,7 +825,7 @@ void EmuThread::stopFullscreenUI()
void EmuThread::bootSystem(std::shared_ptr<SystemBootParameters> params) void EmuThread::bootSystem(std::shared_ptr<SystemBootParameters> params)
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "bootSystem", Qt::QueuedConnection, QMetaObject::invokeMethod(this, "bootSystem", Qt::QueuedConnection,
Q_ARG(std::shared_ptr<SystemBootParameters>, std::move(params))); Q_ARG(std::shared_ptr<SystemBootParameters>, std::move(params)));
@ -848,7 +848,7 @@ void EmuThread::bootSystem(std::shared_ptr<SystemBootParameters> params)
void EmuThread::bootOrLoadState(std::string path) void EmuThread::bootOrLoadState(std::string path)
{ {
DebugAssert(isOnThread()); DebugAssert(isCurrentThread());
if (System::IsValid()) if (System::IsValid())
{ {
@ -869,7 +869,7 @@ void EmuThread::bootOrLoadState(std::string path)
void EmuThread::resumeSystemFromMostRecentState() void EmuThread::resumeSystemFromMostRecentState()
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, &EmuThread::resumeSystemFromMostRecentState, Qt::QueuedConnection); QMetaObject::invokeMethod(this, &EmuThread::resumeSystemFromMostRecentState, Qt::QueuedConnection);
return; return;
@ -891,7 +891,7 @@ void EmuThread::resumeSystemFromMostRecentState()
void EmuThread::onDisplayWindowKeyEvent(int key, bool pressed) void EmuThread::onDisplayWindowKeyEvent(int key, bool pressed)
{ {
DebugAssert(isOnThread()); DebugAssert(isCurrentThread());
InputManager::InvokeEvents(InputManager::MakeHostKeyboardKey(key), static_cast<float>(pressed), InputManager::InvokeEvents(InputManager::MakeHostKeyboardKey(key), static_cast<float>(pressed),
GenericInputBinding::Unknown); GenericInputBinding::Unknown);
@ -899,14 +899,14 @@ void EmuThread::onDisplayWindowKeyEvent(int key, bool pressed)
void EmuThread::onDisplayWindowTextEntered(const QString& text) void EmuThread::onDisplayWindowTextEntered(const QString& text)
{ {
DebugAssert(isOnThread()); DebugAssert(isCurrentThread());
ImGuiManager::AddTextInput(text.toStdString()); ImGuiManager::AddTextInput(text.toStdString());
} }
void EmuThread::onDisplayWindowMouseButtonEvent(int button, bool pressed) void EmuThread::onDisplayWindowMouseButtonEvent(int button, bool pressed)
{ {
DebugAssert(isOnThread()); DebugAssert(isCurrentThread());
InputManager::InvokeEvents(InputManager::MakePointerButtonKey(0, button), static_cast<float>(pressed), InputManager::InvokeEvents(InputManager::MakePointerButtonKey(0, button), static_cast<float>(pressed),
GenericInputBinding::Unknown); GenericInputBinding::Unknown);
@ -914,7 +914,7 @@ void EmuThread::onDisplayWindowMouseButtonEvent(int button, bool pressed)
void EmuThread::onDisplayWindowMouseWheelEvent(const QPoint& delta_angle) void EmuThread::onDisplayWindowMouseWheelEvent(const QPoint& delta_angle)
{ {
DebugAssert(isOnThread()); DebugAssert(isCurrentThread());
const float dx = std::clamp(static_cast<float>(delta_angle.x()) / QtUtils::MOUSE_WHEEL_DELTA, -1.0f, 1.0f); const float dx = std::clamp(static_cast<float>(delta_angle.x()) / QtUtils::MOUSE_WHEEL_DELTA, -1.0f, 1.0f);
if (dx != 0.0f) if (dx != 0.0f)
@ -932,7 +932,7 @@ void EmuThread::onDisplayWindowResized(int width, int height, float scale)
void EmuThread::redrawDisplayWindow() void EmuThread::redrawDisplayWindow()
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "redrawDisplayWindow", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "redrawDisplayWindow", Qt::QueuedConnection);
return; return;
@ -946,7 +946,7 @@ void EmuThread::redrawDisplayWindow()
void EmuThread::toggleFullscreen() void EmuThread::toggleFullscreen()
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "toggleFullscreen", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "toggleFullscreen", Qt::QueuedConnection);
return; return;
@ -957,7 +957,7 @@ void EmuThread::toggleFullscreen()
void EmuThread::setFullscreen(bool fullscreen, bool allow_render_to_main) void EmuThread::setFullscreen(bool fullscreen, bool allow_render_to_main)
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "setFullscreen", Qt::QueuedConnection, Q_ARG(bool, fullscreen), QMetaObject::invokeMethod(this, "setFullscreen", Qt::QueuedConnection, Q_ARG(bool, fullscreen),
Q_ARG(bool, allow_render_to_main)); Q_ARG(bool, allow_render_to_main));
@ -988,7 +988,7 @@ void Host::SetFullscreen(bool enabled)
void EmuThread::setSurfaceless(bool surfaceless) void EmuThread::setSurfaceless(bool surfaceless)
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "setSurfaceless", Qt::QueuedConnection, Q_ARG(bool, surfaceless)); QMetaObject::invokeMethod(this, "setSurfaceless", Qt::QueuedConnection, Q_ARG(bool, surfaceless));
return; return;
@ -1003,7 +1003,7 @@ void EmuThread::setSurfaceless(bool surfaceless)
void EmuThread::requestDisplaySize(float scale) void EmuThread::requestDisplaySize(float scale)
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "requestDisplaySize", Qt::QueuedConnection, Q_ARG(float, scale)); QMetaObject::invokeMethod(this, "requestDisplaySize", Qt::QueuedConnection, Q_ARG(float, scale));
return; return;
@ -1089,7 +1089,7 @@ void Host::OnIdleStateChanged()
void EmuThread::reloadInputSources() void EmuThread::reloadInputSources()
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, &EmuThread::reloadInputSources, Qt::QueuedConnection); QMetaObject::invokeMethod(this, &EmuThread::reloadInputSources, Qt::QueuedConnection);
return; return;
@ -1100,7 +1100,7 @@ void EmuThread::reloadInputSources()
void EmuThread::reloadInputBindings() void EmuThread::reloadInputBindings()
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, &EmuThread::reloadInputBindings, Qt::QueuedConnection); QMetaObject::invokeMethod(this, &EmuThread::reloadInputBindings, Qt::QueuedConnection);
return; return;
@ -1111,7 +1111,7 @@ void EmuThread::reloadInputBindings()
void EmuThread::reloadInputDevices() void EmuThread::reloadInputDevices()
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, &EmuThread::reloadInputDevices, Qt::QueuedConnection); QMetaObject::invokeMethod(this, &EmuThread::reloadInputDevices, Qt::QueuedConnection);
return; return;
@ -1122,7 +1122,7 @@ void EmuThread::reloadInputDevices()
void EmuThread::closeInputSources() void EmuThread::closeInputSources()
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, &EmuThread::reloadInputDevices, Qt::BlockingQueuedConnection); QMetaObject::invokeMethod(this, &EmuThread::reloadInputDevices, Qt::BlockingQueuedConnection);
return; return;
@ -1133,7 +1133,7 @@ void EmuThread::closeInputSources()
void EmuThread::enumerateInputDevices() void EmuThread::enumerateInputDevices()
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, &EmuThread::enumerateInputDevices, Qt::QueuedConnection); QMetaObject::invokeMethod(this, &EmuThread::enumerateInputDevices, Qt::QueuedConnection);
return; return;
@ -1144,7 +1144,7 @@ void EmuThread::enumerateInputDevices()
void EmuThread::enumerateVibrationMotors() void EmuThread::enumerateVibrationMotors()
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, &EmuThread::enumerateVibrationMotors, Qt::QueuedConnection); QMetaObject::invokeMethod(this, &EmuThread::enumerateVibrationMotors, Qt::QueuedConnection);
return; return;
@ -1162,7 +1162,7 @@ void EmuThread::enumerateVibrationMotors()
void EmuThread::confirmActionIfMemoryCardBusy(const QString& action, bool cancel_resume_on_accept, void EmuThread::confirmActionIfMemoryCardBusy(const QString& action, bool cancel_resume_on_accept,
std::function<void(bool)> callback) const std::function<void(bool)> callback) const
{ {
DebugAssert(isOnThread()); DebugAssert(isCurrentThread());
if (!System::IsValid() || !System::IsSavingMemoryCards()) if (!System::IsValid() || !System::IsSavingMemoryCards())
{ {
@ -1189,7 +1189,7 @@ void EmuThread::confirmActionIfMemoryCardBusy(const QString& action, bool cancel
void EmuThread::shutdownSystem(bool save_state, bool check_memcard_busy) void EmuThread::shutdownSystem(bool save_state, bool check_memcard_busy)
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
System::CancelPendingStartup(); System::CancelPendingStartup();
QMetaObject::invokeMethod(this, "shutdownSystem", Qt::QueuedConnection, Q_ARG(bool, save_state), QMetaObject::invokeMethod(this, "shutdownSystem", Qt::QueuedConnection, Q_ARG(bool, save_state),
@ -1213,7 +1213,7 @@ void EmuThread::shutdownSystem(bool save_state, bool check_memcard_busy)
void EmuThread::resetSystem(bool check_memcard_busy) void EmuThread::resetSystem(bool check_memcard_busy)
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "resetSystem", Qt::QueuedConnection, Q_ARG(bool, check_memcard_busy)); QMetaObject::invokeMethod(this, "resetSystem", Qt::QueuedConnection, Q_ARG(bool, check_memcard_busy));
return; return;
@ -1233,7 +1233,7 @@ void EmuThread::resetSystem(bool check_memcard_busy)
void EmuThread::setSystemPaused(bool paused, bool wait_until_paused /* = false */) void EmuThread::setSystemPaused(bool paused, bool wait_until_paused /* = false */)
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "setSystemPaused", QMetaObject::invokeMethod(this, "setSystemPaused",
wait_until_paused ? Qt::BlockingQueuedConnection : Qt::QueuedConnection, wait_until_paused ? Qt::BlockingQueuedConnection : Qt::QueuedConnection,
@ -1246,7 +1246,7 @@ void EmuThread::setSystemPaused(bool paused, bool wait_until_paused /* = false *
void EmuThread::changeDisc(const QString& new_disc_filename, bool reset_system, bool check_memcard_busy) void EmuThread::changeDisc(const QString& new_disc_filename, bool reset_system, bool check_memcard_busy)
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "changeDisc", Qt::QueuedConnection, Q_ARG(const QString&, new_disc_filename), QMetaObject::invokeMethod(this, "changeDisc", Qt::QueuedConnection, Q_ARG(const QString&, new_disc_filename),
Q_ARG(bool, reset_system), Q_ARG(bool, check_memcard_busy)); Q_ARG(bool, reset_system), Q_ARG(bool, check_memcard_busy));
@ -1276,7 +1276,7 @@ void EmuThread::changeDisc(const QString& new_disc_filename, bool reset_system,
void EmuThread::changeDiscFromPlaylist(quint32 index) void EmuThread::changeDiscFromPlaylist(quint32 index)
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "changeDiscFromPlaylist", Qt::QueuedConnection, Q_ARG(quint32, index)); QMetaObject::invokeMethod(this, "changeDiscFromPlaylist", Qt::QueuedConnection, Q_ARG(quint32, index));
return; return;
@ -1291,7 +1291,7 @@ void EmuThread::changeDiscFromPlaylist(quint32 index)
void EmuThread::reloadCheats(bool reload_files, bool reload_enabled_list, bool verbose, bool verbose_if_changed) void EmuThread::reloadCheats(bool reload_files, bool reload_enabled_list, bool verbose, bool verbose_if_changed)
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "reloadCheats", Qt::QueuedConnection, Q_ARG(bool, reload_files), QMetaObject::invokeMethod(this, "reloadCheats", Qt::QueuedConnection, Q_ARG(bool, reload_files),
Q_ARG(bool, reload_enabled_list), Q_ARG(bool, verbose), Q_ARG(bool, verbose_if_changed)); Q_ARG(bool, reload_enabled_list), Q_ARG(bool, verbose), Q_ARG(bool, verbose_if_changed));
@ -1309,7 +1309,7 @@ void EmuThread::reloadCheats(bool reload_files, bool reload_enabled_list, bool v
void EmuThread::applyCheat(const QString& name) void EmuThread::applyCheat(const QString& name)
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "applyCheat", Qt::QueuedConnection, Q_ARG(const QString&, name)); QMetaObject::invokeMethod(this, "applyCheat", Qt::QueuedConnection, Q_ARG(const QString&, name));
return; return;
@ -1321,7 +1321,7 @@ void EmuThread::applyCheat(const QString& name)
void EmuThread::reloadPostProcessingShaders() void EmuThread::reloadPostProcessingShaders()
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "reloadPostProcessingShaders", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "reloadPostProcessingShaders", Qt::QueuedConnection);
return; return;
@ -1333,7 +1333,7 @@ void EmuThread::reloadPostProcessingShaders()
void EmuThread::updatePostProcessingSettings() void EmuThread::updatePostProcessingSettings()
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "updatePostProcessingSettings", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "updatePostProcessingSettings", Qt::QueuedConnection);
return; return;
@ -1345,7 +1345,7 @@ void EmuThread::updatePostProcessingSettings()
void EmuThread::clearInputBindStateFromSource(InputBindingKey key) void EmuThread::clearInputBindStateFromSource(InputBindingKey key)
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "clearInputBindStateFromSource", Qt::QueuedConnection, Q_ARG(InputBindingKey, key)); QMetaObject::invokeMethod(this, "clearInputBindStateFromSource", Qt::QueuedConnection, Q_ARG(InputBindingKey, key));
return; return;
@ -1356,7 +1356,7 @@ void EmuThread::clearInputBindStateFromSource(InputBindingKey key)
void EmuThread::reloadTextureReplacements() void EmuThread::reloadTextureReplacements()
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "reloadTextureReplacements", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "reloadTextureReplacements", Qt::QueuedConnection);
return; return;
@ -1373,7 +1373,7 @@ void EmuThread::runOnEmuThread(std::function<void()> callback)
void Host::RunOnCPUThread(std::function<void()> function, bool block /* = false */) void Host::RunOnCPUThread(std::function<void()> function, bool block /* = false */)
{ {
const bool self = g_emu_thread->isOnThread(); const bool self = g_emu_thread->isCurrentThread();
QMetaObject::invokeMethod(g_emu_thread, "runOnEmuThread", QMetaObject::invokeMethod(g_emu_thread, "runOnEmuThread",
(block && !self) ? Qt::BlockingQueuedConnection : Qt::QueuedConnection, (block && !self) ? Qt::BlockingQueuedConnection : Qt::QueuedConnection,
@ -1399,7 +1399,7 @@ void Host::CancelGameListRefresh()
void EmuThread::loadState(const QString& filename) void EmuThread::loadState(const QString& filename)
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "loadState", Qt::QueuedConnection, Q_ARG(const QString&, filename)); QMetaObject::invokeMethod(this, "loadState", Qt::QueuedConnection, Q_ARG(const QString&, filename));
return; return;
@ -1410,7 +1410,7 @@ void EmuThread::loadState(const QString& filename)
void EmuThread::loadState(bool global, qint32 slot) void EmuThread::loadState(bool global, qint32 slot)
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "loadState", Qt::QueuedConnection, Q_ARG(bool, global), Q_ARG(qint32, slot)); QMetaObject::invokeMethod(this, "loadState", Qt::QueuedConnection, Q_ARG(bool, global), Q_ARG(qint32, slot));
return; return;
@ -1426,7 +1426,7 @@ void EmuThread::loadState(bool global, qint32 slot)
void EmuThread::saveState(const QString& filename, bool block_until_done /* = false */) void EmuThread::saveState(const QString& filename, bool block_until_done /* = false */)
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "saveState", block_until_done ? Qt::BlockingQueuedConnection : Qt::QueuedConnection, QMetaObject::invokeMethod(this, "saveState", block_until_done ? Qt::BlockingQueuedConnection : Qt::QueuedConnection,
Q_ARG(const QString&, filename), Q_ARG(bool, block_until_done)); Q_ARG(const QString&, filename), Q_ARG(bool, block_until_done));
@ -1443,7 +1443,7 @@ void EmuThread::saveState(const QString& filename, bool block_until_done /* = fa
void EmuThread::saveState(bool global, qint32 slot, bool block_until_done /* = false */) void EmuThread::saveState(bool global, qint32 slot, bool block_until_done /* = false */)
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "saveState", block_until_done ? Qt::BlockingQueuedConnection : Qt::QueuedConnection, QMetaObject::invokeMethod(this, "saveState", block_until_done ? Qt::BlockingQueuedConnection : Qt::QueuedConnection,
Q_ARG(bool, global), Q_ARG(qint32, slot), Q_ARG(bool, block_until_done)); Q_ARG(bool, global), Q_ARG(qint32, slot), Q_ARG(bool, block_until_done));
@ -1465,7 +1465,7 @@ void EmuThread::saveState(bool global, qint32 slot, bool block_until_done /* = f
void EmuThread::undoLoadState() void EmuThread::undoLoadState()
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "undoLoadState", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "undoLoadState", Qt::QueuedConnection);
return; return;
@ -1476,7 +1476,7 @@ void EmuThread::undoLoadState()
void EmuThread::setAudioOutputVolume(int volume, int fast_forward_volume) void EmuThread::setAudioOutputVolume(int volume, int fast_forward_volume)
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "setAudioOutputVolume", Qt::QueuedConnection, Q_ARG(int, volume), QMetaObject::invokeMethod(this, "setAudioOutputVolume", Qt::QueuedConnection, Q_ARG(int, volume),
Q_ARG(int, fast_forward_volume)); Q_ARG(int, fast_forward_volume));
@ -1490,7 +1490,7 @@ void EmuThread::setAudioOutputVolume(int volume, int fast_forward_volume)
void EmuThread::setAudioOutputMuted(bool muted) void EmuThread::setAudioOutputMuted(bool muted)
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "setAudioOutputMuted", Qt::QueuedConnection, Q_ARG(bool, muted)); QMetaObject::invokeMethod(this, "setAudioOutputMuted", Qt::QueuedConnection, Q_ARG(bool, muted));
return; return;
@ -1502,7 +1502,7 @@ void EmuThread::setAudioOutputMuted(bool muted)
void EmuThread::startDumpingAudio() void EmuThread::startDumpingAudio()
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "startDumpingAudio", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "startDumpingAudio", Qt::QueuedConnection);
return; return;
@ -1513,7 +1513,7 @@ void EmuThread::startDumpingAudio()
void EmuThread::stopDumpingAudio() void EmuThread::stopDumpingAudio()
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "stopDumpingAudio", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "stopDumpingAudio", Qt::QueuedConnection);
return; return;
@ -1524,7 +1524,7 @@ void EmuThread::stopDumpingAudio()
void EmuThread::singleStepCPU() void EmuThread::singleStepCPU()
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "singleStepCPU", Qt::BlockingQueuedConnection); QMetaObject::invokeMethod(this, "singleStepCPU", Qt::BlockingQueuedConnection);
return; return;
@ -1538,7 +1538,7 @@ void EmuThread::singleStepCPU()
void EmuThread::dumpRAM(const QString& filename) void EmuThread::dumpRAM(const QString& filename)
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "dumpRAM", Qt::QueuedConnection, Q_ARG(const QString&, filename)); QMetaObject::invokeMethod(this, "dumpRAM", Qt::QueuedConnection, Q_ARG(const QString&, filename));
return; return;
@ -1553,7 +1553,7 @@ void EmuThread::dumpRAM(const QString& filename)
void EmuThread::dumpVRAM(const QString& filename) void EmuThread::dumpVRAM(const QString& filename)
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "dumpVRAM", Qt::QueuedConnection, Q_ARG(const QString&, filename)); QMetaObject::invokeMethod(this, "dumpVRAM", Qt::QueuedConnection, Q_ARG(const QString&, filename));
return; return;
@ -1568,7 +1568,7 @@ void EmuThread::dumpVRAM(const QString& filename)
void EmuThread::dumpSPURAM(const QString& filename) void EmuThread::dumpSPURAM(const QString& filename)
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "dumpSPURAM", Qt::QueuedConnection, Q_ARG(const QString&, filename)); QMetaObject::invokeMethod(this, "dumpSPURAM", Qt::QueuedConnection, Q_ARG(const QString&, filename));
return; return;
@ -1583,7 +1583,7 @@ void EmuThread::dumpSPURAM(const QString& filename)
void EmuThread::saveScreenshot() void EmuThread::saveScreenshot()
{ {
if (!isOnThread()) if (!isCurrentThread())
{ {
QMetaObject::invokeMethod(this, "saveScreenshot", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "saveScreenshot", Qt::QueuedConnection);
return; return;
@ -1660,7 +1660,7 @@ void Host::OpenHostFileSelectorAsync(std::string_view title, bool select_directo
FileSelectorFilters filters /* = FileSelectorFilters() */, FileSelectorFilters filters /* = FileSelectorFilters() */,
std::string_view initial_directory /* = std::string_view() */) std::string_view initial_directory /* = std::string_view() */)
{ {
const bool from_cpu_thread = g_emu_thread->isOnThread(); const bool from_cpu_thread = g_emu_thread->isCurrentThread();
QString filters_str; QString filters_str;
if (!filters.empty()) if (!filters.empty())
@ -1735,7 +1735,7 @@ void EmuThread::queueAuxiliaryRenderWindowInputEvent(Host::AuxiliaryRenderWindow
Host::AuxiliaryRenderWindowEventParam param2, Host::AuxiliaryRenderWindowEventParam param2,
Host::AuxiliaryRenderWindowEventParam param3) Host::AuxiliaryRenderWindowEventParam param3)
{ {
DebugAssert(isOnUIThread()); DebugAssert(QThread::isMainThread());
QMetaObject::invokeMethod(this, "processAuxiliaryRenderWindowInputEvent", Qt::QueuedConnection, QMetaObject::invokeMethod(this, "processAuxiliaryRenderWindowInputEvent", Qt::QueuedConnection,
Q_ARG(void*, userdata), Q_ARG(quint32, static_cast<quint32>(event)), Q_ARG(void*, userdata), Q_ARG(quint32, static_cast<quint32>(event)),
Q_ARG(quint32, param1.uint_param), Q_ARG(quint32, param2.uint_param), Q_ARG(quint32, param1.uint_param), Q_ARG(quint32, param2.uint_param),
@ -1745,7 +1745,7 @@ void EmuThread::queueAuxiliaryRenderWindowInputEvent(Host::AuxiliaryRenderWindow
void EmuThread::processAuxiliaryRenderWindowInputEvent(void* userdata, quint32 event, quint32 param1, quint32 param2, void EmuThread::processAuxiliaryRenderWindowInputEvent(void* userdata, quint32 event, quint32 param1, quint32 param2,
quint32 param3) quint32 param3)
{ {
DebugAssert(isOnThread()); DebugAssert(isCurrentThread());
ImGuiManager::ProcessAuxiliaryRenderWindowInputEvent(userdata, static_cast<Host::AuxiliaryRenderWindowEvent>(event), ImGuiManager::ProcessAuxiliaryRenderWindowInputEvent(userdata, static_cast<Host::AuxiliaryRenderWindowEvent>(event),
Host::AuxiliaryRenderWindowEventParam{.uint_param = param1}, Host::AuxiliaryRenderWindowEventParam{.uint_param = param1},
Host::AuxiliaryRenderWindowEventParam{.uint_param = param2}, Host::AuxiliaryRenderWindowEventParam{.uint_param = param2},
@ -1807,7 +1807,7 @@ void EmuThread::start()
void EmuThread::stop() void EmuThread::stop()
{ {
AssertMsg(g_emu_thread, "Emu thread exists"); AssertMsg(g_emu_thread, "Emu thread exists");
AssertMsg(!g_emu_thread->isOnThread(), "Not called on the emu thread"); AssertMsg(!g_emu_thread->isCurrentThread(), "Not called on the emu thread");
QMetaObject::invokeMethod(g_emu_thread, &EmuThread::stopInThread, Qt::QueuedConnection); QMetaObject::invokeMethod(g_emu_thread, &EmuThread::stopInThread, Qt::QueuedConnection);
QtUtils::ProcessEventsWithSleep(QEventLoop::ExcludeUserInputEvents, []() { return (g_emu_thread->isRunning()); }); QtUtils::ProcessEventsWithSleep(QEventLoop::ExcludeUserInputEvents, []() { return (g_emu_thread->isRunning()); });
@ -1885,7 +1885,7 @@ void Host::FrameDone()
void EmuThread::wakeThread() void EmuThread::wakeThread()
{ {
if (isOnThread()) if (isCurrentThread())
m_event_loop->quit(); m_event_loop->quit();
else else
QMetaObject::invokeMethod(m_event_loop, "quit", Qt::QueuedConnection); QMetaObject::invokeMethod(m_event_loop, "quit", Qt::QueuedConnection);
@ -2048,7 +2048,7 @@ std::optional<std::time_t> Host::GetResourceFileTimestamp(std::string_view filen
void Host::CommitBaseSettingChanges() void Host::CommitBaseSettingChanges()
{ {
if (g_emu_thread->isOnThread()) if (g_emu_thread->isCurrentThread())
QtHost::RunOnUIThread([]() { QtHost::QueueSettingsSave(); }); QtHost::RunOnUIThread([]() { QtHost::QueueSettingsSave(); });
else else
QtHost::QueueSettingsSave(); QtHost::QueueSettingsSave();
@ -2171,7 +2171,7 @@ void Host::PumpMessagesOnCPUThread()
void QtHost::SaveSettings() void QtHost::SaveSettings()
{ {
AssertMsg(!g_emu_thread->isOnThread(), "Saving should happen on the UI thread."); AssertMsg(!g_emu_thread->isCurrentThread(), "Saving should happen on the UI thread.");
{ {
Error error; Error error;
@ -2189,7 +2189,7 @@ void QtHost::SaveSettings()
void QtHost::QueueSettingsSave() void QtHost::QueueSettingsSave()
{ {
if (g_emu_thread->isOnThread()) if (g_emu_thread->isCurrentThread())
{ {
QtHost::RunOnUIThread(QueueSettingsSave); QtHost::RunOnUIThread(QueueSettingsSave);
return; return;

View File

@ -89,9 +89,6 @@ public:
static void start(); static void start();
static void stop(); static void stop();
ALWAYS_INLINE bool isOnThread() const { return QThread::currentThread() == this; }
ALWAYS_INLINE bool isOnUIThread() const { return QThread::currentThread() == m_ui_thread; }
ALWAYS_INLINE QEventLoop* getEventLoop() const { return m_event_loop; } ALWAYS_INLINE QEventLoop* getEventLoop() const { return m_event_loop; }
ALWAYS_INLINE bool isFullscreen() const { return m_is_fullscreen; } ALWAYS_INLINE bool isFullscreen() const { return m_is_fullscreen; }