diff options
author | Gunnar Sletta <gunnar.sletta@nokia.com> | 2011-12-07 10:16:20 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-08 10:10:27 +0100 |
commit | fdd14a1a10a0a2f42015b30071771bd95215cc1a (patch) | |
tree | 1e79b74017df70e7f4b034dd4460406041507636 /src/quick/items/qquickcanvas_p.h | |
parent | 9128eb13040c57872e226222c9a45cad9946ed1a (diff) |
Implemented multiple windows and GL context sharing
What was traditionally the QQuickRenderLoop which was used
to support one QQuickCanvas instance has now grown to support
multiple QQuickCanvas instances and is now called
QQuickWindowManager, of which there are two implementations.
QQuickRenderThreadSingleContextWindowManager:
One QSGContext and one OpenGL context is being used to draw
all the windows and we alternate between which surface the gl
context is bound to. This implementation relies on that
swap does not block, but that the graphics pipeline is
vsynced and will eventually block as the buffer queue is
filled up. This is the behavior we get on Mac OS X and
Wayland. The benefit of this implementation is that we have
vsync'ed animations, and the synchronizaiton between GUI and
render thread is simple. (well, simple relative to the
alternative, that is).
QQuickTrivialWindowManager:
One QSGContext and one OpenGL context is being used on the GUI
thread. Animations are ticked from a timer. Performance of this
implementation will deteriorate if the driver is using blocking
swap.
Task-number: QTBUG-19455
Change-Id: Ib961ac7d71eb49c70a057872b7cac020c4d19f3d
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
Diffstat (limited to 'src/quick/items/qquickcanvas_p.h')
-rw-r--r-- | src/quick/items/qquickcanvas_p.h | 142 |
1 files changed, 6 insertions, 136 deletions
diff --git a/src/quick/items/qquickcanvas_p.h b/src/quick/items/qquickcanvas_p.h index 633f382954..d9d130c280 100644 --- a/src/quick/items/qquickcanvas_p.h +++ b/src/quick/items/qquickcanvas_p.h @@ -74,6 +74,8 @@ QT_BEGIN_NAMESPACE //Make it easy to identify and customize the root item if needed +class QQuickWindowManager; + class QQuickRootItem : public QQuickItem { Q_OBJECT @@ -145,7 +147,6 @@ public: void dirtyItem(QQuickItem *); void cleanup(QSGNode *); - void initializeSceneGraph(); void polishItems(); void syncSceneGraph(); void renderSceneGraph(const QSize &size); @@ -166,16 +167,13 @@ public: QSGEngine *engine; QSGContext *context; - QColor clearColor; + QSGRenderer *renderer; - uint vsyncAnimations : 1; - uint clearBeforeRendering : 1; + QQuickWindowManager *windowManager; - QQuickCanvasRenderLoop *thread; - QSize widgetSize; - QSize viewportSize; + QColor clearColor; - QAnimationDriver *animationDriver; + uint clearBeforeRendering : 1; QOpenGLFramebufferObject *renderTarget; @@ -187,134 +185,6 @@ private: static void cleanupNodesOnShutdown(QQuickItem *); }; -class QQuickCanvasRenderLoop -{ -public: - QQuickCanvasRenderLoop() - : d(0) - , renderer(0) - , gl(0) - { - } - virtual ~QQuickCanvasRenderLoop() - { - delete gl; - } - - friend class QQuickCanvasPrivate; - - virtual void paint() = 0; - virtual void resize(const QSize &size) = 0; - virtual void startRendering() = 0; - virtual void stopRendering() = 0; - virtual QImage grab() = 0; - virtual void setWindowSize(const QSize &size) = 0; - virtual void maybeUpdate() = 0; - virtual bool isRunning() const = 0; - virtual void animationStarted() = 0; - virtual void animationStopped() = 0; - virtual void moveContextToThread(QSGContext *) { } - virtual bool *allowMainThreadProcessing() { return 0; } - -protected: - void initializeSceneGraph() { d->initializeSceneGraph(); } - void syncSceneGraph() { d->syncSceneGraph(); } - void cleanupNodesOnShutdown() { d->cleanupNodesOnShutdown(); } - void renderSceneGraph(const QSize &size) { d->renderSceneGraph(size); } - void polishItems() { d->polishItems(); } - QAnimationDriver *animationDriver() const { return d->animationDriver; } - - inline QOpenGLContext *glContext() const { return gl; } - void createGLContext(); - void makeCurrent() { gl->makeCurrent(renderer); } - void doneCurrent() { gl->doneCurrent(); } - void swapBuffers() { - gl->swapBuffers(renderer); - emit renderer->frameSwapped(); - } - -private: - QQuickCanvasPrivate *d; - QQuickCanvas *renderer; - - QOpenGLContext *gl; -}; - -class QQuickCanvasRenderThread : public QThread, public QQuickCanvasRenderLoop -{ - Q_OBJECT -public: - QQuickCanvasRenderThread() - : mutex(QMutex::NonRecursive) - , allowMainThreadProcessingFlag(true) - , animationRunning(false) - , isGuiBlocked(0) - , isPaintCompleted(false) - , isGuiBlockPending(false) - , isRenderBlocked(false) - , isExternalUpdatePending(false) - , syncAlreadyHappened(false) - , inSync(false) - , doGrab(false) - , shouldExit(false) - , hasExited(false) - , renderThreadAwakened(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 startRendering(); - void stopRendering(); - void exhaustSyncEvent(); - void sync(bool guiAlreadyLocked); - bool isRunning() const { return QThread::isRunning(); } - void setWindowSize(const QSize &size) { windowSize = size; } - void maybeUpdate(); - void moveContextToThread(QSGContext *c) { c->moveToThread(this); } - bool *allowMainThreadProcessing() { return &allowMainThreadProcessingFlag; } - - bool event(QEvent *); - - QImage grab(); - -public slots: - void animationStarted(); - void animationStopped(); - -public: - QMutex mutex; - QWaitCondition condition; - - bool allowMainThreadProcessingFlag; - - QSize windowSize; - QSize renderedSize; - - uint animationRunning: 1; - int isGuiBlocked; - uint isPaintCompleted : 1; - uint isGuiBlockPending : 1; - uint isRenderBlocked : 1; - uint isExternalUpdatePending : 1; - uint syncAlreadyHappened : 1; - uint inSync : 1; - uint doGrab : 1; - uint shouldExit : 1; - uint hasExited : 1; - uint renderThreadAwakened : 1; - - QImage grabContent; - - void run(); -}; Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickCanvasPrivate::FocusOptions) |