bootmanager.h 4.2 KB

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