all repos — mgba @ db2b56f418359e03f0505bac5e894cf821989cc3

mGBA Game Boy Advance Emulator

Qt: Add getPixels call for a finished context
Vicki Pfau vi@endrift.com
Thu, 30 May 2019 20:56:19 -0700
commit

db2b56f418359e03f0505bac5e894cf821989cc3

parent

06657d9fde5a2e579ef55b72cfa7ed8269135b83

3 files changed, 22 insertions(+), 4 deletions(-)

jump to
M src/platform/qt/CoreController.cppsrc/platform/qt/CoreController.cpp

@@ -210,6 +210,26 @@ }

return reinterpret_cast<const color_t*>(m_completeBuffer.constData()); } +QImage CoreController::getPixels() { + QByteArray buffer; + QSize size = screenDimensions(); + size_t stride = size.width() * BYTES_PER_PIXEL; + + if (!m_hwaccel) { + buffer = m_completeBuffer; + } else { + Interrupter interrupter(this); + const void* pixels; + m_threadContext.core->getPixels(m_threadContext.core, &pixels, &stride); + stride *= BYTES_PER_PIXEL; + buffer.resize(stride * size.height()); + memcpy(buffer.data(), pixels, buffer.size()); + } + + return QImage(reinterpret_cast<const uchar*>(buffer.constData()), + size.width(), size.height(), stride, QImage::Format_RGBX8888); +} + bool CoreController::isPaused() { return mCoreThreadIsPaused(&m_threadContext); }
M src/platform/qt/CoreController.hsrc/platform/qt/CoreController.h

@@ -67,6 +67,7 @@

mCoreThread* thread() { return &m_threadContext; } const color_t* drawContext(); + QImage getPixels(); bool isPaused(); bool hasStarted();
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -1706,11 +1706,8 @@ }

} void Window::updateFrame() { - QSize size = m_controller->screenDimensions(); - QImage currentImage(reinterpret_cast<const uchar*>(m_controller->drawContext()), size.width(), size.height(), - size.width() * BYTES_PER_PIXEL, QImage::Format_RGBX8888); QPixmap pixmap; - pixmap.convertFromImage(currentImage); + pixmap.convertFromImage(m_controller->getPixels()); m_screenWidget->setPixmap(pixmap); emit paused(true); }