bootmanager.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 <QThread>
  8. #include <QGLWidget>
  9. #include "common/emu_window.h"
  10. #include "common/thread.h"
  11. class QScreen;
  12. class QKeyEvent;
  13. class GRenderWindow;
  14. class GMainWindow;
  15. class EmuThread : public QThread
  16. {
  17. Q_OBJECT
  18. public:
  19. EmuThread(GRenderWindow* render_window);
  20. /**
  21. * Start emulation (on new thread)
  22. * @warning Only call when not running!
  23. */
  24. void run() override;
  25. /**
  26. * Steps the emulation thread by a single CPU instruction (if the CPU is not already running)
  27. * @note This function is thread-safe
  28. */
  29. void ExecStep() { exec_step = true; }
  30. /**
  31. * Sets whether the emulation thread is running or not
  32. * @param running Boolean value, set the emulation thread to running if true
  33. * @note This function is thread-safe
  34. */
  35. void SetRunning(bool running) {
  36. std::unique_lock<std::mutex> lock(running_mutex);
  37. this->running = running;
  38. lock.unlock();
  39. running_cv.notify_all();
  40. }
  41. /**
  42. * Check if the emulation thread is running or not
  43. * @return True if the emulation thread is running, otherwise false
  44. * @note This function is thread-safe
  45. */
  46. bool IsRunning() { return running; }
  47. /**
  48. * Requests for the emulation thread to stop running
  49. */
  50. void RequestStop() {
  51. stop_run = true;
  52. SetRunning(false);
  53. };
  54. private:
  55. bool exec_step;
  56. bool running;
  57. std::atomic<bool> stop_run;
  58. std::mutex running_mutex;
  59. std::condition_variable running_cv;
  60. GRenderWindow* render_window;
  61. signals:
  62. /**
  63. * Emitted when the CPU has halted execution
  64. *
  65. * @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)
  66. */
  67. void DebugModeEntered();
  68. /**
  69. * Emitted right before the CPU continues execution
  70. *
  71. * @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)
  72. */
  73. void DebugModeLeft();
  74. };
  75. class GRenderWindow : public QWidget, public EmuWindow
  76. {
  77. Q_OBJECT
  78. public:
  79. GRenderWindow(QWidget* parent, EmuThread* emu_thread);
  80. // EmuWindow implementation
  81. void SwapBuffers() override;
  82. void MakeCurrent() override;
  83. void DoneCurrent() override;
  84. void PollEvents() override;
  85. void BackupGeometry();
  86. void RestoreGeometry();
  87. void restoreGeometry(const QByteArray& geometry); // overridden
  88. QByteArray saveGeometry(); // overridden
  89. void keyPressEvent(QKeyEvent* event) override;
  90. void keyReleaseEvent(QKeyEvent* event) override;
  91. void mousePressEvent(QMouseEvent *event) override;
  92. void mouseMoveEvent(QMouseEvent *event) override;
  93. void mouseReleaseEvent(QMouseEvent *event) override;
  94. void ReloadSetKeymaps() override;
  95. void OnClientAreaResized(unsigned width, unsigned height);
  96. void OnFramebufferSizeChanged();
  97. public slots:
  98. void moveContext(); // overridden
  99. void OnEmulationStarting(EmuThread* emu_thread);
  100. void OnEmulationStopping();
  101. private:
  102. void OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& minimal_size) override;
  103. QGLWidget* child;
  104. QByteArray geometry;
  105. /// Device id of keyboard for use with KeyMap
  106. int keyboard_id;
  107. EmuThread* emu_thread;
  108. };