[kwin/aurorae] Add mutex locker around access to the render buffer

We were facing crashes when the buffer image was being read from and
written to at the same time.
This commit is contained in:
Martin Gräßlin 2013-11-14 09:01:42 +01:00
parent 73e0a6586c
commit 719923d410
2 changed files with 6 additions and 0 deletions

View file

@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QApplication>
#include <QDebug>
#include <QMutex>
#include <QOpenGLFramebufferObject>
#include <QPainter>
#include <QQmlComponent>
@ -235,6 +236,7 @@ AuroraeClient::AuroraeClient(KDecorationBridge *bridge, KDecorationFactory *fact
: KDecoration(bridge, factory)
, m_view(NULL)
, m_item(AuroraeFactory::instance()->createQmlDecoration(this))
, m_mutex(new QMutex(QMutex::Recursive))
{
connect(AuroraeFactory::instance(), SIGNAL(buttonsChanged()), SIGNAL(buttonsChanged()));
connect(AuroraeFactory::instance(), SIGNAL(configChanged()), SIGNAL(configChanged()));
@ -271,6 +273,7 @@ void AuroraeClient::init()
m_view->setRenderTarget(m_fbo.data());
});
connect(m_view, &QQuickWindow::afterRendering, [this]{
QMutexLocker locker(m_mutex.data());
m_buffer = m_fbo->toImage();
});
connect(m_view, &QQuickWindow::afterRendering, this,
@ -551,6 +554,7 @@ bool AuroraeClient::animationsSupported() const
void AuroraeClient::render(QPaintDevice *device, const QRegion &sourceRegion)
{
QMutexLocker locker(m_mutex.data());
QPainter painter(device);
painter.setClipRegion(sourceRegion);
painter.drawImage(QPoint(0, 0), m_buffer);

View file

@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <kdecoration.h>
#include <kdecorationfactory.h>
class QMutex;
class QOpenGLFramebufferObject;
class QQmlComponent;
class QQmlEngine;
@ -160,6 +161,7 @@ private:
QScopedPointer<QQuickItem> m_item;
QScopedPointer<QOpenGLFramebufferObject> m_fbo;
QImage m_buffer;
QScopedPointer<QMutex> m_mutex;
};
}