This commit is contained in:
Anon 2016-07-30 10:26:25 -05:00
parent 6ab731648b
commit 8aa5a2c64f

View File

@ -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,8 +64,7 @@ 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,7 +82,8 @@ 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) {
@ -142,7 +141,8 @@ GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread) :
} }
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,20 +235,24 @@ 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),
@ -247,26 +260,30 @@ void GRenderWindow::mousePressEvent(QMouseEvent *event) {
} }
} }
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));
} }