From 08f360af90613f1a2b4d0ae2b8a0d334f6eb9129 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Tue, 28 Feb 2023 00:13:32 -0800 Subject: [PATCH] Qt: Ask the display, not the core, what size it should be --- src/platform/qt/Display.h | 1 + src/platform/qt/DisplayGL.cpp | 16 ++++++++++++++++ src/platform/qt/DisplayGL.h | 4 ++++ src/platform/qt/DisplayQt.cpp | 18 +++++++++++++----- src/platform/qt/DisplayQt.h | 1 + src/platform/qt/Window.cpp | 4 ++-- 6 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/platform/qt/Display.h b/src/platform/qt/Display.h index dda48d875..4fc100799 100644 --- a/src/platform/qt/Display.h +++ b/src/platform/qt/Display.h @@ -55,6 +55,7 @@ public: virtual int framebufferHandle() { return -1; } virtual void setVideoScale(int) {} virtual void setBackgroundImage(const QImage&) = 0; + virtual QSize contentSize() const = 0; virtual void setVideoProxy(std::shared_ptr proxy) { m_videoProxy = proxy; } std::shared_ptr videoProxy() { return m_videoProxy; } diff --git a/src/platform/qt/DisplayGL.cpp b/src/platform/qt/DisplayGL.cpp index e3155dc62..dc7ad9a86 100644 --- a/src/platform/qt/DisplayGL.cpp +++ b/src/platform/qt/DisplayGL.cpp @@ -245,6 +245,8 @@ void DisplayGL::startDrawing(std::shared_ptr controller) { show(); m_gl->reset(); } + + QTimer::singleShot(8, this, &DisplayGL::updateContentSize); } bool DisplayGL::supportsFormat(const QSurfaceFormat& format) { @@ -331,12 +333,14 @@ void DisplayGL::unpauseDrawing() { if (!m_gl && shouldDisableUpdates()) { setUpdatesEnabled(false); } + QMetaObject::invokeMethod(this, "updateContentSize", Qt::QueuedConnection); } } void DisplayGL::forceDraw() { if (m_hasStarted) { QMetaObject::invokeMethod(m_painter.get(), "forceDraw"); + QMetaObject::invokeMethod(this, "updateContentSize", Qt::QueuedConnection); } } @@ -398,6 +402,7 @@ void DisplayGL::setVideoScale(int scale) { void DisplayGL::setBackgroundImage(const QImage& image) { QMetaObject::invokeMethod(m_painter.get(), "setBackgroundImage", Q_ARG(const QImage&, image)); + QMetaObject::invokeMethod(this, "updateContentSize", Qt::QueuedConnection); } void DisplayGL::resizeEvent(QResizeEvent* event) { @@ -452,6 +457,10 @@ void DisplayGL::setupProxyThread() { m_proxyThread.start(); } +void DisplayGL::updateContentSize() { + QMetaObject::invokeMethod(m_painter.get(), "contentSize", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QSize, m_cachedContentSize)); +} + int DisplayGL::framebufferHandle() { return m_painter->glTex(); } @@ -972,6 +981,13 @@ VideoShader* PainterGL::shaders() { return &m_shader; } +QSize PainterGL::contentSize() const { + unsigned width, height; + VideoBackendGetFrameSize(m_backend, &width, &height); + return {static_cast(width > static_cast(INT_MAX) ? INT_MAX : width), + static_cast(height > static_cast(INT_MAX) ? INT_MAX : height)}; +} + int PainterGL::glTex() { #if defined(BUILD_GLES2) || defined(BUILD_GLES3) if (supportsShaders()) { diff --git a/src/platform/qt/DisplayGL.h b/src/platform/qt/DisplayGL.h index eed3a37c0..a02b2289c 100644 --- a/src/platform/qt/DisplayGL.h +++ b/src/platform/qt/DisplayGL.h @@ -88,6 +88,7 @@ public: VideoShader* shaders() override; void setVideoProxy(std::shared_ptr) override; int framebufferHandle() override; + QSize contentSize() const override { return m_cachedContentSize; } static bool supportsFormat(const QSurfaceFormat&); @@ -115,6 +116,7 @@ protected: private slots: void setupProxyThread(); + void updateContentSize(); private: void resizePainter(); @@ -131,6 +133,7 @@ private: mGLWidget* m_gl; QOffscreenSurface m_proxySurface; std::unique_ptr m_proxyContext; + QSize m_cachedContentSize; }; class PainterGL : public QObject { @@ -182,6 +185,7 @@ public slots: void setShaders(struct VDir*); void clearShaders(); VideoShader* shaders(); + QSize contentSize() const; signals: void created(); diff --git a/src/platform/qt/DisplayQt.cpp b/src/platform/qt/DisplayQt.cpp index 7669b5cf1..dee0d1244 100644 --- a/src/platform/qt/DisplayQt.cpp +++ b/src/platform/qt/DisplayQt.cpp @@ -106,22 +106,18 @@ void DisplayQt::paintEvent(QPaintEvent*) { QRect bgRect(0, 0, m_background.width(), m_background.height()); QRect imRect(0, 0, m_width, m_height); - QSize outerFrame; + QSize outerFrame = contentSize(); if (bgRect.width() > imRect.width()) { imRect.moveLeft(bgRect.width() - imRect.width()); - outerFrame.setWidth(bgRect.width()); } else { bgRect.moveLeft(imRect.width() - bgRect.width()); - outerFrame.setWidth(imRect.width()); } if (bgRect.height() > imRect.height()) { imRect.moveTop(bgRect.height() - imRect.height()); - outerFrame.setHeight(bgRect.height()); } else { bgRect.moveTop(imRect.height() - bgRect.height()); - outerFrame.setHeight(imRect.height()); } QRect full(clampSize(outerFrame, size(), isAspectRatioLocked(), isIntegerScalingLocked())); @@ -184,3 +180,15 @@ void DisplayQt::paintEvent(QPaintEvent*) { messagePainter()->paint(&painter); } } + +QSize DisplayQt::contentSize() const { + QSize outerFrame(m_width, m_height); + + if (m_background.width() > outerFrame.width()) { + outerFrame.setWidth(m_background.width()); + } + if (m_background.height() > outerFrame.height()) { + outerFrame.setHeight(m_background.height()); + } + return outerFrame; +} diff --git a/src/platform/qt/DisplayQt.h b/src/platform/qt/DisplayQt.h index acdd95f24..889a6a367 100644 --- a/src/platform/qt/DisplayQt.h +++ b/src/platform/qt/DisplayQt.h @@ -22,6 +22,7 @@ public: bool isDrawing() const override { return m_isDrawing; } bool supportsShaders() const override { return false; } VideoShader* shaders() override { return nullptr; } + QSize contentSize() const override; public slots: void stopDrawing() override; diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index ce0c64a06..083732cd8 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -1488,8 +1488,8 @@ void Window::setupMenu(QMenuBar* menubar) { Action* setSize = m_frameSizes[i]; showNormal(); QSize size(GBA_VIDEO_HORIZONTAL_PIXELS, GBA_VIDEO_VERTICAL_PIXELS); - if (m_controller) { - size = m_controller->screenDimensions(); + if (m_display) { + size = m_display->contentSize(); } size *= i; m_savedScale = i;