49 #include "qcolormap.h" |
49 #include "qcolormap.h" |
50 #include <QDebug> |
50 #include <QDebug> |
51 |
51 |
52 |
52 |
53 QT_BEGIN_NAMESPACE |
53 QT_BEGIN_NAMESPACE |
|
54 |
|
55 |
|
56 bool qt_egl_setup_x11_visual(XVisualInfo &vi, EGLDisplay display, EGLConfig config, |
|
57 const QX11Info &x11Info, bool useArgbVisual); |
|
58 |
|
59 /* |
|
60 QGLTemporaryContext implementation |
|
61 */ |
|
62 |
|
63 class QGLTemporaryContextPrivate |
|
64 { |
|
65 public: |
|
66 bool initialized; |
|
67 Window window; |
|
68 EGLContext context; |
|
69 EGLSurface surface; |
|
70 EGLDisplay display; |
|
71 }; |
|
72 |
|
73 QGLTemporaryContext::QGLTemporaryContext(bool, QWidget *) |
|
74 : d(new QGLTemporaryContextPrivate) |
|
75 { |
|
76 d->initialized = false; |
|
77 d->window = 0; |
|
78 d->context = 0; |
|
79 d->surface = 0; |
|
80 int screen = 0; |
|
81 |
|
82 d->display = eglGetDisplay(EGLNativeDisplayType(X11->display)); |
|
83 |
|
84 if (!eglInitialize(d->display, NULL, NULL)) { |
|
85 qWarning("QGLTemporaryContext: Unable to initialize EGL display."); |
|
86 return; |
|
87 } |
|
88 |
|
89 EGLConfig config; |
|
90 int numConfigs = 0; |
|
91 EGLint attribs[] = { |
|
92 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
|
93 #ifdef QT_OPENGL_ES_2 |
|
94 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
|
95 #endif |
|
96 EGL_NONE |
|
97 }; |
|
98 |
|
99 eglChooseConfig(d->display, attribs, &config, 1, &numConfigs); |
|
100 if (!numConfigs) { |
|
101 qWarning("QGLTemporaryContext: No EGL configurations available."); |
|
102 return; |
|
103 } |
|
104 |
|
105 XVisualInfo visualInfo; |
|
106 XVisualInfo *vi; |
|
107 int numVisuals; |
|
108 EGLint id = 0; |
|
109 |
|
110 eglGetConfigAttrib(d->display, config, EGL_NATIVE_VISUAL_ID, &id); |
|
111 if (id == 0) { |
|
112 // EGL_NATIVE_VISUAL_ID is optional and might not be supported |
|
113 // on some implementations - we'll have to do it the hard way |
|
114 QX11Info xinfo; |
|
115 qt_egl_setup_x11_visual(visualInfo, d->display, config, xinfo, false); |
|
116 } else { |
|
117 visualInfo.visualid = id; |
|
118 } |
|
119 vi = XGetVisualInfo(X11->display, VisualIDMask, &visualInfo, &numVisuals); |
|
120 if (!vi || numVisuals < 1) { |
|
121 qWarning("QGLTemporaryContext: Unable to get X11 visual info id."); |
|
122 return; |
|
123 } |
|
124 |
|
125 d->window = XCreateWindow(X11->display, RootWindow(X11->display, screen), |
|
126 0, 0, 1, 1, 0, |
|
127 vi->depth, InputOutput, vi->visual, |
|
128 0, 0); |
|
129 |
|
130 d->surface = eglCreateWindowSurface(d->display, config, (EGLNativeWindowType) d->window, NULL); |
|
131 |
|
132 if (d->surface == EGL_NO_SURFACE) { |
|
133 qWarning("QGLTemporaryContext: Error creating EGL surface."); |
|
134 XFree(vi); |
|
135 XDestroyWindow(X11->display, d->window); |
|
136 return; |
|
137 } |
|
138 |
|
139 EGLint contextAttribs[] = { |
|
140 #ifdef QT_OPENGL_ES_2 |
|
141 EGL_CONTEXT_CLIENT_VERSION, 2, |
|
142 #endif |
|
143 EGL_NONE |
|
144 }; |
|
145 d->context = eglCreateContext(d->display, config, 0, contextAttribs); |
|
146 if (d->context != EGL_NO_CONTEXT |
|
147 && eglMakeCurrent(d->display, d->surface, d->surface, d->context)) |
|
148 { |
|
149 d->initialized = true; |
|
150 } else { |
|
151 qWarning("QGLTemporaryContext: Error creating EGL context."); |
|
152 eglDestroySurface(d->display, d->surface); |
|
153 XDestroyWindow(X11->display, d->window); |
|
154 } |
|
155 XFree(vi); |
|
156 } |
|
157 |
|
158 QGLTemporaryContext::~QGLTemporaryContext() |
|
159 { |
|
160 if (d->initialized) { |
|
161 eglMakeCurrent(d->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
|
162 eglDestroyContext(d->display, d->context); |
|
163 eglDestroySurface(d->display, d->surface); |
|
164 XDestroyWindow(X11->display, d->window); |
|
165 } |
|
166 } |
54 |
167 |
55 bool QGLFormat::hasOpenGLOverlays() |
168 bool QGLFormat::hasOpenGLOverlays() |
56 { |
169 { |
57 return false; |
170 return false; |
58 } |
171 } |
237 } |
350 } |
238 } |
351 } |
239 |
352 |
240 // If EGL does not know the visual ID, so try to select an appropriate one ourselves, first |
353 // If EGL does not know the visual ID, so try to select an appropriate one ourselves, first |
241 // using XRender if we're supposed to have an alpha, then falling back to XGetVisualInfo |
354 // using XRender if we're supposed to have an alpha, then falling back to XGetVisualInfo |
242 |
355 |
243 #if !defined(QT_NO_XRENDER) |
356 #if !defined(QT_NO_XRENDER) |
244 if (vi.visualid == 0 && useArgbVisual) { |
357 if (vi.visualid == 0 && useArgbVisual) { |
245 // Try to use XRender to find an ARGB visual we can use |
358 // Try to use XRender to find an ARGB visual we can use |
246 vi.screen = x11Info.screen(); |
359 vi.screen = x11Info.screen(); |
247 vi.depth = 32; //### We might at some point (soon) get ARGB4444 |
360 vi.depth = 32; //### We might at some point (soon) get ARGB4444 |