1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtOpenGL module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "qgl.h"
|
---|
43 | #include <private/qt_x11_p.h>
|
---|
44 | #include <private/qgl_p.h>
|
---|
45 | #include <private/qpaintengine_opengl_p.h>
|
---|
46 | #include "qgl_egl_p.h"
|
---|
47 | #include "qcolormap.h"
|
---|
48 |
|
---|
49 |
|
---|
50 | QT_BEGIN_NAMESPACE
|
---|
51 |
|
---|
52 |
|
---|
53 | bool QGLFormat::hasOpenGL()
|
---|
54 | {
|
---|
55 | return true;
|
---|
56 | }
|
---|
57 |
|
---|
58 | bool QGLFormat::hasOpenGLOverlays()
|
---|
59 | {
|
---|
60 | return false;
|
---|
61 | }
|
---|
62 |
|
---|
63 | void qt_egl_add_platform_config(QEglProperties& props, QPaintDevice *device)
|
---|
64 | {
|
---|
65 | if (device->devType() == QInternal::Image)
|
---|
66 | props.setPixelFormat(static_cast<QImage *>(device)->format());
|
---|
67 | }
|
---|
68 |
|
---|
69 | bool QGLContext::chooseContext(const QGLContext* shareContext)
|
---|
70 | {
|
---|
71 | Q_D(QGLContext);
|
---|
72 |
|
---|
73 | if (!device())
|
---|
74 | return false;
|
---|
75 |
|
---|
76 | int devType = device()->devType();
|
---|
77 |
|
---|
78 | // Get the display and initialize it.
|
---|
79 | d->eglContext = new QEglContext();
|
---|
80 | d->eglContext->setApi(QEglContext::OpenGL);
|
---|
81 | if (!d->eglContext->openDisplay(device())) {
|
---|
82 | delete d->eglContext;
|
---|
83 | d->eglContext = 0;
|
---|
84 | return false;
|
---|
85 | }
|
---|
86 |
|
---|
87 | // Construct the configuration we need for this surface.
|
---|
88 | QEglProperties configProps;
|
---|
89 | qt_egl_set_format(configProps, devType, d->glFormat);
|
---|
90 | qt_egl_add_platform_config(configProps, device());
|
---|
91 | configProps.setRenderableType(QEglContext::OpenGL);
|
---|
92 |
|
---|
93 | // Search for a matching configuration, reducing the complexity
|
---|
94 | // each time until we get something that matches.
|
---|
95 | if (!d->eglContext->chooseConfig(configProps, QEglContext::BestPixelFormat)) {
|
---|
96 | delete d->eglContext;
|
---|
97 | d->eglContext = 0;
|
---|
98 | return false;
|
---|
99 | }
|
---|
100 |
|
---|
101 | // Inform the higher layers about the actual format properties.
|
---|
102 | qt_egl_update_format(*(d->eglContext), d->glFormat);
|
---|
103 |
|
---|
104 | // Create a new context for the configuration.
|
---|
105 | if (!d->eglContext->createContext
|
---|
106 | (shareContext ? shareContext->d_func()->eglContext : 0)) {
|
---|
107 | delete d->eglContext;
|
---|
108 | d->eglContext = 0;
|
---|
109 | return false;
|
---|
110 | }
|
---|
111 |
|
---|
112 | #if defined(EGL_VERSION_1_1)
|
---|
113 | if (d->glFormat.swapInterval() != -1 && devType == QInternal::Widget)
|
---|
114 | eglSwapInterval(d->eglContext->display(), d->glFormat.swapInterval());
|
---|
115 | #endif
|
---|
116 |
|
---|
117 | // Create the EGL surface to draw into.
|
---|
118 | if (!d->eglContext->createSurface(device())) {
|
---|
119 | delete d->eglContext;
|
---|
120 | d->eglContext = 0;
|
---|
121 | return false;
|
---|
122 | }
|
---|
123 |
|
---|
124 | return true;
|
---|
125 | }
|
---|
126 |
|
---|
127 |
|
---|
128 | void QGLContext::reset()
|
---|
129 | {
|
---|
130 | Q_D(QGLContext);
|
---|
131 | if (!d->valid)
|
---|
132 | return;
|
---|
133 | d->cleanup();
|
---|
134 | doneCurrent();
|
---|
135 | if (d->eglContext) {
|
---|
136 | delete d->eglContext;
|
---|
137 | d->eglContext = 0;
|
---|
138 | }
|
---|
139 | d->crWin = false;
|
---|
140 | d->sharing = false;
|
---|
141 | d->valid = false;
|
---|
142 | d->transpColor = QColor();
|
---|
143 | d->initDone = false;
|
---|
144 | qgl_share_reg()->removeShare(this);
|
---|
145 | }
|
---|
146 |
|
---|
147 | void QGLContext::makeCurrent()
|
---|
148 | {
|
---|
149 | Q_D(QGLContext);
|
---|
150 | if(!d->valid || !d->eglContext) {
|
---|
151 | qWarning("QGLContext::makeCurrent(): Cannot make invalid context current");
|
---|
152 | return;
|
---|
153 | }
|
---|
154 |
|
---|
155 | if (d->eglContext->makeCurrent()) {
|
---|
156 | if (!qgl_context_storage.hasLocalData() && QThread::currentThread())
|
---|
157 | qgl_context_storage.setLocalData(new QGLThreadContext);
|
---|
158 | if (qgl_context_storage.hasLocalData())
|
---|
159 | qgl_context_storage.localData()->context = this;
|
---|
160 | currentCtx = this;
|
---|
161 | }
|
---|
162 | }
|
---|
163 |
|
---|
164 | void QGLContext::doneCurrent()
|
---|
165 | {
|
---|
166 | Q_D(QGLContext);
|
---|
167 | if (d->eglContext)
|
---|
168 | d->eglContext->doneCurrent();
|
---|
169 |
|
---|
170 | if (qgl_context_storage.hasLocalData())
|
---|
171 | qgl_context_storage.localData()->context = 0;
|
---|
172 | currentCtx = 0;
|
---|
173 | }
|
---|
174 |
|
---|
175 |
|
---|
176 | void QGLContext::swapBuffers() const
|
---|
177 | {
|
---|
178 | Q_D(const QGLContext);
|
---|
179 | if(!d->valid || !d->eglContext)
|
---|
180 | return;
|
---|
181 |
|
---|
182 | d->eglContext->swapBuffers();
|
---|
183 | }
|
---|
184 |
|
---|
185 | QColor QGLContext::overlayTransparentColor() const
|
---|
186 | {
|
---|
187 | return QColor(0, 0, 0); // Invalid color
|
---|
188 | }
|
---|
189 |
|
---|
190 | uint QGLContext::colorIndex(const QColor &c) const
|
---|
191 | {
|
---|
192 | //### color index doesn't work on egl
|
---|
193 | Q_UNUSED(c);
|
---|
194 | return 0;
|
---|
195 | }
|
---|
196 |
|
---|
197 | void QGLContext::generateFontDisplayLists(const QFont & fnt, int listBase)
|
---|
198 | {
|
---|
199 | Q_UNUSED(fnt);
|
---|
200 | Q_UNUSED(listBase);
|
---|
201 | }
|
---|
202 |
|
---|
203 | void *QGLContext::getProcAddress(const QString &proc) const
|
---|
204 | {
|
---|
205 | return (void*)eglGetProcAddress(reinterpret_cast<const char *>(proc.toLatin1().data()));
|
---|
206 | }
|
---|
207 |
|
---|
208 | void QGLWidget::setMouseTracking(bool enable)
|
---|
209 | {
|
---|
210 | QWidget::setMouseTracking(enable);
|
---|
211 | }
|
---|
212 |
|
---|
213 |
|
---|
214 | void QGLWidget::resizeEvent(QResizeEvent *)
|
---|
215 | {
|
---|
216 | Q_D(QGLWidget);
|
---|
217 | if (!isValid())
|
---|
218 | return;
|
---|
219 | makeCurrent();
|
---|
220 | if (!d->glcx->initialized())
|
---|
221 | glInit();
|
---|
222 | resizeGL(width(), height());
|
---|
223 | //handle overlay
|
---|
224 | }
|
---|
225 |
|
---|
226 | const QGLContext* QGLWidget::overlayContext() const
|
---|
227 | {
|
---|
228 | return 0;
|
---|
229 | }
|
---|
230 |
|
---|
231 | void QGLWidget::makeOverlayCurrent()
|
---|
232 | {
|
---|
233 | //handle overlay
|
---|
234 | }
|
---|
235 |
|
---|
236 | void QGLWidget::updateOverlayGL()
|
---|
237 | {
|
---|
238 | //handle overlay
|
---|
239 | }
|
---|
240 |
|
---|
241 | void QGLWidget::setContext(QGLContext *context, const QGLContext* shareContext, bool deleteOldContext)
|
---|
242 | {
|
---|
243 | Q_D(QGLWidget);
|
---|
244 | if (context == 0) {
|
---|
245 | qWarning("QGLWidget::setContext: Cannot set null context");
|
---|
246 | return;
|
---|
247 | }
|
---|
248 | if (!context->deviceIsPixmap() && context->device() != this) {
|
---|
249 | qWarning("QGLWidget::setContext: Context must refer to this widget");
|
---|
250 | return;
|
---|
251 | }
|
---|
252 |
|
---|
253 | if (d->glcx)
|
---|
254 | d->glcx->doneCurrent();
|
---|
255 | QGLContext* oldcx = d->glcx;
|
---|
|
---|