glx: Move DRI extensions pointer loading to driOpenDriver().
[mesa.git] / src / glx / dri_common.c
1 /*
2 * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
3 * Copyright © 2008 Red Hat, Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Soft-
7 * ware"), to deal in the Software without restriction, including without
8 * limitation the rights to use, copy, modify, merge, publish, distribute,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, provided that the above copyright
11 * notice(s) and this permission notice appear in all copies of the Soft-
12 * ware and that both the above copyright notice(s) and this permission
13 * notice appear in supporting documentation.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
17 * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
18 * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
19 * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
20 * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
22 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR-
23 * MANCE OF THIS SOFTWARE.
24 *
25 * Except as contained in this notice, the name of a copyright holder shall
26 * not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization of
28 * the copyright holder.
29 *
30 * Authors:
31 * Kevin E. Martin <kevin@precisioninsight.com>
32 * Brian Paul <brian@precisioninsight.com>
33 * Kristian Høgsberg (krh@redhat.com)
34 */
35
36 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
37
38 #include <unistd.h>
39 #include <dlfcn.h>
40 #include <stdarg.h>
41 #include "glxclient.h"
42 #include "dri_common.h"
43 #include "loader.h"
44
45 #ifndef RTLD_NOW
46 #define RTLD_NOW 0
47 #endif
48 #ifndef RTLD_GLOBAL
49 #define RTLD_GLOBAL 0
50 #endif
51
52 _X_HIDDEN void
53 dri_message(int level, const char *f, ...)
54 {
55 va_list args;
56 int threshold = _LOADER_WARNING;
57 const char *libgl_debug;
58
59 libgl_debug = getenv("LIBGL_DEBUG");
60 if (libgl_debug) {
61 if (strstr(libgl_debug, "quiet"))
62 threshold = _LOADER_FATAL;
63 else if (strstr(libgl_debug, "verbose"))
64 threshold = _LOADER_DEBUG;
65 }
66
67 /* Note that the _LOADER_* levels are lower numbers for more severe. */
68 if (level <= threshold) {
69 fprintf(stderr, "libGL%s: ", level <= _LOADER_WARNING ? " error" : "");
70 va_start(args, f);
71 vfprintf(stderr, f, args);
72 va_end(args);
73 }
74 }
75
76 #ifndef GL_LIB_NAME
77 #define GL_LIB_NAME "libGL.so.1"
78 #endif
79
80 static const __DRIextension **
81 driGetDriverExtensions(void *handle, const char *driver_name);
82
83 /**
84 * Try to \c dlopen the named driver.
85 *
86 * This function adds the "_dri.so" suffix to the driver name and searches the
87 * directories specified by the \c LIBGL_DRIVERS_PATH environment variable in
88 * order to find the driver.
89 *
90 * \param driverName - a name like "i965", "radeon", "nouveau", etc.
91 * \param out_driver_handle - Address to return the resulting dlopen() handle.
92 *
93 * \returns
94 * The __DRIextension entrypoint table for the driver, or \c NULL if driver
95 * file not found.
96 */
97 _X_HIDDEN const __DRIextension **
98 driOpenDriver(const char *driverName, void **out_driver_handle)
99 {
100 void *glhandle, *handle;
101 const char *libPaths, *p, *next;
102 char realDriverName[200];
103 int len;
104
105 /* Attempt to make sure libGL symbols will be visible to the driver */
106 glhandle = dlopen(GL_LIB_NAME, RTLD_NOW | RTLD_GLOBAL);
107
108 libPaths = NULL;
109 if (geteuid() == getuid()) {
110 /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */
111 libPaths = getenv("LIBGL_DRIVERS_PATH");
112 if (!libPaths)
113 libPaths = getenv("LIBGL_DRIVERS_DIR"); /* deprecated */
114 }
115 if (libPaths == NULL)
116 libPaths = DEFAULT_DRIVER_DIR;
117
118 handle = NULL;
119 for (p = libPaths; *p; p = next) {
120 next = strchr(p, ':');
121 if (next == NULL) {
122 len = strlen(p);
123 next = p + len;
124 }
125 else {
126 len = next - p;
127 next++;
128 }
129
130 #ifdef GLX_USE_TLS
131 snprintf(realDriverName, sizeof realDriverName,
132 "%.*s/tls/%s_dri.so", len, p, driverName);
133 InfoMessageF("OpenDriver: trying %s\n", realDriverName);
134 handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL);
135 #endif
136
137 if (handle == NULL) {
138 snprintf(realDriverName, sizeof realDriverName,
139 "%.*s/%s_dri.so", len, p, driverName);
140 InfoMessageF("OpenDriver: trying %s\n", realDriverName);
141 handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL);
142 }
143
144 if (handle != NULL)
145 break;
146 else
147 InfoMessageF("dlopen %s failed (%s)\n", realDriverName, dlerror());
148 }
149
150 if (!handle)
151 ErrorMessageF("unable to load driver: %s_dri.so\n", driverName);
152
153 if (glhandle)
154 dlclose(glhandle);
155
156 const __DRIextension **extensions = driGetDriverExtensions(handle,
157 driverName);
158 if (!extensions) {
159 dlclose(handle);
160 handle = NULL;
161 }
162
163 *out_driver_handle = handle;
164 return extensions;
165 }
166
167 static const __DRIextension **
168 driGetDriverExtensions(void *handle, const char *driver_name)
169 {
170 const __DRIextension **extensions = NULL;
171 const __DRIextension **(*get_extensions)(void);
172 char *get_extensions_name = loader_get_extensions_name(driver_name);
173
174 if (get_extensions_name) {
175 get_extensions = dlsym(handle, get_extensions_name);
176 if (get_extensions) {
177 free(get_extensions_name);
178 return get_extensions();
179 } else {
180 InfoMessageF("driver does not expose %s(): %s\n",
181 get_extensions_name, dlerror());
182 free(get_extensions_name);
183 }
184 }
185
186 extensions = dlsym(handle, __DRI_DRIVER_EXTENSIONS);
187 if (extensions == NULL) {
188 ErrorMessageF("driver exports no extensions (%s)\n", dlerror());
189 return NULL;
190 }
191
192 return extensions;
193 }
194
195 static GLboolean
196 __driGetMSCRate(__DRIdrawable *draw,
197 int32_t * numerator, int32_t * denominator,
198 void *loaderPrivate)
199 {
200 __GLXDRIdrawable *glxDraw = loaderPrivate;
201
202 return __glxGetMscRate(glxDraw->psc, numerator, denominator);
203 }
204
205 _X_HIDDEN const __DRIsystemTimeExtension systemTimeExtension = {
206 .base = {__DRI_SYSTEM_TIME, 1 },
207
208 .getUST = __glXGetUST,
209 .getMSCRate = __driGetMSCRate
210 };
211
212 #define __ATTRIB(attrib, field) \
213 { attrib, offsetof(struct glx_config, field) }
214
215 static const struct
216 {
217 unsigned int attrib, offset;
218 } attribMap[] = {
219 __ATTRIB(__DRI_ATTRIB_BUFFER_SIZE, rgbBits),
220 __ATTRIB(__DRI_ATTRIB_LEVEL, level),
221 __ATTRIB(__DRI_ATTRIB_RED_SIZE, redBits),
222 __ATTRIB(__DRI_ATTRIB_GREEN_SIZE, greenBits),
223 __ATTRIB(__DRI_ATTRIB_BLUE_SIZE, blueBits),
224 __ATTRIB(__DRI_ATTRIB_ALPHA_SIZE, alphaBits),
225 __ATTRIB(__DRI_ATTRIB_DEPTH_SIZE, depthBits),
226 __ATTRIB(__DRI_ATTRIB_STENCIL_SIZE, stencilBits),
227 __ATTRIB(__DRI_ATTRIB_ACCUM_RED_SIZE, accumRedBits),
228 __ATTRIB(__DRI_ATTRIB_ACCUM_GREEN_SIZE, accumGreenBits),
229 __ATTRIB(__DRI_ATTRIB_ACCUM_BLUE_SIZE, accumBlueBits),
230 __ATTRIB(__DRI_ATTRIB_ACCUM_ALPHA_SIZE, accumAlphaBits),
231 __ATTRIB(__DRI_ATTRIB_SAMPLE_BUFFERS, sampleBuffers),
232 __ATTRIB(__DRI_ATTRIB_SAMPLES, samples),
233 __ATTRIB(__DRI_ATTRIB_DOUBLE_BUFFER, doubleBufferMode),
234 __ATTRIB(__DRI_ATTRIB_STEREO, stereoMode),
235 __ATTRIB(__DRI_ATTRIB_AUX_BUFFERS, numAuxBuffers),
236 #if 0
237 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_TYPE, transparentPixel),
238 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_INDEX_VALUE, transparentIndex),
239 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_RED_VALUE, transparentRed),
240 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_GREEN_VALUE, transparentGreen),
241 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_BLUE_VALUE, transparentBlue),
242 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE, transparentAlpha),
243 __ATTRIB(__DRI_ATTRIB_RED_MASK, redMask),
244 __ATTRIB(__DRI_ATTRIB_GREEN_MASK, greenMask),
245 __ATTRIB(__DRI_ATTRIB_BLUE_MASK, blueMask),
246 __ATTRIB(__DRI_ATTRIB_ALPHA_MASK, alphaMask),
247 #endif
248 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_WIDTH, maxPbufferWidth),
249 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_HEIGHT, maxPbufferHeight),
250 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_PIXELS, maxPbufferPixels),
251 __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH, optimalPbufferWidth),
252 __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT, optimalPbufferHeight),
253 __ATTRIB(__DRI_ATTRIB_SWAP_METHOD, swapMethod),
254 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGB, bindToTextureRgb),
255 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGBA, bindToTextureRgba),
256 __ATTRIB(__DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE,
257 bindToMipmapTexture),
258 __ATTRIB(__DRI_ATTRIB_YINVERTED, yInverted),
259 __ATTRIB(__DRI_ATTRIB_FRAMEBUFFER_SRGB_CAPABLE, sRGBCapable)
260 };
261
262 static int
263 scalarEqual(struct glx_config *mode, unsigned int attrib, unsigned int value)
264 {
265 unsigned glxValue, i;
266
267 for (i = 0; i < ARRAY_SIZE(attribMap); i++)
268 if (attribMap[i].attrib == attrib) {
269 glxValue = *(unsigned int *) ((char *) mode + attribMap[i].offset);
270 return glxValue == GLX_DONT_CARE || glxValue == value;
271 }
272
273 return GL_TRUE; /* Is a non-existing attribute equal to value? */
274 }
275
276 static int
277 driConfigEqual(const __DRIcoreExtension *core,
278 struct glx_config *config, const __DRIconfig *driConfig)
279 {
280 unsigned int attrib, value, glxValue;
281 int i;
282
283 i = 0;
284 while (core->indexConfigAttrib(driConfig, i++, &attrib, &value)) {
285 switch (attrib) {
286 case __DRI_ATTRIB_RENDER_TYPE:
287 glxValue = 0;
288 if (value & __DRI_ATTRIB_RGBA_BIT) {
289 glxValue |= GLX_RGBA_BIT;
290 }
291 if (value & __DRI_ATTRIB_COLOR_INDEX_BIT) {
292 glxValue |= GLX_COLOR_INDEX_BIT;
293 }
294 if (value & __DRI_ATTRIB_FLOAT_BIT) {
295 glxValue |= GLX_RGBA_FLOAT_BIT_ARB;
296 }
297 if (value & __DRI_ATTRIB_UNSIGNED_FLOAT_BIT) {
298 glxValue |= GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT;
299 }
300 if (glxValue != config->renderType)
301 return GL_FALSE;
302 break;
303
304 case __DRI_ATTRIB_CONFIG_CAVEAT:
305 if (value & __DRI_ATTRIB_NON_CONFORMANT_CONFIG)
306 glxValue = GLX_NON_CONFORMANT_CONFIG;
307 else if (value & __DRI_ATTRIB_SLOW_BIT)
308 glxValue = GLX_SLOW_CONFIG;
309 else
310 glxValue = GLX_NONE;
311 if (glxValue != config->visualRating)
312 return GL_FALSE;
313 break;
314
315 case __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS:
316 glxValue = 0;
317 if (value & __DRI_ATTRIB_TEXTURE_1D_BIT)
318 glxValue |= GLX_TEXTURE_1D_BIT_EXT;
319 if (value & __DRI_ATTRIB_TEXTURE_2D_BIT)
320 glxValue |= GLX_TEXTURE_2D_BIT_EXT;
321 if (value & __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT)
322 glxValue |= GLX_TEXTURE_RECTANGLE_BIT_EXT;
323 if (config->bindToTextureTargets != GLX_DONT_CARE &&
324 glxValue != config->bindToTextureTargets)
325 return GL_FALSE;
326 break;
327
328 case __DRI_ATTRIB_SWAP_METHOD:
329 if (value == __DRI_ATTRIB_SWAP_EXCHANGE)
330 glxValue = GLX_SWAP_EXCHANGE_OML;
331 else if (value == __DRI_ATTRIB_SWAP_COPY)
332 glxValue = GLX_SWAP_COPY_OML;
333 else
334 glxValue = GLX_SWAP_UNDEFINED_OML;
335
336 if (!scalarEqual(config, attrib, glxValue))
337 return GL_FALSE;
338
339 break;
340
341 default:
342 if (!scalarEqual(config, attrib, value))
343 return GL_FALSE;
344 }
345 }
346
347 return GL_TRUE;
348 }
349
350 static struct glx_config *
351 createDriMode(const __DRIcoreExtension * core,
352 struct glx_config *config, const __DRIconfig **driConfigs)
353 {
354 __GLXDRIconfigPrivate *driConfig;
355 int i;
356
357 for (i = 0; driConfigs[i]; i++) {
358 if (driConfigEqual(core, config, driConfigs[i]))
359 break;
360 }
361
362 if (driConfigs[i] == NULL)
363 return NULL;
364
365 driConfig = malloc(sizeof *driConfig);
366 if (driConfig == NULL)
367 return NULL;
368
369 driConfig->base = *config;
370 driConfig->driConfig = driConfigs[i];
371
372 return &driConfig->base;
373 }
374
375 _X_HIDDEN struct glx_config *
376 driConvertConfigs(const __DRIcoreExtension * core,
377 struct glx_config *configs, const __DRIconfig **driConfigs)
378 {
379 struct glx_config head, *tail, *m;
380
381 tail = &head;
382 head.next = NULL;
383 for (m = configs; m; m = m->next) {
384 tail->next = createDriMode(core, m, driConfigs);
385 if (tail->next == NULL) {
386 /* no matching dri config for m */
387 continue;
388 }
389
390
391 tail = tail->next;
392 }
393
394 return head.next;
395 }
396
397 _X_HIDDEN void
398 driDestroyConfigs(const __DRIconfig **configs)
399 {
400 int i;
401
402 for (i = 0; configs[i]; i++)
403 free((__DRIconfig *) configs[i]);
404 free(configs);
405 }
406
407 static struct glx_config *
408 driInferDrawableConfig(struct glx_screen *psc, GLXDrawable draw)
409 {
410 unsigned int fbconfig = 0;
411
412 if (__glXGetDrawableAttribute(psc->dpy, draw, GLX_FBCONFIG_ID, &fbconfig)) {
413 return glx_config_find_fbconfig(psc->configs, fbconfig);
414 }
415
416 return NULL;
417 }
418
419 _X_HIDDEN __GLXDRIdrawable *
420 driFetchDrawable(struct glx_context *gc, GLXDrawable glxDrawable)
421 {
422 struct glx_display *const priv = __glXInitialize(gc->psc->dpy);
423 __GLXDRIdrawable *pdraw;
424 struct glx_screen *psc;
425 struct glx_config *config = gc->config;
426
427 if (priv == NULL)
428 return NULL;
429
430 if (glxDrawable == None)
431 return NULL;
432
433 psc = priv->screens[gc->screen];
434 if (priv->drawHash == NULL)
435 return NULL;
436
437 if (__glxHashLookup(priv->drawHash, glxDrawable, (void *) &pdraw) == 0) {
438 pdraw->refcount ++;
439 return pdraw;
440 }
441
442 if (config == NULL)
443 config = driInferDrawableConfig(gc->psc, glxDrawable);
444 if (config == NULL)
445 return NULL;
446
447 pdraw = psc->driScreen->createDrawable(psc, glxDrawable, glxDrawable,
448 config);
449
450 if (pdraw == NULL) {
451 ErrorMessageF("failed to create drawable\n");
452 return NULL;
453 }
454
455 if (__glxHashInsert(priv->drawHash, glxDrawable, pdraw)) {
456 (*pdraw->destroyDrawable) (pdraw);
457 return NULL;
458 }
459 pdraw->refcount = 1;
460
461 return pdraw;
462 }
463
464 _X_HIDDEN void
465 driReleaseDrawables(struct glx_context *gc)
466 {
467 const struct glx_display *priv = gc->psc->display;
468 __GLXDRIdrawable *pdraw;
469
470 if (priv == NULL)
471 return;
472
473 if (__glxHashLookup(priv->drawHash,
474 gc->currentDrawable, (void *) &pdraw) == 0) {
475 if (pdraw->drawable == pdraw->xDrawable) {
476 pdraw->refcount --;
477 if (pdraw->refcount == 0) {
478 (*pdraw->destroyDrawable)(pdraw);
479 __glxHashDelete(priv->drawHash, gc->currentDrawable);
480 }
481 }
482 }
483
484 if (__glxHashLookup(priv->drawHash,
485 gc->currentReadable, (void *) &pdraw) == 0) {
486 if (pdraw->drawable == pdraw->xDrawable) {
487 pdraw->refcount --;
488 if (pdraw->refcount == 0) {
489 (*pdraw->destroyDrawable)(pdraw);
490 __glxHashDelete(priv->drawHash, gc->currentReadable);
491 }
492 }
493 }
494
495 gc->currentDrawable = None;
496 gc->currentReadable = None;
497
498 }
499
500 _X_HIDDEN bool
501 dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
502 unsigned *major_ver, unsigned *minor_ver,
503 uint32_t *render_type, uint32_t *flags, unsigned *api,
504 int *reset, int *release, unsigned *error)
505 {
506 unsigned i;
507 bool got_profile = false;
508 uint32_t profile;
509
510 *major_ver = 1;
511 *minor_ver = 0;
512 *render_type = GLX_RGBA_TYPE;
513 *reset = __DRI_CTX_RESET_NO_NOTIFICATION;
514 *release = __DRI_CTX_RELEASE_BEHAVIOR_FLUSH;
515 *flags = 0;
516 *api = __DRI_API_OPENGL;
517
518 if (num_attribs == 0) {
519 return true;
520 }
521
522 /* This is actually an internal error, but what the heck.
523 */
524 if (attribs == NULL) {
525 *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
526 return false;
527 }
528
529 for (i = 0; i < num_attribs; i++) {
530 switch (attribs[i * 2]) {
531 case GLX_CONTEXT_MAJOR_VERSION_ARB:
532 *major_ver = attribs[i * 2 + 1];
533 break;
534 case GLX_CONTEXT_MINOR_VERSION_ARB:
535 *minor_ver = attribs[i * 2 + 1];
536 break;
537 case GLX_CONTEXT_FLAGS_ARB:
538 *flags = attribs[i * 2 + 1];
539 break;
540 case GLX_CONTEXT_PROFILE_MASK_ARB:
541 profile = attribs[i * 2 + 1];
542 got_profile = true;
543 break;
544 case GLX_RENDER_TYPE:
545 *render_type = attribs[i * 2 + 1];
546 break;
547 case GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB:
548 switch (attribs[i * 2 + 1]) {
549 case GLX_NO_RESET_NOTIFICATION_ARB:
550 *reset = __DRI_CTX_RESET_NO_NOTIFICATION;
551 break;
552 case GLX_LOSE_CONTEXT_ON_RESET_ARB:
553 *reset = __DRI_CTX_RESET_LOSE_CONTEXT;
554 break;
555 default:
556 *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
557 return false;
558 }
559 break;
560 case GLX_CONTEXT_RELEASE_BEHAVIOR_ARB:
561 switch (attribs[i * 2 + 1]) {
562 case GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB:
563 *release = __DRI_CTX_RELEASE_BEHAVIOR_NONE;
564 break;
565 case GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB:
566 *release = __DRI_CTX_RELEASE_BEHAVIOR_FLUSH;
567 break;
568 default:
569 *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
570 return false;
571 }
572 break;
573 default:
574 /* If an unknown attribute is received, fail.
575 */
576 *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
577 return false;
578 }
579 }
580
581 if (!got_profile) {
582 if (*major_ver > 3 || (*major_ver == 3 && *minor_ver >= 2))
583 *api = __DRI_API_OPENGL_CORE;
584 } else {
585 switch (profile) {
586 case GLX_CONTEXT_CORE_PROFILE_BIT_ARB:
587 /* There are no profiles before OpenGL 3.2. The
588 * GLX_ARB_create_context_profile spec says:
589 *
590 * "If the requested OpenGL version is less than 3.2,
591 * GLX_CONTEXT_PROFILE_MASK_ARB is ignored and the functionality
592 * of the context is determined solely by the requested version."
593 */
594 *api = (*major_ver > 3 || (*major_ver == 3 && *minor_ver >= 2))
595 ? __DRI_API_OPENGL_CORE : __DRI_API_OPENGL;
596 break;
597 case GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB:
598 *api = __DRI_API_OPENGL;
599 break;
600 case GLX_CONTEXT_ES_PROFILE_BIT_EXT:
601 if (*major_ver >= 3)
602 *api = __DRI_API_GLES3;
603 else if (*major_ver == 2 && *minor_ver == 0)
604 *api = __DRI_API_GLES2;
605 else if (*major_ver == 1 && *minor_ver < 2)
606 *api = __DRI_API_GLES;
607 else {
608 *error = __DRI_CTX_ERROR_BAD_API;
609 return false;
610 }
611 break;
612 default:
613 *error = __DRI_CTX_ERROR_BAD_API;
614 return false;
615 }
616 }
617
618 /* Unknown flag value.
619 */
620 if (*flags & ~(__DRI_CTX_FLAG_DEBUG | __DRI_CTX_FLAG_FORWARD_COMPATIBLE
621 | __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS)) {
622 *error = __DRI_CTX_ERROR_UNKNOWN_FLAG;
623 return false;
624 }
625
626 /* There are no forward-compatible contexts before OpenGL 3.0. The
627 * GLX_ARB_create_context spec says:
628 *
629 * "Forward-compatible contexts are defined only for OpenGL versions
630 * 3.0 and later."
631 */
632 if (*major_ver < 3 && (*flags & __DRI_CTX_FLAG_FORWARD_COMPATIBLE) != 0) {
633 *error = __DRI_CTX_ERROR_BAD_FLAG;
634 return false;
635 }
636
637 if (*major_ver >= 3 && *render_type == GLX_COLOR_INDEX_TYPE) {
638 *error = __DRI_CTX_ERROR_BAD_FLAG;
639 return false;
640 }
641
642 *error = __DRI_CTX_ERROR_SUCCESS;
643 return true;
644 }
645
646 #endif /* GLX_DIRECT_RENDERING */