dri: Fix the logger error message handling.
[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 /**
77 * Print informational message to stderr if LIBGL_DEBUG is set to
78 * "verbose".
79 */
80 _X_HIDDEN void
81 InfoMessageF(const char *f, ...)
82 {
83 va_list args;
84 const char *env;
85
86 if ((env = getenv("LIBGL_DEBUG")) && strstr(env, "verbose")) {
87 fprintf(stderr, "libGL: ");
88 va_start(args, f);
89 vfprintf(stderr, f, args);
90 va_end(args);
91 }
92 }
93
94 /**
95 * Print error message to stderr if LIBGL_DEBUG is set to anything but
96 * "quiet", (do nothing if LIBGL_DEBUG is unset).
97 */
98 _X_HIDDEN void
99 ErrorMessageF(const char *f, ...)
100 {
101 va_list args;
102 const char *env;
103
104 if ((env = getenv("LIBGL_DEBUG")) && !strstr(env, "quiet")) {
105 fprintf(stderr, "libGL error: ");
106 va_start(args, f);
107 vfprintf(stderr, f, args);
108 va_end(args);
109 }
110 }
111
112 /**
113 * Print error message unless LIBGL_DEBUG is set to "quiet".
114 *
115 * The distinction between CriticalErrorMessageF and ErrorMessageF is
116 * that critcial errors will be printed by default, (even when
117 * LIBGL_DEBUG is unset).
118 */
119 _X_HIDDEN void
120 CriticalErrorMessageF(const char *f, ...)
121 {
122 va_list args;
123 const char *env;
124
125 if (!(env = getenv("LIBGL_DEBUG")) || !strstr(env, "quiet")) {
126 fprintf(stderr, "libGL error: ");
127 va_start(args, f);
128 vfprintf(stderr, f, args);
129 va_end(args);
130
131 if (!env || !strstr(env, "verbose"))
132 fprintf(stderr, "libGL error: Try again with LIBGL_DEBUG=verbose for more details.\n");
133 }
134 }
135
136 #ifndef DEFAULT_DRIVER_DIR
137 /* this is normally defined in Mesa/configs/default with DRI_DRIVER_SEARCH_PATH */
138 #define DEFAULT_DRIVER_DIR "/usr/local/lib/dri"
139 #endif
140
141 /**
142 * Try to \c dlopen the named driver.
143 *
144 * This function adds the "_dri.so" suffix to the driver name and searches the
145 * directories specified by the \c LIBGL_DRIVERS_PATH environment variable in
146 * order to find the driver.
147 *
148 * \param driverName - a name like "i965", "radeon", "nouveau", etc.
149 *
150 * \returns
151 * A handle from \c dlopen, or \c NULL if driver file not found.
152 */
153 _X_HIDDEN void *
154 driOpenDriver(const char *driverName)
155 {
156 void *glhandle, *handle;
157 const char *libPaths, *p, *next;
158 char realDriverName[200];
159 int len;
160
161 /* Attempt to make sure libGL symbols will be visible to the driver */
162 glhandle = dlopen("libGL.so.1", RTLD_NOW | RTLD_GLOBAL);
163
164 libPaths = NULL;
165 if (geteuid() == getuid()) {
166 /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */
167 libPaths = getenv("LIBGL_DRIVERS_PATH");
168 if (!libPaths)
169 libPaths = getenv("LIBGL_DRIVERS_DIR"); /* deprecated */
170 }
171 if (libPaths == NULL)
172 libPaths = DEFAULT_DRIVER_DIR;
173
174 handle = NULL;
175 for (p = libPaths; *p; p = next) {
176 next = strchr(p, ':');
177 if (next == NULL) {
178 len = strlen(p);
179 next = p + len;
180 }
181 else {
182 len = next - p;
183 next++;
184 }
185
186 #ifdef GLX_USE_TLS
187 snprintf(realDriverName, sizeof realDriverName,
188 "%.*s/tls/%s_dri.so", len, p, driverName);
189 InfoMessageF("OpenDriver: trying %s\n", realDriverName);
190 handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL);
191 #endif
192
193 if (handle == NULL) {
194 snprintf(realDriverName, sizeof realDriverName,
195 "%.*s/%s_dri.so", len, p, driverName);
196 InfoMessageF("OpenDriver: trying %s\n", realDriverName);
197 handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL);
198 }
199
200 if (handle != NULL)
201 break;
202 else
203 ErrorMessageF("dlopen %s failed (%s)\n", realDriverName, dlerror());
204 }
205
206 if (!handle)
207 ErrorMessageF("unable to load driver: %s_dri.so\n", driverName);
208
209 if (glhandle)
210 dlclose(glhandle);
211
212 return handle;
213 }
214
215 _X_HIDDEN const __DRIextension **
216 driGetDriverExtensions(void *handle, const char *driver_name)
217 {
218 const __DRIextension **extensions = NULL;
219 const __DRIextension **(*get_extensions)(void);
220 char *get_extensions_name;
221
222 if (asprintf(&get_extensions_name, "%s_%s",
223 __DRI_DRIVER_GET_EXTENSIONS, driver_name) != -1) {
224 get_extensions = dlsym(handle, get_extensions_name);
225 if (get_extensions) {
226 free(get_extensions_name);
227 return get_extensions();
228 } else {
229 InfoMessageF("driver does not expose %s(): %s\n",
230 get_extensions_name, dlerror());
231 free(get_extensions_name);
232 }
233 }
234
235 extensions = dlsym(handle, __DRI_DRIVER_EXTENSIONS);
236 if (extensions == NULL) {
237 ErrorMessageF("driver exports no extensions (%s)\n", dlerror());
238 return NULL;
239 }
240
241 return extensions;
242 }
243
244 static GLboolean
245 __driGetMSCRate(__DRIdrawable *draw,
246 int32_t * numerator, int32_t * denominator,
247 void *loaderPrivate)
248 {
249 __GLXDRIdrawable *glxDraw = loaderPrivate;
250
251 return __glxGetMscRate(glxDraw->psc, numerator, denominator);
252 }
253
254 _X_HIDDEN const __DRIsystemTimeExtension systemTimeExtension = {
255 {__DRI_SYSTEM_TIME, __DRI_SYSTEM_TIME_VERSION},
256 __glXGetUST,
257 __driGetMSCRate
258 };
259
260 #define __ATTRIB(attrib, field) \
261 { attrib, offsetof(struct glx_config, field) }
262
263 static const struct
264 {
265 unsigned int attrib, offset;
266 } attribMap[] = {
267 __ATTRIB(__DRI_ATTRIB_BUFFER_SIZE, rgbBits),
268 __ATTRIB(__DRI_ATTRIB_LEVEL, level),
269 __ATTRIB(__DRI_ATTRIB_RED_SIZE, redBits),
270 __ATTRIB(__DRI_ATTRIB_GREEN_SIZE, greenBits),
271 __ATTRIB(__DRI_ATTRIB_BLUE_SIZE, blueBits),
272 __ATTRIB(__DRI_ATTRIB_ALPHA_SIZE, alphaBits),
273 __ATTRIB(__DRI_ATTRIB_DEPTH_SIZE, depthBits),
274 __ATTRIB(__DRI_ATTRIB_STENCIL_SIZE, stencilBits),
275 __ATTRIB(__DRI_ATTRIB_ACCUM_RED_SIZE, accumRedBits),
276 __ATTRIB(__DRI_ATTRIB_ACCUM_GREEN_SIZE, accumGreenBits),
277 __ATTRIB(__DRI_ATTRIB_ACCUM_BLUE_SIZE, accumBlueBits),
278 __ATTRIB(__DRI_ATTRIB_ACCUM_ALPHA_SIZE, accumAlphaBits),
279 __ATTRIB(__DRI_ATTRIB_SAMPLE_BUFFERS, sampleBuffers),
280 __ATTRIB(__DRI_ATTRIB_SAMPLES, samples),
281 __ATTRIB(__DRI_ATTRIB_DOUBLE_BUFFER, doubleBufferMode),
282 __ATTRIB(__DRI_ATTRIB_STEREO, stereoMode),
283 __ATTRIB(__DRI_ATTRIB_AUX_BUFFERS, numAuxBuffers),
284 #if 0
285 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_TYPE, transparentPixel),
286 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_INDEX_VALUE, transparentIndex),
287 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_RED_VALUE, transparentRed),
288 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_GREEN_VALUE, transparentGreen),
289 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_BLUE_VALUE, transparentBlue),
290 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE, transparentAlpha),
291 __ATTRIB(__DRI_ATTRIB_RED_MASK, redMask),
292 __ATTRIB(__DRI_ATTRIB_GREEN_MASK, greenMask),
293 __ATTRIB(__DRI_ATTRIB_BLUE_MASK, blueMask),
294 __ATTRIB(__DRI_ATTRIB_ALPHA_MASK, alphaMask),
295 #endif
296 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_WIDTH, maxPbufferWidth),
297 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_HEIGHT, maxPbufferHeight),
298 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_PIXELS, maxPbufferPixels),
299 __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH, optimalPbufferWidth),
300 __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT, optimalPbufferHeight),
301 #if 0
302 __ATTRIB(__DRI_ATTRIB_SWAP_METHOD, swapMethod),
303 #endif
304 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGB, bindToTextureRgb),
305 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGBA, bindToTextureRgba),
306 __ATTRIB(__DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE,
307 bindToMipmapTexture),
308 __ATTRIB(__DRI_ATTRIB_YINVERTED, yInverted),
309 __ATTRIB(__DRI_ATTRIB_FRAMEBUFFER_SRGB_CAPABLE, sRGBCapable)
310 };
311
312 static int
313 scalarEqual(struct glx_config *mode, unsigned int attrib, unsigned int value)
314 {
315 unsigned int glxValue;
316 int i;
317
318 for (i = 0; i < ARRAY_SIZE(attribMap); i++)
319 if (attribMap[i].attrib == attrib) {
320 glxValue = *(unsigned int *) ((char *) mode + attribMap[i].offset);
321 return glxValue == GLX_DONT_CARE || glxValue == value;
322 }
323
324 return GL_TRUE; /* Is a non-existing attribute equal to value? */
325 }
326
327 static int
328 driConfigEqual(const __DRIcoreExtension *core,
329 struct glx_config *config, const __DRIconfig *driConfig)
330 {
331 unsigned int attrib, value, glxValue;
332 int i;
333
334 i = 0;
335 while (core->indexConfigAttrib(driConfig, i++, &attrib, &value)) {
336 switch (attrib) {
337 case __DRI_ATTRIB_RENDER_TYPE:
338 glxValue = 0;
339 if (value & __DRI_ATTRIB_RGBA_BIT) {
340 glxValue |= GLX_RGBA_BIT;
341 }
342 if (value & __DRI_ATTRIB_COLOR_INDEX_BIT) {
343 glxValue |= GLX_COLOR_INDEX_BIT;
344 }
345 if (value & __DRI_ATTRIB_FLOAT_BIT) {
346 glxValue |= GLX_RGBA_FLOAT_BIT_ARB;
347 }
348 if (value & __DRI_ATTRIB_UNSIGNED_FLOAT_BIT) {
349 glxValue |= GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT;
350 }
351 if (glxValue != config->renderType)
352 return GL_FALSE;
353 break;
354
355 case __DRI_ATTRIB_CONFIG_CAVEAT:
356 if (value & __DRI_ATTRIB_NON_CONFORMANT_CONFIG)
357 glxValue = GLX_NON_CONFORMANT_CONFIG;
358 else if (value & __DRI_ATTRIB_SLOW_BIT)
359 glxValue = GLX_SLOW_CONFIG;
360 else
361 glxValue = GLX_NONE;
362 if (glxValue != config->visualRating)
363 return GL_FALSE;
364 break;
365
366 case __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS:
367 glxValue = 0;
368 if (value & __DRI_ATTRIB_TEXTURE_1D_BIT)
369 glxValue |= GLX_TEXTURE_1D_BIT_EXT;
370 if (value & __DRI_ATTRIB_TEXTURE_2D_BIT)
371 glxValue |= GLX_TEXTURE_2D_BIT_EXT;
372 if (value & __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT)
373 glxValue |= GLX_TEXTURE_RECTANGLE_BIT_EXT;
374 if (config->bindToTextureTargets != GLX_DONT_CARE &&
375 glxValue != config->bindToTextureTargets)
376 return GL_FALSE;
377 break;
378
379 default:
380 if (!scalarEqual(config, attrib, value))
381 return GL_FALSE;
382 }
383 }
384
385 return GL_TRUE;
386 }
387
388 static struct glx_config *
389 createDriMode(const __DRIcoreExtension * core,
390 struct glx_config *config, const __DRIconfig **driConfigs)
391 {
392 __GLXDRIconfigPrivate *driConfig;
393 int i;
394
395 for (i = 0; driConfigs[i]; i++) {
396 if (driConfigEqual(core, config, driConfigs[i]))
397 break;
398 }
399
400 if (driConfigs[i] == NULL)
401 return NULL;
402
403 driConfig = malloc(sizeof *driConfig);
404 if (driConfig == NULL)
405 return NULL;
406
407 driConfig->base = *config;
408 driConfig->driConfig = driConfigs[i];
409
410 return &driConfig->base;
411 }
412
413 _X_HIDDEN struct glx_config *
414 driConvertConfigs(const __DRIcoreExtension * core,
415 struct glx_config *configs, const __DRIconfig **driConfigs)
416 {
417 struct glx_config head, *tail, *m;
418
419 tail = &head;
420 head.next = NULL;
421 for (m = configs; m; m = m->next) {
422 tail->next = createDriMode(core, m, driConfigs);
423 if (tail->next == NULL) {
424 /* no matching dri config for m */
425 continue;
426 }
427
428
429 tail = tail->next;
430 }
431
432 return head.next;
433 }
434
435 _X_HIDDEN void
436 driDestroyConfigs(const __DRIconfig **configs)
437 {
438 int i;
439
440 for (i = 0; configs[i]; i++)
441 free((__DRIconfig *) configs[i]);
442 free(configs);
443 }
444
445 _X_HIDDEN __GLXDRIdrawable *
446 driFetchDrawable(struct glx_context *gc, GLXDrawable glxDrawable)
447 {
448 struct glx_display *const priv = __glXInitialize(gc->psc->dpy);
449 __GLXDRIdrawable *pdraw;
450 struct glx_screen *psc;
451
452 if (priv == NULL)
453 return NULL;
454
455 psc = priv->screens[gc->screen];
456 if (priv->drawHash == NULL)
457 return NULL;
458
459 if (__glxHashLookup(priv->drawHash, glxDrawable, (void *) &pdraw) == 0) {
460 pdraw->refcount ++;
461 return pdraw;
462 }
463
464 pdraw = psc->driScreen->createDrawable(psc, glxDrawable,
465 glxDrawable, gc->config);
466
467 if (pdraw == NULL) {
468 ErrorMessageF("failed to create drawable\n");
469 return NULL;
470 }
471
472 if (__glxHashInsert(priv->drawHash, glxDrawable, pdraw)) {
473 (*pdraw->destroyDrawable) (pdraw);
474 return NULL;
475 }
476 pdraw->refcount = 1;
477
478 return pdraw;
479 }
480
481 _X_HIDDEN void
482 driReleaseDrawables(struct glx_context *gc)
483 {
484 const struct glx_display *priv = gc->psc->display;
485 __GLXDRIdrawable *pdraw;
486
487 if (priv == NULL)
488 return;
489
490 if (__glxHashLookup(priv->drawHash,
491 gc->currentDrawable, (void *) &pdraw) == 0) {
492 if (pdraw->drawable == pdraw->xDrawable) {
493 pdraw->refcount --;
494 if (pdraw->refcount == 0) {
495 (*pdraw->destroyDrawable)(pdraw);
496 __glxHashDelete(priv->drawHash, gc->currentDrawable);
497 }
498 }
499 }
500
501 if (__glxHashLookup(priv->drawHash,
502 gc->currentReadable, (void *) &pdraw) == 0) {
503 if (pdraw->drawable == pdraw->xDrawable) {
504 pdraw->refcount --;
505 if (pdraw->refcount == 0) {
506 (*pdraw->destroyDrawable)(pdraw);
507 __glxHashDelete(priv->drawHash, gc->currentReadable);
508 }
509 }
510 }
511
512 gc->currentDrawable = None;
513 gc->currentReadable = None;
514
515 }
516
517 _X_HIDDEN bool
518 dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
519 unsigned *major_ver, unsigned *minor_ver,
520 uint32_t *render_type, uint32_t *flags, unsigned *api,
521 int *reset, unsigned *error)
522 {
523 unsigned i;
524 bool got_profile = false;
525 uint32_t profile;
526
527 *major_ver = 1;
528 *minor_ver = 0;
529 *render_type = GLX_RGBA_TYPE;
530 *reset = __DRI_CTX_RESET_NO_NOTIFICATION;
531 *flags = 0;
532 *api = __DRI_API_OPENGL;
533
534 if (num_attribs == 0) {
535 return true;
536 }
537
538 /* This is actually an internal error, but what the heck.
539 */
540 if (attribs == NULL) {
541 *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
542 return false;
543 }
544
545 for (i = 0; i < num_attribs; i++) {
546 switch (attribs[i * 2]) {
547 case GLX_CONTEXT_MAJOR_VERSION_ARB:
548 *major_ver = attribs[i * 2 + 1];
549 break;
550 case GLX_CONTEXT_MINOR_VERSION_ARB:
551 *minor_ver = attribs[i * 2 + 1];
552 break;
553 case GLX_CONTEXT_FLAGS_ARB:
554 *flags = attribs[i * 2 + 1];
555 break;
556 case GLX_CONTEXT_PROFILE_MASK_ARB:
557 profile = attribs[i * 2 + 1];
558 got_profile = true;
559 break;
560 case GLX_RENDER_TYPE:
561 *render_type = attribs[i * 2 + 1];
562 break;
563 case GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB:
564 switch (attribs[i * 2 + 1]) {
565 case GLX_NO_RESET_NOTIFICATION_ARB:
566 *reset = __DRI_CTX_RESET_NO_NOTIFICATION;
567 break;
568 case GLX_LOSE_CONTEXT_ON_RESET_ARB:
569 *reset = __DRI_CTX_RESET_LOSE_CONTEXT;
570 break;
571 default:
572 *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
573 return false;
574 }
575 break;
576 default:
577 /* If an unknown attribute is received, fail.
578 */
579 *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
580 return false;
581 }
582 }
583
584 if (!got_profile) {
585 if (*major_ver > 3 || (*major_ver == 3 && *minor_ver >= 2))
586 *api = __DRI_API_OPENGL_CORE;
587 } else {
588 switch (profile) {
589 case GLX_CONTEXT_CORE_PROFILE_BIT_ARB:
590 /* There are no profiles before OpenGL 3.2. The
591 * GLX_ARB_create_context_profile spec says:
592 *
593 * "If the requested OpenGL version is less than 3.2,
594 * GLX_CONTEXT_PROFILE_MASK_ARB is ignored and the functionality
595 * of the context is determined solely by the requested version."
596 */
597 *api = (*major_ver > 3 || (*major_ver == 3 && *minor_ver >= 2))
598 ? __DRI_API_OPENGL_CORE : __DRI_API_OPENGL;
599 break;
600 case GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB:
601 *api = __DRI_API_OPENGL;
602 break;
603 case GLX_CONTEXT_ES2_PROFILE_BIT_EXT:
604 *api = __DRI_API_GLES2;
605 break;
606 default:
607 *error = __DRI_CTX_ERROR_BAD_API;
608 return false;
609 }
610 }
611
612 /* Unknown flag value.
613 */
614 if (*flags & ~(__DRI_CTX_FLAG_DEBUG | __DRI_CTX_FLAG_FORWARD_COMPATIBLE
615 | __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS)) {
616 *error = __DRI_CTX_ERROR_UNKNOWN_FLAG;
617 return false;
618 }
619
620 /* There are no forward-compatible contexts before OpenGL 3.0. The
621 * GLX_ARB_create_context spec says:
622 *
623 * "Forward-compatible contexts are defined only for OpenGL versions
624 * 3.0 and later."
625 */
626 if (*major_ver < 3 && (*flags & __DRI_CTX_FLAG_FORWARD_COMPATIBLE) != 0) {
627 *error = __DRI_CTX_ERROR_BAD_FLAG;
628 return false;
629 }
630
631 if (*major_ver >= 3 && *render_type == GLX_COLOR_INDEX_TYPE) {
632 *error = __DRI_CTX_ERROR_BAD_FLAG;
633 return false;
634 }
635
636 /* The GLX_EXT_create_context_es2_profile spec says:
637 *
638 * "... If the version requested is 2.0, and the
639 * GLX_CONTEXT_ES2_PROFILE_BIT_EXT bit is set in the
640 * GLX_CONTEXT_PROFILE_MASK_ARB attribute (see below), then the context
641 * returned will implement OpenGL ES 2.0. This is the only way in which
642 * an implementation may request an OpenGL ES 2.0 context."
643 */
644 if (*api == __DRI_API_GLES2 && (*major_ver != 2 || *minor_ver != 0)) {
645 *error = __DRI_CTX_ERROR_BAD_API;
646 return false;
647 }
648
649 *error = __DRI_CTX_ERROR_SUCCESS;
650 return true;
651 }
652
653 #endif /* GLX_DIRECT_RENDERING */