Qt: Fix tearing issues

This commit is contained in:
Vicki Pfau 2018-09-23 19:41:36 -07:00
parent 749038dd18
commit 41c08151f3
3 changed files with 8 additions and 10 deletions

View File

@ -46,6 +46,7 @@ CoreController::CoreController(mCore* core, QObject* parent)
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 @@ CoreController::~CoreController() {
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 @@ int CoreController::updateAutofire() {
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 @@ void CoreController::finishFrame() {
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) {

View File

@ -58,7 +58,7 @@ public:
mCoreThread* thread() { return &m_threadContext; }
color_t* drawContext();
const color_t* drawContext();
bool isPaused();
bool hasStarted();
@ -174,7 +174,7 @@ private:
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;

View File

@ -51,7 +51,7 @@ void DisplayQt::filter(bool filter) {
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;
}