41 |
41 |
42 #include <QtCore/qdebug.h> |
42 #include <QtCore/qdebug.h> |
43 #include <QtCore/qstringlist.h> |
43 #include <QtCore/qstringlist.h> |
44 |
44 |
45 #include "qeglproperties_p.h" |
45 #include "qeglproperties_p.h" |
|
46 #include "qeglcontext_p.h" |
46 |
47 |
47 QT_BEGIN_NAMESPACE |
48 QT_BEGIN_NAMESPACE |
48 |
|
49 #include "qegl_p.h" |
|
50 |
|
51 |
49 |
52 // Initialize a property block. |
50 // Initialize a property block. |
53 QEglProperties::QEglProperties() |
51 QEglProperties::QEglProperties() |
54 { |
52 { |
55 props.append(EGL_NONE); |
53 props.append(EGL_NONE); |
58 QEglProperties::QEglProperties(EGLConfig cfg) |
56 QEglProperties::QEglProperties(EGLConfig cfg) |
59 { |
57 { |
60 props.append(EGL_NONE); |
58 props.append(EGL_NONE); |
61 for (int name = 0x3020; name <= 0x304F; ++name) { |
59 for (int name = 0x3020; name <= 0x304F; ++name) { |
62 EGLint value; |
60 EGLint value; |
63 if (name != EGL_NONE && eglGetConfigAttrib(QEglContext::display(), cfg, name, &value)) |
61 if (name != EGL_NONE && eglGetConfigAttrib(QEgl::display(), cfg, name, &value)) |
64 setValue(name, value); |
62 setValue(name, value); |
65 } |
63 } |
66 eglGetError(); // Clear the error state. |
64 eglGetError(); // Clear the error state. |
67 } |
65 } |
68 |
66 |
80 case EGL_BUFFER_SIZE: return 0; |
78 case EGL_BUFFER_SIZE: return 0; |
81 case EGL_RED_SIZE: return 0; |
79 case EGL_RED_SIZE: return 0; |
82 case EGL_GREEN_SIZE: return 0; |
80 case EGL_GREEN_SIZE: return 0; |
83 case EGL_BLUE_SIZE: return 0; |
81 case EGL_BLUE_SIZE: return 0; |
84 case EGL_ALPHA_SIZE: return 0; |
82 case EGL_ALPHA_SIZE: return 0; |
85 #if defined(EGL_LUMINANCE_SIZE) |
83 #ifdef EGL_LUMINANCE_SIZE |
86 case EGL_LUMINANCE_SIZE: return 0; |
84 case EGL_LUMINANCE_SIZE: return 0; |
87 #endif |
85 #endif |
88 #if defined(EGL_ALPHA_MASK_SIZE) |
86 #ifdef EGL_ALPHA_MASK_SIZE |
89 case EGL_ALPHA_MASK_SIZE: return 0; |
87 case EGL_ALPHA_MASK_SIZE: return 0; |
90 #endif |
88 #endif |
91 #if defined(EGL_BIND_TO_TEXTURE_RGB) |
89 #ifdef EGL_BIND_TO_TEXTURE_RGB |
92 case EGL_BIND_TO_TEXTURE_RGB: return EGL_DONT_CARE; |
90 case EGL_BIND_TO_TEXTURE_RGB: return EGL_DONT_CARE; |
93 #endif |
91 #endif |
94 #if defined(EGL_BIND_TO_TEXTURE_RGBA) |
92 #ifdef EGL_BIND_TO_TEXTURE_RGBA |
95 case EGL_BIND_TO_TEXTURE_RGBA: return EGL_DONT_CARE; |
93 case EGL_BIND_TO_TEXTURE_RGBA: return EGL_DONT_CARE; |
96 #endif |
94 #endif |
97 #if defined(EGL_COLOR_BUFFER_TYPE) |
95 #ifdef EGL_COLOR_BUFFER_TYPE |
98 case EGL_COLOR_BUFFER_TYPE: return EGL_RGB_BUFFER; |
96 case EGL_COLOR_BUFFER_TYPE: return EGL_RGB_BUFFER; |
99 #endif |
97 #endif |
100 case EGL_CONFIG_CAVEAT: return EGL_DONT_CARE; |
98 case EGL_CONFIG_CAVEAT: return EGL_DONT_CARE; |
101 case EGL_CONFIG_ID: return EGL_DONT_CARE; |
99 case EGL_CONFIG_ID: return EGL_DONT_CARE; |
102 case EGL_DEPTH_SIZE: return 0; |
100 case EGL_DEPTH_SIZE: return 0; |
103 case EGL_LEVEL: return 0; |
101 case EGL_LEVEL: return 0; |
104 case EGL_NATIVE_RENDERABLE: return EGL_DONT_CARE; |
102 case EGL_NATIVE_RENDERABLE: return EGL_DONT_CARE; |
105 case EGL_NATIVE_VISUAL_TYPE: return EGL_DONT_CARE; |
103 case EGL_NATIVE_VISUAL_TYPE: return EGL_DONT_CARE; |
106 case EGL_MAX_SWAP_INTERVAL: return EGL_DONT_CARE; |
104 case EGL_MAX_SWAP_INTERVAL: return EGL_DONT_CARE; |
107 case EGL_MIN_SWAP_INTERVAL: return EGL_DONT_CARE; |
105 case EGL_MIN_SWAP_INTERVAL: return EGL_DONT_CARE; |
108 #if defined(EGL_RENDERABLE_TYPE) |
106 #ifdef EGL_RENDERABLE_TYPE |
109 case EGL_RENDERABLE_TYPE: return EGL_OPENGL_ES_BIT; |
107 case EGL_RENDERABLE_TYPE: return EGL_OPENGL_ES_BIT; |
110 #endif |
108 #endif |
111 case EGL_SAMPLE_BUFFERS: return 0; |
109 case EGL_SAMPLE_BUFFERS: return 0; |
112 case EGL_SAMPLES: return 0; |
110 case EGL_SAMPLES: return 0; |
113 case EGL_STENCIL_SIZE: return 0; |
111 case EGL_STENCIL_SIZE: return 0; |
115 case EGL_TRANSPARENT_TYPE: return EGL_NONE; |
113 case EGL_TRANSPARENT_TYPE: return EGL_NONE; |
116 case EGL_TRANSPARENT_RED_VALUE: return EGL_DONT_CARE; |
114 case EGL_TRANSPARENT_RED_VALUE: return EGL_DONT_CARE; |
117 case EGL_TRANSPARENT_GREEN_VALUE: return EGL_DONT_CARE; |
115 case EGL_TRANSPARENT_GREEN_VALUE: return EGL_DONT_CARE; |
118 case EGL_TRANSPARENT_BLUE_VALUE: return EGL_DONT_CARE; |
116 case EGL_TRANSPARENT_BLUE_VALUE: return EGL_DONT_CARE; |
119 |
117 |
120 #if defined(EGL_VERSION_1_3) |
118 #ifdef EGL_VERSION_1_3 |
121 case EGL_CONFORMANT: return 0; |
119 case EGL_CONFORMANT: return 0; |
122 case EGL_MATCH_NATIVE_PIXMAP: return EGL_NONE; |
120 case EGL_MATCH_NATIVE_PIXMAP: return EGL_NONE; |
123 #endif |
121 #endif |
124 |
122 |
125 case EGL_MAX_PBUFFER_HEIGHT: |
123 case EGL_MAX_PBUFFER_HEIGHT: |
163 return true; |
161 return true; |
164 } |
162 } |
165 } |
163 } |
166 return false; |
164 return false; |
167 } |
165 } |
|
166 |
|
167 void QEglProperties::setDeviceType(int devType) |
|
168 { |
|
169 if (devType == QInternal::Pixmap || devType == QInternal::Image) |
|
170 setValue(EGL_SURFACE_TYPE, EGL_PIXMAP_BIT); |
|
171 else if (devType == QInternal::Pbuffer) |
|
172 setValue(EGL_SURFACE_TYPE, EGL_PBUFFER_BIT); |
|
173 else |
|
174 setValue(EGL_SURFACE_TYPE, EGL_WINDOW_BIT); |
|
175 } |
|
176 |
168 |
177 |
169 // Sets the red, green, blue, and alpha sizes based on a pixel format. |
178 // Sets the red, green, blue, and alpha sizes based on a pixel format. |
170 // Normally used to match a configuration request to the screen format. |
179 // Normally used to match a configuration request to the screen format. |
171 void QEglProperties::setPixelFormat(QImage::Format pixelFormat) |
180 void QEglProperties::setPixelFormat(QImage::Format pixelFormat) |
172 { |
181 { |
204 setValue(EGL_ALPHA_SIZE, alpha); |
213 setValue(EGL_ALPHA_SIZE, alpha); |
205 } |
214 } |
206 |
215 |
207 void QEglProperties::setRenderableType(QEgl::API api) |
216 void QEglProperties::setRenderableType(QEgl::API api) |
208 { |
217 { |
209 #if defined(EGL_RENDERABLE_TYPE) |
218 #ifdef EGL_RENDERABLE_TYPE |
210 #if defined(QT_OPENGL_ES_2) |
219 #if defined(QT_OPENGL_ES_2) |
211 if (api == QEgl::OpenGL) |
220 if (api == QEgl::OpenGL) |
212 setValue(EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT); |
221 setValue(EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT); |
213 #elif defined(QT_OPENGL_ES) |
222 #elif defined(QT_OPENGL_ES) |
214 if (api == QEgl::OpenGL) |
223 if (api == QEgl::OpenGL) |
215 setValue(EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT); |
224 setValue(EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT); |
216 #endif |
225 #elif defined(EGL_OPENGL_BIT) |
217 #if defined(EGL_OPENVG_BIT) |
226 if (api == QEgl::OpenGL) |
|
227 setValue(EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT); |
|
228 #endif |
|
229 #ifdef EGL_OPENVG_BIT |
218 if (api == QEgl::OpenVG) |
230 if (api == QEgl::OpenVG) |
219 setValue(EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT); |
231 setValue(EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT); |
220 #endif |
232 #endif |
221 #else |
233 #else |
222 Q_UNUSED(api); |
234 Q_UNUSED(api); |
227 // because the previous request did not result in success. Returns |
239 // because the previous request did not result in success. Returns |
228 // true if the complexity was reduced, or false if no further |
240 // true if the complexity was reduced, or false if no further |
229 // reductions in complexity are possible. |
241 // reductions in complexity are possible. |
230 bool QEglProperties::reduceConfiguration() |
242 bool QEglProperties::reduceConfiguration() |
231 { |
243 { |
|
244 if (value(EGL_SWAP_BEHAVIOR) != EGL_DONT_CARE) |
|
245 removeValue(EGL_SWAP_BEHAVIOR); |
|
246 |
|
247 #ifdef EGL_VG_ALPHA_FORMAT_PRE_BIT |
|
248 // For OpenVG, we sometimes try to create a surface using a pre-multiplied format. If we can't |
|
249 // find a config which supports pre-multiplied formats, remove the flag on the surface type: |
|
250 EGLint surfaceType = value(EGL_SURFACE_TYPE); |
|
251 if (surfaceType & EGL_VG_ALPHA_FORMAT_PRE_BIT) { |
|
252 surfaceType ^= EGL_VG_ALPHA_FORMAT_PRE_BIT; |
|
253 setValue(EGL_SURFACE_TYPE, surfaceType); |
|
254 return true; |
|
255 } |
|
256 #endif |
232 // EGL chooses configs with the highest color depth over |
257 // EGL chooses configs with the highest color depth over |
233 // those with smaller (but faster) lower color depths. One |
258 // those with smaller (but faster) lower color depths. One |
234 // way around this is to set EGL_BUFFER_SIZE to 16, which |
259 // way around this is to set EGL_BUFFER_SIZE to 16, which |
235 // trumps the others. Of course, there may not be a 16-bit |
260 // trumps the others. Of course, there may not be a 16-bit |
236 // config avaliable, so it's the first restraint we remove. |
261 // config avaliable, so it's the first restraint we remove. |
266 if (lastnl == -1) |
291 if (lastnl == -1) |
267 lastnl = 0; |
292 lastnl = 0; |
268 if ((str.length() - lastnl) >= 50) |
293 if ((str.length() - lastnl) >= 50) |
269 str += QLatin1String("\n "); |
294 str += QLatin1String("\n "); |
270 str += tag; |
295 str += tag; |
271 } |
|
272 |
|
273 void QEglProperties::dumpAllConfigs() |
|
274 { |
|
275 EGLint count = 0; |
|
276 eglGetConfigs(QEglContext::display(), 0, 0, &count); |
|
277 if (count < 1) |
|
278 return; |
|
279 |
|
280 EGLConfig *configs = new EGLConfig [count]; |
|
281 eglGetConfigs(QEglContext::display(), configs, count, &count); |
|
282 for (EGLint index = 0; index < count; ++index) |
|
283 qWarning() << QEglProperties(configs[index]).toString(); |
|
284 delete [] configs; |
|
285 } |
296 } |
286 |
297 |
287 // Convert a property list to a string suitable for debug output. |
298 // Convert a property list to a string suitable for debug output. |
288 QString QEglProperties::toString() const |
299 QString QEglProperties::toString() const |
289 { |
300 { |
305 if ((val & EGL_OPENGL_ES_BIT) != 0) |
316 if ((val & EGL_OPENGL_ES_BIT) != 0) |
306 types += QLatin1String("es1"); |
317 types += QLatin1String("es1"); |
307 #ifdef EGL_OPENGL_ES2_BIT |
318 #ifdef EGL_OPENGL_ES2_BIT |
308 if ((val & EGL_OPENGL_ES2_BIT) != 0) |
319 if ((val & EGL_OPENGL_ES2_BIT) != 0) |
309 types += QLatin1String("es2"); |
320 types += QLatin1String("es2"); |
|
321 #endif |
|
322 #ifdef EGL_OPENGL_BIT |
|
323 if ((val & EGL_OPENGL_BIT) != 0) |
|
324 types += QLatin1String("gl"); |
310 #endif |
325 #endif |
311 if ((val & EGL_OPENVG_BIT) != 0) |
326 if ((val & EGL_OPENVG_BIT) != 0) |
312 types += QLatin1String("vg"); |
327 types += QLatin1String("vg"); |
313 if ((val & ~7) != 0) |
328 if ((val & ~7) != 0) |
314 types += QString::number(val); |
329 types += QString::number(val); |