Qt: Fix tearing issues
Vicki Pfau vi@endrift.com
Sun, 23 Sep 2018 19:41:36 -0700
3 files changed,
8 insertions(+),
10 deletions(-)
M
src/platform/qt/CoreController.cpp
→
src/platform/qt/CoreController.cpp
@@ -46,6 +46,7 @@ m_buffers[1].resize(size.width() * size.height() * sizeof(color_t));
m_buffers[0].fill(0xFF); 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());@@ -209,12 +210,9 @@ mCoreConfigDeinit(&m_threadContext.core->config);
m_threadContext.core->deinit(m_threadContext.core); } -color_t* CoreController::drawContext() { +const color_t* CoreController::drawContext() { QMutexLocker locker(&m_mutex); - if (!m_completeBuffer) { - return nullptr; - } - return reinterpret_cast<color_t*>(m_completeBuffer->data()); + return reinterpret_cast<const color_t*>(m_completeBuffer.constData()); } bool CoreController::isPaused() {@@ -790,7 +788,7 @@ }
void CoreController::finishFrame() { QMutexLocker locker(&m_mutex); - m_completeBuffer = m_activeBuffer; + memcpy(m_completeBuffer.data(), m_activeBuffer->constData(), m_activeBuffer->size()); // TODO: Generalize this to triple buffering? m_activeBuffer = &m_buffers[0];@@ -798,7 +796,7 @@ if (m_activeBuffer == m_completeBuffer) {
m_activeBuffer = &m_buffers[1]; } // Copy contents to avoid issues when doing frameskip - memcpy(m_activeBuffer->data(), m_completeBuffer->data(), m_activeBuffer->size()); + 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()); for (auto& action : m_frameActions) {
M
src/platform/qt/CoreController.h
→
src/platform/qt/CoreController.h
@@ -58,7 +58,7 @@ ~CoreController();
mCoreThread* thread() { return &m_threadContext; } - color_t* drawContext(); + const color_t* drawContext(); bool isPaused(); bool hasStarted();@@ -174,7 +174,7 @@ bool m_patched = false;
QByteArray m_buffers[2]; QByteArray* m_activeBuffer; - QByteArray* m_completeBuffer = nullptr; + QByteArray m_completeBuffer; std::unique_ptr<mCacheSet> m_cacheSet; std::unique_ptr<Override> m_override;
M
src/platform/qt/DisplayQt.cpp
→
src/platform/qt/DisplayQt.cpp
@@ -51,7 +51,7 @@ }
void DisplayQt::framePosted() { update(); - color_t* buffer = m_context->drawContext(); + const color_t* buffer = m_context->drawContext(); if (const_cast<const QImage&>(m_backing).bits() == reinterpret_cast<const uchar*>(buffer)) { return; }