bootmanager.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <atomic>
  6. #include <condition_variable>
  7. #include <mutex>
  8. #include <QGLWidget>
  9. #include <QThread>
  10. #include "common/emu_window.h"
  11. #include "common/thread.h"
  12. class QKeyEvent;
  13. class QScreen;
  14. class GGLWidgetInternal;
  15. class GMainWindow;
  16. class GRenderWindow;
  17. class EmuThread : public QThread {
  18. Q_OBJECT
  19. public:
  20. explicit 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() {
  51. return running;
  52. }
  53. /**
  54. * Requests for the emulation thread to stop running
  55. */
  56. void RequestStop() {
  57. stop_run = true;
  58. SetRunning(false);
  59. };
  60. private:
  61. bool exec_step;
  62. bool running;
  63. std::atomic<bool> stop_run;
  64. std::mutex running_mutex;
  65. std::condition_variable running_cv;
  66. GRenderWindow* render_window;
  67. signals:
  68. /**
  69. * Emitted when the CPU has halted execution
  70. *
  71. * @warning When connecting to this signal from other threads, make sure to specify either
  72. * Qt::QueuedConnection (invoke slot within the destination object's message thread) or even
  73. * Qt::BlockingQueuedConnection (additionally block source thread until slot returns)
  74. */
  75. void DebugModeEntered();
  76. /**
  77. * Emitted right before the CPU continues execution
  78. *
  79. * @warning When connecting to this signal from other threads, make sure to specify either
  80. * Qt::QueuedConnection (invoke slot within the destination object's message thread) or even
  81. * Qt::BlockingQueuedConnection (additionally block source thread until slot returns)
  82. */
  83. void DebugModeLeft();
  84. };
  85. class GRenderWindow : public QWidget, public EmuWindow {
  86. Q_OBJECT
  87. public:
  88. GRenderWindow(QWidget* parent, EmuThread* emu_thread);
  89. // EmuWindow implementation
  90. void SwapBuffers() override;
  91. void MakeCurrent() override;
  92. void DoneCurrent() override;
  93. void PollEvents() override;
  94. void BackupGeometry();
  95. void RestoreGeometry();
  96. void restoreGeometry(const QByteArray& geometry); // overridden
  97. QByteArray saveGeometry(); // overridden
  98. qreal windowPixelRatio();
  99. void closeEvent(QCloseEvent* event) override;
  100. void keyPressEvent(QKeyEvent* event) override;
  101. void keyReleaseEvent(QKeyEvent* event) override;
  102. void mousePressEvent(QMouseEvent* event) override;
  103. void mouseMoveEvent(QMouseEvent* event) override;
  104. void mouseReleaseEvent(QMouseEvent* event) override;
  105. void ReloadSetKeymaps() override;
  106. void OnClientAreaResized(unsigned width, unsigned height);
  107. void InitRenderTarget();
  108. public slots:
  109. void moveContext(); // overridden
  110. void OnEmulationStarting(EmuThread* emu_thread);
  111. void OnEmulationStopping();
  112. void OnFramebufferSizeChanged();
  113. signals:
  114. /// Emitted when the window is closed
  115. void Closed();
  116. private:
  117. void OnMinimalClientAreaChangeRequest(
  118. const std::pair<unsigned, unsigned>& minimal_size) override;
  119. GGLWidgetInternal* child;
  120. QByteArray geometry;
  121. /// Device id of keyboard for use with KeyMap
  122. int keyboard_id;
  123. EmuThread* emu_thread;
  124. protected:
  125. void showEvent(QShowEvent* event) override;
  126. };