1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtOpenGL module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
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.
|
---|
23 | **
|
---|
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.
|
---|
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 have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include <QtOpenGL/qgl.h>
|
---|
43 | #include "qgl_p.h"
|
---|
44 | #include "qgl_egl_p.h"
|
---|
45 |
|
---|
46 | QT_BEGIN_NAMESPACE
|
---|
47 |
|
---|
48 | // Set device configuration attributes from a QGLFormat instance.
|
---|
49 | void qt_egl_set_format(QEglProperties& props, int deviceType, const QGLFormat& f)
|
---|
50 | {
|
---|
51 | if (deviceType == QInternal::Pixmap || deviceType == QInternal::Image)
|
---|
52 | props.setValue(EGL_SURFACE_TYPE, EGL_PIXMAP_BIT);
|
---|
53 | else if (deviceType == QInternal::Pbuffer)
|
---|
54 | props.setValue(EGL_SURFACE_TYPE, EGL_PBUFFER_BIT);
|
---|
55 | else
|
---|
56 | props.setValue(EGL_SURFACE_TYPE, EGL_WINDOW_BIT);
|
---|
57 |
|
---|
58 | // Set the pixel format to that contained in the QGLFormat
|
---|
59 | // if the system hasn't already chosen a fixed format to
|
---|
60 | // match the pixmap, widget, etc.
|
---|
61 | if (props.value(EGL_RED_SIZE) == 0 || f.redBufferSize() != -1)
|
---|
62 | props.setValue(EGL_RED_SIZE, f.redBufferSize() == -1 ? 1 : f.redBufferSize());
|
---|
63 | if (props.value(EGL_GREEN_SIZE) == 0 || f.greenBufferSize() != -1)
|
---|
64 | props.setValue(EGL_GREEN_SIZE, f.greenBufferSize() == -1 ? 1 : f.greenBufferSize());
|
---|
65 | if (props.value(EGL_BLUE_SIZE) == 0 || f.blueBufferSize() != -1)
|
---|
66 | props.setValue(EGL_BLUE_SIZE, f.blueBufferSize() == -1 ? 1 : f.blueBufferSize());
|
---|
67 | if (f.alpha()) {
|
---|
68 | if (props.value(EGL_ALPHA_SIZE) == 0 || f.alphaBufferSize() != -1)
|
---|
69 | props.setValue(EGL_ALPHA_SIZE, f.alphaBufferSize() == -1 ? 1 : f.alphaBufferSize());
|
---|
70 | }
|
---|
71 |
|
---|
72 | if (f.depth())
|
---|
73 | props.setValue(EGL_DEPTH_SIZE, f.depthBufferSize() == -1 ? 1 : f.depthBufferSize());
|
---|
74 | if (f.stencil())
|
---|
75 | props.setValue(EGL_STENCIL_SIZE, f.stencilBufferSize() == -1 ? 1 : f.stencilBufferSize());
|
---|
76 | if (f.sampleBuffers()) {
|
---|
77 | props.setValue(EGL_SAMPLE_BUFFERS, 1);
|
---|
78 | props.setValue(EGL_SAMPLES, f.samples() == -1 ? 1 : f.samples());
|
---|
79 | } else {
|
---|
80 | props.setValue(EGL_SAMPLE_BUFFERS, 0);
|
---|
81 | }
|
---|
82 | if (deviceType == QInternal::Widget)
|
---|
83 | props.setValue(EGL_LEVEL, f.plane());
|
---|
84 | }
|
---|
85 |
|
---|
86 | // Updates "format" with the parameters of the selected configuration.
|
---|
87 | void qt_egl_update_format(const QEglContext& context, QGLFormat& format)
|
---|
88 | {
|
---|
89 | EGLint value = 0;
|
---|
90 |
|
---|
91 | if (context.configAttrib(EGL_RED_SIZE, &value))
|
---|
92 | format.setRedBufferSize(value);
|
---|
93 | if (context.configAttrib(EGL_GREEN_SIZE, &value))
|
---|
94 | format.setGreenBufferSize(value);
|
---|
95 | if (context.configAttrib(EGL_BLUE_SIZE, &value))
|
---|
96 | format.setBlueBufferSize(value);
|
---|
97 | if (context.configAttrib(EGL_ALPHA_SIZE, &value)) {
|
---|
98 | format.setAlpha(value != 0);
|
---|
99 | if (format.alpha())
|
---|
100 | format.setAlphaBufferSize(value);
|
---|
101 | }
|
---|
102 |
|
---|
103 | if (context.configAttrib(EGL_DEPTH_SIZE, &value)) {
|
---|
104 | format.setDepth(value != 0);
|
---|
105 | if (format.depth())
|
---|
106 | format.setDepthBufferSize(value);
|
---|
107 | }
|
---|
108 |
|
---|
109 | if (context.configAttrib(EGL_LEVEL, &value))
|
---|
110 | format.setPlane(value);
|
---|
111 |
|
---|
112 | if (context.configAttrib(EGL_SAMPLE_BUFFERS, &value)) {
|
---|
113 | format.setSampleBuffers(value != 0);
|
---|
114 | if (format.sampleBuffers()) {
|
---|
115 | context.configAttrib(EGL_SAMPLES, &value);
|
---|
116 | format.setSamples(value);
|
---|
117 | }
|
---|
118 | }
|
---|
119 |
|
---|
120 | if (context.configAttrib(EGL_STENCIL_SIZE, &value)) {
|
---|
121 | format.setStencil(value != 0);
|
---|
122 | if (format.stencil())
|
---|
123 | format.setStencilBufferSize(value);
|
---|
124 | }
|
---|
125 |
|
---|
126 | // Clear the EGL error state because some of the above may
|
---|
127 | // have errored out because the attribute is not applicable
|
---|
128 | // to the surface type. Such errors don't matter.
|
---|
129 | context.clearError();
|
---|
130 | }
|
---|
131 |
|
---|
132 | bool QGLFormat::hasOpenGL()
|
---|
133 | {
|
---|
134 | return true;
|
---|
135 | }
|
---|
136 |
|
---|
137 | void QGLContext::reset()
|
---|
138 | {
|
---|
139 | Q_D(QGLContext);
|
---|
140 | if (!d->valid)
|
---|
141 | return;
|
---|
142 | d->cleanup();
|
---|
143 | doneCurrent();
|
---|
144 | if (d->eglContext) {
|
---|
145 | d->destroyEglSurfaceForDevice();
|
---|
146 | delete d->eglContext;
|
---|
147 | }
|
---|
148 | d->eglContext = 0;
|
---|
149 | d->eglSurface = EGL_NO_SURFACE;
|
---|
150 | d->crWin = false;
|
---|
151 | d->sharing = false;
|
---|
152 | d->valid = false;
|
---|
153 | d->transpColor = QColor();
|
---|
154 | d->initDone = false;
|
---|
155 | qgl_share_reg()->removeShare(this);
|
---|
156 | }
|
---|
157 |
|
---|
158 | void QGLContext::makeCurrent()
|
---|
159 | {
|
---|
160 | Q_D(QGLContext);
|
---|
161 | if (!d->valid || !d->eglContext || d->eglSurface == EGL_NO_SURFACE) {
|
---|
162 | qWarning("QGLContext::makeCurrent(): Cannot make invalid context current");
|
---|
163 | return;
|
---|
164 | }
|
---|
165 |
|
---|
166 | if (d->eglContext->makeCurrent(d->eglSurface))
|
---|
167 | QGLContextPrivate::setCurrentContext(this);
|
---|
168 | }
|
---|
169 |
|
---|
170 | void QGLContext::doneCurrent()
|
---|
171 | {
|
---|
172 | Q_D(QGLContext);
|
---|
173 | if (d->eglContext)
|
---|
174 | d->eglContext->doneCurrent();
|
---|
175 |
|
---|
176 | QGLContextPrivate::setCurrentContext(0);
|
---|
177 | }
|
---|
178 |
|
---|
179 |
|
---|
180 | void QGLContext::swapBuffers() const
|
---|
181 | {
|
---|
182 | Q_D(const QGLContext);
|
---|
183 | if (!d->valid || !d->eglContext)
|
---|
184 | return;
|
---|
185 |
|
---|
186 | d->eglContext->swapBuffers(d->eglSurface);
|
---|
187 | }
|
---|
188 |
|
---|
189 | void QGLContextPrivate::destroyEglSurfaceForDevice()
|
---|
190 | {
|
---|
191 | if (eglSurface != EGL_NO_SURFACE) {
|
---|
192 | #ifdef Q_WS_X11
|
---|
193 | // Make sure we don't call eglDestroySurface on a surface which
|
---|
194 | // was created for a different winId:
|
---|
195 | if (paintDevice->devType() == QInternal::Widget) {
|
---|
196 | QGLWidget* w = static_cast<QGLWidget*>(paintDevice);
|
---|
197 |
|
---|
198 | if (w->d_func()->eglSurfaceWindowId == w->winId())
|
---|
199 | eglDestroySurface(eglContext->display(), eglSurface);
|
---|
200 | else
|
---|
201 | qWarning("WARNING: Potential EGL surface leak!");
|
---|
202 | } else
|
---|
203 | #endif
|
---|
204 | eglDestroySurface(eglContext->display(), eglSurface);
|
---|
205 | eglSurface = EGL_NO_SURFACE;
|
---|
206 | }
|
---|
207 | }
|
---|
208 |
|
---|
209 | void QGLWidget::setMouseTracking(bool enable)
|
---|
210 | {
|
---|
211 | QWidget::setMouseTracking(enable);
|
---|
212 | }
|
---|
213 |
|
---|
214 | QColor QGLContext::overlayTransparentColor() const
|
---|
215 | {
|
---|
216 | return d_func()->transpColor;
|
---|
217 | }
|
---|
218 |
|
---|
219 | uint QGLContext::colorIndex(const QColor &c) const
|
---|
220 | {
|
---|
221 | Q_UNUSED(c);
|
---|
222 | return 0;
|
---|
223 | }
|
---|
224 |
|
---|
225 | void QGLContext::generateFontDisplayLists(const QFont & fnt, int listBase)
|
---|
226 | {
|
---|
227 | Q_UNUSED(fnt);
|
---|
228 | Q_UNUSED(listBase);
|
---|
229 | }
|
---|
230 |
|
---|
231 | void *QGLContext::getProcAddress(const QString &proc) const
|
---|
232 | {
|
---|
233 | return (void*)eglGetProcAddress(reinterpret_cast<const char *>(proc.toLatin1().data()));
|
---|
234 | }
|
---|
235 |
|
---|
236 | bool QGLWidgetPrivate::renderCxPm(QPixmap*)
|
---|
237 | {
|
---|
238 | return false;
|
---|
239 | }
|
---|
240 |
|
---|
241 | QT_END_NAMESPACE
|
---|