diff options
author | Gunnar Sletta <gunnar.sletta@nokia.com> | 2011-06-06 08:05:56 +0200 |
---|---|---|
committer | Gunnar Sletta <gunnar.sletta@nokia.com> | 2011-06-06 09:08:05 +0200 |
commit | 6b0af9fe9fd9114bd579510010c09519928f91ce (patch) | |
tree | 9ba8980166578511d9e92f3ed7f39eca7d722608 /src/declarative/items/qsgcanvas_p.h | |
parent | 33e349ac6bdab5c55b428c999ced253890c82305 (diff) |
A better threaded renderer
Diffstat (limited to 'src/declarative/items/qsgcanvas_p.h')
-rw-r--r-- | src/declarative/items/qsgcanvas_p.h | 91 |
1 files changed, 71 insertions, 20 deletions
diff --git a/src/declarative/items/qsgcanvas_p.h b/src/declarative/items/qsgcanvas_p.h index 6b8034f922..9ea11f5892 100644 --- a/src/declarative/items/qsgcanvas_p.h +++ b/src/declarative/items/qsgcanvas_p.h @@ -78,6 +78,8 @@ public: class QSGCanvasPrivate; class QTouchEvent; +class QSGCanvasRenderThread; + class QSGCanvasPrivate : public QGLWidgetPrivate { public: @@ -115,8 +117,6 @@ public: void sendHoverEvent(QEvent::Type, QSGItem *, QGraphicsSceneHoverEvent *); void clearHover(); - void stopRenderingThread(); - QDeclarativeGuard<QSGItem> hoverItem; enum FocusOption { DontChangeFocusProperty = 0x01, @@ -135,11 +135,7 @@ public: void initializeSceneGraph(); void polishItems(); void syncSceneGraph(); - void renderSceneGraph(); - void runThread(); - - void _q_animationStarted(); - void _q_animationStopped(); + void renderSceneGraph(const QSize &size); QSGItem::UpdatePaintNodeData updatePaintNodeData; @@ -158,22 +154,10 @@ public: uint contextInThread : 1; uint threadedRendering : 1; - uint exitThread : 1; uint animationRunning: 1; - uint idle : 1; // Set to true when render thread sees no change and enters a wait() - uint needsRepaint : 1; // Set by callback from render if scene needs repainting. uint renderThreadAwakened : 1; - uint inSync: 1; - struct MyThread : public QThread { - MyThread(QSGCanvasPrivate *r) : renderer(r) {} - virtual void run() { renderer->runThread(); } - static void doWait() { QThread::msleep(16); } - QSGCanvasPrivate *renderer; - }; - MyThread *thread; - QMutex mutex; - QWaitCondition wait; + QSGCanvasRenderThread *thread; QSize widgetSize; QSize viewportSize; @@ -182,6 +166,73 @@ public: QHash<int, QSGItem *> itemForTouchPointId; }; + + +class QSGCanvasRenderThread : public QThread +{ + Q_OBJECT +public: + QSGCanvasRenderThread() + : mutex(QMutex::NonRecursive) + , isGuiBlocked(0) + , isPaintCompleted(false) + , isGuiBlockPending(false) + , isRenderBlocked(false) + , isExternalUpdatePending(false) + , syncAlreadyHappened(false) + , doGrab(false) + , shouldExit(false) + , hasExited(false) + {} + + inline void lock() { mutex.lock(); } + inline void unlock() { mutex.unlock(); } + inline void wait() { condition.wait(&mutex); } + inline void wake() { condition.wakeOne(); } + + void lockInGui(); + void unlockInGui(); + + void paint(); + void resize(const QSize &size); + void startRenderThread(); + void stopRenderThread(); + void exhaustSyncEvent(); + void sync(bool guiAlreadyLocked); + + QImage grab(); + +public slots: + void animationStarted(); + void animationStopped(); + +public: + QMutex mutex; + QWaitCondition condition; + + QSize windowSize; + QSize renderedSize; + + QSGCanvas *renderer; + QSGCanvasPrivate *d; + + int isGuiBlocked; + uint isPaintCompleted : 1; + uint isGuiBlockPending : 1; + uint isRenderBlocked : 1; + uint isExternalUpdatePending : 1; + uint syncAlreadyHappened : 1; + + uint doGrab : 1; + uint shouldExit : 1; + uint hasExited : 1; + + QImage grabContent; + + void run(); +}; + + Q_DECLARE_OPERATORS_FOR_FLAGS(QSGCanvasPrivate::FocusOptions) QT_END_NAMESPACE |