diff options
| author | 2014-10-12 18:14:57 +0200 | |
|---|---|---|
| committer | 2014-11-18 13:09:01 +0100 | |
| commit | bd8f491e4c08e9b9a7b852de0b50c144da8ac8c8 (patch) | |
| tree | b1f350a3506289263c3652f46946baf267cb27f8 /src/citra_qt | |
| parent | Viewport scaling and display density independence (diff) | |
| download | yuzu-bd8f491e4c08e9b9a7b852de0b50c144da8ac8c8.tar.gz yuzu-bd8f491e4c08e9b9a7b852de0b50c144da8ac8c8.tar.xz yuzu-bd8f491e4c08e9b9a7b852de0b50c144da8ac8c8.zip | |
Fixup EmuWindow interface and implementations thereof.
Diffstat (limited to 'src/citra_qt')
| -rw-r--r-- | src/citra_qt/bootmanager.cpp | 53 | ||||
| -rw-r--r-- | src/citra_qt/bootmanager.hxx | 19 |
2 files changed, 47 insertions, 25 deletions
diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index 516e115fd..34a79b306 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp | |||
| @@ -88,20 +88,20 @@ void EmuThread::Stop() | |||
| 88 | class GGLWidgetInternal : public QGLWidget | 88 | class GGLWidgetInternal : public QGLWidget |
| 89 | { | 89 | { |
| 90 | public: | 90 | public: |
| 91 | GGLWidgetInternal(QGLFormat fmt, GRenderWindow* parent) : QGLWidget(fmt, parent) | 91 | GGLWidgetInternal(QGLFormat fmt, GRenderWindow* parent) |
| 92 | { | 92 | : QGLWidget(fmt, parent), parent(parent) { |
| 93 | parent_ = parent; | ||
| 94 | } | 93 | } |
| 95 | 94 | ||
| 96 | void paintEvent(QPaintEvent* ev) override | 95 | void paintEvent(QPaintEvent* ev) override { |
| 97 | { | ||
| 98 | } | 96 | } |
| 97 | |||
| 99 | void resizeEvent(QResizeEvent* ev) override { | 98 | void resizeEvent(QResizeEvent* ev) override { |
| 100 | parent_->SetClientAreaWidth(size().width()); | 99 | parent->OnClientAreaResized(ev->size().width(), ev->size().height()); |
| 101 | parent_->SetClientAreaHeight(size().height()); | 100 | parent->OnFramebufferSizeChanged(); |
| 102 | } | 101 | } |
| 102 | |||
| 103 | private: | 103 | private: |
| 104 | GRenderWindow* parent_; | 104 | GRenderWindow* parent; |
| 105 | }; | 105 | }; |
| 106 | 106 | ||
| 107 | EmuThread& GRenderWindow::GetEmuThread() | 107 | EmuThread& GRenderWindow::GetEmuThread() |
| @@ -120,16 +120,23 @@ GRenderWindow::GRenderWindow(QWidget* parent) : QWidget(parent), emu_thread(this | |||
| 120 | fmt.setProfile(QGLFormat::CoreProfile); | 120 | fmt.setProfile(QGLFormat::CoreProfile); |
| 121 | // Requests a forward-compatible context, which is required to get a 3.2+ context on OS X | 121 | // Requests a forward-compatible context, which is required to get a 3.2+ context on OS X |
| 122 | fmt.setOption(QGL::NoDeprecatedFunctions); | 122 | fmt.setOption(QGL::NoDeprecatedFunctions); |
| 123 | 123 | ||
| 124 | child = new GGLWidgetInternal(fmt, this); | 124 | child = new GGLWidgetInternal(fmt, this); |
| 125 | QBoxLayout* layout = new QHBoxLayout(this); | 125 | QBoxLayout* layout = new QHBoxLayout(this); |
| 126 | resize(VideoCore::kScreenTopWidth, VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight); | 126 | resize(VideoCore::kScreenTopWidth, VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight); |
| 127 | layout->addWidget(child); | 127 | layout->addWidget(child); |
| 128 | layout->setMargin(0); | 128 | layout->setMargin(0); |
| 129 | setLayout(layout); | 129 | setLayout(layout); |
| 130 | QObject::connect(&emu_thread, SIGNAL(started()), this, SLOT(moveContext())); | 130 | connect(&emu_thread, SIGNAL(started()), this, SLOT(moveContext())); |
| 131 | |||
| 132 | OnFramebufferSizeChanged(); | ||
| 133 | NotifyClientAreaSizeChanged(std::pair<unsigned,unsigned>(child->width(), child->height())); | ||
| 131 | 134 | ||
| 132 | BackupGeometry(); | 135 | BackupGeometry(); |
| 136 | |||
| 137 | #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) | ||
| 138 | connect(this->windowHandle(), SIGNAL(screenChanged(QScreen*)), this, SLOT(OnFramebufferSizeChanged())); | ||
| 139 | #endif | ||
| 133 | } | 140 | } |
| 134 | 141 | ||
| 135 | void GRenderWindow::moveContext() | 142 | void GRenderWindow::moveContext() |
| @@ -182,22 +189,26 @@ void GRenderWindow::PollEvents() { | |||
| 182 | */ | 189 | */ |
| 183 | } | 190 | } |
| 184 | 191 | ||
| 185 | // On Qt 5.1+, this correctly gets the size of the framebuffer (pixels). | 192 | // On Qt 5.0+, this correctly gets the size of the framebuffer (pixels). |
| 186 | // | 193 | // |
| 187 | // Older versions get the window size (density independent pixels), | 194 | // Older versions get the window size (density independent pixels), |
| 188 | // and hence, do not support DPI scaling ("retina" displays). | 195 | // and hence, do not support DPI scaling ("retina" displays). |
| 189 | // The result will be a viewport that is smaller than the extent of the window. | 196 | // The result will be a viewport that is smaller than the extent of the window. |
| 190 | void GRenderWindow::GetFramebufferSize(int* fbWidth, int* fbHeight) | 197 | void GRenderWindow::OnFramebufferSizeChanged() |
| 191 | { | 198 | { |
| 192 | #if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) | 199 | // Screen changes potentially incur a change in screen DPI, hence we should update the framebuffer size |
| 193 | int pixelRatio = child->QPaintDevice::devicePixelRatio(); | 200 | #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) |
| 194 | 201 | // windowHandle() might not be accessible until the window is displayed to screen. | |
| 195 | *fbWidth = child->QPaintDevice::width() * pixelRatio; | 202 | auto pixel_ratio = windowHandle() ? (windowHandle()->screen()->devicePixelRatio()) : 1.0; |
| 196 | *fbHeight = child->QPaintDevice::height() * pixelRatio; | 203 | |
| 204 | unsigned width = child->QPaintDevice::width() * pixel_ratio; | ||
| 205 | unsigned height = child->QPaintDevice::height() * pixel_ratio; | ||
| 197 | #else | 206 | #else |
| 198 | *fbWidth = child->QPaintDevice::width(); | 207 | unsigned width = child->QPaintDevice::width(); |
| 199 | *fbHeight = child->QPaintDevice::height(); | 208 | unsigned height = child->QPaintDevice::height(); |
| 200 | #endif | 209 | #endif |
| 210 | |||
| 211 | NotifyFramebufferSizeChanged(std::make_pair(width, height)); | ||
| 201 | } | 212 | } |
| 202 | 213 | ||
| 203 | void GRenderWindow::BackupGeometry() | 214 | void GRenderWindow::BackupGeometry() |
| @@ -260,3 +271,7 @@ void GRenderWindow::ReloadSetKeymaps() | |||
| 260 | KeyMap::SetKeyMapping({Settings::values.pad_sdown_key, keyboard_id}, HID_User::PAD_CIRCLE_DOWN); | 271 | KeyMap::SetKeyMapping({Settings::values.pad_sdown_key, keyboard_id}, HID_User::PAD_CIRCLE_DOWN); |
| 261 | } | 272 | } |
| 262 | 273 | ||
| 274 | void GRenderWindow::OnClientAreaResized(unsigned width, unsigned height) | ||
| 275 | { | ||
| 276 | NotifyClientAreaSizeChanged(std::make_pair(width, height)); | ||
| 277 | } | ||
diff --git a/src/citra_qt/bootmanager.hxx b/src/citra_qt/bootmanager.hxx index ec3e1fe71..3a18f98fd 100644 --- a/src/citra_qt/bootmanager.hxx +++ b/src/citra_qt/bootmanager.hxx | |||
| @@ -1,12 +1,16 @@ | |||
| 1 | #include <atomic> | ||
| 2 | |||
| 1 | #include <QThread> | 3 | #include <QThread> |
| 2 | #include <QGLWidget> | 4 | #include <QGLWidget> |
| 3 | #include <atomic> | 5 | |
| 4 | #include "common/common.h" | 6 | #include "common/common.h" |
| 5 | #include "common/emu_window.h" | 7 | #include "common/emu_window.h" |
| 6 | 8 | ||
| 7 | class GRenderWindow; | 9 | class QScreen; |
| 8 | class QKeyEvent; | 10 | class QKeyEvent; |
| 9 | 11 | ||
| 12 | class GRenderWindow; | ||
| 13 | |||
| 10 | class EmuThread : public QThread | 14 | class EmuThread : public QThread |
| 11 | { | 15 | { |
| 12 | Q_OBJECT | 16 | Q_OBJECT |
| @@ -74,7 +78,7 @@ private: | |||
| 74 | signals: | 78 | signals: |
| 75 | /** | 79 | /** |
| 76 | * Emitted when CPU when we've finished processing a single Gekko instruction | 80 | * Emitted when CPU when we've finished processing a single Gekko instruction |
| 77 | * | 81 | * |
| 78 | * @warning This will only be emitted when the CPU is not running (SetCpuRunning(false)) | 82 | * @warning This will only be emitted when the CPU is not running (SetCpuRunning(false)) |
| 79 | * @warning When connecting to this signal from other threads, make sure to specify either Qt::QueuedConnection (invoke slot within the destination object's message thread) or even Qt::BlockingQueuedConnection (additionally block source thread until slot returns) | 83 | * @warning When connecting to this signal from other threads, make sure to specify either Qt::QueuedConnection (invoke slot within the destination object's message thread) or even Qt::BlockingQueuedConnection (additionally block source thread until slot returns) |
| 80 | */ | 84 | */ |
| @@ -96,12 +100,11 @@ public: | |||
| 96 | void MakeCurrent() override; | 100 | void MakeCurrent() override; |
| 97 | void DoneCurrent() override; | 101 | void DoneCurrent() override; |
| 98 | void PollEvents() override; | 102 | void PollEvents() override; |
| 99 | void GetFramebufferSize(int* fbWidth, int* fbHeight) override; | ||
| 100 | 103 | ||
| 101 | void BackupGeometry(); | 104 | void BackupGeometry(); |
| 102 | void RestoreGeometry(); | 105 | void RestoreGeometry(); |
| 103 | void restoreGeometry(const QByteArray& geometry); // overridden | 106 | void restoreGeometry(const QByteArray& geometry); // overridden |
| 104 | QByteArray saveGeometry(); // overridden | 107 | QByteArray saveGeometry(); // overridden |
| 105 | 108 | ||
| 106 | EmuThread& GetEmuThread(); | 109 | EmuThread& GetEmuThread(); |
| 107 | 110 | ||
| @@ -110,8 +113,12 @@ public: | |||
| 110 | 113 | ||
| 111 | void ReloadSetKeymaps() override; | 114 | void ReloadSetKeymaps() override; |
| 112 | 115 | ||
| 116 | void OnClientAreaResized(unsigned width, unsigned height); | ||
| 117 | |||
| 118 | void OnFramebufferSizeChanged(); | ||
| 119 | |||
| 113 | public slots: | 120 | public slots: |
| 114 | void moveContext(); | 121 | void moveContext(); // overridden |
| 115 | 122 | ||
| 116 | private: | 123 | private: |
| 117 | QGLWidget* child; | 124 | QGLWidget* child; |