forked from hrydgard/ppsspp
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathQtMain.h
189 lines (152 loc) · 3.53 KB
/
QtMain.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#ifndef QTMAIN_H
#define QTMAIN_H
#include <QTouchEvent>
#include <QMouseEvent>
#include <QInputDialog>
#include "Common/GPU/OpenGL/GLSLProgram.h"
#include <QGLWidget>
#ifndef SDL
#include <QAudioOutput>
#include <QAudioFormat>
#endif
#if defined(MOBILE_DEVICE)
#include <QAccelerometer>
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QTM_USE_NAMESPACE
#endif
#endif
#include <cassert>
#include <atomic>
#include <thread>
#include "Common/System/Display.h"
#include "Common/TimeUtil.h"
#include "Common/File/VFS/VFS.h"
#include "Common/File/VFS/DirectoryReader.h"
#include "Common/GPU/OpenGL/GLCommon.h"
#include "Common/GPU/OpenGL/GLFeatures.h"
#include "Common/Input/InputState.h"
#include "Common/Input/KeyCodes.h"
#include "Common/GPU/thin3d.h"
#include "Common/Net/Resolve.h"
#include "NKCodeFromQt.h"
#include "Common/GraphicsContext.h"
#include "Core/Core.h"
#include "Core/Config.h"
#include "Core/ConfigValues.h"
#include "Core/System.h"
#include "Common/GPU/thin3d_create.h"
#include "Common/GPU/OpenGL/GLRenderManager.h"
// Input
void SimulateGamepad();
class QtGLGraphicsContext : public GraphicsContext {
public:
QtGLGraphicsContext() {
CheckGLExtensions();
draw_ = Draw::T3DCreateGLContext(false);
SetGPUBackend(GPUBackend::OPENGL);
renderManager_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
renderManager_->SetInflightFrames(g_Config.iInflightFrames);
bool success = draw_->CreatePresets();
_assert_msg_(success, "Failed to compile preset shaders");
// TODO: Need to figure out how to implement SetSwapInterval for Qt.
}
~QtGLGraphicsContext() {
delete draw_;
draw_ = nullptr;
renderManager_ = nullptr;
}
void Shutdown() override {}
void Resize() override {}
Draw::DrawContext *GetDrawContext() override {
return draw_;
}
void ThreadStart() override {
renderManager_->ThreadStart(draw_);
}
bool ThreadFrame() override {
return renderManager_->ThreadFrame();
}
void ThreadEnd() override {
renderManager_->ThreadEnd();
}
void StopThread() override {
renderManager_->StopThread();
}
private:
Draw::DrawContext *draw_ = nullptr;
GLRenderManager *renderManager_ = nullptr;
};
enum class EmuThreadState {
DISABLED,
START_REQUESTED,
RUNNING,
QUIT_REQUESTED,
STOPPED,
};
// GUI, thread manager
class MainUI : public QGLWidget
{
Q_OBJECT
public:
explicit MainUI(QWidget *parent = 0);
~MainUI();
void resizeGL(int w, int h);
public slots:
QString InputBoxGetQString(QString title, QString defaultValue);
signals:
void doubleClick();
void newFrame();
protected:
void timerEvent(QTimerEvent *);
void changeEvent(QEvent *e);
bool event(QEvent *e);
void initializeGL();
void paintGL();
void updateAccelerometer();
void EmuThreadFunc();
void EmuThreadStart();
void EmuThreadStop();
void EmuThreadJoin();
private:
bool HandleCustomEvent(QEvent *e);
QtGLGraphicsContext *graphicsContext;
float xscale, yscale;
#if defined(MOBILE_DEVICE)
QAccelerometer* acc;
#endif
std::thread emuThread;
std::atomic<int> emuThreadState;
};
class QTCamera : public QObject {
Q_OBJECT
public:
QTCamera() {}
~QTCamera() {};
signals:
void onStartCamera(int width, int height);
void onStopCamera();
public slots:
void startCamera(int width, int height);
void stopCamera();
};
extern MainUI* emugl;
#ifndef SDL
// AUDIO
class MainAudio : public QObject {
Q_OBJECT
public:
MainAudio() {}
~MainAudio();
public slots:
void run();
protected:
void timerEvent(QTimerEvent *);
private:
QIODevice* feed;
QAudioOutput* output;
int mixlen;
char* mixbuf;
int timer;
};
#endif //SDL
#endif