mirror of
https://github.com/citra-emu/citra.git
synced 2024-11-25 15:50:13 +00:00
cleanup
This commit is contained in:
parent
6ab731648b
commit
8aa5a2c64f
@ -54,8 +54,7 @@ void EmuThread::run() {
|
|||||||
was_active = running || exec_step;
|
was_active = running || exec_step;
|
||||||
if (!was_active && !stop_run)
|
if (!was_active && !stop_run)
|
||||||
emit DebugModeEntered();
|
emit DebugModeEntered();
|
||||||
}
|
} else if (exec_step) {
|
||||||
else if (exec_step) {
|
|
||||||
if (!was_active)
|
if (!was_active)
|
||||||
emit DebugModeLeft();
|
emit DebugModeLeft();
|
||||||
|
|
||||||
@ -65,10 +64,9 @@ void EmuThread::run() {
|
|||||||
yieldCurrentThread();
|
yieldCurrentThread();
|
||||||
|
|
||||||
was_active = false;
|
was_active = false;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
std::unique_lock<std::mutex> lock(running_mutex);
|
std::unique_lock<std::mutex> lock(running_mutex);
|
||||||
running_cv.wait(lock, [this] { return IsRunning() || exec_step || stop_run; });
|
running_cv.wait(lock, [this]{ return IsRunning() || exec_step || stop_run; });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,10 +82,11 @@ void EmuThread::run() {
|
|||||||
|
|
||||||
// This class overrides paintEvent and resizeEvent to prevent the GUI thread from stealing GL context.
|
// This class overrides paintEvent and resizeEvent to prevent the GUI thread from stealing GL context.
|
||||||
// The corresponding functionality is handled in EmuThread instead
|
// The corresponding functionality is handled in EmuThread instead
|
||||||
class GGLWidgetInternal : public QGLWidget {
|
class GGLWidgetInternal : public QGLWidget
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
GGLWidgetInternal(QGLFormat fmt, GRenderWindow* parent)
|
GGLWidgetInternal(QGLFormat fmt, GRenderWindow* parent)
|
||||||
: QGLWidget(fmt, parent), parent(parent) {
|
: QGLWidget(fmt, parent), parent(parent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void paintEvent(QPaintEvent* ev) override {
|
void paintEvent(QPaintEvent* ev) override {
|
||||||
@ -120,7 +119,7 @@ GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread) :
|
|||||||
|
|
||||||
// TODO: One of these flags might be interesting: WA_OpaquePaintEvent, WA_NoBackground, WA_DontShowOnScreen, WA_DeleteOnClose
|
// TODO: One of these flags might be interesting: WA_OpaquePaintEvent, WA_NoBackground, WA_DontShowOnScreen, WA_DeleteOnClose
|
||||||
QGLFormat fmt;
|
QGLFormat fmt;
|
||||||
fmt.setVersion(3, 3);
|
fmt.setVersion(3,3);
|
||||||
fmt.setProfile(QGLFormat::CoreProfile);
|
fmt.setProfile(QGLFormat::CoreProfile);
|
||||||
// Requests a forward-compatible context, which is required to get a 3.2+ context on OS X
|
// Requests a forward-compatible context, which is required to get a 3.2+ context on OS X
|
||||||
fmt.setOption(QGL::NoDeprecatedFunctions);
|
fmt.setOption(QGL::NoDeprecatedFunctions);
|
||||||
@ -136,13 +135,14 @@ GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread) :
|
|||||||
OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size);
|
OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size);
|
||||||
|
|
||||||
OnFramebufferSizeChanged();
|
OnFramebufferSizeChanged();
|
||||||
NotifyClientAreaSizeChanged(std::pair<unsigned, unsigned>(child->width(), child->height()));
|
NotifyClientAreaSizeChanged(std::pair<unsigned,unsigned>(child->width(), child->height()));
|
||||||
|
|
||||||
BackupGeometry();
|
BackupGeometry();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRenderWindow::moveContext() {
|
void GRenderWindow::moveContext()
|
||||||
|
{
|
||||||
DoneCurrent();
|
DoneCurrent();
|
||||||
// We need to move GL context to the swapping thread in Qt5
|
// We need to move GL context to the swapping thread in Qt5
|
||||||
#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
|
#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
|
||||||
@ -152,7 +152,8 @@ void GRenderWindow::moveContext() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRenderWindow::SwapBuffers() {
|
void GRenderWindow::SwapBuffers()
|
||||||
|
{
|
||||||
#if !defined(QT_NO_DEBUG)
|
#if !defined(QT_NO_DEBUG)
|
||||||
// Qt debug runtime prints a bogus warning on the console if you haven't called makeCurrent
|
// Qt debug runtime prints a bogus warning on the console if you haven't called makeCurrent
|
||||||
// since the last time you called swapBuffers. This presumably means something if you're using
|
// since the last time you called swapBuffers. This presumably means something if you're using
|
||||||
@ -163,11 +164,13 @@ void GRenderWindow::SwapBuffers() {
|
|||||||
child->swapBuffers();
|
child->swapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRenderWindow::MakeCurrent() {
|
void GRenderWindow::MakeCurrent()
|
||||||
|
{
|
||||||
child->makeCurrent();
|
child->makeCurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRenderWindow::DoneCurrent() {
|
void GRenderWindow::DoneCurrent()
|
||||||
|
{
|
||||||
child->doneCurrent();
|
child->doneCurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +182,8 @@ void GRenderWindow::PollEvents() {
|
|||||||
// Older versions get the window size (density independent pixels),
|
// Older versions get the window size (density independent pixels),
|
||||||
// and hence, do not support DPI scaling ("retina" displays).
|
// and hence, do not support DPI scaling ("retina" displays).
|
||||||
// The result will be a viewport that is smaller than the extent of the window.
|
// The result will be a viewport that is smaller than the extent of the window.
|
||||||
void GRenderWindow::OnFramebufferSizeChanged() {
|
void GRenderWindow::OnFramebufferSizeChanged()
|
||||||
|
{
|
||||||
// Screen changes potentially incur a change in screen DPI, hence we should update the framebuffer size
|
// Screen changes potentially incur a change in screen DPI, hence we should update the framebuffer size
|
||||||
qreal pixelRatio = windowPixelRatio();
|
qreal pixelRatio = windowPixelRatio();
|
||||||
unsigned width = child->QPaintDevice::width() * pixelRatio;
|
unsigned width = child->QPaintDevice::width() * pixelRatio;
|
||||||
@ -188,22 +192,26 @@ void GRenderWindow::OnFramebufferSizeChanged() {
|
|||||||
NotifyFramebufferLayoutChanged(EmuWindow::FramebufferLayout::DefaultScreenLayout(width, height));
|
NotifyFramebufferLayoutChanged(EmuWindow::FramebufferLayout::DefaultScreenLayout(width, height));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRenderWindow::BackupGeometry() {
|
void GRenderWindow::BackupGeometry()
|
||||||
|
{
|
||||||
geometry = ((QGLWidget*)this)->saveGeometry();
|
geometry = ((QGLWidget*)this)->saveGeometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRenderWindow::RestoreGeometry() {
|
void GRenderWindow::RestoreGeometry()
|
||||||
|
{
|
||||||
// We don't want to back up the geometry here (obviously)
|
// We don't want to back up the geometry here (obviously)
|
||||||
QWidget::restoreGeometry(geometry);
|
QWidget::restoreGeometry(geometry);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRenderWindow::restoreGeometry(const QByteArray& geometry) {
|
void GRenderWindow::restoreGeometry(const QByteArray& geometry)
|
||||||
|
{
|
||||||
// Make sure users of this class don't need to deal with backing up the geometry themselves
|
// Make sure users of this class don't need to deal with backing up the geometry themselves
|
||||||
QWidget::restoreGeometry(geometry);
|
QWidget::restoreGeometry(geometry);
|
||||||
BackupGeometry();
|
BackupGeometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray GRenderWindow::saveGeometry() {
|
QByteArray GRenderWindow::saveGeometry()
|
||||||
|
{
|
||||||
// If we are a top-level widget, store the current geometry
|
// If we are a top-level widget, store the current geometry
|
||||||
// otherwise, store the last backup
|
// otherwise, store the last backup
|
||||||
if (parent() == nullptr)
|
if (parent() == nullptr)
|
||||||
@ -212,7 +220,8 @@ QByteArray GRenderWindow::saveGeometry() {
|
|||||||
return geometry;
|
return geometry;
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal GRenderWindow::windowPixelRatio() {
|
qreal GRenderWindow::windowPixelRatio()
|
||||||
|
{
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||||
// windowHandle() might not be accessible until the window is displayed to screen.
|
// windowHandle() might not be accessible until the window is displayed to screen.
|
||||||
return windowHandle() ? windowHandle()->screen()->devicePixelRatio() : 1.0f;
|
return windowHandle() ? windowHandle()->screen()->devicePixelRatio() : 1.0f;
|
||||||
@ -226,51 +235,59 @@ void GRenderWindow::closeEvent(QCloseEvent* event) {
|
|||||||
QWidget::closeEvent(event);
|
QWidget::closeEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRenderWindow::keyPressEvent(QKeyEvent* event) {
|
void GRenderWindow::keyPressEvent(QKeyEvent* event)
|
||||||
|
{
|
||||||
auto& keyboard = InputCore::main_keyboard;
|
auto& keyboard = InputCore::main_keyboard;
|
||||||
KeyboardKey param = KeyboardKey(event->key(), event->nativeScanCode(), QKeySequence(event->key()).toString().toStdString());
|
KeyboardKey param = KeyboardKey(event->key(), event->nativeScanCode(), QKeySequence(event->key()).toString().toStdString());
|
||||||
keyboard->KeyPressed(param);
|
keyboard->KeyPressed(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRenderWindow::keyReleaseEvent(QKeyEvent* event) {
|
void GRenderWindow::keyReleaseEvent(QKeyEvent* event)
|
||||||
|
{
|
||||||
auto& keyboard = InputCore::main_keyboard;
|
auto& keyboard = InputCore::main_keyboard;
|
||||||
KeyboardKey param = KeyboardKey(event->key(), event->nativeScanCode(), QKeySequence(event->key()).toString().toStdString());
|
KeyboardKey param = KeyboardKey(event->key(), event->nativeScanCode(), QKeySequence(event->key()).toString().toStdString());
|
||||||
keyboard->KeyReleased(param);
|
keyboard->KeyReleased(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRenderWindow::mousePressEvent(QMouseEvent *event) {
|
void GRenderWindow::mousePressEvent(QMouseEvent *event)
|
||||||
if (event->button() == Qt::LeftButton) {
|
{
|
||||||
|
if (event->button() == Qt::LeftButton)
|
||||||
|
{
|
||||||
auto pos = event->pos();
|
auto pos = event->pos();
|
||||||
qreal pixelRatio = windowPixelRatio();
|
qreal pixelRatio = windowPixelRatio();
|
||||||
this->TouchPressed(static_cast<unsigned>(pos.x() * pixelRatio),
|
this->TouchPressed(static_cast<unsigned>(pos.x() * pixelRatio),
|
||||||
static_cast<unsigned>(pos.y() * pixelRatio));
|
static_cast<unsigned>(pos.y() * pixelRatio));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRenderWindow::mouseMoveEvent(QMouseEvent *event) {
|
void GRenderWindow::mouseMoveEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
auto pos = event->pos();
|
auto pos = event->pos();
|
||||||
qreal pixelRatio = windowPixelRatio();
|
qreal pixelRatio = windowPixelRatio();
|
||||||
this->TouchMoved(std::max(static_cast<unsigned>(pos.x() * pixelRatio), 0u),
|
this->TouchMoved(std::max(static_cast<unsigned>(pos.x() * pixelRatio), 0u),
|
||||||
std::max(static_cast<unsigned>(pos.y() * pixelRatio), 0u));
|
std::max(static_cast<unsigned>(pos.y() * pixelRatio), 0u));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRenderWindow::mouseReleaseEvent(QMouseEvent *event) {
|
void GRenderWindow::mouseReleaseEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
if (event->button() == Qt::LeftButton)
|
if (event->button() == Qt::LeftButton)
|
||||||
this->TouchReleased();
|
this->TouchReleased();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRenderWindow::ReloadSetKeymaps() {
|
void GRenderWindow::ReloadSetKeymaps()
|
||||||
|
{
|
||||||
/*KeyMap::ClearKeyMapping(keyboard_id);
|
/*KeyMap::ClearKeyMapping(keyboard_id);
|
||||||
for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) {
|
for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) {
|
||||||
KeyMap::SetKeyMapping({ Settings::values.input_mappings[Settings::NativeInput::All[i]], keyboard_id }, KeyMap::mapping_targets[i]);
|
KeyMap::SetKeyMapping({ Settings::values.input_mappings[Settings::NativeInput::All[i]], keyboard_id }, KeyMap::mapping_targets[i]);
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRenderWindow::OnClientAreaResized(unsigned width, unsigned height) {
|
void GRenderWindow::OnClientAreaResized(unsigned width, unsigned height)
|
||||||
|
{
|
||||||
NotifyClientAreaSizeChanged(std::make_pair(width, height));
|
NotifyClientAreaSizeChanged(std::make_pair(width, height));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRenderWindow::OnMinimalClientAreaChangeRequest(const std::pair<unsigned, unsigned>& minimal_size) {
|
void GRenderWindow::OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& minimal_size) {
|
||||||
setMinimumSize(minimal_size.first, minimal_size.second);
|
setMinimumSize(minimal_size.first, minimal_size.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,7 +305,7 @@ void GRenderWindow::showEvent(QShowEvent * event) {
|
|||||||
QWidget::showEvent(event);
|
QWidget::showEvent(event);
|
||||||
|
|
||||||
// windowHandle() is not initialized until the Window is shown, so we connect it here.
|
// windowHandle() is not initialized until the Window is shown, so we connect it here.
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||||
connect(this->windowHandle(), SIGNAL(screenChanged(QScreen*)), this, SLOT(OnFramebufferSizeChanged()), Qt::UniqueConnection);
|
connect(this->windowHandle(), SIGNAL(screenChanged(QScreen*)), this, SLOT(OnFramebufferSizeChanged()), Qt::UniqueConnection);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user