summaryrefslogtreecommitdiff
path: root/src/citra_qt/bootmanager.cpp
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2016-09-21 11:29:48 -0700
committerGravatar GitHub2016-09-21 11:29:48 -0700
commitd5d2ca8058a0f1c00ab7ca9fe2c058ba47546c0a (patch)
tree8a22ca73ff838f3f0090b29a548ae81087fc90ed /src/citra_qt/bootmanager.cpp
parentREADME: Specify master branch for Travis CI badge (diff)
parentFix Travis clang-format check (diff)
downloadyuzu-d5d2ca8058a0f1c00ab7ca9fe2c058ba47546c0a.tar.gz
yuzu-d5d2ca8058a0f1c00ab7ca9fe2c058ba47546c0a.tar.xz
yuzu-d5d2ca8058a0f1c00ab7ca9fe2c058ba47546c0a.zip
Merge pull request #2086 from linkmauve/clang-format
Add clang-format as part of our {commit,travis}-time checks
Diffstat (limited to 'src/citra_qt/bootmanager.cpp')
-rw-r--r--src/citra_qt/bootmanager.cpp140
1 files changed, 66 insertions, 74 deletions
diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp
index 6dddde9ba..0abae86c3 100644
--- a/src/citra_qt/bootmanager.cpp
+++ b/src/citra_qt/bootmanager.cpp
@@ -9,27 +9,23 @@
9#endif 9#endif
10 10
11#include "citra_qt/bootmanager.h" 11#include "citra_qt/bootmanager.h"
12
13#include "common/key_map.h" 12#include "common/key_map.h"
14#include "common/microprofile.h" 13#include "common/microprofile.h"
15#include "common/scm_rev.h" 14#include "common/scm_rev.h"
16#include "common/string_util.h" 15#include "common/string_util.h"
17
18#include "core/core.h" 16#include "core/core.h"
19#include "core/settings.h" 17#include "core/settings.h"
20#include "core/system.h" 18#include "core/system.h"
21
22#include "video_core/debug_utils/debug_utils.h" 19#include "video_core/debug_utils/debug_utils.h"
23#include "video_core/video_core.h" 20#include "video_core/video_core.h"
24 21
25#define APP_NAME "citra" 22#define APP_NAME "citra"
26#define APP_VERSION "0.1-" VERSION 23#define APP_VERSION "0.1-" VERSION
27#define APP_TITLE APP_NAME " " APP_VERSION 24#define APP_TITLE APP_NAME " " APP_VERSION
28#define COPYRIGHT "Copyright (C) 2013-2014 Citra Team" 25#define COPYRIGHT "Copyright (C) 2013-2014 Citra Team"
29 26
30EmuThread::EmuThread(GRenderWindow* render_window) : 27EmuThread::EmuThread(GRenderWindow* render_window)
31 exec_step(false), running(false), stop_run(false), render_window(render_window) { 28 : exec_step(false), running(false), stop_run(false), render_window(render_window) {}
32}
33 29
34void EmuThread::run() { 30void EmuThread::run() {
35 render_window->MakeCurrent(); 31 render_window->MakeCurrent();
@@ -64,7 +60,7 @@ void EmuThread::run() {
64 was_active = false; 60 was_active = false;
65 } else { 61 } else {
66 std::unique_lock<std::mutex> lock(running_mutex); 62 std::unique_lock<std::mutex> lock(running_mutex);
67 running_cv.wait(lock, [this]{ return IsRunning() || exec_step || stop_run; }); 63 running_cv.wait(lock, [this] { return IsRunning() || exec_step || stop_run; });
68 } 64 }
69 } 65 }
70 66
@@ -78,14 +74,13 @@ void EmuThread::run() {
78 render_window->moveContext(); 74 render_window->moveContext();
79} 75}
80 76
81// This class overrides paintEvent and resizeEvent to prevent the GUI thread from stealing GL context. 77// This class overrides paintEvent and resizeEvent to prevent the GUI thread from stealing GL
78// context.
82// The corresponding functionality is handled in EmuThread instead 79// The corresponding functionality is handled in EmuThread instead
83class GGLWidgetInternal : public QGLWidget 80class GGLWidgetInternal : public QGLWidget {
84{
85public: 81public:
86 GGLWidgetInternal(QGLFormat fmt, GRenderWindow* parent) 82 GGLWidgetInternal(QGLFormat fmt, GRenderWindow* parent)
87 : QGLWidget(fmt, parent), parent(parent) { 83 : QGLWidget(fmt, parent), parent(parent) {}
88 }
89 84
90 void paintEvent(QPaintEvent* ev) override { 85 void paintEvent(QPaintEvent* ev) override {
91 if (do_painting) { 86 if (do_painting) {
@@ -98,37 +93,43 @@ public:
98 parent->OnFramebufferSizeChanged(); 93 parent->OnFramebufferSizeChanged();
99 } 94 }
100 95
101 void DisablePainting() { do_painting = false; } 96 void DisablePainting() {
102 void EnablePainting() { do_painting = true; } 97 do_painting = false;
98 }
99 void EnablePainting() {
100 do_painting = true;
101 }
103 102
104private: 103private:
105 GRenderWindow* parent; 104 GRenderWindow* parent;
106 bool do_painting; 105 bool do_painting;
107}; 106};
108 107
109GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread) : 108GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread)
110 QWidget(parent), keyboard_id(0), emu_thread(emu_thread), child(nullptr) { 109 : QWidget(parent), keyboard_id(0), emu_thread(emu_thread), child(nullptr) {
111 110
112 std::string window_title = Common::StringFromFormat("Citra | %s-%s", Common::g_scm_branch, Common::g_scm_desc); 111 std::string window_title =
112 Common::StringFromFormat("Citra | %s-%s", Common::g_scm_branch, Common::g_scm_desc);
113 setWindowTitle(QString::fromStdString(window_title)); 113 setWindowTitle(QString::fromStdString(window_title));
114 114
115 keyboard_id = KeyMap::NewDeviceId(); 115 keyboard_id = KeyMap::NewDeviceId();
116 ReloadSetKeymaps(); 116 ReloadSetKeymaps();
117} 117}
118 118
119void GRenderWindow::moveContext() 119void GRenderWindow::moveContext() {
120{
121 DoneCurrent(); 120 DoneCurrent();
122 // We need to move GL context to the swapping thread in Qt5 121// We need to move GL context to the swapping thread in Qt5
123#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0) 122#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
124 // If the thread started running, move the GL Context to the new thread. Otherwise, move it back. 123 // If the thread started running, move the GL Context to the new thread. Otherwise, move it
125 auto thread = (QThread::currentThread() == qApp->thread() && emu_thread != nullptr) ? emu_thread : qApp->thread(); 124 // back.
125 auto thread = (QThread::currentThread() == qApp->thread() && emu_thread != nullptr)
126 ? emu_thread
127 : qApp->thread();
126 child->context()->moveToThread(thread); 128 child->context()->moveToThread(thread);
127#endif 129#endif
128} 130}
129 131
130void GRenderWindow::SwapBuffers() 132void GRenderWindow::SwapBuffers() {
131{
132#if !defined(QT_NO_DEBUG) 133#if !defined(QT_NO_DEBUG)
133 // Qt debug runtime prints a bogus warning on the console if you haven't called makeCurrent 134 // Qt debug runtime prints a bogus warning on the console if you haven't called makeCurrent
134 // since the last time you called swapBuffers. This presumably means something if you're using 135 // since the last time you called swapBuffers. This presumably means something if you're using
@@ -139,54 +140,48 @@ void GRenderWindow::SwapBuffers()
139 child->swapBuffers(); 140 child->swapBuffers();
140} 141}
141 142
142void GRenderWindow::MakeCurrent() 143void GRenderWindow::MakeCurrent() {
143{
144 child->makeCurrent(); 144 child->makeCurrent();
145} 145}
146 146
147void GRenderWindow::DoneCurrent() 147void GRenderWindow::DoneCurrent() {
148{
149 child->doneCurrent(); 148 child->doneCurrent();
150} 149}
151 150
152void GRenderWindow::PollEvents() { 151void GRenderWindow::PollEvents() {}
153}
154 152
155// On Qt 5.0+, this correctly gets the size of the framebuffer (pixels). 153// On Qt 5.0+, this correctly gets the size of the framebuffer (pixels).
156// 154//
157// Older versions get the window size (density independent pixels), 155// Older versions get the window size (density independent pixels),
158// and hence, do not support DPI scaling ("retina" displays). 156// and hence, do not support DPI scaling ("retina" displays).
159// The result will be a viewport that is smaller than the extent of the window. 157// The result will be a viewport that is smaller than the extent of the window.
160void GRenderWindow::OnFramebufferSizeChanged() 158void GRenderWindow::OnFramebufferSizeChanged() {
161{ 159 // Screen changes potentially incur a change in screen DPI, hence we should update the
162 // Screen changes potentially incur a change in screen DPI, hence we should update the framebuffer size 160 // framebuffer size
163 qreal pixelRatio = windowPixelRatio(); 161 qreal pixelRatio = windowPixelRatio();
164 unsigned width = child->QPaintDevice::width() * pixelRatio; 162 unsigned width = child->QPaintDevice::width() * pixelRatio;
165 unsigned height = child->QPaintDevice::height() * pixelRatio; 163 unsigned height = child->QPaintDevice::height() * pixelRatio;
166 164
167 NotifyFramebufferLayoutChanged(EmuWindow::FramebufferLayout::DefaultScreenLayout(width, height)); 165 NotifyFramebufferLayoutChanged(
166 EmuWindow::FramebufferLayout::DefaultScreenLayout(width, height));
168} 167}
169 168
170void GRenderWindow::BackupGeometry() 169void GRenderWindow::BackupGeometry() {
171{
172 geometry = ((QGLWidget*)this)->saveGeometry(); 170 geometry = ((QGLWidget*)this)->saveGeometry();
173} 171}
174 172
175void GRenderWindow::RestoreGeometry() 173void GRenderWindow::RestoreGeometry() {
176{
177 // We don't want to back up the geometry here (obviously) 174 // We don't want to back up the geometry here (obviously)
178 QWidget::restoreGeometry(geometry); 175 QWidget::restoreGeometry(geometry);
179} 176}
180 177
181void GRenderWindow::restoreGeometry(const QByteArray& geometry) 178void GRenderWindow::restoreGeometry(const QByteArray& geometry) {
182{
183 // Make sure users of this class don't need to deal with backing up the geometry themselves 179 // Make sure users of this class don't need to deal with backing up the geometry themselves
184 QWidget::restoreGeometry(geometry); 180 QWidget::restoreGeometry(geometry);
185 BackupGeometry(); 181 BackupGeometry();
186} 182}
187 183
188QByteArray GRenderWindow::saveGeometry() 184QByteArray GRenderWindow::saveGeometry() {
189{
190 // If we are a top-level widget, store the current geometry 185 // If we are a top-level widget, store the current geometry
191 // otherwise, store the last backup 186 // otherwise, store the last backup
192 if (parent() == nullptr) 187 if (parent() == nullptr)
@@ -195,8 +190,7 @@ QByteArray GRenderWindow::saveGeometry()
195 return geometry; 190 return geometry;
196} 191}
197 192
198qreal GRenderWindow::windowPixelRatio() 193qreal GRenderWindow::windowPixelRatio() {
199{
200#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) 194#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
201 // windowHandle() might not be accessible until the window is displayed to screen. 195 // windowHandle() might not be accessible until the window is displayed to screen.
202 return windowHandle() ? windowHandle()->screen()->devicePixelRatio() : 1.0f; 196 return windowHandle() ? windowHandle()->screen()->devicePixelRatio() : 1.0f;
@@ -210,20 +204,16 @@ void GRenderWindow::closeEvent(QCloseEvent* event) {
210 QWidget::closeEvent(event); 204 QWidget::closeEvent(event);
211} 205}
212 206
213void GRenderWindow::keyPressEvent(QKeyEvent* event) 207void GRenderWindow::keyPressEvent(QKeyEvent* event) {
214{ 208 KeyMap::PressKey(*this, {event->key(), keyboard_id});
215 KeyMap::PressKey(*this, { event->key(), keyboard_id });
216} 209}
217 210
218void GRenderWindow::keyReleaseEvent(QKeyEvent* event) 211void GRenderWindow::keyReleaseEvent(QKeyEvent* event) {
219{ 212 KeyMap::ReleaseKey(*this, {event->key(), keyboard_id});
220 KeyMap::ReleaseKey(*this, { event->key(), keyboard_id });
221} 213}
222 214
223void GRenderWindow::mousePressEvent(QMouseEvent *event) 215void GRenderWindow::mousePressEvent(QMouseEvent* event) {
224{ 216 if (event->button() == Qt::LeftButton) {
225 if (event->button() == Qt::LeftButton)
226 {
227 auto pos = event->pos(); 217 auto pos = event->pos();
228 qreal pixelRatio = windowPixelRatio(); 218 qreal pixelRatio = windowPixelRatio();
229 this->TouchPressed(static_cast<unsigned>(pos.x() * pixelRatio), 219 this->TouchPressed(static_cast<unsigned>(pos.x() * pixelRatio),
@@ -231,30 +221,28 @@ void GRenderWindow::mousePressEvent(QMouseEvent *event)
231 } 221 }
232} 222}
233 223
234void GRenderWindow::mouseMoveEvent(QMouseEvent *event) 224void GRenderWindow::mouseMoveEvent(QMouseEvent* event) {
235{
236 auto pos = event->pos(); 225 auto pos = event->pos();
237 qreal pixelRatio = windowPixelRatio(); 226 qreal pixelRatio = windowPixelRatio();
238 this->TouchMoved(std::max(static_cast<unsigned>(pos.x() * pixelRatio), 0u), 227 this->TouchMoved(std::max(static_cast<unsigned>(pos.x() * pixelRatio), 0u),
239 std::max(static_cast<unsigned>(pos.y() * pixelRatio), 0u)); 228 std::max(static_cast<unsigned>(pos.y() * pixelRatio), 0u));
240} 229}
241 230
242void GRenderWindow::mouseReleaseEvent(QMouseEvent *event) 231void GRenderWindow::mouseReleaseEvent(QMouseEvent* event) {
243{
244 if (event->button() == Qt::LeftButton) 232 if (event->button() == Qt::LeftButton)
245 this->TouchReleased(); 233 this->TouchReleased();
246} 234}
247 235
248void GRenderWindow::ReloadSetKeymaps() 236void GRenderWindow::ReloadSetKeymaps() {
249{
250 KeyMap::ClearKeyMapping(keyboard_id); 237 KeyMap::ClearKeyMapping(keyboard_id);
251 for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) { 238 for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) {
252 KeyMap::SetKeyMapping({ Settings::values.input_mappings[Settings::NativeInput::All[i]], keyboard_id }, KeyMap::mapping_targets[i]); 239 KeyMap::SetKeyMapping(
240 {Settings::values.input_mappings[Settings::NativeInput::All[i]], keyboard_id},
241 KeyMap::mapping_targets[i]);
253 } 242 }
254} 243}
255 244
256void GRenderWindow::OnClientAreaResized(unsigned width, unsigned height) 245void GRenderWindow::OnClientAreaResized(unsigned width, unsigned height) {
257{
258 NotifyClientAreaSizeChanged(std::make_pair(width, height)); 246 NotifyClientAreaSizeChanged(std::make_pair(width, height));
259} 247}
260 248
@@ -267,7 +255,8 @@ void GRenderWindow::InitRenderTarget() {
267 delete layout(); 255 delete layout();
268 } 256 }
269 257
270 // TODO: One of these flags might be interesting: WA_OpaquePaintEvent, WA_NoBackground, WA_DontShowOnScreen, WA_DeleteOnClose 258 // TODO: One of these flags might be interesting: WA_OpaquePaintEvent, WA_NoBackground,
259 // WA_DontShowOnScreen, WA_DeleteOnClose
271 QGLFormat fmt; 260 QGLFormat fmt;
272 fmt.setVersion(3, 3); 261 fmt.setVersion(3, 3);
273 fmt.setProfile(QGLFormat::CoreProfile); 262 fmt.setProfile(QGLFormat::CoreProfile);
@@ -279,7 +268,8 @@ void GRenderWindow::InitRenderTarget() {
279 child = new GGLWidgetInternal(fmt, this); 268 child = new GGLWidgetInternal(fmt, this);
280 QBoxLayout* layout = new QHBoxLayout(this); 269 QBoxLayout* layout = new QHBoxLayout(this);
281 270
282 resize(VideoCore::kScreenTopWidth, VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight); 271 resize(VideoCore::kScreenTopWidth,
272 VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight);
283 layout->addWidget(child); 273 layout->addWidget(child);
284 layout->setMargin(0); 274 layout->setMargin(0);
285 setLayout(layout); 275 setLayout(layout);
@@ -292,7 +282,8 @@ void GRenderWindow::InitRenderTarget() {
292 BackupGeometry(); 282 BackupGeometry();
293} 283}
294 284
295void GRenderWindow::OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& minimal_size) { 285void GRenderWindow::OnMinimalClientAreaChangeRequest(
286 const std::pair<unsigned, unsigned>& minimal_size) {
296 setMinimumSize(minimal_size.first, minimal_size.second); 287 setMinimumSize(minimal_size.first, minimal_size.second);
297} 288}
298 289
@@ -306,11 +297,12 @@ void GRenderWindow::OnEmulationStopping() {
306 child->EnablePainting(); 297 child->EnablePainting();
307} 298}
308 299
309void GRenderWindow::showEvent(QShowEvent * event) { 300void GRenderWindow::showEvent(QShowEvent* event) {
310 QWidget::showEvent(event); 301 QWidget::showEvent(event);
311 302
303#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
312 // windowHandle() is not initialized until the Window is shown, so we connect it here. 304 // windowHandle() is not initialized until the Window is shown, so we connect it here.
313 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) 305 connect(this->windowHandle(), SIGNAL(screenChanged(QScreen*)), this,
314 connect(this->windowHandle(), SIGNAL(screenChanged(QScreen*)), this, SLOT(OnFramebufferSizeChanged()), Qt::UniqueConnection); 306 SLOT(OnFramebufferSizeChanged()), Qt::UniqueConnection);
315 #endif 307#endif
316} 308}