got canvas rendering...
authorGunnar Sletta <gunnar.sletta@nokia.com>
Fri, 5 Aug 2011 05:48:38 +0000 (07:48 +0200)
committerSamuel Rødal <samuel.rodal@nokia.com>
Fri, 5 Aug 2011 08:47:16 +0000 (10:47 +0200)
Change-Id: Ifefda68628d489fef47684742db9adece7d15683
Reviewed-on: http://codereview.qt.nokia.com/2676
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
src/declarative/items/qsgcanvas.cpp
src/declarative/items/qsgview.cpp

index 341d3bd..4f76184 100644 (file)
@@ -145,7 +145,7 @@ have a scope focused item), and the other items will have their focus cleared.
 // #define MOUSE_DEBUG
 // #define TOUCH_DEBUG
 // #define DIRTY_DEBUG
-#define THREAD_DEBUG
+// #define THREAD_DEBUG
 
 // #define FRAME_TIMING
 
@@ -172,12 +172,22 @@ void QSGCanvas::exposeEvent(QExposeEvent *)
 
 void QSGCanvas::resizeEvent(QResizeEvent *e)
 {
+    // Since we are faking resizeEvent from QEvent::Map in event(), spit
+    // out a warning when it starts to work properly
+    if (e)
+        qDebug("Resize events are working, remove this code: %s : %d", __FILE__, __LINE__);
+
     Q_D(QSGCanvas);
-    d->thread->resize(e->size());
+    d->thread->resize(size());
 }
 
 void QSGCanvas::showEvent(QShowEvent *e)
 {
+    // Since we are faking the showEvent from QEvent::Map in ::event(), spit
+    // out a warning when it starts to work properly...
+    if (e)
+        qDebug("Show events are working, remove this code: %s : %d", __FILE__, __LINE__);
+
     Q_D(QSGCanvas);
 
     if (d->vsyncAnimations) {
@@ -188,11 +198,20 @@ void QSGCanvas::showEvent(QShowEvent *e)
         }
         d->animationDriver->install();
     }
-    d->thread->startRenderThread();
+
+    if (!d->thread->isRunning()) {
+        d->thread->windowSize = size();
+        d->thread->startRenderThread();
+    }
 }
 
 void QSGCanvas::hideEvent(QHideEvent *e)
 {
+    // Since we are faking the showEvent from QEvent::Map in ::event(), spit
+    // out a warning when it starts to work properly...
+    if (e)
+        qDebug("Hide events are working, remove this code: %s : %d", __FILE__, __LINE__);
+
     Q_D(QSGCanvas);
     d->thread->stopRenderThread();
 }
@@ -339,6 +358,9 @@ void QSGCanvasPrivate::init(QSGCanvas *c)
     thread = new QSGCanvasRenderThread;
     thread->renderer = q;
     thread->d = this;
+
+    context = QSGContext::createDefaultContext();
+    context->moveToThread(thread);
 }
 
 void QSGCanvasPrivate::sceneMouseEventForTransform(QGraphicsSceneMouseEvent &sceneEvent,
@@ -735,7 +757,6 @@ QSGCanvas::QSGCanvas(QWindow *parent)
     : QWindow(parent)
 {
     Q_D(QSGCanvas);
-
     d->init(this);
 }
 
@@ -743,7 +764,6 @@ QSGCanvas::QSGCanvas(QSGCanvasPrivate &dd, QWindow *parent)
     : QWindow(dd, parent)
 {
     Q_D(QSGCanvas);
-
     d->init(this);
 }
 
@@ -805,6 +825,14 @@ void QSGCanvasPrivate::clearHover()
 
 bool QSGCanvas::event(QEvent *e)
 {
+    // Fake a resize/show/hide events until QWindow starts sending events properly.
+    if (e->type() == QEvent::Map) {
+        resizeEvent(0);
+        showEvent(0);
+    } else if(e->type() == QEvent::Unmap) {
+        hideEvent(0);
+    }
+
     Q_D(QSGCanvas);
 
     if (e->type() == QEvent::User) {
index cf90638..48b3074 100644 (file)
@@ -87,6 +87,8 @@ public:
     QSGView::ResizeMode resizeMode;
     QSize initialSize;
     QElapsedTimer frameTimer;
+
+    bool resized;
 };
 
 void QSGViewPrivate::init()
@@ -97,7 +99,7 @@ void QSGViewPrivate::init()
 }
 
 QSGViewPrivate::QSGViewPrivate()
-: root(0), component(0), resizeMode(QSGView::SizeViewToRootObject), initialSize(0,0) 
+    : root(0), component(0), resizeMode(QSGView::SizeViewToRootObject), initialSize(0,0), resized(false)
 {
 }
 
@@ -334,12 +336,13 @@ void QSGViewPrivate::setRootObject(QObject *obj)
         delete obj;
         root = 0;
     }
-
     if (root) {
         initialSize = rootObjectSize();
-        if ((resizeMode == QSGView::SizeViewToRootObject) // ### refactor:  || !q->testAttribute(Qt::WA_Resized)
+        if ((resizeMode == QSGView::SizeViewToRootObject || !resized) // ### refactor:  || !q->testAttribute(Qt::WA_Resized)
              && initialSize != q->size()) {
-             q->resize(initialSize);
+
+            q->resize(initialSize);
+            resized = true;
         }
         initResize();
     }