Respect QPlatformIntegration::ThreadedOpenGL and fix thread affinity of the QSGContext
authorGunnar Sletta <gunnar.sletta@nokia.com>
Mon, 29 Aug 2011 07:29:40 +0000 (09:29 +0200)
committerSamuel Rødal <samuel.rodal@nokia.com>
Mon, 29 Aug 2011 07:31:57 +0000 (09:31 +0200)
Change-Id: I3a63e8a3d515bfb41895f7717d534a46e2ab2bde
Reviewed-on: http://codereview.qt.nokia.com/3705
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
src/declarative/items/qsgcanvas.cpp
src/declarative/items/qsgcanvas_p.h

index 052b439..e6cda60 100644 (file)
@@ -452,14 +452,23 @@ void QSGCanvasPrivate::init(QSGCanvas *c)
     // has a canvas..
     rootItem->setFocus(true);
 
-    thread = qmlNoThreadedRenderer()
-            ? static_cast<QSGCanvasRenderLoop *>(new QSGCanvasPlainRenderLoop())
-            : static_cast<QSGCanvasRenderLoop *>(new QSGCanvasRenderThread());
+    bool threaded = !qmlNoThreadedRenderer();
+
+    if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ThreadedOpenGL)) {
+        qWarning("QSGCanvas: platform does not support threaded rendering!");
+        threaded = false;
+    }
+
+    if (threaded)
+        thread = new QSGCanvasRenderThread();
+    else
+        thread = new QSGCanvasPlainRenderLoop();
+
     thread->renderer = q;
     thread->d = this;
 
     context = QSGContext::createDefaultContext();
-    thread->moveCanvasToThread(context);
+    thread->moveContextToThread(context);
 }
 
 void QSGCanvasPrivate::sceneMouseEventForTransform(QGraphicsSceneMouseEvent &sceneEvent,
index 7daa142..592e66b 100644 (file)
@@ -200,7 +200,7 @@ public:
     virtual bool isRunning() const = 0;
     virtual void animationStarted() = 0;
     virtual void animationStopped() = 0;
-    virtual void moveCanvasToThread(QSGContext *) { }
+    virtual void moveContextToThread(QSGContext *) { }
 
 protected:
     void initializeSceneGraph() { d->initializeSceneGraph(); }
@@ -262,7 +262,7 @@ public:
     bool isRunning() const { return QThread::isRunning(); }
     void setWindowSize(const QSize &size) { windowSize = size; }
     void maybeUpdate();
-    void moveCanvasToThread(QSGCanvas *c) { c->moveToThread(this); }
+    void moveContextToThread(QSGContext *c) { c->moveToThread(this); }
 
     bool event(QEvent *);