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;
if (!was_active && !stop_run)
emit DebugModeEntered();
}
else if (exec_step) {
} else if (exec_step) {
if (!was_active)
emit DebugModeLeft();
@ -65,10 +64,9 @@ void EmuThread::run() {
yieldCurrentThread();
was_active = false;
}
else {
} else {
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.
// The corresponding functionality is handled in EmuThread instead
class GGLWidgetInternal : public QGLWidget {
class GGLWidgetInternal : public QGLWidget
{
public:
GGLWidgetInternal(QGLFormat fmt, GRenderWindow* parent)
: QGLWidget(fmt, parent), parent(parent) {
@ -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
QGLFormat fmt;
fmt.setVersion(3, 3);
fmt.setVersion(3,3);
fmt.setProfile(QGLFormat::CoreProfile);
// Requests a forward-compatible context, which is required to get a 3.2+ context on OS X
fmt.setOption(QGL::NoDeprecatedFunctions);
@ -136,13 +135,14 @@ GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread) :
OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size);
OnFramebufferSizeChanged();
NotifyClientAreaSizeChanged(std::pair<unsigned, unsigned>(child->width(), child->height()));
NotifyClientAreaSizeChanged(std::pair<unsigned,unsigned>(child->width(), child->height()));
BackupGeometry();
}
void GRenderWindow::moveContext() {
void GRenderWindow::moveContext()
{
DoneCurrent();
// We need to move GL context to the swapping thread in Qt5
#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
@ -152,7 +152,8 @@ void GRenderWindow::moveContext() {
#endif
}
void GRenderWindow::SwapBuffers() {
void GRenderWindow::SwapBuffers()
{
#if !defined(QT_NO_DEBUG)
// 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
@ -163,11 +164,13 @@ void GRenderWindow::SwapBuffers() {
child->swapBuffers();
}
void GRenderWindow::MakeCurrent() {
void GRenderWindow::MakeCurrent()
{
child->makeCurrent();
}
void GRenderWindow::DoneCurrent() {
void GRenderWindow::DoneCurrent()
{
child->doneCurrent();
}
@ -179,7 +182,8 @@ void GRenderWindow::PollEvents() {
// Older versions get the window size (density independent pixels),
// and hence, do not support DPI scaling ("retina" displays).
// 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
qreal pixelRatio = windowPixelRatio();
unsigned width = child->QPaintDevice::width() * pixelRatio;
@ -188,22 +192,26 @@ void GRenderWindow::OnFramebufferSizeChanged() {
NotifyFramebufferLayoutChanged(EmuWindow::FramebufferLayout::DefaultScreenLayout(width, height));
}
void GRenderWindow::BackupGeometry() {
void GRenderWindow::BackupGeometry()
{
geometry = ((QGLWidget*)this)->saveGeometry();
}
void GRenderWindow::RestoreGeometry() {
void GRenderWindow::RestoreGeometry()
{
// We don't want to back up the geometry here (obviously)
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
QWidget::restoreGeometry(geometry);
BackupGeometry();
}
QByteArray GRenderWindow::saveGeometry() {
QByteArray GRenderWindow::saveGeometry()
{
// If we are a top-level widget, store the current geometry
// otherwise, store the last backup
if (parent() == nullptr)
@ -212,7 +220,8 @@ QByteArray GRenderWindow::saveGeometry() {
return geometry;
}
qreal GRenderWindow::windowPixelRatio() {
qreal GRenderWindow::windowPixelRatio()
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
// windowHandle() might not be accessible until the window is displayed to screen.
return windowHandle() ? windowHandle()->screen()->devicePixelRatio() : 1.0f;
@ -226,20 +235,24 @@ void GRenderWindow::closeEvent(QCloseEvent* event) {
QWidget::closeEvent(event);
}
void GRenderWindow::keyPressEvent(QKeyEvent* event) {
void GRenderWindow::keyPressEvent(QKeyEvent* event)
{
auto& keyboard = InputCore::main_keyboard;
KeyboardKey param = KeyboardKey(event->key(), event->nativeScanCode(), QKeySequence(event->key()).toString().toStdString());
keyboard->KeyPressed(param);
}
void GRenderWindow::keyReleaseEvent(QKeyEvent* event) {
void GRenderWindow::keyReleaseEvent(QKeyEvent* event)
{
auto& keyboard = InputCore::main_keyboard;
KeyboardKey param = KeyboardKey(event->key(), event->nativeScanCode(), QKeySequence(event->key()).toString().toStdString());
keyboard->KeyReleased(param);
}
void GRenderWindow::mousePressEvent(QMouseEvent *event) {
if (event->button() == Qt::LeftButton) {
void GRenderWindow::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
auto pos = event->pos();
qreal pixelRatio = windowPixelRatio();
this->TouchPressed(static_cast<unsigned>(pos.x() * pixelRatio),
@ -247,30 +260,34 @@ void GRenderWindow::mousePressEvent(QMouseEvent *event) {
}
}
void GRenderWindow::mouseMoveEvent(QMouseEvent *event) {
void GRenderWindow::mouseMoveEvent(QMouseEvent *event)
{
auto pos = event->pos();
qreal pixelRatio = windowPixelRatio();
this->TouchMoved(std::max(static_cast<unsigned>(pos.x() * 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)
this->TouchReleased();
}
void GRenderWindow::ReloadSetKeymaps() {
void GRenderWindow::ReloadSetKeymaps()
{
/*KeyMap::ClearKeyMapping(keyboard_id);
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]);
}*/
}
void GRenderWindow::OnClientAreaResized(unsigned width, unsigned height) {
void GRenderWindow::OnClientAreaResized(unsigned width, unsigned 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);
}
@ -288,7 +305,7 @@ void GRenderWindow::showEvent(QShowEvent * event) {
QWidget::showEvent(event);
// 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);
#endif
#endif
}