From 2a77a88cc2284506bacbe9116ea68432d93efd5d Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Fri, 5 Aug 2011 07:48:38 +0200 Subject: [PATCH] got canvas rendering... MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: Ifefda68628d489fef47684742db9adece7d15683 Reviewed-on: http://codereview.qt.nokia.com/2676 Reviewed-by: Samuel Rødal --- src/declarative/items/qsgcanvas.cpp | 38 ++++++++++++++++++++++++++++++---- src/declarative/items/qsgview.cpp | 11 ++++++--- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/declarative/items/qsgcanvas.cpp b/src/declarative/items/qsgcanvas.cpp index 341d3bd..4f76184 100644 --- a/src/declarative/items/qsgcanvas.cpp +++ b/src/declarative/items/qsgcanvas.cpp @@ -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) { diff --git a/src/declarative/items/qsgview.cpp b/src/declarative/items/qsgview.cpp index cf90638..48b3074 100644 --- a/src/declarative/items/qsgview.cpp +++ b/src/declarative/items/qsgview.cpp @@ -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(); } -- 1.7.2.5