| |
| |
|
|
| #pragma once |
|
|
| #include <condition_variable> |
| #include <cstddef> |
| #include <memory> |
| #include <mutex> |
| #include <utility> |
| #include <vector> |
|
|
| #include <QByteArray> |
| #include <QImage> |
| #include <QObject> |
| #include <QPoint> |
| #include <QString> |
| #include <QStringList> |
| #include <QThread> |
| #include <QTimer> |
| #include <QWidget> |
| #include <qglobal.h> |
| #include <qnamespace.h> |
| #include <qobjectdefs.h> |
|
|
| #include "common/common_types.h" |
| #include "common/logging/log.h" |
| #include "common/polyfill_thread.h" |
| #include "common/thread.h" |
| #include "core/frontend/emu_window.h" |
|
|
| class GMainWindow; |
| class QCamera; |
| class QCameraImageCapture; |
| class QCloseEvent; |
| class QFocusEvent; |
| class QKeyEvent; |
| class QMouseEvent; |
| class QObject; |
| class QResizeEvent; |
| class QShowEvent; |
| class QTouchEvent; |
| class QWheelEvent; |
|
|
| namespace Core { |
| class System; |
| } |
|
|
| namespace InputCommon { |
| class InputSubsystem; |
| enum class MouseButton; |
| } |
|
|
| namespace InputCommon::TasInput { |
| enum class TasState; |
| } |
|
|
| namespace VideoCore { |
| enum class LoadCallbackStage; |
| } |
|
|
| class EmuThread final : public QThread { |
| Q_OBJECT |
|
|
| public: |
| explicit EmuThread(Core::System& system); |
| ~EmuThread() override; |
|
|
| |
| |
| |
| |
| void run() override; |
|
|
| |
| |
| |
| |
| void SetRunning(bool should_run) { |
| |
| { |
| |
| std::unique_lock run_lk{m_should_run_mutex}; |
| m_should_run = should_run; |
| m_should_run_cv.notify_one(); |
| } |
|
|
| |
| if (!should_run) { |
| m_stopped.Wait(); |
| } |
| } |
|
|
| |
| |
| |
| |
| bool IsRunning() const { |
| return m_should_run; |
| } |
|
|
| |
| |
| |
| void ForceStop() { |
| LOG_WARNING(Frontend, "Force stopping EmuThread"); |
| m_stop_source.request_stop(); |
| } |
|
|
| private: |
| void EmulationPaused(std::unique_lock<std::mutex>& lk); |
| void EmulationResumed(std::unique_lock<std::mutex>& lk); |
|
|
| private: |
| Core::System& m_system; |
|
|
| std::stop_source m_stop_source; |
| std::mutex m_should_run_mutex; |
| std::condition_variable_any m_should_run_cv; |
| Common::Event m_stopped; |
| bool m_should_run{true}; |
|
|
| signals: |
| |
| |
| |
| |
| |
| |
| |
| void DebugModeEntered(); |
|
|
| |
| |
| |
| |
| |
| |
| |
| void DebugModeLeft(); |
|
|
| void LoadProgress(VideoCore::LoadCallbackStage stage, std::size_t value, std::size_t total); |
| }; |
|
|
| class GRenderWindow : public QWidget, public Core::Frontend::EmuWindow { |
| Q_OBJECT |
|
|
| public: |
| explicit GRenderWindow(GMainWindow* parent, EmuThread* emu_thread_, |
| std::shared_ptr<InputCommon::InputSubsystem> input_subsystem_, |
| Core::System& system_); |
| ~GRenderWindow() override; |
|
|
| |
| void OnFrameDisplayed() override; |
| bool IsShown() const override; |
| std::unique_ptr<Core::Frontend::GraphicsContext> CreateSharedContext() const override; |
|
|
| void BackupGeometry(); |
| void RestoreGeometry(); |
| void restoreGeometry(const QByteArray& geometry_); |
| QByteArray saveGeometry(); |
|
|
| qreal windowPixelRatio() const; |
|
|
| std::pair<u32, u32> ScaleTouch(const QPointF& pos) const; |
|
|
| void closeEvent(QCloseEvent* event) override; |
| void leaveEvent(QEvent* event) override; |
|
|
| void resizeEvent(QResizeEvent* event) override; |
|
|
| |
| static int QtKeyToSwitchKey(Qt::Key qt_keys); |
|
|
| |
| static int QtModifierToSwitchModifier(Qt::KeyboardModifiers qt_modifiers); |
|
|
| void keyPressEvent(QKeyEvent* event) override; |
| void keyReleaseEvent(QKeyEvent* event) override; |
|
|
| |
| static InputCommon::MouseButton QtButtonToMouseButton(Qt::MouseButton button); |
|
|
| void mousePressEvent(QMouseEvent* event) override; |
| void mouseMoveEvent(QMouseEvent* event) override; |
| void mouseReleaseEvent(QMouseEvent* event) override; |
| void wheelEvent(QWheelEvent* event) override; |
|
|
| void InitializeCamera(); |
| void FinalizeCamera(); |
|
|
| bool event(QEvent* event) override; |
|
|
| void focusOutEvent(QFocusEvent* event) override; |
|
|
| bool InitRenderTarget(); |
|
|
| |
| void ReleaseRenderTarget(); |
|
|
| bool IsLoadingComplete() const; |
|
|
| void CaptureScreenshot(const QString& screenshot_path); |
|
|
| |
| |
| |
| |
| void ExecuteProgram(std::size_t program_index); |
|
|
| |
| void Exit(); |
|
|
| public slots: |
| void OnEmulationStarting(EmuThread* emu_thread_); |
| void OnEmulationStopping(); |
| void OnFramebufferSizeChanged(); |
|
|
| signals: |
| |
| void Closed(); |
| void FirstFrameDisplayed(); |
| void ExecuteProgramSignal(std::size_t program_index); |
| void ExitSignal(); |
| void MouseActivity(); |
| void TasPlaybackStateChanged(); |
|
|
| private: |
| void TouchBeginEvent(const QTouchEvent* event); |
| void TouchUpdateEvent(const QTouchEvent* event); |
| void TouchEndEvent(); |
| void ConstrainMouse(); |
|
|
| void RequestCameraCapture(); |
| void OnCameraCapture(int requestId, const QImage& img); |
|
|
| void OnMinimalClientAreaChangeRequest(std::pair<u32, u32> minimal_size) override; |
|
|
| bool InitializeOpenGL(); |
| bool InitializeVulkan(); |
| void InitializeNull(); |
| bool LoadOpenGL(); |
| QStringList GetUnsupportedGLExtensions() const; |
|
|
| EmuThread* emu_thread; |
| std::shared_ptr<InputCommon::InputSubsystem> input_subsystem; |
|
|
| |
| |
| |
| std::shared_ptr<Core::Frontend::GraphicsContext> main_context; |
|
|
| |
| QImage screenshot_image; |
|
|
| QByteArray geometry; |
|
|
| QWidget* child_widget = nullptr; |
|
|
| bool first_frame = false; |
| InputCommon::TasInput::TasState last_tas_state; |
|
|
| #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) && YUZU_USE_QT_MULTIMEDIA |
| bool is_virtual_camera; |
| int pending_camera_snapshots; |
| std::vector<u32> camera_data; |
| std::unique_ptr<QCamera> camera; |
| std::unique_ptr<QCameraImageCapture> camera_capture; |
| std::unique_ptr<QTimer> camera_timer; |
| #endif |
|
|
| QTimer mouse_constrain_timer; |
|
|
| Core::System& system; |
|
|
| protected: |
| void showEvent(QShowEvent* event) override; |
| bool eventFilter(QObject* object, QEvent* event) override; |
| }; |
|
|