Qt: Add getPixels call for a finished context

This commit is contained in:
Vicki Pfau 2019-05-30 20:56:19 -07:00
parent 06657d9fde
commit db2b56f418
3 changed files with 22 additions and 4 deletions

View File

@ -210,6 +210,26 @@ const color_t* CoreController::drawContext() {
return reinterpret_cast<const color_t*>(m_completeBuffer.constData()); 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() { bool CoreController::isPaused() {
return mCoreThreadIsPaused(&m_threadContext); return mCoreThreadIsPaused(&m_threadContext);
} }

View File

@ -67,6 +67,7 @@ public:
mCoreThread* thread() { return &m_threadContext; } mCoreThread* thread() { return &m_threadContext; }
const color_t* drawContext(); const color_t* drawContext();
QImage getPixels();
bool isPaused(); bool isPaused();
bool hasStarted(); bool hasStarted();

View File

@ -1706,11 +1706,8 @@ void Window::focusCheck() {
} }
void Window::updateFrame() { 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; QPixmap pixmap;
pixmap.convertFromImage(currentImage); pixmap.convertFromImage(m_controller->getPixels());
m_screenWidget->setPixmap(pixmap); m_screenWidget->setPixmap(pixmap);
emit paused(true); emit paused(true);
} }