1 /****************************************************************************
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
57 #include "qsgcanvas.h"
58 #include <private/qdeclarativeguard_p.h>
60 #include <private/qsgcontext_p.h>
62 #include <QtCore/qthread.h>
63 #include <QtCore/qmutex.h>
64 #include <QtCore/qwaitcondition.h>
65 #include <private/qwidget_p.h>
66 #include <private/qgl_p.h>
70 //Make it easy to identify and customize the root item if needed
71 class QSGRootItem : public QSGItem
78 class QSGCanvasPrivate;
80 class QSGThreadedRendererAnimationDriver : public QAnimationDriver
83 QSGThreadedRendererAnimationDriver(QSGCanvasPrivate *r, QObject *parent);
86 virtual void started();
87 virtual void stopped();
89 QSGCanvasPrivate *renderer;
93 class QSGCanvasPrivate : public QGLWidgetPrivate
96 Q_DECLARE_PUBLIC(QSGCanvas)
98 static inline QSGCanvasPrivate *get(QSGCanvas *c) { return c->d_func(); }
101 virtual ~QSGCanvasPrivate();
103 void init(QSGCanvas *);
105 QSGRootItem *rootItem;
107 QSGItem *activeFocusItem;
108 QSGItem *mouseGrabberItem;
110 // Mouse positions are saved in widget coordinates
111 QPoint lastMousePosition;
112 QPoint buttonDownPositions[5]; // Left, Right, Middle, XButton1, XButton2
113 void sceneMouseEventFromMouseEvent(QGraphicsSceneMouseEvent &, QMouseEvent *);
114 void translateTouchEvent(QTouchEvent *touchEvent);
115 static QEvent::Type sceneMouseEventTypeFromMouseEvent(QMouseEvent *);
116 static void sceneMouseEventForTransform(QGraphicsSceneMouseEvent &, const QTransform &);
117 static void transformTouchPoints(QList<QTouchEvent::TouchPoint> &touchPoints, const QTransform &transform);
118 bool deliverInitialMousePressEvent(QSGItem *, QGraphicsSceneMouseEvent *);
119 bool deliverMouseEvent(QGraphicsSceneMouseEvent *);
120 bool sendFilteredMouseEvent(QSGItem *, QSGItem *, QGraphicsSceneMouseEvent *);
121 bool deliverWheelEvent(QSGItem *, QGraphicsSceneWheelEvent *);
122 bool deliverTouchPoints(QSGItem *, QTouchEvent *, const QList<QTouchEvent::TouchPoint> &, QSet<int> *,
123 QHash<QSGItem *, QList<QTouchEvent::TouchPoint> > *);
124 bool deliverTouchEvent(QTouchEvent *);
125 void sceneHoverEventFromMouseEvent(QGraphicsSceneHoverEvent &, QMouseEvent *);
126 bool deliverHoverEvent(QSGItem *, QGraphicsSceneHoverEvent *);
127 void sendHoverEvent(QEvent::Type, QSGItem *, QGraphicsSceneHoverEvent *);
130 QDeclarativeGuard<QSGItem> hoverItem;
132 DontChangeFocusProperty = 0x01,
134 Q_DECLARE_FLAGS(FocusOptions, FocusOption)
136 void setFocusInScope(QSGItem *scope, QSGItem *item, FocusOptions = 0);
137 void clearFocusInScope(QSGItem *scope, QSGItem *item, FocusOptions = 0);
138 void notifyFocusChangesRecur(QSGItem **item, int remaining);
140 void updateInputMethodData();
142 void dirtyItem(QSGItem *);
143 void cleanup(QSGNode *);
145 void initializeSceneGraph();
147 void syncSceneGraph();
148 void renderSceneGraph();
151 QSGItem::UpdatePaintNodeData updatePaintNodeData;
153 QSGItem *dirtyItemList;
154 QList<QSGNode *> cleanupNodeList;
156 QSet<QSGItem *> itemsToPolish;
158 void updateDirtyNodes();
160 bool updateEffectiveOpacity(QSGItem *);
161 void updateEffectiveOpacityRoot(QSGItem *, qreal);
162 void updateDirtyNode(QSGItem *);
166 uint contextInThread : 1;
167 uint threadedRendering : 1;
169 uint animationRunning: 1;
170 uint idle : 1; // Set to true when render thread sees no change and enters a wait()
171 uint needsRepaint : 1; // Set by callback from render if scene needs repainting.
172 uint renderThreadAwakened : 1;
174 struct MyThread : public QThread {
175 MyThread(QSGCanvasPrivate *r) : renderer(r) {}
176 virtual void run() { renderer->runThread(); }
177 static void doWait() { QThread::msleep(16); }
178 QSGCanvasPrivate *renderer;
186 QAnimationDriver *animationDriver;
188 QHash<int, QSGItem *> itemForTouchPointId;
191 Q_DECLARE_OPERATORS_FOR_FLAGS(QSGCanvasPrivate::FocusOptions)
195 #endif // QSGCANVAS_P_H