summaryrefslogtreecommitdiff
path: root/src/citra_qt/bootmanager.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/citra_qt/bootmanager.h')
-rw-r--r--src/citra_qt/bootmanager.h138
1 files changed, 138 insertions, 0 deletions
diff --git a/src/citra_qt/bootmanager.h b/src/citra_qt/bootmanager.h
new file mode 100644
index 000000000..1c893384c
--- /dev/null
+++ b/src/citra_qt/bootmanager.h
@@ -0,0 +1,138 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <atomic>
6
7#include <QThread>
8#include <QGLWidget>
9
10#include "common/common.h"
11#include "common/emu_window.h"
12
13class QScreen;
14class QKeyEvent;
15
16class GRenderWindow;
17
18class EmuThread : public QThread
19{
20 Q_OBJECT
21
22public:
23 /**
24 * Set image filename
25 *
26 * @param filename
27 * @warning Only call when not running!
28 */
29 void SetFilename(std::string filename);
30
31 /**
32 * Start emulation (on new thread)
33 *
34 * @warning Only call when not running!
35 */
36 void run() override;
37
38 /**
39 * Allow the CPU to process a single instruction (if cpu is not running)
40 *
41 * @note This function is thread-safe
42 */
43 void ExecStep() { exec_cpu_step = true; }
44
45 /**
46 * Allow the CPU to continue processing instructions without interruption
47 *
48 * @note This function is thread-safe
49 */
50 void SetCpuRunning(bool running) { cpu_running = running; }
51
52 /**
53 * Allow the CPU to continue processing instructions without interruption
54 *
55 * @note This function is thread-safe
56 */
57 bool IsCpuRunning() { return cpu_running; }
58
59
60public slots:
61 /**
62 * Stop emulation and wait for the thread to finish.
63 *
64 * @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.
65 * @note: This function is thread-safe.
66 */
67 void Stop();
68
69private:
70 friend class GRenderWindow;
71
72 EmuThread(GRenderWindow* render_window);
73
74 std::string filename;
75
76 bool exec_cpu_step;
77 bool cpu_running;
78 std::atomic<bool> stop_run;
79
80 GRenderWindow* render_window;
81
82signals:
83 /**
84 * Emitted when CPU when we've finished processing a single Gekko instruction
85 *
86 * @warning This will only be emitted when the CPU is not running (SetCpuRunning(false))
87 * @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)
88 */
89 void CPUStepped();
90};
91
92class GRenderWindow : public QWidget, public EmuWindow
93{
94 Q_OBJECT
95
96public:
97 GRenderWindow(QWidget* parent = NULL);
98 ~GRenderWindow();
99
100 void closeEvent(QCloseEvent*) override;
101
102 // EmuWindow implementation
103 void SwapBuffers() override;
104 void MakeCurrent() override;
105 void DoneCurrent() override;
106 void PollEvents() override;
107
108 void BackupGeometry();
109 void RestoreGeometry();
110 void restoreGeometry(const QByteArray& geometry); // overridden
111 QByteArray saveGeometry(); // overridden
112
113 EmuThread& GetEmuThread();
114
115 void keyPressEvent(QKeyEvent* event) override;
116 void keyReleaseEvent(QKeyEvent* event) override;
117
118 void ReloadSetKeymaps() override;
119
120 void OnClientAreaResized(unsigned width, unsigned height);
121
122 void OnFramebufferSizeChanged();
123
124public slots:
125 void moveContext(); // overridden
126
127private:
128 void OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& minimal_size) override;
129
130 QGLWidget* child;
131
132 EmuThread emu_thread;
133
134 QByteArray geometry;
135
136 /// Device id of keyboard for use with KeyMap
137 int keyboard_id;
138};