bootmanager.hxx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include <atomic>
  2. #include <QThread>
  3. #include <QGLWidget>
  4. #include "common/common.h"
  5. #include "common/emu_window.h"
  6. class QScreen;
  7. class QKeyEvent;
  8. class GRenderWindow;
  9. class EmuThread : public QThread
  10. {
  11. Q_OBJECT
  12. public:
  13. /**
  14. * Set image filename
  15. *
  16. * @param filename
  17. * @warning Only call when not running!
  18. */
  19. void SetFilename(std::string filename);
  20. /**
  21. * Start emulation (on new thread)
  22. *
  23. * @warning Only call when not running!
  24. */
  25. void run() override;
  26. /**
  27. * Allow the CPU to process a single instruction (if cpu is not running)
  28. *
  29. * @note This function is thread-safe
  30. */
  31. void ExecStep() { exec_cpu_step = true; }
  32. /**
  33. * Allow the CPU to continue processing instructions without interruption
  34. *
  35. * @note This function is thread-safe
  36. */
  37. void SetCpuRunning(bool running) { cpu_running = running; }
  38. /**
  39. * Allow the CPU to continue processing instructions without interruption
  40. *
  41. * @note This function is thread-safe
  42. */
  43. bool IsCpuRunning() { return cpu_running; }
  44. public slots:
  45. /**
  46. * Stop emulation and wait for the thread to finish.
  47. *
  48. * @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.
  49. * @note: This function is thread-safe.
  50. */
  51. void Stop();
  52. private:
  53. friend class GRenderWindow;
  54. EmuThread(GRenderWindow* render_window);
  55. std::string filename;
  56. bool exec_cpu_step;
  57. bool cpu_running;
  58. std::atomic<bool> stop_run;
  59. GRenderWindow* render_window;
  60. signals:
  61. /**
  62. * Emitted when CPU when we've finished processing a single Gekko instruction
  63. *
  64. * @warning This will only be emitted when the CPU is not running (SetCpuRunning(false))
  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 CPUStepped();
  68. };
  69. class GRenderWindow : public QWidget, public EmuWindow
  70. {
  71. Q_OBJECT
  72. public:
  73. GRenderWindow(QWidget* parent = NULL);
  74. ~GRenderWindow();
  75. void closeEvent(QCloseEvent*) override;
  76. // EmuWindow implementation
  77. void SwapBuffers() override;
  78. void MakeCurrent() override;
  79. void DoneCurrent() override;
  80. void PollEvents() override;
  81. void BackupGeometry();
  82. void RestoreGeometry();
  83. void restoreGeometry(const QByteArray& geometry); // overridden
  84. QByteArray saveGeometry(); // overridden
  85. EmuThread& GetEmuThread();
  86. void keyPressEvent(QKeyEvent* event) override;
  87. void keyReleaseEvent(QKeyEvent* event) override;
  88. void ReloadSetKeymaps() override;
  89. void OnClientAreaResized(unsigned width, unsigned height);
  90. void OnFramebufferSizeChanged();
  91. public slots:
  92. void moveContext(); // overridden
  93. private:
  94. void OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& minimal_size) override;
  95. QGLWidget* child;
  96. EmuThread emu_thread;
  97. QByteArray geometry;
  98. /// Device id of keyboard for use with KeyMap
  99. int keyboard_id;
  100. };