QNX: Enable threaded OpenGL rendering on QNX
[profile/ivi/qtbase.git] / src / plugins / platforms / qnx / qqnxwindow.h
1 /***************************************************************************
2 **
3 ** Copyright (C) 2011 - 2012 Research In Motion
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QQNXWINDOW_H
43 #define QQNXWINDOW_H
44
45 #include <qpa/qplatformwindow.h>
46
47 #include "qqnxbuffer.h"
48
49 #include <QtGui/QImage>
50 #include <QtCore/QMutex>
51
52 #ifndef QT_NO_OPENGL
53 #include <EGL/egl.h>
54 #endif
55
56 #include <screen/screen.h>
57
58 QT_BEGIN_NAMESPACE
59
60 // all surfaces double buffered
61 #define MAX_BUFFER_COUNT    2
62
63 #ifndef QT_NO_OPENGL
64 class QQnxGLContext;
65 #endif
66 class QQnxScreen;
67
68 class QSurfaceFormat;
69
70 class QQnxWindow : public QPlatformWindow
71 {
72 friend class QQnxScreen;
73 public:
74     QQnxWindow(QWindow *window, screen_context_t context);
75     virtual ~QQnxWindow();
76
77     void setGeometry(const QRect &rect);
78     void setVisible(bool visible);
79     void setOpacity(qreal level);
80
81     bool isExposed() const;
82
83     WId winId() const { return (WId)m_window; }
84     screen_window_t nativeHandle() const { return m_window; }
85
86     // Called by QQnxGLContext::createSurface()
87     QSize requestedBufferSize() const;
88
89     void setBufferSize(const QSize &size);
90     QSize bufferSize() const { return m_bufferSize; }
91     bool hasBuffers() const { return !m_bufferSize.isEmpty(); }
92
93     QQnxBuffer &renderBuffer();
94     void scroll(const QRegion &region, int dx, int dy, bool flush=false);
95     void post(const QRegion &dirty);
96
97     void setScreen(QQnxScreen *platformScreen);
98
99     void setParent(const QPlatformWindow *window);
100     void raise();
101     void lower();
102     void requestActivateWindow();
103     Qt::WindowState setWindowState(Qt::WindowState state);
104
105     void gainedFocus();
106
107     QQnxScreen *screen() const { return m_screen; }
108     const QList<QQnxWindow*>& children() const { return m_childWindows; }
109
110 #ifndef QT_NO_OPENGL
111     void setPlatformOpenGLContext(QQnxGLContext *platformOpenGLContext);
112     QQnxGLContext *platformOpenGLContext() const { return m_platformOpenGLContext; }
113 #endif
114
115     QQnxWindow *findWindow(screen_window_t windowHandle);
116
117 private:
118     void removeFromParent();
119     void setOffset(const QPoint &setOffset);
120     void updateVisibility(bool parentVisible);
121     void updateZorder(int &topZorder);
122
123     void fetchBuffers();
124
125     void copyBack(const QRegion &region, int dx, int dy, bool flush=false);
126
127     static int platformWindowFormatToNativeFormat(const QSurfaceFormat &format);
128
129     screen_context_t m_screenContext;
130     screen_window_t m_window;
131     QSize m_bufferSize;
132     QQnxBuffer m_buffers[MAX_BUFFER_COUNT];
133     int m_currentBufferIndex;
134     int m_previousBufferIndex;
135     QRegion m_previousDirty;
136     QRegion m_scrolled;
137
138 #ifndef QT_NO_OPENGL
139     QQnxGLContext *m_platformOpenGLContext;
140 #endif
141     QQnxScreen *m_screen;
142     QList<QQnxWindow*> m_childWindows;
143     QQnxWindow *m_parentWindow;
144     bool m_visible;
145     QRect m_unmaximizedGeometry;
146     Qt::WindowState m_windowState;
147
148     // This mutex is used to protect access to the m_requestedBufferSize
149     // member. This member is used in conjunction with QQnxGLContext::requestNewSurface()
150     // to coordinate recreating the EGL surface which involves destroying any
151     // existing EGL surface; resizing the native window buffers; and creating a new
152     // EGL surface. All of this has to be done from the thread that is calling
153     // QQnxGLContext::makeCurrent()
154     mutable QMutex m_mutex;
155     QSize m_requestedBufferSize;
156 };
157
158 QT_END_NAMESPACE
159
160 #endif // QQNXWINDOW_H