author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 12:15:23 +0300 | |
branch | RCL_3 |
changeset 12 | cc75c76972ee |
parent 7 | 3f74d0d4af4c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtOpenGL module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
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 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qgl.h" |
|
43 |
#include <private/qt_x11_p.h> |
|
44 |
#include <private/qpixmap_x11_p.h> |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
45 |
#include <private/qimagepixmapcleanuphooks_p.h> |
0 | 46 |
#include <private/qgl_p.h> |
47 |
#include <private/qpaintengine_opengl_p.h> |
|
48 |
#include "qgl_egl_p.h" |
|
49 |
#include "qcolormap.h" |
|
50 |
#include <QDebug> |
|
51 |
||
52 |
||
53 |
QT_BEGIN_NAMESPACE |
|
54 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
55 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
56 |
bool qt_egl_setup_x11_visual(XVisualInfo &vi, EGLDisplay display, EGLConfig config, |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
57 |
const QX11Info &x11Info, bool useArgbVisual); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
58 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
59 |
/* |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
60 |
QGLTemporaryContext implementation |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
61 |
*/ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
62 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
63 |
class QGLTemporaryContextPrivate |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
64 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
65 |
public: |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
66 |
bool initialized; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
67 |
Window window; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
68 |
EGLContext context; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
69 |
EGLSurface surface; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
70 |
EGLDisplay display; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
71 |
}; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
72 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
73 |
QGLTemporaryContext::QGLTemporaryContext(bool, QWidget *) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
74 |
: d(new QGLTemporaryContextPrivate) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
75 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
76 |
d->initialized = false; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
77 |
d->window = 0; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
78 |
d->context = 0; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
79 |
d->surface = 0; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
80 |
int screen = 0; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
81 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
82 |
d->display = eglGetDisplay(EGLNativeDisplayType(X11->display)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
83 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
84 |
if (!eglInitialize(d->display, NULL, NULL)) { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
85 |
qWarning("QGLTemporaryContext: Unable to initialize EGL display."); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
86 |
return; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
87 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
88 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
89 |
EGLConfig config; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
90 |
int numConfigs = 0; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
91 |
EGLint attribs[] = { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
92 |
EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
93 |
#ifdef QT_OPENGL_ES_2 |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
94 |
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
95 |
#endif |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
96 |
EGL_NONE |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
97 |
}; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
98 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
99 |
eglChooseConfig(d->display, attribs, &config, 1, &numConfigs); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
100 |
if (!numConfigs) { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
101 |
qWarning("QGLTemporaryContext: No EGL configurations available."); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
102 |
return; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
103 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
104 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
105 |
XVisualInfo visualInfo; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
106 |
XVisualInfo *vi; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
107 |
int numVisuals; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
108 |
EGLint id = 0; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
109 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
110 |
eglGetConfigAttrib(d->display, config, EGL_NATIVE_VISUAL_ID, &id); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
111 |
if (id == 0) { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
112 |
// EGL_NATIVE_VISUAL_ID is optional and might not be supported |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
113 |
// on some implementations - we'll have to do it the hard way |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
114 |
QX11Info xinfo; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
115 |
qt_egl_setup_x11_visual(visualInfo, d->display, config, xinfo, false); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
116 |
} else { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
117 |
visualInfo.visualid = id; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
118 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
119 |
vi = XGetVisualInfo(X11->display, VisualIDMask, &visualInfo, &numVisuals); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
120 |
if (!vi || numVisuals < 1) { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
121 |
qWarning("QGLTemporaryContext: Unable to get X11 visual info id."); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
122 |
return; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
123 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
124 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
125 |
d->window = XCreateWindow(X11->display, RootWindow(X11->display, screen), |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
126 |
0, 0, 1, 1, 0, |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
127 |
vi->depth, InputOutput, vi->visual, |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
128 |
0, 0); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
129 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
130 |
d->surface = eglCreateWindowSurface(d->display, config, (EGLNativeWindowType) d->window, NULL); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
131 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
132 |
if (d->surface == EGL_NO_SURFACE) { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
133 |
qWarning("QGLTemporaryContext: Error creating EGL surface."); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
134 |
XFree(vi); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
135 |
XDestroyWindow(X11->display, d->window); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
136 |
return; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
137 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
138 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
139 |
EGLint contextAttribs[] = { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
140 |
#ifdef QT_OPENGL_ES_2 |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
141 |
EGL_CONTEXT_CLIENT_VERSION, 2, |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
142 |
#endif |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
143 |
EGL_NONE |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
144 |
}; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
145 |
d->context = eglCreateContext(d->display, config, 0, contextAttribs); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
146 |
if (d->context != EGL_NO_CONTEXT |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
147 |
&& eglMakeCurrent(d->display, d->surface, d->surface, d->context)) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
148 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
149 |
d->initialized = true; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
150 |
} else { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
151 |
qWarning("QGLTemporaryContext: Error creating EGL context."); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
152 |
eglDestroySurface(d->display, d->surface); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
153 |
XDestroyWindow(X11->display, d->window); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
154 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
155 |
XFree(vi); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
156 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
157 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
158 |
QGLTemporaryContext::~QGLTemporaryContext() |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
159 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
160 |
if (d->initialized) { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
161 |
eglMakeCurrent(d->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
162 |
eglDestroyContext(d->display, d->context); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
163 |
eglDestroySurface(d->display, d->surface); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
164 |
XDestroyWindow(X11->display, d->window); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
165 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
166 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
167 |
|
0 | 168 |
bool QGLFormat::hasOpenGLOverlays() |
169 |
{ |
|
170 |
return false; |
|
171 |
} |
|
172 |
||
173 |
void qt_egl_add_platform_config(QEglProperties& props, QPaintDevice *device) |
|
174 |
{ |
|
175 |
if (device->devType() == QInternal::Image) |
|
176 |
props.setPixelFormat(static_cast<QImage *>(device)->format()); |
|
177 |
} |
|
178 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
179 |
// Chooses the EGL config and creates the EGL context |
0 | 180 |
bool QGLContext::chooseContext(const QGLContext* shareContext) |
181 |
{ |
|
182 |
Q_D(QGLContext); |
|
183 |
||
184 |
if (!device()) |
|
185 |
return false; |
|
186 |
||
187 |
int devType = device()->devType(); |
|
188 |
||
189 |
// Get the display and initialize it. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
190 |
if (d->eglContext == 0) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
191 |
d->eglContext = new QEglContext(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
192 |
d->eglContext->setApi(QEgl::OpenGL); |
0 | 193 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
194 |
// Construct the configuration we need for this surface. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
195 |
QEglProperties configProps; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
196 |
qt_egl_set_format(configProps, devType, d->glFormat); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
197 |
qt_egl_add_platform_config(configProps, device()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
198 |
configProps.setRenderableType(QEgl::OpenGL); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
199 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
200 |
#if We_have_an_EGL_library_which_bothers_to_check_EGL_BUFFER_SIZE |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
201 |
if (device()->depth() == 16 && configProps.value(EGL_ALPHA_SIZE) <= 0) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
202 |
qDebug("Setting EGL_BUFFER_SIZE to 16"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
203 |
configProps.setValue(EGL_BUFFER_SIZE, 16); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
204 |
configProps.setValue(EGL_ALPHA_SIZE, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
205 |
} |
0 | 206 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
207 |
if (!d->eglContext->chooseConfig(configProps, QEgl::BestPixelFormat)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
208 |
delete d->eglContext; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
209 |
d->eglContext = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
210 |
return false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
211 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
212 |
#else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
213 |
QEgl::PixelFormatMatch matchType = QEgl::BestPixelFormat; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
214 |
if ((device()->depth() == 16) && configProps.value(EGL_ALPHA_SIZE) == 0) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
215 |
configProps.setValue(EGL_RED_SIZE, 5); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
216 |
configProps.setValue(EGL_GREEN_SIZE, 6); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
217 |
configProps.setValue(EGL_BLUE_SIZE, 5); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
218 |
configProps.setValue(EGL_ALPHA_SIZE, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
219 |
matchType = QEgl::ExactPixelFormat; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
220 |
} |
0 | 221 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
222 |
// Search for a matching configuration, reducing the complexity |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
223 |
// each time until we get something that matches. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
224 |
if (!d->eglContext->chooseConfig(configProps, matchType)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
225 |
delete d->eglContext; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
226 |
d->eglContext = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
227 |
return false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
228 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
229 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
230 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
231 |
// qDebug("QGLContext::chooseContext() - using EGL config %d:", d->eglContext->config()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
232 |
// qDebug() << QEglProperties(d->eglContext->config()).toString(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
233 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
234 |
// Create a new context for the configuration. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
235 |
if (!d->eglContext->createContext |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
236 |
(shareContext ? shareContext->d_func()->eglContext : 0)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
237 |
delete d->eglContext; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
238 |
d->eglContext = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
239 |
return false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
240 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
241 |
d->sharing = d->eglContext->isSharing(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
242 |
if (d->sharing && shareContext) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
243 |
const_cast<QGLContext *>(shareContext)->d_func()->sharing = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
244 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
245 |
#if defined(EGL_VERSION_1_1) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
246 |
if (d->glFormat.swapInterval() != -1 && devType == QInternal::Widget) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
247 |
eglSwapInterval(d->eglContext->display(), d->glFormat.swapInterval()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
248 |
#endif |
0 | 249 |
} |
250 |
||
251 |
// Inform the higher layers about the actual format properties. |
|
252 |
qt_egl_update_format(*(d->eglContext), d->glFormat); |
|
253 |
||
254 |
return true; |
|
255 |
} |
|
256 |
||
257 |
void QGLWidget::resizeEvent(QResizeEvent *) |
|
258 |
{ |
|
259 |
Q_D(QGLWidget); |
|
260 |
if (!isValid()) |
|
261 |
return; |
|
262 |
makeCurrent(); |
|
263 |
if (!d->glcx->initialized()) |
|
264 |
glInit(); |
|
265 |
resizeGL(width(), height()); |
|
266 |
//handle overlay |
|
267 |
} |
|
268 |
||
269 |
const QGLContext* QGLWidget::overlayContext() const |
|
270 |
{ |
|
271 |
return 0; |
|
272 |
} |
|
273 |
||
274 |
void QGLWidget::makeOverlayCurrent() |
|
275 |
{ |
|
276 |
//handle overlay |
|
277 |
} |
|
278 |
||
279 |
void QGLWidget::updateOverlayGL() |
|
280 |
{ |
|
281 |
//handle overlay |
|
282 |
} |
|
283 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
284 |
//#define QT_DEBUG_X11_VISUAL_SELECTION 1 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
285 |
|
0 | 286 |
bool qt_egl_setup_x11_visual(XVisualInfo &vi, EGLDisplay display, EGLConfig config, const QX11Info &x11Info, bool useArgbVisual) |
287 |
{ |
|
288 |
bool foundVisualIsArgb = useArgbVisual; |
|
289 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
290 |
#ifdef QT_DEBUG_X11_VISUAL_SELECTION |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
291 |
qDebug("qt_egl_setup_x11_visual() - useArgbVisual=%d", useArgbVisual); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
292 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
293 |
|
0 | 294 |
memset(&vi, 0, sizeof(XVisualInfo)); |
295 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
296 |
EGLint eglConfigColorSize; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
297 |
eglGetConfigAttrib(display, config, EGL_BUFFER_SIZE, &eglConfigColorSize); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
298 |
|
0 | 299 |
// Check to see if EGL is suggesting an appropriate visual id: |
300 |
EGLint nativeVisualId; |
|
301 |
eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &nativeVisualId); |
|
302 |
vi.visualid = nativeVisualId; |
|
303 |
||
304 |
if (vi.visualid) { |
|
305 |
// EGL has suggested a visual id, so get the rest of the visual info for that id: |
|
306 |
XVisualInfo *chosenVisualInfo; |
|
307 |
int matchingCount = 0; |
|
308 |
chosenVisualInfo = XGetVisualInfo(x11Info.display(), VisualIDMask, &vi, &matchingCount); |
|
309 |
if (chosenVisualInfo) { |
|
310 |
#if !defined(QT_NO_XRENDER) |
|
311 |
if (useArgbVisual) { |
|
312 |
// Check to make sure the visual provided by EGL is ARGB |
|
313 |
XRenderPictFormat *format; |
|
314 |
format = XRenderFindVisualFormat(x11Info.display(), chosenVisualInfo->visual); |
|
315 |
if (format->type == PictTypeDirect && format->direct.alphaMask) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
316 |
#ifdef QT_DEBUG_X11_VISUAL_SELECTION |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
317 |
qDebug("Using ARGB X Visual ID (%d) provided by EGL", (int)vi.visualid); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
318 |
#endif |
0 | 319 |
foundVisualIsArgb = true; |
320 |
vi = *chosenVisualInfo; |
|
321 |
} |
|
322 |
else { |
|
323 |
qWarning("Warning: EGL suggested using X visual ID %d for config %d, but this is not ARGB", |
|
324 |
nativeVisualId, (int)config); |
|
325 |
vi.visualid = 0; |
|
326 |
} |
|
327 |
} else |
|
328 |
#endif |
|
329 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
330 |
if (eglConfigColorSize == chosenVisualInfo->depth) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
331 |
#ifdef QT_DEBUG_X11_VISUAL_SELECTION |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
332 |
qDebug("Using opaque X Visual ID (%d) provided by EGL", (int)vi.visualid); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
333 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
334 |
vi = *chosenVisualInfo; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
335 |
} else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
336 |
qWarning("Warning: EGL suggested using X visual ID %d (%d bpp) for config %d (%d bpp), but the depths do not match!", |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
337 |
nativeVisualId, chosenVisualInfo->depth, (int)config, eglConfigColorSize); |
0 | 338 |
} |
339 |
XFree(chosenVisualInfo); |
|
340 |
} |
|
341 |
else { |
|
342 |
qWarning("Warning: EGL suggested using X visual ID %d for config %d, but this seems to be invalid!", |
|
343 |
nativeVisualId, (int)config); |
|
344 |
vi.visualid = 0; |
|
345 |
} |
|
346 |
} |
|
347 |
||
348 |
// If EGL does not know the visual ID, so try to select an appropriate one ourselves, first |
|
349 |
// using XRender if we're supposed to have an alpha, then falling back to XGetVisualInfo |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
350 |
|
0 | 351 |
#if !defined(QT_NO_XRENDER) |
352 |
if (vi.visualid == 0 && useArgbVisual) { |
|
353 |
// Try to use XRender to find an ARGB visual we can use |
|
354 |
vi.screen = x11Info.screen(); |
|
355 |
vi.depth = 32; //### We might at some point (soon) get ARGB4444 |
|
356 |
vi.c_class = TrueColor; |
|
357 |
XVisualInfo *matchingVisuals; |
|
358 |
int matchingCount = 0; |
|
359 |
matchingVisuals = XGetVisualInfo(x11Info.display(), |
|
360 |
VisualScreenMask|VisualDepthMask|VisualClassMask, |
|
361 |
&vi, &matchingCount); |
|
362 |
||
363 |
for (int i = 0; i < matchingCount; ++i) { |
|
364 |
XRenderPictFormat *format; |
|
365 |
format = XRenderFindVisualFormat(x11Info.display(), matchingVisuals[i].visual); |
|
366 |
if (format->type == PictTypeDirect && format->direct.alphaMask) { |
|
367 |
vi = matchingVisuals[i]; |
|
368 |
foundVisualIsArgb = true; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
369 |
#ifdef QT_DEBUG_X11_VISUAL_SELECTION |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
370 |
qDebug("Using X Visual ID (%d) for ARGB visual as provided by XRender", (int)vi.visualid); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
371 |
#endif |
0 | 372 |
break; |
373 |
} |
|
374 |
} |
|
375 |
XFree(matchingVisuals); |
|
376 |
} |
|
377 |
#endif |
|
378 |
||
379 |
if (vi.visualid == 0) { |
|
380 |
EGLint depth; |
|
381 |
eglGetConfigAttrib(display, config, EGL_BUFFER_SIZE, &depth); |
|
382 |
int err; |
|
383 |
err = XMatchVisualInfo(x11Info.display(), x11Info.screen(), depth, TrueColor, &vi); |
|
384 |
if (err == 0) { |
|
385 |
qWarning("Warning: Can't find an X visual which matches the EGL config(%d)'s depth (%d)!", |
|
386 |
(int)config, depth); |
|
387 |
depth = x11Info.depth(); |
|
388 |
err = XMatchVisualInfo(x11Info.display(), x11Info.screen(), depth, TrueColor, &vi); |
|
389 |
if (err == 0) { |
|
390 |
qWarning("Error: Couldn't get any matching X visual!"); |
|
391 |
return false; |
|
392 |
} else |
|
393 |
qWarning(" - Falling back to X11 suggested depth (%d)", depth); |
|
394 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
395 |
#ifdef QT_DEBUG_X11_VISUAL_SELECTION |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
396 |
else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
397 |
qDebug("Using X Visual ID (%d) for EGL provided depth (%d)", (int)vi.visualid, depth); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
398 |
#endif |
0 | 399 |
|
400 |
// Don't try to use ARGB now unless the visual is 32-bit - even then it might stil fail :-( |
|
401 |
if (useArgbVisual) |
|
402 |
foundVisualIsArgb = vi.depth == 32; //### We might at some point (soon) get ARGB4444 |
|
403 |
} |
|
404 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
405 |
#ifdef QT_DEBUG_X11_VISUAL_SELECTION |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
406 |
qDebug("Visual Info:"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
407 |
qDebug(" bits_per_rgb=%d", vi.bits_per_rgb); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
408 |
qDebug(" red_mask=0x%x", vi.red_mask); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
409 |
qDebug(" green_mask=0x%x", vi.green_mask); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
410 |
qDebug(" blue_mask=0x%x", vi.blue_mask); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
411 |
qDebug(" colormap_size=%d", vi.colormap_size); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
412 |
qDebug(" c_class=%d", vi.c_class); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
413 |
qDebug(" depth=%d", vi.depth); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
414 |
qDebug(" screen=%d", vi.screen); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
415 |
qDebug(" visualid=%d", vi.visualid); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
416 |
#endif |
0 | 417 |
return foundVisualIsArgb; |
418 |
} |
|
419 |
||
420 |
void QGLWidget::setContext(QGLContext *context, const QGLContext* shareContext, bool deleteOldContext) |
|
421 |
{ |
|
422 |
Q_D(QGLWidget); |
|
423 |
if (context == 0) { |
|
424 |
qWarning("QGLWidget::setContext: Cannot set null context"); |
|
425 |
return; |
|
426 |
} |
|
427 |
if (!context->deviceIsPixmap() && context->device() != this) { |
|
428 |
qWarning("QGLWidget::setContext: Context must refer to this widget"); |
|
429 |
return; |
|
430 |
} |
|
431 |
||
432 |
if (d->glcx) |
|
433 |
d->glcx->doneCurrent(); |
|
434 |
QGLContext* oldcx = d->glcx; |
|
435 |
d->glcx = context; |
|
436 |
||
437 |
if (parentWidget()) { |
|
438 |
// force creation of delay-created widgets |
|
439 |
parentWidget()->winId(); |
|
440 |
if (parentWidget()->x11Info().screen() != x11Info().screen()) |
|
441 |
d_func()->xinfo = parentWidget()->d_func()->xinfo; |
|
442 |
} |
|
443 |
||
444 |
// If the application has set WA_TranslucentBackground and not explicitly set |
|
445 |
// the alpha buffer size to zero, modify the format so it have an alpha channel |
|
446 |
QGLFormat& fmt = d->glcx->d_func()->glFormat; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
447 |
const bool tryArgbVisual = testAttribute(Qt::WA_TranslucentBackground) || fmt.alpha(); |
0 | 448 |
if (tryArgbVisual && fmt.alphaBufferSize() == -1) |
449 |
fmt.setAlphaBufferSize(1); |
|
450 |
||
451 |
bool createFailed = false; |
|
452 |
if (!d->glcx->isValid()) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
453 |
// Create the QGLContext here, which in turn chooses the EGL config |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
454 |
// and creates the EGL context: |
0 | 455 |
if (!d->glcx->create(shareContext ? shareContext : oldcx)) |
456 |
createFailed = true; |
|
457 |
} |
|
458 |
if (createFailed) { |
|
459 |
if (deleteOldContext) |
|
460 |
delete oldcx; |
|
461 |
return; |
|
462 |
} |
|
463 |
||
464 |
if (d->glcx->windowCreated() || d->glcx->deviceIsPixmap()) { |
|
465 |
if (deleteOldContext) |
|
466 |
delete oldcx; |
|
467 |
return; |
|
468 |
} |
|
469 |
||
470 |
bool visible = isVisible(); |
|
471 |
if (visible) |
|
472 |
hide(); |
|
473 |
||
474 |
XVisualInfo vi; |
|
475 |
QEglContext *eglContext = d->glcx->d_func()->eglContext; |
|
476 |
bool usingArgbVisual = qt_egl_setup_x11_visual(vi, eglContext->display(), eglContext->config(), |
|
477 |
x11Info(), tryArgbVisual); |
|
478 |
||
479 |
XSetWindowAttributes a; |
|
480 |
||
481 |
Window p = RootWindow(x11Info().display(), x11Info().screen()); |
|
482 |
if (parentWidget()) |
|
483 |
p = parentWidget()->winId(); |
|
484 |
||
485 |
QColormap colmap = QColormap::instance(vi.screen); |
|
486 |
a.background_pixel = colmap.pixel(palette().color(backgroundRole())); |
|
487 |
a.border_pixel = colmap.pixel(Qt::black); |
|
488 |
||
489 |
unsigned int valueMask = CWBackPixel|CWBorderPixel; |
|
490 |
if (usingArgbVisual) { |
|
491 |
a.colormap = XCreateColormap(x11Info().display(), p, vi.visual, AllocNone); |
|
492 |
valueMask |= CWColormap; |
|
493 |
} |
|
494 |
||
495 |
Window w = XCreateWindow(x11Info().display(), p, x(), y(), width(), height(), |
|
496 |
0, vi.depth, InputOutput, vi.visual, valueMask, &a); |
|
497 |
||
498 |
if (deleteOldContext) |
|
499 |
delete oldcx; |
|
500 |
oldcx = 0; |
|
501 |
||
502 |
create(w); // Create with the ID of the window we've just created |
|
503 |
||
504 |
||
505 |
// Create the EGL surface to draw into. |
|
506 |
QGLContextPrivate *ctxpriv = d->glcx->d_func(); |
|
507 |
ctxpriv->eglSurface = ctxpriv->eglContext->createSurface(this); |
|
508 |
if (ctxpriv->eglSurface == EGL_NO_SURFACE) { |
|
509 |
delete ctxpriv->eglContext; |
|
510 |
ctxpriv->eglContext = 0; |
|
511 |
return; |
|
512 |
} |
|
513 |
||
514 |
d->eglSurfaceWindowId = w; // Remember the window id we created the surface for |
|
515 |
||
516 |
if (visible) |
|
517 |
show(); |
|
518 |
||
519 |
XFlush(X11->display); |
|
520 |
d->glcx->setWindowCreated(true); |
|
521 |
} |
|
522 |
||
523 |
void QGLWidgetPrivate::init(QGLContext *context, const QGLWidget* shareWidget) |
|
524 |
{ |
|
525 |
Q_Q(QGLWidget); |
|
526 |
||
527 |
initContext(context, shareWidget); |
|
528 |
||
529 |
if(q->isValid() && glcx->format().hasOverlay()) { |
|
530 |
//no overlay |
|
531 |
qWarning("QtOpenGL ES doesn't currently support overlays"); |
|
532 |
} |
|
533 |
} |
|
534 |
||
535 |
void QGLWidgetPrivate::cleanupColormaps() |
|
536 |
{ |
|
537 |
} |
|
538 |
||
539 |
const QGLColormap & QGLWidget::colormap() const |
|
540 |
{ |
|
541 |
return d_func()->cmap; |
|
542 |
} |
|
543 |
||
544 |
void QGLWidget::setColormap(const QGLColormap &) |
|
545 |
{ |
|
546 |
} |
|
547 |
||
548 |
// Re-creates the EGL surface if the window ID has changed or if force is true |
|
549 |
void QGLWidgetPrivate::recreateEglSurface(bool force) |
|
550 |
{ |
|
551 |
Q_Q(QGLWidget); |
|
552 |
||
553 |
Window currentId = q->winId(); |
|
554 |
||
555 |
if ( force || (currentId != eglSurfaceWindowId) ) { |
|
556 |
// The window id has changed so we need to re-create the EGL surface |
|
557 |
QEglContext *ctx = glcx->d_func()->eglContext; |
|
558 |
EGLSurface surface = glcx->d_func()->eglSurface; |
|
559 |
if (surface != EGL_NO_SURFACE) |
|
560 |
ctx->destroySurface(surface); // Will force doneCurrent() if nec. |
|
561 |
surface = ctx->createSurface(q); |
|
562 |
if (surface == EGL_NO_SURFACE) |
|
563 |
qWarning("Error creating EGL window surface: 0x%x", eglGetError()); |
|
564 |
glcx->d_func()->eglSurface = surface; |
|
565 |
||
566 |
eglSurfaceWindowId = currentId; |
|
567 |
} |
|
568 |
} |
|
569 |
||
570 |
// Selects which configs should be used |
|
571 |
EGLConfig Q_OPENGL_EXPORT qt_chooseEGLConfigForPixmap(bool hasAlpha, bool readOnly) |
|
572 |
{ |
|
573 |
// Cache the configs we select as they wont change: |
|
574 |
static EGLConfig roPixmapRGBConfig = 0; |
|
575 |
static EGLConfig roPixmapRGBAConfig = 0; |
|
576 |
static EGLConfig rwPixmapRGBConfig = 0; |
|
577 |
static EGLConfig rwPixmapRGBAConfig = 0; |
|
578 |
||
579 |
EGLConfig* targetConfig; |
|
580 |
||
581 |
if (hasAlpha) { |
|
582 |
if (readOnly) |
|
583 |
targetConfig = &roPixmapRGBAConfig; |
|
584 |
else |
|
585 |
targetConfig = &rwPixmapRGBAConfig; |
|
586 |
} |
|
587 |
else { |
|
588 |
if (readOnly) |
|
589 |
targetConfig = &roPixmapRGBConfig; |
|
590 |
else |
|
591 |
targetConfig = &rwPixmapRGBConfig; |
|
592 |
} |
|
593 |
||
594 |
if (*targetConfig == 0) { |
|
595 |
QEglProperties configAttribs; |
|
596 |
configAttribs.setValue(EGL_SURFACE_TYPE, EGL_PIXMAP_BIT); |
|
597 |
configAttribs.setRenderableType(QEgl::OpenGL); |
|
598 |
if (hasAlpha) |
|
599 |
configAttribs.setValue(EGL_BIND_TO_TEXTURE_RGBA, EGL_TRUE); |
|
600 |
else |
|
601 |
configAttribs.setValue(EGL_BIND_TO_TEXTURE_RGB, EGL_TRUE); |
|
602 |
||
603 |
// If this is going to be a render target, it needs to have a depth, stencil & sample buffer |
|
604 |
if (!readOnly) { |
|
605 |
configAttribs.setValue(EGL_DEPTH_SIZE, 1); |
|
606 |
configAttribs.setValue(EGL_STENCIL_SIZE, 1); |
|
607 |
configAttribs.setValue(EGL_SAMPLE_BUFFERS, 1); |
|
608 |
} |
|
609 |
||
610 |
EGLint configCount = 0; |
|
611 |
do { |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
612 |
eglChooseConfig(QEglContext::display(), configAttribs.properties(), targetConfig, 1, &configCount); |
0 | 613 |
if (configCount > 0) { |
614 |
// Got one |
|
615 |
qDebug() << "Found an" << (hasAlpha ? "ARGB" : "RGB") << (readOnly ? "readonly" : "target" ) |
|
616 |
<< "config (" << int(*targetConfig) << ") to create a pixmap surface:"; |
|
617 |
||
618 |
// QEglProperties configProps(*targetConfig); |
|
619 |
// qDebug() << configProps.toString(); |
|
620 |
break; |
|
621 |
} |
|
622 |
qWarning("choosePixmapConfig() - No suitible config found, reducing requirements"); |
|
623 |
} while (configAttribs.reduceConfiguration()); |
|
624 |
} |
|
625 |
||
626 |
if (*targetConfig == 0) |
|
627 |
qWarning("choosePixmapConfig() - Couldn't find a suitable config"); |
|
628 |
||
629 |
return *targetConfig; |
|
630 |
} |
|
631 |
||
632 |
bool Q_OPENGL_EXPORT qt_createEGLSurfaceForPixmap(QPixmapData* pmd, bool readOnly) |
|
633 |
{ |
|
634 |
Q_ASSERT(pmd->classId() == QPixmapData::X11Class); |
|
635 |
QX11PixmapData* pixmapData = static_cast<QX11PixmapData*>(pmd); |
|
636 |
||
637 |
bool hasAlpha = pixmapData->hasAlphaChannel(); |
|
638 |
||
639 |
EGLConfig pixmapConfig = qt_chooseEGLConfigForPixmap(hasAlpha, readOnly); |
|
640 |
||
641 |
QEglProperties pixmapAttribs; |
|
642 |
||
643 |
// If the pixmap can't be bound to a texture, it's pretty useless |
|
644 |
pixmapAttribs.setValue(EGL_TEXTURE_TARGET, EGL_TEXTURE_2D); |
|
645 |
if (hasAlpha) |
|
646 |
pixmapAttribs.setValue(EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA); |
|
647 |
else |
|
648 |
pixmapAttribs.setValue(EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGB); |
|
649 |
||
650 |
EGLSurface pixmapSurface; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
651 |
pixmapSurface = eglCreatePixmapSurface(QEglContext::display(), |
0 | 652 |
pixmapConfig, |
653 |
(EGLNativePixmapType) pixmapData->handle(), |
|
654 |
pixmapAttribs.properties()); |
|
655 |
// qDebug("qt_createEGLSurfaceForPixmap() created surface 0x%x for pixmap 0x%x", |
|
656 |
// pixmapSurface, pixmapData->handle()); |
|
657 |
if (pixmapSurface == EGL_NO_SURFACE) { |
|
658 |
qWarning() << "Failed to create a pixmap surface using config" << (int)pixmapConfig |
|
659 |
<< ":" << QEglContext::errorString(eglGetError()); |
|
660 |
return false; |
|
661 |
} |
|
662 |
||
663 |
static bool doneOnce = false; |
|
664 |
if (!doneOnce) { |
|
665 |
// Make sure QGLTextureCache is instanciated so it can install cleanup hooks |
|
666 |
// which cleanup the EGL surface. |
|
667 |
QGLTextureCache::instance(); |
|
668 |
doneOnce = true; |
|
669 |
} |
|
670 |
||
671 |
Q_ASSERT(sizeof(Qt::HANDLE) >= sizeof(EGLSurface)); // Just to make totally sure! |
|
672 |
pixmapData->gl_surface = (Qt::HANDLE)pixmapSurface; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
673 |
QImagePixmapCleanupHooks::enableCleanupHooks(pixmapData); // Make sure the cleanup hook gets called |
0 | 674 |
|
675 |
return true; |
|
676 |
} |
|
677 |
||
678 |
||
679 |
QGLTexture *QGLContextPrivate::bindTextureFromNativePixmap(QPixmapData* pd, const qint64 key, |
|
680 |
QGLContext::BindOptions options) |
|
681 |
{ |
|
682 |
Q_Q(QGLContext); |
|
683 |
||
684 |
// The EGL texture_from_pixmap has no facility to invert the y coordinate |
|
685 |
if (!(options & QGLContext::CanFlipNativePixmapBindOption)) |
|
686 |
return 0; |
|
687 |
||
688 |
Q_ASSERT(pd->classId() == QPixmapData::X11Class); |
|
689 |
||
690 |
static bool checkedForTFP = false; |
|
691 |
static bool haveTFP = false; |
|
692 |
||
693 |
if (!checkedForTFP) { |
|
694 |
// Check for texture_from_pixmap egl extension |
|
695 |
checkedForTFP = true; |
|
696 |
if (eglContext->hasExtension("EGL_NOKIA_texture_from_pixmap") || |
|
697 |
eglContext->hasExtension("EGL_EXT_texture_from_pixmap")) |
|
698 |
{ |
|
699 |
qDebug("Found texture_from_pixmap EGL extension!"); |
|
700 |
haveTFP = true; |
|
701 |
} |
|
702 |
} |
|
703 |
||
704 |
if (!haveTFP) |
|
705 |
return 0; |
|
706 |
||
707 |
QX11PixmapData *pixmapData = static_cast<QX11PixmapData*>(pd); |
|
708 |
||
709 |
bool hasAlpha = pixmapData->hasAlphaChannel(); |
|
710 |
||
711 |
// Check to see if the surface is still valid |
|
712 |
if (pixmapData->gl_surface && |
|
713 |
hasAlpha != (pixmapData->flags & QX11PixmapData::GlSurfaceCreatedWithAlpha)) |
|
714 |
{ |
|
715 |
// Surface is invalid! |
|
716 |
destroyGlSurfaceForPixmap(pixmapData); |
|
717 |
} |
|
718 |
||
719 |
if (pixmapData->gl_surface == 0) { |
|
720 |
bool success = qt_createEGLSurfaceForPixmap(pixmapData, true); |
|
721 |
if (!success) { |
|
722 |
haveTFP = false; |
|
723 |
return 0; |
|
724 |
} |
|
725 |
} |
|
726 |
||
727 |
Q_ASSERT(pixmapData->gl_surface); |
|
728 |
||
729 |
GLuint textureId; |
|
730 |
glGenTextures(1, &textureId); |
|
731 |
glBindTexture(GL_TEXTURE_2D, textureId); |
|
732 |
||
733 |
// bind the egl pixmap surface to a texture |
|
734 |
EGLBoolean success; |
|
735 |
success = eglBindTexImage(eglContext->display(), (EGLSurface)pixmapData->gl_surface, EGL_BACK_BUFFER); |
|
736 |
if (success == EGL_FALSE) { |
|
737 |
qWarning() << "eglBindTexImage() failed:" << eglContext->errorString(eglGetError()); |
|
738 |
eglDestroySurface(eglContext->display(), (EGLSurface)pixmapData->gl_surface); |
|
739 |
pixmapData->gl_surface = (Qt::HANDLE)EGL_NO_SURFACE; |
|
740 |
haveTFP = false; |
|
741 |
return 0; |
|
742 |
} |
|
743 |
||
744 |
QGLTexture *texture = new QGLTexture(q, textureId, GL_TEXTURE_2D, options); |
|
745 |
pixmapData->flags |= QX11PixmapData::InvertedWhenBoundToTexture; |
|
746 |
||
747 |
// We assume the cost of bound pixmaps is zero |
|
748 |
QGLTextureCache::instance()->insert(q, key, texture, 0); |
|
749 |
||
750 |
glBindTexture(GL_TEXTURE_2D, textureId); |
|
751 |
return texture; |
|
752 |
} |
|
753 |
||
754 |
void QGLContextPrivate::destroyGlSurfaceForPixmap(QPixmapData* pmd) |
|
755 |
{ |
|
756 |
Q_ASSERT(pmd->classId() == QPixmapData::X11Class); |
|
757 |
QX11PixmapData *pixmapData = static_cast<QX11PixmapData*>(pmd); |
|
758 |
if (pixmapData->gl_surface) { |
|
759 |
EGLBoolean success; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
760 |
success = eglDestroySurface(QEglContext::display(), (EGLSurface)pixmapData->gl_surface); |
0 | 761 |
if (success == EGL_FALSE) { |
762 |
qWarning() << "destroyGlSurfaceForPixmap() - Error deleting surface: " |
|
763 |
<< QEglContext::errorString(eglGetError()); |
|
764 |
} |
|
765 |
pixmapData->gl_surface = 0; |
|
766 |
} |
|
767 |
} |
|
768 |
||
769 |
void QGLContextPrivate::unbindPixmapFromTexture(QPixmapData* pmd) |
|
770 |
{ |
|
771 |
Q_ASSERT(pmd->classId() == QPixmapData::X11Class); |
|
772 |
QX11PixmapData *pixmapData = static_cast<QX11PixmapData*>(pmd); |
|
773 |
if (pixmapData->gl_surface) { |
|
774 |
EGLBoolean success; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
775 |
success = eglReleaseTexImage(QEglContext::display(), |
0 | 776 |
(EGLSurface)pixmapData->gl_surface, |
777 |
EGL_BACK_BUFFER); |
|
778 |
if (success == EGL_FALSE) { |
|
779 |
qWarning() << "unbindPixmapFromTexture() - Unable to release bound texture: " |
|
780 |
<< QEglContext::errorString(eglGetError()); |
|
781 |
} |
|
782 |
} |
|
783 |
} |
|
784 |
||
785 |
QT_END_NAMESPACE |