mirror of https://github.com/mgba-emu/mgba.git
Qt: Remove backing from startDrawing signal
This commit is contained in:
parent
34512371bb
commit
e11d34d761
|
@ -19,7 +19,7 @@ public:
|
|||
Display(QWidget* parent = nullptr);
|
||||
|
||||
public slots:
|
||||
virtual void startDrawing(const uint32_t* buffer, GBAThread* context) = 0;
|
||||
virtual void startDrawing(GBAThread* context) = 0;
|
||||
virtual void stopDrawing() = 0;
|
||||
virtual void pauseDrawing() = 0;
|
||||
virtual void unpauseDrawing() = 0;
|
||||
|
|
|
@ -35,12 +35,11 @@ DisplayGL::DisplayGL(const QGLFormat& format, QWidget* parent)
|
|||
{
|
||||
}
|
||||
|
||||
void DisplayGL::startDrawing(const uint32_t* buffer, GBAThread* thread) {
|
||||
void DisplayGL::startDrawing(GBAThread* thread) {
|
||||
if (m_started) {
|
||||
return;
|
||||
}
|
||||
m_painter->setContext(thread);
|
||||
m_painter->setBacking(buffer);
|
||||
m_context = thread;
|
||||
m_painter->start();
|
||||
m_painter->resize(size());
|
||||
|
@ -114,6 +113,10 @@ void DisplayGL::filter(bool filter) {
|
|||
}
|
||||
}
|
||||
|
||||
void DisplayGL::framePosted(const uint32_t* buffer) {
|
||||
m_painter->setBacking(buffer);
|
||||
}
|
||||
|
||||
void DisplayGL::resizeEvent(QResizeEvent* event) {
|
||||
m_painter->resize(event->size());
|
||||
}
|
||||
|
@ -135,6 +138,17 @@ void Painter::setContext(GBAThread* context) {
|
|||
|
||||
void Painter::setBacking(const uint32_t* backing) {
|
||||
m_backing = backing;
|
||||
makeCurrent();
|
||||
#ifdef COLOR_16_BIT
|
||||
#ifdef COLOR_5_6_5
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, m_backing);
|
||||
#else
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, m_backing);
|
||||
#endif
|
||||
#else
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_backing);
|
||||
#endif
|
||||
doneCurrent();
|
||||
}
|
||||
|
||||
void Painter::resize(const QSize& size) {
|
||||
|
@ -260,15 +274,6 @@ void Painter::performDraw() {
|
|||
}
|
||||
}
|
||||
glViewport((w - drawW) / 2, (h - drawH) / 2, drawW, drawH);
|
||||
#ifdef COLOR_16_BIT
|
||||
#ifdef COLOR_5_6_5
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, m_backing);
|
||||
#else
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, m_backing);
|
||||
#endif
|
||||
#else
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_backing);
|
||||
#endif
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
if (m_context->sync.videoFrameWait) {
|
||||
glFlush();
|
||||
|
|
|
@ -24,14 +24,14 @@ public:
|
|||
DisplayGL(const QGLFormat& format, QWidget* parent = nullptr);
|
||||
|
||||
public slots:
|
||||
void startDrawing(const uint32_t* buffer, GBAThread* context) override;
|
||||
void startDrawing(GBAThread* context) override;
|
||||
void stopDrawing() override;
|
||||
void pauseDrawing() override;
|
||||
void unpauseDrawing() override;
|
||||
void forceDraw() override;
|
||||
void lockAspectRatio(bool lock) override;
|
||||
void filter(bool filter) override;
|
||||
void framePosted(const uint32_t*) override {}
|
||||
void framePosted(const uint32_t*) override;
|
||||
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent*) override {};
|
||||
|
|
|
@ -11,22 +11,14 @@ using namespace QGBA;
|
|||
|
||||
DisplayQt::DisplayQt(QWidget* parent)
|
||||
: Display(parent)
|
||||
, m_backing(nullptr)
|
||||
, m_lockAspectRatio(false)
|
||||
, m_filter(false)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayQt::startDrawing(const uint32_t* buffer, GBAThread* context) {
|
||||
void DisplayQt::startDrawing(GBAThread* context) {
|
||||
m_context = context;
|
||||
#ifdef COLOR_16_BIT
|
||||
#ifdef COLOR_5_6_5
|
||||
m_backing = QImage(reinterpret_cast<const uchar*>(buffer), 256, 256, QImage::Format_RGB16);
|
||||
#else
|
||||
m_backing = QImage(reinterpret_cast<const uchar*>(buffer), 256, 256, QImage::Format_RGB555);
|
||||
#endif
|
||||
#else
|
||||
m_backing = QImage(reinterpret_cast<const uchar*>(buffer), 256, 256, QImage::Format_RGB32);
|
||||
#endif
|
||||
}
|
||||
|
||||
void DisplayQt::lockAspectRatio(bool lock) {
|
||||
|
@ -39,6 +31,22 @@ void DisplayQt::filter(bool filter) {
|
|||
update();
|
||||
}
|
||||
|
||||
void DisplayQt::framePosted(const uint32_t* buffer) {
|
||||
update();
|
||||
if (const_cast<const QImage&>(m_backing).bits() == reinterpret_cast<const uchar*>(buffer)) {
|
||||
return;
|
||||
}
|
||||
#ifdef COLOR_16_BIT
|
||||
#ifdef COLOR_5_6_5
|
||||
m_backing = QImage(reinterpret_cast<const uchar*>(buffer), 256, 256, QImage::Format_RGB16);
|
||||
#else
|
||||
m_backing = QImage(reinterpret_cast<const uchar*>(buffer), 256, 256, QImage::Format_RGB555);
|
||||
#endif
|
||||
#else
|
||||
m_backing = QImage(reinterpret_cast<const uchar*>(buffer), 256, 256, QImage::Format_RGB32);
|
||||
#endif
|
||||
}
|
||||
|
||||
void DisplayQt::paintEvent(QPaintEvent*) {
|
||||
QPainter painter(this);
|
||||
painter.fillRect(QRect(QPoint(), size()), Qt::black);
|
||||
|
|
|
@ -22,14 +22,14 @@ public:
|
|||
DisplayQt(QWidget* parent = nullptr);
|
||||
|
||||
public slots:
|
||||
void startDrawing(const uint32_t* buffer, GBAThread* context) override;
|
||||
void startDrawing(GBAThread* context) override;
|
||||
void stopDrawing() override {}
|
||||
void pauseDrawing() override {}
|
||||
void unpauseDrawing() override {}
|
||||
void forceDraw() override { update(); }
|
||||
void lockAspectRatio(bool lock) override;
|
||||
void filter(bool filter) override;
|
||||
void framePosted(const uint32_t*) override { update(); }
|
||||
void framePosted(const uint32_t*) override;
|
||||
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent*) override;
|
||||
|
|
|
@ -111,7 +111,7 @@ Window::Window(ConfigController* config, int playerId, QWidget* parent)
|
|||
connect(m_logView, SIGNAL(levelsSet(int)), m_controller, SLOT(setLogLevel(int)));
|
||||
connect(m_logView, SIGNAL(levelsEnabled(int)), m_controller, SLOT(enableLogLevel(int)));
|
||||
connect(m_logView, SIGNAL(levelsDisabled(int)), m_controller, SLOT(disableLogLevel(int)));
|
||||
connect(this, SIGNAL(startDrawing(const uint32_t*, GBAThread*)), m_display, SLOT(startDrawing(const uint32_t*, GBAThread*)), Qt::QueuedConnection);
|
||||
connect(this, SIGNAL(startDrawing(GBAThread*)), m_display, SLOT(startDrawing(GBAThread*)), Qt::QueuedConnection);
|
||||
connect(this, SIGNAL(shutdown()), m_display, SLOT(stopDrawing()));
|
||||
connect(this, SIGNAL(shutdown()), m_controller, SLOT(closeGame()));
|
||||
connect(this, SIGNAL(shutdown()), m_logView, SLOT(hide()));
|
||||
|
@ -480,7 +480,7 @@ void Window::gameStarted(GBAThread* context) {
|
|||
char title[13] = { '\0' };
|
||||
MutexLock(&context->stateMutex);
|
||||
if (context->state < THREAD_EXITING) {
|
||||
emit startDrawing(m_controller->drawContext(), context);
|
||||
emit startDrawing(context);
|
||||
GBAGetGameTitle(context->gba, title);
|
||||
} else {
|
||||
MutexUnlock(&context->stateMutex);
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
void resizeFrame(int width, int height);
|
||||
|
||||
signals:
|
||||
void startDrawing(const uint32_t*, GBAThread*);
|
||||
void startDrawing(GBAThread*);
|
||||
void shutdown();
|
||||
void audioBufferSamplesChanged(int samples);
|
||||
void fpsTargetChanged(float target);
|
||||
|
|
Loading…
Reference in New Issue