mirror of https://github.com/mgba-emu/mgba.git
Qt: Ask the display, not the core, what size it should be
This commit is contained in:
parent
c7e4db58e3
commit
08f360af90
|
@ -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<VideoProxy> proxy) { m_videoProxy = proxy; }
|
||||
std::shared_ptr<VideoProxy> videoProxy() { return m_videoProxy; }
|
||||
|
|
|
@ -245,6 +245,8 @@ void DisplayGL::startDrawing(std::shared_ptr<CoreController> 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<int>(width > static_cast<unsigned>(INT_MAX) ? INT_MAX : width),
|
||||
static_cast<int>(height > static_cast<unsigned>(INT_MAX) ? INT_MAX : height)};
|
||||
}
|
||||
|
||||
int PainterGL::glTex() {
|
||||
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
|
||||
if (supportsShaders()) {
|
||||
|
|
|
@ -88,6 +88,7 @@ public:
|
|||
VideoShader* shaders() override;
|
||||
void setVideoProxy(std::shared_ptr<VideoProxy>) 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<QOpenGLContext> 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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue