Warning: That file was not part of the compilation database. It may have many parsing errors.
1 | /**************************************************************************** |
---|---|
2 | ** |
3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/legal |
5 | ** |
6 | ** This file is part of the QtOpenGL module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and Digia. For licensing terms and |
14 | ** conditions see http://qt.digia.com/licensing. For further information |
15 | ** use the contact form at http://qt.digia.com/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 2.1 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
24 | ** |
25 | ** In addition, as a special exception, Digia gives you certain additional |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
28 | ** |
29 | ** GNU General Public License Usage |
30 | ** Alternatively, this file may be used under the terms of the GNU |
31 | ** General Public License version 3.0 as published by the Free Software |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
33 | ** packaging of this file. Please review the following information to |
34 | ** ensure the GNU General Public License version 3.0 requirements will be |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
36 | ** |
37 | ** |
38 | ** $QT_END_LICENSE$ |
39 | ** |
40 | ****************************************************************************/ |
41 | |
42 | #include <QApplication> |
43 | #include <QtGui/private/qapplication_p.h> |
44 | #include <QPixmap> |
45 | #include <QDebug> |
46 | |
47 | #include <QtGui/private/qapplication_p.h> |
48 | #include <QtGui/QPlatformWindow> |
49 | |
50 | #include "qgl.h" |
51 | #include "qgl_p.h" |
52 | |
53 | QT_BEGIN_NAMESPACE |
54 | |
55 | /*! |
56 | \since 4.8 |
57 | |
58 | Returns an OpenGL format for the platform window format specified by \a format. |
59 | */ |
60 | QGLFormat QGLFormat::fromPlatformWindowFormat(const QPlatformWindowFormat &format) |
61 | { |
62 | QGLFormat retFormat; |
63 | retFormat.setAccum(format.accum()); |
64 | if (format.accumBufferSize() >= 0) |
65 | retFormat.setAccumBufferSize(format.accumBufferSize()); |
66 | retFormat.setAlpha(format.alpha()); |
67 | if (format.alphaBufferSize() >= 0) |
68 | retFormat.setAlphaBufferSize(format.alphaBufferSize()); |
69 | if (format.blueBufferSize() >= 0) |
70 | retFormat.setBlueBufferSize(format.blueBufferSize()); |
71 | retFormat.setDepth(format.depth()); |
72 | if (format.depthBufferSize() >= 0) |
73 | retFormat.setDepthBufferSize(format.depthBufferSize()); |
74 | retFormat.setDirectRendering(format.directRendering()); |
75 | retFormat.setDoubleBuffer(format.doubleBuffer()); |
76 | if (format.greenBufferSize() >= 0) |
77 | retFormat.setGreenBufferSize(format.greenBufferSize()); |
78 | if (format.redBufferSize() >= 0) |
79 | retFormat.setRedBufferSize(format.redBufferSize()); |
80 | retFormat.setRgba(format.rgba()); |
81 | retFormat.setSampleBuffers(format.sampleBuffers()); |
82 | retFormat.setSamples(format.sampleBuffers()); |
83 | retFormat.setStencil(format.stencil()); |
84 | if (format.stencilBufferSize() >= 0) |
85 | retFormat.setStencilBufferSize(format.stencilBufferSize()); |
86 | retFormat.setStereo(format.stereo()); |
87 | retFormat.setSwapInterval(format.swapInterval()); |
88 | return retFormat; |
89 | } |
90 | |
91 | /*! |
92 | \since 4.8 |
93 | |
94 | Returns a platform window format for the OpenGL format specified by \a format. |
95 | */ |
96 | QPlatformWindowFormat QGLFormat::toPlatformWindowFormat(const QGLFormat &format) |
97 | { |
98 | QPlatformWindowFormat retFormat; |
99 | retFormat.setAccum(format.accum()); |
100 | if (format.accumBufferSize() >= 0) |
101 | retFormat.setAccumBufferSize(format.accumBufferSize()); |
102 | retFormat.setAlpha(format.alpha()); |
103 | if (format.alphaBufferSize() >= 0) |
104 | retFormat.setAlphaBufferSize(format.alphaBufferSize()); |
105 | if (format.blueBufferSize() >= 0) |
106 | retFormat.setBlueBufferSize(format.blueBufferSize()); |
107 | retFormat.setDepth(format.depth()); |
108 | if (format.depthBufferSize() >= 0) |
109 | retFormat.setDepthBufferSize(format.depthBufferSize()); |
110 | retFormat.setDirectRendering(format.directRendering()); |
111 | retFormat.setDoubleBuffer(format.doubleBuffer()); |
112 | if (format.greenBufferSize() >= 0) |
113 | retFormat.setGreenBufferSize(format.greenBufferSize()); |
114 | if (format.redBufferSize() >= 0) |
115 | retFormat.setRedBufferSize(format.redBufferSize()); |
116 | retFormat.setRgba(format.rgba()); |
117 | retFormat.setSampleBuffers(format.sampleBuffers()); |
118 | if (format.samples() >= 0) |
119 | retFormat.setSamples(format.samples()); |
120 | retFormat.setStencil(format.stencil()); |
121 | if (format.stencilBufferSize() >= 0) |
122 | retFormat.setStencilBufferSize(format.stencilBufferSize()); |
123 | retFormat.setStereo(format.stereo()); |
124 | retFormat.setSwapInterval(format.swapInterval()); |
125 | return retFormat; |
126 | } |
127 | |
128 | void QGLContextPrivate::setupSharing() { |
129 | Q_Q(QGLContext); |
130 | QPlatformGLContext *sharedPlatformGLContext = platformContext->platformWindowFormat().sharedGLContext(); |
131 | if (sharedPlatformGLContext) { |
132 | QGLContext *actualSharedContext = QGLContext::fromPlatformGLContext(sharedPlatformGLContext); |
133 | sharing = true; |
134 | QGLContextGroup::addShare(q,actualSharedContext); |
135 | } |
136 | } |
137 | |
138 | bool QGLFormat::hasOpenGL() |
139 | { |
140 | return QApplicationPrivate::platformIntegration() |
141 | ->hasCapability(QPlatformIntegration::OpenGL); |
142 | } |
143 | |
144 | void qDeleteQGLContext(void *handle) |
145 | { |
146 | QGLContext *context = static_cast<QGLContext *>(handle); |
147 | delete context; |
148 | } |
149 | |
150 | bool QGLContext::chooseContext(const QGLContext* shareContext) |
151 | { |
152 | Q_D(QGLContext); |
153 | if(!d->paintDevice || d->paintDevice->devType() != QInternal::Widget) { |
154 | d->valid = false; |
155 | }else { |
156 | QWidget *widget = static_cast<QWidget *>(d->paintDevice); |
157 | if (!widget->platformWindow()){ |
158 | QGLFormat glformat = format(); |
159 | QPlatformWindowFormat winFormat = QGLFormat::toPlatformWindowFormat(glformat); |
160 | if (shareContext) { |
161 | winFormat.setSharedContext(shareContext->d_func()->platformContext); |
162 | } |
163 | if (widget->testAttribute(Qt::WA_TranslucentBackground)) |
164 | winFormat.setAlpha(true); |
165 | winFormat.setWindowApi(QPlatformWindowFormat::OpenGL); |
166 | winFormat.setWindowSurface(false); |
167 | widget->setPlatformWindowFormat(winFormat); |
168 | widget->winId();//make window |
169 | } |
170 | d->platformContext = widget->platformWindow()->glContext(); |
171 | Q_ASSERT(d->platformContext); |
172 | d->glFormat = QGLFormat::fromPlatformWindowFormat(d->platformContext->platformWindowFormat()); |
173 | d->valid =(bool) d->platformContext; |
174 | if (d->valid) { |
175 | d->platformContext->setQGLContextHandle(this,qDeleteQGLContext); |
176 | } |
177 | d->setupSharing(); |
178 | } |
179 | |
180 | |
181 | return d->valid; |
182 | } |
183 | |
184 | void QGLContext::reset() |
185 | { |
186 | Q_D(QGLContext); |
187 | if (!d->valid) |
188 | return; |
189 | d->cleanup(); |
190 | |
191 | d->crWin = false; |
192 | d->sharing = false; |
193 | d->valid = false; |
194 | d->transpColor = QColor(); |
195 | d->initDone = false; |
196 | QGLContextGroup::removeShare(this); |
197 | if (d->platformContext) { |
198 | d->platformContext->setQGLContextHandle(0,0); |
199 | } |
200 | } |
201 | |
202 | void QGLContext::makeCurrent() |
203 | { |
204 | Q_D(QGLContext); |
205 | d->platformContext->makeCurrent(); |
206 | |
207 | if (!d->workaroundsCached) { |
208 | d->workaroundsCached = true; |
209 | const char *renderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER)); |
210 | if (renderer && strstr(renderer, "Mali")) { |
211 | d->workaround_brokenFBOReadBack = true; |
212 | } |
213 | } |
214 | |
215 | } |
216 | |
217 | void QGLContext::doneCurrent() |
218 | { |
219 | Q_D(QGLContext); |
220 | d->platformContext->doneCurrent(); |
221 | } |
222 | |
223 | void QGLContext::swapBuffers() const |
224 | { |
225 | Q_D(const QGLContext); |
226 | d->platformContext->swapBuffers(); |
227 | } |
228 | |
229 | void *QGLContext::getProcAddress(const QString &procName) const |
230 | { |
231 | Q_D(const QGLContext); |
232 | return d->platformContext->getProcAddress(procName); |
233 | } |
234 | |
235 | void QGLWidget::setContext(QGLContext *context, |
236 | const QGLContext* shareContext, |
237 | bool deleteOldContext) |
238 | { |
239 | Q_D(QGLWidget); |
240 | if (context == 0) { |
241 | qWarning("QGLWidget::setContext: Cannot set null context"); |
242 | return; |
243 | } |
244 | |
245 | if (context->device() == 0) // a context may refere to more than 1 window. |
246 | context->setDevice(this); //but its better to point to 1 of them than none of them. |
247 | |
248 | QGLContext* oldcx = d->glcx; |
249 | d->glcx = context; |
250 | |
251 | if (!d->glcx->isValid()) |
252 | d->glcx->create(shareContext ? shareContext : oldcx); |
253 | |
254 | if (deleteOldContext) |
255 | delete oldcx; |
256 | } |
257 | |
258 | void QGLWidgetPrivate::init(QGLContext *context, const QGLWidget *shareWidget) |
259 | { |
260 | initContext(context, shareWidget); |
261 | } |
262 | |
263 | bool QGLFormat::hasOpenGLOverlays() |
264 | { |
265 | return false; |
266 | } |
267 | |
268 | QColor QGLContext::overlayTransparentColor() const |
269 | { |
270 | return QColor(); // Invalid color |
271 | } |
272 | |
273 | uint QGLContext::colorIndex(const QColor&) const |
274 | { |
275 | return 0; |
276 | } |
277 | |
278 | void QGLContext::generateFontDisplayLists(const QFont & fnt, int listBase) |
279 | { |
280 | Q_UNUSED(fnt); |
281 | Q_UNUSED(listBase); |
282 | } |
283 | |
284 | /* |
285 | QGLTemporaryContext implementation |
286 | */ |
287 | class QGLTemporaryContextPrivate |
288 | { |
289 | public: |
290 | QWidget *widget; |
291 | QPlatformGLContext *context; |
292 | }; |
293 | |
294 | QGLTemporaryContext::QGLTemporaryContext(bool, QWidget *) |
295 | : d(new QGLTemporaryContextPrivate) |
296 | { |
297 | d->context = const_cast<QPlatformGLContext *>(QPlatformGLContext::currentContext()); |
298 | if (d->context) |
299 | d->context->doneCurrent(); |
300 | d->widget = new QWidget; |
301 | d->widget->setGeometry(0,0,3,3); |
302 | QPlatformWindowFormat format = d->widget->platformWindowFormat(); |
303 | format.setWindowApi(QPlatformWindowFormat::OpenGL); |
304 | format.setWindowSurface(false); |
305 | d->widget->setPlatformWindowFormat(format); |
306 | d->widget->winId(); |
307 | |
308 | d->widget->platformWindow()->glContext()->makeCurrent(); |
309 | } |
310 | |
311 | QGLTemporaryContext::~QGLTemporaryContext() |
312 | { |
313 | d->widget->platformWindow()->glContext()->doneCurrent(); |
314 | if (d->context) |
315 | d->context->makeCurrent(); |
316 | delete d->widget; |
317 | } |
318 | |
319 | |
320 | bool QGLWidgetPrivate::renderCxPm(QPixmap*) |
321 | { |
322 | return false; |
323 | } |
324 | |
325 | /*! \internal |
326 | Free up any allocated colormaps. This fn is only called for |
327 | top-level widgets. |
328 | */ |
329 | void QGLWidgetPrivate::cleanupColormaps() |
330 | { |
331 | } |
332 | |
333 | void QGLWidget::setMouseTracking(bool enable) |
334 | { |
335 | Q_UNUSED(enable); |
336 | } |
337 | |
338 | bool QGLWidget::event(QEvent *e) |
339 | { |
340 | return QWidget::event(e); |
341 | } |
342 | |
343 | void QGLWidget::resizeEvent(QResizeEvent *e) |
344 | { |
345 | Q_D(QGLWidget); |
346 | |
347 | QWidget::resizeEvent(e); |
348 | if (!isValid()) |
349 | return; |
350 | makeCurrent(); |
351 | if (!d->glcx->initialized()) |
352 | glInit(); |
353 | resizeGL(width(), height()); |
354 | } |
355 | |
356 | |
357 | const QGLContext* QGLWidget::overlayContext() const |
358 | { |
359 | return 0; |
360 | } |
361 | |
362 | void QGLWidget::makeOverlayCurrent() |
363 | { |
364 | } |
365 | |
366 | |
367 | void QGLWidget::updateOverlayGL() |
368 | { |
369 | } |
370 | |
371 | const QGLColormap & QGLWidget::colormap() const |
372 | { |
373 | Q_D(const QGLWidget); |
374 | return d->cmap; |
375 | } |
376 | |
377 | void QGLWidget::setColormap(const QGLColormap & c) |
378 | { |
379 | Q_UNUSED(c); |
380 | } |
381 | |
382 | QGLContext::QGLContext(QPlatformGLContext *platformContext) |
383 | : d_ptr(new QGLContextPrivate(this)) |
384 | { |
385 | Q_D(QGLContext); |
386 | d->init(0,QGLFormat::fromPlatformWindowFormat(platformContext->platformWindowFormat())); |
387 | d->platformContext = platformContext; |
388 | d->platformContext->setQGLContextHandle(this,qDeleteQGLContext); |
389 | d->valid = true; |
390 | d->setupSharing(); |
391 | } |
392 | |
393 | /*! |
394 | \since 4.8 |
395 | |
396 | Returns a OpenGL context for the platform-specific OpenGL context given by |
397 | \a platformContext. |
398 | */ |
399 | QGLContext *QGLContext::fromPlatformGLContext(QPlatformGLContext *platformContext) |
400 | { |
401 | if (!platformContext) |
402 | return 0; |
403 | if (platformContext->qGLContextHandle()) { |
404 | return reinterpret_cast<QGLContext *>(platformContext->qGLContextHandle()); |
405 | } |
406 | QGLContext *glContext = new QGLContext(platformContext); |
407 | //Don't call create on context. This can cause the platformFormat to be set on the widget, which |
408 | //will cause the platformWindow to be recreated. |
409 | return glContext; |
410 | } |
411 | |
412 | QT_END_NAMESPACE |
413 |
Warning: That file was not part of the compilation database. It may have many parsing errors.