bootmanager.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 <QThread>
  6. #include <QGLWidget>
  7. #include "common/common.h"
  8. #include "common/emu_window.h"
  9. #include "common/thread.h"
  10. class QScreen;
  11. class QKeyEvent;
  12. class GRenderWindow;
  13. class GMainWindow;
  14. class EmuThread : public QThread
  15. {
  16. Q_OBJECT
  17. public:
  18. /**
  19. * Start emulation (on new thread)
  20. *
  21. * @warning Only call when not running!
  22. */
  23. void run() override;
  24. /**
  25. * Allow the CPU to process a single instruction (if cpu is not running)
  26. *
  27. * @note This function is thread-safe
  28. */
  29. void ExecStep() { exec_cpu_step = true; }
  30. /**
  31. * Sets whether the CPU is running
  32. *
  33. * @note This function is thread-safe
  34. */
  35. void SetCpuRunning(bool running) { cpu_running = running; }
  36. /**
  37. * Allow the CPU to continue processing instructions without interruption
  38. *
  39. * @note This function is thread-safe
  40. */
  41. bool IsCpuRunning() { return cpu_running; }
  42. /**
  43. * Shutdown (permantently stops) the CPU
  44. */
  45. void ShutdownCpu() { stop_run = true; };
  46. /**
  47. * Waits for the CPU shutdown to complete
  48. */
  49. void WaitForCpuShutdown() { shutdown_event.Wait(); }
  50. public slots:
  51. /**
  52. * Stop emulation and wait for the thread to finish.
  53. *
  54. * @details: This function will wait a second for the thread to finish; if it hasn't finished until then, we'll terminate() it and wait another second, hoping that it will be terminated by then.
  55. * @note: This function is thread-safe.
  56. */
  57. void Stop();
  58. private:
  59. friend class GMainWindow;
  60. EmuThread(GRenderWindow* render_window);
  61. bool exec_cpu_step;
  62. bool cpu_running;
  63. std::atomic<bool> stop_run;
  64. GRenderWindow* render_window;
  65. Common::Event shutdown_event;
  66. signals:
  67. /**
  68. * Emitted when the CPU has halted execution
  69. *
  70. * @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)
  71. */
  72. void DebugModeEntered();
  73. /**
  74. * Emitted right before the CPU continues execution
  75. *
  76. * @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)
  77. */
  78. void DebugModeLeft();
  79. };
  80. class GRenderWindow : public QWidget, public EmuWindow
  81. {
  82. Q_OBJECT
  83. public:
  84. GRenderWindow(QWidget* parent, GMainWindow& main_window);
  85. // EmuWindow implementation
  86. void SwapBuffers() override;
  87. void MakeCurrent() override;
  88. void DoneCurrent() override;
  89. void PollEvents() override;
  90. void BackupGeometry();
  91. void RestoreGeometry();
  92. void restoreGeometry(const QByteArray& geometry); // overridden
  93. QByteArray saveGeometry(); // overridden
  94. void keyPressEvent(QKeyEvent* event) override;
  95. void keyReleaseEvent(QKeyEvent* event) override;
  96. void mousePressEvent(QMouseEvent *event) override;
  97. void mouseMoveEvent(QMouseEvent *event) override;
  98. void mouseReleaseEvent(QMouseEvent *event) override;
  99. void ReloadSetKeymaps() override;
  100. void OnClientAreaResized(unsigned width, unsigned height);
  101. void OnFramebufferSizeChanged();
  102. public slots:
  103. void moveContext(); // overridden
  104. private:
  105. void OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& minimal_size) override;
  106. QGLWidget* child;
  107. QByteArray geometry;
  108. GMainWindow& main_window;
  109. /// Device id of keyboard for use with KeyMap
  110. int keyboard_id;
  111. };