bootmanager.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <atomic>
  5. #include <condition_variable>
  6. #include <mutex>
  7. #include <QGLWidget>
  8. #include <QThread>
  9. #include "common/emu_window.h"
  10. #include "common/thread.h"
  11. class QKeyEvent;
  12. class QScreen;
  13. class GGLWidgetInternal;
  14. class GMainWindow;
  15. class GRenderWindow;
  16. class EmuThread : public QThread
  17. {
  18. Q_OBJECT
  19. public:
  20. EmuThread(GRenderWindow* render_window);
  21. /**
  22. * Start emulation (on new thread)
  23. * @warning Only call when not running!
  24. */
  25. void run() override;
  26. /**
  27. * Steps the emulation thread by a single CPU instruction (if the CPU is not already running)
  28. * @note This function is thread-safe
  29. */
  30. void ExecStep() {
  31. exec_step = true;
  32. running_cv.notify_all();
  33. }
  34. /**
  35. * Sets whether the emulation thread is running or not
  36. * @param running Boolean value, set the emulation thread to running if true
  37. * @note This function is thread-safe
  38. */
  39. void SetRunning(bool running) {
  40. std::unique_lock<std::mutex> lock(running_mutex);
  41. this->running = running;
  42. lock.unlock();
  43. running_cv.notify_all();
  44. }
  45. /**
  46. * Check if the emulation thread is running or not
  47. * @return True if the emulation thread is running, otherwise false
  48. * @note This function is thread-safe
  49. */
  50. bool IsRunning() { return running; }
  51. /**
  52. * Requests for the emulation thread to stop running
  53. */
  54. void RequestStop() {
  55. stop_run = true;
  56. SetRunning(false);
  57. };
  58. private:
  59. bool exec_step;
  60. bool running;
  61. std::atomic<bool> stop_run;
  62. std::mutex running_mutex;
  63. std::condition_variable running_cv;
  64. GRenderWindow* render_window;
  65. signals:
  66. /**
  67. * Emitted when the CPU has halted execution
  68. *
  69. * @warning When connecting to this signal from other threads, make sure to specify either Qt::QueuedConnection (invoke slot within the destination object's message thread) or even Qt::BlockingQueuedConnection (additionally block source thread until slot returns)
  70. */
  71. void DebugModeEntered();
  72. /**
  73. * Emitted right before the CPU continues execution
  74. *
  75. * @warning When connecting to this signal from other threads, make sure to specify either Qt::QueuedConnection (invoke slot within the destination object's message thread) or even Qt::BlockingQueuedConnection (additionally block source thread until slot returns)
  76. */
  77. void DebugModeLeft();
  78. };
  79. class GRenderWindow : public QWidget, public EmuWindow
  80. {
  81. Q_OBJECT
  82. public:
  83. GRenderWindow(QWidget* parent, EmuThread* emu_thread);
  84. // EmuWindow implementation
  85. void SwapBuffers() override;
  86. void MakeCurrent() override;
  87. void DoneCurrent() override;
  88. void PollEvents() override;
  89. void BackupGeometry();
  90. void RestoreGeometry();
  91. void restoreGeometry(const QByteArray& geometry); // overridden
  92. QByteArray saveGeometry(); // overridden
  93. qreal windowPixelRatio();
  94. void closeEvent(QCloseEvent* event) override;
  95. void keyPressEvent(QKeyEvent* event) override;
  96. void keyReleaseEvent(QKeyEvent* event) override;
  97. void mousePressEvent(QMouseEvent *event) override;
  98. void mouseMoveEvent(QMouseEvent *event) override;
  99. void mouseReleaseEvent(QMouseEvent *event) override;
  100. void ReloadSetKeymaps() override;
  101. void OnClientAreaResized(unsigned width, unsigned height);
  102. public slots:
  103. void moveContext(); // overridden
  104. void OnEmulationStarting(EmuThread* emu_thread);
  105. void OnEmulationStopping();
  106. void OnFramebufferSizeChanged();
  107. signals:
  108. /// Emitted when the window is closed
  109. void Closed();
  110. private:
  111. void OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& minimal_size) override;
  112. GGLWidgetInternal* child;
  113. QByteArray geometry;
  114. /// Device id of keyboard for use with KeyMap
  115. int keyboard_id;
  116. EmuThread* emu_thread;
  117. protected:
  118. void showEvent(QShowEvent* event) override;
  119. };