all repos — mgba @ e11d34d7617cd6f7c1da26dcb2d6bfbfbc5375e4

mGBA Game Boy Advance Emulator

Qt: Remove backing from startDrawing signal
Jeffrey Pfau jeffrey@endrift.com
Sat, 18 Apr 2015 02:51:28 -0700
commit

e11d34d7617cd6f7c1da26dcb2d6bfbfbc5375e4

parent

34512371bb3269c3d3b8c863978deb2eedce7871

M src/platform/qt/Display.hsrc/platform/qt/Display.h

@@ -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;
M src/platform/qt/DisplayGL.cppsrc/platform/qt/DisplayGL.cpp

@@ -35,12 +35,11 @@ , m_started(false)

{ } -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 @@ m_painter->filter(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::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 @@ drawH = w * 2 / 3;

} } 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();
M src/platform/qt/DisplayGL.hsrc/platform/qt/DisplayGL.h

@@ -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 {};
M src/platform/qt/DisplayQt.cppsrc/platform/qt/DisplayQt.cpp

@@ -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) {

@@ -37,6 +29,22 @@

void DisplayQt::filter(bool filter) { m_filter = 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*) {
M src/platform/qt/DisplayQt.hsrc/platform/qt/DisplayQt.h

@@ -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;
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -111,7 +111,7 @@ connect(m_controller, SIGNAL(unimplementedBiosCall(int)), this, SLOT(unimplementedBiosCall(int)));

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);
M src/platform/qt/Window.hsrc/platform/qt/Window.h

@@ -50,7 +50,7 @@

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);