Implemented multiple windows and GL context sharing
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickcanvas_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QQUICKCANVAS_P_H
43 #define QQUICKCANVAS_P_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
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.
52 //
53 // We mean it.
54 //
55
56 #include "qquickitem.h"
57 #include "qquickcanvas.h"
58 #include <private/qdeclarativeguard_p.h>
59
60 #include <QtQuick/private/qsgcontext_p.h>
61 #include <private/qquickdrag_p.h>
62
63 #include <QtCore/qthread.h>
64 #include <QtCore/qmutex.h>
65 #include <QtCore/qwaitcondition.h>
66 #include <private/qwindow_p.h>
67 #include <private/qopengl_p.h>
68 #include <qopenglcontext.h>
69 #include <QtGui/qopenglframebufferobject.h>
70 #include <QtGui/qevent.h>
71 #include <QtGui/qinputpanel.h>
72
73 QT_BEGIN_NAMESPACE
74
75 //Make it easy to identify and customize the root item if needed
76
77 class QQuickWindowManager;
78
79 class QQuickRootItem : public QQuickItem
80 {
81     Q_OBJECT
82 public:
83     QQuickRootItem();
84 public Q_SLOTS:
85     void setWidth(int w) {QQuickItem::setWidth(qreal(w));}
86     void setHeight(int h) {QQuickItem::setHeight(qreal(h));}
87 };
88
89 class QQuickItemPrivate;
90 class QQuickCanvasPrivate;
91
92 class QTouchEvent;
93 class QQuickCanvasRenderLoop;
94 class QQuickCanvasIncubationController;
95
96 class QQuickCanvasPrivate : public QWindowPrivate
97 {
98 public:
99     Q_DECLARE_PUBLIC(QQuickCanvas)
100
101     static inline QQuickCanvasPrivate *get(QQuickCanvas *c) { return c->d_func(); }
102
103     QQuickCanvasPrivate();
104     virtual ~QQuickCanvasPrivate();
105
106     void init(QQuickCanvas *);
107     void initRootItem();//Currently only used if items added in QML
108
109     QQuickRootItem *rootItem;
110     QDeclarativeListProperty<QObject> data();
111
112     QQuickItem *activeFocusItem;
113     QQuickItem *mouseGrabberItem;
114     QQuickDragGrabber dragGrabber;
115
116     // Mouse positions are saved in widget coordinates
117     QPointF lastMousePosition;
118     void translateTouchEvent(QTouchEvent *touchEvent);
119     static void transformTouchPoints(QList<QTouchEvent::TouchPoint> &touchPoints, const QTransform &transform);
120     bool deliverInitialMousePressEvent(QQuickItem *, QMouseEvent *);
121     bool deliverMouseEvent(QMouseEvent *);
122     bool sendFilteredMouseEvent(QQuickItem *, QQuickItem *, QEvent *);
123     bool deliverWheelEvent(QQuickItem *, QWheelEvent *);
124     bool deliverTouchPoints(QQuickItem *, QTouchEvent *, const QList<QTouchEvent::TouchPoint> &, QSet<int> *,
125             QHash<QQuickItem *, QList<QTouchEvent::TouchPoint> > *);
126     bool deliverTouchEvent(QTouchEvent *);
127     bool deliverHoverEvent(QQuickItem *, const QPointF &scenePos, const QPointF &lastScenePos, Qt::KeyboardModifiers modifiers, bool &accepted);
128     bool sendHoverEvent(QEvent::Type, QQuickItem *, const QPointF &scenePos, const QPointF &lastScenePos,
129                         Qt::KeyboardModifiers modifiers, bool accepted);
130     bool clearHover();
131     void deliverDragEvent(QQuickDragGrabber *, QEvent *);
132     bool deliverDragEvent(QQuickDragGrabber *, QQuickItem *, QDragMoveEvent *);
133
134     QList<QQuickItem*> hoverItems;
135     enum FocusOption {
136         DontChangeFocusProperty = 0x01,
137     };
138     Q_DECLARE_FLAGS(FocusOptions, FocusOption)
139
140     void setFocusInScope(QQuickItem *scope, QQuickItem *item, FocusOptions = 0);
141     void clearFocusInScope(QQuickItem *scope, QQuickItem *item, FocusOptions = 0);
142     void notifyFocusChangesRecur(QQuickItem **item, int remaining);
143
144     void updateInputMethodData();
145     void updateFocusItemTransform();
146
147     void dirtyItem(QQuickItem *);
148     void cleanup(QSGNode *);
149
150     void polishItems();
151     void syncSceneGraph();
152     void renderSceneGraph(const QSize &size);
153
154     QQuickItem::UpdatePaintNodeData updatePaintNodeData;
155
156     QQuickItem *dirtyItemList;
157     QList<QSGNode *> cleanupNodeList;
158
159     QSet<QQuickItem *> itemsToPolish;
160
161     void updateDirtyNodes();
162     void cleanupNodes();
163     void cleanupNodesOnShutdown();
164     bool updateEffectiveOpacity(QQuickItem *);
165     void updateEffectiveOpacityRoot(QQuickItem *, qreal);
166     void updateDirtyNode(QQuickItem *);
167
168     QSGEngine *engine;
169     QSGContext *context;
170     QSGRenderer *renderer;
171
172     QQuickWindowManager *windowManager;
173
174     QColor clearColor;
175
176     uint clearBeforeRendering : 1;
177
178     QOpenGLFramebufferObject *renderTarget;
179
180     QHash<int, QQuickItem *> itemForTouchPointId;
181
182     mutable QQuickCanvasIncubationController *incubationController;
183
184 private:
185     static void cleanupNodesOnShutdown(QQuickItem *);
186 };
187
188
189 Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickCanvasPrivate::FocusOptions)
190
191 QT_END_NAMESPACE
192
193 #endif // QQUICKCANVAS_P_H