bootmanager.h 4.5 KB

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