From 7983f0df7f734d250d6e4cb1b5d91fa12b2c2df1 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Thu, 5 May 2011 10:03:04 +0200 Subject: [PATCH] Enable the threaded renderer. Disable by specifying QML_NO_THREADED_RENDERER if this causes problems --- src/declarative/items/qsgcanvas.cpp | 62 ++++++++++++----------------------- src/declarative/items/qsgcanvas.h | 4 ++- src/declarative/items/qsgcanvas_p.h | 15 ++------- 3 files changed, 27 insertions(+), 54 deletions(-) diff --git a/src/declarative/items/qsgcanvas.cpp b/src/declarative/items/qsgcanvas.cpp index 5d5c49d..1ac14a0 100644 --- a/src/declarative/items/qsgcanvas.cpp +++ b/src/declarative/items/qsgcanvas.cpp @@ -61,7 +61,7 @@ QT_BEGIN_NAMESPACE -DEFINE_BOOL_CONFIG_OPTION(qmlThreadedRenderer, QML_THREADED_RENDERER) +DEFINE_BOOL_CONFIG_OPTION(qmlNoThreadedRenderer, QML_NO_THREADED_RENDERER) DEFINE_BOOL_CONFIG_OPTION(qmlFixedAnimationStep, QML_FIXED_ANIMATION_STEP) /* @@ -97,24 +97,6 @@ int sceneGraphRenderTime; int readbackTime; #endif - -class QSGAnimationDriver : public QAnimationDriver -{ -public: - QSGAnimationDriver(QWidget *w, QObject *parent) - : QAnimationDriver(parent), widget(w) - { - Q_ASSERT(w); - } - - void started() - { - widget->update(); - } - - QWidget *widget; -}; - QSGItem::UpdatePaintNodeData::UpdatePaintNodeData() : transformNode(0) { @@ -124,34 +106,26 @@ QSGRootItem::QSGRootItem() { } -QSGThreadedRendererAnimationDriver::QSGThreadedRendererAnimationDriver(QSGCanvasPrivate *r, QObject *parent) - : QAnimationDriver(parent) - , renderer(r) -{ -} - -void QSGThreadedRendererAnimationDriver::started() +void QSGCanvasPrivate::_q_animationStarted() { #ifdef THREAD_DEBUG qWarning("AnimationDriver: Main Thread: started"); #endif - renderer->mutex.lock(); - renderer->animationRunning = true; - if (renderer->idle) - renderer->wait.wakeOne(); - renderer->mutex.unlock(); - - + mutex.lock(); + animationRunning = true; + if (idle) + wait.wakeOne(); + mutex.unlock(); } -void QSGThreadedRendererAnimationDriver::stopped() +void QSGCanvasPrivate::_q_animationStopped() { #ifdef THREAD_DEBUG qWarning("AnimationDriver: Main Thread: stopped"); #endif - renderer->mutex.lock(); - renderer->animationRunning = false; - renderer->mutex.unlock(); + mutex.lock(); + animationRunning = false; + mutex.unlock(); } void QSGCanvas::paintEvent(QPaintEvent *) @@ -238,8 +212,11 @@ void QSGCanvas::showEvent(QShowEvent *e) if (d->threadedRendering) { d->contextInThread = true; doneCurrent(); - if (!d->animationDriver) - d->animationDriver = new QSGThreadedRendererAnimationDriver(d, this); + if (!d->animationDriver) { + d->animationDriver = new QAnimationDriver(this); + connect(d->animationDriver, SIGNAL(started()), this, SLOT(_q_animationStarted()), Qt::DirectConnection); + connect(d->animationDriver, SIGNAL(stopped()), this, SLOT(_q_animationStopped()), Qt::DirectConnection); + } d->animationDriver->install(); d->mutex.lock(); d->thread->start(); @@ -250,7 +227,8 @@ void QSGCanvas::showEvent(QShowEvent *e) if (!d->context || !d->context->isReady()) { d->initializeSceneGraph(); - d->animationDriver = new QSGAnimationDriver(this, this); + d->animationDriver = new QAnimationDriver(this); + connect(d->animationDriver, SIGNAL(started()), this, SLOT(update())); } d->animationDriver->install(); @@ -471,7 +449,7 @@ QSGCanvasPrivate::QSGCanvasPrivate() , thread(new MyThread(this)) , animationDriver(0) { - threadedRendering = qmlThreadedRenderer(); + threadedRendering = !qmlNoThreadedRenderer(); } QSGCanvasPrivate::~QSGCanvasPrivate() @@ -1894,4 +1872,6 @@ QSGEngine *QSGCanvas::sceneGraphEngine() const return 0; } +#include "moc_qsgcanvas.cpp" + QT_END_NAMESPACE diff --git a/src/declarative/items/qsgcanvas.h b/src/declarative/items/qsgcanvas.h index 8f3b303..d076d09 100644 --- a/src/declarative/items/qsgcanvas.h +++ b/src/declarative/items/qsgcanvas.h @@ -105,7 +105,9 @@ private slots: void maybeUpdate(); private: - Q_DISABLE_COPY(QSGCanvas); + Q_DISABLE_COPY(QSGCanvas) + Q_PRIVATE_SLOT(d_func(), void _q_animationStarted()) + Q_PRIVATE_SLOT(d_func(), void _q_animationStopped()) }; QT_END_NAMESPACE diff --git a/src/declarative/items/qsgcanvas_p.h b/src/declarative/items/qsgcanvas_p.h index 63bd2df..c0aabaa 100644 --- a/src/declarative/items/qsgcanvas_p.h +++ b/src/declarative/items/qsgcanvas_p.h @@ -77,18 +77,6 @@ public: class QSGCanvasPrivate; -class QSGThreadedRendererAnimationDriver : public QAnimationDriver -{ -public: - QSGThreadedRendererAnimationDriver(QSGCanvasPrivate *r, QObject *parent); - -protected: - virtual void started(); - virtual void stopped(); - - QSGCanvasPrivate *renderer; -}; - class QTouchEvent; class QSGCanvasPrivate : public QGLWidgetPrivate { @@ -148,6 +136,9 @@ public: void renderSceneGraph(); void runThread(); + void _q_animationStarted(); + void _q_animationStopped(); + QSGItem::UpdatePaintNodeData updatePaintNodeData; QSGItem *dirtyItemList; -- 1.7.2.5