Qt: Remove excess memcpying (fixes #1437)

This commit is contained in:
Vicki Pfau 2019-06-05 10:06:41 -07:00
parent 9ac838d14d
commit c5fc0f0492
2 changed files with 11 additions and 22 deletions

View File

@ -82,8 +82,7 @@ CoreController::CoreController(mCore* core, QObject* parent)
controller->m_resetActions.clear(); controller->m_resetActions.clear();
if (!controller->m_hwaccel) { if (!controller->m_hwaccel) {
controller->m_activeBuffer = &controller->m_buffers[0]; context->core->setVideoBuffer(context->core, reinterpret_cast<color_t*>(controller->m_activeBuffer.data()), controller->screenDimensions().width());
context->core->setVideoBuffer(context->core, reinterpret_cast<color_t*>(controller->m_activeBuffer->data()), controller->screenDimensions().width());
} }
QMetaObject::invokeMethod(controller, "didReset"); QMetaObject::invokeMethod(controller, "didReset");
@ -357,15 +356,12 @@ void CoreController::setLogger(LogController* logger) {
void CoreController::start() { void CoreController::start() {
if (!m_hwaccel) { if (!m_hwaccel) {
QSize size(1024, 2048); QSize size(256, 224);
m_buffers[0].resize(size.width() * size.height() * sizeof(color_t)); m_activeBuffer.resize(size.width() * size.height() * sizeof(color_t));
m_buffers[1].resize(size.width() * size.height() * sizeof(color_t)); m_activeBuffer.fill(0xFF);
m_buffers[0].fill(0xFF); m_completeBuffer = m_activeBuffer;
m_buffers[1].fill(0xFF);
m_activeBuffer = &m_buffers[0];
m_completeBuffer = m_buffers[0];
m_threadContext.core->setVideoBuffer(m_threadContext.core, reinterpret_cast<color_t*>(m_activeBuffer->data()), size.width()); m_threadContext.core->setVideoBuffer(m_threadContext.core, reinterpret_cast<color_t*>(m_activeBuffer.data()), size.width());
} }
if (!m_patched) { if (!m_patched) {
@ -884,17 +880,11 @@ int CoreController::updateAutofire() {
void CoreController::finishFrame() { void CoreController::finishFrame() {
if (!m_hwaccel) { if (!m_hwaccel) {
QMutexLocker locker(&m_bufferMutex); unsigned width, height;
memcpy(m_completeBuffer.data(), m_activeBuffer->constData(), m_activeBuffer->size()); m_threadContext.core->desiredVideoDimensions(m_threadContext.core, &width, &height);
// TODO: Generalize this to triple buffering? QMutexLocker locker(&m_bufferMutex);
m_activeBuffer = &m_buffers[0]; memcpy(m_completeBuffer.data(), m_activeBuffer.constData(), 256 * height * BYTES_PER_PIXEL);
if (m_activeBuffer == m_completeBuffer) {
m_activeBuffer = &m_buffers[1];
}
// Copy contents to avoid issues when doing frameskip
memcpy(m_activeBuffer->data(), m_completeBuffer.constData(), m_activeBuffer->size());
m_threadContext.core->setVideoBuffer(m_threadContext.core, reinterpret_cast<color_t*>(m_activeBuffer->data()), screenDimensions().width());
} }
QMutexLocker locker(&m_actionMutex); QMutexLocker locker(&m_actionMutex);

View File

@ -201,8 +201,7 @@ private:
bool m_patched = false; bool m_patched = false;
QByteArray m_buffers[2]; QByteArray m_activeBuffer;
QByteArray* m_activeBuffer;
QByteArray m_completeBuffer; QByteArray m_completeBuffer;
bool m_hwaccel = false; bool m_hwaccel = false;